@ckeditor/ckeditor5-undo 47.6.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 (94) hide show
  1. package/ckeditor5-metadata.json +3 -3
  2. package/dist/index.css +3 -0
  3. package/dist/index.css.map +1 -0
  4. package/package.json +23 -43
  5. package/lang/contexts.json +0 -4
  6. package/lang/translations/af.po +0 -20
  7. package/lang/translations/ar.po +0 -20
  8. package/lang/translations/ast.po +0 -20
  9. package/lang/translations/az.po +0 -20
  10. package/lang/translations/be.po +0 -20
  11. package/lang/translations/bg.po +0 -20
  12. package/lang/translations/bn.po +0 -20
  13. package/lang/translations/bs.po +0 -20
  14. package/lang/translations/ca.po +0 -20
  15. package/lang/translations/cs.po +0 -20
  16. package/lang/translations/da.po +0 -20
  17. package/lang/translations/de-ch.po +0 -20
  18. package/lang/translations/de.po +0 -20
  19. package/lang/translations/el.po +0 -20
  20. package/lang/translations/en-au.po +0 -20
  21. package/lang/translations/en-gb.po +0 -20
  22. package/lang/translations/en.po +0 -20
  23. package/lang/translations/eo.po +0 -20
  24. package/lang/translations/es-co.po +0 -20
  25. package/lang/translations/es.po +0 -20
  26. package/lang/translations/et.po +0 -20
  27. package/lang/translations/eu.po +0 -20
  28. package/lang/translations/fa.po +0 -20
  29. package/lang/translations/fi.po +0 -20
  30. package/lang/translations/fr.po +0 -20
  31. package/lang/translations/gl.po +0 -20
  32. package/lang/translations/gu.po +0 -20
  33. package/lang/translations/he.po +0 -20
  34. package/lang/translations/hi.po +0 -20
  35. package/lang/translations/hr.po +0 -20
  36. package/lang/translations/hu.po +0 -20
  37. package/lang/translations/hy.po +0 -20
  38. package/lang/translations/id.po +0 -20
  39. package/lang/translations/it.po +0 -20
  40. package/lang/translations/ja.po +0 -20
  41. package/lang/translations/jv.po +0 -20
  42. package/lang/translations/kk.po +0 -20
  43. package/lang/translations/km.po +0 -20
  44. package/lang/translations/kn.po +0 -20
  45. package/lang/translations/ko.po +0 -20
  46. package/lang/translations/ku.po +0 -20
  47. package/lang/translations/lt.po +0 -20
  48. package/lang/translations/lv.po +0 -20
  49. package/lang/translations/ms.po +0 -20
  50. package/lang/translations/nb.po +0 -20
  51. package/lang/translations/ne.po +0 -20
  52. package/lang/translations/nl.po +0 -20
  53. package/lang/translations/no.po +0 -20
  54. package/lang/translations/oc.po +0 -20
  55. package/lang/translations/pl.po +0 -20
  56. package/lang/translations/pt-br.po +0 -20
  57. package/lang/translations/pt.po +0 -20
  58. package/lang/translations/ro.po +0 -20
  59. package/lang/translations/ru.po +0 -20
  60. package/lang/translations/si.po +0 -20
  61. package/lang/translations/sk.po +0 -20
  62. package/lang/translations/sl.po +0 -20
  63. package/lang/translations/sq.po +0 -20
  64. package/lang/translations/sr-latn.po +0 -20
  65. package/lang/translations/sr.po +0 -20
  66. package/lang/translations/sv.po +0 -20
  67. package/lang/translations/th.po +0 -20
  68. package/lang/translations/ti.po +0 -20
  69. package/lang/translations/tk.po +0 -20
  70. package/lang/translations/tr.po +0 -20
  71. package/lang/translations/tt.po +0 -20
  72. package/lang/translations/ug.po +0 -20
  73. package/lang/translations/uk.po +0 -20
  74. package/lang/translations/ur.po +0 -20
  75. package/lang/translations/uz.po +0 -20
  76. package/lang/translations/vi.po +0 -20
  77. package/lang/translations/zh-cn.po +0 -20
  78. package/lang/translations/zh.po +0 -20
  79. package/src/augmentation.js +0 -5
  80. package/src/basecommand.js +0 -192
  81. package/src/index.js +0 -14
  82. package/src/redocommand.js +0 -44
  83. package/src/undo.js +0 -127
  84. package/src/undocommand.js +0 -44
  85. package/src/undoediting.js +0 -109
  86. package/src/undoui.js +0 -80
  87. /package/{src → dist}/augmentation.d.ts +0 -0
  88. /package/{src → dist}/basecommand.d.ts +0 -0
  89. /package/{src → dist}/index.d.ts +0 -0
  90. /package/{src → dist}/redocommand.d.ts +0 -0
  91. /package/{src → dist}/undo.d.ts +0 -0
  92. /package/{src → dist}/undocommand.d.ts +0 -0
  93. /package/{src → dist}/undoediting.d.ts +0 -0
  94. /package/{src → dist}/undoui.d.ts +0 -0
