Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disallow rules in the Schema #15916

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add disallow rules in the Schema #15916

wants to merge 4 commits into from

Conversation

map-r
Copy link
Contributor

@map-r map-r commented Feb 23, 2024

Suggested merge commit message (convention)

Feature (engine): Schema now supports disallowing items. Introduced SchemaItemDefinition#disallowIn, #disallowChildren and #disallowAttributes. Closes #15835.

… `SchemaItemDefinition#disallowIn`, `#disallowChildren` and `disallowAttributes`.
Copy link
Contributor

coderabbitai bot commented May 13, 2024

Walkthrough

The recent updates across various modules introduce the ability to specify disallowed children and attributes in the schema definitions of the editing engine. This enhancement aims to provide finer control over document structure by allowing exclusions in element behavior, crucial for complex document integrations.

Changes

Files Summary of Changes
docs/framework/.../editing-engine.md
docs/tutorials/.../model-and-schema.md
packages/ckeditor5-engine/docs/framework/.../schema.md
Updated documentation to include details about disallowing children and attributes in schemas.
packages/ckeditor5-code-block/.../codeblockediting.ts
packages/ckeditor5-code-block/.../codeblockediting.js
Adjustments in schema definitions to disallow certain children and attributes within codeBlock.
packages/ckeditor5-engine/src/model/schema.ts
packages/ckeditor5-engine/tests/model/schema.js
Core schema logic updated to handle disallowing rules, including new methods for compiling and propagating schema rules.
packages/ckeditor5-image/src/image/imageinlineediting.ts Logic updated for disallowing inline images in certain contexts, with added clarity in comments.

Assessment against linked issues

