@ckeditor/ckeditor5-style 34.0.0 → 34.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +0 -4
  3. package/build/style.js +1 -1
  4. package/build/translations/cs.js +1 -0
  5. package/build/translations/de.js +1 -0
  6. package/build/translations/el.js +1 -0
  7. package/build/translations/en-au.js +1 -0
  8. package/build/translations/gl.js +1 -0
  9. package/build/translations/hr.js +1 -0
  10. package/build/translations/it.js +1 -0
  11. package/build/translations/lv.js +1 -0
  12. package/build/translations/nl.js +1 -0
  13. package/build/translations/pl.js +1 -0
  14. package/build/translations/pt-br.js +1 -0
  15. package/build/translations/sk.js +1 -0
  16. package/build/translations/sr-latn.js +1 -0
  17. package/build/translations/sr.js +1 -0
  18. package/build/translations/zh.js +1 -0
  19. package/ckeditor5-metadata.json +1 -1
  20. package/lang/translations/cs.po +33 -0
  21. package/lang/translations/de.po +33 -0
  22. package/lang/translations/el.po +33 -0
  23. package/lang/translations/en-au.po +33 -0
  24. package/lang/translations/gl.po +33 -0
  25. package/lang/translations/hr.po +33 -0
  26. package/lang/translations/it.po +33 -0
  27. package/lang/translations/lv.po +33 -0
  28. package/lang/translations/nl.po +33 -0
  29. package/lang/translations/pl.po +33 -0
  30. package/lang/translations/pt-br.po +33 -0
  31. package/lang/translations/sk.po +33 -0
  32. package/lang/translations/sr-latn.po +33 -0
  33. package/lang/translations/sr.po +33 -0
  34. package/lang/translations/zh.po +33 -0
  35. package/package.json +34 -33
  36. package/src/stylecommand.js +144 -153
  37. package/src/styleediting.js +1 -85
  38. package/src/styleui.js +1 -1
  39. package/src/ui/stylegridbuttonview.js +1 -1
  40. package/src/utils.js +13 -6
  41. package/theme/stylegrid.css +1 -0
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ #
3
+ # !!! IMPORTANT !!!
4
+ #
5
+ # Before you edit this file, please keep in mind that contributing to the project
6
+ # translations is possible ONLY via the Transifex online service.
7
+ #
8
+ # To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
9
+ #
10
+ # To learn more, check out the official contributor's guide:
11
+ # https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
12
+ #
13
+ msgid ""
14
+ msgstr ""
15
+ "Language-Team: Serbian (https://www.transifex.com/ckeditor/teams/11143/sr/)\n"
16
+ "Language: sr\n"
17
+ "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
18
+
19
+ msgctxt "The label of the styles dropdown button in the toolbar displayed when no style is currently active."
20
+ msgid "Styles"
21
+ msgstr "Стилови"
22
+
23
+ msgctxt "The label of the styles dropdown button in the toolbar displayed when multiple styles are currently active."
24
+ msgid "Multiple styles"
25
+ msgstr "Више стилова"
26
+
27
+ msgctxt "The label of the group in the styles dropdown containing styles applicable to blocks only (paragraphs, headings, etc.)."
28
+ msgid "Block styles"
29
+ msgstr "Блок стилови"
30
+
31
+ msgctxt "The label of the group in the styles dropdown containing inline applicable to text only."
32
+ msgid "Text styles"
33
+ msgstr "Стилови текста"
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ #
3
+ # !!! IMPORTANT !!!
4
+ #
5
+ # Before you edit this file, please keep in mind that contributing to the project
6
+ # translations is possible ONLY via the Transifex online service.
7
+ #
8
+ # To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
9
+ #
10
+ # To learn more, check out the official contributor's guide:
11
+ # https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
12
+ #
13
+ msgid ""
14
+ msgstr ""
15
+ "Language-Team: Chinese (Taiwan) (https://www.transifex.com/ckeditor/teams/11143/zh_TW/)\n"
16
+ "Language: zh_TW\n"
17
+ "Plural-Forms: nplurals=1; plural=0;\n"
18
+
19
+ msgctxt "The label of the styles dropdown button in the toolbar displayed when no style is currently active."
20
+ msgid "Styles"
21
+ msgstr "樣式"
22
+
23
+ msgctxt "The label of the styles dropdown button in the toolbar displayed when multiple styles are currently active."
24
+ msgid "Multiple styles"
25
+ msgstr "多重樣式"
26
+
27
+ msgctxt "The label of the group in the styles dropdown containing styles applicable to blocks only (paragraphs, headings, etc.)."
28
+ msgid "Block styles"
29
+ msgstr "區塊樣式"
30
+
31
+ msgctxt "The label of the group in the styles dropdown containing inline applicable to text only."
32
+ msgid "Text styles"
33
+ msgstr "文字樣式"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-style",
3
- "version": "34.0.0",
3
+ "version": "34.1.0",
4
4
  "description": "Style feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,41 +12,42 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^34.0.0"
