@ckeditor/ckeditor5-typing 47.6.1-alpha.1 → 48.0.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.
Files changed (41) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +1 -1
  3. package/dist/index.css +3 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/{src → dist}/texttransformation.d.ts +3 -1
  8. package/package.json +22 -41
  9. package/src/augmentation.js +0 -5
  10. package/src/delete.js +0 -122
  11. package/src/deletecommand.js +0 -212
  12. package/src/deleteobserver.js +0 -262
  13. package/src/index.js +0 -21
  14. package/src/input.js +0 -486
  15. package/src/inserttextcommand.js +0 -87
  16. package/src/inserttextobserver.js +0 -112
  17. package/src/texttransformation.js +0 -237
  18. package/src/textwatcher.js +0 -123
  19. package/src/twostepcaretmovement.js +0 -661
  20. package/src/typing.js +0 -33
  21. package/src/typingconfig.js +0 -5
  22. package/src/utils/changebuffer.js +0 -148
  23. package/src/utils/findattributerange.js +0 -41
  24. package/src/utils/getlasttextline.js +0 -43
  25. package/src/utils/inlinehighlight.js +0 -74
  26. /package/{src → dist}/augmentation.d.ts +0 -0
  27. /package/{src → dist}/delete.d.ts +0 -0
  28. /package/{src → dist}/deletecommand.d.ts +0 -0
  29. /package/{src → dist}/deleteobserver.d.ts +0 -0
  30. /package/{src → dist}/index.d.ts +0 -0
  31. /package/{src → dist}/input.d.ts +0 -0
  32. /package/{src → dist}/inserttextcommand.d.ts +0 -0
  33. /package/{src → dist}/inserttextobserver.d.ts +0 -0
  34. /package/{src → dist}/textwatcher.d.ts +0 -0
  35. /package/{src → dist}/twostepcaretmovement.d.ts +0 -0
  36. /package/{src → dist}/typing.d.ts +0 -0
  37. /package/{src → dist}/typingconfig.d.ts +0 -0
  38. /package/{src → dist}/utils/changebuffer.d.ts +0 -0
  39. /package/{src → dist}/utils/findattributerange.d.ts +0 -0
  40. /package/{src → dist}/utils/getlasttextline.d.ts +0 -0
  41. /package/{src → dist}/utils/inlinehighlight.d.ts +0 -0
@@ -6,6 +6,8 @@
6
6
  * @module typing/texttransformation
7
7
  */
8
8
  import { Plugin, type Editor } from '@ckeditor/ckeditor5-core';
9
+ import { Delete } from './delete.js';
10
+ import { Input } from './input.js';
9
11
  /**
10
12
  * The text transformation plugin.
11
13
  */
@@ -13,7 +15,7 @@ export declare class TextTransformation extends Plugin {
13
15
  /**
14
16
  * @inheritDoc
15
17
  */
16
- static get requires(): readonly ["Delete", "Input"];
18
+ static get requires(): readonly [typeof Delete, typeof Input];
17
19
  /**
18
20
  * @inheritDoc
19
21
  */
package/package.json CHANGED
@@ -1,59 +1,40 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-typing",
3
- "version": "47.6.1-alpha.1",
3
+ "version": "48.0.0-alpha.0",
4
4
  "description": "Typing feature for CKEditor 5.",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "author": "CKSource (http://cksource.com/)",
7
+ "homepage": "https://ckeditor.com/ckeditor-5",
8
+ "bugs": "https://github.com/ckeditor/ckeditor5/issues",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ckeditor/ckeditor5.git",
12
+ "directory": "packages/ckeditor5-typing"
13
+ },
5
14
  "keywords": [
6
15
  "ckeditor",
7
16
  "ckeditor5",
8
17
  "ckeditor 5",
9
18
  "ckeditor5-feature",
10
- "ckeditor5-plugin",
11
- "ckeditor5-dll"
19
+ "ckeditor5-plugin"
12
20
  ],
13
21
  "type": "module",
