@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-typing",
3
- "version": "35.2.1",
3
+ "version": "35.3.0",
4
4
  "description": "Typing feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,24 +12,32 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-core": "^35.2.1",
16
- "@ckeditor/ckeditor5-engine": "^35.2.1",
17
- "@ckeditor/ckeditor5-utils": "^35.2.1",
15
+ "@ckeditor/ckeditor5-core": "^35.3.0",
16
+ "@ckeditor/ckeditor5-engine": "^35.3.0",
17
+ "@ckeditor/ckeditor5-utils": "^35.3.0",
18
18
  "lodash-es": "^4.17.15"
19
19
  },
20
20
  "devDependencies": {
21
- "@ckeditor/ckeditor5-basic-styles": "^35.2.1",
22
- "@ckeditor/ckeditor5-block-quote": "^35.2.1",
23
- "@ckeditor/ckeditor5-editor-classic": "^35.2.1",
24
- "@ckeditor/ckeditor5-enter": "^35.2.1",
25
- "@ckeditor/ckeditor5-essentials": "^35.2.1",
26
- "@ckeditor/ckeditor5-heading": "^35.2.1",
27
- "@ckeditor/ckeditor5-image": "^35.2.1",
28
- "@ckeditor/ckeditor5-link": "^35.2.1",
29
- "@ckeditor/ckeditor5-list": "^35.2.1",
30
- "@ckeditor/ckeditor5-paragraph": "^35.2.1",
31
- "@ckeditor/ckeditor5-undo": "^35.2.1",
32
- "@ckeditor/ckeditor5-code-block": "^35.2.1"
21
+ "@ckeditor/ckeditor5-autoformat": "^35.3.0",
22
+ "@ckeditor/ckeditor5-basic-styles": "^35.3.0",
23
+ "@ckeditor/ckeditor5-block-quote": "^35.3.0",
24
+ "@ckeditor/ckeditor5-code-block": "^35.3.0",
25
+ "@ckeditor/ckeditor5-editor-classic": "^35.3.0",
26
+ "@ckeditor/ckeditor5-enter": "^35.3.0",
27
+ "@ckeditor/ckeditor5-essentials": "^35.3.0",
28
+ "@ckeditor/ckeditor5-heading": "^35.3.0",
29
+ "@ckeditor/ckeditor5-image": "^35.3.0",
30
+ "@ckeditor/ckeditor5-indent": "^35.3.0",
31
+ "@ckeditor/ckeditor5-link": "^35.3.0",
32
+ "@ckeditor/ckeditor5-list": "^35.3.0",
33
+ "@ckeditor/ckeditor5-media-embed": "^35.3.0",
34
+ "@ckeditor/ckeditor5-mention": "^35.3.0",
35
+ "@ckeditor/ckeditor5-paragraph": "^35.3.0",
36
+ "@ckeditor/ckeditor5-table": "^35.3.0",
37
+ "@ckeditor/ckeditor5-undo": "^35.3.0",
38
+ "typescript": "^4.8.4",
39
+ "webpack": "^5.58.1",
40
+ "webpack-cli": "^4.9.0"
33
41
  },
34
42
  "engines": {
35
43
  "node": ">=14.0.0",
@@ -46,9 +54,14 @@
46
54
  },
47
55
  "files": [
48
56
  "lang",
49
- "src",
57
+ "src/**/*.js",
58
+ "src/**/*.d.ts",
50
59
  "theme",
51
60
  "ckeditor5-metadata.json",
52
61
  "CHANGELOG.md"
53
- ]
62
+ ],
63
+ "scripts": {
64
+ "build": "tsc -p ./tsconfig.release.json",
65
+ "postversion": "npm run build"
66
+ }
54
67
  }
package/src/delete.js CHANGED
@@ -2,138 +2,83 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module typing/delete
8
7
  */
9
-
10
8
  import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11
9
  import DeleteCommand from './deletecommand';
12
10
  import DeleteObserver from './deleteobserver';