15
+ "ckeditor5": "^34.1.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-alignment": "^34.0.0",
19
- "@ckeditor/ckeditor5-basic-styles": "^34.0.0",
20
- "@ckeditor/ckeditor5-cloud-services": "^34.0.0",
21
- "@ckeditor/ckeditor5-code-block": "^34.0.0",
22
- "@ckeditor/ckeditor5-core": "^34.0.0",
18
+ "@ckeditor/ckeditor5-alignment": "^34.1.0",
19
+ "@ckeditor/ckeditor5-basic-styles": "^34.1.0",
20
+ "@ckeditor/ckeditor5-block-quote": "^34.1.0",
21
+ "@ckeditor/ckeditor5-cloud-services": "^34.1.0",
22
+ "@ckeditor/ckeditor5-code-block": "^34.1.0",
23
+ "@ckeditor/ckeditor5-core": "^34.1.0",
23
24
  "@ckeditor/ckeditor5-dev-utils": "^30.0.0",
24
- "@ckeditor/ckeditor5-easy-image": "^34.0.0",
25
- "@ckeditor/ckeditor5-editor-classic": "^34.0.0",
26
- "@ckeditor/ckeditor5-engine": "^34.0.0",
27
- "@ckeditor/ckeditor5-font": "^34.0.0",
28
- "@ckeditor/ckeditor5-heading": "^34.0.0",
29
- "@ckeditor/ckeditor5-highlight": "^34.0.0",
30
- "@ckeditor/ckeditor5-horizontal-line": "^34.0.0",
31
- "@ckeditor/ckeditor5-html-embed": "^34.0.0",
32
- "@ckeditor/ckeditor5-html-support": "^34.0.0",
33
- "@ckeditor/ckeditor5-image": "^34.0.0",
34
- "@ckeditor/ckeditor5-indent": "^34.0.0",
35
- "@ckeditor/ckeditor5-language": "^34.0.0",
36
- "@ckeditor/ckeditor5-link": "^34.0.0",
37
- "@ckeditor/ckeditor5-list": "^34.0.0",
38
- "@ckeditor/ckeditor5-mention": "^34.0.0",
39
- "@ckeditor/ckeditor5-page-break": "^34.0.0",
40
- "@ckeditor/ckeditor5-paragraph": "^34.0.0",
41
- "@ckeditor/ckeditor5-paste-from-office": "^34.0.0",
42
- "@ckeditor/ckeditor5-remove-format": "^34.0.0",
43
- "@ckeditor/ckeditor5-source-editing": "^34.0.0",
44
- "@ckeditor/ckeditor5-table": "^34.0.0",
45
- "@ckeditor/ckeditor5-theme-lark": "^34.0.0",
46
- "@ckeditor/ckeditor5-typing": "^34.0.0",
47
- "@ckeditor/ckeditor5-ui": "^34.0.0",
48
- "@ckeditor/ckeditor5-utils": "^34.0.0",
49
- "@ckeditor/ckeditor5-word-count": "^34.0.0",
25
+ "@ckeditor/ckeditor5-easy-image": "^34.1.0",
26
+ "@ckeditor/ckeditor5-editor-classic": "^34.1.0",
27
+ "@ckeditor/ckeditor5-engine": "^34.1.0",
28
+ "@ckeditor/ckeditor5-font": "^34.1.0",
29
+ "@ckeditor/ckeditor5-heading": "^34.1.0",
30
+ "@ckeditor/ckeditor5-highlight": "^34.1.0",
31
+ "@ckeditor/ckeditor5-horizontal-line": "^34.1.0",
32
+ "@ckeditor/ckeditor5-html-embed": "^34.1.0",
33
+ "@ckeditor/ckeditor5-html-support": "^34.1.0",
34
+ "@ckeditor/ckeditor5-image": "^34.1.0",
35
+ "@ckeditor/ckeditor5-indent": "^34.1.0",
36
+ "@ckeditor/ckeditor5-language": "^34.1.0",
37
+ "@ckeditor/ckeditor5-link": "^34.1.0",
38
+ "@ckeditor/ckeditor5-list": "^34.1.0",
39
+ "@ckeditor/ckeditor5-mention": "^34.1.0",
40
+ "@ckeditor/ckeditor5-page-break": "^34.1.0",
41
+ "@ckeditor/ckeditor5-paragraph": "^34.1.0",
42
+ "@ckeditor/ckeditor5-paste-from-office": "^34.1.0",
43
+ "@ckeditor/ckeditor5-remove-format": "^34.1.0",
44
+ "@ckeditor/ckeditor5-source-editing": "^34.1.0",
45
+ "@ckeditor/ckeditor5-table": "^34.1.0",
46
+ "@ckeditor/ckeditor5-theme-lark": "^34.1.0",
47
+ "@ckeditor/ckeditor5-typing": "^34.1.0",
48
+ "@ckeditor/ckeditor5-ui": "^34.1.0",
49
+ "@ckeditor/ckeditor5-utils": "^34.1.0",
50
+ "@ckeditor/ckeditor5-word-count": "^34.1.0",
50
51
  "webpack": "^5.58.1",
