@ckeditor/ckeditor5-undo 40.0.0 → 40.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +1,37 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module undo/undoediting
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- /**
10
- * The undo engine feature.
11
- *
12
- * It introduces the `'undo'` and `'redo'` commands to the editor.
13
- */
14
- export default class UndoEditing extends Plugin {
15
- /**
16
- * The command that manages the undo {@link module:engine/model/batch~Batch batches} stack (history).
17
- * Created and registered during the {@link #init feature initialization}.
18
- */
19
- private _undoCommand;
20
- /**
21
- * The command that manages the redo {@link module:engine/model/batch~Batch batches} stack (history).
22
- * Created and registered during the {@link #init feature initialization}.
23
- */
24
- private _redoCommand;
25
- /**
26
- * Keeps track of which batches were registered in undo.
27
- */
28
- private _batchRegistry;
29
- /**
30
- * @inheritDoc
31
- */
32
- static get pluginName(): "UndoEditing";
33
- /**
34
- * @inheritDoc
35
- */
36
- init(): void;
37
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module undo/undoediting
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ /**
10
+ * The undo engine feature.
11
+ *
12
+ * It introduces the `'undo'` and `'redo'` commands to the editor.
13
+ */
14
+ export default class UndoEditing extends Plugin {
15
+ /**
16
+ * The command that manages the undo {@link module:engine/model/batch~Batch batches} stack (history).
17
+ * Created and registered during the {@link #init feature initialization}.
18
+ */
19
+ private _undoCommand;
20
+ /**
21
+ * The command that manages the redo {@link module:engine/model/batch~Batch batches} stack (history).
22
+ * Created and registered during the {@link #init feature initialization}.
23
+ */
24
+ private _redoCommand;
25
+ /**
26
+ * Keeps track of which batches were registered in undo.
27
+ */
28
+ private _batchRegistry;
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get pluginName(): "UndoEditing";
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ init(): void;
37
+ }
@@ -1,82 +1,82 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module undo/undoediting
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import UndoCommand from './undocommand';
10
- import RedoCommand from './redocommand';
11
- /**
12
- * The undo engine feature.
13
- *
14
- * It introduces the `'undo'` and `'redo'` commands to the editor.
15
- */
16
- export default class UndoEditing extends Plugin {
17
- constructor() {
18
- super(...arguments);
19
- /**
20
- * Keeps track of which batches were registered in undo.
21
- */
22
- this._batchRegistry = new WeakSet();
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName() {
28
- return 'UndoEditing';
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- init() {
34
- const editor = this.editor;
35
- // Create commands.
36
- this._undoCommand = new UndoCommand(editor);
37
- this._redoCommand = new RedoCommand(editor);
38
- // Register command to the editor.
39
- editor.commands.add('undo', this._undoCommand);
40
- editor.commands.add('redo', this._redoCommand);
41
- this.listenTo(editor.model, 'applyOperation', (evt, args) => {
42
- const operation = args[0];
43
- // Do not register batch if the operation is not a document operation.
44
- // This prevents from creating empty undo steps, where all operations where non-document operations.
45
- // Non-document operations creates and alters content in detached tree fragments (for example, document fragments).
46
- // Most of time this is preparing data before it is inserted into actual tree (for example during copy & paste).
47
- // Such operations should not be reversed.
48
- if (!operation.isDocumentOperation) {
49
- return;
50
- }
51
- const batch = operation.batch;
52
- const isRedoBatch = this._redoCommand.createdBatches.has(batch);
53
- const isUndoBatch = this._undoCommand.createdBatches.has(batch);
54
- const wasProcessed = this._batchRegistry.has(batch);
55
- // Skip the batch if it was already processed.
56
- if (wasProcessed) {
57
- return;
58
- }
59
- // Add the batch to the registry so it will not be processed again.
60
- this._batchRegistry.add(batch);
61
- if (!batch.isUndoable) {
62
- return;
63
- }
64
- if (isRedoBatch) {
65
- // If this batch comes from `redoCommand`, add it to the `undoCommand` stack.
66
- this._undoCommand.addBatch(batch);
67
- }
68
- else if (!isUndoBatch) {
69
- // If the batch comes neither from `redoCommand` nor from `undoCommand` then it is a new, regular batch.
70
- // Add the batch to the `undoCommand` stack and clear the `redoCommand` stack.
71
- this._undoCommand.addBatch(batch);
72
- this._redoCommand.clearStack();
73
- }
74
- }, { priority: 'highest' });
75
- this.listenTo(this._undoCommand, 'revert', (evt, undoneBatch, undoingBatch) => {
76
- this._redoCommand.addBatch(undoingBatch);
77
- });
78
- editor.keystrokes.set('CTRL+Z', 'undo');
79
- editor.keystrokes.set('CTRL+Y', 'redo');
80
- editor.keystrokes.set('CTRL+SHIFT+Z', 'redo');
81
- }
82
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module undo/undoediting
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import UndoCommand from './undocommand';
10
+ import RedoCommand from './redocommand';
11
+ /**
12
+ * The undo engine feature.
13
+ *
14
+ * It introduces the `'undo'` and `'redo'` commands to the editor.
15
+ */
16
+ export default class UndoEditing extends Plugin {
17
+ constructor() {
18
+ super(...arguments);
19
+ /**
20
+ * Keeps track of which batches were registered in undo.
21
+ */
22
+ this._batchRegistry = new WeakSet();
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'UndoEditing';
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init() {
34
+ const editor = this.editor;
35
+ // Create commands.
36
+ this._undoCommand = new UndoCommand(editor);
37
+ this._redoCommand = new RedoCommand(editor);
38
+ // Register command to the editor.
39
+ editor.commands.add('undo', this._undoCommand);
40
+ editor.commands.add('redo', this._redoCommand);
41
+ this.listenTo(editor.model, 'applyOperation', (evt, args) => {
42
+ const operation = args[0];
43
+ // Do not register batch if the operation is not a document operation.
44
+ // This prevents from creating empty undo steps, where all operations where non-document operations.
45
+ // Non-document operations creates and alters content in detached tree fragments (for example, document fragments).
46
+ // Most of time this is preparing data before it is inserted into actual tree (for example during copy & paste).
47
+ // Such operations should not be reversed.
48
+ if (!operation.isDocumentOperation) {
49
+ return;
50
+ }
51
+ const batch = operation.batch;
52
+ const isRedoBatch = this._redoCommand.createdBatches.has(batch);
53
+ const isUndoBatch = this._undoCommand.createdBatches.has(batch);
54
+ const wasProcessed = this._batchRegistry.has(batch);
55
+ // Skip the batch if it was already processed.
56
+ if (wasProcessed) {
57
+ return;
58
+ }
59
+ // Add the batch to the registry so it will not be processed again.
60
+ this._batchRegistry.add(batch);
61
+ if (!batch.isUndoable) {
62
+ return;
63
+ }
64
+ if (isRedoBatch) {
65
+ // If this batch comes from `redoCommand`, add it to the `undoCommand` stack.
66
+ this._undoCommand.addBatch(batch);
67
+ }
68
+ else if (!isUndoBatch) {
69
+ // If the batch comes neither from `redoCommand` nor from `undoCommand` then it is a new, regular batch.
70
+ // Add the batch to the `undoCommand` stack and clear the `redoCommand` stack.
71
+ this._undoCommand.addBatch(batch);
72
+ this._redoCommand.clearStack();
73
+ }
74
+ }, { priority: 'highest' });
75
+ this.listenTo(this._undoCommand, 'revert', (evt, undoneBatch, undoingBatch) => {
76
+ this._redoCommand.addBatch(undoingBatch);
77
+ });
78
+ editor.keystrokes.set('CTRL+Z', 'undo');
79
+ editor.keystrokes.set('CTRL+Y', 'redo');
80
+ editor.keystrokes.set('CTRL+SHIFT+Z', 'redo');
81
+ }
82
+ }
package/src/undoui.d.ts CHANGED
@@ -1,30 +1,30 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module undo/undoui
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- /**
10
- * The undo UI feature. It introduces the `'undo'` and `'redo'` buttons to the editor.
11
- */
12
- export default class UndoUI extends Plugin {
13
- /**
14
- * @inheritDoc
15
- */
16
- static get pluginName(): "UndoUI";
17
- /**
18
- * @inheritDoc
19
- */
20
- init(): void;
21
- /**
22
- * Creates a button for the specified command.
23
- *
24
- * @param name Command name.
25
- * @param label Button label.
26
- * @param keystroke Command keystroke.
27
- * @param Icon Source of the icon.
28
- */
29
- private _addButton;
30
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module undo/undoui
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ /**
10
+ * The undo UI feature. It introduces the `'undo'` and `'redo'` buttons to the editor.
11
+ */
12
+ export default class UndoUI extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): "UndoUI";
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ init(): void;
21
+ /**
22
+ * Creates a button for the specified command.
23
+ *
24
+ * @param name Command name.
25
+ * @param label Button label.
26
+ * @param keystroke Command keystroke.
27
+ * @param Icon Source of the icon.
28
+ */
29
+ private _addButton;
30
+ }
package/src/undoui.js CHANGED
@@ -1,61 +1,61 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module undo/undoui
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { ButtonView } from '@ckeditor/ckeditor5-ui';
10
- import undoIcon from '../theme/icons/undo.svg';
11
- import redoIcon from '../theme/icons/redo.svg';
12
- /**
13
- * The undo UI feature. It introduces the `'undo'` and `'redo'` buttons to the editor.
14
- */
15
- export default class UndoUI extends Plugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName() {
20
- return 'UndoUI';
21
- }
22
- /**
23
- * @inheritDoc
24
- */
25
- init() {
26
- const editor = this.editor;
27
- const locale = editor.locale;
28
- const t = editor.t;
29
- const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? undoIcon : redoIcon;
30
- const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? redoIcon : undoIcon;
31
- this._addButton('undo', t('Undo'), 'CTRL+Z', localizedUndoIcon);
32
- this._addButton('redo', t('Redo'), 'CTRL+Y', localizedRedoIcon);
33
- }
34
- /**
35
- * Creates a button for the specified command.
36
- *
37
- * @param name Command name.
38
- * @param label Button label.
39
- * @param keystroke Command keystroke.
40
- * @param Icon Source of the icon.
41
- */
42
- _addButton(name, label, keystroke, Icon) {
43
- const editor = this.editor;
44
- editor.ui.componentFactory.add(name, locale => {
45
- const command = editor.commands.get(name);
46
- const view = new ButtonView(locale);
47
- view.set({
48
- label,
49
- icon: Icon,
50
- keystroke,
51
- tooltip: true
52
- });
53
- view.bind('isEnabled').to(command, 'isEnabled');
54
- this.listenTo(view, 'execute', () => {
55
- editor.execute(name);
56
- editor.editing.view.focus();
57
- });
58
- return view;
59
- });
60
- }
61
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module undo/undoui
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import { ButtonView } from '@ckeditor/ckeditor5-ui';
10
+ import undoIcon from '../theme/icons/undo.svg';
11
+ import redoIcon from '../theme/icons/redo.svg';
12
+ /**
13
+ * The undo UI feature. It introduces the `'undo'` and `'redo'` buttons to the editor.
14
+ */
15
+ export default class UndoUI extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName() {
20
+ return 'UndoUI';
21
+ }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ init() {
26
+ const editor = this.editor;
27
+ const locale = editor.locale;
28
+ const t = editor.t;
29
+ const localizedUndoIcon = locale.uiLanguageDirection == 'ltr' ? undoIcon : redoIcon;
30
+ const localizedRedoIcon = locale.uiLanguageDirection == 'ltr' ? redoIcon : undoIcon;
31
+ this._addButton('undo', t('Undo'), 'CTRL+Z', localizedUndoIcon);
32
+ this._addButton('redo', t('Redo'), 'CTRL+Y', localizedRedoIcon);
33
+ }
34
+ /**
35
+ * Creates a button for the specified command.
36
+ *
37
+ * @param name Command name.
38
+ * @param label Button label.
39
+ * @param keystroke Command keystroke.
40
+ * @param Icon Source of the icon.
41
+ */
42
+ _addButton(name, label, keystroke, Icon) {
43
+ const editor = this.editor;
44
+ editor.ui.componentFactory.add(name, locale => {
45
+ const command = editor.commands.get(name);
46
+ const view = new ButtonView(locale);
47
+ view.set({
48
+ label,
49
+ icon: Icon,
50
+ keystroke,
51
+ tooltip: true
52
+ });
53
+ view.bind('isEnabled').to(command, 'isEnabled');
54
+ this.listenTo(view, 'execute', () => {
55
+ editor.execute(name);
56
+ editor.editing.view.focus();
57
+ });
58
+ return view;
59
+ });
60
+ }
61
+ }