@ckeditor/ckeditor5-link 41.3.1 → 41.4.0-alpha.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/build/link.js +1 -1
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +44 -0
- package/dist/index.css +148 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +2422 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/ast.d.ts +8 -0
- package/dist/translations/ast.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/eo.d.ts +8 -0
- package/dist/translations/eo.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/eu.d.ts +8 -0
- package/dist/translations/eu.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hy.d.ts +8 -0
- package/dist/translations/hy.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/km.d.ts +8 -0
- package/dist/translations/km.js +5 -0
- package/dist/translations/kn.d.ts +8 -0
- package/dist/translations/kn.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tt.d.ts +8 -0
- package/dist/translations/tt.js +5 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +34 -0
- package/dist/types/autolink.d.ts +79 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/link.d.ts +31 -0
- package/dist/types/linkcommand.d.ts +136 -0
- package/dist/types/linkconfig.d.ts +294 -0
- package/dist/types/linkediting.d.ts +74 -0
- package/dist/types/linkimage.d.ts +31 -0
- package/dist/types/linkimageediting.d.ts +43 -0
- package/dist/types/linkimageui.d.ts +44 -0
- package/dist/types/linkui.d.ts +173 -0
- package/dist/types/ui/linkactionsview.d.ts +107 -0
- package/dist/types/ui/linkformview.d.ts +175 -0
- package/dist/types/unlinkcommand.d.ts +35 -0
- package/dist/types/utils/automaticdecorators.d.ts +49 -0
- package/dist/types/utils/manualdecorator.d.ts +76 -0
- package/dist/types/utils.d.ts +84 -0
- package/lang/contexts.json +1 -0
- package/package.json +4 -3
- package/src/index.d.ts +1 -1
- package/src/linkui.js +30 -8
- package/src/ui/linkformview.d.ts +31 -1
- package/src/ui/linkformview.js +41 -1
- package/theme/linkform.css +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/autolink
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
13
|
+
import { Delete } from 'ckeditor5/src/typing.js';
|
|
14
|
+
import LinkEditing from './linkediting.js';
|
|
15
|
+
/**
|
|
16
|
+
* The autolink plugin.
|
|
17
|
+
*/
|
|
18
|
+
export default class AutoLink extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get requires(): readonly [typeof Delete, typeof LinkEditing];
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get pluginName(): "AutoLink";
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
init(): void;
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
afterInit(): void;
|
|
35
|
+
/**
|
|
36
|
+
* For given position, returns a range that includes the whole link that contains the position.
|
|
37
|
+
*
|
|
38
|
+
* If position is not inside a link, returns `null`.
|
|
39
|
+
*/
|
|
40
|
+
private _expandLinkRange;
|
|
41
|
+
/**
|
|
42
|
+
* Extends the document selection to includes all links that intersects with given `selectedRange`.
|
|
43
|
+
*/
|
|
44
|
+
private _selectEntireLinks;
|
|
45
|
+
/**
|
|
46
|
+
* Enables autolinking on pasting a URL when some content is selected.
|
|
47
|
+
*/
|
|
48
|
+
private _enablePasteLinking;
|
|
49
|
+
/**
|
|
50
|
+
* Enables autolinking on typing.
|
|
51
|
+
*/
|
|
52
|
+
private _enableTypingHandling;
|
|
53
|
+
/**
|
|
54
|
+
* Enables autolinking on the <kbd>Enter</kbd> key.
|
|
55
|
+
*/
|
|
56
|
+
private _enableEnterHandling;
|
|
57
|
+
/**
|
|
58
|
+
* Enables autolinking on the <kbd>Shift</kbd>+<kbd>Enter</kbd> keyboard shortcut.
|
|
59
|
+
*/
|
|
60
|
+
private _enableShiftEnterHandling;
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the passed range contains a linkable text.
|
|
63
|
+
*/
|
|
64
|
+
private _checkAndApplyAutoLinkOnRange;
|
|
65
|
+
/**
|
|
66
|
+
* Applies a link on a given range if the link should be applied.
|
|
67
|
+
*
|
|
68
|
+
* @param url The URL to link.
|
|
69
|
+
* @param range The text range to apply the link attribute to.
|
|
70
|
+
*/
|
|
71
|
+
private _applyAutoLink;
|
|
72
|
+
/**
|
|
73
|
+
* Enqueues autolink changes in the model.
|
|
74
|
+
*
|
|
75
|
+
* @param url The URL to link.
|
|
76
|
+
* @param range The text range to apply the link attribute to.
|
|
77
|
+
*/
|
|
78
|
+
private _persistAutoLink;
|
|
79
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link
|
|
11
|
+
*/
|
|
12
|
+
export { default as Link } from './link.js';
|
|
13
|
+
export { default as LinkEditing } from './linkediting.js';
|
|
14
|
+
export { default as LinkUI } from './linkui.js';
|
|
15
|
+
export { default as LinkImage } from './linkimage.js';
|
|
16
|
+
export { default as LinkImageEditing } from './linkimageediting.js';
|
|
17
|
+
export { default as LinkImageUI } from './linkimageui.js';
|
|
18
|
+
export { default as AutoLink } from './autolink.js';
|
|
19
|
+
export type { LinkConfig, LinkDecoratorDefinition } from './linkconfig.js';
|
|
20
|
+
export { default as LinkCommand } from './linkcommand.js';
|
|
21
|
+
export { default as UnlinkCommand } from './unlinkcommand.js';
|
|
22
|
+
import './augmentation.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/link
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
13
|
+
import LinkEditing from './linkediting.js';
|
|
14
|
+
import LinkUI from './linkui.js';
|
|
15
|
+
import AutoLink from './autolink.js';
|
|
16
|
+
/**
|
|
17
|
+
* The link plugin.
|
|
18
|
+
*
|
|
19
|
+
* This is a "glue" plugin that loads the {@link module:link/linkediting~LinkEditing link editing feature}
|
|
20
|
+
* and {@link module:link/linkui~LinkUI link UI feature}.
|
|
21
|
+
*/
|
|
22
|
+
export default class Link extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get requires(): readonly [typeof LinkEditing, typeof LinkUI, typeof AutoLink];
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
static get pluginName(): "Link";
|
|
31
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/linkcommand
|
|
11
|
+
*/
|
|
12
|
+
import { Command } from 'ckeditor5/src/core.js';
|
|
13
|
+
import { Collection } from 'ckeditor5/src/utils.js';
|
|
14
|
+
import AutomaticDecorators from './utils/automaticdecorators.js';
|
|
15
|
+
import type ManualDecorator from './utils/manualdecorator.js';
|
|
16
|
+
/**
|
|
17
|
+
* The link command. It is used by the {@link module:link/link~Link link feature}.
|
|
18
|
+
*/
|
|
19
|
+
export default class LinkCommand extends Command {
|
|
20
|
+
/**
|
|
21
|
+
* The value of the `'linkHref'` attribute if the start of the selection is located in a node with this attribute.
|
|
22
|
+
*
|
|
23
|
+
* @observable
|
|
24
|
+
* @readonly
|
|
25
|
+
*/
|
|
26
|
+
value: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* A collection of {@link module:link/utils/manualdecorator~ManualDecorator manual decorators}
|
|
29
|
+
* corresponding to the {@link module:link/linkconfig~LinkConfig#decorators decorator configuration}.
|
|
30
|
+
*
|
|
31
|
+
* You can consider it a model with states of manual decorators added to the currently selected link.
|
|
32
|
+
*/
|
|
33
|
+
readonly manualDecorators: Collection<ManualDecorator>;
|
|
34
|
+
/**
|
|
35
|
+
* An instance of the helper that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition}
|
|
36
|
+
* that are used by the {@glink features/link link} and the {@glink features/images/images-linking linking images} features.
|
|
37
|
+
*/
|
|
38
|
+
readonly automaticDecorators: AutomaticDecorators;
|
|
39
|
+
/**
|
|
40
|
+
* Synchronizes the state of {@link #manualDecorators} with the currently present elements in the model.
|
|
41
|
+
*/
|
|
42
|
+
restoreManualDecoratorStates(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
refresh(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Executes the command.
|
|
49
|
+
*
|
|
50
|
+
* When the selection is non-collapsed, the `linkHref` attribute will be applied to nodes inside the selection, but only to
|
|
51
|
+
* those nodes where the `linkHref` attribute is allowed (disallowed nodes will be omitted).
|
|
52
|
+
*
|
|
53
|
+
* When the selection is collapsed and is not inside the text with the `linkHref` attribute, a
|
|
54
|
+
* new {@link module:engine/model/text~Text text node} with the `linkHref` attribute will be inserted in place of the caret, but
|
|
55
|
+
* only if such element is allowed in this place. The `_data` of the inserted text will equal the `href` parameter.
|
|
56
|
+
* The selection will be updated to wrap the just inserted text node.
|
|
57
|
+
*
|
|
58
|
+
* When the selection is collapsed and inside the text with the `linkHref` attribute, the attribute value will be updated.
|
|
59
|
+
*
|
|
60
|
+
* # Decorators and model attribute management
|
|
61
|
+
*
|
|
62
|
+
* There is an optional argument to this command that applies or removes model
|
|
63
|
+
* {@glink framework/architecture/editing-engine#text-attributes text attributes} brought by
|
|
64
|
+
* {@link module:link/utils/manualdecorator~ManualDecorator manual link decorators}.
|
|
65
|
+
*
|
|
66
|
+
* Text attribute names in the model correspond to the entries in the {@link module:link/linkconfig~LinkConfig#decorators
|
|
67
|
+
* configuration}.
|
|
68
|
+
* For every decorator configured, a model text attribute exists with the "link" prefix. For example, a `'linkMyDecorator'` attribute
|
|
69
|
+
* corresponds to `'myDecorator'` in the configuration.
|
|
70
|
+
*
|
|
71
|
+
* To learn more about link decorators, check out the {@link module:link/linkconfig~LinkConfig#decorators `config.link.decorators`}
|
|
72
|
+
* documentation.
|
|
73
|
+
*
|
|
74
|
+
* Here is how to manage decorator attributes with the link command:
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* const linkCommand = editor.commands.get( 'link' );
|
|
78
|
+
*
|
|
79
|
+
* // Adding a new decorator attribute.
|
|
80
|
+
* linkCommand.execute( 'http://example.com', {
|
|
81
|
+
* linkIsExternal: true
|
|
82
|
+
* } );
|
|
83
|
+
*
|
|
84
|
+
* // Removing a decorator attribute from the selection.
|
|
85
|
+
* linkCommand.execute( 'http://example.com', {
|
|
86
|
+
* linkIsExternal: false
|
|
87
|
+
* } );
|
|
88
|
+
*
|
|
89
|
+
* // Adding multiple decorator attributes at the same time.
|
|
90
|
+
* linkCommand.execute( 'http://example.com', {
|
|
91
|
+
* linkIsExternal: true,
|
|
92
|
+
* linkIsDownloadable: true,
|
|
93
|
+
* } );
|
|
94
|
+
*
|
|
95
|
+
* // Removing and adding decorator attributes at the same time.
|
|
96
|
+
* linkCommand.execute( 'http://example.com', {
|
|
97
|
+
* linkIsExternal: false,
|
|
98
|
+
* linkFoo: true,
|
|
99
|
+
* linkIsDownloadable: false,
|
|
100
|
+
* } );
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* **Note**: If the decorator attribute name is not specified, its state remains untouched.
|
|
104
|
+
*
|
|
105
|
+
* **Note**: {@link module:link/unlinkcommand~UnlinkCommand#execute `UnlinkCommand#execute()`} removes all
|
|
106
|
+
* decorator attributes.
|
|
107
|
+
*
|
|
108
|
+
* @fires execute
|
|
109
|
+
* @param href Link destination.
|
|
110
|
+
* @param manualDecoratorIds The information about manual decorator attributes to be applied or removed upon execution.
|
|
111
|
+
*/
|
|
112
|
+
execute(href: string, manualDecoratorIds?: Record<string, boolean>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Provides information whether a decorator with a given name is present in the currently processed selection.
|
|
115
|
+
*
|
|
116
|
+
* @param decoratorName The name of the manual decorator used in the model
|
|
117
|
+
* @returns The information whether a given decorator is currently present in the selection.
|
|
118
|
+
*/
|
|
119
|
+
private _getDecoratorStateFromModel;
|
|
120
|
+
/**
|
|
121
|
+
* Checks whether specified `range` is inside an element that accepts the `linkHref` attribute.
|
|
122
|
+
*
|
|
123
|
+
* @param range A range to check.
|
|
124
|
+
* @param allowedRanges An array of ranges created on elements where the attribute is accepted.
|
|
125
|
+
*/
|
|
126
|
+
private _isRangeToUpdate;
|
|
127
|
+
/**
|
|
128
|
+
* Updates selected link with a new value as its content and as its href attribute.
|
|
129
|
+
*
|
|
130
|
+
* @param model Model is need to insert content.
|
|
131
|
+
* @param writer Writer is need to create text element in model.
|
|
132
|
+
* @param range A range where should be inserted content.
|
|
133
|
+
* @param href A link value which should be in the href attribute and in the content.
|
|
134
|
+
*/
|
|
135
|
+
private _updateLinkContent;
|
|
136
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/linkconfig
|
|
11
|
+
*/
|
|
12
|
+
import type { ArrayOrItem } from 'ckeditor5/src/utils.js';
|
|
13
|
+
/**
|
|
14
|
+
* The configuration of the {@link module:link/link~Link link feature}.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* ClassicEditor
|
|
18
|
+
* .create( editorElement, {
|
|
19
|
+
* link: ... // Link feature configuration.
|
|
20
|
+
* } )
|
|
21
|
+
* .then( ... )
|
|
22
|
+
* .catch( ... );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
26
|
+
*/
|
|
27
|
+
export interface LinkConfig {
|
|
28
|
+
/**
|
|
29
|
+
* When set, the editor will add the given protocol to the link when the user creates a link without one.
|
|
30
|
+
* For example, when the user is creating a link and types `ckeditor.com` in the link form input, during link submission
|
|
31
|
+
* the editor will automatically add the `http://` protocol, so the link will look as follows: `http://ckeditor.com`.
|
|
32
|
+
*
|
|
33
|
+
* The feature also provides email address auto-detection. When you submit `hello@example.com`,
|
|
34
|
+
* the plugin will automatically change it to `mailto:hello@example.com`.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* ClassicEditor
|
|
38
|
+
* .create( editorElement, {
|
|
39
|
+
* link: {
|
|
40
|
+
* defaultProtocol: 'http://'
|
|
41
|
+
* }
|
|
42
|
+
* } )
|
|
43
|
+
* .then( ... )
|
|
44
|
+
* .catch( ... );
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* **NOTE:** If no configuration is provided, the editor will not auto-fix the links.
|
|
48
|
+
*/
|
|
49
|
+
defaultProtocol?: string;
|
|
50
|
+
/**
|
|
51
|
+
* This is a protocols whitelist that can be used in links, defined as an array of strings.
|
|
52
|
+
* When not set, the editor will use a default list of allowed protocols.
|
|
53
|
+
*
|
|
54
|
+
* **Note:** Use this with caution and at your own risk - adding unsafe protocols like `javascript:`
|
|
55
|
+
* can result in serious security vulnerabilities!
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* ClassicEditor
|
|
59
|
+
* .create( editorElement, {
|
|
60
|
+
* link: {
|
|
61
|
+
* allowedProtocols: [ 'http', 'https', 'ftp', 'tel', 'mailto', 'ssh' ]
|
|
62
|
+
* }
|
|
63
|
+
* } )
|
|
64
|
+
* .then( ... )
|
|
65
|
+
* .catch( ... );
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
allowedProtocols?: Array<string>;
|
|
70
|
+
/**
|
|
71
|
+
* When set to `true`, the form will accept an empty value in the URL field, creating a link with an empty `href` (`<a href="">`).
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* ClassicEditor
|
|
75
|
+
* .create( editorElement, {
|
|
76
|
+
* link: {
|
|
77
|
+
* allowCreatingEmptyLinks: true
|
|
78
|
+
* }
|
|
79
|
+
* } )
|
|
80
|
+
* .then( ... )
|
|
81
|
+
* .catch( ... );
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* **NOTE:** This option only adds form validation. If a link with an empty `href` is loaded into the editor, it will be left as-is.
|
|
85
|
+
*
|
|
86
|
+
* @default false
|
|
87
|
+
*/
|
|
88
|
+
allowCreatingEmptyLinks?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* When set to `true`, the `target="blank"` and `rel="noopener noreferrer"` attributes are automatically added to all external links
|
|
91
|
+
* in the editor. "External links" are all links in the editor content starting with `http`, `https`, or `//`.
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* ClassicEditor
|
|
95
|
+
* .create( editorElement, {
|
|
96
|
+
* link: {
|
|
97
|
+
* addTargetToExternalLinks: true
|
|
98
|
+
* }
|
|
99
|
+
* } )
|
|
100
|
+
* .then( ... )
|
|
101
|
+
* .catch( ... );
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* Internally, this option activates a predefined {@link module:link/linkconfig~LinkConfig#decorators automatic link decorator}
|
|
105
|
+
* that extends all external links with the `target` and `rel` attributes.
|
|
106
|
+
*
|
|
107
|
+
* **Note**: To control the `target` and `rel` attributes of specific links in the edited content, a dedicated
|
|
108
|
+
* {@link module:link/linkconfig~LinkDecoratorManualDefinition manual} decorator must be defined in the
|
|
109
|
+
* {@link module:link/linkconfig~LinkConfig#decorators `config.link.decorators`} array. In such scenario,
|
|
110
|
+
* the `config.link.addTargetToExternalLinks` option should remain `undefined` or `false` to not interfere with the manual decorator.
|
|
111
|
+
*
|
|
112
|
+
* It is possible to add other {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic}
|
|
113
|
+
* or {@link module:link/linkconfig~LinkDecoratorManualDefinition manual} link decorators when this option is active.
|
|
114
|
+
*
|
|
115
|
+
* More information about decorators can be found in the {@link module:link/linkconfig~LinkConfig#decorators decorators configuration}
|
|
116
|
+
* reference.
|
|
117
|
+
*
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
addTargetToExternalLinks?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Decorators provide an easy way to configure and manage additional link attributes in the editor content. There are
|
|
123
|
+
* two types of link decorators:
|
|
124
|
+
*
|
|
125
|
+
* * {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition Automatic} – They match links against pre–defined rules and
|
|
126
|
+
* manage their attributes based on the results.
|
|
127
|
+
* * {@link module:link/linkconfig~LinkDecoratorManualDefinition Manual} – They allow users to control link attributes
|
|
128
|
+
* individually, using the editor UI.
|
|
129
|
+
*
|
|
130
|
+
* Link decorators are defined as objects with key-value pairs, where the key is the name provided for a given decorator and the
|
|
131
|
+
* value is the decorator definition.
|
|
132
|
+
*
|
|
133
|
+
* The name of the decorator also corresponds to the {@glink framework/architecture/editing-engine#text-attributes text
|
|
134
|
+
* attribute} in the model. For instance, the `isExternal` decorator below is represented as a `linkIsExternal` attribute in the model.
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* ClassicEditor
|
|
138
|
+
* .create( editorElement, {
|
|
139
|
+
* link: {
|
|
140
|
+
* decorators: {
|
|
141
|
+
* isExternal: {
|
|
142
|
+
* mode: 'automatic',
|
|
143
|
+
* callback: url => url.startsWith( 'http://' ),
|
|
144
|
+
* attributes: {
|
|
145
|
+
* target: '_blank',
|
|
146
|
+
* rel: 'noopener noreferrer'
|
|
147
|
+
* }
|
|
148
|
+
* },
|
|
149
|
+
* isDownloadable: {
|
|
150
|
+
* mode: 'manual',
|
|
151
|
+
* label: 'Downloadable',
|
|
152
|
+
* attributes: {
|
|
153
|
+
* download: 'file.png',
|
|
154
|
+
* }
|
|
155
|
+
* },
|
|
156
|
+
* // ...
|
|
157
|
+
* }
|
|
158
|
+
* }
|
|
159
|
+
* } )
|
|
160
|
+
* .then( ... )
|
|
161
|
+
* .catch( ... );
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* To learn more about the configuration syntax, check out the {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic}
|
|
165
|
+
* and {@link module:link/linkconfig~LinkDecoratorManualDefinition manual} decorator option reference.
|
|
166
|
+
*
|
|
167
|
+
* **Warning:** Currently, link decorators work independently of one another and no conflict resolution mechanism exists.
|
|
168
|
+
* For example, configuring the `target` attribute using both an automatic and a manual decorator at the same time could end up with
|
|
169
|
+
* quirky results. The same applies if multiple manual or automatic decorators were defined for the same attribute.
|
|
170
|
+
*
|
|
171
|
+
* **Note**: Since the `target` attribute management for external links is a common use case, there is a predefined automatic decorator
|
|
172
|
+
* dedicated for that purpose which can be enabled by turning a single option on. Check out the
|
|
173
|
+
* {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}
|
|
174
|
+
* configuration description to learn more.
|
|
175
|
+
*
|
|
176
|
+
* See also the {@glink features/link#custom-link-attributes-decorators link feature guide} for more information.
|
|
177
|
+
*/
|
|
178
|
+
decorators?: Record<string, LinkDecoratorDefinition>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A link decorator definition. Two types implement this definition:
|
|
182
|
+
*
|
|
183
|
+
* * {@link module:link/linkconfig~LinkDecoratorManualDefinition}
|
|
184
|
+
* * {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition}
|
|
185
|
+
*
|
|
186
|
+
* Refer to their document for more information about available options or to the
|
|
187
|
+
* {@glink features/link#custom-link-attributes-decorators link feature guide} for general information.
|
|
188
|
+
*/
|
|
189
|
+
export type LinkDecoratorDefinition = LinkDecoratorAutomaticDefinition | LinkDecoratorManualDefinition;
|
|
190
|
+
/**
|
|
191
|
+
* Describes an automatic {@link module:link/linkconfig~LinkConfig#decorators link decorator}. This decorator type matches
|
|
192
|
+
* all links in the editor content against a function that decides whether the link should receive a pre–defined set of attributes.
|
|
193
|
+
*
|
|
194
|
+
* It takes an object with key-value pairs of attributes and a callback function that must return a Boolean value based on the link's
|
|
195
|
+
* `href` (URL). When the callback returns `true`, attributes are applied to the link.
|
|
196
|
+
*
|
|
197
|
+
* For example, to add the `target="_blank"` attribute to all links in the editor starting with `http://`, the
|
|
198
|
+
* configuration could look like this:
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* {
|
|
202
|
+
* mode: 'automatic',
|
|
203
|
+
* callback: url => url.startsWith( 'http://' ),
|
|
204
|
+
* attributes: {
|
|
205
|
+
* target: '_blank'
|
|
206
|
+
* }
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* **Note**: Since the `target` attribute management for external links is a common use case, there is a predefined automatic decorator
|
|
211
|
+
* dedicated for that purpose that can be enabled by turning a single option on. Check out the
|
|
212
|
+
* {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}
|
|
213
|
+
* configuration description to learn more.
|
|
214
|
+
*/
|
|
215
|
+
export interface LinkDecoratorAutomaticDefinition {
|
|
216
|
+
/**
|
|
217
|
+
* Link decorator type. It is `'automatic'` for all automatic decorators.
|
|
218
|
+
*/
|
|
219
|
+
mode: 'automatic';
|
|
220
|
+
/**
|
|
221
|
+
* Takes a `url` as a parameter and returns `true` if the `attributes` should be applied to the link.
|
|
222
|
+
*/
|
|
223
|
+
callback: (url: string | null) => boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Key-value pairs used as link attributes added to the output during the
|
|
226
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
227
|
+
* Attributes should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
228
|
+
*/
|
|
229
|
+
attributes?: Record<string, string>;
|
|
230
|
+
/**
|
|
231
|
+
* Key-value pairs used as link styles added to the output during the
|
|
232
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
233
|
+
* Styles should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
234
|
+
*/
|
|
235
|
+
styles?: Record<string, string>;
|
|
236
|
+
/**
|
|
237
|
+
* Class names used as link classes added to the output during the
|
|
238
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
239
|
+
* Classes should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
240
|
+
*/
|
|
241
|
+
classes?: ArrayOrItem<string>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Describes a manual {@link module:link/linkconfig~LinkConfig#decorators link decorator}. This decorator type is represented in
|
|
245
|
+
* the link feature's {@link module:link/linkui user interface} as a switch that the user can use to control the presence
|
|
246
|
+
* of a predefined set of attributes.
|
|
247
|
+
*
|
|
248
|
+
* For instance, to allow the users to manually control the presence of the `target="_blank"` and
|
|
249
|
+
* `rel="noopener noreferrer"` attributes on specific links, the decorator could look as follows:
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* {
|
|
253
|
+
* mode: 'manual',
|
|
254
|
+
* label: 'Open in a new tab',
|
|
255
|
+
* defaultValue: true,
|
|
256
|
+
* attributes: {
|
|
257
|
+
* target: '_blank',
|
|
258
|
+
* rel: 'noopener noreferrer'
|
|
259
|
+
* }
|
|
260
|
+
* }
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export interface LinkDecoratorManualDefinition {
|
|
264
|
+
/**
|
|
265
|
+
* Link decorator type. It is `'manual'` for all manual decorators.
|
|
266
|
+
*/
|
|
267
|
+
mode: 'manual';
|
|
268
|
+
/**
|
|
269
|
+
* The label of the UI button that the user can use to control the presence of link attributes.
|
|
270
|
+
*/
|
|
271
|
+
label: string;
|
|
272
|
+
/**
|
|
273
|
+
* Key-value pairs used as link attributes added to the output during the
|
|
274
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
275
|
+
* Attributes should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
276
|
+
*/
|
|
277
|
+
attributes?: Record<string, string>;
|
|
278
|
+
/**
|
|
279
|
+
* Key-value pairs used as link styles added to the output during the
|
|
280
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
281
|
+
* Styles should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
282
|
+
*/
|
|
283
|
+
styles?: Record<string, string>;
|
|
284
|
+
/**
|
|
285
|
+
* Class names used as link classes added to the output during the
|
|
286
|
+
* {@glink framework/architecture/editing-engine#conversion downcasting}.
|
|
287
|
+
* Classes should follow the {@link module:engine/view/elementdefinition~ElementDefinition} syntax.
|
|
288
|
+
*/
|
|
289
|
+
classes?: ArrayOrItem<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Controls whether the decorator is "on" by default.
|
|
292
|
+
*/
|
|
293
|
+
defaultValue?: boolean;
|
|
294
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/linkediting
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core.js';
|
|
13
|
+
import { Input, TwoStepCaretMovement } from 'ckeditor5/src/typing.js';
|
|
14
|
+
import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
|
|
15
|
+
import '../theme/link.css';
|
|
16
|
+
/**
|
|
17
|
+
* The link engine feature.
|
|
18
|
+
*
|
|
19
|
+
* It introduces the `linkHref="url"` attribute in the model which renders to the view as a `<a href="url">` element
|
|
20
|
+
* as well as `'link'` and `'unlink'` commands.
|
|
21
|
+
*/
|
|
22
|
+
export default class LinkEditing extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get pluginName(): "LinkEditing";
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
static get requires(): readonly [typeof TwoStepCaretMovement, typeof Input, typeof ClipboardPipeline];
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
constructor(editor: Editor);
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
init(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Processes an array of configured {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}
|
|
41
|
+
* and registers a {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast dispatcher}
|
|
42
|
+
* for each one of them. Downcast dispatchers are obtained using the
|
|
43
|
+
* {@link module:link/utils/automaticdecorators~AutomaticDecorators#getDispatcher} method.
|
|
44
|
+
*
|
|
45
|
+
* **Note**: This method also activates the automatic external link decorator if enabled with
|
|
46
|
+
* {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}.
|
|
47
|
+
*/
|
|
48
|
+
private _enableAutomaticDecorators;
|
|
49
|
+
/**
|
|
50
|
+
* Processes an array of configured {@link module:link/linkconfig~LinkDecoratorManualDefinition manual decorators},
|
|
51
|
+
* transforms them into {@link module:link/utils/manualdecorator~ManualDecorator} instances and stores them in the
|
|
52
|
+
* {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
|
|
53
|
+
*
|
|
54
|
+
* Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attribute-to-element}
|
|
55
|
+
* converter for each manual decorator and extends the {@link module:engine/model/schema~Schema model's schema}
|
|
56
|
+
* with adequate model attributes.
|
|
57
|
+
*/
|
|
58
|
+
private _enableManualDecorators;
|
|
59
|
+
/**
|
|
60
|
+
* Attaches handlers for {@link module:engine/view/document~Document#event:enter} and
|
|
61
|
+
* {@link module:engine/view/document~Document#event:click} to enable link following.
|
|
62
|
+
*/
|
|
63
|
+
private _enableLinkOpen;
|
|
64
|
+
/**
|
|
65
|
+
* Watches the DocumentSelection attribute changes and removes link decorator attributes when the linkHref attribute is removed.
|
|
66
|
+
*
|
|
67
|
+
* This is to ensure that there is no left-over link decorator attributes on the document selection that is no longer in a link.
|
|
68
|
+
*/
|
|
69
|
+
private _enableSelectionAttributesFixer;
|
|
70
|
+
/**
|
|
71
|
+
* Enables URL fixing on pasting.
|
|
72
|
+
*/
|
|
73
|
+
private _enableClipboardIntegration;
|
|
74
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
7
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @module link/linkimage
|
|
11
|
+
*/
|
|
12
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
13
|
+
import LinkImageEditing from './linkimageediting.js';
|
|
14
|
+
import LinkImageUI from './linkimageui.js';
|
|
15
|
+
import '../theme/linkimage.css';
|
|
16
|
+
/**
|
|
17
|
+
* The `LinkImage` plugin.
|
|
18
|
+
*
|
|
19
|
+
* This is a "glue" plugin that loads the {@link module:link/linkimageediting~LinkImageEditing link image editing feature}
|
|
20
|
+
* and {@link module:link/linkimageui~LinkImageUI link image UI feature}.
|
|
21
|
+
*/
|
|
22
|
+
export default class LinkImage extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get requires(): readonly [typeof LinkImageEditing, typeof LinkImageUI];
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
static get pluginName(): "LinkImage";
|
|
31
|
+
}
|