@ckeditor/ckeditor5-alignment 40.0.0 → 40.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.
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor&nbsp;5 text alignment feature** – https://github.com/ckeditor/ckeditor5-alignment <br>
5
- Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 20032023, [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
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-alignment",
3
- "version": "40.0.0",
3
+ "version": "40.1.0",
4
4
  "description": "Text alignment feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "40.0.0"
15
+ "ckeditor5": "40.1.0"
16
16
  },
17
17
  "author": "CKSource (http://cksource.com/)",
18
18
  "license": "GPL-2.0-or-later",
@@ -1,29 +1,29 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignment
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import AlignmentEditing from './alignmentediting';
10
- import AlignmentUI from './alignmentui';
11
- /**
12
- * The text alignment plugin.
13
- *
14
- * For a detailed overview, check the {@glink features/text-alignment Text alignment} feature guide
15
- * and the {@glink api/alignment package page}.
16
- *
17
- * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
18
- * {@link module:alignment/alignmentui~AlignmentUI} plugins.
19
- */
20
- export default class Alignment extends Plugin {
21
- /**
22
- * @inheritDoc
23
- */
24
- static get requires(): readonly [typeof AlignmentEditing, typeof AlignmentUI];
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName(): "Alignment";
29
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignment
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import AlignmentEditing from './alignmentediting';
10
+ import AlignmentUI from './alignmentui';
11
+ /**
12
+ * The text alignment plugin.
13
+ *
14
+ * For a detailed overview, check the {@glink features/text-alignment Text alignment} feature guide
15
+ * and the {@glink api/alignment package page}.
16
+ *
17
+ * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
18
+ * {@link module:alignment/alignmentui~AlignmentUI} plugins.
19
+ */
20
+ export default class Alignment extends Plugin {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get requires(): readonly [typeof AlignmentEditing, typeof AlignmentUI];
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get pluginName(): "Alignment";
29
+ }
package/src/alignment.js CHANGED
@@ -1,33 +1,33 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignment
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import AlignmentEditing from './alignmentediting';
10
- import AlignmentUI from './alignmentui';
11
- /**
12
- * The text alignment plugin.
13
- *
14
- * For a detailed overview, check the {@glink features/text-alignment Text alignment} feature guide
15
- * and the {@glink api/alignment package page}.
16
- *
17
- * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
18
- * {@link module:alignment/alignmentui~AlignmentUI} plugins.
19
- */
20
- export default class Alignment extends Plugin {
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
- }
33
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignment
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import AlignmentEditing from './alignmentediting';
10
+ import AlignmentUI from './alignmentui';
11
+ /**
12
+ * The text alignment plugin.
13
+ *
14
+ * For a detailed overview, check the {@glink features/text-alignment Text alignment} feature guide
15
+ * and the {@glink api/alignment package page}.
16
+ *
17
+ * This is a "glue" plugin which loads the {@link module:alignment/alignmentediting~AlignmentEditing} and
18
+ * {@link module:alignment/alignmentui~AlignmentUI} plugins.
19
+ */
20
+ export default class Alignment extends Plugin {
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
+ }
33
+ }
@@ -1,43 +1,43 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignmentcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- import type { SupportedOption } from './alignmentconfig';
10
- /**
11
- * The alignment command plugin.
12
- */
13
- export default class AlignmentCommand extends Command {
14
- /**
15
- * A value of the current block's alignment.
16
- *
17
- * @observable
18
- * @readonly
19
- */
20
- value: SupportedOption;
21
- /**
22
- * @inheritDoc
23
- */
24
- refresh(): void;
25
- /**
26
- * Executes the command. Applies the alignment `value` to the selected blocks.
27
- * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
28
- * the command will remove the attribute from the selected blocks.
29
- *
30
- * @param options Options for the executed command.
31
- * @param options.value The value to apply.
32
- * @fires execute
33
- */
34
- execute(options?: {
35
- value?: SupportedOption;
36
- }): void;
37
- /**
38
- * Checks whether a block can have alignment set.
39
- *
40
- * @param block The block to be checked.
41
- */
42
- private _canBeAligned;
43
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignmentcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ import type { SupportedOption } from './alignmentconfig';
10
+ /**
11
+ * The alignment command plugin.
12
+ */
13
+ export default class AlignmentCommand extends Command {
14
+ /**
15
+ * A value of the current block's alignment.
16
+ *
17
+ * @observable
18
+ * @readonly
19
+ */
20
+ value: SupportedOption;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ refresh(): void;
25
+ /**
26
+ * Executes the command. Applies the alignment `value` to the selected blocks.
27
+ * If no `value` is passed, the `value` is the default one or it is equal to the currently selected block's alignment attribute,
28
+ * the command will remove the attribute from the selected blocks.
29
+ *
30
+ * @param options Options for the executed command.
31
+ * @param options.value The value to apply.
32
+ * @fires execute
33
+ */
34
+ execute(options?: {
35
+ value?: SupportedOption;
36
+ }): void;
37
+ /**
38
+ * Checks whether a block can have alignment set.
39
+ *
40
+ * @param block The block to be checked.
41
+ */
42
+ private _canBeAligned;
43
+ }
@@ -1,88 +1,88 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignmentcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- import { first } from 'ckeditor5/src/utils';
10
- import { isDefault } from './utils';
11
- const ALIGNMENT = 'alignment';
12
- /**
13
- * The alignment command plugin.
14
- */
15
- export default class AlignmentCommand extends Command {
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
- }
72
- }
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
- }
80
- }
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
- }
88
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignmentcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ import { first } from 'ckeditor5/src/utils';
10
+ import { isDefault } from './utils';
11
+ const ALIGNMENT = 'alignment';
12
+ /**
13
+ * The alignment command plugin.
14
+ */
15
+ export default class AlignmentCommand extends Command {
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
+ }
72
+ }
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
+ }
80
+ }
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
+ }
88
+ }
@@ -1,72 +1,72 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignmentconfig
7
- */
8
- /**
9
- * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
10
- *
11
- * ```ts
12
- * ClassicEditor
13
- * .create( editorElement, {
14
- * alignment: {
15
- * options: [ 'left', 'right' ]
16
- * }
17
- * } )
18
- * .then( ... )
19
- * .catch( ... );
20
- * ```
21
- *
22
- * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
23
- */
24
- export interface AlignmentConfig {
25
- options?: Array<SupportedOption | AlignmentFormat>;
26
- }
27
- /**
28
- * Available alignment options.
29
- *
30
- * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`. Other values are ignored.
31
- *
32
- * **Note:** It is recommended to always use `'left'` or `'right'` as these are default values which the user should
33
- * normally be able to choose depending on the
34
- * {@glink features/ui-language#setting-the-language-of-the-content language of the editor content}.
35
- *
36
- * ```ts
37
- * ClassicEditor
38
- * .create( editorElement, {
39
- * alignment: {
40
- * options: [ 'left', 'right' ]
41
- * }
42
- * } )
43
- * .then( ... )
44
- * .catch( ... );
45
- * ```
46
- *
47
- * By default the alignment is set inline using the `text-align` CSS property. To further customize the alignment,
48
- * you can provide names of classes for each alignment option using the `className` property.
49
- *
50
- * **Note:** Once you define the `className` property for one option, you need to specify it for all other options.
51
- *
52
- * ```ts
53
- * ClassicEditor
54
- * .create( editorElement, {
55
- * alignment: {
56
- * options: [
57
- * { name: 'left', className: 'my-align-left' },
58
- * { name: 'right', className: 'my-align-right' }
59
- * ]
60
- * }
61
- * } )
62
- * .then( ... )
63
- * .catch( ... );
64
- * ```
65
- *
66
- * See the demo of {@glink features/text-alignment#configuring-alignment-options custom alignment options}.
67
- */
68
- export type AlignmentFormat = {
69
- name: SupportedOption;
70
- className?: string;
71
- };
72
- export type SupportedOption = 'left' | 'right' | 'center' | 'justify';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignmentconfig
7
+ */
8
+ /**
9
+ * The configuration of the {@link module:alignment/alignment~Alignment alignment feature}.
10
+ *
11
+ * ```ts
12
+ * ClassicEditor
13
+ * .create( editorElement, {
14
+ * alignment: {
15
+ * options: [ 'left', 'right' ]
16
+ * }
17
+ * } )
18
+ * .then( ... )
19
+ * .catch( ... );
20
+ * ```
21
+ *
22
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
23
+ */
24
+ export interface AlignmentConfig {
25
+ options?: Array<SupportedOption | AlignmentFormat>;
26
+ }
27
+ /**
28
+ * Available alignment options.
29
+ *
30
+ * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`. Other values are ignored.
31
+ *
32
+ * **Note:** It is recommended to always use `'left'` or `'right'` as these are default values which the user should
33
+ * normally be able to choose depending on the
34
+ * {@glink features/ui-language#setting-the-language-of-the-content language of the editor content}.
35
+ *
36
+ * ```ts
37
+ * ClassicEditor
38
+ * .create( editorElement, {
39
+ * alignment: {
40
+ * options: [ 'left', 'right' ]
41
+ * }
42
+ * } )
43
+ * .then( ... )
44
+ * .catch( ... );
45
+ * ```
46
+ *
47
+ * By default the alignment is set inline using the `text-align` CSS property. To further customize the alignment,
48
+ * you can provide names of classes for each alignment option using the `className` property.
49
+ *
50
+ * **Note:** Once you define the `className` property for one option, you need to specify it for all other options.
51
+ *
52
+ * ```ts
53
+ * ClassicEditor
54
+ * .create( editorElement, {
55
+ * alignment: {
56
+ * options: [
57
+ * { name: 'left', className: 'my-align-left' },
58
+ * { name: 'right', className: 'my-align-right' }
59
+ * ]
60
+ * }
61
+ * } )
62
+ * .then( ... )
63
+ * .catch( ... );
64
+ * ```
65
+ *
66
+ * See the demo of {@glink features/text-alignment#configuring-alignment-options custom alignment options}.
67
+ */
68
+ export type AlignmentFormat = {
69
+ name: SupportedOption;
70
+ className?: string;
71
+ };
72
+ export type SupportedOption = 'left' | 'right' | 'center' | 'justify';
@@ -1,5 +1,5 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ export {};
@@ -1,26 +1,26 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module alignment/alignmentediting
7
- */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- /**
10
- * The alignment editing feature. It introduces the {@link module:alignment/alignmentcommand~AlignmentCommand command} and adds
11
- * the `alignment` attribute for block elements in the {@link module:engine/model/model~Model model}.
12
- */
13
- export default class AlignmentEditing extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get pluginName(): "AlignmentEditing";
18
- /**
19
- * @inheritDoc
20
- */
21
- constructor(editor: Editor);
22
- /**
23
- * @inheritDoc
24
- */
25
- init(): void;
26
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module alignment/alignmentediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The alignment editing feature. It introduces the {@link module:alignment/alignmentcommand~AlignmentCommand command} and adds
11
+ * the `alignment` attribute for block elements in the {@link module:engine/model/model~Model model}.
12
+ */
13
+ export default class AlignmentEditing extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "AlignmentEditing";
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ constructor(editor: Editor);
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ init(): void;
26
+ }