@ckeditor/ckeditor5-alignment 39.0.2 → 40.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/src/utils.js CHANGED
@@ -1,118 +1,118 @@
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
- import { CKEditorError, logWarning } from 'ckeditor5/src/utils';
6
- /**
7
- * @module alignment/utils
8
- */
9
- /**
10
- * The list of supported alignment options:
11
- *
12
- * * `'left'`,
13
- * * `'right'`,
14
- * * `'center'`,
15
- * * `'justify'`
16
- */
17
- export const supportedOptions = ['left', 'right', 'center', 'justify'];
18
- /**
19
- * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
20
- *
21
- * @param option The option value to check.
22
- */
23
- export function isSupported(option) {
24
- return supportedOptions.includes(option);
25
- }
26
- /**
27
- * Checks whether alignment is the default one considering the direction
28
- * of the editor content.
29
- *
30
- * @param alignment The name of the alignment to check.
31
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
32
- */
33
- export function isDefault(alignment, locale) {
34
- // Right now only LTR is supported so the 'left' value is always the default one.
35
- if (locale.contentLanguageDirection == 'rtl') {
36
- return alignment === 'right';
37
- }
38
- else {
39
- return alignment === 'left';
40
- }
41
- }
42
- /**
43
- * Brings the configuration to the common form, an array of objects.
44
- *
45
- * @param configuredOptions Alignment plugin configuration.
46
- * @returns Normalized object holding the configuration.
47
- */
48
- export function normalizeAlignmentOptions(configuredOptions) {
49
- const normalizedOptions = configuredOptions
50
- .map(option => {
51
- let result;
52
- if (typeof option == 'string') {
53
- result = { name: option };
54
- }
55
- else {
56
- result = option;
57
- }
58
- return result;
59
- })
60
- // Remove all unknown options.
61
- .filter(option => {
62
- const isNameValid = supportedOptions.includes(option.name);
63
- if (!isNameValid) {
64
- /**
65
- * The `name` in one of the `alignment.options` is not recognized.
66
- * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`.
67
- *
68
- * @error alignment-config-name-not-recognized
69
- * @param option Options with unknown value of the `name` property.
70
- */
71
- logWarning('alignment-config-name-not-recognized', { option });
72
- }
73
- return isNameValid;
74
- });
75
- const classNameCount = normalizedOptions.filter(option => Boolean(option.className)).length;
76
- // We either use classes for all styling options or for none.
77
- if (classNameCount && classNameCount < normalizedOptions.length) {
78
- /**
79
- * The `className` property has to be defined for all options once at least one option declares `className`.
80
- *
81
- * @error alignment-config-classnames-are-missing
82
- * @param configuredOptions Contents of `alignment.options`.
83
- */
84
- throw new CKEditorError('alignment-config-classnames-are-missing', { configuredOptions });
85
- }
86
- // Validate resulting config.
87
- normalizedOptions.forEach((option, index, allOptions) => {
88
- const succeedingOptions = allOptions.slice(index + 1);
89
- const nameAlreadyExists = succeedingOptions.some(item => item.name == option.name);
90
- if (nameAlreadyExists) {
91
- /**
92
- * The same `name` in one of the `alignment.options` was already declared.
93
- * Each `name` representing one alignment option can be set exactly once.
94
- *
95
- * @error alignment-config-name-already-defined
96
- * @param option First option that declares given `name`.
97
- * @param configuredOptions Contents of `alignment.options`.
98
- */
99
- throw new CKEditorError('alignment-config-name-already-defined', { option, configuredOptions });
100
- }
101
- // The `className` property is present. Check for duplicates then.
102
- if (option.className) {
103
- const classNameAlreadyExists = succeedingOptions.some(item => item.className == option.className);
104
- if (classNameAlreadyExists) {
105
- /**
106
- * The same `className` in one of the `alignment.options` was already declared.
107
- *
108
- * @error alignment-config-classname-already-defined
109
- * @param option First option that declares given `className`.
110
- * @param configuredOptions
111
- * Contents of `alignment.options`.
112
- */
113
- throw new CKEditorError('alignment-config-classname-already-defined', { option, configuredOptions });
114
- }
115
- }
116
- });
117
- return normalizedOptions;
118
- }
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
+ import { CKEditorError, logWarning } from 'ckeditor5/src/utils';
6
+ /**
7
+ * @module alignment/utils
8
+ */
9
+ /**
10
+ * The list of supported alignment options:
11
+ *
12
+ * * `'left'`,
13
+ * * `'right'`,
14
+ * * `'center'`,
15
+ * * `'justify'`
16
+ */
17
+ export const supportedOptions = ['left', 'right', 'center', 'justify'];
18
+ /**
19
+ * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
20
+ *
21
+ * @param option The option value to check.
22
+ */
23
+ export function isSupported(option) {
24
+ return supportedOptions.includes(option);
25
+ }
26
+ /**
27
+ * Checks whether alignment is the default one considering the direction
28
+ * of the editor content.
29
+ *
30
+ * @param alignment The name of the alignment to check.
31
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
32
+ */
33
+ export function isDefault(alignment, locale) {
34
+ // Right now only LTR is supported so the 'left' value is always the default one.
35
+ if (locale.contentLanguageDirection == 'rtl') {
36
+ return alignment === 'right';
37
+ }
38
+ else {
39
+ return alignment === 'left';
40
+ }
41
+ }
42
+ /**
43
+ * Brings the configuration to the common form, an array of objects.
44
+ *
45
+ * @param configuredOptions Alignment plugin configuration.
46
+ * @returns Normalized object holding the configuration.
47
+ */
48
+ export function normalizeAlignmentOptions(configuredOptions) {
49
+ const normalizedOptions = configuredOptions
50
+ .map(option => {
51
+ let result;
52
+ if (typeof option == 'string') {
53
+ result = { name: option };
54
+ }
55
+ else {
56
+ result = option;
57
+ }
58
+ return result;
59
+ })
60
+ // Remove all unknown options.
61
+ .filter(option => {
62
+ const isNameValid = supportedOptions.includes(option.name);
63
+ if (!isNameValid) {
64
+ /**
65
+ * The `name` in one of the `alignment.options` is not recognized.
66
+ * The available options are: `'left'`, `'right'`, `'center'` and `'justify'`.
67
+ *
68
+ * @error alignment-config-name-not-recognized
69
+ * @param option Options with unknown value of the `name` property.
70
+ */
71
+ logWarning('alignment-config-name-not-recognized', { option });
72
+ }
73
+ return isNameValid;
74
+ });
75
+ const classNameCount = normalizedOptions.filter(option => Boolean(option.className)).length;
76
+ // We either use classes for all styling options or for none.
77
+ if (classNameCount && classNameCount < normalizedOptions.length) {
78
+ /**
79
+ * The `className` property has to be defined for all options once at least one option declares `className`.
80
+ *
81
+ * @error alignment-config-classnames-are-missing
82
+ * @param configuredOptions Contents of `alignment.options`.
83
+ */
84
+ throw new CKEditorError('alignment-config-classnames-are-missing', { configuredOptions });
85
+ }
86
+ // Validate resulting config.
87
+ normalizedOptions.forEach((option, index, allOptions) => {
88
+ const succeedingOptions = allOptions.slice(index + 1);
89
+ const nameAlreadyExists = succeedingOptions.some(item => item.name == option.name);
90
+ if (nameAlreadyExists) {
91
+ /**
92
+ * The same `name` in one of the `alignment.options` was already declared.
93
+ * Each `name` representing one alignment option can be set exactly once.
94
+ *
95
+ * @error alignment-config-name-already-defined
96
+ * @param option First option that declares given `name`.
97
+ * @param configuredOptions Contents of `alignment.options`.
98
+ */
99
+ throw new CKEditorError('alignment-config-name-already-defined', { option, configuredOptions });
100
+ }
101
+ // The `className` property is present. Check for duplicates then.
102
+ if (option.className) {
103
+ const classNameAlreadyExists = succeedingOptions.some(item => item.className == option.className);
104
+ if (classNameAlreadyExists) {
105
+ /**
106
+ * The same `className` in one of the `alignment.options` was already declared.
107
+ *
108
+ * @error alignment-config-classname-already-defined
109
+ * @param option First option that declares given `className`.
110
+ * @param configuredOptions
111
+ * Contents of `alignment.options`.
112
+ */
113
+ throw new CKEditorError('alignment-config-classname-already-defined', { option, configuredOptions });
114
+ }
115
+ }
116
+ });
117
+ return normalizedOptions;
118
+ }