@ckeditor/ckeditor5-bookmark 0.0.0-nightly-next-20250225.0 → 0.0.0-nightly-next-20250226.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 (92) hide show
  1. package/build/bookmark.js +2 -2
  2. package/build/translations/af.js +1 -1
  3. package/build/translations/ar.js +1 -1
  4. package/build/translations/ast.js +1 -1
  5. package/build/translations/az.js +1 -1
  6. package/build/translations/bg.js +1 -1
  7. package/build/translations/bn.js +1 -1
  8. package/build/translations/bs.js +1 -1
  9. package/build/translations/ca.js +1 -1
  10. package/build/translations/cs.js +1 -1
  11. package/build/translations/da.js +1 -1
  12. package/build/translations/de-ch.js +1 -1
  13. package/build/translations/de.js +1 -1
  14. package/build/translations/el.js +1 -1
  15. package/build/translations/en-au.js +1 -1
  16. package/build/translations/en-gb.js +1 -1
  17. package/build/translations/eo.js +1 -1
  18. package/build/translations/es-co.js +1 -1
  19. package/build/translations/es.js +1 -1
  20. package/build/translations/et.js +1 -1
  21. package/build/translations/eu.js +1 -1
  22. package/build/translations/fa.js +1 -1
  23. package/build/translations/fi.js +1 -1
  24. package/build/translations/fr.js +1 -1
  25. package/build/translations/gl.js +1 -1
  26. package/build/translations/gu.js +1 -1
  27. package/build/translations/he.js +1 -1
  28. package/build/translations/hi.js +1 -1
  29. package/build/translations/hr.js +1 -1
  30. package/build/translations/hu.js +1 -1
  31. package/build/translations/hy.js +1 -1
  32. package/build/translations/id.js +1 -1
  33. package/build/translations/it.js +1 -1
  34. package/build/translations/ja.js +1 -1
  35. package/build/translations/jv.js +1 -1
  36. package/build/translations/kk.js +1 -1
  37. package/build/translations/km.js +1 -1
  38. package/build/translations/kn.js +1 -1
  39. package/build/translations/ko.js +1 -1
  40. package/build/translations/ku.js +1 -1
  41. package/build/translations/lt.js +1 -1
  42. package/build/translations/lv.js +1 -1
  43. package/build/translations/ms.js +1 -1
  44. package/build/translations/nb.js +1 -1
  45. package/build/translations/ne.js +1 -1
  46. package/build/translations/nl.js +1 -1
  47. package/build/translations/no.js +1 -1
  48. package/build/translations/oc.js +1 -1
  49. package/build/translations/pl.js +1 -1
  50. package/build/translations/pt-br.js +1 -1
  51. package/build/translations/pt.js +1 -1
  52. package/build/translations/ro.js +1 -1
  53. package/build/translations/ru.js +1 -1
  54. package/build/translations/si.js +1 -1
  55. package/build/translations/sk.js +1 -1
  56. package/build/translations/sl.js +1 -1
  57. package/build/translations/sq.js +1 -1
  58. package/build/translations/sr-latn.js +1 -1
  59. package/build/translations/sr.js +1 -1
  60. package/build/translations/sv.js +1 -1
  61. package/build/translations/th.js +1 -1
  62. package/build/translations/ti.js +1 -1
  63. package/build/translations/tk.js +1 -1
  64. package/build/translations/tr.js +1 -1
  65. package/build/translations/tt.js +1 -1
  66. package/build/translations/ug.js +1 -1
  67. package/build/translations/uk.js +1 -1
  68. package/build/translations/ur.js +1 -1
  69. package/build/translations/uz.js +1 -1
  70. package/build/translations/vi.js +1 -1
  71. package/build/translations/zh-cn.js +1 -1
  72. package/build/translations/zh.js +1 -1
  73. package/dist/index-editor.css +56 -101
  74. package/dist/index.css +59 -119
  75. package/dist/index.css.map +1 -1
  76. package/dist/index.js +279 -387
  77. package/dist/index.js.map +1 -1
  78. package/lang/contexts.json +5 -3
  79. package/package.json +8 -8
  80. package/src/bookmarkconfig.d.ts +24 -0
  81. package/src/bookmarkediting.d.ts +9 -1
  82. package/src/bookmarkediting.js +16 -0
  83. package/src/bookmarkui.d.ts +24 -57
  84. package/src/bookmarkui.js +197 -204
  85. package/src/ui/bookmarkformview.d.ts +24 -14
  86. package/src/ui/bookmarkformview.js +73 -52
  87. package/theme/bookmark.css +0 -46
  88. package/theme/bookmarkform.css +0 -38
  89. package/theme/bookmarktoolbar.css +4 -0
  90. package/src/ui/bookmarkactionsview.d.ts +0 -102
  91. package/src/ui/bookmarkactionsview.js +0 -170
  92. package/theme/bookmarkactions.css +0 -44
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
5
  import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { toWidget, Widget } from '@ckeditor/ckeditor5-widget/dist/index.js';