14
- "main": "src/index.js",
15
- "dependencies": {
16
- "@ckeditor/ckeditor5-core": "47.6.1-alpha.1",
17
- "@ckeditor/ckeditor5-engine": "47.6.1-alpha.1",
18
- "@ckeditor/ckeditor5-utils": "47.6.1-alpha.1",
19
- "es-toolkit": "1.39.5"
22
+ "main": "./dist/index.js",
23
+ "exports": {
24
+ ".": "./dist/index.js",
25
+ "./dist/*": "./dist/*",
26
+ "./package.json": "./package.json"
20
27
  },
21
- "author": "CKSource (http://cksource.com/)",
22
- "license": "SEE LICENSE IN LICENSE.md",
23
- "homepage": "https://ckeditor.com/ckeditor-5",
24
- "bugs": "https://github.com/ckeditor/ckeditor5/issues",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/ckeditor/ckeditor5.git",
28
- "directory": "packages/ckeditor5-typing"
28
+ "dependencies": {
29
+ "@ckeditor/ckeditor5-core": "48.0.0-alpha.0",
30
+ "@ckeditor/ckeditor5-engine": "48.0.0-alpha.0",
31
+ "@ckeditor/ckeditor5-utils": "48.0.0-alpha.0",
32
+ "es-toolkit": "1.45.1"
29
33
  },
30
34
  "files": [
31
35
  "dist",
32
- "lang",
33
- "src/**/*.js",
34
- "src/**/*.d.ts",
35
- "theme",
36
36
  "ckeditor5-metadata.json",
37
37
  "CHANGELOG.md"
38
38
  ],
39
- "types": "src/index.d.ts",
40
- "exports": {
41
- ".": {
42
- "types": "./src/index.d.ts",
43
- "import": "./src/index.js",
44
- "default": "./src/index.js"
45
- },
46
- "./dist/*": {
47
- "types": "./src/index.d.ts",
48
- "import": "./dist/*",
49
- "default": "./dist/*"
50
- },
51
- "./src/*": {
52
- "types": "./src/*.d.ts",
53
- "import": "./src/*",
54
- "default": "./src/*"
55
- },
56
- "./ckeditor5-metadata.json": "./ckeditor5-metadata.json",
57
- "./package.json": "./package.json"
58
- }
39
+ "types": "./dist/index.d.ts"
59
40
  }
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
package/src/delete.js DELETED
@@ -1,122 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module typing/delete
7
- */
8
- import { _tryFixingModelRange, BubblingEventInfo, ViewDocumentDomEventData } from '@ckeditor/ckeditor5-engine';
9
- import { Plugin } from '@ckeditor/ckeditor5-core';
10
- import { keyCodes } from '@ckeditor/ckeditor5-utils';
11
- import { DeleteCommand } from './deletecommand.js';
12
- import { DeleteObserver } from './deleteobserver.js';
13
- /**
14
- * The delete and backspace feature. Handles keys such as <kbd>Delete</kbd> and <kbd>Backspace</kbd>, other
15
- * keystrokes and user actions that result in deleting content in the editor.
16
- */
17
- export class Delete extends Plugin {
18
- /**
19
- * Whether pressing backspace should trigger undo action
20
- */
21
- _undoOnBackspace;
22
- /**
23
- * @inheritDoc
24
- */
25
- static get pluginName() {
26
- return 'Delete';
27
- }
28
- /**
29
- * @inheritDoc
30
- */
31
- static get isOfficialPlugin() {
32
- return true;
33
- }
34
- /**
35
- * @inheritDoc
36
- */
37
- init() {
38
- const editor = this.editor;
39
- const view = editor.editing.view;
40
- const viewDocument = view.document;
41
- const modelDocument = editor.model.document;
42
- view.addObserver(DeleteObserver);
43
- this._undoOnBackspace = false;
44
- const deleteForwardCommand = new DeleteCommand(editor, 'forward');
45
- // Register `deleteForward` command and add `forwardDelete` command as an alias for backward compatibility.
46
- editor.commands.add('deleteForward', deleteForwardCommand);
47
- editor.commands.add('forwardDelete', deleteForwardCommand);
48
- editor.commands.add('delete', new DeleteCommand(editor, 'backward'));
49
- this.listenTo(viewDocument, 'delete', (evt, data) => {
50
- // When not in composition, we handle the action, so prevent the default one.
51
- // When in composition, it's the browser who modify the DOM (renderer is disabled).
52
- if (!viewDocument.isComposing) {
53
- data.preventDefault();
54
- }
55
- const { direction, sequence, selectionToRemove, unit } = data;
56
- const commandName = direction === 'forward' ? 'deleteForward' : 'delete';
57
- const commandData = { sequence };
58
- if (unit == 'selection') {
59
- const modelRanges = Array.from(selectionToRemove.getRanges())
60
- .map(viewRange => editor.editing.mapper.toModelRange(viewRange))
61
- .map(modelRange => _tryFixingModelRange(modelRange, editor.model.schema) || modelRange);
62
- commandData.selection = editor.model.createSelection(modelRanges);
63
- }
64
- else {
65
- commandData.unit = unit;
66
- }
67
- editor.execute(commandName, commandData);
68
- view.scrollToTheSelection();
69
- }, { priority: 'low' });
70
- // Handle the Backspace key while at the beginning of a nested editable. See https://github.com/ckeditor/ckeditor5/issues/17383.
71
- this.listenTo(viewDocument, 'keydown', (evt, data) => {
72
- if (viewDocument.isComposing ||
73
- data.keyCode != keyCodes.backspace ||
74
- !modelDocument.selection.isCollapsed) {
75
- return;
76
- }
77
- const ancestorLimit = editor.model.schema.getLimitElement(modelDocument.selection);
78
- const limitStartPosition = editor.model.createPositionAt(ancestorLimit, 0);
79
- if (limitStartPosition.isTouching(modelDocument.selection.getFirstPosition())) {
80
- // Stop the beforeinput event as it could be invalid.
81
- data.preventDefault();
82
- // Create a fake delete event so all features can act on it and the target range is proper.
83
- const modelRange = editor.model.schema.getNearestSelectionRange(limitStartPosition, 'forward');
84
- if (!modelRange) {
85
- return;
86
- }
87
- const viewSelection = view.createSelection(editor.editing.mapper.toViewRange(modelRange));
88
- const targetRange = viewSelection.getFirstRange();
89
- const eventInfo = new BubblingEventInfo(document, 'delete', targetRange);
90
- const deleteData = {
91
- unit: 'selection',
92
- direction: 'backward',
93
- selectionToRemove: viewSelection
94
- };
95
- viewDocument.fire(eventInfo, new ViewDocumentDomEventData(view, data.domEvent, deleteData));
96
- }
97
- });
98
- if (this.editor.plugins.has('UndoEditing')) {
99
- this.listenTo(viewDocument, 'delete', (evt, data) => {
100
- if (this._undoOnBackspace && data.direction == 'backward' && data.sequence == 1 && data.unit == 'codePoint') {
101
- this._undoOnBackspace = false;
102
- editor.execute('undo');
103
- data.preventDefault();
104
- evt.stop();
105
- }
106
- }, { context: '$capture' });
107
- this.listenTo(modelDocument, 'change', () => {
108
- this._undoOnBackspace = false;
109
- });
110
- }
111
- }
112
- /**
113
- * If the next user action after calling this method is pressing backspace, it would undo the last change.
114
- *
115
- * Requires {@link module:undo/undoediting~UndoEditing} plugin. If not loaded, does nothing.
116
- */
117
- requestUndoOnBackspace() {
118
- if (this.editor.plugins.has('UndoEditing')) {
119
- this._undoOnBackspace = true;
120
- }
121
- }
122
- }
@@ -1,212 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module typing/deletecommand
7
- */
8
- import { Command } from '@ckeditor/ckeditor5-core';
9
- import { count } from '@ckeditor/ckeditor5-utils';
10
- import { TypingChangeBuffer } from './utils/changebuffer.js';
11
- // @if CK_DEBUG_TYPING // const { _buildLogMessage } = require( '@ckeditor/ckeditor5-engine/src/dev-utils/utils.js' );
12
- /**
13
- * The delete command. Used by the {@link module:typing/delete~Delete delete feature} to handle the <kbd>Delete</kbd> and
14
- * <kbd>Backspace</kbd> keys.
15
- */
16
- export class DeleteCommand extends Command {
17
- /**
18
- * The directionality of the delete describing in what direction it should
19
- * consume the content when the selection is collapsed.
20
- */
21
- direction;
22
- /**
23
- * Delete's change buffer used to group subsequent changes into batches.
24
- */
25
- _buffer;
26
- /**
27
- * Creates an instance of the command.
28
- *
29
- * @param direction The directionality of the delete describing in what direction it
30
- * should consume the content when the selection is collapsed.
31
- */
32
- constructor(editor, direction) {
33
- super(editor);
34
- this.direction = direction;
35
- this._buffer = new TypingChangeBuffer(editor.model, editor.config.get('typing.undoStep'));
36
- // Since this command may execute on different selectable than selection, it should be checked directly in execute block.
37
- this._isEnabledBasedOnSelection = false;
38
- }
39
- /**
40
- * The current change buffer.
41
- */
42
- get buffer() {
43
- return this._buffer;
44
- }
45
- /**
46
- * Executes the delete command. Depending on whether the selection is collapsed or not, deletes its content
47
- * or a piece of content in the {@link #direction defined direction}.
48
- *
49
- * @fires execute
50
- * @param options The command options.
51
- * @param options.unit See {@link module:engine/model/utils/modifyselection~modifySelection}'s options.
52
- * @param options.sequence A number describing which subsequent delete event it is without the key being released.
53
- * See the {@link module:engine/view/document~ViewDocument#event:delete} event data.
54
- * @param options.selection Selection to remove. If not set, current model selection will be used.
55
- */
56
- execute(options = {}) {
57
- const model = this.editor.model;
58
- const doc = model.document;
59
- model.enqueueChange(this._buffer.batch, writer => {
60
- this._buffer.lock();
61
- const selection = writer.createSelection(options.selection || doc.selection);
62
- // Don't execute command when selection is in non-editable place.
63
- if (!model.canEditAt(selection)) {
64
- return;
65
- }
66
- const sequence = options.sequence || 1;
67
- // Do not replace the whole selected content if selection was collapsed.
68
- // This prevents such situation:
69
- //
70
- // <h1></h1><p>[]</p> --> <h1>[</h1><p>]</p> --> <p></p>
71
- // starting content --> after `modifySelection` --> after `deleteContent`.
72
- const doNotResetEntireContent = selection.isCollapsed;
73
- // Try to extend the selection in the specified direction.
74
- if (selection.isCollapsed) {
75
- model.modifySelection(selection, {
76
- direction: this.direction,
77
- unit: options.unit,
78
- treatEmojiAsSingleUnit: true
79
- });
80
- }
81
- // Check if deleting in an empty editor. See #61.
82
- if (this._shouldEntireContentBeReplacedWithParagraph(sequence)) {
83
- this._replaceEntireContentWithParagraph(writer);
84
- return;
85
- }
86
- // Check if deleting in the first empty block.
87
- // See https://github.com/ckeditor/ckeditor5/issues/8137.
88
- if (this._shouldReplaceFirstBlockWithParagraph(selection, sequence)) {
89
- this.editor.execute('paragraph', { selection });
90
- return;
91
- }
92
- // If selection is still collapsed, then there's nothing to delete.
93
- if (selection.isCollapsed) {
94
- return;
95
- }
96
- let changeCount = 0;
97
- selection.getFirstRange().getMinimalFlatRanges().forEach(range => {
98
- changeCount += count(range.getWalker({ singleCharacters: true, ignoreElementEnd: true, shallow: true }));
99
- });
100
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
101
- // @if CK_DEBUG_TYPING // console.log( ..._buildLogMessage( this, 'DeleteCommand',
102
- // @if CK_DEBUG_TYPING // 'Delete content',
103
- // @if CK_DEBUG_TYPING // `[${ selection.getFirstPosition()!.path }]-[${ selection.getLastPosition()!.path }]`,
104
- // @if CK_DEBUG_TYPING // options
105
- // @if CK_DEBUG_TYPING // ) );
106
- // @if CK_DEBUG_TYPING // }
107
- model.deleteContent(selection, {
108
- doNotResetEntireContent,
109
- direction: this.direction
110
- });
111
- this._buffer.input(changeCount);
112
- writer.setSelection(selection);
113
- this._buffer.unlock();
114
- });
115
- }
116
- /**
117
- * If the user keeps <kbd>Backspace</kbd> or <kbd>Delete</kbd> key pressed, the content of the current
118
- * editable will be cleared. However, this will not yet lead to resetting the remaining block to a paragraph
119
- * (which happens e.g. when the user does <kbd>Ctrl</kbd> + <kbd>A</kbd>, <kbd>Backspace</kbd>).
120
- *
121
- * But, if the user pressed the key in an empty editable for the first time,
122
- * we want to replace the entire content with a paragraph if:
123
- *
124
- * * the current limit element is empty,
125
- * * the paragraph is allowed in the limit element,
126
- * * the limit doesn't already have a paragraph inside.
127
- *
128
- * See https://github.com/ckeditor/ckeditor5-typing/issues/61.
129
- *
130
- * @param sequence A number describing which subsequent delete event it is without the key being released.
131
- */
132
- _shouldEntireContentBeReplacedWithParagraph(sequence) {
133
- // Does nothing if user pressed and held the "Backspace" or "Delete" key.
134
- if (sequence > 1) {
135
- return false;
136
- }
137
- const model = this.editor.model;
138
- const doc = model.document;
139
- const selection = doc.selection;
140
- const limitElement = model.schema.getLimitElement(selection);
141
- // If a collapsed selection contains the whole content it means that the content is empty
142
- // (from the user perspective).
143
- const limitElementIsEmpty = selection.isCollapsed && selection.containsEntireContent(limitElement);
144
- if (!limitElementIsEmpty) {
145
- return false;
146
- }
147
- if (!model.schema.checkChild(limitElement, 'paragraph')) {
148
- return false;
149
- }
150
- const limitElementFirstChild = limitElement.getChild(0);
151
- // Does nothing if the limit element already contains only a paragraph.
152
- // We ignore the case when paragraph might have some inline elements (<p><inlineWidget>[]</inlineWidget></p>)
153
- // because we don't support such cases yet and it's unclear whether inlineWidget shouldn't be a limit itself.
154
- if (limitElementFirstChild && limitElementFirstChild.is('element', 'paragraph')) {
155
- return false;
156
- }
157
- return true;
158
- }
159
- /**
160
- * The entire content is replaced with the paragraph. Selection is moved inside the paragraph.
161
- *
162
- * @param writer The model writer.
163
- */
164
- _replaceEntireContentWithParagraph(writer) {
165
- const model = this.editor.model;
166
- const doc = model.document;
167
- const selection = doc.selection;
168
- const limitElement = model.schema.getLimitElement(selection);
169
- const paragraph = writer.createElement('paragraph');
170
- writer.remove(writer.createRangeIn(limitElement));
171
- writer.insert(paragraph, limitElement);
172
- writer.setSelection(paragraph, 0);
173
- }
174
- /**
175
- * Checks if the selection is inside an empty element that is the first child of the limit element
176
- * and should be replaced with a paragraph.
177
- *
178
- * @param selection The selection.
179
- * @param sequence A number describing which subsequent delete event it is without the key being released.
180
- */
181
- _shouldReplaceFirstBlockWithParagraph(selection, sequence) {
182
- const model = this.editor.model;
183
- // Does nothing if user pressed and held the "Backspace" key or it was a "Delete" button.
184
- if (sequence > 1 || this.direction != 'backward') {
185
- return false;
186
- }
187
- if (!selection.isCollapsed) {
188
- return false;
189
- }
190
- const position = selection.getFirstPosition();
191
- const limitElement = model.schema.getLimitElement(position);
192
- const limitElementFirstChild = limitElement.getChild(0);
193
- // Only elements that are direct children of the limit element can be replaced.
194
- // Unwrapping from a block quote should be handled in a dedicated feature.
195
- if (position.parent != limitElementFirstChild) {
196
- return false;
197
- }
198
- // A block should be replaced only if it was empty.
199
- if (!selection.containsEntireContent(limitElementFirstChild)) {
200
- return false;
201
- }
202
- // Replace with a paragraph only if it's allowed there.
203
- if (!model.schema.checkChild(limitElement, 'paragraph')) {
204
- return false;
205
- }
206
- // Does nothing if the limit element already contains only a paragraph.
207
- if (limitElementFirstChild.name == 'paragraph') {
208
- return false;
209
- }
210
- return true;
211
- }
212
- }