@ckeditor/ckeditor5-link 38.1.0 → 38.1.1

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.
@@ -1,45 +1,45 @@
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 link/utils/automaticdecorators
7
- */
8
- import { type ArrayOrItem } from 'ckeditor5/src/utils';
9
- import type { DowncastDispatcher } from 'ckeditor5/src/engine';
10
- import type { NormalizedLinkDecoratorAutomaticDefinition } from '../utils';
11
- /**
12
- * Helper class that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition} and provides
13
- * the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement downcast dispatchers} for them.
14
- */
15
- export default class AutomaticDecorators {
16
- /**
17
- * Stores the definition of {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}.
18
- * This data is used as a source for a downcast dispatcher to create a proper conversion to output data.
19
- */
20
- private _definitions;
21
- /**
22
- * Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~AutomaticDecorators}
23
- * instance.
24
- */
25
- get length(): number;
26
- /**
27
- * Adds automatic decorator objects or an array with them to be used during downcasting.
28
- *
29
- * @param item A configuration object of automatic rules for decorating links. It might also be an array of such objects.
30
- */
31
- add(item: ArrayOrItem<NormalizedLinkDecoratorAutomaticDefinition>): void;
32
- /**
33
- * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method.
34
- *
35
- * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
36
- */
37
- getDispatcher(): (dispatcher: DowncastDispatcher) => void;
38
- /**
39
- * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method
40
- * when linking images.
41
- *
42
- * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
43
- */
44
- getDispatcherForLinkedImage(): (dispatcher: DowncastDispatcher) => void;
45
- }
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 link/utils/automaticdecorators
7
+ */
8
+ import { type ArrayOrItem } from 'ckeditor5/src/utils';
9
+ import type { DowncastDispatcher } from 'ckeditor5/src/engine';
10
+ import type { NormalizedLinkDecoratorAutomaticDefinition } from '../utils';
11
+ /**
12
+ * Helper class that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition} and provides
13
+ * the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement downcast dispatchers} for them.
14
+ */
15
+ export default class AutomaticDecorators {
16
+ /**
17
+ * Stores the definition of {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}.
18
+ * This data is used as a source for a downcast dispatcher to create a proper conversion to output data.
19
+ */
20
+ private _definitions;
21
+ /**
22
+ * Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~AutomaticDecorators}
23
+ * instance.
24
+ */
25
+ get length(): number;
26
+ /**
27
+ * Adds automatic decorator objects or an array with them to be used during downcasting.
28
+ *
29
+ * @param item A configuration object of automatic rules for decorating links. It might also be an array of such objects.
30
+ */
31
+ add(item: ArrayOrItem<NormalizedLinkDecoratorAutomaticDefinition>): void;
32
+ /**
33
+ * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method.
34
+ *
35
+ * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
36
+ */
37
+ getDispatcher(): (dispatcher: DowncastDispatcher) => void;
38
+ /**
39
+ * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method
40
+ * when linking images.
41
+ *
42
+ * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
43
+ */
44
+ getDispatcherForLinkedImage(): (dispatcher: DowncastDispatcher) => void;
45
+ }
@@ -1,140 +1,140 @@
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 link/utils/automaticdecorators
7
- */
8
- import { toMap } from 'ckeditor5/src/utils';
9
- /**
10
- * Helper class that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition} and provides
11
- * the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement downcast dispatchers} for them.
12
- */
13
- export default class AutomaticDecorators {
14
- constructor() {
15
- /**
16
- * Stores the definition of {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}.
17
- * This data is used as a source for a downcast dispatcher to create a proper conversion to output data.
18
- */
19
- this._definitions = new Set();
20
- }
21
- /**
22
- * Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~AutomaticDecorators}
23
- * instance.
24
- */
25
- get length() {
26
- return this._definitions.size;
27
- }
28
- /**
29
- * Adds automatic decorator objects or an array with them to be used during downcasting.
30
- *
31
- * @param item A configuration object of automatic rules for decorating links. It might also be an array of such objects.
32
- */
33
- add(item) {
34
- if (Array.isArray(item)) {
35
- item.forEach(item => this._definitions.add(item));
36
- }
37
- else {
38
- this._definitions.add(item);
39
- }
40
- }
41
- /**
42
- * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method.
43
- *
44
- * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
45
- */
46
- getDispatcher() {
47
- return dispatcher => {
48
- dispatcher.on('attribute:linkHref', (evt, data, conversionApi) => {
49
- // There is only test as this behavior decorates links and
50
- // it is run before dispatcher which actually consumes this node.
51
- // This allows on writing own dispatcher with highest priority,
52
- // which blocks both native converter and this additional decoration.
53
- if (!conversionApi.consumable.test(data.item, 'attribute:linkHref')) {
54
- return;
55
- }
56
- // Automatic decorators for block links are handled e.g. in LinkImageEditing.
57
- if (!(data.item.is('selection') || conversionApi.schema.isInline(data.item))) {
58
- return;
59
- }
60
- const viewWriter = conversionApi.writer;
61
- const viewSelection = viewWriter.document.selection;
62
- for (const item of this._definitions) {
63
- const viewElement = viewWriter.createAttributeElement('a', item.attributes, {
64
- priority: 5
65
- });
66
- if (item.classes) {
67
- viewWriter.addClass(item.classes, viewElement);
68
- }
69
- for (const key in item.styles) {
70
- viewWriter.setStyle(key, item.styles[key], viewElement);
71
- }
72
- viewWriter.setCustomProperty('link', true, viewElement);
73
- if (item.callback(data.attributeNewValue)) {
74
- if (data.item.is('selection')) {
75
- viewWriter.wrap(viewSelection.getFirstRange(), viewElement);
76
- }
77
- else {
78
- viewWriter.wrap(conversionApi.mapper.toViewRange(data.range), viewElement);
79
- }
80
- }
81
- else {
82
- viewWriter.unwrap(conversionApi.mapper.toViewRange(data.range), viewElement);
83
- }
84
- }
85
- }, { priority: 'high' });
86
- };
87
- }
88
- /**
89
- * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method
90
- * when linking images.
91
- *
92
- * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
93
- */
94
- getDispatcherForLinkedImage() {
95
- return dispatcher => {
96
- dispatcher.on('attribute:linkHref:imageBlock', (evt, data, { writer, mapper }) => {
97
- const viewFigure = mapper.toViewElement(data.item);
98
- const linkInImage = Array.from(viewFigure.getChildren())
99
- .find((child) => child.is('element', 'a'));
100
- for (const item of this._definitions) {
101
- const attributes = toMap(item.attributes);
102
- if (item.callback(data.attributeNewValue)) {
103
- for (const [key, val] of attributes) {
104
- // Left for backward compatibility. Since v30 decorator should
105
- // accept `classes` and `styles` separately from `attributes`.
106
- if (key === 'class') {
107
- writer.addClass(val, linkInImage);
108
- }
109
- else {
110
- writer.setAttribute(key, val, linkInImage);
111
- }
112
- }
113
- if (item.classes) {
114
- writer.addClass(item.classes, linkInImage);
115
- }
116
- for (const key in item.styles) {
117
- writer.setStyle(key, item.styles[key], linkInImage);
118
- }
119
- }
120
- else {
121
- for (const [key, val] of attributes) {
122
- if (key === 'class') {
123
- writer.removeClass(val, linkInImage);
124
- }
125
- else {
126
- writer.removeAttribute(key, linkInImage);
127
- }
128
- }
129
- if (item.classes) {
130
- writer.removeClass(item.classes, linkInImage);
131
- }
132
- for (const key in item.styles) {
133
- writer.removeStyle(key, linkInImage);
134
- }
135
- }
136
- }
137
- });
138
- };
139
- }
140
- }
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 link/utils/automaticdecorators
7
+ */
8
+ import { toMap } from 'ckeditor5/src/utils';
9
+ /**
10
+ * Helper class that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition} and provides
11
+ * the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement downcast dispatchers} for them.
12
+ */
13
+ export default class AutomaticDecorators {
14
+ constructor() {
15
+ /**
16
+ * Stores the definition of {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}.
17
+ * This data is used as a source for a downcast dispatcher to create a proper conversion to output data.
18
+ */
19
+ this._definitions = new Set();
20
+ }
21
+ /**
22
+ * Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~AutomaticDecorators}
23
+ * instance.
24
+ */
25
+ get length() {
26
+ return this._definitions.size;
27
+ }
28
+ /**
29
+ * Adds automatic decorator objects or an array with them to be used during downcasting.
30
+ *
31
+ * @param item A configuration object of automatic rules for decorating links. It might also be an array of such objects.
32
+ */
33
+ add(item) {
34
+ if (Array.isArray(item)) {
35
+ item.forEach(item => this._definitions.add(item));
36
+ }
37
+ else {
38
+ this._definitions.add(item);
39
+ }
40
+ }
41
+ /**
42
+ * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method.
43
+ *
44
+ * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
45
+ */
46
+ getDispatcher() {
47
+ return dispatcher => {
48
+ dispatcher.on('attribute:linkHref', (evt, data, conversionApi) => {
49
+ // There is only test as this behavior decorates links and
50
+ // it is run before dispatcher which actually consumes this node.
51
+ // This allows on writing own dispatcher with highest priority,
52
+ // which blocks both native converter and this additional decoration.
53
+ if (!conversionApi.consumable.test(data.item, 'attribute:linkHref')) {
54
+ return;
55
+ }
56
+ // Automatic decorators for block links are handled e.g. in LinkImageEditing.
57
+ if (!(data.item.is('selection') || conversionApi.schema.isInline(data.item))) {
58
+ return;
59
+ }
60
+ const viewWriter = conversionApi.writer;
61
+ const viewSelection = viewWriter.document.selection;
62
+ for (const item of this._definitions) {
63
+ const viewElement = viewWriter.createAttributeElement('a', item.attributes, {
64
+ priority: 5
65
+ });
66
+ if (item.classes) {
67
+ viewWriter.addClass(item.classes, viewElement);
68
+ }
69
+ for (const key in item.styles) {
70
+ viewWriter.setStyle(key, item.styles[key], viewElement);
71
+ }
72
+ viewWriter.setCustomProperty('link', true, viewElement);
73
+ if (item.callback(data.attributeNewValue)) {
74
+ if (data.item.is('selection')) {
75
+ viewWriter.wrap(viewSelection.getFirstRange(), viewElement);
76
+ }
77
+ else {
78
+ viewWriter.wrap(conversionApi.mapper.toViewRange(data.range), viewElement);
79
+ }
80
+ }
81
+ else {
82
+ viewWriter.unwrap(conversionApi.mapper.toViewRange(data.range), viewElement);
83
+ }
84
+ }
85
+ }, { priority: 'high' });
86
+ };
87
+ }
88
+ /**
89
+ * Provides the conversion helper used in the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add} method
90
+ * when linking images.
91
+ *
92
+ * @returns A dispatcher function used as conversion helper in {@link module:engine/conversion/downcasthelpers~DowncastHelpers#add}.
93
+ */
94
+ getDispatcherForLinkedImage() {
95
+ return dispatcher => {
96
+ dispatcher.on('attribute:linkHref:imageBlock', (evt, data, { writer, mapper }) => {
97
+ const viewFigure = mapper.toViewElement(data.item);
98
+ const linkInImage = Array.from(viewFigure.getChildren())
99
+ .find((child) => child.is('element', 'a'));
100
+ for (const item of this._definitions) {
101
+ const attributes = toMap(item.attributes);
102
+ if (item.callback(data.attributeNewValue)) {
103
+ for (const [key, val] of attributes) {
104
+ // Left for backward compatibility. Since v30 decorator should
105
+ // accept `classes` and `styles` separately from `attributes`.
106
+ if (key === 'class') {
107
+ writer.addClass(val, linkInImage);
108
+ }
109
+ else {
110
+ writer.setAttribute(key, val, linkInImage);
111
+ }
112
+ }
113
+ if (item.classes) {
114
+ writer.addClass(item.classes, linkInImage);
115
+ }
116
+ for (const key in item.styles) {
117
+ writer.setStyle(key, item.styles[key], linkInImage);
118
+ }
119
+ }
120
+ else {
121
+ for (const [key, val] of attributes) {
122
+ if (key === 'class') {
123
+ writer.removeClass(val, linkInImage);
124
+ }
125
+ else {
126
+ writer.removeAttribute(key, linkInImage);
127
+ }
128
+ }
129
+ if (item.classes) {
130
+ writer.removeClass(item.classes, linkInImage);
131
+ }
132
+ for (const key in item.styles) {
133
+ writer.removeStyle(key, linkInImage);
134
+ }
135
+ }
136
+ }
137
+ });
138
+ };
139
+ }
140
+ }
@@ -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 link/utils/manualdecorator
7
- */
8
- import { type ArrayOrItem } from 'ckeditor5/src/utils';
9
- import type { MatcherObjectPattern } from 'ckeditor5/src/engine';
10
- import type { NormalizedLinkDecoratorManualDefinition } from '../utils';
11
- declare const ManualDecorator_base: {
12
- new (): import("ckeditor5/src/utils").Observable;
13
- prototype: import("ckeditor5/src/utils").Observable;
14
- };
15
- /**
16
- * Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~ManualDecorator#value}
17
- * to support integration with the UI state. An instance of this class is a model with the state of individual manual decorators.
18
- * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
19
- */
20
- export default class ManualDecorator extends ManualDecorator_base {
21
- /**
22
- * An ID of a manual decorator which is the name of the attribute in the model, for example: 'linkManualDecorator0'.
23
- */
24
- id: string;
25
- /**
26
- * The value of the current manual decorator. It reflects its state from the UI.
27
- *
28
- * @observable
29
- */
30
- value: boolean | undefined;
31
- /**
32
- * The default value of manual decorator.
33
- */
34
- defaultValue?: boolean;
35
- /**
36
- * The label used in the user interface to toggle the manual decorator.
37
- */
38
- label: string;
39
- /**
40
- * A set of attributes added to downcasted data when the decorator is activated for a specific link.
41
- * Attributes should be added in a form of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
42
- */
43
- attributes?: Record<string, string>;
44
- /**
45
- * A set of classes added to downcasted data when the decorator is activated for a specific link.
46
- * Classes should be added in a form of classes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
47
- */
48
- classes?: ArrayOrItem<string>;
49
- /**
50
- * A set of styles added to downcasted data when the decorator is activated for a specific link.
51
- * Styles should be added in a form of styles defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
52
- */
53
- styles?: Record<string, string>;
54
- /**
55
- * Creates a new instance of {@link module:link/utils/manualdecorator~ManualDecorator}.
56
- *
57
- * @param config.id The name of the attribute used in the model that represents a given manual decorator.
58
- * For example: `'linkIsExternal'`.
59
- * @param config.label The label used in the user interface to toggle the manual decorator.
60
- * @param config.attributes A set of attributes added to output data when the decorator is active for a specific link.
61
- * Attributes should keep the format of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
62
- * @param [config.defaultValue] Controls whether the decorator is "on" by default.
63
- */
64
- constructor({ id, label, attributes, classes, styles, defaultValue }: NormalizedLinkDecoratorManualDefinition);
65
- /**
66
- * Returns {@link module:engine/view/matcher~MatcherPattern} with decorator attributes.
67
- *
68
- * @internal
69
- */
70
- _createPattern(): MatcherObjectPattern;
71
- }
72
- 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
+ /**
6
+ * @module link/utils/manualdecorator
7
+ */
8
+ import { type ArrayOrItem } from 'ckeditor5/src/utils';
9
+ import type { MatcherObjectPattern } from 'ckeditor5/src/engine';
10
+ import type { NormalizedLinkDecoratorManualDefinition } from '../utils';
11
+ declare const ManualDecorator_base: {
12
+ new (): import("ckeditor5/src/utils").Observable;
13
+ prototype: import("ckeditor5/src/utils").Observable;
14
+ };
15
+ /**
16
+ * Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~ManualDecorator#value}
17
+ * to support integration with the UI state. An instance of this class is a model with the state of individual manual decorators.
18
+ * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
19
+ */
20
+ export default class ManualDecorator extends ManualDecorator_base {
21
+ /**
22
+ * An ID of a manual decorator which is the name of the attribute in the model, for example: 'linkManualDecorator0'.
23
+ */
24
+ id: string;
25
+ /**
26
+ * The value of the current manual decorator. It reflects its state from the UI.
27
+ *
28
+ * @observable
29
+ */
30
+ value: boolean | undefined;
31
+ /**
32
+ * The default value of manual decorator.
33
+ */
34
+ defaultValue?: boolean;
35
+ /**
36
+ * The label used in the user interface to toggle the manual decorator.
37
+ */
38
+ label: string;
39
+ /**
40
+ * A set of attributes added to downcasted data when the decorator is activated for a specific link.
41
+ * Attributes should be added in a form of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
42
+ */
43
+ attributes?: Record<string, string>;
44
+ /**
45
+ * A set of classes added to downcasted data when the decorator is activated for a specific link.
46
+ * Classes should be added in a form of classes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
47
+ */
48
+ classes?: ArrayOrItem<string>;
49
+ /**
50
+ * A set of styles added to downcasted data when the decorator is activated for a specific link.
51
+ * Styles should be added in a form of styles defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
52
+ */
53
+ styles?: Record<string, string>;
54
+ /**
55
+ * Creates a new instance of {@link module:link/utils/manualdecorator~ManualDecorator}.
56
+ *
57
+ * @param config.id The name of the attribute used in the model that represents a given manual decorator.
58
+ * For example: `'linkIsExternal'`.
59
+ * @param config.label The label used in the user interface to toggle the manual decorator.
60
+ * @param config.attributes A set of attributes added to output data when the decorator is active for a specific link.
61
+ * Attributes should keep the format of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
62
+ * @param [config.defaultValue] Controls whether the decorator is "on" by default.
63
+ */
64
+ constructor({ id, label, attributes, classes, styles, defaultValue }: NormalizedLinkDecoratorManualDefinition);
65
+ /**
66
+ * Returns {@link module:engine/view/matcher~MatcherPattern} with decorator attributes.
67
+ *
68
+ * @internal
69
+ */
70
+ _createPattern(): MatcherObjectPattern;
71
+ }
72
+ export {};
@@ -1,47 +1,47 @@
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 link/utils/manualdecorator
7
- */
8
- import { ObservableMixin } from 'ckeditor5/src/utils';
9
- /**
10
- * Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~ManualDecorator#value}
11
- * to support integration with the UI state. An instance of this class is a model with the state of individual manual decorators.
12
- * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
13
- */
14
- export default class ManualDecorator extends ObservableMixin() {
15
- /**
16
- * Creates a new instance of {@link module:link/utils/manualdecorator~ManualDecorator}.
17
- *
18
- * @param config.id The name of the attribute used in the model that represents a given manual decorator.
19
- * For example: `'linkIsExternal'`.
20
- * @param config.label The label used in the user interface to toggle the manual decorator.
21
- * @param config.attributes A set of attributes added to output data when the decorator is active for a specific link.
22
- * Attributes should keep the format of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
23
- * @param [config.defaultValue] Controls whether the decorator is "on" by default.
24
- */
25
- constructor({ id, label, attributes, classes, styles, defaultValue }) {
26
- super();
27
- this.id = id;
28
- this.set('value', undefined);
29
- this.defaultValue = defaultValue;
30
- this.label = label;
31
- this.attributes = attributes;
32
- this.classes = classes;
33
- this.styles = styles;
34
- }
35
- /**
36
- * Returns {@link module:engine/view/matcher~MatcherPattern} with decorator attributes.
37
- *
38
- * @internal
39
- */
40
- _createPattern() {
41
- return {
42
- attributes: this.attributes,
43
- classes: this.classes,
44
- styles: this.styles
45
- };
46
- }
47
- }
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 link/utils/manualdecorator
7
+ */
8
+ import { ObservableMixin } from 'ckeditor5/src/utils';
9
+ /**
10
+ * Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~ManualDecorator#value}
11
+ * to support integration with the UI state. An instance of this class is a model with the state of individual manual decorators.
12
+ * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
13
+ */
14
+ export default class ManualDecorator extends ObservableMixin() {
15
+ /**
16
+ * Creates a new instance of {@link module:link/utils/manualdecorator~ManualDecorator}.
17
+ *
18
+ * @param config.id The name of the attribute used in the model that represents a given manual decorator.
19
+ * For example: `'linkIsExternal'`.
20
+ * @param config.label The label used in the user interface to toggle the manual decorator.
21
+ * @param config.attributes A set of attributes added to output data when the decorator is active for a specific link.
22
+ * Attributes should keep the format of attributes defined in {@link module:engine/view/elementdefinition~ElementDefinition}.
23
+ * @param [config.defaultValue] Controls whether the decorator is "on" by default.
24
+ */
25
+ constructor({ id, label, attributes, classes, styles, defaultValue }) {
26
+ super();
27
+ this.id = id;
28
+ this.set('value', undefined);
29
+ this.defaultValue = defaultValue;
30
+ this.label = label;
31
+ this.attributes = attributes;
32
+ this.classes = classes;
33
+ this.styles = styles;
34
+ }
35
+ /**
36
+ * Returns {@link module:engine/view/matcher~MatcherPattern} with decorator attributes.
37
+ *
38
+ * @internal
39
+ */
40
+ _createPattern() {
41
+ return {
42
+ attributes: this.attributes,
43
+ classes: this.classes,
44
+ styles: this.styles
45
+ };
46
+ }
47
+ }