7
- import { View, ViewCollection, FocusCycler, submitHandler, FormHeaderView, LabeledFieldView, createLabeledInputText, ButtonView, LabelView, IconView, ContextualBalloon, CssTransitionDisablerMixin, MenuBarMenuListItemButtonView, clickOutsideHandler } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
- import { IconRemove, IconPencil, IconBookmarkInline, IconBookmark } from '@ckeditor/ckeditor5-icons/dist/index.js';
9
- import { ClickObserver } from '@ckeditor/ckeditor5-engine/dist/index.js';
6
+ import { toWidget, WidgetToolbarRepository, isWidget, Widget } from '@ckeditor/ckeditor5-widget/dist/index.js';
7
+ import { View, ViewCollection, FormRowView, FocusCycler, submitHandler, ButtonView, FormHeaderView, LabeledFieldView, createLabeledInputText, IconView, ContextualBalloon, BalloonPanelView, CssTransitionDisablerMixin, MenuBarMenuListItemButtonView, LabelView, clickOutsideHandler } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
+ import { IconBookmarkInline, IconPencil, IconRemove, IconBookmark, IconBookmarkMedium, IconBookmarkSmall } from '@ckeditor/ckeditor5-icons/dist/index.js';
10
9
  import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-utils/dist/index.js';
10
+ import { IconPreviousArrow } from '@ckeditor/ckeditor5-icons/dist/index.js';
11
11
 
12
12
  /**
13
13
  * The bookmark form view controller class.
@@ -24,8 +24,11 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
24
24
  * The ID input view.
25
25
  */ idInputView;
26
26
  /**
27
- * The Submit button view.
28
- */ buttonView;
27
+ * The Back button view displayed in the header.
28
+ */ backButtonView;
29
+ /**
30
+ * A button used to submit the form.
31
+ */ saveButtonView;
29
32
  /**
30
33
  * A collection of form child views in the form.
31
34
  */ children;
