@ckeditor/ckeditor5-restricted-editing 36.0.1 → 37.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.
- package/build/restricted-editing.js +1 -1
- package/package.json +25 -20
- package/src/index.d.ts +13 -0
- package/src/index.js +0 -2
- package/src/restrictededitingconfig.d.ts +71 -0
- package/src/restrictededitingconfig.js +5 -0
- package/src/restrictededitingexceptioncommand.d.ts +35 -0
- package/src/restrictededitingexceptioncommand.js +49 -54
- package/src/restrictededitingmode/converters.d.ts +39 -0
- package/src/restrictededitingmode/converters.js +107 -156
- package/src/restrictededitingmode/utils.d.ts +30 -0
- package/src/restrictededitingmode/utils.js +28 -48
- package/src/restrictededitingmode.d.ts +32 -0
- package/src/restrictededitingmode.js +12 -82
- package/src/restrictededitingmodeediting.d.ts +88 -0
- package/src/restrictededitingmodeediting.js +363 -473
- package/src/restrictededitingmodenavigationcommand.d.ts +48 -0
- package/src/restrictededitingmodenavigationcommand.js +83 -109
- package/src/restrictededitingmodeui.d.ts +37 -0
- package/src/restrictededitingmodeui.js +55 -80
- package/src/standardeditingmode.d.ts +29 -0
- package/src/standardeditingmode.js +9 -17
- package/src/standardeditingmodeediting.d.ts +30 -0
- package/src/standardeditingmodeediting.js +35 -47
- package/src/standardeditingmodeui.d.ts +28 -0
- package/src/standardeditingmodeui.js +31 -36
@@ -0,0 +1,48 @@
|
|
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
|
+
import { Command, type Editor } from 'ckeditor5/src/core';
|
6
|
+
/**
|
7
|
+
* The command that allows navigation across the exceptions in the edited document.
|
8
|
+
*/
|
9
|
+
export default class RestrictedEditingModeNavigationCommand extends Command {
|
10
|
+
/**
|
11
|
+
* The direction of the command.
|
12
|
+
*/
|
13
|
+
private _direction;
|
14
|
+
/**
|
15
|
+
* Creates an instance of the command.
|
16
|
+
*
|
17
|
+
* @param editor The editor instance.
|
18
|
+
* @param direction The direction that the command works.
|
19
|
+
*/
|
20
|
+
constructor(editor: Editor, direction: RestrictedEditingModeNavigationDirection);
|
21
|
+
/**
|
22
|
+
* @inheritDoc
|
23
|
+
*/
|
24
|
+
refresh(): void;
|
25
|
+
/**
|
26
|
+
* Executes the command.
|
27
|
+
*
|
28
|
+
* @fires execute
|
29
|
+
*/
|
30
|
+
execute(): void;
|
31
|
+
/**
|
32
|
+
* Checks whether the command can be enabled in the current context.
|
33
|
+
*
|
34
|
+
* @returns Whether the command should be enabled.
|
35
|
+
*/
|
36
|
+
private _checkEnabled;
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Directions in which the
|
40
|
+
* {@link module:restricted-editing/restrictededitingmodenavigationcommand~RestrictedEditingModeNavigationCommand} can work.
|
41
|
+
*/
|
42
|
+
export type RestrictedEditingModeNavigationDirection = 'forward' | 'backward';
|
43
|
+
declare module '@ckeditor/ckeditor5-core' {
|
44
|
+
interface CommandsMap {
|
45
|
+
goToPreviousRestrictedEditingException: RestrictedEditingModeNavigationCommand;
|
46
|
+
goToNextRestrictedEditingException: RestrictedEditingModeNavigationCommand;
|
47
|
+
}
|
48
|
+
}
|
@@ -2,119 +2,93 @@
|
|
2
2
|
* @license Copyright (c) 2003-2023, 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
|
-
/**
|
7
|
-
* @module restricted-editing/restrictededitingmodenavigationcommand
|
8
|
-
*/
|
9
|
-
|
10
5
|
import { Command } from 'ckeditor5/src/core';
|
11
|
-
|
12
6
|
/**
|
13
7
|
* The command that allows navigation across the exceptions in the edited document.
|
14
|
-
*
|
15
|
-
* @extends module:core/command~Command
|
16
8
|
*/
|
17
9
|
export default class RestrictedEditingModeNavigationCommand extends Command {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Checks whether the command can be enabled in the current context.
|
62
|
-
*
|
63
|
-
* @private
|
64
|
-
* @returns {Boolean} Whether the command should be enabled.
|
65
|
-
*/
|
66
|
-
_checkEnabled() {
|
67
|
-
return !!getNearestExceptionRange( this.editor.model, this._direction );
|
68
|
-
}
|
10
|
+
/**
|
11
|
+
* Creates an instance of the command.
|
12
|
+
*
|
13
|
+
* @param editor The editor instance.
|
14
|
+
* @param direction The direction that the command works.
|
15
|
+
*/
|
16
|
+
constructor(editor, direction) {
|
17
|
+
super(editor);
|
18
|
+
// It does not affect data so should be enabled in read-only mode and in restricted editing mode.
|
19
|
+
this.affectsData = false;
|
20
|
+
this._direction = direction;
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* @inheritDoc
|
24
|
+
*/
|
25
|
+
refresh() {
|
26
|
+
this.isEnabled = this._checkEnabled();
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Executes the command.
|
30
|
+
*
|
31
|
+
* @fires execute
|
32
|
+
*/
|
33
|
+
execute() {
|
34
|
+
const position = getNearestExceptionRange(this.editor.model, this._direction);
|
35
|
+
if (!position) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
this.editor.model.change(writer => {
|
39
|
+
writer.setSelection(position);
|
40
|
+
});
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Checks whether the command can be enabled in the current context.
|
44
|
+
*
|
45
|
+
* @returns Whether the command should be enabled.
|
46
|
+
*/
|
47
|
+
_checkEnabled() {
|
48
|
+
return !!getNearestExceptionRange(this.editor.model, this._direction);
|
49
|
+
}
|
69
50
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
return markerRanges.sort( ( rangeA, rangeB ) => {
|
114
|
-
if ( direction === 'forward' ) {
|
115
|
-
return rangeA.start.isAfter( rangeB.start ) ? 1 : -1;
|
116
|
-
} else {
|
117
|
-
return rangeA.start.isBefore( rangeB.start ) ? 1 : -1;
|
118
|
-
}
|
119
|
-
} ).shift();
|
51
|
+
/**
|
52
|
+
* Returns the range of the exception marker closest to the last position of the model selection.
|
53
|
+
*/
|
54
|
+
function getNearestExceptionRange(model, direction) {
|
55
|
+
const selection = model.document.selection;
|
56
|
+
const selectionPosition = selection.getFirstPosition();
|
57
|
+
const markerRanges = [];
|
58
|
+
// Get all exception marker positions that start after/before the selection position.
|
59
|
+
for (const marker of model.markers.getMarkersGroup('restrictedEditingException')) {
|
60
|
+
const markerRange = marker.getRange();
|
61
|
+
// Checking parent because there two positions <paragraph>foo^</paragraph><paragraph>^bar</paragraph>
|
62
|
+
// are touching but they will represent different markers.
|
63
|
+
const isMarkerRangeTouching = selectionPosition.isTouching(markerRange.start) && selectionPosition.hasSameParentAs(markerRange.start) ||
|
64
|
+
selectionPosition.isTouching(markerRange.end) && selectionPosition.hasSameParentAs(markerRange.end);
|
65
|
+
// <paragraph>foo <marker≥b[]ar</marker> baz</paragraph>
|
66
|
+
// <paragraph>foo <marker≥b[ar</marker> ba]z</paragraph>
|
67
|
+
// <paragraph>foo <marker≥bar</marker>[] baz</paragraph>
|
68
|
+
// <paragraph>foo []<marker≥bar</marker> baz</paragraph>
|
69
|
+
if (markerRange.containsPosition(selectionPosition) || isMarkerRangeTouching) {
|
70
|
+
continue;
|
71
|
+
}
|
72
|
+
if (direction === 'forward' && markerRange.start.isAfter(selectionPosition)) {
|
73
|
+
markerRanges.push(markerRange);
|
74
|
+
}
|
75
|
+
else if (direction === 'backward' && markerRange.end.isBefore(selectionPosition)) {
|
76
|
+
markerRanges.push(markerRange);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
if (!markerRanges.length) {
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
// Get the marker closest to the selection position among many. To know that, we need to sort
|
83
|
+
// them first.
|
84
|
+
return markerRanges
|
85
|
+
.sort((rangeA, rangeB) => {
|
86
|
+
if (direction === 'forward') {
|
87
|
+
return rangeA.start.isAfter(rangeB.start) ? 1 : -1;
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
return rangeA.start.isBefore(rangeB.start) ? 1 : -1;
|
91
|
+
}
|
92
|
+
})
|
93
|
+
.shift();
|
120
94
|
}
|
@@ -0,0 +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 restricted-editing/restrictededitingmodeui
|
7
|
+
*/
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
9
|
+
/**
|
10
|
+
* The restricted editing mode UI feature.
|
11
|
+
*
|
12
|
+
* It introduces the `'restrictedEditing'` dropdown that offers tools to navigate between exceptions across
|
13
|
+
* the document.
|
14
|
+
*/
|
15
|
+
export default class RestrictedEditingModeUI extends Plugin {
|
16
|
+
/**
|
17
|
+
* @inheritDoc
|
18
|
+
*/
|
19
|
+
static get pluginName(): 'RestrictedEditingModeUI';
|
20
|
+
/**
|
21
|
+
* @inheritDoc
|
22
|
+
*/
|
23
|
+
init(): void;
|
24
|
+
/**
|
25
|
+
* Returns a definition of the navigation button to be used in the dropdown.
|
26
|
+
|
27
|
+
* @param commandName The name of the command that the button represents.
|
28
|
+
* @param label The translated label of the button.
|
29
|
+
* @param keystroke The button keystroke.
|
30
|
+
*/
|
31
|
+
private _getButtonDefinition;
|
32
|
+
}
|
33
|
+
declare module '@ckeditor/ckeditor5-core' {
|
34
|
+
interface PluginsMap {
|
35
|
+
[RestrictedEditingModeUI.pluginName]: RestrictedEditingModeUI;
|
36
|
+
}
|
37
|
+
}
|
@@ -2,99 +2,74 @@
|
|
2
2
|
* @license Copyright (c) 2003-2023, 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 restricted-editing/restrictededitingmodeui
|
8
7
|
*/
|
9
|
-
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
11
9
|
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
12
10
|
import { Collection } from 'ckeditor5/src/utils';
|
13
|
-
|
14
11
|
import lockIcon from '../theme/icons/contentlock.svg';
|
15
|
-
|
16
12
|
/**
|
17
13
|
* The restricted editing mode UI feature.
|
18
14
|
*
|
19
15
|
* It introduces the `'restrictedEditing'` dropdown that offers tools to navigate between exceptions across
|
20
16
|
* the document.
|
21
|
-
*
|
22
|
-
* @extends module:core/plugin~Plugin
|
23
17
|
*/
|
24
18
|
export default class RestrictedEditingModeUI extends Plugin {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
isEnabled: true,
|
61
|
-
isOn: false
|
62
|
-
} );
|
63
|
-
|
64
|
-
this.listenTo( dropdownView, 'execute', evt => {
|
65
|
-
editor.execute( evt.source._commandName );
|
66
|
-
editor.editing.view.focus();
|
67
|
-
} );
|
68
|
-
|
69
|
-
return dropdownView;
|
70
|
-
} );
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Returns a definition of the navigation button to be used in the dropdown.
|
75
|
-
*
|
76
|
-
* @private
|
77
|
-
* @param {String} commandName The name of the command that the button represents.
|
78
|
-
* @param {String} label The translated label of the button.
|
79
|
-
* @param {String} keystroke The button keystroke.
|
80
|
-
* @returns {module:ui/dropdown/utils~ListDropdownItemDefinition}
|
81
|
-
*/
|
82
|
-
_getButtonDefinition( commandName, label, keystroke ) {
|
83
|
-
const editor = this.editor;
|
84
|
-
const command = editor.commands.get( commandName );
|
85
|
-
const definition = {
|
86
|
-
type: 'button',
|
87
|
-
model: new Model( {
|
88
|
-
label,
|
89
|
-
withText: true,
|
90
|
-
keystroke,
|
91
|
-
withKeystroke: true,
|
92
|
-
_commandName: commandName
|
93
|
-
} )
|
94
|
-
};
|
95
|
-
|
96
|
-
definition.model.bind( 'isEnabled' ).to( command, 'isEnabled' );
|
19
|
+
/**
|
20
|
+
* @inheritDoc
|
21
|
+
*/
|
22
|
+
static get pluginName() {
|
23
|
+
return 'RestrictedEditingModeUI';
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* @inheritDoc
|
27
|
+
*/
|
28
|
+
init() {
|
29
|
+
const editor = this.editor;
|
30
|
+
const t = editor.t;
|
31
|
+
editor.ui.componentFactory.add('restrictedEditing', locale => {
|
32
|
+
const dropdownView = createDropdown(locale);
|
33
|
+
const listItems = new Collection();
|
34
|
+
listItems.add(this._getButtonDefinition('goToPreviousRestrictedEditingException', t('Previous editable region'), 'Shift+Tab'));
|
35
|
+
listItems.add(this._getButtonDefinition('goToNextRestrictedEditingException', t('Next editable region'), 'Tab'));
|
36
|
+
addListToDropdown(dropdownView, listItems);
|
37
|
+
dropdownView.buttonView.set({
|
38
|
+
label: t('Navigate editable regions'),
|
39
|
+
icon: lockIcon,
|
40
|
+
tooltip: true,
|
41
|
+
isEnabled: true,
|
42
|
+
isOn: false
|
43
|
+
});
|
44
|
+
this.listenTo(dropdownView, 'execute', evt => {
|
45
|
+
const { _commandName } = evt.source;
|
46
|
+
editor.execute(_commandName);
|
47
|
+
editor.editing.view.focus();
|
48
|
+
});
|
49
|
+
return dropdownView;
|
50
|
+
});
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Returns a definition of the navigation button to be used in the dropdown.
|
97
54
|
|
98
|
-
|
99
|
-
|
55
|
+
* @param commandName The name of the command that the button represents.
|
56
|
+
* @param label The translated label of the button.
|
57
|
+
* @param keystroke The button keystroke.
|
58
|
+
*/
|
59
|
+
_getButtonDefinition(commandName, label, keystroke) {
|
60
|
+
const editor = this.editor;
|
61
|
+
const command = editor.commands.get(commandName);
|
62
|
+
const definition = {
|
63
|
+
type: 'button',
|
64
|
+
model: new Model({
|
65
|
+
label,
|
66
|
+
withText: true,
|
67
|
+
keystroke,
|
68
|
+
withKeystroke: true,
|
69
|
+
_commandName: commandName
|
70
|
+
})
|
71
|
+
};
|
72
|
+
definition.model.bind('isEnabled').to(command, 'isEnabled');
|
73
|
+
return definition;
|
74
|
+
}
|
100
75
|
}
|
@@ -0,0 +1,29 @@
|
|
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 restricted-editing/standardeditingmode
|
7
|
+
*/
|
8
|
+
import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
|
9
|
+
import '../theme/restrictedediting.css';
|
10
|
+
/**
|
11
|
+
* The standard editing mode plugin.
|
12
|
+
*
|
13
|
+
* This is a "glue" plugin that loads the following plugins:
|
14
|
+
*
|
15
|
+
* * The {@link module:restricted-editing/standardeditingmodeediting~StandardEditingModeEditing standard mode editing feature}.
|
16
|
+
* * The {@link module:restricted-editing/standardeditingmodeui~StandardEditingModeUI standard mode UI feature}.
|
17
|
+
*/
|
18
|
+
export default class StandardEditingMode extends Plugin {
|
19
|
+
/**
|
20
|
+
* @inheritDoc
|
21
|
+
*/
|
22
|
+
static get pluginName(): 'StandardEditingMode';
|
23
|
+
static get requires(): PluginDependencies;
|
24
|
+
}
|
25
|
+
declare module '@ckeditor/ckeditor5-core' {
|
26
|
+
interface PluginsMap {
|
27
|
+
[StandardEditingMode.pluginName]: StandardEditingMode;
|
28
|
+
}
|
29
|
+
}
|
@@ -2,18 +2,13 @@
|
|
2
2
|
* @license Copyright (c) 2003-2023, 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 restricted-editing/standardeditingmode
|
8
7
|
*/
|
9
|
-
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
11
|
-
|
12
9
|
import StandardEditingModeEditing from './standardeditingmodeediting';
|
13
10
|
import StandardEditingModeUI from './standardeditingmodeui';
|
14
|
-
|
15
11
|
import '../theme/restrictedediting.css';
|
16
|
-
|
17
12
|
/**
|
18
13
|
* The standard editing mode plugin.
|
19
14
|
*
|
@@ -21,18 +16,15 @@ import '../theme/restrictedediting.css';
|
|
21
16
|
*
|
22
17
|
* * The {@link module:restricted-editing/standardeditingmodeediting~StandardEditingModeEditing standard mode editing feature}.
|
23
18
|
* * The {@link module:restricted-editing/standardeditingmodeui~StandardEditingModeUI standard mode UI feature}.
|
24
|
-
*
|
25
|
-
* @extends module:core/plugin~Plugin
|
26
19
|
*/
|
27
20
|
export default class StandardEditingMode extends Plugin {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
21
|
+
/**
|
22
|
+
* @inheritDoc
|
23
|
+
*/
|
24
|
+
static get pluginName() {
|
25
|
+
return 'StandardEditingMode';
|
26
|
+
}
|
27
|
+
static get requires() {
|
28
|
+
return [StandardEditingModeEditing, StandardEditingModeUI];
|
29
|
+
}
|
38
30
|
}
|
@@ -0,0 +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 restricted-editing/standardeditingmodeediting
|
7
|
+
*/
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
9
|
+
/**
|
10
|
+
* The standard editing mode editing feature.
|
11
|
+
*
|
12
|
+
* * It introduces the `restrictedEditingException` text attribute that is rendered as
|
13
|
+
* a `<span>` element with the `restricted-editing-exception` CSS class.
|
14
|
+
* * It registers the `'restrictedEditingException'` command.
|
15
|
+
*/
|
16
|
+
export default class StandardEditingModeEditing extends Plugin {
|
17
|
+
/**
|
18
|
+
* @inheritDoc
|
19
|
+
*/
|
20
|
+
static get pluginName(): 'StandardEditingModeEditing';
|
21
|
+
/**
|
22
|
+
* @inheritDoc
|
23
|
+
*/
|
24
|
+
init(): void;
|
25
|
+
}
|
26
|
+
declare module '@ckeditor/ckeditor5-core' {
|
27
|
+
interface PluginsMap {
|
28
|
+
[StandardEditingModeEditing.pluginName]: StandardEditingModeEditing;
|
29
|
+
}
|
30
|
+
}
|
@@ -2,64 +2,52 @@
|
|
2
2
|
* @license Copyright (c) 2003-2023, 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 restricted-editing/standardeditingmodeediting
|
8
7
|
*/
|
9
|
-
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
11
|
-
|
12
9
|
import RestrictedEditingExceptionCommand from './restrictededitingexceptioncommand';
|
13
|
-
|
14
10
|
/**
|
15
11
|
* The standard editing mode editing feature.
|
16
12
|
*
|
17
13
|
* * It introduces the `restrictedEditingException` text attribute that is rendered as
|
18
14
|
* a `<span>` element with the `restricted-editing-exception` CSS class.
|
19
15
|
* * It registers the `'restrictedEditingException'` command.
|
20
|
-
*
|
21
|
-
* @extends module:core/plugin~Plugin
|
22
16
|
*/
|
23
17
|
export default class StandardEditingModeEditing extends Plugin {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
editor.editing.view.change( writer => {
|
60
|
-
for ( const root of editor.editing.view.document.roots ) {
|
61
|
-
writer.addClass( 'ck-restricted-editing_mode_standard', root );
|
62
|
-
}
|
63
|
-
} );
|
64
|
-
}
|
18
|
+
/**
|
19
|
+
* @inheritDoc
|
20
|
+
*/
|
21
|
+
static get pluginName() {
|
22
|
+
return 'StandardEditingModeEditing';
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* @inheritDoc
|
26
|
+
*/
|
27
|
+
init() {
|
28
|
+
const editor = this.editor;
|
29
|
+
editor.model.schema.extend('$text', { allowAttributes: ['restrictedEditingException'] });
|
30
|
+
editor.conversion.for('upcast').elementToAttribute({
|
31
|
+
model: 'restrictedEditingException',
|
32
|
+
view: {
|
33
|
+
name: 'span',
|
34
|
+
classes: 'restricted-editing-exception'
|
35
|
+
}
|
36
|
+
});
|
37
|
+
editor.conversion.for('downcast').attributeToElement({
|
38
|
+
model: 'restrictedEditingException',
|
39
|
+
view: (modelAttributeValue, { writer }) => {
|
40
|
+
if (modelAttributeValue) {
|
41
|
+
// Make the restricted editing <span> outer-most in the view.
|
42
|
+
return writer.createAttributeElement('span', { class: 'restricted-editing-exception' }, { priority: -10 });
|
43
|
+
}
|
44
|
+
}
|
45
|
+
});
|
46
|
+
editor.commands.add('restrictedEditingException', new RestrictedEditingExceptionCommand(editor));
|
47
|
+
editor.editing.view.change(writer => {
|
48
|
+
for (const root of editor.editing.view.document.roots) {
|
49
|
+
writer.addClass('ck-restricted-editing_mode_standard', root);
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}
|
65
53
|
}
|