@ckeditor/ckeditor5-link 45.2.1 → 46.0.0-alpha.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.
- package/build/link.js +1 -1
- package/dist/index-editor.css +11 -11
- package/dist/index.css +15 -15
- package/dist/index.css.map +1 -1
- package/dist/index.js +35 -28
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/autolink.d.ts +2 -2
- package/src/autolink.js +2 -2
- package/src/index.d.ts +23 -12
- package/src/index.js +17 -11
- package/src/link.d.ts +4 -4
- package/src/link.js +4 -4
- package/src/linkcommand.d.ts +8 -8
- package/src/linkcommand.js +9 -9
- package/src/linkconfig.d.ts +6 -6
- package/src/linkediting.d.ts +7 -7
- package/src/linkediting.js +12 -12
- package/src/linkimage.d.ts +3 -3
- package/src/linkimage.js +3 -3
- package/src/linkimageediting.d.ts +3 -3
- package/src/linkimageediting.js +3 -3
- package/src/linkimageui.d.ts +3 -3
- package/src/linkimageui.js +3 -3
- package/src/linkui.d.ts +7 -7
- package/src/linkui.js +9 -9
- package/src/ui/linkbuttonview.d.ts +1 -1
- package/src/ui/linkbuttonview.js +1 -1
- package/src/ui/linkformview.d.ts +3 -3
- package/src/ui/linkformview.js +1 -1
- package/src/ui/linkpreviewbuttonview.d.ts +1 -1
- package/src/ui/linkpreviewbuttonview.js +1 -1
- package/src/ui/linkpropertiesview.d.ts +2 -2
- package/src/ui/linkpropertiesview.js +1 -1
- package/src/ui/linkprovideritemsview.d.ts +2 -2
- package/src/ui/linkprovideritemsview.js +1 -1
- package/src/unlinkcommand.d.ts +1 -1
- package/src/unlinkcommand.js +1 -1
- package/src/utils/automaticdecorators.d.ts +2 -2
- package/src/utils/automaticdecorators.js +2 -2
- package/src/utils/manualdecorator.d.ts +7 -7
- package/src/utils/manualdecorator.js +6 -6
- package/src/utils.d.ts +11 -4
- package/src/utils.js +8 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
|
|
|
6
6
|
import { findAttributeRange, TwoStepCaretMovement, Input, inlineHighlight, Delete, TextWatcher, getLastTextLine } from '@ckeditor/ckeditor5-typing/dist/index.js';
|
|
7
7
|
import { ClipboardPipeline } from '@ckeditor/ckeditor5-clipboard/dist/index.js';
|
|
8
8
|
import { toMap, Collection, first, diff, ObservableMixin, env, keyCodes, FocusTracker, KeystrokeHandler } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
|
9
|
-
import {
|
|
9
|
+
import { ModelLivePosition, ClickObserver, Matcher } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
|
10
10
|
import { upperFirst } from 'es-toolkit/compat';
|
|
11
11
|
import { IconPreviousArrow, IconUnlink, IconPencil, IconSettings, IconLink } from '@ckeditor/ckeditor5-icons/dist/index.js';
|
|
12
12
|
import { ButtonView, View, ViewCollection, FocusCycler, submitHandler, FormHeaderView, ListView, ListItemView, LabeledFieldView, createLabeledInputText, FormRowView, IconView, ContextualBalloon, ToolbarView, CssTransitionDisablerMixin, SwitchButtonView, MenuBarMenuListItemButtonView, clickOutsideHandler } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
@@ -16,13 +16,13 @@ import { IconPreviousArrow as IconPreviousArrow$1, IconNextArrow } from '@ckedit
|
|
|
16
16
|
/**
|
|
17
17
|
* Helper class that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition} and provides
|
|
18
18
|
* the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement downcast dispatchers} for them.
|
|
19
|
-
*/ class
|
|
19
|
+
*/ class AutomaticLinkDecorators {
|
|
20
20
|
/**
|
|
21
21
|
* Stores the definition of {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}.
|
|
22
22
|
* This data is used as a source for a downcast dispatcher to create a proper conversion to output data.
|
|
23
23
|
*/ _definitions = new Set();
|
|
24
24
|
/**
|
|
25
|
-
* Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~
|
|
25
|
+
* Gives information about the number of decorators stored in the {@link module:link/utils/automaticdecorators~AutomaticLinkDecorators}
|
|
26
26
|
* instance.
|
|
27
27
|
*/ get length() {
|
|
28
28
|
return this._definitions.size;
|
|
@@ -160,7 +160,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
160
160
|
return node.is('attributeElement') && !!node.getCustomProperty('link');
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
|
-
* Creates a link {@link module:engine/view/attributeelement~
|
|
163
|
+
* Creates a link {@link module:engine/view/attributeelement~ViewAttributeElement} with the provided `href` attribute.
|
|
164
164
|
*/ function createLinkElement(href, { writer }) {
|
|
165
165
|
// Priority 5 - https://github.com/ckeditor/ckeditor5-link/issues/121.
|
|
166
166
|
const linkElement = writer.createAttributeElement('a', {
|
|
@@ -201,6 +201,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
201
201
|
*
|
|
202
202
|
* @param t Shorthand for {@link module:utils/locale~Locale#t Locale#t}.
|
|
203
203
|
* @param decorators The decorator reference where the label values should be localized.
|
|
204
|
+
* @internal
|
|
204
205
|
*/ function getLocalizedDecorators(t, decorators) {
|
|
205
206
|
const localizedDecoratorsLabels = {
|
|
206
207
|
'Open in a new tab': t('Open in a new tab'),
|
|
@@ -217,6 +218,8 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
217
218
|
/**
|
|
218
219
|
* Converts an object with defined decorators to a normalized array of decorators. The `id` key is added for each decorator and
|
|
219
220
|
* is used as the attribute's name in the model.
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
220
223
|
*/ function normalizeDecorators(decorators) {
|
|
221
224
|
const retArray = [];
|
|
222
225
|
if (decorators) {
|
|
@@ -239,6 +242,8 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
239
242
|
}
|
|
240
243
|
/**
|
|
241
244
|
* Returns `true` if the specified `value` is an email.
|
|
245
|
+
*
|
|
246
|
+
* @internal
|
|
242
247
|
*/ function isEmail(value) {
|
|
243
248
|
return EMAIL_REG_EXP.test(value);
|
|
244
249
|
}
|
|
@@ -255,6 +260,8 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
255
260
|
}
|
|
256
261
|
/**
|
|
257
262
|
* Checks if protocol is already included in the link.
|
|
263
|
+
*
|
|
264
|
+
* @internal
|
|
258
265
|
*/ function linkHasProtocol(link) {
|
|
259
266
|
return PROTOCOL_REG_EXP.test(link);
|
|
260
267
|
}
|
|
@@ -282,7 +289,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
282
289
|
* The link command. It is used by the {@link module:link/link~Link link feature}.
|
|
283
290
|
*/ class LinkCommand extends Command {
|
|
284
291
|
/**
|
|
285
|
-
* A collection of {@link module:link/utils/manualdecorator~
|
|
292
|
+
* A collection of {@link module:link/utils/manualdecorator~LinkManualDecorator manual decorators}
|
|
286
293
|
* corresponding to the {@link module:link/linkconfig~LinkConfig#decorators decorator configuration}.
|
|
287
294
|
*
|
|
288
295
|
* You can consider it a model with states of manual decorators added to the currently selected link.
|
|
@@ -290,7 +297,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
290
297
|
/**
|
|
291
298
|
* An instance of the helper that ties together all {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition}
|
|
292
299
|
* that are used by the {@glink features/link link} and the {@glink features/images/images-linking linking images} features.
|
|
293
|
-
*/ automaticDecorators = new
|
|
300
|
+
*/ automaticDecorators = new AutomaticLinkDecorators();
|
|
294
301
|
/**
|
|
295
302
|
* Synchronizes the state of {@link #manualDecorators} with the currently present elements in the model.
|
|
296
303
|
*/ restoreManualDecoratorStates() {
|
|
@@ -324,7 +331,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
324
331
|
* those nodes where the `linkHref` attribute is allowed (disallowed nodes will be omitted).
|
|
325
332
|
*
|
|
326
333
|
* When the selection is collapsed and is not inside the text with the `linkHref` attribute, a
|
|
327
|
-
* new {@link module:engine/model/text~
|
|
334
|
+
* new {@link module:engine/model/text~ModelText text node} with the `linkHref` attribute will be inserted in place of the caret, but
|
|
328
335
|
* only if such element is allowed in this place. The `_data` of the inserted text will equal the `href` parameter.
|
|
329
336
|
* The selection will be updated to wrap the just inserted text node.
|
|
330
337
|
*
|
|
@@ -334,7 +341,7 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
334
341
|
*
|
|
335
342
|
* There is an optional argument to this command that applies or removes model
|
|
336
343
|
* {@glink framework/architecture/editing-engine#text-attributes text attributes} brought by
|
|
337
|
-
* {@link module:link/utils/manualdecorator~
|
|
344
|
+
* {@link module:link/utils/manualdecorator~LinkManualDecorator manual link decorators}.
|
|
338
345
|
*
|
|
339
346
|
* Text attribute names in the model correspond to the entries in the {@link module:link/linkconfig~LinkConfig#decorators
|
|
340
347
|
* configuration}.
|
|
@@ -523,8 +530,8 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
523
530
|
}
|
|
524
531
|
// Store the selection ranges in a pseudo live range array (stickiness to the outside of the range).
|
|
525
532
|
const stickyPseudoRanges = selectionRanges.map((range)=>({
|
|
526
|
-
start:
|
|
527
|
-
end:
|
|
533
|
+
start: ModelLivePosition.fromPosition(range.start, 'toPrevious'),
|
|
534
|
+
end: ModelLivePosition.fromPosition(range.end, 'toNext')
|
|
528
535
|
}));
|
|
529
536
|
// Update or set links (including text update if needed).
|
|
530
537
|
for (let range of rangesToUpdate){
|
|
@@ -723,10 +730,10 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
723
730
|
}
|
|
724
731
|
|
|
725
732
|
/**
|
|
726
|
-
* Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~
|
|
733
|
+
* Helper class that stores manual decorators with observable {@link module:link/utils/manualdecorator~LinkManualDecorator#value}
|
|
727
734
|
* to support integration with the UI state. An instance of this class is a model with the state of individual manual decorators.
|
|
728
735
|
* These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
|
|
729
|
-
*/ class
|
|
736
|
+
*/ class LinkManualDecorator extends /* #__PURE__ */ ObservableMixin() {
|
|
730
737
|
/**
|
|
731
738
|
* An ID of a manual decorator which is the name of the attribute in the model, for example: 'linkManualDecorator0'.
|
|
732
739
|
*/ id;
|
|
@@ -738,18 +745,18 @@ const DEFAULT_LINK_PROTOCOLS = [
|
|
|
738
745
|
*/ label;
|
|
739
746
|
/**
|
|
740
747
|
* A set of attributes added to downcasted data when the decorator is activated for a specific link.
|
|
741
|
-
* Attributes should be added in a form of attributes defined in {@link module:engine/view/elementdefinition~
|
|
748
|
+
* Attributes should be added in a form of attributes defined in {@link module:engine/view/elementdefinition~ViewElementDefinition}.
|
|
742
749
|
*/ attributes;
|
|
743
750
|
/**
|
|
744
751
|
* A set of classes added to downcasted data when the decorator is activated for a specific link.
|
|
745
|
-
* Classes should be added in a form of classes defined in {@link module:engine/view/elementdefinition~
|
|
752
|
+
* Classes should be added in a form of classes defined in {@link module:engine/view/elementdefinition~ViewElementDefinition}.
|
|
746
753
|
*/ classes;
|
|
747
754
|
/**
|
|
748
755
|
* A set of styles added to downcasted data when the decorator is activated for a specific link.
|
|
749
|
-
* Styles should be added in a form of styles defined in {@link module:engine/view/elementdefinition~
|
|
756
|
+
* Styles should be added in a form of styles defined in {@link module:engine/view/elementdefinition~ViewElementDefinition}.
|
|
750
757
|
*/ styles;
|
|
751
758
|
/**
|
|
752
|
-
* Creates a new instance of {@link module:link/utils/manualdecorator~
|
|
759
|
+
* Creates a new instance of {@link module:link/utils/manualdecorator~LinkManualDecorator}.
|
|
753
760
|
*
|
|
754
761
|
* @param options The configuration object.
|
|
755
762
|
*/ constructor({ id, label, attributes, classes, styles, defaultValue }){
|
|
@@ -868,7 +875,7 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
868
875
|
inlineHighlight(editor, 'linkHref', 'a', HIGHLIGHT_CLASS);
|
|
869
876
|
// Handle link following by CTRL+click or ALT+ENTER
|
|
870
877
|
this._enableLinkOpen();
|
|
871
|
-
// Clears the
|
|
878
|
+
// Clears the ModelDocumentSelection decorator attributes if the selection is no longer in a link (for example while using 2-SCM).
|
|
872
879
|
this._enableSelectionAttributesFixer();
|
|
873
880
|
// Handle adding default protocol to pasted links.
|
|
874
881
|
this._enableClipboardIntegration();
|
|
@@ -885,7 +892,7 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
885
892
|
* Processes an array of configured {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}
|
|
886
893
|
* and registers a {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast dispatcher}
|
|
887
894
|
* for each one of them. Downcast dispatchers are obtained using the
|
|
888
|
-
* {@link module:link/utils/automaticdecorators~
|
|
895
|
+
* {@link module:link/utils/automaticdecorators~AutomaticLinkDecorators#getDispatcher} method.
|
|
889
896
|
*
|
|
890
897
|
* **Note**: This method also activates the automatic external link decorator if enabled with
|
|
891
898
|
* {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}.
|
|
@@ -914,11 +921,11 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
914
921
|
}
|
|
915
922
|
/**
|
|
916
923
|
* Processes an array of configured {@link module:link/linkconfig~LinkDecoratorManualDefinition manual decorators},
|
|
917
|
-
* transforms them into {@link module:link/utils/manualdecorator~
|
|
924
|
+
* transforms them into {@link module:link/utils/manualdecorator~LinkManualDecorator} instances and stores them in the
|
|
918
925
|
* {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
|
|
919
926
|
*
|
|
920
927
|
* Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attribute-to-element}
|
|
921
|
-
* converter for each manual decorator and extends the {@link module:engine/model/schema~
|
|
928
|
+
* converter for each manual decorator and extends the {@link module:engine/model/schema~ModelSchema model's schema}
|
|
922
929
|
* with adequate model attributes.
|
|
923
930
|
*/ _enableManualDecorators(manualDecoratorDefinitions) {
|
|
924
931
|
if (!manualDecoratorDefinitions.length) {
|
|
@@ -932,7 +939,7 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
932
939
|
allowAttributes: decoratorDefinition.id
|
|
933
940
|
});
|
|
934
941
|
// Keeps reference to manual decorator to decode its name to attributes during downcast.
|
|
935
|
-
const decorator = new
|
|
942
|
+
const decorator = new LinkManualDecorator(decoratorDefinition);
|
|
936
943
|
manualDecorators.add(decorator);
|
|
937
944
|
editor.conversion.for('downcast').attributeToElement({
|
|
938
945
|
model: decorator.id,
|
|
@@ -968,8 +975,8 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
968
975
|
});
|
|
969
976
|
}
|
|
970
977
|
/**
|
|
971
|
-
* Attaches handlers for {@link module:engine/view/document~
|
|
972
|
-
* {@link module:engine/view/document~
|
|
978
|
+
* Attaches handlers for {@link module:engine/view/document~ViewDocument#event:enter} and
|
|
979
|
+
* {@link module:engine/view/document~ViewDocument#event:click} to enable link following.
|
|
973
980
|
*/ _enableLinkOpen() {
|
|
974
981
|
const editor = this.editor;
|
|
975
982
|
const view = editor.editing.view;
|
|
@@ -1014,7 +1021,7 @@ const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
|
|
|
1014
1021
|
});
|
|
1015
1022
|
}
|
|
1016
1023
|
/**
|
|
1017
|
-
* Watches the
|
|
1024
|
+
* Watches the ModelDocumentSelection attribute changes and removes link decorator attributes when the linkHref attribute is removed.
|
|
1018
1025
|
*
|
|
1019
1026
|
* This is to ensure that there is no left-over link decorator attributes on the document selection that is no longer in a link.
|
|
1020
1027
|
*/ _enableSelectionAttributesFixer() {
|
|
@@ -2591,8 +2598,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'link-ui';
|
|
|
2591
2598
|
};
|
|
2592
2599
|
}
|
|
2593
2600
|
/**
|
|
2594
|
-
* Returns the link {@link module:engine/view/attributeelement~
|
|
2595
|
-
* the {@link module:engine/view/document~
|
|
2601
|
+
* Returns the link {@link module:engine/view/attributeelement~ViewAttributeElement} under
|
|
2602
|
+
* the {@link module:engine/view/document~ViewDocument editing view's} selection or `null`
|
|
2596
2603
|
* if there is none.
|
|
2597
2604
|
*
|
|
2598
2605
|
* **Note**: For a non–collapsed selection, the link element is returned when **fully**
|
|
@@ -3063,7 +3070,7 @@ function linkIsAlreadySet(range) {
|
|
|
3063
3070
|
}
|
|
3064
3071
|
}
|
|
3065
3072
|
/**
|
|
3066
|
-
* Processes transformed {@link module:link/utils/manualdecorator~
|
|
3073
|
+
* Processes transformed {@link module:link/utils/manualdecorator~LinkManualDecorator} instances and attaches proper converters
|
|
3067
3074
|
* that will work when linking an image.
|
|
3068
3075
|
*/ _enableManualDecorators() {
|
|
3069
3076
|
const editor = this.editor;
|
|
@@ -3386,5 +3393,5 @@ function linkIsAlreadySet(range) {
|
|
|
3386
3393
|
}
|
|
3387
3394
|
}
|
|
3388
3395
|
|
|
3389
|
-
export { AutoLink, Link, LinkCommand, LinkEditing, LinkFormView, LinkImage, LinkImageEditing, LinkImageUI, LinkUI, UnlinkCommand, addLinkProtocolIfApplicable, ensureSafeUrl, isLinkableElement };
|
|
3396
|
+
export { AutoLink, AutomaticLinkDecorators, Link, LinkCommand, LinkEditing, LinkFormView, LinkImage, LinkImageEditing, LinkImageUI, LinkManualDecorator, LinkPropertiesView, LinkProviderItemsView, LinkUI, UnlinkCommand, LINK_KEYSTROKE as _LINK_KEYSTROKE, LinkButtonView as _LinkButtonView, LinkPreviewButtonView as _LinkPreviewButtonView, createLinkElement as _createLinkElement, ensureSafeUrl as _ensureSafeLinkUrl, extractTextFromLinkRange as _extractTextFromLinkRange, getLocalizedDecorators as _getLocalizedLinkDecorators, linkHasProtocol as _hasLinkProtocol, isEmail as _isEmailLink, normalizeDecorators as _normalizeLinkDecorators, openLink as _openLink, addLinkProtocolIfApplicable, ensureSafeUrl, isLinkElement, isLinkableElement };
|
|
3390
3397
|
//# sourceMappingURL=index.js.map
|