51
52
  "webpack-cli": "^4.9.0"
52
53
  },
@@ -18,29 +18,28 @@ import { logWarning, first } from 'ckeditor5/src/utils';
18
18
  * @extends module:core/command~Command
19
19
  */
20
20
  export default class StyleCommand extends Command {
21
- constructor( editor, styles ) {
21
+ /**
22
+ * Creates an instance of the command.
23
+ *
24
+ * @param {module:core/editor/editor~Editor} editor Editor on which this command will be used.
25
+ * @param {Object} styleDefinitions Normalized definitions of the styles.
26
+ * @param {Array.<module:style/style~StyleDefinition>} styleDefinitions.block Definitions of block styles.
27
+ * @param {Array.<module:style/style~StyleDefinition>} styleDefinitions.inline Definitions of inline styles.
28
+ */
29
+ constructor( editor, styleDefinitions ) {
22
30
  super( editor );
23
31
 
24
32
  /**
25
- * Set of currently applied styles on current selection.
33
+ * Set of currently applied styles on the current selection.
26
34
  *
27
35
  * Names of styles correspond to the `name` property of
28
36
  * {@link module:style/style~StyleDefinition configured definitions}.
29
37
  *
30
- * @observable
31
38
  * @readonly
32
- * @member {Boolean|String} #value
33
- */
34
-
35
- /**
36
- * Styles object. Helps in getting styles definitions by
37
- * class name, style name and model element name.
38
- *
39
- * @private
40
- * @readonly
41
- * @member {module:style/styleediting~Styles}
39
+ * @observable
40
+ * @member {Array.<String>} #value
42
41
  */
43
- this.styles = styles;
42
+ this.set( 'value', [] );
44
43
 
45
44
  /**
46
45
  * Names of enabled styles (styles that can be applied to the current selection).
@@ -55,33 +54,80 @@ export default class StyleCommand extends Command {
55
54
  this.set( 'enabledStyles', [] );
56
55
 
57
56
  /**
58
- * Refresh state.
57
+ * Normalized definitions of the styles.
58
+ *
59
+ * @private
60
+ * @readonly
61
+ * @member {Object} #styleDefinitions
59
62
  */
60
- this.refresh();
63
+ this._styleDefinitions = styleDefinitions;
61
64
  }
62
65
 
63
66
  /**
64
67
  * @inheritDoc
65
68
  */
66
69
  refresh() {
67
- let value = [];
68
- const editor = this.editor;
69
- const selection = editor.model.document.selection;
70
- const block = first( selection.getSelectedBlocks() );
70
+ const model = this.editor.model;
71
+ const selection = model.document.selection;
72
+
73
+ const value = new Set();
74
+ const enabledStyles = new Set();
75
+
76
+ // Inline styles.
77
+ for ( const definition of this._styleDefinitions.inline ) {
78
+ for ( const ghsAttributeName of definition.ghsAttributes ) {
79
+ // Check if this inline style is enabled.
80
+ if ( model.schema.checkAttributeInSelection( selection, ghsAttributeName ) ) {
81
+ enabledStyles.add( definition.name );
82
+ }
83
+
84
+ // Check if this inline style is active.
85
+ const ghsAttributeValue = this._getValueFromFirstAllowedNode( ghsAttributeName );
86
+
87
+ if ( hasAllClasses( ghsAttributeValue, definition.classes ) ) {
88
+ value.add( definition.name );
89
+ }
90
+ }
91
+ }
92
+
93
+ // Block styles.
94
+ const firstBlock = first( selection.getSelectedBlocks() );
95
+
96
+ if ( firstBlock ) {
97
+ const ancestorBlocks = firstBlock.getAncestors( { includeSelf: true, parentFirst: true } );
71
98
 
72
- this.enabledStyles = [];
99
+ for ( const block of ancestorBlocks ) {
100
+ // E.g. reached a model table when the selection is in a cell. The command should not modify
101
+ // ancestors of a table.
102
+ if ( model.schema.isLimit( block ) ) {
103
+ break;
104
+ }
105
+
106
+ if ( !model.schema.checkAttribute( block, 'htmlAttributes' ) ) {
107
+ continue;
108
+ }
109
+
110
+ for ( const definition of this._styleDefinitions.block ) {
111
+ // Check if this block style is enabled.
112
+ if ( !definition.modelElements.includes( block.name ) ) {
113
+ continue;
114
+ }
73
115
 
74
- if ( !block || !editor.model.schema.isObject( block ) ) {
75
- value = this._prepareNewInlineElementValue( value, selection );
76
- this.enabledStyles = this.styles.getInlineElementsNames();
116
+ enabledStyles.add( definition.name );
77
117
 
78
- if ( block ) {
79
- value = this._prepareNewBlockElementValue( value, block );
118
+ // Check if this block style is active.
119
+ const ghsAttributeValue = block.getAttribute( 'htmlAttributes' );
120
+
121
+ if ( hasAllClasses( ghsAttributeValue, definition.classes ) ) {
122
+ value.add( definition.name );
123
+ }
124
+ }
80
125
  }
81
126
  }
82
127
 
128
+ this.enabledStyles = Array.from( enabledStyles ).sort();
83
129
  this.isEnabled = this.enabledStyles.length > 0;
84
- this.value = this.isEnabled ? value : [];
130
+ this.value = this.isEnabled ? Array.from( value ).sort() : [];
85
131
  }
86
132
 
87
133
  /**
@@ -95,145 +141,68 @@ export default class StyleCommand extends Command {
95
141
  * * When applying inline styles:
96
142
  * * If the selection is on a range, the command applies the style classes to all nodes in that range.
97
143
  * * If the selection is collapsed in a non-empty node, the command applies the style classes to the
98
- * {@link module:engine/model/document~Document#selection} itself (note that typed characters copy style classes from the selection).
144
+ * {@link module:engine/model/document~Document#selection}.
99
145
  *
100
146
  * * When applying block styles:
101
147
  * * If the selection is on a range, the command applies the style classes to the nearest block parent element.
102
148
  *
103
- * * When selection is set on a widget object:
104
- * * Do nothing. Widgets are not yet supported by the style command.
105
- *
106
149
  * @fires execute
107
- * @param {String} styleName Style name matching the one defined in the config.
150
+ * @param {String} styleName Style name matching the one defined in the
151
+ * {@link module:style/style~StyleConfig#definitions configuration}.
108
152
  */
109
153
  execute( styleName ) {
110
154
  if ( !this.enabledStyles.includes( styleName ) ) {
111
155
  /**
112
- * Style command can be executed only on a correct style name.
113
- * This warning may be caused by passing name that it not specified in any of the
114
- * definitions in the styles config, when trying to apply style that is not allowed
115
- * on given element or passing class name instead of the style name.
156
+ * Style command can be executed only with a correct style name.
157
+ *
158
+ * This warning may be caused by:
159
+ *
160
+ * * passing a name that is not specified in the {@link module:style/style~StyleConfig#definitions configuration}
161
+ * (e.g. a CSS class name),
162
+ * * when trying to apply a style that is not allowed on a given element.
116
163
  *
117
164
  * @error style-command-executed-with-incorrect-style-name
118
165
  */
119
166
  logWarning( 'style-command-executed-with-incorrect-style-name' );
120
- return;
121
- }
122
-
123
- const editor = this.editor;
124
- const model = editor.model;
125
- const doc = model.document;
126
- const selection = doc.selection;
127
-
128
- const selectedBlockElement = first( selection.getSelectedBlocks() );
129
- const definition = this.styles.getDefinitionsByName( styleName );
130
167
 
131
- if ( selectedBlockElement && definition.isBlock ) {
132
- this._handleStyleUpdate( definition, selectedBlockElement );
133
- } else {
134
- this._handleStyleUpdate( definition, selection );
168
+ return;
135
169
  }
136
- }
137
170
 
138
- /**
139
- * Adds or removes classes to element, range or selection.
140
- *
141
- * @private
142
- * @param {Object} definition Style definition object.
143
- * @param {module:engine/model/selection~Selectable} selectable Selection, range or element to update the style on.
144
- */
145
- _handleStyleUpdate( definition, selectable ) {
146
- const { name, element, classes } = definition;
171
+ const model = this.editor.model;
172
+ const selection = model.document.selection;
147
173
  const htmlSupport = this.editor.plugins.get( 'GeneralHtmlSupport' );
148
174
 
149
- if ( this.value.includes( name ) ) {
150
- htmlSupport.removeModelHtmlClass( element, classes, selectable );
151
- } else {
152
- htmlSupport.addModelHtmlClass( element, classes, selectable );
153
- }
154
- }
175
+ const definition = [
176
+ ...this._styleDefinitions.inline,
177
+ ...this._styleDefinitions.block
178
+ ].find( ( { name } ) => name == styleName );
155
179
 
156
- /**
157
- * Returns inline element value.
158
- *
159
- * @private
160
- * @param {Array} value
161
- * @param {module:engine/model/selection~Selection} selection
162
- */
163
- _prepareNewInlineElementValue( value, selection ) {
164
- let newValue = [ ...value ];
165
-
166
- const attributes = selection.getAttributes();
167
-
168
- for ( const [ attribute ] of attributes ) {
169
- newValue = [ ...newValue, ...this._getAttributeValue( attribute ) ];
170
- }
171
-
172
- return newValue;
173
- }
174
-
175
- /**
176
- * Returns element value and sets enabled styles.
177
- *
178
- * @private
179
- * @param {Array} value
180
- * @param {Object|null} element
181
- * @return {Array} Current block element styles value.
182
- */
183
- _prepareNewBlockElementValue( value, element ) {
184
- const availableDefinitions = this.styles.getDefinitionsByElementName( element.name );
185
-
186
- if ( availableDefinitions ) {
187
- const blockStyleNames = availableDefinitions.map( ( { name } ) => name );
188
- this.enabledStyles = [ ...this.enabledStyles, ...blockStyleNames ];
189
- }
180
+ model.change( () => {
181
+ let selectables;
190
182
 
191
- return [ ...value, ...this._getAttributeValue( 'htmlAttributes' ) ];
192
- }
193
-
194
- /**
195
- * Get classes attribute value.
196
- *
197
- * @private
198
- * @param {String} attribute
199
- */
200
- _getAttributeValue( attribute ) {
201
- const value = [];
202
- const classes = attribute === 'htmlAttributes' ?
203
- this._getValueFromBlockElement() :
204
- this._getValueFromFirstAllowedNode( attribute );
205
-
206
- for ( const htmlClass of classes ) {
207
- const { name } = this.styles.getDefinitionsByClassName( htmlClass ) || {};
208
-
209
- value.push( name );
210
- }
211
-
212
- return value;
213
- }
214
-
215
- /**
216
- * Gets classes from currently selected block element.
217
- *
218
- * @private
219
- */
220
- _getValueFromBlockElement() {
221
- const selection = this.editor.model.document.selection;
222
- const block = first( selection.getSelectedBlocks() );
223
- const attributes = block.getAttribute( 'htmlAttributes' );
224
-
225
- if ( attributes ) {
226
- return attributes.classes;
227
- }
183
+ if ( definition.isBlock ) {
184
+ selectables = getAffectedBlocks( selection.getSelectedBlocks(), definition.modelElements, model.schema );
185
+ } else {
186
+ selectables = [ selection ];
187
+ }
228
188
 
229
- return [];
189
+ for ( const selectable of selectables ) {
190
+ if ( this.value.includes( definition.name ) ) {
191
+ htmlSupport.removeModelHtmlClass( definition.element, definition.classes, selectable );
192
+ } else {
193
+ htmlSupport.addModelHtmlClass( definition.element, definition.classes, selectable );
194
+ }
195
+ }
196
+ } );
230
197
  }
231
198
 
232
199
  /**
233
- * Gets classes from currently selected text element.
200
+ * Checks the attribute value of the first node in the selection that allows the attribute.
201
+ * For the collapsed selection, returns the selection attribute.
234
202
  *
235
203
  * @private
236
- * @param {String} attributeName Text attribute name.
204
+ * @param {String} attributeName Name of the GHS attribute.
205
+ * @returns {Object|null} The attribute value.
237
206
  */
238
207
  _getValueFromFirstAllowedNode( attributeName ) {
239
208
  const model = this.editor.model;
@@ -241,27 +210,49 @@ export default class StyleCommand extends Command {
241
210
  const selection = model.document.selection;
242
211
 
243
212
  if ( selection.isCollapsed ) {
244
- /* istanbul ignore next */
245
- const { classes } = selection.getAttribute( attributeName ) || {};
246
-
247
- /* istanbul ignore next */
248
- return classes || [];
213
+ return selection.getAttribute( attributeName );
249
214
  }
250
215
 
251
216
  for ( const range of selection.getRanges() ) {
252
217
  for ( const item of range.getItems() ) {
253
- /* istanbul ignore else */
254
218
  if ( schema.checkAttribute( item, attributeName ) ) {
255
- /* istanbul ignore next */
256
- const { classes } = item.getAttribute( attributeName ) || {};
257
-
258
- /* istanbul ignore next */
259
- return classes || [];
219
+ return item.getAttribute( attributeName );
260
220
  }
261
221
  }
262
222
  }
263
223
 
264
- /* istanbul ignore next */
265
- return [];
224
+ return null;
225
+ }
226
+ }
227
+
228
+ // Verifies if all classes are present in the given GHS attribute.
229
+ function hasAllClasses( ghsAttributeValue, classes ) {
230
+ if ( !ghsAttributeValue || !ghsAttributeValue.classes ) {
231
+ return false;
266
232
  }
233
+
234
+ return classes.every( className => ghsAttributeValue.classes.includes( className ) );
235
+ }
236
+
237
+ // Returns a set of elements that should be affected by the block-style change.
238
+ function getAffectedBlocks( selectedBlocks, elementNames, schema ) {
239
+ const blocks = new Set();
240
+
241
+ for ( const selectedBlock of selectedBlocks ) {
242
+ const ancestorBlocks = selectedBlock.getAncestors( { includeSelf: true, parentFirst: true } );
243
+
244
+ for ( const block of ancestorBlocks ) {
245
+ if ( schema.isLimit( block ) ) {
246
+ break;
247
+ }
248
+
249
+ if ( elementNames.includes( block.name ) ) {
250
+ blocks.add( block );
251
+
252
+ break;
253
+ }
254
+ }
255
+ }
256
+
257
+ return blocks;
267
258
  }
@@ -43,9 +43,8 @@ export default class StyleEditing extends Plugin {
43
43
  const editor = this.editor;
44
44
  const dataSchema = editor.plugins.get( 'DataSchema' );
45
45
  const normalizedStyleDefinitions = normalizeConfig( dataSchema, editor.config.get( 'style.definitions' ) );
46
- const styles = new Styles( normalizedStyleDefinitions );
47
46
 
48
- editor.commands.add( 'style', new StyleCommand( editor, styles ) );
47
+ editor.commands.add( 'style', new StyleCommand( editor, normalizedStyleDefinitions ) );
49
48
 
50
49
  this._configureGHSDataFilter( normalizedStyleDefinitions );
51
50
  }
@@ -66,89 +65,6 @@ export default class StyleEditing extends Plugin {
66
65
  }
67
66
  }
68
67
 
69
- /**
70
- * The helper class storing various mappings based on
71
- * {@link module:style/style~StyleConfig#definitions configured style definitions}. Used internally by
72
- * {@link module:style/stylecommand~StyleCommand}.
73
- *
74
- * @private
75
- */
76
- class Styles {
77
- /**
78
- * @param {Object} An object with normalized style definitions grouped into `block` and `inline` categories (arrays).
79
- */
80
- constructor( styleDefinitions ) {
81
- this.styleTypes = [ 'inline', 'block' ];
82
- this.styleDefinitions = styleDefinitions;
83
- this.elementToDefinition = new Map();
84
- this.classToDefinition = new Map();
85
- this.nameToDefinition = new Map();
86
-
87
- this._prepareDefinitionsMapping();
88
- }
89
-
90
- /**
91
- * Populates various maps to simplify getting config definitions
92
- * by model name,class name and style name.
93
- *
94
- * @private
95
- */
96
- _prepareDefinitionsMapping() {
97
- for ( const type of this.styleTypes ) {
98
- for ( const { modelElements, name, element, classes, isBlock } of this.styleDefinitions[ type ] ) {
99
- for ( const modelElement of modelElements ) {
100
- const currentValue = this.elementToDefinition.get( modelElement ) || [];
101
- const newValue = [ ...currentValue, { name, element, classes } ];
102
- this.elementToDefinition.set( modelElement, newValue );
103
- }
104
-
105
- this.classToDefinition.set( classes.join( ' ' ), { name, element, classes } );
106
- this.nameToDefinition.set( name, { name, element, classes, isBlock } );
107
- }
108
- }
109
- }
110
-
111
- /**
112
- * Returns all inline definitions elements names.
113
- *
114
- * @protected
115
- * @return {Array.<String>} Inline elements names.
116
- */
117
- getInlineElementsNames() {
118
- return this.styleDefinitions.inline.map( ( { name } ) => name );
119
- }
120
-
121
- /**
122
- * Returns the style config definitions by the model element name.
123
- *
124
- * @protected
125
- * @return {Object} Style config definition.
126
- */
127
- getDefinitionsByElementName( elementName ) {
128
- return this.elementToDefinition.get( elementName );
129
- }
130
-
131
- /**
132
- * Returns the style config definitions by the style name.
133
- *
134
- * @protected
135
- * @return {Object} Style config definition.
136
- */
137
- getDefinitionsByName( name ) {
138
- return this.nameToDefinition.get( name );
139
- }
140
-
141
- /**
142
- * Returns the style config definitions by the style name.
143
- *
144
- * @protected
145
- * @return {Object} Style config definition.
146
- */
147
- getDefinitionsByClassName( className ) {
148
- return this.classToDefinition.get( className );
149
- }
150
- }
151
-
152
68
  // Translates a normalized style definition to a view matcher pattern.
153
69
  //
154
70
  // @param {Object} definition A normalized style definition.
package/src/styleui.js CHANGED
@@ -39,7 +39,7 @@ export default class StyleUI extends Plugin {
39
39
  const dataSchema = editor.plugins.get( 'DataSchema' );
40
40
  const normalizedStyleDefinitions = normalizeConfig( dataSchema, editor.config.get( 'style.definitions' ) );
41
41
 
42
- // Add the dropdown fo the component factory.
42
+ // Add the dropdown to the component factory.
43
43
  editor.ui.componentFactory.add( 'style', locale => {
44
44
  const t = locale.t;
45
45
  const dropdown = createDropdown( locale );
@@ -109,7 +109,7 @@ export default class StyleGridButtonView extends ButtonView {
109
109
  * be used instead. This avoids previewing a standalone `<td>`, `<li>`, etc. without a parent.
110
110
  *
111
111
  * @private
112
- * @param {module:style/style~StyleDefinition} styleDefinition
112
+ * @param {String} elementName
113
113
  * @returns {Boolean} `true` when the element can be rendered. `false` otherwise.
114
114
  */
115
115
  _isPreviewable( elementName ) {