@@ -47,12 +50,30 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
47
50
  * @param validators Form validators used by {@link #isValid}.
48
51
  */ constructor(locale, validators){
49
52
  super(locale);
50
- const t = locale.t;
51
53
  this._validators = validators;
54
+ // Create buttons.
55
+ this.backButtonView = this._createBackButton();
56
+ this.saveButtonView = this._createSaveButton();
57
+ // Create input fields.
52
58
  this.idInputView = this._createIdInput();
53
- this.buttonView = this._createButton(t('Insert'), 'ck-button-action ck-button-bold');
54
- this.buttonView.type = 'submit';
55
- this.children = this._createViewChildren();
59
+ this.children = this.createCollection([
60
+ this._createHeaderView()
61
+ ]);
62
+ this.children.add(new FormRowView(locale, {
63
+ children: [
64
+ this.idInputView,
65
+ this.saveButtonView
66
+ ],
67
+ class: [
68
+ 'ck-form__row_with-submit',
69
+ 'ck-form__row_large-top-padding'
70
+ ]
71
+ }));
72
+ // Close the panel on esc key press when the **form has focus**.
73
+ this.keystrokes.set('Esc', (data, cancel)=>{
74
+ this.fire('cancel');
75
+ cancel();
76
+ });
56
77
  this._focusCycler = new FocusCycler({
57
78
  focusables: this._focusables,
58
79
  focusTracker: this.focusTracker,
@@ -64,14 +85,15 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
64
85
  focusNext: 'tab'
65
86
  }
66
87
  });
67
- const classList = [
68
- 'ck',
69
- 'ck-bookmark-view'
70
- ];
71
88
  this.setTemplate({
72
89
  tag: 'form',
73
90
  attributes: {
74
- class: classList,
91
+ class: [
92
+ 'ck',
93
+ 'ck-form',
94
+ 'ck-bookmark-form',
95
+ 'ck-responsive-form'
96
+ ],
75
97
  // https://github.com/ckeditor/ckeditor5-link/issues/90
76
98
  tabindex: '-1'
77
99
  },
@@ -86,8 +108,9 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
86
108
  view: this
87
109
  });
88
110
  const childViews = [
111
+ this.backButtonView,
89
112
  this.idInputView,
90
- this.buttonView
113
+ this.saveButtonView
91
114
  ];
92
115
  childViews.forEach((v)=>{
93
116
  // Register the view as focusable.
@@ -108,7 +131,7 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
108
131
  /**
109
132
  * Focuses the fist {@link #_focusables} in the form.
110
133
  */ focus() {
111
- this._focusCycler.focusFirst();
134
+ this.idInputView.focus();
112
135
  }
113
136
  /**
114
137
  * Validates the form and returns `false` when some fields are invalid.
@@ -134,36 +157,41 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
134
157
  this.idInputView.errorText = null;
135
158
  }
136
159
  /**
137
- * Creates header and form view.
138
- */ _createViewChildren() {
139
- const children = this.createCollection();
140
- const t = this.t;
141
- children.add(new FormHeaderView(this.locale, {
142
- label: t('Bookmark')
143
- }));
144
- children.add(this._createFormContentView());
145
- return children;
160
+ * Creates a back button view that cancels the form.
161
+ */ _createBackButton() {
162
+ const t = this.locale.t;
163
+ const backButton = new ButtonView(this.locale);
164
+ backButton.set({
165
+ class: 'ck-button-back',
166
+ label: t('Back'),
167
+ icon: IconPreviousArrow,
168
+ tooltip: true
169
+ });
170
+ backButton.delegate('execute').to(this, 'cancel');
171
+ return backButton;
146
172
  }
147
173
  /**
148
- * Creates form content view with input and button.
149
- */ _createFormContentView() {
150
- const view = new View(this.locale);
151
- const children = this.createCollection();
152
- const classList = [
153
- 'ck',
154
- 'ck-bookmark-form',
155
- 'ck-responsive-form'
156
- ];
157
- children.add(this.idInputView);
158
- children.add(this.buttonView);
159
- view.setTemplate({
160
- tag: 'div',
161
- attributes: {
162
- class: classList
163
- },
164
- children
174
+ * Creates a save button view that saves the bookmark.
175
+ */ _createSaveButton() {
176
+ const t = this.locale.t;
177
+ const saveButton = new ButtonView(this.locale);
178
+ saveButton.set({
179
+ label: t('Save'),
180
+ withText: true,
181
+ type: 'submit',
182
+ class: 'ck-button-action ck-button-bold'
165
183
  });
166
- return view;
184
+ return saveButton;
185
+ }
186
+ /**
187
+ * Creates a header view for the form.
188
+ */ _createHeaderView() {
189
+ const t = this.locale.t;
190
+ const header = new FormHeaderView(this.locale, {
191
+ label: t('Bookmark')
192
+ });
193
+ header.children.add(this.backButtonView, 0);
194
+ return header;
167
195
  }
168
196
  /**
169
197
  * Creates a labeled input view.
@@ -174,27 +202,9 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
174
202
  const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
175
203
  labeledInput.label = t('Bookmark name');
176
204
  labeledInput.infoText = t('Enter the bookmark name without spaces.');
205
+ labeledInput.class = 'ck-labeled-field-view_full-width';
177
206
  return labeledInput;
178
207
  }
179
- /**
180
- * Creates a button view.
181
- *
182
- * @param label The button label.
183
- * @param className The additional button CSS class name.
184
- * @returns The button view instance.
185
- */ _createButton(label, className) {
186
- const button = new ButtonView(this.locale);
187
- button.set({
188
- label,
189
- withText: true
190
- });
191
- button.extendTemplate({
192
- attributes: {
193
- class: className
194
- }
195
- });
196
- return button;
197
- }
198
208
  /**
199
209
  * The native DOM `value` of the {@link #idInputView} element.
200
210
  *
@@ -209,149 +219,6 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
209
219
  }
210
220
  }
211
221
 
212
- /**
213
- * The bookmark actions view class. This view displays the bookmark preview, allows
214
- * removing or editing the bookmark.
215
- */ class BookmarkActionsView extends View {
216
- /**
217
- * Tracks information about DOM focus in the actions.
218
- */ focusTracker = new FocusTracker();
219
- /**
220
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
221
- */ keystrokes = new KeystrokeHandler();
222
- /**
223
- * The bookmark preview view.
224
- */ bookmarkPreviewView;
225
- /**
226
- * The remove button view.
227
- */ removeButtonView;
228
- /**
229
- * The edit bookmark button view.
230
- */ editButtonView;
231
- /**
232
- * A collection of views that can be focused in the view.
233
- */ _focusables = new ViewCollection();
234
- /**
235
- * Helps cycling over {@link #_focusables} in the view.
236
- */ _focusCycler;
237
- /**
238
- * @inheritDoc
239
- */ constructor(locale){
240
- super(locale);
241
- const t = locale.t;
242
- this.bookmarkPreviewView = this._createBookmarkPreviewView();
243
- this.removeButtonView = this._createButton(t('Remove bookmark'), IconRemove, 'remove', this.bookmarkPreviewView);
244
- this.editButtonView = this._createButton(t('Edit bookmark'), IconPencil, 'edit', this.bookmarkPreviewView);
245
- this.set('id', undefined);
246
- this._focusCycler = new FocusCycler({
247
- focusables: this._focusables,
248
- focusTracker: this.focusTracker,
249
- keystrokeHandler: this.keystrokes,
250
- actions: {
251
- // Navigate fields backwards using the Shift + Tab keystroke.
252
- focusPrevious: 'shift + tab',
253
- // Navigate fields forwards using the Tab key.
254
- focusNext: 'tab'
255
- }
256
- });
257
- this.setTemplate({
258
- tag: 'div',
259
- attributes: {
260
- class: [
261
- 'ck',
262
- 'ck-bookmark-actions',
263
- 'ck-responsive-form'
264
- ],
265
- // https://github.com/ckeditor/ckeditor5-link/issues/90
266
- tabindex: '-1'
267
- },
268
- children: [
269
- this.bookmarkPreviewView,
270
- this.editButtonView,
271
- this.removeButtonView
272
- ]
273
- });
274
- }
275
- /**
276
- * @inheritDoc
277
- */ render() {
278
- super.render();
279
- const childViews = [
280
- this.editButtonView,
281
- this.removeButtonView
282
- ];
283
- childViews.forEach((v)=>{
284
- // Register the view as focusable.
285
- this._focusables.add(v);
286
- // Register the view in the focus tracker.
287
- this.focusTracker.add(v.element);
288
- });
289
- // Start listening for the keystrokes coming from #element.
290
- this.keystrokes.listenTo(this.element);
291
- }
292
- /**
293
- * @inheritDoc
294
- */ destroy() {
295
- super.destroy();
296
- this.focusTracker.destroy();
297
- this.keystrokes.destroy();
298
- }
299
- /**
300
- * Focuses the fist {@link #_focusables} in the actions.
301
- */ focus() {
302
- this._focusCycler.focusFirst();
303
- }
304
- /**
305
- * Creates a button view.
306
- *
307
- * @param label The button label.
308
- * @param icon The button icon.
309
- * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
310
- * @param additionalLabel An additional label outside the button.
311
- * @returns The button view instance.
312
- */ _createButton(label, icon, eventName, additionalLabel) {
313
- const button = new ButtonView(this.locale);
314
- button.set({
315
- label,
316
- icon,
317
- tooltip: true
318
- });
319
- button.delegate('execute').to(this, eventName);
320
- // Since button label `id` is bound to the `ariaLabelledBy` property
321
- // we need to modify this binding to include only the first ID token
322
- // as this button will be labeled by multiple labels.
323
- button.labelView.unbind('id');
324
- button.labelView.bind('id').to(button, 'ariaLabelledBy', (ariaLabelledBy)=>{
325
- return getFirstToken(ariaLabelledBy);
326
- });
327
- button.ariaLabelledBy = `${button.ariaLabelledBy} ${additionalLabel.id}`;
328
- return button;
329
- }
330
- /**
331
- * Creates a bookmark name preview label.
332
- *
333
- * @returns The label view instance.
334
- */ _createBookmarkPreviewView() {
335
- const label = new LabelView(this.locale);
336
- label.extendTemplate({
337
- attributes: {
338
- class: [
339
- 'ck',
340
- 'ck-bookmark-actions__preview'
341
- ]
342
- }
343
- });
344
- // Bind label text with the bookmark ID.
345
- label.bind('text').to(this, 'id');
346
- return label;
347
- }
348
- }
349
- /**
350
- * Returns the first token from space separated token list.
351
- */ function getFirstToken(tokenList) {
352
- return tokenList.split(' ')[0];
353
- }
354
-
355
222
  /**
356
223
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
357
224
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
@@ -549,6 +416,19 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
549
416
  */ static get isOfficialPlugin() {
550
417
  return true;
551
418
  }
419
+ /**
420
+ * @inheritDoc
421
+ */ constructor(editor){
422
+ super(editor);
423
+ editor.config.define('bookmark', {
424
+ toolbar: [
425
+ 'bookmarkPreview',
426
+ '|',
427
+ 'editBookmark',
428
+ 'removeBookmark'
429
+ ]
430
+ });
431
+ }
552
432
  /**
553
433
  * @inheritDoc
554
434
  */ init() {
@@ -571,6 +451,11 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
571
451
  }
572
452
  return null;
573
453
  }
454
+ /**
455
+ * Returns all unique bookmark names existing in the content.
456
+ */ getAllBookmarkNames() {
457
+ return new Set(this._bookmarkElements.values());
458
+ }
574
459
  /**
575
460
  * Defines the schema for the bookmark feature.
576
461
  */ _defineSchema() {
@@ -623,6 +508,7 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
623
508
  }, [
624
509
  this._createBookmarkUIElement(writer)
625
510
  ]);
511
+ writer.setCustomProperty('bookmark', true, containerElement);
626
512
  this._bookmarkElements.set(modelElement, id);
627
513
  // `getFillerOffset` is not needed to set here, because `toWidget` has already covered it.
628
514
  const labelCreator = ()=>`${id} ${t('bookmark widget')}`;
@@ -752,9 +638,6 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
752
638
  * It registers the `'bookmark'` UI button in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
753
639
  * which inserts the `bookmark` element upon selection.
754
640
  */ class BookmarkUI extends Plugin {
755
- /**
756
- * The actions view displayed inside of the balloon.
757
- */ actionsView = null;
758
641
  /**
759
642
  * The form view displayed inside the balloon.
760
643
  */ formView = null;
@@ -766,7 +649,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
766
649
  */ static get requires() {
767
650
  return [
768
651
  BookmarkEditing,
769
- ContextualBalloon
652
+ ContextualBalloon,
653
+ WidgetToolbarRepository
770
654
  ];
771
655
  }
772
656
  /**
@@ -783,11 +667,13 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
783
667
  * @inheritDoc
784
668
  */ init() {
785
669
  const editor = this.editor;
786
- editor.editing.view.addObserver(ClickObserver);
787
670
  this._balloon = editor.plugins.get(ContextualBalloon);
671
+ // Register the link provider in link plugin to display the link form.
672
+ if (editor.plugins.has('LinkUI')) {
673
+ this._registerLinkProvider();
674
+ }
788
675
  // Create toolbar buttons.
789
- this._createToolbarBookmarkButton();
790
- this._enableBalloonActivators();
676
+ this._registerComponents();
791
677
  // Renders a fake visual selection marker on an expanded selection.
792
678
  editor.conversion.for('editingDowncast').markerToHighlight({
793
679
  model: VISUAL_SELECTION_MARKER_NAME,
@@ -813,6 +699,34 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
813
699
  }
814
700
  });
815
701
  }
702
+ /**
703
+ * @inheritDoc
704
+ */ afterInit() {
705
+ const editor = this.editor;
706
+ const t = editor.locale.t;
707
+ const widgetToolbarRepository = this.editor.plugins.get(WidgetToolbarRepository);
708
+ const defaultPositions = BalloonPanelView.defaultPositions;
709
+ widgetToolbarRepository.register('bookmark', {
710
+ ariaLabel: t('Bookmark toolbar'),
711
+ items: editor.config.get('bookmark.toolbar'),
712
+ getRelatedElement: getSelectedBookmarkWidget,
713
+ // Override positions to the same list as for balloon panel default
714
+ // so widget toolbar will try to use same position as form view.
715
+ positions: [
716
+ defaultPositions.southArrowNorth,
717
+ defaultPositions.southArrowNorthMiddleWest,
718
+ defaultPositions.southArrowNorthMiddleEast,
719
+ defaultPositions.southArrowNorthWest,
720
+ defaultPositions.southArrowNorthEast,
721
+ defaultPositions.northArrowSouth,
722
+ defaultPositions.northArrowSouthMiddleWest,
723
+ defaultPositions.northArrowSouthMiddleEast,
724
+ defaultPositions.northArrowSouthWest,
725
+ defaultPositions.northArrowSouthEast,
726
+ defaultPositions.viewportStickyNorth
727
+ ]
728
+ });
729
+ }
816
730
  /**
817
731
  * @inheritDoc
818
732
  */ destroy() {
@@ -821,49 +735,20 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
821
735
  if (this.formView) {
822
736
  this.formView.destroy();
823
737
  }
824
- if (this.actionsView) {
825
- this.actionsView.destroy();
826
- }
827
738
  }
828
739
  /**
829
740
  * Creates views.
830
741
  */ _createViews() {
831
- this.actionsView = this._createActionsView();
832
742
  this.formView = this._createFormView();
833
743
  // Attach lifecycle actions to the the balloon.
834
744
  this._enableUserBalloonInteractions();
835
745
  }
836
- /**
837
- * Creates the {@link module:bookmark/ui/bookmarkactionsview~BookmarkActionsView} instance.
838
- */ _createActionsView() {
839
- const editor = this.editor;
840
- const actionsView = new BookmarkActionsView(editor.locale);
841
- const updateBookmarkCommand = editor.commands.get('updateBookmark');
842
- const deleteCommand = editor.commands.get('delete');
843
- actionsView.bind('id').to(updateBookmarkCommand, 'value');
844
- actionsView.editButtonView.bind('isEnabled').to(updateBookmarkCommand);
845
- actionsView.removeButtonView.bind('isEnabled').to(deleteCommand);
846
- // Display edit form view after clicking on the "Edit" button.
847
- this.listenTo(actionsView, 'edit', ()=>{
848
- this._addFormView();
849
- });
850
- // Execute remove command after clicking on the "Remove" button.
851
- this.listenTo(actionsView, 'remove', ()=>{
852
- this._hideUI();
853
- editor.execute('delete');
854
- });
855
- // Close the panel on esc key press when the **actions have focus**.
856
- actionsView.keystrokes.set('Esc', (data, cancel)=>{
857
- this._hideUI();
858
- cancel();
859
- });
860
- return actionsView;
861
- }
862
746
  /**
863
747
  * Creates the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} instance.
864
748
  */ _createFormView() {
865
749
  const editor = this.editor;
866
750
  const locale = editor.locale;
751
+ const t = locale.t;
867
752
  const insertBookmarkCommand = editor.commands.get('insertBookmark');
868
753
  const updateBookmarkCommand = editor.commands.get('updateBookmark');
869
754
  const commands = [
@@ -872,10 +757,15 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
872
757
  ];
873
758
  const formView = new (CssTransitionDisablerMixin(BookmarkFormView))(locale, getFormValidators(editor));
874
759
  formView.idInputView.fieldView.bind('value').to(updateBookmarkCommand, 'value');
760
+ formView.saveButtonView.bind('label').to(updateBookmarkCommand, 'value', (value)=>value ? t('Save') : t('Insert'));
875
761
  // Form elements should be read-only when corresponding commands are disabled.
876
762
  formView.idInputView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled)=>areEnabled.some((isEnabled)=>isEnabled));
877
763
  // Disable the "save" button if the command is disabled.
878
- formView.buttonView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled)=>areEnabled.some((isEnabled)=>isEnabled));
764
+ formView.saveButtonView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled)=>areEnabled.some((isEnabled)=>isEnabled));
765
+ // Close the panel on form after clicking back button.
766
+ this.listenTo(formView, 'cancel', ()=>{
767
+ this._hideFormView();
768
+ });
879
769
  // Execute link command after clicking the "Save" button.
880
770
  this.listenTo(formView, 'submit', ()=>{
881
771
  if (formView.isValid()) {
@@ -889,39 +779,131 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
889
779
  bookmarkId: value
890
780
  });
891
781
  }
892
- this._closeFormView();
782
+ this._hideFormView();
893
783
  }
894
784
  });
895
785
  // Update balloon position when form error changes.
896
786
  this.listenTo(formView.idInputView, 'change:errorText', ()=>{
897
787
  editor.ui.update();
898
788
  });
899
- // Close the panel on esc key press when the **form has focus**.
900
- formView.keystrokes.set('Esc', (data, cancel)=>{
901
- this._closeFormView();
902
- cancel();
903
- });
904
789
  return formView;
905
790
  }
791
+ /**
792
+ * Creates link form menu list entry, so it'll be possible to access
793
+ * the list of the bookmarks from the link form.
794
+ */ _registerLinkProvider() {
795
+ const t = this.editor.locale.t;
796
+ const linksUI = this.editor.plugins.get('LinkUI');
797
+ const bookmarkEditing = this.editor.plugins.get(BookmarkEditing);
798
+ const getListItems = ()=>Array.from(bookmarkEditing.getAllBookmarkNames()).sort((a, b)=>a.localeCompare(b)).map((bookmarkId)=>({
799
+ id: bookmarkId,
800
+ href: `#${bookmarkId}`,
801
+ label: bookmarkId,
802
+ icon: IconBookmarkMedium
803
+ }));
804
+ const getItem = (href)=>{
805
+ const bookmark = [
806
+ ...bookmarkEditing.getAllBookmarkNames()
807
+ ].find((item)=>`#${item}` === href);
808
+ if (!bookmark) {
809
+ return null;
810
+ }
811
+ return {
812
+ href,
813
+ label: bookmark,
814
+ icon: IconBookmarkSmall,
815
+ tooltip: t('Scroll to bookmark')
816
+ };
817
+ };
818
+ linksUI.registerLinksListProvider({
819
+ label: t('Bookmarks'),
820
+ emptyListPlaceholder: t('No bookmarks available.'),
821
+ navigate: ({ href })=>this._scrollToBookmark(href),
822
+ getListItems,
823
+ getItem
824
+ });
825
+ }
826
+ /**
827
+ * Scrolls the editor to the bookmark with the given id.
828
+ */ _scrollToBookmark(href) {
829
+ const bookmarkEditing = this.editor.plugins.get(BookmarkEditing);
830
+ const bookmarkElement = bookmarkEditing.getElementForBookmarkId(href.slice(1));
831
+ if (!bookmarkElement) {
832
+ return false;
833
+ }
834
+ this.editor.model.change((writer)=>{
835
+ writer.setSelection(bookmarkElement, 'on');
836
+ });
837
+ this.editor.editing.view.scrollToTheSelection({
838
+ alignToTop: true,
839
+ forceScroll: true
840
+ });
841
+ return true;
842
+ }
906
843
  /**
907
844
  * Creates a toolbar Bookmark button. Clicking this button will show
908
845
  * a {@link #_balloon} attached to the selection.
909
- */ _createToolbarBookmarkButton() {
846
+ */ _registerComponents() {
910
847
  const editor = this.editor;
911
848
  editor.ui.componentFactory.add('bookmark', ()=>{
912
- const buttonView = this._createButton(ButtonView);
849
+ const buttonView = this._createBookmarkButton(ButtonView);
913
850
  buttonView.set({
914
851
  tooltip: true
915
852
  });
916
853
  return buttonView;
917
854
  });
918
855
  editor.ui.componentFactory.add('menuBar:bookmark', ()=>{
919
- return this._createButton(MenuBarMenuListItemButtonView);
856
+ return this._createBookmarkButton(MenuBarMenuListItemButtonView);
857
+ });
858
+ // Bookmark toolbar buttons.
859
+ editor.ui.componentFactory.add('bookmarkPreview', (locale)=>{
860
+ const updateBookmarkCommand = editor.commands.get('updateBookmark');
861
+ const label = new LabelView(locale);
862
+ label.extendTemplate({
863
+ attributes: {
864
+ class: [
865
+ 'ck-bookmark-toolbar__preview'
866
+ ]
867
+ }
868
+ });
869
+ label.bind('text').to(updateBookmarkCommand, 'value');
870
+ return label;
871
+ });
872
+ editor.ui.componentFactory.add('editBookmark', (locale)=>{
873
+ const updateBookmarkCommand = editor.commands.get('updateBookmark');
874
+ const button = new ButtonView(locale);
875
+ const t = locale.t;
876
+ button.set({
877
+ label: t('Edit bookmark'),
878
+ icon: IconPencil,
879
+ tooltip: true
880
+ });
881
+ button.bind('isEnabled').to(updateBookmarkCommand);
882
+ this.listenTo(button, 'execute', ()=>{
883
+ this._showFormView();
884
+ });
885
+ return button;
886
+ });
887
+ editor.ui.componentFactory.add('removeBookmark', (locale)=>{
888
+ const deleteCommand = editor.commands.get('delete');
889
+ const button = new ButtonView(locale);
890
+ const t = locale.t;
891
+ button.set({
892
+ label: t('Remove bookmark'),
893
+ icon: IconRemove,
894
+ tooltip: true
895
+ });
896
+ button.bind('isEnabled').to(deleteCommand);
897
+ this.listenTo(button, 'execute', ()=>{
898
+ editor.execute('delete');
899
+ editor.editing.view.focus();
900
+ });
901
+ return button;
920
902
  });
921
903
  }
922
904
  /**
923
905
  * Creates a button for `bookmark` command to use either in toolbar or in menu bar.
924
- */ _createButton(ButtonClass) {
906
+ */ _createBookmarkButton(ButtonClass) {
925
907
  const editor = this.editor;
926
908
  const locale = editor.locale;
927
909
  const view = new ButtonClass(locale);
@@ -933,7 +915,7 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
933
915
  icon: IconBookmark
934
916
  });
935
917
  // Execute the command.
936
- this.listenTo(view, 'execute', ()=>this._showUI(true));
918
+ this.listenTo(view, 'execute', ()=>this._showFormView());
937
919
  view.bind('isEnabled').toMany([
938
920
  insertCommand,
939
921
  updateCommand
@@ -941,75 +923,25 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
941
923
  view.bind('isOn').to(updateCommand, 'value', (value)=>!!value);
942
924
  return view;
943
925
  }
944
- /**
945
- * Attaches actions that control whether the balloon panel containing the
946
- * {@link #formView} should be displayed.
947
- */ _enableBalloonActivators() {
948
- const editor = this.editor;
949
- const viewDocument = editor.editing.view.document;
950
- // Handle click on view document and show panel when selection is placed inside the bookmark element.
951
- // Keep panel open until selection will be inside the same bookmark element.
952
- this.listenTo(viewDocument, 'click', ()=>{
953
- const bookmark = this._getSelectedBookmarkElement();
954
- if (bookmark) {
955
- // Then show panel but keep focus inside editor editable.
956
- this._showUI();
957
- }
958
- });
959
- }
960
926
  /**
961
927
  * Attaches actions that control whether the balloon panel containing the
962
928
  * {@link #formView} is visible or not.
963
929
  */ _enableUserBalloonInteractions() {
964
- // Focus the form if the balloon is visible and the Tab key has been pressed.
965
- this.editor.keystrokes.set('Tab', (data, cancel)=>{
966
- if (this._areActionsVisible && !this.actionsView.focusTracker.isFocused) {
967
- this.actionsView.focus();
968
- cancel();
969
- }
970
- }, {
971
- // Use the high priority because the bookmark UI navigation is more important
972
- // than other feature's actions, e.g. list indentation.
973
- priority: 'high'
974
- });
975
930
  // Close the panel on the Esc key press when the editable has focus and the balloon is visible.
976
931
  this.editor.keystrokes.set('Esc', (data, cancel)=>{
977
- if (this._isUIVisible) {
978
- this._hideUI();
932
+ if (this._isFormVisible) {
933
+ this._hideFormView();
979
934
  cancel();
980
935
  }
981
936
  });
982
937
  // Close on click outside of balloon panel element.
983
938
  clickOutsideHandler({
984
939
  emitter: this.formView,
985
- activator: ()=>this._isUIInPanel,
940
+ activator: ()=>this._isFormInPanel,
986
941
  contextElements: ()=>[
987
942
  this._balloon.view.element
988
943
  ],
989
- callback: ()=>this._hideUI()
990
- });
991
- }
992
- /**
993
- * Updates the button label. If bookmark is selected label is set to 'Update' otherwise
994
- * it is 'Insert'.
995
- */ _updateFormButtonLabel(isBookmarkSelected) {
996
- const t = this.editor.locale.t;
997
- this.formView.buttonView.label = isBookmarkSelected ? t('Update') : t('Insert');
998
- }
999
- /**
1000
- * Adds the {@link #actionsView} to the {@link #_balloon}.
1001
- *
1002
- * @internal
1003
- */ _addActionsView() {
1004
- if (!this.actionsView) {
1005
- this._createViews();
1006
- }
1007
- if (this._areActionsInPanel) {
1008
- return;
1009
- }
1010
- this._balloon.add({
1011
- view: this.actionsView,
1012
- position: this._getBalloonPositionData()
944
+ callback: ()=>this._hideFormView()
1013
945
  });
1014
946
  }
1015
947
  /**
@@ -1021,14 +953,14 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1021
953
  if (this._isFormInPanel) {
1022
954
  return;
1023
955
  }
1024
- const editor = this.editor;
1025
- const updateBookmarkCommand = editor.commands.get('updateBookmark');
956
+ const updateBookmarkCommand = this.editor.commands.get('updateBookmark');
1026
957
  this.formView.disableCssTransitions();
1027
958
  this.formView.resetFormStatus();
1028
959
  this._balloon.add({
1029
960
  view: this.formView,
1030
961
  position: this._getBalloonPositionData()
1031
962
  });
963
+ this.formView.backButtonView.isVisible = updateBookmarkCommand.isEnabled;
1032
964
  this.formView.idInputView.fieldView.value = updateBookmarkCommand.value || '';
1033
965
  // Select input when form view is currently visible.
1034
966
  if (this._balloon.visibleView === this.formView) {
@@ -1036,69 +968,39 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1036
968
  }
1037
969
  this.formView.enableCssTransitions();
1038
970
  }
1039
- /**
1040
- * Closes the form view. Decides whether the balloon should be hidden completely.
1041
- */ _closeFormView() {
1042
- const updateBookmarkCommand = this.editor.commands.get('updateBookmark');
1043
- if (updateBookmarkCommand.value !== undefined) {
1044
- this._removeFormView();
1045
- } else {
1046
- this._hideUI();
1047
- }
1048
- }
1049
971
  /**
1050
972
  * Removes the {@link #formView} from the {@link #_balloon}.
1051
973
  */ _removeFormView() {
1052
- if (this._isFormInPanel) {
1053
- // Blur the input element before removing it from DOM to prevent issues in some browsers.
1054
- // See https://github.com/ckeditor/ckeditor5/issues/1501.
1055
- this.formView.buttonView.focus();
1056
- // Reset the ID field to update the state of the submit button.
1057
- this.formView.idInputView.fieldView.reset();
1058
- this._balloon.remove(this.formView);
1059
- // Because the form has an input which has focus, the focus must be brought back
1060
- // to the editor. Otherwise, it would be lost.
1061
- this.editor.editing.view.focus();
1062
- this._hideFakeVisualSelection();
1063
- }
974
+ // Blur the input element before removing it from DOM to prevent issues in some browsers.
975
+ // See https://github.com/ckeditor/ckeditor5/issues/1501.
976
+ this.formView.saveButtonView.focus();
977
+ // Reset the ID field to update the state of the submit button.
978
+ this.formView.idInputView.fieldView.reset();
979
+ this._balloon.remove(this.formView);
980
+ // Because the form has an input which has focus, the focus must be brought back
981
+ // to the editor. Otherwise, it would be lost.
982
+ this.editor.editing.view.focus();
983
+ this._hideFakeVisualSelection();
1064
984
  }
1065
985
  /**
1066
- * Shows the correct UI type. It is either {@link #formView} or {@link #actionsView}.
1067
- */ _showUI(forceVisible = false) {
986
+ * Shows the {@link #formView}.
987
+ */ _showFormView() {
1068
988
  if (!this.formView) {
1069
989
  this._createViews();
1070
990
  }
1071
- // When there's no bookmark under the selection, go straight to the editing UI.
1072
991
  if (!this._getSelectedBookmarkElement()) {
1073
- // Show visual selection on a text without a bookmark when the contextual balloon is displayed.
1074
992
  this._showFakeVisualSelection();
1075
- this._addActionsView();
1076
- // Be sure panel with bookmark is visible.
1077
- if (forceVisible) {
1078
- this._balloon.showStack('main');
1079
- }
1080
- this._addFormView();
1081
- } else {
1082
- // Go to the editing UI if actions are already visible.
1083
- if (this._areActionsVisible) {
1084
- this._addFormView();
1085
- } else {
1086
- this._addActionsView();
1087
- }
1088
- // Be sure panel with bookmark is visible.
1089
- if (forceVisible) {
1090
- this._balloon.showStack('main');
1091
- }
1092
993
  }
994
+ this._addFormView();
995
+ // Be sure panel with bookmark is visible.
996
+ this._balloon.showStack('main');
1093
997
  // Begin responding to ui#update once the UI is added.
1094
998
  this._startUpdatingUI();
1095
999
  }
1096
1000
  /**
1097
1001
  * Removes the {@link #formView} from the {@link #_balloon}.
1098
- *
1099
- * See {@link #_addFormView}, {@link #_addActionsView}.
1100
- */ _hideUI() {
1101
- if (!this._isUIInPanel) {
1002
+ */ _hideFormView() {
1003
+ if (!this._isFormInPanel) {
1102
1004
  return;
1103
1005
  }
1104
1006
  const editor = this.editor;
@@ -1109,21 +1011,18 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1109
1011
  editor.editing.view.focus();
1110
1012
  // Remove form first because it's on top of the stack.
1111
1013
  this._removeFormView();
1112
- // Then remove the actions view because it's beneath the form.
1113
- this._balloon.remove(this.actionsView);
1114
1014
  this._hideFakeVisualSelection();
1115
1015
  }
1116
1016
  /**
1117
1017
  * Makes the UI react to the {@link module:ui/editorui/editorui~EditorUI#event:update} event to
1118
1018
  * reposition itself when the editor UI should be refreshed.
1119
1019
  *
1120
- * See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
1020
+ * See: {@link #_hideFormView} to learn when the UI stops reacting to the `update` event.
1121
1021
  */ _startUpdatingUI() {
1122
1022
  const editor = this.editor;
1123
1023
  const viewDocument = editor.editing.view.document;
1124
1024
  let prevSelectedBookmark = this._getSelectedBookmarkElement();
1125
1025
  let prevSelectionParent = getSelectionParent();
1126
- this._updateFormButtonLabel(!!prevSelectedBookmark);
1127
1026
  const update = ()=>{
1128
1027
  const selectedBookmark = this._getSelectedBookmarkElement();
1129
1028
  const selectionParent = getSelectionParent();
@@ -1136,14 +1035,13 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1136
1035
  // * the selection has expanded (e.g. displaying bookmark actions then pressing SHIFT+Right arrow).
1137
1036
  //
1138
1037
  if (prevSelectedBookmark && !selectedBookmark || !prevSelectedBookmark && selectionParent !== prevSelectionParent) {
1139
- this._hideUI();
1140
- } else if (this._isUIVisible) {
1038
+ this._hideFormView();
1039
+ } else if (this._isFormVisible) {
1141
1040
  // If still in a bookmark element, simply update the position of the balloon.
1142
1041
  // If there was no bookmark (e.g. inserting one), the balloon must be moved
1143
1042
  // to the new position in the editing view (a new native DOM range).
1144
1043
  this._balloon.updatePosition(this._getBalloonPositionData());
1145
1044
  }
1146
- this._updateFormButtonLabel(!!prevSelectedBookmark);
1147
1045
  prevSelectedBookmark = selectedBookmark;
1148
1046
  prevSelectionParent = selectionParent;
1149
1047
  };
@@ -1159,27 +1057,9 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1159
1057
  return !!this.formView && this._balloon.hasView(this.formView);
1160
1058
  }
1161
1059
  /**
1162
- * Returns `true` when {@link #actionsView} is in the {@link #_balloon}.
1163
- */ get _areActionsInPanel() {
1164
- return !!this.actionsView && this._balloon.hasView(this.actionsView);
1165
- }
1166
- /**
1167
- * Returns `true` when {@link #actionsView} is in the {@link #_balloon} and it is
1168
- * currently visible.
1169
- */ get _areActionsVisible() {
1170
- return !!this.actionsView && this._balloon.visibleView === this.actionsView;
1171
- }
1172
- /**
1173
- * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon}.
1174
- */ get _isUIInPanel() {
1175
- return this._isFormInPanel || this._areActionsInPanel;
1176
- }
1177
- /**
1178
- * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon} and it is
1179
- * currently visible.
1180
- */ get _isUIVisible() {
1181
- const visibleView = this._balloon.visibleView;
1182
- return !!this.formView && visibleView == this.formView || this._areActionsVisible;
1060
+ * Returns `true` when {@link #formView} is in the {@link #_balloon} and it is currently visible.
1061
+ */ get _isFormVisible() {
1062
+ return !!this.formView && this._balloon.visibleView == this.formView;
1183
1063
  }
1184
1064
  /**
1185
1065
  * Returns positioning options for the {@link #_balloon}. They control the way the balloon is attached
@@ -1202,7 +1082,10 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1202
1082
  return domConverter.mapViewToDom(viewElement);
1203
1083
  };
1204
1084
  }
1205
- return target && {
1085
+ if (!target) {
1086
+ return;
1087
+ }
1088
+ return {
1206
1089
  target
1207
1090
  };
1208
1091
  }
@@ -1290,6 +1173,15 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
1290
1173
  }
1291
1174
  ];
1292
1175
  }
1176
+ /**
1177
+ * Returns the currently selected bookmark view element.
1178
+ */ function getSelectedBookmarkWidget(selection) {
1179
+ const element = selection.getSelectedElement();
1180
+ if (!element || !isWidget(element) || !element.getCustomProperty('bookmark')) {
1181
+ return null;
1182
+ }
1183
+ return element;
1184
+ }
1293
1185
 
1294
1186
  /**
1295
1187
  * The bookmark feature.