-
Notifications
You must be signed in to change notification settings - Fork 40
Introduced schema#setAttributeProperties() and schema#getAttributeProperties() methods #1711
Conversation
…ributeProperties() methods.
…edef describing known properties.
…teProperties to a more proper place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔂 😛
src/model/schema.js
Outdated
* A map containing attribute's properties. | ||
* | ||
* @private | ||
* @member {Map.<String,String>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a plain object, not a map. So Object.<String,String>
src/model/schema.js
Outdated
* | ||
* @returns {Object.<String,module:engine/model/schema~SchemaCompiledItemDefinition>} | ||
*/ | ||
getDefinitions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? This method was here on purpose (next to getDefinition()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As funny as it might sound I have grabbed one method too much where moving setAttributeProperties
and getAttributeProperties
. Thanks for catching that.
Restored to the original position.
src/model/schema.js
Outdated
@@ -475,6 +470,70 @@ export default class Schema { | |||
}, { priority: 'high' } ); | |||
} | |||
|
|||
/** | |||
* Registers custom properties to a given attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets? Registering means saying "I exist!". We register nodes (Schema#register()
). You can call register( foo )
only once too (cause you report your existence once).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather:
Defines properties of the given attribute.
This method allows assigning additional information to model attributes. Currently, it is only used to mark formatting attributes (like
bold
,italic
) which allows differentiating them from semantic attributes (such assrc
,listType
, etc.). This knowledge is then used by features like "Remove format".
And that's it. Good documentation should back all big words by giving real-life examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you used "metadata" below. That's a nice word too. You may try to use it here too. It may be better than "information" or "properties".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The introduction was modified to shortly mention cases and link AttributeProperties#isFormatting
example for further reading.
Unfortunately I could not link to isFormatting property directly due to ckeditor/ckeditor5-dev#504.
PTAL
src/model/schema.js
Outdated
* } ); | ||
* | ||
* console.log( schema.getAttributeProperties( 'blockQuote' ) ); | ||
* // Logs: {one: 1, two: 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ one: 1, two: 2 }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was actually the output copied straight from the browser. I'll reformat this.
src/model/schema.js
Outdated
* isFormatting: false | ||
* } ); | ||
* | ||
* You can also use custom attributes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom properties
src/model/schema.js
Outdated
* You can also use custom attributes: | ||
* | ||
* schema.setAttributeProperties( 'blockQuote', { | ||
* customAttribute: 'value' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customProperty
src/model/schema.js
Outdated
* | ||
* It can be used to mark the attributes relation and handle them in a common way. | ||
* | ||
* // Mark blockQuote as a formatting attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blockQuote is not an attribute – it's an element
Let's use something realistic – bold
, italic
, fontFamily
, etc.
src/model/schema.js
Outdated
} | ||
|
||
/** | ||
* Returns properties assigned to a given attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns properties of the given attribute.
src/model/schema.js
Outdated
* See {@link module:engine/model/schema~Schema#setAttributeProperties `Schema#setAttributeProperties()`} for usage examples. | ||
* | ||
* @typedef {Object} module:engine/model/schema~AttributeProperties | ||
* @property {Boolean} [isFormatting] Indicates that the attribute should be considered as a visual formatting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing examples of what it means. Show what common attrs are considered "formatting" and which not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly changes in docs.
I also find the custom AttributeProperties
data type confusing and it should be somehow resolved.
src/model/schema.js
Outdated
@@ -39,6 +39,14 @@ export default class Schema { | |||
constructor() { | |||
this._sourceDefinitions = {}; | |||
|
|||
/** | |||
* A map containing attribute's properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* A map containing attribute's properties. | |
* A map containing attribute properties. |
src/model/schema.js
Outdated
* A map containing attribute's properties. | ||
* | ||
* @private | ||
* @member {Map.<String,String>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @member {Map.<String,String>} | |
* @member {Object.<String,String>} |
src/model/schema.js
Outdated
@@ -475,6 +470,70 @@ export default class Schema { | |||
}, { priority: 'high' } ); | |||
} | |||
|
|||
/** | |||
* Registers custom properties to a given attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Registers custom properties to a given attribute. | |
* Adds custom properties to an attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was addressed by fix for one issues raised in previous review.
src/model/schema.js
Outdated
/** | ||
* Registers custom properties to a given attribute. | ||
* | ||
* It can be used to mark the attributes relation and handle them in a common way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* It can be used to mark the attributes relation and handle them in a common way. | |
* Properties allow categorization of model attributes. Thanks to that, certain groups of attributes can be recognized and handled in the same way by some of the editor features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was addressed by fix for one issues raised in previous review.
src/model/schema.js
Outdated
* isFormatting: false | ||
* } ); | ||
* | ||
* You can also use custom attributes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very confusing. We're talking about properties and all of the sudden there's this line about custom attributes of... attributes? This needs rewording. I guess the intention was that one can use any property name they want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it was a typo, should be custom properties.
src/model/schema.js
Outdated
* console.log( schema.getAttributeProperties( 'blockQuote' ) ); | ||
* // Logs: {one: 1, two: 2} | ||
* | ||
* @param {String} attributeName Name of the attribute to receive properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {String} attributeName Name of the attribute to receive properties. | |
* @param {String} attributeName A name of the attribute to gain the properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about receive -> gain change. I semantically both words are very similar, while receive is used more commonly.
I'll keep receive - but ofc feel free to follow this up.
* // Logs: {one: 1, two: 2} | ||
* | ||
* @param {String} attributeName Name of the attribute to receive properties. | ||
* @param {module:engine/model/schema~AttributeProperties} properties A dictionary of properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. First, it is stated that
You can also use custom attributes:
Then we enforce a type, which clearly declares which properties are allowed.
src/model/schema.js
Outdated
* @param {module:engine/model/schema~AttributeProperties} properties A dictionary of properties. | ||
*/ | ||
setAttributeProperties( attributeName, properties ) { | ||
this._attributeProperties[ attributeName ] = Object.assign( this._attributeProperties[ attributeName ] || {}, properties ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._attributeProperties[ attributeName ] = Object.assign( this._attributeProperties[ attributeName ] || {}, properties ); | |
this._attributeProperties[ attributeName ] = Object.assign( this.getAttributeProperties( attributeName ) || {}, properties ); |
src/model/schema.js
Outdated
} | ||
|
||
/** | ||
* Returns properties assigned to a given attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Returns properties assigned to a given attribute. | |
* Returns properties associated with a given model attribute. See {@link #setAttributeProperties `setAttributeProperties()`}. |
@@ -1285,6 +1344,15 @@ export class SchemaContext { | |||
* @typedef {Object} module:engine/model/schema~SchemaContextItem | |||
*/ | |||
|
|||
/** | |||
* A structure containing additional metadata describing the attribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I wrote earlier, setAttributeProperties()
allows any property names while this type clearly narrows possible options to isFormatting
only. We should figure that out.
I accidentally moved it too while reordering Schema#setAttributeProperties() method.
…ributes than specified in the AttributeProperties typedef.
All the requested changes were addressed. There's one thing that requires some comments:
This is interesting point @oleq and I can see how it can be an issue. I can see two ways to resolve it:
Taking above into consideration I'm strongly for going with a dedicated typedef, but explicitly say that it can be extended. |
Perfect! ❤️ |
Suggested merge commit message (convention)
Feature: Introduced
schema#setAttributeProperties()
andschema#getAttributeProperties()
methods. Closes ckeditor/ckeditor5#1659.Followups
highlightI'll actually start a discussion whether highlight should be considered formatting markup or not.