@ckeditor/ckeditor5-restricted-editing 41.3.1 → 41.4.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 (178) hide show
  1. package/build/restricted-editing.js +1 -1
  2. package/dist/index-content.css +4 -0
  3. package/dist/index-editor.css +4 -0
  4. package/dist/index.css +4 -0
  5. package/dist/index.js +977 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/translations/ar.d.ts +8 -0
  8. package/dist/translations/ar.js +5 -0
  9. package/dist/translations/ar.umd.js +11 -0
  10. package/dist/translations/az.d.ts +8 -0
  11. package/dist/translations/az.js +5 -0
  12. package/dist/translations/az.umd.js +11 -0
  13. package/dist/translations/bg.d.ts +8 -0
  14. package/dist/translations/bg.js +5 -0
  15. package/dist/translations/bg.umd.js +11 -0
  16. package/dist/translations/bn.d.ts +8 -0
  17. package/dist/translations/bn.js +5 -0
  18. package/dist/translations/bn.umd.js +11 -0
  19. package/dist/translations/ca.d.ts +8 -0
  20. package/dist/translations/ca.js +5 -0
  21. package/dist/translations/ca.umd.js +11 -0
  22. package/dist/translations/cs.d.ts +8 -0
  23. package/dist/translations/cs.js +5 -0
  24. package/dist/translations/cs.umd.js +11 -0
  25. package/dist/translations/da.d.ts +8 -0
  26. package/dist/translations/da.js +5 -0
  27. package/dist/translations/da.umd.js +11 -0
  28. package/dist/translations/de-ch.d.ts +8 -0
  29. package/dist/translations/de-ch.js +5 -0
  30. package/dist/translations/de-ch.umd.js +11 -0
  31. package/dist/translations/de.d.ts +8 -0
  32. package/dist/translations/de.js +5 -0
  33. package/dist/translations/de.umd.js +11 -0
  34. package/dist/translations/el.d.ts +8 -0
  35. package/dist/translations/el.js +5 -0
  36. package/dist/translations/el.umd.js +11 -0
  37. package/dist/translations/en-au.d.ts +8 -0
  38. package/dist/translations/en-au.js +5 -0
  39. package/dist/translations/en-au.umd.js +11 -0
  40. package/dist/translations/en-gb.d.ts +8 -0
  41. package/dist/translations/en-gb.js +5 -0
  42. package/dist/translations/en-gb.umd.js +11 -0
  43. package/dist/translations/en.d.ts +8 -0
  44. package/dist/translations/en.js +5 -0
  45. package/dist/translations/en.umd.js +11 -0
  46. package/dist/translations/es.d.ts +8 -0
  47. package/dist/translations/es.js +5 -0
  48. package/dist/translations/es.umd.js +11 -0
  49. package/dist/translations/et.d.ts +8 -0
  50. package/dist/translations/et.js +5 -0
  51. package/dist/translations/et.umd.js +11 -0
  52. package/dist/translations/fa.d.ts +8 -0
  53. package/dist/translations/fa.js +5 -0
  54. package/dist/translations/fa.umd.js +11 -0
  55. package/dist/translations/fi.d.ts +8 -0
  56. package/dist/translations/fi.js +5 -0
  57. package/dist/translations/fi.umd.js +11 -0
  58. package/dist/translations/fr.d.ts +8 -0
  59. package/dist/translations/fr.js +5 -0
  60. package/dist/translations/fr.umd.js +11 -0
  61. package/dist/translations/gl.d.ts +8 -0
  62. package/dist/translations/gl.js +5 -0
  63. package/dist/translations/gl.umd.js +11 -0
  64. package/dist/translations/he.d.ts +8 -0
  65. package/dist/translations/he.js +5 -0
  66. package/dist/translations/he.umd.js +11 -0
  67. package/dist/translations/hi.d.ts +8 -0
  68. package/dist/translations/hi.js +5 -0
  69. package/dist/translations/hi.umd.js +11 -0
  70. package/dist/translations/hr.d.ts +8 -0
  71. package/dist/translations/hr.js +5 -0
  72. package/dist/translations/hr.umd.js +11 -0
  73. package/dist/translations/hu.d.ts +8 -0
  74. package/dist/translations/hu.js +5 -0
  75. package/dist/translations/hu.umd.js +11 -0
  76. package/dist/translations/id.d.ts +8 -0
  77. package/dist/translations/id.js +5 -0
  78. package/dist/translations/id.umd.js +11 -0
  79. package/dist/translations/it.d.ts +8 -0
  80. package/dist/translations/it.js +5 -0
  81. package/dist/translations/it.umd.js +11 -0
  82. package/dist/translations/ja.d.ts +8 -0
  83. package/dist/translations/ja.js +5 -0
  84. package/dist/translations/ja.umd.js +11 -0
  85. package/dist/translations/ko.d.ts +8 -0
  86. package/dist/translations/ko.js +5 -0
  87. package/dist/translations/ko.umd.js +11 -0
  88. package/dist/translations/ku.d.ts +8 -0
  89. package/dist/translations/ku.js +5 -0
  90. package/dist/translations/ku.umd.js +11 -0
  91. package/dist/translations/lt.d.ts +8 -0
  92. package/dist/translations/lt.js +5 -0
  93. package/dist/translations/lt.umd.js +11 -0
  94. package/dist/translations/lv.d.ts +8 -0
  95. package/dist/translations/lv.js +5 -0
  96. package/dist/translations/lv.umd.js +11 -0
  97. package/dist/translations/ms.d.ts +8 -0
  98. package/dist/translations/ms.js +5 -0
  99. package/dist/translations/ms.umd.js +11 -0
  100. package/dist/translations/nl.d.ts +8 -0
  101. package/dist/translations/nl.js +5 -0
  102. package/dist/translations/nl.umd.js +11 -0
  103. package/dist/translations/no.d.ts +8 -0
  104. package/dist/translations/no.js +5 -0
  105. package/dist/translations/no.umd.js +11 -0
  106. package/dist/translations/pl.d.ts +8 -0
  107. package/dist/translations/pl.js +5 -0
  108. package/dist/translations/pl.umd.js +11 -0
  109. package/dist/translations/pt-br.d.ts +8 -0
  110. package/dist/translations/pt-br.js +5 -0
  111. package/dist/translations/pt-br.umd.js +11 -0
  112. package/dist/translations/pt.d.ts +8 -0
  113. package/dist/translations/pt.js +5 -0
  114. package/dist/translations/pt.umd.js +11 -0
  115. package/dist/translations/ro.d.ts +8 -0
  116. package/dist/translations/ro.js +5 -0
  117. package/dist/translations/ro.umd.js +11 -0
  118. package/dist/translations/ru.d.ts +8 -0
  119. package/dist/translations/ru.js +5 -0
  120. package/dist/translations/ru.umd.js +11 -0
  121. package/dist/translations/sk.d.ts +8 -0
  122. package/dist/translations/sk.js +5 -0
  123. package/dist/translations/sk.umd.js +11 -0
  124. package/dist/translations/sq.d.ts +8 -0
  125. package/dist/translations/sq.js +5 -0
  126. package/dist/translations/sq.umd.js +11 -0
  127. package/dist/translations/sr-latn.d.ts +8 -0
  128. package/dist/translations/sr-latn.js +5 -0
  129. package/dist/translations/sr-latn.umd.js +11 -0
  130. package/dist/translations/sr.d.ts +8 -0
  131. package/dist/translations/sr.js +5 -0
  132. package/dist/translations/sr.umd.js +11 -0
  133. package/dist/translations/sv.d.ts +8 -0
  134. package/dist/translations/sv.js +5 -0
  135. package/dist/translations/sv.umd.js +11 -0
  136. package/dist/translations/th.d.ts +8 -0
  137. package/dist/translations/th.js +5 -0
  138. package/dist/translations/th.umd.js +11 -0
  139. package/dist/translations/tk.d.ts +8 -0
  140. package/dist/translations/tk.js +5 -0
  141. package/dist/translations/tk.umd.js +11 -0
  142. package/dist/translations/tr.d.ts +8 -0
  143. package/dist/translations/tr.js +5 -0
  144. package/dist/translations/tr.umd.js +11 -0
  145. package/dist/translations/uk.d.ts +8 -0
  146. package/dist/translations/uk.js +5 -0
  147. package/dist/translations/uk.umd.js +11 -0
  148. package/dist/translations/ur.d.ts +8 -0
  149. package/dist/translations/ur.js +5 -0
  150. package/dist/translations/ur.umd.js +11 -0
  151. package/dist/translations/uz.d.ts +8 -0
  152. package/dist/translations/uz.js +5 -0
  153. package/dist/translations/uz.umd.js +11 -0
  154. package/dist/translations/vi.d.ts +8 -0
  155. package/dist/translations/vi.js +5 -0
  156. package/dist/translations/vi.umd.js +11 -0
  157. package/dist/translations/zh-cn.d.ts +8 -0
  158. package/dist/translations/zh-cn.js +5 -0
  159. package/dist/translations/zh-cn.umd.js +11 -0
  160. package/dist/translations/zh.d.ts +8 -0
  161. package/dist/translations/zh.js +5 -0
  162. package/dist/translations/zh.umd.js +11 -0
  163. package/dist/types/augmentation.d.ts +33 -0
  164. package/dist/types/index.d.ts +21 -0
  165. package/dist/types/restrictededitingconfig.d.ts +64 -0
  166. package/dist/types/restrictededitingexceptioncommand.d.ts +34 -0
  167. package/dist/types/restrictededitingmode/converters.d.ts +43 -0
  168. package/dist/types/restrictededitingmode/utils.d.ts +34 -0
  169. package/dist/types/restrictededitingmode.d.ts +33 -0
  170. package/dist/types/restrictededitingmodeediting.d.ts +87 -0
  171. package/dist/types/restrictededitingmodenavigationcommand.d.ts +46 -0
  172. package/dist/types/restrictededitingmodeui.d.ts +46 -0
  173. package/dist/types/standardeditingmode.d.ts +30 -0
  174. package/dist/types/standardeditingmodeediting.d.ts +29 -0
  175. package/dist/types/standardeditingmodeui.d.ts +31 -0
  176. package/package.json +3 -2
  177. package/src/restrictededitingmodeediting.js +51 -18
  178. package/src/restrictededitingmodeui.js +4 -1
