UNPKG

2.05 kBJavaScriptView Raw
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 */
8import { 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 */
14export 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}