@ckeditor/ckeditor5-utils 41.3.1 → 41.4.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/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.js +5491 -0
- package/dist/index.js.map +1 -0
- package/dist/types/abortabledebounce.d.ts +21 -0
- package/dist/types/areconnectedthroughproperties.d.ts +15 -0
- package/dist/types/ckeditorerror.d.ts +127 -0
- package/dist/types/collection.d.ts +437 -0
- package/dist/types/comparearrays.d.ts +34 -0
- package/dist/types/config.d.ts +167 -0
- package/dist/types/count.d.ts +22 -0
- package/dist/types/delay.d.ts +23 -0
- package/dist/types/diff.d.ts +35 -0
- package/dist/types/difftochanges.d.ts +63 -0
- package/dist/types/dom/createelement.d.ts +61 -0
- package/dist/types/dom/emittermixin.d.ts +146 -0
- package/dist/types/dom/findclosestscrollableancestor.d.ts +15 -0
- package/dist/types/dom/getancestors.d.ts +21 -0
- package/dist/types/dom/getborderwidths.d.ts +28 -0
- package/dist/types/dom/getcommonancestor.d.ts +16 -0
- package/dist/types/dom/getdatafromelement.d.ts +18 -0
- package/dist/types/dom/getpositionedancestor.d.ts +14 -0
- package/dist/types/dom/global.d.ts +36 -0
- package/dist/types/dom/indexof.d.ts +18 -0
- package/dist/types/dom/insertat.d.ts +19 -0
- package/dist/types/dom/iscomment.d.ts +15 -0
- package/dist/types/dom/isnode.d.ts +15 -0
- package/dist/types/dom/isrange.d.ts +15 -0
- package/dist/types/dom/istext.d.ts +15 -0
- package/dist/types/dom/isvalidattributename.d.ts +14 -0
- package/dist/types/dom/isvisible.d.ts +22 -0
- package/dist/types/dom/iswindow.d.ts +15 -0
- package/dist/types/dom/position.d.ts +215 -0
- package/dist/types/dom/rect.d.ts +199 -0
- package/dist/types/dom/remove.d.ts +17 -0
- package/dist/types/dom/resizeobserver.d.ts +78 -0
- package/dist/types/dom/scroll.d.ts +77 -0
- package/dist/types/dom/setdatainelement.d.ts +18 -0
- package/dist/types/dom/tounit.d.ts +26 -0
- package/dist/types/elementreplacer.d.ts +35 -0
- package/dist/types/emittermixin.d.ts +316 -0
- package/dist/types/env.d.ts +137 -0
- package/dist/types/eventinfo.d.ts +62 -0
- package/dist/types/fastdiff.d.ts +116 -0
- package/dist/types/first.d.ts +15 -0
- package/dist/types/focustracker.d.ts +79 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/inserttopriorityarray.d.ts +34 -0
- package/dist/types/isiterable.d.ts +18 -0
- package/dist/types/keyboard.d.ts +130 -0
- package/dist/types/keystrokehandler.d.ts +91 -0
- package/dist/types/language.d.ts +21 -0
- package/dist/types/locale.d.ts +145 -0
- package/dist/types/mapsequal.d.ts +19 -0
- package/dist/types/mix.d.ts +89 -0
- package/dist/types/nth.d.ts +20 -0
- package/dist/types/objecttomap.d.ts +27 -0
- package/dist/types/observablemixin.d.ts +564 -0
- package/dist/types/priorities.d.ts +37 -0
- package/dist/types/retry.d.ts +37 -0
- package/dist/types/splicearray.d.ts +30 -0
- package/dist/types/spy.d.ts +25 -0
- package/dist/types/toarray.d.ts +29 -0
- package/dist/types/tomap.d.ts +23 -0
- package/dist/types/translation-service.d.ts +178 -0
- package/dist/types/uid.d.ts +19 -0
- package/dist/types/unicode.d.ts +58 -0
- package/dist/types/verifylicense.d.ts +19 -0
- package/dist/types/version.d.ts +14 -0
- package/dist/types/wait.d.ts +20 -0
- package/package.json +2 -1
- package/src/env.d.ts +16 -0
- package/src/env.js +16 -0
- package/src/locale.d.ts +1 -1
- package/src/version.d.ts +1 -1
- package/src/version.js +2 -2
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import type { DiffResult } from './diff.js';
|
|
10
|
+
import type { Change } from './difftochanges.js';
|
|
11
|
+
/**
|
|
12
|
+
* @module utils/fastdiff
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Finds positions of the first and last change in the given string/array and generates a set of changes:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* fastDiff( '12a', '12xyza' );
|
|
19
|
+
* // [ { index: 2, type: 'insert', values: [ 'x', 'y', 'z' ] } ]
|
|
20
|
+
*
|
|
21
|
+
* fastDiff( '12a', '12aa' );
|
|
22
|
+
* // [ { index: 3, type: 'insert', values: [ 'a' ] } ]
|
|
23
|
+
*
|
|
24
|
+
* fastDiff( '12xyza', '12a' );
|
|
25
|
+
* // [ { index: 2, type: 'delete', howMany: 3 } ]
|
|
26
|
+
*
|
|
27
|
+
* fastDiff( [ '1', '2', 'a', 'a' ], [ '1', '2', 'a' ] );
|
|
28
|
+
* // [ { index: 3, type: 'delete', howMany: 1 } ]
|
|
29
|
+
*
|
|
30
|
+
* fastDiff( [ '1', '2', 'a', 'b', 'c', '3' ], [ '2', 'a', 'b' ] );
|
|
31
|
+
* // [ { index: 0, type: 'insert', values: [ '2', 'a', 'b' ] }, { index: 3, type: 'delete', howMany: 6 } ]
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Passed arrays can contain any type of data, however to compare them correctly custom comparator function
|
|
35
|
+
* should be passed as a third parameter:
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* fastDiff( [ { value: 1 }, { value: 2 } ], [ { value: 1 }, { value: 3 } ], ( a, b ) => {
|
|
39
|
+
* return a.value === b.value;
|
|
40
|
+
* } );
|
|
41
|
+
* // [ { index: 1, type: 'insert', values: [ { value: 3 } ] }, { index: 2, type: 'delete', howMany: 1 } ]
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* The resulted set of changes can be applied to the input in order to transform it into the output, for example:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* let input = '12abc3';
|
|
48
|
+
* const output = '2ab';
|
|
49
|
+
* const changes = fastDiff( input, output );
|
|
50
|
+
*
|
|
51
|
+
* changes.forEach( change => {
|
|
52
|
+
* if ( change.type == 'insert' ) {
|
|
53
|
+
* input = input.substring( 0, change.index ) + change.values.join( '' ) + input.substring( change.index );
|
|
54
|
+
* } else if ( change.type == 'delete' ) {
|
|
55
|
+
* input = input.substring( 0, change.index ) + input.substring( change.index + change.howMany );
|
|
56
|
+
* }
|
|
57
|
+
* } );
|
|
58
|
+
*
|
|
59
|
+
* // input equals output now
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* or in case of arrays:
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* let input = [ '1', '2', 'a', 'b', 'c', '3' ];
|
|
66
|
+
* const output = [ '2', 'a', 'b' ];
|
|
67
|
+
* const changes = fastDiff( input, output );
|
|
68
|
+
*
|
|
69
|
+
* changes.forEach( change => {
|
|
70
|
+
* if ( change.type == 'insert' ) {
|
|
71
|
+
* input = input.slice( 0, change.index ).concat( change.values, input.slice( change.index ) );
|
|
72
|
+
* } else if ( change.type == 'delete' ) {
|
|
73
|
+
* input = input.slice( 0, change.index ).concat( input.slice( change.index + change.howMany ) );
|
|
74
|
+
* }
|
|
75
|
+
* } );
|
|
76
|
+
*
|
|
77
|
+
* // input equals output now
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* By passing `true` as the fourth parameter (`atomicChanges`) the output of this function will become compatible with
|
|
81
|
+
* the {@link module:utils/diff~diff `diff()`} function:
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* fastDiff( '12a', '12xyza', undefined, true );
|
|
85
|
+
* // [ 'equal', 'equal', 'insert', 'insert', 'insert', 'equal' ]
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* The default output format of this function is compatible with the output format of
|
|
89
|
+
* {@link module:utils/difftochanges~diffToChanges `diffToChanges()`}. The `diffToChanges()` input format is, in turn,
|
|
90
|
+
* compatible with the output of {@link module:utils/diff~diff `diff()`}:
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* const a = '1234';
|
|
94
|
+
* const b = '12xyz34';
|
|
95
|
+
*
|
|
96
|
+
* // Both calls will return the same results (grouped changes format).
|
|
97
|
+
* fastDiff( a, b );
|
|
98
|
+
* diffToChanges( diff( a, b ) );
|
|
99
|
+
*
|
|
100
|
+
* // Again, both calls will return the same results (atomic changes format).
|
|
101
|
+
* fastDiff( a, b, undefined, true );
|
|
102
|
+
* diff( a, b );
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @typeParam T The type of array elements.
|
|
106
|
+
* @typeParam AtomicChanges The type of `atomicChanges` parameter (selects the result type).
|
|
107
|
+
* @param a Input array or string.
|
|
108
|
+
* @param b Input array or string.
|
|
109
|
+
* @param cmp Optional function used to compare array values, by default `===` (strict equal operator) is used.
|
|
110
|
+
* @param atomicChanges Whether an array of `inset|delete|equal` operations should
|
|
111
|
+
* be returned instead of changes set. This makes this function compatible with {@link module:utils/diff~diff `diff()`}.
|
|
112
|
+
* Defaults to `false`.
|
|
113
|
+
* @returns Array of changes. The elements are either {@link module:utils/diff~DiffResult} or {@link module:utils/difftochanges~Change},
|
|
114
|
+
* depending on `atomicChanges` parameter.
|
|
115
|
+
*/
|
|
116
|
+
export default function fastDiff<T, AtomicChanges extends boolean = false>(a: ArrayLike<T>, b: ArrayLike<T>, cmp?: (a: T, b: T) => boolean, atomicChanges?: AtomicChanges): Array<AtomicChanges extends true ? DiffResult : Change<T>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 utils/first
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns first item of the given `iterator`.
|
|
14
|
+
*/
|
|
15
|
+
export default function first<T>(iterator: Iterator<T>): T | null;
|
|
@@ -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
|
+
declare const FocusTracker_base: import("./mix.js").Mixed<{
|
|
10
|
+
new (): import("./observablemixin.js").Observable;
|
|
11
|
+
prototype: import("./observablemixin.js").Observable;
|
|
12
|
+
}, import("./dom/emittermixin.js").DomEmitter>;
|
|
13
|
+
/**
|
|
14
|
+
* Allows observing a group of `Element`s whether at least one of them is focused.
|
|
15
|
+
*
|
|
16
|
+
* Used by the {@link module:core/editor/editor~Editor} in order to track whether the focus is still within the application,
|
|
17
|
+
* or were used outside of its UI.
|
|
18
|
+
*
|
|
19
|
+
* **Note** `focus` and `blur` listeners use event capturing, so it is only needed to register wrapper `Element`
|
|
20
|
+
* which contain other `focusable` elements. But note that this wrapper element has to be focusable too
|
|
21
|
+
* (have e.g. `tabindex="-1"`).
|
|
22
|
+
*
|
|
23
|
+
* Check out the {@glink framework/deep-dive/ui/focus-tracking "Deep dive into focus tracking"} guide to learn more.
|
|
24
|
+
*/
|
|
25
|
+
export default class FocusTracker extends FocusTracker_base {
|
|
26
|
+
/**
|
|
27
|
+
* True when one of the registered elements is focused.
|
|
28
|
+
*
|
|
29
|
+
* @readonly
|
|
30
|
+
* @observable
|
|
31
|
+
*/
|
|
32
|
+
isFocused: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The currently focused element.
|
|
35
|
+
*
|
|
36
|
+
* While {@link #isFocused `isFocused`} remains `true`, the focus can
|
|
37
|
+
* move between different UI elements. This property tracks those
|
|
38
|
+
* elements and tells which one is currently focused.
|
|
39
|
+
*
|
|
40
|
+
* @readonly
|
|
41
|
+
* @observable
|
|
42
|
+
*/
|
|
43
|
+
focusedElement: Element | null;
|
|
44
|
+
/**
|
|
45
|
+
* List of registered elements.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
_elements: Set<Element>;
|
|
50
|
+
/**
|
|
51
|
+
* Event loop timeout.
|
|
52
|
+
*/
|
|
53
|
+
private _nextEventLoopTimeout;
|
|
54
|
+
constructor();
|
|
55
|
+
/**
|
|
56
|
+
* Starts tracking the specified element.
|
|
57
|
+
*/
|
|
58
|
+
add(element: Element): void;
|
|
59
|
+
/**
|
|
60
|
+
* Stops tracking the specified element and stops listening on this element.
|
|
61
|
+
*/
|
|
62
|
+
remove(element: Element): void;
|
|
63
|
+
/**
|
|
64
|
+
* Destroys the focus tracker by:
|
|
65
|
+
* - Disabling all event listeners attached to tracked elements.
|
|
66
|
+
* - Removing all tracked elements that were previously added.
|
|
67
|
+
*/
|
|
68
|
+
destroy(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Stores currently focused element and set {@link #isFocused} as `true`.
|
|
71
|
+
*/
|
|
72
|
+
private _focus;
|
|
73
|
+
/**
|
|
74
|
+
* Clears currently focused element and set {@link #isFocused} as `false`.
|
|
75
|
+
* This method uses `setTimeout` to change order of fires `blur` and `focus` events.
|
|
76
|
+
*/
|
|
77
|
+
private _blur;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
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 utils
|
|
11
|
+
*/
|
|
12
|
+
export { default as env } from './env.js';
|
|
13
|
+
export { default as diff, type DiffResult } from './diff.js';
|
|
14
|
+
export { default as fastDiff } from './fastdiff.js';
|
|
15
|
+
export { default as diffToChanges } from './difftochanges.js';
|
|
16
|
+
export { default as mix } from './mix.js';
|
|
17
|
+
export type { Constructor, Mixed } from './mix.js';
|
|
18
|
+
export { default as EmitterMixin, type Emitter, type BaseEvent, type CallbackOptions, type EmitterMixinDelegateChain, type GetCallback, type GetCallbackOptions, type GetEventInfo, type GetNameOrEventInfo } from './emittermixin.js';
|
|
19
|
+
export { default as EventInfo } from './eventinfo.js';
|
|
20
|
+
export { default as ObservableMixin, type Observable, type DecoratedMethodEvent, type ObservableChangeEvent, type ObservableSetEvent } from './observablemixin.js';
|
|
21
|
+
export { default as CKEditorError, logError, logWarning } from './ckeditorerror.js';
|
|
22
|
+
export { default as ElementReplacer } from './elementreplacer.js';
|
|
23
|
+
export { default as abortableDebounce, type AbortableFunc } from './abortabledebounce.js';
|
|
24
|
+
export { default as count } from './count.js';
|
|
25
|
+
export { default as compareArrays } from './comparearrays.js';
|
|
26
|
+
export { default as createElement } from './dom/createelement.js';
|
|
27
|
+
export { default as Config } from './config.js';
|
|
28
|
+
export { default as isIterable } from './isiterable.js';
|
|
29
|
+
export { default as DomEmitterMixin, type DomEmitter } from './dom/emittermixin.js';
|
|
30
|
+
export { default as findClosestScrollableAncestor } from './dom/findclosestscrollableancestor.js';
|
|
31
|
+
export { default as global } from './dom/global.js';
|
|
32
|
+
export { default as getAncestors } from './dom/getancestors.js';
|
|
33
|
+
export { default as getDataFromElement } from './dom/getdatafromelement.js';
|
|
34
|
+
export { default as getBorderWidths } from './dom/getborderwidths.js';
|
|
35
|
+
export { default as isText } from './dom/istext.js';
|
|
36
|
+
export { default as Rect, type RectSource } from './dom/rect.js';
|
|
37
|
+
export { default as ResizeObserver } from './dom/resizeobserver.js';
|
|
38
|
+
export { default as setDataInElement } from './dom/setdatainelement.js';
|
|
39
|
+
export { default as toUnit } from './dom/tounit.js';
|
|
40
|
+
export { default as indexOf } from './dom/indexof.js';
|
|
41
|
+
export { default as insertAt } from './dom/insertat.js';
|
|
42
|
+
export { default as isComment } from './dom/iscomment.js';
|
|
43
|
+
export { default as isNode } from './dom/isnode.js';
|
|
44
|
+
export { default as isRange } from './dom/isrange.js';
|
|
45
|
+
export { default as isValidAttributeName } from './dom/isvalidattributename.js';
|
|
46
|
+
export { default as isVisible } from './dom/isvisible.js';
|
|
47
|
+
export { getOptimalPosition, type Options as PositionOptions, type PositioningFunction, type DomPoint } from './dom/position.js';
|
|
48
|
+
export { default as remove } from './dom/remove.js';
|
|
49
|
+
export * from './dom/scroll.js';
|
|
50
|
+
export * from './keyboard.js';
|
|
51
|
+
export * from './language.js';
|
|
52
|
+
export { default as Locale, type LocaleTranslate, type Translations } from './locale.js';
|
|
53
|
+
export { default as Collection, type CollectionAddEvent, type CollectionChangeEvent, type CollectionRemoveEvent } from './collection.js';
|
|
54
|
+
export { default as first } from './first.js';
|
|
55
|
+
export { default as FocusTracker } from './focustracker.js';
|
|
56
|
+
export { default as KeystrokeHandler } from './keystrokehandler.js';
|
|
57
|
+
export { default as toArray, type ArrayOrItem, type ReadonlyArrayOrItem } from './toarray.js';
|
|
58
|
+
export { default as toMap } from './tomap.js';
|
|
59
|
+
export { default as priorities, type PriorityString } from './priorities.js';
|
|
60
|
+
export { default as retry, exponentialDelay } from './retry.js';
|
|
61
|
+
export { default as insertToPriorityArray } from './inserttopriorityarray.js';
|
|
62
|
+
export { default as spliceArray } from './splicearray.js';
|
|
63
|
+
export { default as uid } from './uid.js';
|
|
64
|
+
export { default as delay, type DelayedFunc } from './delay.js';
|
|
65
|
+
export { default as verifyLicense } from './verifylicense.js';
|
|
66
|
+
export { default as wait } from './wait.js';
|
|
67
|
+
export * from './unicode.js';
|
|
68
|
+
export { default as version, releaseDate } from './version.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
import { type PriorityString } from './priorities.js';
|
|
10
|
+
/**
|
|
11
|
+
* @module utils/inserttopriorityarray
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The priority object descriptor.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const objectWithPriority = {
|
|
18
|
+
* priority: 'high'
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ObjectWithPriority {
|
|
23
|
+
/**
|
|
24
|
+
* Priority of the object.
|
|
25
|
+
*/
|
|
26
|
+
priority: PriorityString;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Inserts any object with priority at correct index by priority so registered objects are always sorted from highest to lowest priority.
|
|
30
|
+
*
|
|
31
|
+
* @param objects Array of objects with priority to insert object to.
|
|
32
|
+
* @param objectToInsert Object with `priority` property.
|
|
33
|
+
*/
|
|
34
|
+
export default function insertToPriorityArray<T extends ObjectWithPriority>(objects: Array<T>, objectToInsert: T): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 utils/isiterable
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Checks if value implements iterator interface.
|
|
14
|
+
*
|
|
15
|
+
* @param value The value to check.
|
|
16
|
+
* @returns True if value implements iterator interface.
|
|
17
|
+
*/
|
|
18
|
+
export default function isIterable(value: any): value is Iterable<any>;
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
* A set of utilities related to keyboard support.
|
|
11
|
+
*
|
|
12
|
+
* @module utils/keyboard
|
|
13
|
+
*/
|
|
14
|
+
import type { LanguageDirection } from './language.js';
|
|
15
|
+
/**
|
|
16
|
+
* An object with `keyName => keyCode` pairs for a set of known keys.
|
|
17
|
+
*
|
|
18
|
+
* Contains:
|
|
19
|
+
*
|
|
20
|
+
* * `a-z`,
|
|
21
|
+
* * `0-9`,
|
|
22
|
+
* * `f1-f12`,
|
|
23
|
+
* * `` ` ``, `-`, `=`, `[`, `]`, `;`, `'`, `,`, `.`, `/`, `\`,
|
|
24
|
+
* * `arrow(left|up|right|bottom)`,
|
|
25
|
+
* * `backspace`, `delete`, `enter`, `esc`, `tab`,
|
|
26
|
+
* * `ctrl`, `cmd`, `shift`, `alt`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const keyCodes: {
|
|
29
|
+
readonly [keyCode: string]: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Converts a key name or {@link module:utils/keyboard~KeystrokeInfo keystroke info} into a key code.
|
|
33
|
+
*
|
|
34
|
+
* Note: Key names are matched with {@link module:utils/keyboard#keyCodes} in a case-insensitive way.
|
|
35
|
+
*
|
|
36
|
+
* @param key A key name (see {@link module:utils/keyboard#keyCodes}) or a keystroke data object.
|
|
37
|
+
* @returns Key or keystroke code.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getCode(key: string | Readonly<KeystrokeInfo>): number;
|
|
40
|
+
/**
|
|
41
|
+
* Parses the keystroke and returns a keystroke code that will match the code returned by
|
|
42
|
+
* {@link module:utils/keyboard~getCode} for the corresponding {@link module:utils/keyboard~KeystrokeInfo keystroke info}.
|
|
43
|
+
*
|
|
44
|
+
* The keystroke can be passed in two formats:
|
|
45
|
+
*
|
|
46
|
+
* * as a single string – e.g. `ctrl + A`,
|
|
47
|
+
* * as an array of {@link module:utils/keyboard~keyCodes known key names} and key codes – e.g.:
|
|
48
|
+
* * `[ 'ctrl', 32 ]` (ctrl + space),
|
|
49
|
+
* * `[ 'ctrl', 'a' ]` (ctrl + A).
|
|
50
|
+
*
|
|
51
|
+
* Note: Key names are matched with {@link module:utils/keyboard#keyCodes} in a case-insensitive way.
|
|
52
|
+
*
|
|
53
|
+
* Note: Only keystrokes with a single non-modifier key are supported (e.g. `ctrl+A` is OK, but `ctrl+A+B` is not).
|
|
54
|
+
*
|
|
55
|
+
* Note: On macOS, keystroke handling is translating the `Ctrl` key to the `Cmd` key and handling only that keystroke.
|
|
56
|
+
* For example, a registered keystroke `Ctrl+A` will be translated to `Cmd+A` on macOS. To disable the translation of some keystroke,
|
|
57
|
+
* use the forced modifier: `Ctrl!+A` (note the exclamation mark).
|
|
58
|
+
*
|
|
59
|
+
* @param keystroke The keystroke definition.
|
|
60
|
+
* @returns Keystroke code.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseKeystroke(keystroke: string | ReadonlyArray<number | string>): number;
|
|
63
|
+
/**
|
|
64
|
+
* Translates any keystroke string text like `"Ctrl+A"` to an
|
|
65
|
+
* environment–specific keystroke, i.e. `"⌘A"` on macOS.
|
|
66
|
+
*
|
|
67
|
+
* @param keystroke The keystroke text.
|
|
68
|
+
* @returns The keystroke text specific for the environment.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getEnvKeystrokeText(keystroke: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Returns `true` if the provided key code represents one of the arrow keys.
|
|
73
|
+
*
|
|
74
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
75
|
+
*/
|
|
76
|
+
export declare function isArrowKeyCode(keyCode: number): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* String representing a direction of an arrow key kode.
|
|
79
|
+
*/
|
|
80
|
+
export type ArrowKeyCodeDirection = 'left' | 'up' | 'right' | 'down';
|
|
81
|
+
/**
|
|
82
|
+
* Returns the direction in which the {@link module:engine/model/documentselection~DocumentSelection selection}
|
|
83
|
+
* will move when the provided arrow key code is pressed considering the language direction of the editor content.
|
|
84
|
+
*
|
|
85
|
+
* For instance, in right–to–left (RTL) content languages, pressing the left arrow means moving the selection right (forward)
|
|
86
|
+
* in the model structure. Similarly, pressing the right arrow moves the selection left (backward).
|
|
87
|
+
*
|
|
88
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
89
|
+
* @param contentLanguageDirection The content language direction, corresponding to
|
|
90
|
+
* {@link module:utils/locale~Locale#contentLanguageDirection}.
|
|
91
|
+
* @returns Localized arrow direction or `undefined` for non-arrow key codes.
|
|
92
|
+
*/
|
|
93
|
+
export declare function getLocalizedArrowKeyCodeDirection(keyCode: number, contentLanguageDirection: LanguageDirection): ArrowKeyCodeDirection | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Determines if the provided key code moves the {@link module:engine/model/documentselection~DocumentSelection selection}
|
|
96
|
+
* forward or backward considering the language direction of the editor content.
|
|
97
|
+
*
|
|
98
|
+
* For instance, in right–to–left (RTL) languages, pressing the left arrow means moving forward
|
|
99
|
+
* in the model structure. Similarly, pressing the right arrow moves the selection backward.
|
|
100
|
+
*
|
|
101
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
102
|
+
* @param contentLanguageDirection The content language direction, corresponding to
|
|
103
|
+
* {@link module:utils/locale~Locale#contentLanguageDirection}.
|
|
104
|
+
*/
|
|
105
|
+
export declare function isForwardArrowKeyCode(keyCode: number, contentLanguageDirection: LanguageDirection): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Information about the keystroke.
|
|
108
|
+
*/
|
|
109
|
+
export interface KeystrokeInfo {
|
|
110
|
+
/**
|
|
111
|
+
* The [key code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode).
|
|
112
|
+
*/
|
|
113
|
+
keyCode: number;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the <kbd>Alt</kbd> modifier was pressed.
|
|
116
|
+
*/
|
|
117
|
+
altKey: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the <kbd>Cmd</kbd> modifier was pressed.
|
|
120
|
+
*/
|
|
121
|
+
metaKey: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the <kbd>Ctrl</kbd> modifier was pressed.
|
|
124
|
+
*/
|
|
125
|
+
ctrlKey: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the <kbd>Shift</kbd> modifier was pressed.
|
|
128
|
+
*/
|
|
129
|
+
shiftKey: boolean;
|
|
130
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
import type { Emitter } from './emittermixin.js';
|
|
10
|
+
import { type KeystrokeInfo } from './keyboard.js';
|
|
11
|
+
import type { PriorityString } from './priorities.js';
|
|
12
|
+
/**
|
|
13
|
+
* Keystroke handler allows registering callbacks for given keystrokes.
|
|
14
|
+
*
|
|
15
|
+
* The most frequent use of this class is through the {@link module:core/editor/editor~Editor#keystrokes `editor.keystrokes`}
|
|
16
|
+
* property. It allows listening to keystrokes executed in the editing view:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* editor.keystrokes.set( 'Ctrl+A', ( keyEvtData, cancel ) => {
|
|
20
|
+
* console.log( 'Ctrl+A has been pressed' );
|
|
21
|
+
* cancel();
|
|
22
|
+
* } );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* However, this utility class can be used in various part of the UI. For instance, a certain {@link module:ui/view~View}
|
|
26
|
+
* can use it like this:
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* class MyView extends View {
|
|
30
|
+
* constructor() {
|
|
31
|
+
* this.keystrokes = new KeystrokeHandler();
|
|
32
|
+
*
|
|
33
|
+
* this.keystrokes.set( 'tab', handleTabKey );
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* render() {
|
|
37
|
+
* super.render();
|
|
38
|
+
*
|
|
39
|
+
* this.keystrokes.listenTo( this.element );
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* That keystroke handler will listen to `keydown` events fired in this view's main element.
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export default class KeystrokeHandler {
|
|
48
|
+
/**
|
|
49
|
+
* Listener used to listen to events for easier keystroke handler destruction.
|
|
50
|
+
*/
|
|
51
|
+
private readonly _listener;
|
|
52
|
+
/**
|
|
53
|
+
* Creates an instance of the keystroke handler.
|
|
54
|
+
*/
|
|
55
|
+
constructor();
|
|
56
|
+
/**
|
|
57
|
+
* Starts listening for `keydown` events from a given emitter.
|
|
58
|
+
*/
|
|
59
|
+
listenTo(emitter: Emitter | HTMLElement | Window): void;
|
|
60
|
+
/**
|
|
61
|
+
* Registers a handler for the specified keystroke.
|
|
62
|
+
*
|
|
63
|
+
* @param keystroke Keystroke defined in a format accepted by
|
|
64
|
+
* the {@link module:utils/keyboard~parseKeystroke} function.
|
|
65
|
+
* @param callback A function called with the
|
|
66
|
+
* {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
|
|
67
|
+
* a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
|
|
68
|
+
* @param options Additional options.
|
|
69
|
+
* @param options.priority The priority of the keystroke
|
|
70
|
+
* callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
|
|
71
|
+
* are called in the order they were added.
|
|
72
|
+
*/
|
|
73
|
+
set(keystroke: string | ReadonlyArray<string | number>, callback: (ev: KeyboardEvent, cancel: () => void) => void, options?: {
|
|
74
|
+
readonly priority?: PriorityString;
|
|
75
|
+
}): void;
|
|
76
|
+
/**
|
|
77
|
+
* Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
|
|
78
|
+
*
|
|
79
|
+
* @param keyEvtData Key event data.
|
|
80
|
+
* @returns Whether the keystroke was handled.
|
|
81
|
+
*/
|
|
82
|
+
press(keyEvtData: Readonly<KeystrokeInfo>): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Stops listening to `keydown` events from the given emitter.
|
|
85
|
+
*/
|
|
86
|
+
stopListening(emitter?: Emitter | HTMLElement | Window): void;
|
|
87
|
+
/**
|
|
88
|
+
* Destroys the keystroke handler.
|
|
89
|
+
*/
|
|
90
|
+
destroy(): void;
|
|
91
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 utils/language
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* String representing a language direction.
|
|
14
|
+
*/
|
|
15
|
+
export type LanguageDirection = 'ltr' | 'rtl';
|
|
16
|
+
/**
|
|
17
|
+
* Helps determine whether a language text direction is LTR or RTL.
|
|
18
|
+
*
|
|
19
|
+
* @param languageCode The ISO 639-1 or ISO 639-2 language code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getLanguageDirection(languageCode: string): LanguageDirection;
|