package/src/undo.js DELETED
@@ -1,127 +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 undo/undo
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { UndoEditing } from './undoediting.js';
10
- import { UndoUI } from './undoui.js';
11
- /**
12
- * The undo feature.
13
- *
14
- * This is a "glue" plugin which loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
15
- * and the {@link module:undo/undoui~UndoUI undo UI feature}.
16
- *
17
- * Below is an explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
18
- *
19
- * Whenever an {@link module:engine/model/operation/operation~Operation operation} is applied to the
20
- * {@link module:engine/model/document~ModelDocument document}, it is saved to `History` as is.
21
- * The {@link module:engine/model/batch~Batch batch} that owns that operation is also saved, in
22
- * {@link module:undo/undocommand~UndoCommand}, together with the selection that was present in the document before the
23
- * operation was applied. A batch is saved instead of the operation because changes are undone batch-by-batch, not operation-by-operation
24
- * and a batch is seen as one undo step.
25
- *
26
- * After changes happen to the document, the `History` and `UndoCommand` stack can be represented as follows:
27
- *
28
- * ```
29
- * History Undo stack
30
- * ============== ==================================
31
- * [operation A1] [ batch A ]
32
- * [operation B1] [ batch B ]
33
- * [operation B2] [ batch C ]
34
- * [operation C1]
35
- * [operation C2]
36
- * [operation B3]
37
- * [operation C3]
38
- * ```
39
- *
40
- * Where operations starting with the same letter are from same batch.
41
- *
42
- * Undoing a batch means that a set of operations which will reverse the effects of that batch needs to be generated.
43
- * For example, if a batch added several letters, undoing the batch should remove them. It is important to apply undoing
44
- * operations in the reversed order, so if a batch has operation `X`, `Y`, `Z`, reversed operations `Zr`, `Yr` and `Xr`
45
- * need to be applied. Otherwise reversed operation `Xr` would operate on a wrong document state, because operation `X`
46
- * does not know that operations `Y` and `Z` happened.
47
- *
48
- * After operations from an undone batch got {@link module:engine/model/operation/operation~Operation#getReversed reversed},
49
- * one needs to make sure if they are ready to be applied. In the scenario above, operation `C3` is the last operation and `C3r`
50
- * bases on up-to-date document state, so it can be applied to the document.
51
- *
52
- * ```
53
- * History Undo stack
54
- * ================= ==================================
55
- * [ operation A1 ] [ batch A ]
56
- * [ operation B1 ] [ batch B ]
57
- * [ operation B2 ] [ processing undoing batch C ]
58
- * [ operation C1 ]
59
- * [ operation C2 ]
60
- * [ operation B3 ]
61
- * [ operation C3 ]
62
- * [ operation C3r ]
63
- * ```
64
- *
65
- * Next is operation `C2`, reversed to `C2r`. `C2r` bases on `C2`, so it bases on the wrong document state. It needs to be
66
- * transformed by operations from history that happened after it, so it "knows" about them. Let us assume that `C2' = C2r * B3 * C3 * C3r`,
67
- * where `*` means "transformed by". Rest of operations from that batch are processed in the same fashion.
68
- *
69
- * ```
70
- * History Undo stack Redo stack
71
- * ================= ================================== ==================================
72
- * [ operation A1 ] [ batch A ] [ batch Cr ]
73
- * [ operation B1 ] [ batch B ]
74
- * [ operation B2 ]
75
- * [ operation C1 ]
76
- * [ operation C2 ]
77
- * [ operation B3 ]
78
- * [ operation C3 ]
79
- * [ operation C3r ]
80
- * [ operation C2' ]
81
- * [ operation C1' ]
82
- * ```
83
- *
84
- * Selective undo works on the same basis, however, instead of undoing the last batch in the undo stack, any batch can be undone.
85
- * The same algorithm applies: operations from a batch (i.e. `A1`) are reversed and then transformed by operations stored in history.
86
- *
87
- * Redo also is very similar to undo. It has its own stack that is filled with undoing (reversed batches). Operations from
88
- * the batch that is re-done are reversed-back, transformed in proper order and applied to the document.
89
- *
90
- * ```
91
- * History Undo stack Redo stack
92
- * ================= ================================== ==================================
93
- * [ operation A1 ] [ batch A ]
94
- * [ operation B1 ] [ batch B ]
95
- * [ operation B2 ] [ batch Crr ]
96
- * [ operation C1 ]
97
- * [ operation C2 ]
98
- * [ operation B3 ]
99
- * [ operation C3 ]
100
- * [ operation C3r ]
101
- * [ operation C2' ]
102
- * [ operation C1' ]
103
- * [ operation C1'r]
104
- * [ operation C2'r]
105
- * [ operation C3rr]
106
- * ```
107
- */
108
- export class Undo extends Plugin {
109
- /**
110
- * @inheritDoc
111
- */
112
- static get requires() {
113
- return [UndoEditing, UndoUI];
114
- }
115
- /**
116
- * @inheritDoc
117
- */
118
- static get pluginName() {
119
- return 'Undo';
120
- }
121
- /**
122
- * @inheritDoc
123
- */
124
- static get isOfficialPlugin() {
125
- return true;
126
- }
127
- }
@@ -1,44 +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 undo/undocommand
7
- */
8
- import { UndoRedoBaseCommand } from './basecommand.js';
9
- /**
10
- * The undo command stores {@link module:engine/model/batch~Batch batches} applied to the
11
- * {@link module:engine/model/document~ModelDocument document} and is able to undo a batch by reversing it and transforming by
12
- * batches from {@link module:engine/model/document~ModelDocument#history history} that happened after the reversed batch.
13
- *
14
- * The undo command also takes care of restoring the {@link module:engine/model/document~ModelDocument#selection document selection}.
15
- */
16
- export class UndoCommand extends UndoRedoBaseCommand {
17
- /**
18
- * Executes the command. This method reverts a {@link module:engine/model/batch~Batch batch} added to the command's stack, transforms
19
- * and applies the reverted version on the {@link module:engine/model/document~ModelDocument document} and removes the batch from
20
- * the stack. Then, it restores the {@link module:engine/model/document~ModelDocument#selection document selection}.
21
- *
22
- * @fires execute
23
- * @fires revert
24
- * @param batch A batch that should be undone. If not set, the last added batch will be undone.
25
- */
26
- execute(batch = null) {
27
- // If batch is not given, set `batchIndex` to the last index in command stack.
28
- const batchIndex = batch ? this._stack.findIndex(a => a.batch == batch) : this._stack.length - 1;
29
- const item = this._stack.splice(batchIndex, 1)[0];
30
- const undoingBatch = this.editor.model.createBatch({ isUndo: true });
31
- // All changes have to be done in one `enqueueChange` callback so other listeners will not
32
- // step between consecutive operations, or won't do changes to the document before selection is properly restored.
33
- this.editor.model.enqueueChange(undoingBatch, () => {
34
- this._undo(item.batch, undoingBatch);
35
- const operations = this.editor.model.document.history.getOperations(item.batch.baseVersion);
36
- this._restoreSelection(item.selection.ranges, item.selection.isBackward, operations);
37
- });
38
- // Firing `revert` event after the change block to make sure that it includes all changes from post-fixers
39
- // and make sure that the selection is "stabilized" (the selection range is saved after undo is executed and then
40
- // restored on redo, so it is important that the selection range is saved after post-fixers are done).
41
- this.fire('revert', item.batch, undoingBatch);
42
- this.refresh();
43
- }
44
- }
@@ -1,109 +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 undo/undoediting
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { UndoCommand } from './undocommand.js';
10
- import { RedoCommand } from './redocommand.js';
11
- /**
12
- * The undo engine feature.
13
- *
14
- * It introduces the `'undo'` and `'redo'` commands to the editor.
15
- */
16
- export class UndoEditing extends Plugin {
17
- /**
18
- * The command that manages the undo {@link module:engine/model/batch~Batch batches} stack (history).
19
- * Created and registered during the {@link #init feature initialization}.
20
- */
21
- _undoCommand;
22
- /**
23
- * The command that manages the redo {@link module:engine/model/batch~Batch batches} stack (history).
24
- * Created and registered during the {@link #init feature initialization}.
25
- */
26
- _redoCommand;
27
- /**
28
- * Keeps track of which batches were registered in undo.
29
- */
30
- _batchRegistry = new WeakSet();
31
- /**
32
- * @inheritDoc
33
- */
34
- static get pluginName() {
35
- return 'UndoEditing';
36
- }
37
- /**
38
- * @inheritDoc
39
- */
40
- static get isOfficialPlugin() {
41
- return true;
42
- }
43
- /**
44
- * @inheritDoc
45
- */
46
- init() {
47
- const editor = this.editor;
48
- const t = editor.t;
49
- // Create commands.
50
- this._undoCommand = new UndoCommand(editor);
51
- this._redoCommand = new RedoCommand(editor);
52
- // Register command to the editor.
53
- editor.commands.add('undo', this._undoCommand);
54
- editor.commands.add('redo', this._redoCommand);
55
- this.listenTo(editor.model, 'applyOperation', (evt, args) => {
56
- const operation = args[0];
57
- // Do not register batch if the operation is not a document operation.
58
- // This prevents from creating empty undo steps, where all operations where non-document operations.
59
- // Non-document operations creates and alters content in detached tree fragments (for example, document fragments).
60
- // Most of time this is preparing data before it is inserted into actual tree (for example during copy & paste).
61
- // Such operations should not be reversed.
62
- if (!operation.isDocumentOperation) {
63
- return;
64
- }
65
- const batch = operation.batch;
66
- const isRedoBatch = this._redoCommand.createdBatches.has(batch);
67
- const isUndoBatch = this._undoCommand.createdBatches.has(batch);
68
- const wasProcessed = this._batchRegistry.has(batch);
69
- // Skip the batch if it was already processed.
70
- if (wasProcessed) {
71
- return;
72
- }
73
- // Add the batch to the registry so it will not be processed again.
74
- this._batchRegistry.add(batch);
75
- if (!batch.isUndoable) {
76
- return;
77
- }
78
- if (isRedoBatch) {
79
- // If this batch comes from `redoCommand`, add it to the `undoCommand` stack.
80
- this._undoCommand.addBatch(batch);
81
- }
82
- else if (!isUndoBatch) {
83
- // If the batch comes neither from `redoCommand` nor from `undoCommand` then it is a new, regular batch.
84
- // Add the batch to the `undoCommand` stack and clear the `redoCommand` stack.
85
- this._undoCommand.addBatch(batch);
86
- this._redoCommand.clearStack();
87
- }
88
- }, { priority: 'highest' });
89
- this.listenTo(this._undoCommand, 'revert', (evt, undoneBatch, undoingBatch) => {
90
- this._redoCommand.addBatch(undoingBatch);
91
- });
92
- editor.keystrokes.set('CTRL+Z', 'undo');
93
- editor.keystrokes.set('CTRL+Y', 'redo');
94
- editor.keystrokes.set('CTRL+SHIFT+Z', 'redo');
95
- // Add the information about the keystrokes to the accessibility database.
96
- editor.accessibility.addKeystrokeInfos({
97
- keystrokes: [
98
- {
99
- label: t('Undo'),
100
- keystroke: 'CTRL+Z'
101
- },
102
- {
103
- label: t('Redo'),
104
- keystroke: [['CTRL+Y'], ['CTRL+SHIFT+Z']]
105
- }
106
- ]
107
- });
108
- }
109
- }
package/src/undoui.js DELETED
@@ -1,80 +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 undo/undoui
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { ButtonView, MenuBarMenuListItemButtonView } from '@ckeditor/ckeditor5-ui';
10
- import { IconUndo, IconRedo } from '@ckeditor/ckeditor5-icons';
11
- /**
12
- * The undo UI feature. It introduces the `'undo'` and `'redo'` buttons to the editor.
13
- */
14
- export class UndoUI extends Plugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get pluginName() {
19
- return 'UndoUI';
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- static get isOfficialPlugin() {
25
- return true;
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- init() {
31
- const editor = this.editor;
32
- const locale = editor.locale;
33
- const t = editor.t;
34
- const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? IconUndo : IconRedo;
35
- const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? IconRedo : IconUndo;
36
- this._addButtonsToFactory('undo', t('Undo'), 'CTRL+Z', localizedUndoIcon);
37
- this._addButtonsToFactory('redo', t('Redo'), 'CTRL+Y', localizedRedoIcon);
38
- }
39
- /**
40
- * Creates a button for the specified command.
41
- *
42
- * @param name Command name.
43
- * @param label Button label.
44
- * @param keystroke Command keystroke.
45
- * @param Icon Source of the icon.
46
- */
47
- _addButtonsToFactory(name, label, keystroke, Icon) {
48
- const editor = this.editor;
49
- editor.ui.componentFactory.add(name, () => {
50
- const buttonView = this._createButton(ButtonView, name, label, keystroke, Icon);
51
- buttonView.set({
52
- tooltip: true
53
- });
54
- return buttonView;
55
- });
56
- editor.ui.componentFactory.add('menuBar:' + name, () => {
57
- return this._createButton(MenuBarMenuListItemButtonView, name, label, keystroke, Icon);
58
- });
59
- }
60
- /**
61
- * TODO
62
- */
63
- _createButton(ButtonClass, name, label, keystroke, Icon) {
64
- const editor = this.editor;
65
- const locale = editor.locale;
66
- const command = editor.commands.get(name);
67
- const view = new ButtonClass(locale);
68
- view.set({
69
- label,
70
- icon: Icon,
71
- keystroke
72
- });
73
- view.bind('isEnabled').to(command, 'isEnabled');
74
- this.listenTo(view, 'execute', () => {
75
- editor.execute(name);
76
- editor.editing.view.focus();
77
- });
78
- return view;
79
- }
80
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes