@ckeditor/ckeditor5-restricted-editing 41.4.2 → 42.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/README.md CHANGED
@@ -15,6 +15,12 @@ Check out the demo in the [restricted editing feature guide](https://ckeditor.co
15
15
 
16
16
  See the [`@ckeditor/ckeditor5-restricted-editing` package](https://ckeditor.com/docs/ckeditor5/latest/api/restricted-editing.html) page as well as the [restricted editing feature](https://ckeditor.com/docs/ckeditor5/latest/features/restricted-editing.html) guide in the [CKEditor 5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
17
17
 
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install ckeditor5
22
+ ```
23
+
18
24
  ## License
19
25
 
20
26
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html). For full details about the license, please check the `LICENSE.md` file or [https://ckeditor.com/legal/ckeditor-oss-license](https://ckeditor.com/legal/ckeditor-oss-license).
package/dist/index.js CHANGED
@@ -7,17 +7,33 @@ import { Matcher } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
7
  import { createDropdown, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ViewModel, ButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
8
  import { Collection } from '@ckeditor/ckeditor5-utils/dist/index.js';
9
9
 
10
- class RestrictedEditingModeNavigationCommand extends Command {
10
+ /**
11
+ * The command that allows navigation across the exceptions in the edited document.
12
+ */ class RestrictedEditingModeNavigationCommand extends Command {
13
+ /**
14
+ * The direction of the command.
15
+ */ _direction;
11
16
  /**
12
- * @inheritDoc
13
- */ refresh() {
17
+ * Creates an instance of the command.
18
+ *
19
+ * @param editor The editor instance.
20
+ * @param direction The direction that the command works.
21
+ */ constructor(editor, direction){
22
+ super(editor);
23
+ // It does not affect data so should be enabled in read-only mode and in restricted editing mode.
24
+ this.affectsData = false;
25
+ this._direction = direction;
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */ refresh() {
14
30
  this.isEnabled = this._checkEnabled();
15
31
  }
16
32
  /**
17
- * Executes the command.
18
- *
19
- * @fires execute
20
- */ execute() {
33
+ * Executes the command.
34
+ *
35
+ * @fires execute
36
+ */ execute() {
21
37
  const position = getNearestExceptionRange(this.editor.model, this._direction);
22
38
  if (!position) {
23
39
  return;
@@ -27,23 +43,12 @@ class RestrictedEditingModeNavigationCommand extends Command {
27
43
  });
28
44
  }
29
45
  /**
30
- * Checks whether the command can be enabled in the current context.
31
- *
32
- * @returns Whether the command should be enabled.
33
- */ _checkEnabled() {
46
+ * Checks whether the command can be enabled in the current context.
47
+ *
48
+ * @returns Whether the command should be enabled.
49
+ */ _checkEnabled() {
34
50
  return !!getNearestExceptionRange(this.editor.model, this._direction);
35
51
  }
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
52
  }
48
53
  /**
49
54
  * Returns the range of the exception marker closest to the last position of the model selection.
@@ -271,15 +276,58 @@ const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
271
276
  }
272
277
 
273
278
  const COMMAND_FORCE_DISABLE_ID = 'RestrictedEditingMode';
274
- class RestrictedEditingModeEditing extends Plugin {
279
+ /**
280
+ * The restricted editing mode editing feature.
281
+ *
282
+ * * It introduces the exception marker group that renders to `<span>` elements with the `restricted-editing-exception` CSS class.
283
+ * * It registers the `'goToPreviousRestrictedEditingException'` and `'goToNextRestrictedEditingException'` commands.
284
+ * * It also enables highlighting exception markers that are selected.
285
+ */ class RestrictedEditingModeEditing extends Plugin {
275
286
  /**
276
- * @inheritDoc
277
- */ static get pluginName() {
287
+ * Command names that are enabled outside the non-restricted regions.
288
+ */ _alwaysEnabled;
289
+ /**
290
+ * Commands allowed in non-restricted areas.
291
+ *
292
+ * Commands always enabled combine typing feature commands: `'input'`, `'insertText'`, `'delete'`, and `'deleteForward'` with
293
+ * commands defined in the feature configuration.
294
+ */ _allowedInException;
295
+ /**
296
+ * @inheritDoc
297
+ */ static get pluginName() {
278
298
  return 'RestrictedEditingModeEditing';
279
299
  }
280
300
  /**
281
- * @inheritDoc
282
- */ init() {
301
+ * @inheritDoc
302
+ */ constructor(editor){
303
+ super(editor);
304
+ editor.config.define('restrictedEditing', {
305
+ allowedCommands: [
306
+ 'bold',
307
+ 'italic',
308
+ 'link',
309
+ 'unlink'
310
+ ],
311
+ allowedAttributes: [
312
+ 'bold',
313
+ 'italic',
314
+ 'linkHref'
315
+ ]
316
+ });
317
+ this._alwaysEnabled = new Set([
318
+ 'undo',
319
+ 'redo'
320
+ ]);
321
+ this._allowedInException = new Set([
322
+ 'input',
323
+ 'insertText',
324
+ 'delete',
325
+ 'deleteForward'
326
+ ]);
327
+ }
328
+ /**
329
+ * @inheritDoc
330
+ */ init() {
283
331
  const editor = this.editor;
284
332
  const editingView = editor.editing.view;
285
333
  const allowedCommands = editor.config.get('restrictedEditing.allowedCommands');
@@ -312,25 +360,25 @@ class RestrictedEditingModeEditing extends Plugin {
312
360
  });
313
361
  }
314
362
  /**
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) {
363
+ * Makes the given command always enabled in the restricted editing mode (regardless
364
+ * of selection location).
365
+ *
366
+ * To enable some commands in non-restricted areas of the content use
367
+ * {@link module:restricted-editing/restrictededitingconfig~RestrictedEditingConfig#allowedCommands} configuration option.
368
+ *
369
+ * @param commandName Name of the command to enable.
370
+ */ enableCommand(commandName) {
323
371
  const command = this.editor.commands.get(commandName);
324
372
  command.clearForceDisabled(COMMAND_FORCE_DISABLE_ID);
325
373
  this._alwaysEnabled.add(commandName);
326
374
  }
327
375
  /**
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() {
376
+ * Sets up the restricted mode editing conversion:
377
+ *
378
+ * * ucpast & downcast converters,
379
+ * * marker highlighting in the edting area,
380
+ * * marker post-fixers.
381
+ */ _setupConversion() {
334
382
  const editor = this.editor;
335
383
  const model = editor.model;
336
384
  const doc = model.document;
@@ -418,13 +466,13 @@ class RestrictedEditingModeEditing extends Plugin {
418
466
  setupExceptionHighlighting(editor);
419
467
  }
420
468
  /**
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() {
469
+ * Setups additional editing restrictions beyond command toggling:
470
+ *
471
+ * * delete content range trimming
472
+ * * disabling input command outside exception marker
473
+ * * restricting clipboard holder to text only
474
+ * * restricting text attributes in content
475
+ */ _setupRestrictions() {
428
476
  const editor = this.editor;
429
477
  const model = editor.model;
430
478
  const selection = model.document.selection;
@@ -460,8 +508,8 @@ class RestrictedEditingModeEditing extends Plugin {
460
508
  model.schema.addChildCheck(allowTextOnlyInClipboardHolder());
461
509
  }
462
510
  /**
463
- * Sets up the command toggling which enables or disables commands based on the user selection.
464
- */ _setupCommandsToggling() {
511
+ * Sets up the command toggling which enables or disables commands based on the user selection.
512
+ */ _setupCommandsToggling() {
465
513
  const editor = this.editor;
466
514
  const model = editor.model;
467
515
  const doc = model.document;
@@ -470,8 +518,8 @@ class RestrictedEditingModeEditing extends Plugin {
470
518
  this.listenTo(doc, 'change:data', this._checkCommands.bind(this));
471
519
  }
472
520
  /**
473
- * Checks if commands should be enabled or disabled based on the current selection.
474
- */ _checkCommands() {
521
+ * Checks if commands should be enabled or disabled based on the current selection.
522
+ */ _checkCommands() {
475
523
  const editor = this.editor;
476
524
  const selection = editor.model.document.selection;
477
525
  if (selection.rangeCount > 1) {
@@ -485,8 +533,8 @@ class RestrictedEditingModeEditing extends Plugin {
485
533
  }
486
534
  }
487
535
  /**
488
- * Enables commands in non-restricted regions.
489
- */ _enableCommands(marker) {
536
+ * Enables commands in non-restricted regions.
537
+ */ _enableCommands(marker) {
490
538
  const editor = this.editor;
491
539
  for (const [commandName, command] of editor.commands){
492
540
  if (!command.affectsData || this._alwaysEnabled.has(commandName)) {
@@ -504,8 +552,8 @@ class RestrictedEditingModeEditing extends Plugin {
504
552
  }
505
553
  }
506
554
  /**
507
- * Disables commands outside non-restricted regions.
508
- */ _disableCommands() {
555
+ * Disables commands outside non-restricted regions.
556
+ */ _disableCommands() {
509
557
  const editor = this.editor;
510
558
  for (const [commandName, command] of editor.commands){
511
559
  if (!command.affectsData || this._alwaysEnabled.has(commandName)) {
@@ -514,34 +562,6 @@ class RestrictedEditingModeEditing extends Plugin {
514
562
  command.forceDisabled(COMMAND_FORCE_DISABLE_ID);
515
563
  }
516
564
  }
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
565
  }
546
566
  /**
547
567
  * Helper for handling Ctrl+A keydown behaviour.
@@ -685,15 +705,20 @@ function allowTextOnlyInClipboardHolder() {
685
705
 
686
706
  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
707
 
688
- class RestrictedEditingModeUI extends Plugin {
708
+ /**
709
+ * The restricted editing mode UI feature.
710
+ *
711
+ * It introduces the `'restrictedEditing'` dropdown that offers tools to navigate between exceptions across
712
+ * the document.
713
+ */ class RestrictedEditingModeUI extends Plugin {
689
714
  /**
690
- * @inheritDoc
691
- */ static get pluginName() {
715
+ * @inheritDoc
716
+ */ static get pluginName() {
692
717
  return 'RestrictedEditingModeUI';
693
718
  }
694
719
  /**
695
- * @inheritDoc
696
- */ init() {
720
+ * @inheritDoc
721
+ */ init() {
697
722
  const editor = this.editor;
698
723
  const t = editor.t;
699
724
  editor.ui.componentFactory.add('restrictedEditing', (locale)=>{
@@ -742,8 +767,8 @@ class RestrictedEditingModeUI extends Plugin {
742
767
  });
743
768
  }
744
769
  /**
745
- * Creates a button for restricted editing command to use in menu bar.
746
- */ _createMenuBarButton(label, commandName, keystroke) {
770
+ * Creates a button for restricted editing command to use in menu bar.
771
+ */ _createMenuBarButton(label, commandName, keystroke) {
747
772
  const editor = this.editor;
748
773
  const command = editor.commands.get(commandName);
749
774
  const view = new MenuBarMenuListItemButtonView(editor.locale);
@@ -762,12 +787,12 @@ class RestrictedEditingModeUI extends Plugin {
762
787
  return view;
763
788
  }
764
789
  /**
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) {
790
+ * Returns a definition of the navigation button to be used in the dropdown.
791
+ *
792
+ * @param commandName The name of the command that the button represents.
793
+ * @param label The translated label of the button.
794
+ * @param keystroke The button keystroke.
795
+ */ _getButtonDefinition(commandName, label, keystroke) {
771
796
  const editor = this.editor;
772
797
  const command = editor.commands.get(commandName);
773
798
  const definition = {
@@ -785,10 +810,10 @@ class RestrictedEditingModeUI extends Plugin {
785
810
  return definition;
786
811
  }
787
812
  /**
788
- * Returns definitions for UI buttons.
789
- *
790
- * @internal
791
- */ _getButtonDefinitions() {
813
+ * Returns definitions for UI buttons.
814
+ *
815
+ * @internal
816
+ */ _getButtonDefinitions() {
792
817
  const t = this.editor.locale.t;
793
818
  return [
794
819
  {
@@ -805,15 +830,22 @@ class RestrictedEditingModeUI extends Plugin {
805
830
  }
806
831
  }
807
832
 
808
- class RestrictedEditingMode extends Plugin {
833
+ /**
834
+ * The restricted editing mode plugin.
835
+ *
836
+ * This is a "glue" plugin which loads the following plugins:
837
+ *
838
+ * * The {@link module:restricted-editing/restrictededitingmodeediting~RestrictedEditingModeEditing restricted mode editing feature}.
839
+ * * The {@link module:restricted-editing/restrictededitingmodeui~RestrictedEditingModeUI restricted mode UI feature}.
840
+ */ class RestrictedEditingMode extends Plugin {
809
841
  /**
810
- * @inheritDoc
811
- */ static get pluginName() {
842
+ * @inheritDoc
843
+ */ static get pluginName() {
812
844
  return 'RestrictedEditingMode';
813
845
  }
814
846
  /**
815
- * @inheritDoc
816
- */ static get requires() {
847
+ * @inheritDoc
848
+ */ static get requires() {
817
849
  return [
818
850
  RestrictedEditingModeEditing,
819
851
  RestrictedEditingModeUI
@@ -821,18 +853,20 @@ class RestrictedEditingMode extends Plugin {
821
853
  }
822
854
  }
823
855
 
824
- class RestrictedEditingExceptionCommand extends Command {
856
+ /**
857
+ * The command that toggles exceptions from the restricted editing on text.
858
+ */ class RestrictedEditingExceptionCommand extends Command {
825
859
  /**
826
- * @inheritDoc
827
- */ refresh() {
860
+ * @inheritDoc
861
+ */ refresh() {
828
862
  const model = this.editor.model;
829
863
  const doc = model.document;
830
864
  this.value = !!doc.selection.getAttribute('restrictedEditingException');
831
865
  this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'restrictedEditingException');
832
866
  }
833
867
  /**
834
- * @inheritDoc
835
- */ execute(options = {}) {
868
+ * @inheritDoc
869
+ */ execute(options = {}) {
836
870
  const model = this.editor.model;
837
871
  const document = model.document;
838
872
  const selection = document.selection;
@@ -869,15 +903,21 @@ class RestrictedEditingExceptionCommand extends Command {
869
903
  }
870
904
  }
871
905
 
872
- class StandardEditingModeEditing extends Plugin {
906
+ /**
907
+ * The standard editing mode editing feature.
908
+ *
909
+ * * It introduces the `restrictedEditingException` text attribute that is rendered as
910
+ * a `<span>` element with the `restricted-editing-exception` CSS class.
911
+ * * It registers the `'restrictedEditingException'` command.
912
+ */ class StandardEditingModeEditing extends Plugin {
873
913
  /**
874
- * @inheritDoc
875
- */ static get pluginName() {
914
+ * @inheritDoc
915
+ */ static get pluginName() {
876
916
  return 'StandardEditingModeEditing';
877
917
  }
878
918
  /**
879
- * @inheritDoc
880
- */ init() {
919
+ * @inheritDoc
920
+ */ init() {
881
921
  const editor = this.editor;
882
922
  editor.model.schema.extend('$text', {
883
923
  allowAttributes: [
@@ -915,15 +955,19 @@ class StandardEditingModeEditing extends Plugin {
915
955
 
916
956
  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
957
 
918
- class StandardEditingModeUI extends Plugin {
958
+ /**
959
+ * The standard editing mode UI feature.
960
+ *
961
+ * It introduces the `'restrictedEditingException'` button that marks text as unrestricted for editing.
962
+ */ class StandardEditingModeUI extends Plugin {
919
963
  /**
920
- * @inheritDoc
921
- */ static get pluginName() {
964
+ * @inheritDoc
965
+ */ static get pluginName() {
922
966
  return 'StandardEditingModeUI';
923
967
  }
924
968
  /**
925
- * @inheritDoc
926
- */ init() {
969
+ * @inheritDoc
970
+ */ init() {
927
971
  const editor = this.editor;
928
972
  editor.ui.componentFactory.add('restrictedEditingException', ()=>{
929
973
  const button = this._createButton(ButtonView);
@@ -938,8 +982,8 @@ class StandardEditingModeUI extends Plugin {
938
982
  });
939
983
  }
940
984
  /**
941
- * Creates a button for restricted editing exception command to use either in toolbar or in menu bar.
942
- */ _createButton(ButtonClass) {
985
+ * Creates a button for restricted editing exception command to use either in toolbar or in menu bar.
986
+ */ _createButton(ButtonClass) {
943
987
  const editor = this.editor;
944
988
  const locale = editor.locale;
945
989
  const command = this.editor.commands.get('restrictedEditingException');
@@ -959,10 +1003,17 @@ class StandardEditingModeUI extends Plugin {
959
1003
  }
960
1004
  }
961
1005
 
962
- class StandardEditingMode extends Plugin {
1006
+ /**
1007
+ * The standard editing mode plugin.
1008
+ *
1009
+ * This is a "glue" plugin that loads the following plugins:
1010
+ *
1011
+ * * The {@link module:restricted-editing/standardeditingmodeediting~StandardEditingModeEditing standard mode editing feature}.
1012
+ * * The {@link module:restricted-editing/standardeditingmodeui~StandardEditingModeUI standard mode UI feature}.
1013
+ */ class StandardEditingMode extends Plugin {
963
1014
  /**
964
- * @inheritDoc
965
- */ static get pluginName() {
1015
+ * @inheritDoc
1016
+ */ static get pluginName() {
966
1017
  return 'StandardEditingMode';
967
1018
  }
968
1019
  static get requires() {