@ckeditor/ckeditor5-alignment 35.3.2 → 36.0.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.
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor 5 text alignment feature** – https://github.com/ckeditor/ckeditor5-alignment <br>
5
- Copyright (c) 2003-2022, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -1,5 +1,5 @@
1
1
  !function(t){const e=t.en=t.en||{};e.dictionary=Object.assign(e.dictionary||{},{"Align center":"Align center","Align left":"Align left","Align right":"Align right",Justify:"Justify","Text alignment":"Text alignment","Text alignment toolbar":"Text alignment toolbar"})}(window.CKEDITOR_TRANSLATIONS||(window.CKEDITOR_TRANSLATIONS={})),
2
2
  /*!
3
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var t={704:(t,e,n)=>{t.exports=n(79)("./src/core.js")},273:(t,e,n)=>{t.exports=n(79)("./src/ui.js")},209:(t,e,n)=>{t.exports=n(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};(()=>{"use strict";n.r(i),n.d(i,{Alignment:()=>f,AlignmentEditing:()=>g,AlignmentUI:()=>d});var t=n(704),e=n(209);const o=["left","right","center","justify"];function r(t){return o.includes(t)}function a(t,e){return"rtl"==e.contentLanguageDirection?"right"===t:"left"===t}function s(t){const n=t.map((t=>{let e;return e="string"==typeof t?{name:t}:t,e})).filter((t=>{const n=!!o.includes(t.name);return n||(0,e.logWarning)("alignment-config-name-not-recognized",{option:t}),n})),i=n.filter((t=>!!t.className)).length;if(i&&i<n.length)throw new e.CKEditorError("alignment-config-classnames-are-missing",{configuredOptions:t});return n.forEach(((n,i,o)=>{const r=o.slice(i+1);if(r.some((t=>t.name==n.name)))throw new e.CKEditorError("alignment-config-name-already-defined",{option:n,configuredOptions:t});if(n.className){if(r.some((t=>t.className==n.className)))throw new e.CKEditorError("alignment-config-classname-already-defined",{option:n,configuredOptions:t})}})),n}const l="alignment";class c extends t.Command{refresh(){const t=this.editor.locale,n=(0,e.first)(this.editor.model.document.selection.getSelectedBlocks());this.isEnabled=!!n&&this._canBeAligned(n),this.isEnabled&&n.hasAttribute("alignment")?this.value=n.getAttribute("alignment"):this.value="rtl"===t.contentLanguageDirection?"right":"left"}execute(t={}){const e=this.editor,n=e.locale,i=e.model,o=i.document,r=t.value;i.change((t=>{const e=Array.from(o.selection.getSelectedBlocks()).filter((t=>this._canBeAligned(t))),i=e[0].getAttribute("alignment");a(r,n)||i===r||!r?function(t,e){for(const n of t)e.removeAttribute(l,n)}(e,t):function(t,e,n){for(const i of t)e.setAttribute(l,n,i)}(e,t,r)}))}_canBeAligned(t){return this.editor.model.schema.checkAttribute(t,l)}}class g extends t.Plugin{static get pluginName(){return"AlignmentEditing"}constructor(t){super(t),t.config.define("alignment",{options:[...o.map((t=>({name:t})))]})}init(){const t=this.editor,e=t.locale,n=t.model.schema,i=s(t.config.get("alignment.options")).filter((t=>r(t.name)&&!a(t.name,e))),o=i.some((t=>!!t.className));n.extend("$block",{allowAttributes:"alignment"}),t.model.schema.setAttributeProperties("alignment",{isFormatting:!0}),o?t.conversion.attributeToAttribute(function(t){const e={model:{key:"alignment",values:t.map((t=>t.name))},view:{}};for(const n of t)e.view[n.name]={key:"class",value:n.className};return e}(i)):t.conversion.for("downcast").attributeToAttribute(function(t){const e={model:{key:"alignment",values:t.map((t=>t.name))},view:{}};for(const{name:n}of t)e.view[n]={key:"style",value:{"text-align":n}};return e}(i));const l=function(t){const e=[];for(const{name:n}of t)e.push({view:{key:"style",value:{"text-align":n}},model:{key:"alignment",value:n}});return e}(i);for(const e of l)t.conversion.for("upcast").attributeToAttribute(e);const g=function(t){const e=[];for(const{name:n}of t)e.push({view:{key:"align",value:n},model:{key:"alignment",value:n}});return e}(i);for(const e of g)t.conversion.for("upcast").attributeToAttribute(e);t.commands.add("alignment",new c(t))}}var u=n(273);const m=new Map([["left",t.icons.alignLeft],["right",t.icons.alignRight],["center",t.icons.alignCenter],["justify",t.icons.alignJustify]]);class d extends t.Plugin{get localizedOptionTitles(){const t=this.editor.t;return{left:t("Align left"),right:t("Align right"),center:t("Align center"),justify:t("Justify")}}static get pluginName(){return"AlignmentUI"}init(){const t=this.editor,e=t.ui.componentFactory,n=t.t,i=s(t.config.get("alignment.options"));i.map((t=>t.name)).filter(r).forEach((t=>this._addButton(t))),e.add("alignment",(o=>{const r=(0,u.createDropdown)(o),a=i.map((t=>e.create(`alignment:${t.name}`)));(0,u.addToolbarToDropdown)(r,a,{enableActiveItemFocusOnDropdownOpen:!0}),r.buttonView.set({label:n("Text alignment"),tooltip:!0}),r.toolbarView.isVertical=!0,r.toolbarView.ariaLabel=n("Text alignment toolbar"),r.extendTemplate({attributes:{class:"ck-alignment-dropdown"}});const s="rtl"===o.contentLanguageDirection?m.get("right"):m.get("left");return r.buttonView.bind("icon").toMany(a,"isOn",((...t)=>{const e=t.findIndex((t=>t));return e<0?s:a[e].icon})),r.bind("isEnabled").toMany(a,"isEnabled",((...t)=>t.some((t=>t)))),this.listenTo(r,"execute",(()=>{t.editing.view.focus()})),r}))}_addButton(t){const e=this.editor;e.ui.componentFactory.add(`alignment:${t}`,(n=>{const i=e.commands.get("alignment"),o=new u.ButtonView(n);return o.set({label:this.localizedOptionTitles[t],icon:m.get(t),tooltip:!0,isToggleable:!0}),o.bind("isEnabled").to(i),o.bind("isOn").to(i,"value",(e=>e===t)),this.listenTo(o,"execute",(()=>{e.execute("alignment",{value:t}),e.editing.view.focus()})),o}))}}class f extends t.Plugin{static get requires(){return[g,d]}static get pluginName(){return"Alignment"}}})(),(window.CKEditor5=window.CKEditor5||{}).alignment=i})();
5
+ */(()=>{var t={704:(t,e,n)=>{t.exports=n(79)("./src/core.js")},273:(t,e,n)=>{t.exports=n(79)("./src/ui.js")},209:(t,e,n)=>{t.exports=n(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function n(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={exports:{}};return t[i](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};(()=>{"use strict";n.r(i),n.d(i,{Alignment:()=>f,AlignmentEditing:()=>g,AlignmentUI:()=>d});var t=n(704),e=n(209);const o=["left","right","center","justify"];function r(t){return o.includes(t)}function a(t,e){return"rtl"==e.contentLanguageDirection?"right"===t:"left"===t}function s(t){const n=t.map((t=>{let e;return e="string"==typeof t?{name:t}:t,e})).filter((t=>{const n=o.includes(t.name);return n||(0,e.logWarning)("alignment-config-name-not-recognized",{option:t}),n})),i=n.filter((t=>Boolean(t.className))).length;if(i&&i<n.length)throw new e.CKEditorError("alignment-config-classnames-are-missing",{configuredOptions:t});return n.forEach(((n,i,o)=>{const r=o.slice(i+1);if(r.some((t=>t.name==n.name)))throw new e.CKEditorError("alignment-config-name-already-defined",{option:n,configuredOptions:t});if(n.className){if(r.some((t=>t.className==n.className)))throw new e.CKEditorError("alignment-config-classname-already-defined",{option:n,configuredOptions:t})}})),n}const l="alignment";class c extends t.Command{refresh(){const t=this.editor.locale,n=(0,e.first)(this.editor.model.document.selection.getSelectedBlocks());this.isEnabled=Boolean(n)&&this._canBeAligned(n),this.isEnabled&&n.hasAttribute("alignment")?this.value=n.getAttribute("alignment"):this.value="rtl"===t.contentLanguageDirection?"right":"left"}execute(t={}){const e=this.editor,n=e.locale,i=e.model,o=i.document,r=t.value;i.change((t=>{const e=Array.from(o.selection.getSelectedBlocks()).filter((t=>this._canBeAligned(t))),i=e[0].getAttribute("alignment");a(r,n)||i===r||!r?function(t,e){for(const n of t)e.removeAttribute(l,n)}(e,t):function(t,e,n){for(const i of t)e.setAttribute(l,n,i)}(e,t,r)}))}_canBeAligned(t){return this.editor.model.schema.checkAttribute(t,l)}}class g extends t.Plugin{static get pluginName(){return"AlignmentEditing"}constructor(t){super(t),t.config.define("alignment",{options:o.map((t=>({name:t})))})}init(){const t=this.editor,e=t.locale,n=t.model.schema,i=s(t.config.get("alignment.options")).filter((t=>r(t.name)&&!a(t.name,e))),o=i.some((t=>!!t.className));n.extend("$block",{allowAttributes:"alignment"}),t.model.schema.setAttributeProperties("alignment",{isFormatting:!0}),o?t.conversion.attributeToAttribute(function(t){const e={};for(const n of t)e[n.name]={key:"class",value:n.className};const n={model:{key:"alignment",values:t.map((t=>t.name))},view:e};return n}(i)):t.conversion.for("downcast").attributeToAttribute(function(t){const e={};for(const{name:n}of t)e[n]={key:"style",value:{"text-align":n}};const n={model:{key:"alignment",values:t.map((t=>t.name))},view:e};return n}(i));const l=function(t){const e=[];for(const{name:n}of t)e.push({view:{key:"style",value:{"text-align":n}},model:{key:"alignment",value:n}});return e}(i);for(const e of l)t.conversion.for("upcast").attributeToAttribute(e);const g=function(t){const e=[];for(const{name:n}of t)e.push({view:{key:"align",value:n},model:{key:"alignment",value:n}});return e}(i);for(const e of g)t.conversion.for("upcast").attributeToAttribute(e);t.commands.add("alignment",new c(t))}}var u=n(273);const m=new Map([["left",t.icons.alignLeft],["right",t.icons.alignRight],["center",t.icons.alignCenter],["justify",t.icons.alignJustify]]);class d extends t.Plugin{get localizedOptionTitles(){const t=this.editor.t;return{left:t("Align left"),right:t("Align right"),center:t("Align center"),justify:t("Justify")}}static get pluginName(){return"AlignmentUI"}init(){const t=this.editor,e=t.ui.componentFactory,n=t.t,i=s(t.config.get("alignment.options"));i.map((t=>t.name)).filter(r).forEach((t=>this._addButton(t))),e.add("alignment",(o=>{const r=(0,u.createDropdown)(o);(0,u.addToolbarToDropdown)(r,(()=>i.map((t=>e.create(`alignment:${t.name}`)))),{enableActiveItemFocusOnDropdownOpen:!0,isVertical:!0,ariaLabel:n("Text alignment toolbar")}),r.buttonView.set({label:n("Text alignment"),tooltip:!0}),r.extendTemplate({attributes:{class:"ck-alignment-dropdown"}});const a="rtl"===o.contentLanguageDirection?m.get("right"):m.get("left"),s=t.commands.get("alignment");return r.buttonView.bind("icon").to(s,"value",(t=>m.get(t)||a)),r.bind("isEnabled").to(s,"isEnabled"),this.listenTo(r,"execute",(()=>{t.editing.view.focus()})),r}))}_addButton(t){const e=this.editor;e.ui.componentFactory.add(`alignment:${t}`,(n=>{const i=e.commands.get("alignment"),o=new u.ButtonView(n);return o.set({label:this.localizedOptionTitles[t],icon:m.get(t),tooltip:!0,isToggleable:!0}),o.bind("isEnabled").to(i),o.bind("isOn").to(i,"value",(e=>e===t)),this.listenTo(o,"execute",(()=>{e.execute("alignment",{value:t}),e.editing.view.focus()})),o}))}}class f extends t.Plugin{static get requires(){return[g,d]}static get pluginName(){return"Alignment"}}})(),(window.CKEditor5=window.CKEditor5||{}).alignment=i})();
@@ -1 +1 @@
1
- !function(n){const i=n.ug=n.ug||{};i.dictionary=Object.assign(i.dictionary||{},{"Align center":"ئوتتۇرىغا توغرىلاش","Align left":"سولغا توغرىلاش","Align right":"ئوڭغا توغرىلاش",Justify:"تەكشىلەش","Text alignment":"تېكىست توغرىلاش","Text alignment toolbar":"تېكىست توغرىلاش قورالبالدىقى"})}(window.CKEDITOR_TRANSLATIONS||(window.CKEDITOR_TRANSLATIONS={}));
1
+ !function(n){const i=n.ug=n.ug||{};i.dictionary=Object.assign(i.dictionary||{},{"Align center":"ئوتتۇرىغا توغرىلاش","Align left":"سولغا توغرىلاش","Align right":"ئوڭغا توغرىلاش",Justify:"ئوڭ سولدىن توغرىلا","Text alignment":"تېكىست توغرىلاش","Text alignment toolbar":"تېكىست توغرىلاش قورالبالدىقى"})}(window.CKEDITOR_TRANSLATIONS||(window.CKEDITOR_TRANSLATIONS={}));
@@ -30,7 +30,7 @@ msgstr "ئوتتۇرىغا توغرىلاش"
30
30
 
31
31
  msgctxt "Toolbar button tooltip for making the text justified."
32
32
  msgid "Justify"
33
- msgstr "تەكشىلەش"
33
+ msgstr "ئوڭ سولدىن توغرىلا"
34
34
 
35
35
  msgctxt "Dropdown button tooltip for the text alignment feature."
36
36
  msgid "Text alignment"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-alignment",
3
- "version": "35.3.2",
3
+ "version": "36.0.0",
4
4
  "description": "Text alignment feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,21 +12,22 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^35.3.2"
15
+ "ckeditor5": "^36.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-block-quote": "^35.3.2",
19
- "@ckeditor/ckeditor5-core": "^35.3.2",
20
- "@ckeditor/ckeditor5-dev-utils": "^31.0.0",
21
- "@ckeditor/ckeditor5-editor-classic": "^35.3.2",
22
- "@ckeditor/ckeditor5-engine": "^35.3.2",
23
- "@ckeditor/ckeditor5-enter": "^35.3.2",
24
- "@ckeditor/ckeditor5-heading": "^35.3.2",
25
- "@ckeditor/ckeditor5-image": "^35.3.2",
26
- "@ckeditor/ckeditor5-list": "^35.3.2",
27
- "@ckeditor/ckeditor5-paragraph": "^35.3.2",
28
- "@ckeditor/ckeditor5-theme-lark": "^35.3.2",
29
- "@ckeditor/ckeditor5-typing": "^35.3.2",
18
+ "@ckeditor/ckeditor5-block-quote": "^36.0.0",
19
+ "@ckeditor/ckeditor5-core": "^36.0.0",
20
+ "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
21
+ "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
22
+ "@ckeditor/ckeditor5-engine": "^36.0.0",
23
+ "@ckeditor/ckeditor5-enter": "^36.0.0",
24
+ "@ckeditor/ckeditor5-heading": "^36.0.0",
25
+ "@ckeditor/ckeditor5-image": "^36.0.0",
26
+ "@ckeditor/ckeditor5-list": "^36.0.0",
27
+ "@ckeditor/ckeditor5-paragraph": "^36.0.0",
28
+ "@ckeditor/ckeditor5-theme-lark": "^36.0.0",
29
+ "@ckeditor/ckeditor5-typing": "^36.0.0",
30
+ "typescript": "^4.8.4",
30
31
  "webpack": "^5.58.1",
31
32
  "webpack-cli": "^4.9.0"
32
33
  },
@@ -45,13 +46,16 @@
45
46
  },
46
47
  "files": [
47
48
  "lang",
48
- "src",
49
+ "src/**/*.js",
50
+ "src/**/*.d.ts",
49
51
  "theme",
50
52
  "build",
51
53
  "ckeditor5-metadata.json",
52
54
  "CHANGELOG.md"
53
55
  ],
54
56
  "scripts": {
55
- "dll:build": "webpack"
57
+ "dll:build": "webpack",
58
+ "build": "tsc -p ./tsconfig.release.json",
59
+ "postversion": "npm run build"
56
60
  }
57
61
  }
package/src/alignment.js CHANGED
@@ -1,17 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module alignment/alignment
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import AlignmentEditing from './alignmentediting';
13
10
  import AlignmentUI from './alignmentui';
14
-
15
11
  /**
16
12
  * The text alignment plugin.
17
13
  *
@@ -20,86 +16,18 @@ import AlignmentUI from './alignmentui';
20
16
  *
21
17
  * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
22
18
  * {@link module:alignment/alignmentui~AlignmentUI} plugins.
23
- *
24
- * @extends module:core/plugin~Plugin
25
19
  */
26
20
  export default class Alignment extends Plugin {
27
- /**
28
- * @inheritDoc
29
- */
30
- static get requires() {
31
- return [ AlignmentEditing, AlignmentUI ];
32
- }
33
-
34
- /**
35
- * @inheritDoc
36
- */
37
- static get pluginName() {
38
- return 'Alignment';
39
- }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires() {
25
+ return [AlignmentEditing, AlignmentUI];
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get pluginName() {
31
+ return 'Alignment';
32
+ }
40
33
  }
41
-
42
- /**
43
- * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
44
- *
45
- * Read more in {@link module:alignment/alignment~AlignmentConfig}.
46
- *
47
- * @member {module:alignment/alignment~AlignmentConfig} module:core/editor/editorconfig~EditorConfig#alignment
48
- */
49
-
50
- /**
51
- * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
52
- *
53
- * ClassicEditor
54
- * .create( editorElement, {
55
- * alignment: {
56
- * options: [ 'left', 'right' ]
57
- * }
58
- * } )
59
- * .then( ... )
60
- * .catch( ... );
61
- *
62
- * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
63
- *
64
- * @interface AlignmentConfig
65
- */
66
-
67
- /**
68
- * Available alignment options.
69
- *
70
- * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`. Other values are ignored.
71
- *
72
- * **Note:** It is recommended to always use `'left'` or `'right'` as these are default values which the user should
73
- * normally be able to choose depending on the
74
- * {@glink features/ui-language#setting-the-language-of-the-content language of the editor content}.
75
- *
76
- * ClassicEditor
77
- * .create( editorElement, {
78
- * alignment: {
79
- * options: [ 'left', 'right' ]
80
- * }
81
- * } )
82
- * .then( ... )
83
- * .catch( ... );
84
- *
85
- * By default the alignment is set inline using the `text-align` CSS property. To further customize the alignment,
86
- * you can provide names of classes for each alignment option using the `className` property.
87
- *
88
- * **Note:** Once you define the `className` property for one option, you need to specify it for all other options.
89
- *
90
- * ClassicEditor
91
- * .create( editorElement, {
92
- * alignment: {
93
- * options: [
94
- * { name: 'left', className: 'my-align-left' },
95
- * { name: 'right', className: 'my-align-right' }
96
- * ]
97
- * }
98
- * } )
99
- * .then( ... )
100
- * .catch( ... );
101
- *
102
- * See the demo of {@glink features/text-alignment#configuring-alignment-options custom alignment options}.
103
- *
104
- * @member {Array.<String|module:alignment/alignmentediting~AlignmentFormat>} module:alignment/alignment~AlignmentConfig#options
105
- */
@@ -1,110 +1,88 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module alignment/alignmentcommand
8
7
  */
9
-
10
8
  import { Command } from 'ckeditor5/src/core';
11
9
  import { first } from 'ckeditor5/src/utils';
12
-
13
10
  import { isDefault } from './utils';
14
-
15
11
  const ALIGNMENT = 'alignment';
16
-
17
12
  /**
18
13
  * The alignment command plugin.
19
- *
20
- * @extends module:core/command~Command
21
14
  */
22
15
  export default class AlignmentCommand extends Command {
23
- /**
24
- * @inheritDoc
25
- */
26
- refresh() {
27
- const editor = this.editor;
28
- const locale = editor.locale;
29
- const firstBlock = first( this.editor.model.document.selection.getSelectedBlocks() );
30
-
31
- // As first check whether to enable or disable the command as the value will always be false if the command cannot be enabled.
32
- this.isEnabled = !!firstBlock && this._canBeAligned( firstBlock );
33
-
34
- /**
35
- * A value of the current block's alignment.
36
- *
37
- * @observable
38
- * @readonly
39
- * @member {String} #value
40
- */
41
- if ( this.isEnabled && firstBlock.hasAttribute( 'alignment' ) ) {
42
- this.value = firstBlock.getAttribute( 'alignment' );
43
- } else {
44
- this.value = locale.contentLanguageDirection === 'rtl' ? 'right' : 'left';
45
- }
46
- }
47
-
48
- /**
49
- * Executes the command. Applies the alignment `value` to the selected blocks.
50
- * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
51
- * the command will remove the attribute from the selected blocks.
52
- *
53
- * @param {Object} [options] Options for the executed command.
54
- * @param {String} [options.value] The value to apply.
55
- * @fires execute
56
- */
57
- execute( options = {} ) {
58
- const editor = this.editor;
59
- const locale = editor.locale;
60
- const model = editor.model;
61
- const doc = model.document;
62
-
63
- const value = options.value;
64
-
65
- model.change( writer => {
66
- // Get only those blocks from selected that can have alignment set
67
- const blocks = Array.from( doc.selection.getSelectedBlocks() ).filter( block => this._canBeAligned( block ) );
68
- const currentAlignment = blocks[ 0 ].getAttribute( 'alignment' );
69
-
70
- // Remove alignment attribute if current alignment is:
71
- // - default (should not be stored in model as it will bloat model data)
72
- // - equal to currently set
73
- // - or no value is passed - denotes default alignment.
74
- const removeAlignment = isDefault( value, locale ) || currentAlignment === value || !value;
75
-
76
- if ( removeAlignment ) {
77
- removeAlignmentFromSelection( blocks, writer );
78
- } else {
79
- setAlignmentOnSelection( blocks, writer, value );
80
- }
81
- } );
82
- }
83
-
84
- /**
85
- * Checks whether a block can have alignment set.
86
- *
87
- * @private
88
- * @param {module:engine/model/element~Element} block The block to be checked.
89
- * @returns {Boolean}
90
- */
91
- _canBeAligned( block ) {
92
- return this.editor.model.schema.checkAttribute( block, ALIGNMENT );
93
- }
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ refresh() {
20
+ const editor = this.editor;
21
+ const locale = editor.locale;
22
+ const firstBlock = first(this.editor.model.document.selection.getSelectedBlocks());
23
+ // As first check whether to enable or disable the command as the value will always be false if the command cannot be enabled.
24
+ this.isEnabled = Boolean(firstBlock) && this._canBeAligned(firstBlock);
25
+ if (this.isEnabled && firstBlock.hasAttribute('alignment')) {
26
+ this.value = firstBlock.getAttribute('alignment');
27
+ }
28
+ else {
29
+ this.value = locale.contentLanguageDirection === 'rtl' ? 'right' : 'left';
30
+ }
31
+ }
32
+ /**
33
+ * Executes the command. Applies the alignment `value` to the selected blocks.
34
+ * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
35
+ * the command will remove the attribute from the selected blocks.
36
+ *
37
+ * @param options Options for the executed command.
38
+ * @param options.value The value to apply.
39
+ * @fires execute
40
+ */
41
+ execute(options = {}) {
42
+ const editor = this.editor;
43
+ const locale = editor.locale;
44
+ const model = editor.model;
45
+ const doc = model.document;
46
+ const value = options.value;
47
+ model.change(writer => {
48
+ // Get only those blocks from selected that can have alignment set
49
+ const blocks = Array.from(doc.selection.getSelectedBlocks()).filter(block => this._canBeAligned(block));
50
+ const currentAlignment = blocks[0].getAttribute('alignment');
51
+ // Remove alignment attribute if current alignment is:
52
+ // - default (should not be stored in model as it will bloat model data)
53
+ // - equal to currently set
54
+ // - or no value is passed - denotes default alignment.
55
+ const removeAlignment = isDefault(value, locale) || currentAlignment === value || !value;
56
+ if (removeAlignment) {
57
+ removeAlignmentFromSelection(blocks, writer);
58
+ }
59
+ else {
60
+ setAlignmentOnSelection(blocks, writer, value);
61
+ }
62
+ });
63
+ }
64
+ /**
65
+ * Checks whether a block can have alignment set.
66
+ *
67
+ * @param block The block to be checked.
68
+ */
69
+ _canBeAligned(block) {
70
+ return this.editor.model.schema.checkAttribute(block, ALIGNMENT);
71
+ }
94
72
  }
95
-
96
- // Removes the alignment attribute from blocks.
97
- // @private
98
- function removeAlignmentFromSelection( blocks, writer ) {
99
- for ( const block of blocks ) {
100
- writer.removeAttribute( ALIGNMENT, block );
101
- }
73
+ /**
74
+ * Removes the alignment attribute from blocks.
75
+ */
76
+ function removeAlignmentFromSelection(blocks, writer) {
77
+ for (const block of blocks) {
78
+ writer.removeAttribute(ALIGNMENT, block);
79
+ }
102
80
  }
103
-
104
- // Sets the alignment attribute on blocks.
105
- // @private
106
- function setAlignmentOnSelection( blocks, writer, alignment ) {
107
- for ( const block of blocks ) {
108
- writer.setAttribute( ALIGNMENT, alignment, block );
109
- }
81
+ /**
82
+ * Sets the alignment attribute on blocks.
83
+ */
84
+ function setAlignmentOnSelection(blocks, writer, alignment) {
85
+ for (const block of blocks) {
86
+ writer.setAttribute(ALIGNMENT, alignment, block);
87
+ }
110
88
  }