Objective Addressed Explanation
Implement children and attributes disallowing in Schema (#15835)
Ensure disallows take precedence over allows in schema compilation (#15835)
Allow schema to inherit disallows from other elements (#15835)
Update documentation to reflect new schema capabilities (#15835)
Verify schema changes do not introduce recursion issues (#15835) The changes include logic for handling disallows, but it's unclear if recursion problems are specifically addressed without seeing runtime behavior or specific tests for this case.

The changes align well with the objectives of enhancing schema capabilities to include disallowing specific children and attributes, crucial for creating more structured and controlled document environments.


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ec9b919 and 3b02216.
Files selected for processing (3)
  • packages/ckeditor5-code-block/src/codeblockediting.ts (2 hunks)
  • packages/ckeditor5-code-block/tests/codeblockediting.js (1 hunks)
  • packages/ckeditor5-engine/docs/framework/deep-dive/schema.md (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/ckeditor5-code-block/src/codeblockediting.ts
  • packages/ckeditor5-code-block/tests/codeblockediting.js
Additional Context Used
LanguageTool (8)
packages/ckeditor5-engine/docs/framework/deep-dive/schema.md (8)

Near line 13: Although “in regards of” is sometimes used in casual speech, it is typically considered a nonstandard phrase.
Context: ...cteristics (inline vs. block, atomicity in regards of external actions). This information is ...


Near line 453: ‘made out of’ might be wordy. Consider a shorter alternative.
Context: ... Generally speaking, content is usually made out of blocks like paragraphs, list items, ima...


Near line 585: “despite the fact that” is a wordy phrase. Consider making your sentence clearer.
Context: ...(see schema.register( '$block' ...)), despite the fact that the block quote and paragraph features ...


Near line 587: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...with the allowContentOf: '$root' rule), because <$container> is also allowed in `<$ro...


Near line 680: Two determiners in a row. Choose either “the” or “a”.
Context: ... Schema#checkChild()} method which is the a base method used to check whether some ...


Near line 718: Consider adding a comma after ‘Normally’ for more clarity.
Context: ... user presses the "Block quote" button. Normally it would wrap the two selected blocks (...


Near line 747: This expression is wordy and can make your writing hard to follow, try rephrasing to be more direct.
Context: ...violate rules defined in the schema**. The reason for this is that when you implement a command or any oth...


Near line 748: ‘in the meantime’ might be wordy. Consider a shorter alternative.
Context: ...do all the necessary changes. The state in the meantime (between these atomic operations) may b...


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Out of diff range and nitpick comments (22)
docs/tutorials/crash-course/model-and-schema.md (1)

Line range hint 96-96: Consider adding a comma after "On the right side" for better readability.

- On the right side you should see `highlight:true` under the `Allowed Attributes` section.
+ On the right side, you should see `highlight:true` under the `Allowed Attributes` section.
docs/framework/architecture/editing-engine.md (5)

Line range hint 29-31: Clarify the repeated words in the description of the model.

- Like in the DOM, the model structure is contained within a {@link module:engine/model/document~Document document} that contains {@link module:engine/model/document~Document#roots root elements} (the model, as well as the view, may have multiple roots). The document also holds its {@link module:engine/model/history~History history of its changes}.
+ Like in the DOM, the model structure is contained within a {@link module:engine/model/document~Document document}, which includes {@link module:engine/model/document~Document#roots root elements} (the model, as well as the view, may have multiple roots). The document also maintains a record of its changes through the {@link module:engine/model/history~History}.

Line range hint 61-61: Ensure consistency in the explanation of nested change blocks.

- All changes done within a single `change()` block are combined into one undo step (they are added to a single {@link module:engine/model/batch~Batch batch}). When nesting `change()` blocks, all changes are added to the outermost `change()` block's batch.
+ All changes made within a single `change()` block are combined into one undo step, grouped into a single {@link module:engine/model/batch~Batch batch}. When nesting `change()` blocks, all changes are consolidated into the batch of the outermost `change()` block.

Line range hint 116-116: Clarify the conditional phrase regarding the effect on typed text.

- OK, but how to let CKEditor&nbsp;5 know that I want the selection to "be bold" in the case described above? This is important information because it affects whether or not the typed text will be bold, too.
+ OK, but how does one inform CKEditor&nbsp;5 that the selection should "be bold" in the described scenario? This is crucial as it determines whether the typed text will also be bold.

Line range hint 152-152: Ensure clarity in the description of ranges and selections.

- A {@link module:engine/model/range~Range} contains two positions: {@link module:engine/model/range~Range#start start} and {@link module:engine/model/range~Range#end end} ones.
+ A {@link module:engine/model/range~Range} is defined by two positions: the {@link module:engine/model/range~Range#start start} and the {@link module:engine/model/range~Range#end end}.

Line range hint 364-364: Clarify the description of the editing downcasting process.

- {@link framework/deep-dive/conversion/downcast#downcast-pipelines **Editing downcasting**} is a bit different process than the other two.
+ {@link framework/deep-dive/conversion/downcast#downcast-pipelines **Editing downcasting**} differs from the other two processes.
packages/ckeditor5-engine/docs/framework/deep-dive/schema.md (15)

Line range hint 13-13: Consider revising the phrase "in regards of" to "in regard to" for grammatical correctness.

- atomicity in regards of external actions
+ atomicity in regard to external actions

Line range hint 412-412: Consider adding a preposition to correct the sentence structure.

- Taken these characteristics, the image caption should be defined as a limit element
+ Considering these characteristics, the image caption should be defined as a limit element

Line range hint 428-428: Insert a comma after "like in the example above" for better readability.

- For an image caption like in the example above it does not make much sense to select the caption box
+ For an image caption like in the example above, it does not make much sense to select the caption box

Line range hint 430-430: Insert a comma after "Most likely" for better readability.

- Most likely users should be able to select the entire image
+ Most likely, users should be able to select the entire image

Line range hint 453-453: Consider revising "made out of" to a more concise alternative like "composed of".

- content is usually made out of blocks like paragraphs
+ content is usually composed of blocks like paragraphs

Line range hint 497-497: Insert a comma after "and this".

- find their way into the editor data and this is what makes them content elements
+ find their way into the editor data, and this is what makes them content elements

Line range hint 585-585: Consider revising "despite the fact that" to a more concise alternative like "although".

- despite the fact that the block quote and paragraph features know nothing about each other
+ although the block quote and paragraph features know nothing about each other

Line range hint 587-587: Remove the comma before "because" as the clause is essential to the meaning.

- with the `allowContentOf: '$root'` rule), because `<$container>` is also allowed in `<$root>`
+ with the `allowContentOf: '$root'` rule) because `<$container>` is also allowed in `<$root>`

Line range hint 680-680: Correct the double determiner issue by choosing either "the" or "a".

- which is the a base method used to check whether some element is allowed
+ which is a base method used to check whether some element is allowed

Line range hint 718-718: Insert a comma after "Normally" for better clarity.

- Normally it would wrap the two selected blocks (`<y>` and `<z>`) with a `<blockQuote>` element
+ Normally, it would wrap the two selected blocks (`<y>` and `<z>`) with a `<blockQuote>` element

Line range hint 736-736: Insert a comma after "code".

- specifically for your scenario by your code which makes their implementation much easier
+ specifically for your scenario by your code, which makes their implementation much easier

Line range hint 747-747: Consider revising the wordy expression to be more direct.

- The reason for this is that when you implement a command or any other feature
+ This is because when you implement a command or any other feature

Line range hint 748-748: Insert a comma after "feature".

- when you implement a command or any other feature you may need to perform multiple operations
+ when you implement a command or any other feature, you may need to perform multiple operations

Line range hint 748-748: Consider revising "in the meantime" to a more concise alternative like "meanwhile".

- The state in the meantime (between these atomic operations) may be incorrect
+ The state meanwhile (between these atomic operations) may be incorrect

Line range hint 767-767: Insert a comma after "Thanks to that".

- Thanks to that if you tried to load incorrect data to the editor
+ Thanks to that, if you tried to load incorrect data to the editor
packages/ckeditor5-engine/src/model/schema.ts (1)

929-986: Optimize the schema compilation process for performance.

The schema compilation process in the _compile method involves multiple iterations over potentially large sets of schema definitions. Consider optimizing this process by reducing the number of iterations and exploring more efficient data structures or algorithms. This could significantly improve the performance, especially for large schemas.

packages/ckeditor5-code-block/tests/codeblockediting.js Outdated Show resolved Hide resolved
Comment on lines +50 to +57
it( 'copies definitions objects', () => {
const definitions = {};

schema.register( 'foo', definitions );

definitions.isBlock = true;

expect( schema.getDefinitions().foo ).to.not.have.property( 'isBlock' );
expect( schema.getDefinitions().foo.isBlock ).to.be.false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the definitions object is properly cloned to avoid unintended side effects.

-  const definitions = {};
+  const definitions = { ...{} };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it( 'copies definitions objects', () => {
const definitions = {};
schema.register( 'foo', definitions );
definitions.isBlock = true;
expect( schema.getDefinitions().foo ).to.not.have.property( 'isBlock' );
expect( schema.getDefinitions().foo.isBlock ).to.be.false;
it( 'copies definitions objects', () => {
const definitions = { ...{} };
schema.register( 'foo', definitions );
definitions.isBlock = true;
expect( schema.getDefinitions().foo.isBlock ).to.be.false;

packages/ckeditor5-engine/src/model/schema.ts Show resolved Hide resolved
docs/framework/architecture/editing-engine.md Show resolved Hide resolved
@scofalik scofalik requested a review from niegowski May 16, 2024 16:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Out of diff range and nitpick comments (9)
packages/ckeditor5-engine/docs/framework/deep-dive/schema.md (9)

Line range hint 13-13: Consider revising "in regards of" to "with regard to" for better clarity.

- atomicity in regards of external actions
+ atomicity with regard to external actions

Line range hint 585-585: Consider revising "despite the fact that" to "although" for conciseness.

- despite the fact that the block quote and paragraph features
+ although the block quote and paragraph features

Line range hint 587-587: Remove the comma before "because" as it is not necessary.

- rule), because `<$container>` is also allowed in `<$root>`
+ rule) because `<$container>` is also allowed in `<$root>`

Line range hint 680-680: Remove the extra determiner "the" for grammatical correctness.

- which is the a base method used to check
+ which is the base method used to check

Line range hint 718-718: Add a comma after "Normally" for better readability.

- Normally it would wrap the two selected blocks
+ Normally, it would wrap the two selected blocks

Line range hint 747-747: Consider revising "The reason for this is that" to "This is because" for conciseness.

- The reason for this is that when you implement a command or any other feature
+ This is because when you implement a command or any other feature

Line range hint 748-748: Consider revising "in the meantime" to "meanwhile" for conciseness.

- The state in the meantime (between these atomic operations)
+ The state meanwhile (between these atomic operations)

Line range hint 25-25: Replace hard tabs with spaces for consistency.

-	<code>
+    <code>

Also applies to: 35-35, 43-45, 53-54, 62-64, 71-71, 82-83, 145-148, 149-150, 151-152, 153-154, 155-156, 157-158, 159-160, 161-162, 163-164, 165-166, 167-168, 169-170, 171-172, 173-174, 175-176, 177-178, 179-180, 181-182, 183-184, 185-186, 187-188, 189-190, 191-192, 193-194, 195-196, 197-198, 199-200, 201-202, 203-204, 205-206, 207-208, 209-210, 211-212, 213-214, 215-216, 217-218, 219-220, 221-222, 223-224, 225-226, 227-228, 229-230, 231-232, 233-234, 235-236, 237-238, 239-240, 241-242, 243-244, 245-246, 247-248, 249-250, 251-252, 253-254, 255-256, 257-258, 259-260, 261-262, 263-264, 265-266, 267-268, 269-270, 271-272, 273-274, 275-276, 277-278, 279-280, 281-282, 283-284, 285-286, 287-288, 289-290, 291-292, 293-294, 295-296, 297-298, 299-300, 301-302, 303-304, 305-306, 307-308, 309-310, 311-312, 313-314, 315-316, 317-318, 319-320, 321-322, 323-324, 325-326, 327-328, 329-330, 331-332, 333-334, 335-336, 337-338, 339-340, 341-342, 343-344, 345-346, 347-348, 349-350, 351-352, 353-354, 355-356, 357-358, 359-360, 361-362, 363-364, 365-366, 367-368, 369-370, 371-372, 373-374, 375-376, 377-378, 379-380, 381-382, 383-384, 385-386, 387-388, 389-390, 391-392, 393-394, 398-398, 399-400, 416-416, 423-423, 434-434, 440-440, 444-444, 446-448, 460-460, 462-462, 474-474, 483-483, 490-490, 501-501, 510-510, 519-519, 523-523, 527-528, 532-534, 538-541, 545-547, 555-555, 563-566, 581-581, 590-590, 599-599, 600-600, 601-601, 602-602, 603-603, 604-604, 605-605, 606-606, 607-607, 608-608, 616-616, 617-617, 618-618, 619-619, 620-620, 621-621, 622-622, 623-623, 624-624, 625-625, 626-626, 627-627, 628-628, 629-629, 630-630, 631-631, 632-632, 633-633, 634-634, 635-635, 636-636, 637-637, 638-638, 639-639, 640-640, 641-641, 649-649, 650-650, 651-651, 652-652, 653-653, 654-654, 655-655, 656-656, 657-657, 658-658, 659-659, 660-660, 661-661, 662-662, 663-663, 664-664, 665-665, 666-666, 667-667, 668-668, 669-669, 670-670, 671-671, 672-672, 673-673, 674-674, 688-688, 689-689, 691-691, 692-692, 693-693, 694-694, 695-695, 712-712, 713-713, 714-714, 722-722, 723-723, 724-724, 725-725, 726-726, 770-770, 775-775, 780-780, 784-785, 789-789, 793-793, 797-797, 803-804, 808-809, 813-817


Line range hint 436-436: Add blank lines before and after fenced code blocks for better readability.

436a437
+
446a447
+
462a463
+

Comment on lines +74 to +76
## Disallowing structures

The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line before the heading for better readability.

74a75
+

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
## Disallowing structures
The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.

Disallowing structures

The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.


</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

@@ -71,6 +71,70 @@ Both the `{@link module:engine/model/schema~SchemaItemDefinition#allowIn}` and `
You can read more about the format of the item definition in the {@link module:engine/model/schema~SchemaItemDefinition} API guide.
</info-box>

## Disallowing structures

The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider revising "made out of" to "composed of" for conciseness.

- Generally speaking, content is usually made out of blocks
+ Generally speaking, content is usually composed of blocks

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.
The schema, in addition to allowing certain structures, can also be used to ensure some structures are explicitly disallowed. This can be achieved with the use of disallow rules.
Generally speaking, content is usually composed of blocks

schema.extend( 'baseChild', { disallowIn: 'extendedParent' } );
```

This changes how schema rules are resolved. `baseChild` will still be disallowed in `extendedParent` as before. But now, `extendedChild` will be disallowed in `extendedParent` as well. That's because it will inherit this rule from `baseChild`, and there is no other rule that would allow `extendedChild` in `extendedParent`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing space for consistency.

- 
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
This changes how schema rules are resolved. `baseChild` will still be disallowed in `extendedParent` as before. But now, `extendedChild` will be disallowed in `extendedParent` as well. That's because it will inherit this rule from `baseChild`, and there is no other rule that would allow `extendedChild` in `extendedParent`.
This changes how schema rules are resolved. `baseChild` will still be disallowed in `extendedParent` as before. But now, `extendedChild` will be disallowed in `extendedParent` as well. That's because it will inherit this rule from `baseChild`, and there is no other rule that would allow `extendedChild` in `extendedParent`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement children and attributes disallowing in Schema
2 participants