@ckeditor/ckeditor5-typing 35.2.1 → 35.3.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.
@@ -1,104 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, 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
- /**
7
- * @module typing/utils/utils
8
- */
9
-
10
- import diff from '@ckeditor/ckeditor5-utils/src/diff';
11
- import diffToChanges from '@ckeditor/ckeditor5-utils/src/difftochanges';
12
- import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
13
-
14
- /**
15
- * Returns true if container children have mutated or more than a single text node was changed.
16
- *
17
- * @private
18
- * @param {Array.<module:engine/view/observer/mutationobserver~MutatedText|
19
- * module:engine/view/observer/mutationobserver~MutatedChildren>} mutations
20
- * @returns {Boolean}
21
- */
22
- export function containerChildrenMutated( mutations ) {
23
- if ( mutations.length == 0 ) {
24
- return false;
25
- }
26
-
27
- // Check if there is any mutation of `children` type or any mutation that changes more than one text node.
28
- for ( const mutation of mutations ) {
29
- if ( mutation.type === 'children' && !getSingleTextNodeChange( mutation ) ) {
30
- return true;
31
- }
32
- }
33
-
34
- return false;
35
- }
36
-
37
- /**
38
- * Returns change made to a single text node.
39
- *
40
- * @private
41
- * @param {module:engine/view/observer/mutationobserver~MutatedText|
42
- * module:engine/view/observer/mutationobserver~MutatedChildren} mutation
43
- * @returns {Object|undefined} Change object (see {@link module:utils/difftochanges~diffToChanges} output)
44
- * or undefined if more than a single text node was changed.
45
- */
46
- export function getSingleTextNodeChange( mutation ) {
47
- // One new node.
48
- if ( mutation.newChildren.length - mutation.oldChildren.length != 1 ) {
49
- return;
50
- }
51
-
52
- // Which is text.
53
- const diffResult = diff( mutation.oldChildren, mutation.newChildren, compareChildNodes );
54
- const changes = diffToChanges( diffResult, mutation.newChildren );
55
-
56
- // In case of [ delete, insert, insert ] the previous check will not exit.
57
- if ( changes.length > 1 ) {
58
- return;
59
- }
60
-
61
- const change = changes[ 0 ];
62
-
63
- // Which is text.
64
- if ( !( !!change.values[ 0 ] && change.values[ 0 ].is( '$text' ) ) ) {
65
- return;
66
- }
67
-
68
- return change;
69
- }
70
-
71
- /**
72
- * Checks whether two view nodes are identical, which means they are the same object
73
- * or contain exactly same data (in case of text nodes).
74
- *
75
- * @private
76
- * @param {module:engine/view/node~Node} oldChild
77
- * @param {module:engine/view/node~Node} newChild
78
- * @returns {Boolean}
79
- */
80
- export function compareChildNodes( oldChild, newChild ) {
81
- if ( !!oldChild && oldChild.is( '$text' ) && !!newChild && newChild.is( '$text' ) ) {
82
- return oldChild.data === newChild.data;
83
- } else {
84
- return oldChild === newChild;
85
- }
86
- }
87
-
88
- /**
89
- * Checks if <kbd>Shift</kbd> + <kbd>Delete</kbd> keystroke was pressed on a non-collapsed selection.
90
- *
91
- * This key combination has a special meaning on Windows machines and it should work in the same way as the `cut` event on a non-collapsed
92
- * selection.
93
- *
94
- * @param {module:engine/view/observer/domeventdata~DomEventData} domEventData Event data.
95
- * @param {module:engine/view/document~Document} document The document instance on which the event has been fired.
96
- * @returns {Boolean}
97
- */
98
- export function isShiftDeleteOnNonCollapsedSelection( domEventData, document ) {
99
- const selection = document.selection;
100
- const isShiftDelete = domEventData.shiftKey && domEventData.keyCode === keyCodes.delete;
101
- const isNonCollapsedSelection = !selection.isCollapsed;
102
-
103
- return isShiftDelete && isNonCollapsedSelection;
104
- }