13
- import env from '@ckeditor/ckeditor5-utils/src/env';
14
-
15
11
  /**
16
- * The delete and backspace feature. Handles the <kbd>Delete</kbd> and <kbd>Backspace</kbd> keys in the editor.
12
+ * The delete and backspace feature. Handles keys such as <kbd>Delete</kbd> and <kbd>Backspace</kbd>, other
13
+ * keystrokes and user actions that result in deleting content in the editor.
17
14
  *
18
15
  * @extends module:core/plugin~Plugin
19
16
  */
20
17
  export default class Delete extends Plugin {
21
- /**
22
- * Whether pressing backspace should trigger undo action
23
- *
24
- * @private
25
- * @member {Boolean} #_undoOnBackspace
26
- */
27
-
28
- /**
29
- * @inheritDoc
30
- */
31
- static get pluginName() {
32
- return 'Delete';
33
- }
34
-
35
- init() {
36
- const editor = this.editor;
37
- const view = editor.editing.view;
38
- const viewDocument = view.document;
39
- const modelDocument = editor.model.document;
40
-
41
- view.addObserver( DeleteObserver );
42
-
43
- this._undoOnBackspace = false;
44
-
45
- const deleteForwardCommand = new DeleteCommand( editor, 'forward' );
46
-
47
- // Register `deleteForward` command and add `forwardDelete` command as an alias for backward compatibility.
48
- editor.commands.add( 'deleteForward', deleteForwardCommand );
49
- editor.commands.add( 'forwardDelete', deleteForwardCommand );
50
-
51
- editor.commands.add( 'delete', new DeleteCommand( editor, 'backward' ) );
52
-
53
- this.listenTo( viewDocument, 'delete', ( evt, data ) => {
54
- const deleteCommandParams = { unit: data.unit, sequence: data.sequence };
55
-
56
- // If a specific (view) selection to remove was set, convert it to a model selection and set as a parameter for `DeleteCommand`.
57
- if ( data.selectionToRemove ) {
58
- const modelSelection = editor.model.createSelection();
59
- const ranges = [];
60
-
61
- for ( const viewRange of data.selectionToRemove.getRanges() ) {
62
- ranges.push( editor.editing.mapper.toModelRange( viewRange ) );
63
- }
64
-
65
- modelSelection.setTo( ranges );
66
-
67
- deleteCommandParams.selection = modelSelection;
68
- }
69
-
70
- editor.execute( data.direction == 'forward' ? 'deleteForward' : 'delete', deleteCommandParams );
71
-
72
- data.preventDefault();
73
-
74
- view.scrollToTheSelection();
75
- }, { priority: 'low' } );
76
-
77
- // Android IMEs have a quirk - they change DOM selection after the input changes were performed by the browser.
78
- // This happens on `keyup` event. Android doesn't know anything about our deletion and selection handling. Even if the selection
79
- // was changed during input events, IME remembers the position where the selection "should" be placed and moves it there.
80
- //
81
- // To prevent incorrect selection, we save the selection after deleting here and then re-set it on `keyup`. This has to be done
82
- // on DOM selection level, because on `keyup` the model selection is still the same as it was just after deletion, so it
83
- // wouldn't be changed and the fix would do nothing.
84
- //
85
- if ( env.isAndroid ) {
86
- let domSelectionAfterDeletion = null;
87
-
88
- this.listenTo( viewDocument, 'delete', ( evt, data ) => {
89
- const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
90
-
91
- domSelectionAfterDeletion = {
92
- anchorNode: domSelection.anchorNode,
93
- anchorOffset: domSelection.anchorOffset,
94
- focusNode: domSelection.focusNode,
95
- focusOffset: domSelection.focusOffset
96
- };
97
- }, { priority: 'lowest' } );
98
-
99
- this.listenTo( viewDocument, 'keyup', ( evt, data ) => {
100
- if ( domSelectionAfterDeletion ) {
101
- const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
102
-
103
- domSelection.collapse( domSelectionAfterDeletion.anchorNode, domSelectionAfterDeletion.anchorOffset );
104
- domSelection.extend( domSelectionAfterDeletion.focusNode, domSelectionAfterDeletion.focusOffset );
105
-
106
- domSelectionAfterDeletion = null;
107
- }
108
- } );
109
- }
110
-
111
- if ( this.editor.plugins.has( 'UndoEditing' ) ) {
112
- this.listenTo( viewDocument, 'delete', ( evt, data ) => {
113
- if ( this._undoOnBackspace && data.direction == 'backward' && data.sequence == 1 && data.unit == 'codePoint' ) {
114
- this._undoOnBackspace = false;
115
-
116
- editor.execute( 'undo' );
117
-
118
- data.preventDefault();
119
- evt.stop();
120
- }
121
- }, { context: '$capture' } );
122
-
123
- this.listenTo( modelDocument, 'change', () => {
124
- this._undoOnBackspace = false;
125
- } );
126
- }
127
- }
128
-
129
- /**
130
- * If the next user action after calling this method is pressing backspace, it would undo the last change.
131
- *
132
- * Requires {@link module:undo/undoediting~UndoEditing} plugin. If not loaded, does nothing.
133
- */
134
- requestUndoOnBackspace() {
135
- if ( this.editor.plugins.has( 'UndoEditing' ) ) {
136
- this._undoOnBackspace = true;
137
- }
138
- }
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName() {
22
+ return 'Delete';
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init() {
28
+ const editor = this.editor;
29
+ const view = editor.editing.view;
30
+ const viewDocument = view.document;
31
+ const modelDocument = editor.model.document;
32
+ view.addObserver(DeleteObserver);
33
+ this._undoOnBackspace = false;
34
+ const deleteForwardCommand = new DeleteCommand(editor, 'forward');
35
+ // Register `deleteForward` command and add `forwardDelete` command as an alias for backward compatibility.
36
+ editor.commands.add('deleteForward', deleteForwardCommand);
37
+ editor.commands.add('forwardDelete', deleteForwardCommand);
38
+ editor.commands.add('delete', new DeleteCommand(editor, 'backward'));
39
+ this.listenTo(viewDocument, 'delete', (evt, data) => {
40
+ // When not in composition, we handle the action, so prevent the default one.
41
+ // When in composition, it's the browser who modify the DOM (renderer is disabled).
42
+ if (!viewDocument.isComposing) {
43
+ data.preventDefault();
44
+ }
45
+ const { direction, sequence, selectionToRemove, unit } = data;
46
+ const commandName = direction === 'forward' ? 'deleteForward' : 'delete';
47
+ const commandData = { sequence };
48
+ if (unit == 'selection') {
49
+ const modelRanges = Array.from(selectionToRemove.getRanges()).map(viewRange => {
50
+ return editor.editing.mapper.toModelRange(viewRange);
51
+ });
52
+ commandData.selection = editor.model.createSelection(modelRanges);
53
+ }
54
+ else {
55
+ commandData.unit = unit;
56
+ }
57
+ editor.execute(commandName, commandData);
58
+ view.scrollToTheSelection();
59
+ }, { priority: 'low' });
60
+ if (this.editor.plugins.has('UndoEditing')) {
61
+ this.listenTo(viewDocument, 'delete', (evt, data) => {
62
+ if (this._undoOnBackspace && data.direction == 'backward' && data.sequence == 1 && data.unit == 'codePoint') {
63
+ this._undoOnBackspace = false;
64
+ editor.execute('undo');
65
+ data.preventDefault();
66
+ evt.stop();
67
+ }
68
+ }, { context: '$capture' });
69
+ this.listenTo(modelDocument, 'change', () => {
70
+ this._undoOnBackspace = false;
71
+ });
72
+ }
73
+ }
74
+ /**
75
+ * If the next user action after calling this method is pressing backspace, it would undo the last change.
76
+ *
77
+ * Requires {@link module:undo/undoediting~UndoEditing} plugin. If not loaded, does nothing.
78
+ */
79
+ requestUndoOnBackspace() {
80
+ if (this.editor.plugins.has('UndoEditing')) {
81
+ this._undoOnBackspace = true;
82
+ }
83
+ }
139
84
  }