package/dist/index.js ADDED
@@ -0,0 +1,977 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
+ import { Matcher } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
+ import { createDropdown, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ViewModel, ButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
+ import { Collection } from '@ckeditor/ckeditor5-utils/dist/index.js';
9
+
10
+ class RestrictedEditingModeNavigationCommand extends Command {
11
+ /**
12
+ * @inheritDoc
13
+ */ refresh() {
14
+ this.isEnabled = this._checkEnabled();
15
+ }
16
+ /**
17
+ * Executes the command.
18
+ *
19
+ * @fires execute
20
+ */ execute() {
21
+ const position = getNearestExceptionRange(this.editor.model, this._direction);
22
+ if (!position) {
23
+ return;
24
+ }
25
+ this.editor.model.change((writer)=>{
26
+ writer.setSelection(position);
27
+ });
28
+ }
29
+ /**
30
+ * Checks whether the command can be enabled in the current context.
31
+ *
32
+ * @returns Whether the command should be enabled.
33
+ */ _checkEnabled() {
34
+ return !!getNearestExceptionRange(this.editor.model, this._direction);
35
+ }
36
+ /**
37
+ * Creates an instance of the command.
38
+ *
39
+ * @param editor The editor instance.
40
+ * @param direction The direction that the command works.
41
+ */ constructor(editor, direction){
42
+ super(editor);
43
+ // It does not affect data so should be enabled in read-only mode and in restricted editing mode.
44
+ this.affectsData = false;
45
+ this._direction = direction;
46
+ }
47
+ }
48
+ /**
49
+ * Returns the range of the exception marker closest to the last position of the model selection.
50
+ */ function getNearestExceptionRange(model, direction) {
51
+ const selection = model.document.selection;
52
+ const selectionPosition = selection.getFirstPosition();
53
+ const markerRanges = [];
54
+ // Get all exception marker positions that start after/before the selection position.
55
+ for (const marker of model.markers.getMarkersGroup('restrictedEditingException')){
56
+ const markerRange = marker.getRange();
57
+ // Checking parent because there two positions <paragraph>foo^</paragraph><paragraph>^bar</paragraph>
58
+ // are touching but they will represent different markers.
59
+ const isMarkerRangeTouching = selectionPosition.isTouching(markerRange.start) && selectionPosition.hasSameParentAs(markerRange.start) || selectionPosition.isTouching(markerRange.end) && selectionPosition.hasSameParentAs(markerRange.end);
60
+ // <paragraph>foo <marker≥b[]ar</marker> baz</paragraph>
61
+ // <paragraph>foo <marker≥b[ar</marker> ba]z</paragraph>
62
+ // <paragraph>foo <marker≥bar</marker>[] baz</paragraph>
63
+ // <paragraph>foo []<marker≥bar</marker> baz</paragraph>
64
+ if (markerRange.containsPosition(selectionPosition) || isMarkerRangeTouching) {
65
+ continue;
66
+ }
67
+ if (direction === 'forward' && markerRange.start.isAfter(selectionPosition)) {
68
+ markerRanges.push(markerRange);
69
+ } else if (direction === 'backward' && markerRange.end.isBefore(selectionPosition)) {
70
+ markerRanges.push(markerRange);
71
+ }
72
+ }
73
+ if (!markerRanges.length) {
74
+ return;
75
+ }
76
+ // Get the marker closest to the selection position among many. To know that, we need to sort
77
+ // them first.
78
+ return markerRanges.sort((rangeA, rangeB)=>{
79
+ if (direction === 'forward') {
80
+ return rangeA.start.isAfter(rangeB.start) ? 1 : -1;
81
+ } else {
82
+ return rangeA.start.isBefore(rangeB.start) ? 1 : -1;
83
+ }
84
+ }).shift();
85
+ }
86
+
87
+ /**
88
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
89
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
90
+ */ /**
91
+ * @module restricted-editing/restrictededitingmode/utils
92
+ */ /**
93
+ * Returns a single "restricted-editing-exception" marker at a given position. Contrary to
94
+ * {@link module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition}, it returnd a marker also when the postion is
95
+ * equal to one of the marker's start or end positions.
96
+ */ function getMarkerAtPosition(editor, position) {
97
+ for (const marker of editor.model.markers){
98
+ const markerRange = marker.getRange();
99
+ if (isPositionInRangeBoundaries(markerRange, position)) {
100
+ if (marker.name.startsWith('restrictedEditingException:')) {
101
+ return marker;
102
+ }
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * Checks if the position is fully contained in the range. Positions equal to range start or end are considered "in".
108
+ */ function isPositionInRangeBoundaries(range, position) {
109
+ return range.containsPosition(position) || range.end.isEqual(position) || range.start.isEqual(position);
110
+ }
111
+ /**
112
+ * Checks if the selection is fully contained in the marker. Positions on marker boundaries are considered "in".
113
+ *
114
+ * ```xml
115
+ * <marker>[]foo</marker> -> true
116
+ * <marker>f[oo]</marker> -> true
117
+ * <marker>f[oo</marker> ba]r -> false
118
+ * <marker>foo</marker> []bar -> false
119
+ * ```
120
+ */ function isSelectionInMarker(selection, marker) {
121
+ if (!marker) {
122
+ return false;
123
+ }
124
+ const markerRange = marker.getRange();
125
+ if (selection.isCollapsed) {
126
+ return isPositionInRangeBoundaries(markerRange, selection.focus);
127
+ }
128
+ return markerRange.containsRange(selection.getFirstRange(), true);
129
+ }
130
+
131
+ const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
132
+ /**
133
+ * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
134
+ *
135
+ * The highlight is turned on by adding the `.restricted-editing-exception_selected` class to the
136
+ * exception in the view:
137
+ *
138
+ * * The class is removed before the conversion starts, as callbacks added with the `'highest'` priority
139
+ * to {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} events.
140
+ * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
141
+ *
142
+ * This way, adding and removing the highlight does not interfere with conversion.
143
+ */ function setupExceptionHighlighting(editor) {
144
+ const view = editor.editing.view;
145
+ const model = editor.model;
146
+ const highlightedMarkers = new Set();
147
+ // Adding the class.
148
+ view.document.registerPostFixer((writer)=>{
149
+ const modelSelection = model.document.selection;
150
+ const marker = getMarkerAtPosition(editor, modelSelection.anchor);
151
+ if (!marker) {
152
+ return false;
153
+ }
154
+ for (const viewElement of editor.editing.mapper.markerNameToElements(marker.name)){
155
+ writer.addClass(HIGHLIGHT_CLASS, viewElement);
156
+ highlightedMarkers.add(viewElement);
157
+ }
158
+ return false;
159
+ });
160
+ // Removing the class.
161
+ editor.conversion.for('editingDowncast').add((dispatcher)=>{
162
+ // Make sure the highlight is removed on every possible event, before conversion is started.
163
+ dispatcher.on('insert', removeHighlight, {
164
+ priority: 'highest'
165
+ });
166
+ dispatcher.on('remove', removeHighlight, {
167
+ priority: 'highest'
168
+ });
169
+ dispatcher.on('attribute', removeHighlight, {
170
+ priority: 'highest'
171
+ });
172
+ dispatcher.on('cleanSelection', removeHighlight);
173
+ function removeHighlight() {
174
+ view.change((writer)=>{
175
+ for (const item of highlightedMarkers.values()){
176
+ writer.removeClass(HIGHLIGHT_CLASS, item);
177
+ highlightedMarkers.delete(item);
178
+ }
179
+ });
180
+ }
181
+ });
182
+ }
183
+ /**
184
+ * A post-fixer that prevents removing a collapsed marker from the document.
185
+ */ function resurrectCollapsedMarkerPostFixer(editor) {
186
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
187
+ return (writer)=>{
188
+ let changeApplied = false;
189
+ for (const { name, data } of editor.model.document.differ.getChangedMarkers()){
190
+ if (name.startsWith('restrictedEditingException') && data.newRange && data.newRange.root.rootName == '$graveyard') {
191
+ writer.updateMarker(name, {
192
+ range: writer.createRange(writer.createPositionAt(data.oldRange.start))
193
+ });
194
+ changeApplied = true;
195
+ }
196
+ }
197
+ return changeApplied;
198
+ };
199
+ }
200
+ /**
201
+ * A post-fixer that extends a marker when the user types on its boundaries.
202
+ */ function extendMarkerOnTypingPostFixer(editor) {
203
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
204
+ return (writer)=>{
205
+ let changeApplied = false;
206
+ const schema = editor.model.schema;
207
+ for (const change of editor.model.document.differ.getChanges()){
208
+ if (change.type == 'insert' && schema.checkChild('$block', change.name)) {
209
+ changeApplied = _tryExtendMarkerStart(editor, change.position, change.length, writer) || changeApplied;
210
+ changeApplied = _tryExtendMarkedEnd(editor, change.position, change.length, writer) || changeApplied;
211
+ }
212
+ }
213
+ return changeApplied;
214
+ };
215
+ }
216
+ /**
217
+ * A view highlight-to-marker conversion helper.
218
+ *
219
+ * @param config Conversion configuration.
220
+ */ function upcastHighlightToMarker(config) {
221
+ return (dispatcher)=>dispatcher.on('element:span', (evt, data, conversionApi)=>{
222
+ const { writer } = conversionApi;
223
+ const matcher = new Matcher(config.view);
224
+ const matcherResult = matcher.match(data.viewItem);
225
+ // If there is no match, this callback should not do anything.
226
+ if (!matcherResult) {
227
+ return;
228
+ }
229
+ const match = matcherResult.match;
230
+ // Force consuming element's name (taken from upcast helpers elementToElement converter).
231
+ match.name = true;
232
+ const { modelRange: convertedChildrenRange } = conversionApi.convertChildren(data.viewItem, data.modelCursor);
233
+ conversionApi.consumable.consume(data.viewItem, match);
234
+ const markerName = config.model();
235
+ const fakeMarkerStart = writer.createElement('$marker', {
236
+ 'data-name': markerName
237
+ });
238
+ const fakeMarkerEnd = writer.createElement('$marker', {
239
+ 'data-name': markerName
240
+ });
241
+ // Insert in reverse order to use converter content positions directly (without recalculating).
242
+ writer.insert(fakeMarkerEnd, convertedChildrenRange.end);
243
+ writer.insert(fakeMarkerStart, convertedChildrenRange.start);
244
+ data.modelRange = writer.createRange(writer.createPositionBefore(fakeMarkerStart), writer.createPositionAfter(fakeMarkerEnd));
245
+ data.modelCursor = data.modelRange.end;
246
+ });
247
+ }
248
+ /**
249
+ * Extend marker if change detected on marker's start position.
250
+ */ function _tryExtendMarkerStart(editor, position, length, writer) {
251
+ const markerAtStart = getMarkerAtPosition(editor, position.getShiftedBy(length));
252
+ if (markerAtStart && markerAtStart.getStart().isEqual(position.getShiftedBy(length))) {
253
+ writer.updateMarker(markerAtStart, {
254
+ range: writer.createRange(markerAtStart.getStart().getShiftedBy(-length), markerAtStart.getEnd())
255
+ });
256
+ return true;
257
+ }
258
+ return false;
259
+ }
260
+ /**
261
+ * Extend marker if change detected on marker's end position.
262
+ */ function _tryExtendMarkedEnd(editor, position, length, writer) {
263
+ const markerAtEnd = getMarkerAtPosition(editor, position);
264
+ if (markerAtEnd && markerAtEnd.getEnd().isEqual(position)) {
265
+ writer.updateMarker(markerAtEnd, {
266
+ range: writer.createRange(markerAtEnd.getStart(), markerAtEnd.getEnd().getShiftedBy(length))
267
+ });
268
+ return true;
269
+ }
270
+ return false;
271
+ }
272
+
273
+ const COMMAND_FORCE_DISABLE_ID = 'RestrictedEditingMode';
274
+ class RestrictedEditingModeEditing extends Plugin {
275
+ /**
276
+ * @inheritDoc
277
+ */ static get pluginName() {
278
+ return 'RestrictedEditingModeEditing';
279
+ }
280
+ /**
281
+ * @inheritDoc
282
+ */ init() {
283
+ const editor = this.editor;
284
+ const editingView = editor.editing.view;
285
+ const allowedCommands = editor.config.get('restrictedEditing.allowedCommands');
286
+ allowedCommands.forEach((commandName)=>this._allowedInException.add(commandName));
287
+ this._setupConversion();
288
+ this._setupCommandsToggling();
289
+ this._setupRestrictions();
290
+ // Commands & keystrokes that allow navigation in the content.
291
+ editor.commands.add('goToPreviousRestrictedEditingException', new RestrictedEditingModeNavigationCommand(editor, 'backward'));
292
+ editor.commands.add('goToNextRestrictedEditingException', new RestrictedEditingModeNavigationCommand(editor, 'forward'));
293
+ this.listenTo(editingView.document, 'tab', (evt, data)=>{
294
+ const commandName = !data.shiftKey ? 'goToNextRestrictedEditingException' : 'goToPreviousRestrictedEditingException';
295
+ const command = editor.commands.get(commandName);
296
+ if (command.isEnabled) {
297
+ editor.execute(commandName);
298
+ // Stop the event in the DOM: no listener in the web page will be triggered by this event.
299
+ data.preventDefault();
300
+ data.stopPropagation();
301
+ }
302
+ // Stop the event bubbling in the editor: no more callbacks will be executed for this keystroke.
303
+ evt.stop();
304
+ }, {
305
+ context: '$capture'
306
+ });
307
+ editor.keystrokes.set('Ctrl+A', getSelectAllHandler(editor));
308
+ editingView.change((writer)=>{
309
+ for (const root of editingView.document.roots){
310
+ writer.addClass('ck-restricted-editing_mode_restricted', root);
311
+ }
312
+ });
313
+ }
314
+ /**
315
+ * Makes the given command always enabled in the restricted editing mode (regardless
316
+ * of selection location).
317
+ *
318
+ * To enable some commands in non-restricted areas of the content use
319
+ * {@link module:restricted-editing/restrictededitingconfig~RestrictedEditingConfig#allowedCommands} configuration option.
320
+ *
321
+ * @param commandName Name of the command to enable.
322
+ */ enableCommand(commandName) {
323
+ const command = this.editor.commands.get(commandName);
324
+ command.clearForceDisabled(COMMAND_FORCE_DISABLE_ID);
325
+ this._alwaysEnabled.add(commandName);
326
+ }
327
+ /**
328
+ * Sets up the restricted mode editing conversion:
329
+ *
330
+ * * ucpast & downcast converters,
331
+ * * marker highlighting in the edting area,
332
+ * * marker post-fixers.
333
+ */ _setupConversion() {
334
+ const editor = this.editor;
335
+ const model = editor.model;
336
+ const doc = model.document;
337
+ // The restricted editing does not attach additional data to the zones so there's no need for smarter markers managing.
338
+ // Also, the markers will only be created when loading the data.
339
+ let markerNumber = 0;
340
+ editor.conversion.for('upcast').add(upcastHighlightToMarker({
341
+ view: {
342
+ name: 'span',
343
+ classes: 'restricted-editing-exception'
344
+ },
345
+ model: ()=>{
346
+ markerNumber++; // Starting from restrictedEditingException:1 marker.
347
+ return `restrictedEditingException:${markerNumber}`;
348
+ }
349
+ }));
350
+ // Currently the marker helpers are tied to other use-cases and do not render a collapsed marker as highlight.
351
+ // Also, markerToHighlight can not convert marker on an inline object. It handles only text and widgets,
352
+ // but it is not a case in the data pipeline. That's why there are 3 downcast converters for them:
353
+ //
354
+ // 1. The custom inline item (text or inline object) converter (but not the selection).
355
+ editor.conversion.for('downcast').add((dispatcher)=>{
356
+ dispatcher.on('addMarker:restrictedEditingException', (evt, data, conversionApi)=>{
357
+ // Only convert per-item conversion.
358
+ if (!data.item) {
359
+ return;
360
+ }
361
+ // Do not convert the selection or non-inline items.
362
+ if (data.item.is('selection') || !conversionApi.schema.isInline(data.item)) {
363
+ return;
364
+ }
365
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
366
+ return;
367
+ }
368
+ const viewWriter = conversionApi.writer;
369
+ const viewElement = viewWriter.createAttributeElement('span', {
370
+ class: 'restricted-editing-exception'
371
+ }, {
372
+ id: data.markerName,
373
+ priority: -10
374
+ });
375
+ const viewRange = conversionApi.mapper.toViewRange(data.range);
376
+ const rangeAfterWrap = viewWriter.wrap(viewRange, viewElement);
377
+ for (const element of rangeAfterWrap.getItems()){
378
+ if (element.is('attributeElement') && element.isSimilar(viewElement)) {
379
+ conversionApi.mapper.bindElementToMarker(element, data.markerName);
380
+ break;
381
+ }
382
+ }
383
+ });
384
+ });
385
+ // 2. The marker-to-highlight converter for the document selection.
386
+ editor.conversion.for('downcast').markerToHighlight({
387
+ model: 'restrictedEditingException',
388
+ // Use callback to return new object every time new marker instance is created - otherwise it will be seen as the same marker.
389
+ view: ()=>{
390
+ return {
391
+ name: 'span',
392
+ classes: 'restricted-editing-exception',
393
+ priority: -10
394
+ };
395
+ }
396
+ });
397
+ // 3. And for collapsed marker we need to render it as an element.
398
+ // Additionally, the editing pipeline should always display a collapsed marker.
399
+ editor.conversion.for('editingDowncast').markerToElement({
400
+ model: 'restrictedEditingException',
401
+ view: (markerData, { writer })=>{
402
+ return writer.createUIElement('span', {
403
+ class: 'restricted-editing-exception restricted-editing-exception_collapsed'
404
+ });
405
+ }
406
+ });
407
+ editor.conversion.for('dataDowncast').markerToElement({
408
+ model: 'restrictedEditingException',
409
+ view: (markerData, { writer })=>{
410
+ return writer.createEmptyElement('span', {
411
+ class: 'restricted-editing-exception'
412
+ });
413
+ }
414
+ });
415
+ doc.registerPostFixer(extendMarkerOnTypingPostFixer(editor));
416
+ doc.registerPostFixer(resurrectCollapsedMarkerPostFixer(editor));
417
+ doc.registerPostFixer(ensureNewMarkerIsFlatPostFixer(editor));
418
+ setupExceptionHighlighting(editor);
419
+ }
420
+ /**
421
+ * Setups additional editing restrictions beyond command toggling:
422
+ *
423
+ * * delete content range trimming
424
+ * * disabling input command outside exception marker
425
+ * * restricting clipboard holder to text only
426
+ * * restricting text attributes in content
427
+ */ _setupRestrictions() {
428
+ const editor = this.editor;
429
+ const model = editor.model;
430
+ const selection = model.document.selection;
431
+ const viewDoc = editor.editing.view.document;
432
+ const clipboard = editor.plugins.get('ClipboardPipeline');
433
+ this.listenTo(model, 'deleteContent', restrictDeleteContent(editor), {
434
+ priority: 'high'
435
+ });
436
+ const insertTextCommand = editor.commands.get('insertText');
437
+ // The restricted editing might be configured without insert text support - ie allow only bolding or removing text.
438
+ // This check is bit synthetic since only tests are used this way.
439
+ if (insertTextCommand) {
440
+ this.listenTo(insertTextCommand, 'execute', disallowInputExecForWrongRange(editor), {
441
+ priority: 'high'
442
+ });
443
+ }
444
+ // Block clipboard outside exception marker on paste and drop.
445
+ this.listenTo(clipboard, 'contentInsertion', (evt)=>{
446
+ if (!isRangeInsideSingleMarker(editor, selection.getFirstRange())) {
447
+ evt.stop();
448
+ }
449
+ });
450
+ // Block clipboard outside exception marker on cut.
451
+ this.listenTo(viewDoc, 'clipboardOutput', (evt, data)=>{
452
+ if (data.method == 'cut' && !isRangeInsideSingleMarker(editor, selection.getFirstRange())) {
453
+ evt.stop();
454
+ }
455
+ }, {
456
+ priority: 'high'
457
+ });
458
+ const allowedAttributes = editor.config.get('restrictedEditing.allowedAttributes');
459
+ model.schema.addAttributeCheck(onlyAllowAttributesFromList(allowedAttributes));
460
+ model.schema.addChildCheck(allowTextOnlyInClipboardHolder());
461
+ }
462
+ /**
463
+ * Sets up the command toggling which enables or disables commands based on the user selection.
464
+ */ _setupCommandsToggling() {
465
+ const editor = this.editor;
466
+ const model = editor.model;
467
+ const doc = model.document;
468
+ this._disableCommands();
469
+ this.listenTo(doc.selection, 'change', this._checkCommands.bind(this));
470
+ this.listenTo(doc, 'change:data', this._checkCommands.bind(this));
471
+ }
472
+ /**
473
+ * Checks if commands should be enabled or disabled based on the current selection.
474
+ */ _checkCommands() {
475
+ const editor = this.editor;
476
+ const selection = editor.model.document.selection;
477
+ if (selection.rangeCount > 1) {
478
+ this._disableCommands();
479
+ return;
480
+ }
481
+ const marker = getMarkerAtPosition(editor, selection.focus);
482
+ this._disableCommands();
483
+ if (isSelectionInMarker(selection, marker)) {
484
+ this._enableCommands(marker);
485
+ }
486
+ }
487
+ /**
488
+ * Enables commands in non-restricted regions.
489
+ */ _enableCommands(marker) {
490
+ const editor = this.editor;
491
+ for (const [commandName, command] of editor.commands){
492
+ if (!command.affectsData || this._alwaysEnabled.has(commandName)) {
493
+ continue;
494
+ }
495
+ // Enable ony those commands that are allowed in the exception marker.
496
+ if (!this._allowedInException.has(commandName)) {
497
+ continue;
498
+ }
499
+ // Do not enable 'delete' and 'deleteForward' commands on the exception marker boundaries.
500
+ if (isDeleteCommandOnMarkerBoundaries(commandName, editor.model.document.selection, marker.getRange())) {
501
+ continue;
502
+ }
503
+ command.clearForceDisabled(COMMAND_FORCE_DISABLE_ID);
504
+ }
505
+ }
506
+ /**
507
+ * Disables commands outside non-restricted regions.
508
+ */ _disableCommands() {
509
+ const editor = this.editor;
510
+ for (const [commandName, command] of editor.commands){
511
+ if (!command.affectsData || this._alwaysEnabled.has(commandName)) {
512
+ continue;
513
+ }
514
+ command.forceDisabled(COMMAND_FORCE_DISABLE_ID);
515
+ }
516
+ }
517
+ /**
518
+ * @inheritDoc
519
+ */ constructor(editor){
520
+ super(editor);
521
+ editor.config.define('restrictedEditing', {
522
+ allowedCommands: [
523
+ 'bold',
524
+ 'italic',
525
+ 'link',
526
+ 'unlink'
527
+ ],
528
+ allowedAttributes: [
529
+ 'bold',
530
+ 'italic',
531
+ 'linkHref'
532
+ ]
533
+ });
534
+ this._alwaysEnabled = new Set([
535
+ 'undo',
536
+ 'redo'
537
+ ]);
538
+ this._allowedInException = new Set([
539
+ 'input',
540
+ 'insertText',
541
+ 'delete',
542
+ 'deleteForward'
543
+ ]);
544
+ }
545
+ }
546
+ /**
547
+ * Helper for handling Ctrl+A keydown behaviour.
548
+ */ function getSelectAllHandler(editor) {
549
+ return (_, cancel)=>{
550
+ const model = editor.model;
551
+ const selection = editor.model.document.selection;
552
+ const marker = getMarkerAtPosition(editor, selection.focus);
553
+ if (!marker) {
554
+ return;
555
+ }
556
+ // If selection range is inside a restricted editing exception, select text only within the exception.
557
+ //
558
+ // Note: Second Ctrl+A press is also blocked and it won't select the entire text in the editor.
559
+ const selectionRange = selection.getFirstRange();
560
+ const markerRange = marker.getRange();
561
+ if (markerRange.containsRange(selectionRange, true) || selection.isCollapsed) {
562
+ cancel();
563
+ model.change((writer)=>{
564
+ writer.setSelection(marker.getRange());
565
+ });
566
+ }
567
+ };
568
+ }
569
+ /**
570
+ * Additional rule for enabling "delete" and "deleteForward" commands if selection is on range boundaries:
571
+ *
572
+ * Does not allow to enable command when selection focus is:
573
+ * - is on marker start - "delete" - to prevent removing content before marker
574
+ * - is on marker end - "deleteForward" - to prevent removing content after marker
575
+ */ function isDeleteCommandOnMarkerBoundaries(commandName, selection, markerRange) {
576
+ if (commandName == 'delete' && markerRange.start.isEqual(selection.focus)) {
577
+ return true;
578
+ }
579
+ // Only for collapsed selection - non-collapsed selection that extends over a marker is handled elsewhere.
580
+ if (commandName == 'deleteForward' && selection.isCollapsed && markerRange.end.isEqual(selection.focus)) {
581
+ return true;
582
+ }
583
+ return false;
584
+ }
585
+ /**
586
+ * Ensures that model.deleteContent() does not delete outside exception markers ranges.
587
+ *
588
+ * The enforced restrictions are:
589
+ * - only execute deleteContent() inside exception markers
590
+ * - restrict passed selection to exception marker
591
+ */ function restrictDeleteContent(editor) {
592
+ return (evt, args)=>{
593
+ const [selection] = args;
594
+ const marker = getMarkerAtPosition(editor, selection.focus) || getMarkerAtPosition(editor, selection.anchor);
595
+ // Stop method execution if marker was not found at selection focus.
596
+ if (!marker) {
597
+ evt.stop();
598
+ return;
599
+ }
600
+ // Collapsed selection inside exception marker does not require fixing.
601
+ if (selection.isCollapsed) {
602
+ return;
603
+ }
604
+ // Shrink the selection to the range inside exception marker.
605
+ const allowedToDelete = marker.getRange().getIntersection(selection.getFirstRange());
606
+ // Some features uses selection passed to model.deleteContent() to set the selection afterwards. For this we need to properly modify
607
+ // either the document selection using change block...
608
+ if (selection.is('documentSelection')) {
609
+ editor.model.change((writer)=>{
610
+ writer.setSelection(allowedToDelete);
611
+ });
612
+ } else {
613
+ selection.setTo(allowedToDelete);
614
+ }
615
+ };
616
+ }
617
+ /**
618
+ * Ensures that input command is executed with a range that is inside exception marker.
619
+ *
620
+ * This restriction is due to fact that using native spell check changes text outside exception marker.
621
+ */ function disallowInputExecForWrongRange(editor) {
622
+ return (evt, args)=>{
623
+ const [options] = args;
624
+ const { range } = options;
625
+ // Only check "input" command executed with a range value.
626
+ // Selection might be set in exception marker but passed range might point elsewhere.
627
+ if (!range) {
628
+ return;
629
+ }
630
+ if (!isRangeInsideSingleMarker(editor, range)) {
631
+ evt.stop();
632
+ }
633
+ };
634
+ }
635
+ function isRangeInsideSingleMarker(editor, range) {
636
+ const markerAtStart = getMarkerAtPosition(editor, range.start);
637
+ const markerAtEnd = getMarkerAtPosition(editor, range.end);
638
+ return markerAtStart && markerAtEnd && markerAtEnd === markerAtStart;
639
+ }
640
+ /**
641
+ * Checks if new marker range is flat. Non-flat ranges might appear during upcast conversion in nested structures, ie tables.
642
+ *
643
+ * Note: This marker fixer only consider case which is possible to create using StandardEditing mode plugin.
644
+ * Markers created by developer in the data might break in many other ways.
645
+ *
646
+ * See #6003.
647
+ */ function ensureNewMarkerIsFlatPostFixer(editor) {
648
+ return (writer)=>{
649
+ let changeApplied = false;
650
+ const changedMarkers = editor.model.document.differ.getChangedMarkers();
651
+ for (const { data, name } of changedMarkers){
652
+ if (!name.startsWith('restrictedEditingException')) {
653
+ continue;
654
+ }
655
+ const newRange = data.newRange;
656
+ if (!data.oldRange && !newRange.isFlat) {
657
+ const start = newRange.start;
658
+ const end = newRange.end;
659
+ const startIsHigherInTree = start.path.length > end.path.length;
660
+ const fixedStart = startIsHigherInTree ? newRange.start : writer.createPositionAt(end.parent, 0);
661
+ const fixedEnd = startIsHigherInTree ? writer.createPositionAt(start.parent, 'end') : newRange.end;
662
+ writer.updateMarker(name, {
663
+ range: writer.createRange(fixedStart, fixedEnd)
664
+ });
665
+ changeApplied = true;
666
+ }
667
+ }
668
+ return changeApplied;
669
+ };
670
+ }
671
+ function onlyAllowAttributesFromList(allowedAttributes) {
672
+ return (context, attributeName)=>{
673
+ if (context.startsWith('$clipboardHolder')) {
674
+ return allowedAttributes.includes(attributeName);
675
+ }
676
+ };
677
+ }
678
+ function allowTextOnlyInClipboardHolder() {
679
+ return (context, childDefinition)=>{
680
+ if (context.startsWith('$clipboardHolder')) {
681
+ return childDefinition.name === '$text';
682
+ }
683
+ };
684
+ }
685
+
686
+ var lockIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M15.5 6.5a3.5 3.5 0 0 1 3.495 3.308L19 10v2a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1v-2l.005-.192A3.5 3.5 0 0 1 15.5 6.5zm0 7.5a.5.5 0 0 0-.492.41L15 14.5v2a.5.5 0 0 0 .992.09L16 16.5v-2a.5.5 0 0 0-.5-.5zm0-6a2 2 0 0 0-2 2v2h4v-2a2 2 0 0 0-2-2zm-9.25 8a.75.75 0 1 1 0 1.5H.75a.75.75 0 1 1 0-1.5h5.5zm0-5a.75.75 0 1 1 0 1.5H.75a.75.75 0 1 1 0-1.5h5.5zm3-5a.75.75 0 0 1 0 1.5H.75a.75.75 0 0 1 0-1.5h8.5zm6-5a.75.75 0 1 1 0 1.5H.75a.75.75 0 0 1 0-1.5h14.5z\"/></svg>";
687
+
688
+ class RestrictedEditingModeUI extends Plugin {
689
+ /**
690
+ * @inheritDoc
691
+ */ static get pluginName() {
692
+ return 'RestrictedEditingModeUI';
693
+ }
694
+ /**
695
+ * @inheritDoc
696
+ */ init() {
697
+ const editor = this.editor;
698
+ const t = editor.t;
699
+ editor.ui.componentFactory.add('restrictedEditing', (locale)=>{
700
+ const dropdownView = createDropdown(locale);
701
+ const listItems = new Collection();
702
+ this._getButtonDefinitions().forEach(({ commandName, label, keystroke })=>{
703
+ listItems.add(this._getButtonDefinition(commandName, label, keystroke));
704
+ });
705
+ addListToDropdown(dropdownView, listItems, {
706
+ role: 'menu'
707
+ });
708
+ dropdownView.buttonView.set({
709
+ label: t('Navigate editable regions'),
710
+ icon: lockIcon,
711
+ tooltip: true,
712
+ isEnabled: true,
713
+ isOn: false
714
+ });
715
+ this.listenTo(dropdownView, 'execute', (evt)=>{
716
+ const { _commandName } = evt.source;
717
+ editor.execute(_commandName);
718
+ editor.editing.view.focus();
719
+ });
720
+ return dropdownView;
721
+ });
722
+ editor.ui.componentFactory.add('menuBar:restrictedEditing', (locale)=>{
723
+ const menuView = new MenuBarMenuView(locale);
724
+ const listView = new MenuBarMenuListView(locale);
725
+ listView.set({
726
+ ariaLabel: t('Navigate editable regions'),
727
+ role: 'menu'
728
+ });
729
+ menuView.buttonView.set({
730
+ label: t('Navigate editable regions'),
731
+ icon: lockIcon
732
+ });
733
+ menuView.panelView.children.add(listView);
734
+ this._getButtonDefinitions().forEach(({ commandName, label, keystroke })=>{
735
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
736
+ const buttonView = this._createMenuBarButton(label, commandName, keystroke);
737
+ buttonView.delegate('execute').to(menuView);
738
+ listItemView.children.add(buttonView);
739
+ listView.items.add(listItemView);
740
+ });
741
+ return menuView;
742
+ });
743
+ }
744
+ /**
745
+ * Creates a button for restricted editing command to use in menu bar.
746
+ */ _createMenuBarButton(label, commandName, keystroke) {
747
+ const editor = this.editor;
748
+ const command = editor.commands.get(commandName);
749
+ const view = new MenuBarMenuListItemButtonView(editor.locale);
750
+ view.set({
751
+ label,
752
+ keystroke,
753
+ isEnabled: true,
754
+ isOn: false
755
+ });
756
+ view.bind('isEnabled').to(command);
757
+ // Execute the command.
758
+ this.listenTo(view, 'execute', ()=>{
759
+ editor.execute(commandName);
760
+ editor.editing.view.focus();
761
+ });
762
+ return view;
763
+ }
764
+ /**
765
+ * Returns a definition of the navigation button to be used in the dropdown.
766
+ *
767
+ * @param commandName The name of the command that the button represents.
768
+ * @param label The translated label of the button.
769
+ * @param keystroke The button keystroke.
770
+ */ _getButtonDefinition(commandName, label, keystroke) {
771
+ const editor = this.editor;
772
+ const command = editor.commands.get(commandName);
773
+ const definition = {
774
+ type: 'button',
775
+ model: new ViewModel({
776
+ label,
777
+ withText: true,
778
+ keystroke,
779
+ withKeystroke: true,
780
+ role: 'menuitem',
781
+ _commandName: commandName
782
+ })
783
+ };
784
+ definition.model.bind('isEnabled').to(command, 'isEnabled');
785
+ return definition;
786
+ }
787
+ /**
788
+ * Returns definitions for UI buttons.
789
+ *
790
+ * @internal
791
+ */ _getButtonDefinitions() {
792
+ const t = this.editor.locale.t;
793
+ return [
794
+ {
795
+ commandName: 'goToPreviousRestrictedEditingException',
796
+ label: t('Previous editable region'),
797
+ keystroke: 'Shift+Tab'
798
+ },
799
+ {
800
+ commandName: 'goToNextRestrictedEditingException',
801
+ label: t('Next editable region'),
802
+ keystroke: 'Tab'
803
+ }
804
+ ];
805
+ }
806
+ }
807
+
808
+ class RestrictedEditingMode extends Plugin {
809
+ /**
810
+ * @inheritDoc
811
+ */ static get pluginName() {
812
+ return 'RestrictedEditingMode';
813
+ }
814
+ /**
815
+ * @inheritDoc
816
+ */ static get requires() {
817
+ return [
818
+ RestrictedEditingModeEditing,
819
+ RestrictedEditingModeUI
820
+ ];
821
+ }
822
+ }
823
+
824
+ class RestrictedEditingExceptionCommand extends Command {
825
+ /**
826
+ * @inheritDoc
827
+ */ refresh() {
828
+ const model = this.editor.model;
829
+ const doc = model.document;
830
+ this.value = !!doc.selection.getAttribute('restrictedEditingException');
831
+ this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'restrictedEditingException');
832
+ }
833
+ /**
834
+ * @inheritDoc
835
+ */ execute(options = {}) {
836
+ const model = this.editor.model;
837
+ const document = model.document;
838
+ const selection = document.selection;
839
+ const valueToSet = options.forceValue === undefined ? !this.value : options.forceValue;
840
+ model.change((writer)=>{
841
+ const ranges = model.schema.getValidRanges(selection.getRanges(), 'restrictedEditingException');
842
+ if (selection.isCollapsed) {
843
+ if (valueToSet) {
844
+ writer.setSelectionAttribute('restrictedEditingException', valueToSet);
845
+ } else {
846
+ const isSameException = (value)=>{
847
+ return value.item.getAttribute('restrictedEditingException') === this.value;
848
+ };
849
+ const focus = selection.focus;
850
+ const exceptionStart = focus.getLastMatchingPosition(isSameException, {
851
+ direction: 'backward'
852
+ });
853
+ const exceptionEnd = focus.getLastMatchingPosition(isSameException);
854
+ writer.removeSelectionAttribute('restrictedEditingException');
855
+ if (!(focus.isEqual(exceptionStart) || focus.isEqual(exceptionEnd))) {
856
+ writer.removeAttribute('restrictedEditingException', writer.createRange(exceptionStart, exceptionEnd));
857
+ }
858
+ }
859
+ } else {
860
+ for (const range of ranges){
861
+ if (valueToSet) {
862
+ writer.setAttribute('restrictedEditingException', valueToSet, range);
863
+ } else {
864
+ writer.removeAttribute('restrictedEditingException', range);
865
+ }
866
+ }
867
+ }
868
+ });
869
+ }
870
+ }
871
+
872
+ class StandardEditingModeEditing extends Plugin {
873
+ /**
874
+ * @inheritDoc
875
+ */ static get pluginName() {
876
+ return 'StandardEditingModeEditing';
877
+ }
878
+ /**
879
+ * @inheritDoc
880
+ */ init() {
881
+ const editor = this.editor;
882
+ editor.model.schema.extend('$text', {
883
+ allowAttributes: [
884
+ 'restrictedEditingException'
885
+ ]
886
+ });
887
+ editor.conversion.for('upcast').elementToAttribute({
888
+ model: 'restrictedEditingException',
889
+ view: {
890
+ name: 'span',
891
+ classes: 'restricted-editing-exception'
892
+ }
893
+ });
894
+ editor.conversion.for('downcast').attributeToElement({
895
+ model: 'restrictedEditingException',
896
+ view: (modelAttributeValue, { writer })=>{
897
+ if (modelAttributeValue) {
898
+ // Make the restricted editing <span> outer-most in the view.
899
+ return writer.createAttributeElement('span', {
900
+ class: 'restricted-editing-exception'
901
+ }, {
902
+ priority: -10
903
+ });
904
+ }
905
+ }
906
+ });
907
+ editor.commands.add('restrictedEditingException', new RestrictedEditingExceptionCommand(editor));
908
+ editor.editing.view.change((writer)=>{
909
+ for (const root of editor.editing.view.document.roots){
910
+ writer.addClass('ck-restricted-editing_mode_standard', root);
911
+ }
912
+ });
913
+ }
914
+ }
915
+
916
+ var unlockIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6.25 16a.75.75 0 1 1 0 1.5H.75a.75.75 0 1 1 0-1.5h5.5zm0-5a.75.75 0 1 1 0 1.5H.75a.75.75 0 1 1 0-1.5h5.5zm3-5a.75.75 0 0 1 0 1.5H.75a.75.75 0 0 1 0-1.5h8.5zm6-5a.75.75 0 1 1 0 1.5H.75a.75.75 0 0 1 0-1.5h14.5zm.25 5.5a3.5 3.5 0 0 1 3.143 1.959.75.75 0 0 1-1.36.636A2 2 0 0 0 13.5 10v2H19a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1v-2l.005-.192A3.5 3.5 0 0 1 15.5 6.5zm0 7.5a.5.5 0 0 0-.492.41L15 14.5v2a.5.5 0 0 0 .992.09L16 16.5v-2a.5.5 0 0 0-.5-.5z\"/></svg>";
917
+
918
+ class StandardEditingModeUI extends Plugin {
919
+ /**
920
+ * @inheritDoc
921
+ */ static get pluginName() {
922
+ return 'StandardEditingModeUI';
923
+ }
924
+ /**
925
+ * @inheritDoc
926
+ */ init() {
927
+ const editor = this.editor;
928
+ editor.ui.componentFactory.add('restrictedEditingException', ()=>{
929
+ const button = this._createButton(ButtonView);
930
+ button.set({
931
+ tooltip: true,
932
+ isToggleable: true
933
+ });
934
+ return button;
935
+ });
936
+ editor.ui.componentFactory.add('menuBar:restrictedEditingException', ()=>{
937
+ return this._createButton(MenuBarMenuListItemButtonView);
938
+ });
939
+ }
940
+ /**
941
+ * Creates a button for restricted editing exception command to use either in toolbar or in menu bar.
942
+ */ _createButton(ButtonClass) {
943
+ const editor = this.editor;
944
+ const locale = editor.locale;
945
+ const command = this.editor.commands.get('restrictedEditingException');
946
+ const view = new ButtonClass(locale);
947
+ const t = locale.t;
948
+ view.icon = unlockIcon;
949
+ view.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
950
+ view.bind('label').to(command, 'value', (value)=>{
951
+ return value ? t('Disable editing') : t('Enable editing');
952
+ });
953
+ // Execute the command.
954
+ this.listenTo(view, 'execute', ()=>{
955
+ editor.execute('restrictedEditingException');
956
+ editor.editing.view.focus();
957
+ });
958
+ return view;
959
+ }
960
+ }
961
+
962
+ class StandardEditingMode extends Plugin {
963
+ /**
964
+ * @inheritDoc
965
+ */ static get pluginName() {
966
+ return 'StandardEditingMode';
967
+ }
968
+ static get requires() {
969
+ return [
970
+ StandardEditingModeEditing,
971
+ StandardEditingModeUI
972
+ ];
973
+ }
974
+ }
975
+
976
+ export { RestrictedEditingMode, RestrictedEditingModeEditing, RestrictedEditingModeUI, StandardEditingMode, StandardEditingModeEditing, StandardEditingModeUI };
977
+ //# sourceMappingURL=index.js.map