@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.
@@ -2,17 +2,9 @@
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/restrictededitingmode/converters
8
- */
9
-
10
5
  import { Matcher } from 'ckeditor5/src/engine';
11
-
12
6
  import { getMarkerAtPosition } from './utils';
13
-
14
7
  const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
15
-
16
8
  /**
17
9
  * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
18
10
  *
@@ -24,168 +16,127 @@ const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
24
16
  * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
25
17
  *
26
18
  * This way, adding and removing the highlight does not interfere with conversion.
27
- *
28
- * @param {module:core/editor/editor~Editor} editor
29
19
  */
30
- export function setupExceptionHighlighting( editor ) {
31
- const view = editor.editing.view;
32
- const model = editor.model;
33
- const highlightedMarkers = new Set();
34
-
35
- // Adding the class.
36
- view.document.registerPostFixer( writer => {
37
- const modelSelection = model.document.selection;
38
-
39
- const marker = getMarkerAtPosition( editor, modelSelection.anchor );
40
-
41
- if ( !marker ) {
42
- return;
43
- }
44
-
45
- for ( const viewElement of editor.editing.mapper.markerNameToElements( marker.name ) ) {
46
- writer.addClass( HIGHLIGHT_CLASS, viewElement );
47
- highlightedMarkers.add( viewElement );
48
- }
49
- } );
50
-
51
- // Removing the class.
52
- editor.conversion.for( 'editingDowncast' ).add( dispatcher => {
53
- // Make sure the highlight is removed on every possible event, before conversion is started.
54
- dispatcher.on( 'insert', removeHighlight, { priority: 'highest' } );
55
- dispatcher.on( 'remove', removeHighlight, { priority: 'highest' } );
56
- dispatcher.on( 'attribute', removeHighlight, { priority: 'highest' } );
57
- dispatcher.on( 'selection', removeHighlight, { priority: 'highest' } );
58
-
59
- function removeHighlight() {
60
- view.change( writer => {
61
- for ( const item of highlightedMarkers.values() ) {
62
- writer.removeClass( HIGHLIGHT_CLASS, item );
63
- highlightedMarkers.delete( item );
64
- }
65
- } );
66
- }
67
- } );
20
+ export function setupExceptionHighlighting(editor) {
21
+ const view = editor.editing.view;
22
+ const model = editor.model;
23
+ const highlightedMarkers = new Set();
24
+ // Adding the class.
25
+ view.document.registerPostFixer((writer) => {
26
+ const modelSelection = model.document.selection;
27
+ const marker = getMarkerAtPosition(editor, modelSelection.anchor);
28
+ if (!marker) {
29
+ return false;
30
+ }
31
+ for (const viewElement of editor.editing.mapper.markerNameToElements(marker.name)) {
32
+ writer.addClass(HIGHLIGHT_CLASS, viewElement);
33
+ highlightedMarkers.add(viewElement);
34
+ }
35
+ return false;
36
+ });
37
+ // Removing the class.
38
+ editor.conversion.for('editingDowncast').add(dispatcher => {
39
+ // Make sure the highlight is removed on every possible event, before conversion is started.
40
+ dispatcher.on('insert', removeHighlight, { priority: 'highest' });
41
+ dispatcher.on('remove', removeHighlight, { priority: 'highest' });
42
+ dispatcher.on('attribute', removeHighlight, { priority: 'highest' });
43
+ dispatcher.on('selection', removeHighlight, { priority: 'highest' });
44
+ function removeHighlight() {
45
+ view.change(writer => {
46
+ for (const item of highlightedMarkers.values()) {
47
+ writer.removeClass(HIGHLIGHT_CLASS, item);
48
+ highlightedMarkers.delete(item);
49
+ }
50
+ });
51
+ }
52
+ });
68
53
  }
69
-
70
54
  /**
71
55
  * A post-fixer that prevents removing a collapsed marker from the document.
72
- *
73
- * @param {module:core/editor/editor~Editor} editor
74
- * @returns {Function}
75
56
  */
76
- export function resurrectCollapsedMarkerPostFixer( editor ) {
77
- // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
78
- return writer => {
79
- let changeApplied = false;
80
-
81
- for ( const { name, data } of editor.model.document.differ.getChangedMarkers() ) {
82
- if ( name.startsWith( 'restrictedEditingException' ) && data.newRange && data.newRange.root.rootName == '$graveyard' ) {
83
- writer.updateMarker( name, {
84
- range: writer.createRange( writer.createPositionAt( data.oldRange.start ) )
85
- } );
86
-
87
- changeApplied = true;
88
- }
89
- }
90
-
91
- return changeApplied;
92
- };
57
+ export function resurrectCollapsedMarkerPostFixer(editor) {
58
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
59
+ return writer => {
60
+ let changeApplied = false;
61
+ for (const { name, data } of editor.model.document.differ.getChangedMarkers()) {
62
+ if (name.startsWith('restrictedEditingException') && data.newRange && data.newRange.root.rootName == '$graveyard') {
63
+ writer.updateMarker(name, {
64
+ range: writer.createRange(writer.createPositionAt(data.oldRange.start))
65
+ });
66
+ changeApplied = true;
67
+ }
68
+ }
69
+ return changeApplied;
70
+ };
93
71
  }
94
-
95
72
  /**
96
73
  * A post-fixer that extends a marker when the user types on its boundaries.
97
- *
98
- * @param {module:core/editor/editor~Editor} editor
99
- * @returns {Function}
100
74
  */
101
- export function extendMarkerOnTypingPostFixer( editor ) {
102
- // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
103
- return writer => {
104
- let changeApplied = false;
105
-
106
- for ( const change of editor.model.document.differ.getChanges() ) {
107
- if ( change.type == 'insert' && change.name == '$text' ) {
108
- changeApplied = _tryExtendMarkerStart( editor, change.position, change.length, writer ) || changeApplied;
109
- changeApplied = _tryExtendMarkedEnd( editor, change.position, change.length, writer ) || changeApplied;
110
- }
111
- }
112
-
113
- return changeApplied;
114
- };
75
+ export function extendMarkerOnTypingPostFixer(editor) {
76
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
77
+ return writer => {
78
+ let changeApplied = false;
79
+ for (const change of editor.model.document.differ.getChanges()) {
80
+ if (change.type == 'insert' && change.name == '$text') {
81
+ changeApplied = _tryExtendMarkerStart(editor, change.position, change.length, writer) || changeApplied;
82
+ changeApplied = _tryExtendMarkedEnd(editor, change.position, change.length, writer) || changeApplied;
83
+ }
84
+ }
85
+ return changeApplied;
86
+ };
115
87
  }
116
-
117
88
  /**
118
89
  * A view highlight-to-marker conversion helper.
119
90
  *
120
- * @param {Object} config Conversion configuration.
121
- * @param {module:engine/view/matcher~MatcherPattern} [config.view] A pattern matching all view elements which should be converted. If not
122
- * set, the converter will fire for every view element.
123
- * @param {String|module:engine/model/element~Element|Function} config.model The name of the model element, a model element
124
- * instance or a function that takes a view element and returns a model element. The model element will be inserted in the model.
125
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
91
+ * @param config Conversion configuration.
126
92
  */
127
- export function upcastHighlightToMarker( config ) {
128
- return dispatcher => dispatcher.on( 'element:span', ( evt, data, conversionApi ) => {
129
- const { writer } = conversionApi;
130
-
131
- const matcher = new Matcher( config.view );
132
- const matcherResult = matcher.match( data.viewItem );
133
-
134
- // If there is no match, this callback should not do anything.
135
- if ( !matcherResult ) {
136
- return;
137
- }
138
-
139
- const match = matcherResult.match;
140
-
141
- // Force consuming element's name (taken from upcast helpers elementToElement converter).
142
- match.name = true;
143
-
144
- const { modelRange: convertedChildrenRange } = conversionApi.convertChildren( data.viewItem, data.modelCursor );
145
- conversionApi.consumable.consume( data.viewItem, match );
146
-
147
- const markerName = config.model( data.viewItem );
148
- const fakeMarkerStart = writer.createElement( '$marker', { 'data-name': markerName } );
149
- const fakeMarkerEnd = writer.createElement( '$marker', { 'data-name': markerName } );
150
-
151
- // Insert in reverse order to use converter content positions directly (without recalculating).
152
- writer.insert( fakeMarkerEnd, convertedChildrenRange.end );
153
- writer.insert( fakeMarkerStart, convertedChildrenRange.start );
154
-
155
- data.modelRange = writer.createRange(
156
- writer.createPositionBefore( fakeMarkerStart ),
157
- writer.createPositionAfter( fakeMarkerEnd )
158
- );
159
- data.modelCursor = data.modelRange.end;
160
- } );
93
+ export function upcastHighlightToMarker(config) {
94
+ return (dispatcher) => dispatcher.on('element:span', (evt, data, conversionApi) => {
95
+ const { writer } = conversionApi;
96
+ const matcher = new Matcher(config.view);
97
+ const matcherResult = matcher.match(data.viewItem);
98
+ // If there is no match, this callback should not do anything.
99
+ if (!matcherResult) {
100
+ return;
101
+ }
102
+ const match = matcherResult.match;
103
+ // Force consuming element's name (taken from upcast helpers elementToElement converter).
104
+ match.name = true;
105
+ const { modelRange: convertedChildrenRange } = conversionApi.convertChildren(data.viewItem, data.modelCursor);
106
+ conversionApi.consumable.consume(data.viewItem, match);
107
+ const markerName = config.model();
108
+ const fakeMarkerStart = writer.createElement('$marker', { 'data-name': markerName });
109
+ const fakeMarkerEnd = writer.createElement('$marker', { 'data-name': markerName });
110
+ // Insert in reverse order to use converter content positions directly (without recalculating).
111
+ writer.insert(fakeMarkerEnd, convertedChildrenRange.end);
112
+ writer.insert(fakeMarkerStart, convertedChildrenRange.start);
113
+ data.modelRange = writer.createRange(writer.createPositionBefore(fakeMarkerStart), writer.createPositionAfter(fakeMarkerEnd));
114
+ data.modelCursor = data.modelRange.end;
115
+ });
161
116
  }
162
-
163
- // Extend marker if change detected on marker's start position.
164
- function _tryExtendMarkerStart( editor, position, length, writer ) {
165
- const markerAtStart = getMarkerAtPosition( editor, position.getShiftedBy( length ) );
166
-
167
- if ( markerAtStart && markerAtStart.getStart().isEqual( position.getShiftedBy( length ) ) ) {
168
- writer.updateMarker( markerAtStart, {
169
- range: writer.createRange( markerAtStart.getStart().getShiftedBy( -length ), markerAtStart.getEnd() )
170
- } );
171
-
172
- return true;
173
- }
174
-
175
- return false;
117
+ /**
118
+ * Extend marker if change detected on marker's start position.
119
+ */
120
+ function _tryExtendMarkerStart(editor, position, length, writer) {
121
+ const markerAtStart = getMarkerAtPosition(editor, position.getShiftedBy(length));
122
+ if (markerAtStart && markerAtStart.getStart().isEqual(position.getShiftedBy(length))) {
123
+ writer.updateMarker(markerAtStart, {
124
+ range: writer.createRange(markerAtStart.getStart().getShiftedBy(-length), markerAtStart.getEnd())
125
+ });
126
+ return true;
127
+ }
128
+ return false;
176
129
  }
177
-
178
- // Extend marker if change detected on marker's end position.
179
- function _tryExtendMarkedEnd( editor, position, length, writer ) {
180
- const markerAtEnd = getMarkerAtPosition( editor, position );
181
-
182
- if ( markerAtEnd && markerAtEnd.getEnd().isEqual( position ) ) {
183
- writer.updateMarker( markerAtEnd, {
184
- range: writer.createRange( markerAtEnd.getStart(), markerAtEnd.getEnd().getShiftedBy( length ) )
185
- } );
186
-
187
- return true;
188
- }
189
-
190
- return false;
130
+ /**
131
+ * Extend marker if change detected on marker's end position.
132
+ */
133
+ function _tryExtendMarkedEnd(editor, position, length, writer) {
134
+ const markerAtEnd = getMarkerAtPosition(editor, position);
135
+ if (markerAtEnd && markerAtEnd.getEnd().isEqual(position)) {
136
+ writer.updateMarker(markerAtEnd, {
137
+ range: writer.createRange(markerAtEnd.getStart(), markerAtEnd.getEnd().getShiftedBy(length))
138
+ });
139
+ return true;
140
+ }
141
+ return false;
191
142
  }
@@ -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
+ import type { Editor } from 'ckeditor5/src/core';
6
+ import type { DocumentSelection, Marker, Position, Range } from 'ckeditor5/src/engine';
7
+ /**
8
+ * @module restricted-editing/restrictededitingmode/utils
9
+ */
10
+ /**
11
+ * Returns a single "restricted-editing-exception" marker at a given position. Contrary to
12
+ * {@link module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition}, it returnd a marker also when the postion is
13
+ * equal to one of the marker's start or end positions.
14
+ */
15
+ export declare function getMarkerAtPosition(editor: Editor, position: Position): Marker | undefined;
16
+ /**
17
+ * Checks if the position is fully contained in the range. Positions equal to range start or end are considered "in".
18
+ */
19
+ export declare function isPositionInRangeBoundaries(range: Range, position: Position): boolean;
20
+ /**
21
+ * Checks if the selection is fully contained in the marker. Positions on marker boundaries are considered "in".
22
+ *
23
+ * ```xml
24
+ * <marker>[]foo</marker> -> true
25
+ * <marker>f[oo]</marker> -> true
26
+ * <marker>f[oo</marker> ba]r -> false
27
+ * <marker>foo</marker> []bar -> false
28
+ * ```
29
+ */
30
+ export declare function isSelectionInMarker(selection: DocumentSelection, marker?: Marker): boolean;
@@ -2,69 +2,49 @@
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/restrictededitingmode/utils
8
7
  */
9
-
10
8
  /**
11
9
  * Returns a single "restricted-editing-exception" marker at a given position. Contrary to
12
10
  * {@link module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition}, it returnd a marker also when the postion is
13
11
  * equal to one of the marker's start or end positions.
14
- *
15
- * @param {module:core/editor/editor~Editor} editor
16
- * @param {module:engine/model/position~Position} position
17
- * @returns {module:engine/model/markercollection~Marker|undefined} marker
18
12
  */
19
- export function getMarkerAtPosition( editor, position ) {
20
- for ( const marker of editor.model.markers ) {
21
- const markerRange = marker.getRange();
22
-
23
- if ( isPositionInRangeBoundaries( markerRange, position ) ) {
24
- if ( marker.name.startsWith( 'restrictedEditingException:' ) ) {
25
- return marker;
26
- }
27
- }
28
- }
13
+ export function getMarkerAtPosition(editor, position) {
14
+ for (const marker of editor.model.markers) {
15
+ const markerRange = marker.getRange();
16
+ if (isPositionInRangeBoundaries(markerRange, position)) {
17
+ if (marker.name.startsWith('restrictedEditingException:')) {
18
+ return marker;
19
+ }
20
+ }
21
+ }
29
22
  }
30
-
31
23
  /**
32
24
  * Checks if the position is fully contained in the range. Positions equal to range start or end are considered "in".
33
- *
34
- * @param {module:engine/model/range~Range} range
35
- * @param {module:engine/model/position~Position} position
36
- * @returns {Boolean}
37
25
  */
38
- export function isPositionInRangeBoundaries( range, position ) {
39
- return (
40
- range.containsPosition( position ) ||
41
- range.end.isEqual( position ) ||
42
- range.start.isEqual( position )
43
- );
26
+ export function isPositionInRangeBoundaries(range, position) {
27
+ return (range.containsPosition(position) ||
28
+ range.end.isEqual(position) ||
29
+ range.start.isEqual(position));
44
30
  }
45
-
46
31
  /**
47
32
  * Checks if the selection is fully contained in the marker. Positions on marker boundaries are considered "in".
48
33
  *
49
- * <marker>[]foo</marker> -> true
50
- * <marker>f[oo]</marker> -> true
51
- * <marker>f[oo</marker> ba]r -> false
52
- * <marker>foo</marker> []bar -> false
53
- *
54
- * @param {module:engine/model/selection~Selection} selection
55
- * @param {module:engine/model/markercollection~Marker} marker
56
- * @returns {Boolean}
34
+ * ```xml
35
+ * <marker>[]foo</marker> -> true
36
+ * <marker>f[oo]</marker> -> true
37
+ * <marker>f[oo</marker> ba]r -> false
38
+ * <marker>foo</marker> []bar -> false
39
+ * ```
57
40
  */
58
- export function isSelectionInMarker( selection, marker ) {
59
- if ( !marker ) {
60
- return false;
61
- }
62
-
63
- const markerRange = marker.getRange();
64
-
65
- if ( selection.isCollapsed ) {
66
- return isPositionInRangeBoundaries( markerRange, selection.focus );
67
- }
68
-
69
- return markerRange.containsRange( selection.getFirstRange(), true );
41
+ export function isSelectionInMarker(selection, marker) {
42
+ if (!marker) {
43
+ return false;
44
+ }
45
+ const markerRange = marker.getRange();
46
+ if (selection.isCollapsed) {
47
+ return isPositionInRangeBoundaries(markerRange, selection.focus);
48
+ }
49
+ return markerRange.containsRange(selection.getFirstRange(), true);
70
50
  }
@@ -0,0 +1,32 @@
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/restrictededitingmode
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ import '../theme/restrictedediting.css';
10
+ /**
11
+ * The restricted editing mode plugin.
12
+ *
13
+ * This is a "glue" plugin which loads the following plugins:
14
+ *
15
+ * * The {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing restricted mode editing feature}.
16
+ * * The {@link module:restricted-editing/restrictededitingmodeui~RestrictedEditingModeUI restricted mode UI feature}.
17
+ */
18
+ export default class RestrictedEditingMode extends Plugin {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName(): 'RestrictedEditingMode';
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires(): PluginDependencies;
27
+ }
28
+ declare module '@ckeditor/ckeditor5-core' {
29
+ interface PluginsMap {
30
+ [RestrictedEditingMode.pluginName]: RestrictedEditingMode;
31
+ }
32
+ }
@@ -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/restrictededitingmode
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import RestrictedEditingModeEditing from './restrictededitingmodeediting';
13
10
  import RestrictedEditingModeUI from './restrictededitingmodeui';
14
-
15
11
  import '../theme/restrictedediting.css';
16
-
17
12
  /**
18
13
  * The restricted editing mode plugin.
19
14
  *
@@ -21,83 +16,18 @@ import '../theme/restrictedediting.css';
21
16
  *
22
17
  * * The {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing restricted mode editing feature}.
23
18
  * * The {@link module:restricted-editing/restrictededitingmodeui~RestrictedEditingModeUI restricted mode UI feature}.
24
- *
25
- * @extends module:core/plugin~Plugin
26
19
  */
27
20
  export default class RestrictedEditingMode extends Plugin {
28
- /**
29
- * @inheritDoc
30
- */
31
- static get pluginName() {
32
- return 'RestrictedEditingMode';
33
- }
34
-
35
- /**
36
- * @inheritDoc
37
- */
38
- static get requires() {
39
- return [ RestrictedEditingModeEditing, RestrictedEditingModeUI ];
40
- }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName() {
25
+ return 'RestrictedEditingMode';
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get requires() {
31
+ return [RestrictedEditingModeEditing, RestrictedEditingModeUI];
32
+ }
41
33
  }
42
-
43
- /**
44
- * The configuration of the restricted editing mode feature. Introduced by the
45
- * {@link module:restricted-editing/restrictededitingmode~RestrictedEditingMode} feature.
46
- *
47
- * Read more in {@link module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig}.
48
- *
49
- * @member {module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig}
50
- * module:core/editor/editorconfig~EditorConfig#restrictedEditing
51
- */
52
-
53
- /**
54
- * The configuration of the restricted editing mode feature.
55
- * The option is used by the {@link module:restricted-editing/restrictededitingmode~RestrictedEditingMode} feature.
56
- *
57
- * ClassicEditor
58
- * .create( {
59
- * restrictedEditing: {
60
- * allowedCommands: [ 'bold', 'link', 'unlink' ],
61
- * allowedAttributes: [ 'bold', 'linkHref' ]
62
- * }
63
- * } )
64
- * .then( ... )
65
- * .catch( ... );
66
- *
67
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
68
- *
69
- * @interface module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig
70
- */
71
-
72
- /**
73
- * The command names allowed in non-restricted areas of the content.
74
- *
75
- * Defines which feature commands should be enabled in the restricted editing mode. The commands used for typing and deleting text
76
- * (`'input'`, `'delete'` and `'deleteForward'`) are allowed by the feature inside non-restricted regions and do not need to be defined.
77
- *
78
- * **Note**: The restricted editing mode always allows to use the restricted mode navigation commands as well as `'undo'` and `'redo'`
79
- * commands.
80
- *
81
- * The default value is:
82
- *
83
- * const restrictedEditingConfig = {
84
- * allowedCommands: [ 'bold', 'italic', 'link', 'unlink' ]
85
- * };
86
- *
87
- * To make a command always enabled (also outside non-restricted areas) use
88
- * {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing#enableCommand} method.
89
- *
90
- * @member {Array.<String>} module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig#allowedCommands
91
- */
92
-
93
- /**
94
- * The text attribute names allowed when pasting content ot non-restricted areas.
95
- *
96
- * The default value is:
97
- *
98
- * const restrictedEditingConfig = {
99
- * allowedAttributes: [ 'bold', 'italic', 'linkHref' ]
100
- * };
101
- *
102
- * @member {Array.<String>} module:restricted-editing/restrictededitingmode~RestrictedEditingModeConfig#allowedAttributes
103
- */
@@ -0,0 +1,88 @@
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/restrictededitingmodeediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ /**
10
+ * The restricted editing mode editing feature.
11
+ *
12
+ * * It introduces the exception marker group that renders to `<span>` elements with the `restricted-editing-exception` CSS class.
13
+ * * It registers the `'goToPreviousRestrictedEditingException'` and `'goToNextRestrictedEditingException'` commands.
14
+ * * It also enables highlighting exception markers that are selected.
15
+ */
16
+ export default class RestrictedEditingModeEditing extends Plugin {
17
+ /**
18
+ * Command names that are enabled outside the non-restricted regions.
19
+ */
20
+ private _alwaysEnabled;
21
+ /**
22
+ * Commands allowed in non-restricted areas.
23
+ *
24
+ * Commands always enabled combine typing feature commands: `'input'`, `'insertText'`, `'delete'`, and `'deleteForward'` with
25
+ * commands defined in the feature configuration.
26
+ */
27
+ private _allowedInException;
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName(): 'RestrictedEditingModeEditing';
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ constructor(editor: Editor);
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ init(): void;
40
+ /**
41
+ * Makes the given command always enabled in the restricted editing mode (regardless
42
+ * of selection location).
43
+ *
44
+ * To enable some commands in non-restricted areas of the content use
45
+ * {@link module:restricted-editing/restrictededitingconfig~RestrictedEditingConfig#allowedCommands} configuration option.
46
+ *
47
+ * @param commandName Name of the command to enable.
48
+ */
49
+ enableCommand(commandName: string): void;
50
+ /**
51
+ * Sets up the restricted mode editing conversion:
52
+ *
53
+ * * ucpast & downcast converters,
54
+ * * marker highlighting in the edting area,
55
+ * * marker post-fixers.
56
+ */
57
+ private _setupConversion;
58
+ /**
59
+ * Setups additional editing restrictions beyond command toggling:
60
+ *
61
+ * * delete content range trimming
62
+ * * disabling input command outside exception marker
63
+ * * restricting clipboard holder to text only
64
+ * * restricting text attributes in content
65
+ */
66
+ private _setupRestrictions;
67
+ /**
68
+ * Sets up the command toggling which enables or disables commands based on the user selection.
69
+ */
70
+ private _setupCommandsToggling;
71
+ /**
72
+ * Checks if commands should be enabled or disabled based on the current selection.
73
+ */
74
+ private _checkCommands;
75
+ /**
76
+ * Enables commands in non-restricted regions.
77
+ */
78
+ private _enableCommands;
79
+ /**
80
+ * Disables commands outside non-restricted regions.
81
+ */
82
+ private _disableCommands;
83
+ }
84
+ declare module '@ckeditor/ckeditor5-core' {
85
+ interface PluginsMap {
86
+ [RestrictedEditingModeEditing.pluginName]: RestrictedEditingModeEditing;
87
+ }
88
+ }