@ckeditor/ckeditor5-bookmark 0.0.0-nightly-20241219.0 → 0.0.0-nightly-20241219.2
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/dist/index.js +246 -222
- package/dist/index.js.map +1 -1
- package/package.json +14 -11
package/dist/index.js
CHANGED
|
@@ -14,23 +14,38 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
14
14
|
* See {@link module:bookmark/ui/bookmarkformview~BookmarkFormView}.
|
|
15
15
|
*/ class BookmarkFormView extends View {
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
* Tracks information about DOM focus in the form.
|
|
18
|
+
*/ focusTracker = new FocusTracker();
|
|
19
|
+
/**
|
|
20
|
+
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
21
|
+
*/ keystrokes = new KeystrokeHandler();
|
|
22
|
+
/**
|
|
23
|
+
* The ID input view.
|
|
24
|
+
*/ idInputView;
|
|
25
|
+
/**
|
|
26
|
+
* The Submit button view.
|
|
27
|
+
*/ buttonView;
|
|
28
|
+
/**
|
|
29
|
+
* A collection of form child views in the form.
|
|
30
|
+
*/ children;
|
|
31
|
+
/**
|
|
32
|
+
* An array of form validators used by {@link #isValid}.
|
|
33
|
+
*/ _validators;
|
|
34
|
+
/**
|
|
35
|
+
* A collection of views that can be focused in the form.
|
|
36
|
+
*/ _focusables = new ViewCollection();
|
|
37
|
+
/**
|
|
38
|
+
* Helps cycling over {@link #_focusables} in the form.
|
|
39
|
+
*/ _focusCycler;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an instance of the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} class.
|
|
42
|
+
*
|
|
43
|
+
* Also see {@link #render}.
|
|
44
|
+
*
|
|
45
|
+
* @param locale The localization services instance.
|
|
46
|
+
* @param validators Form validators used by {@link #isValid}.
|
|
47
|
+
*/ constructor(locale, validators){
|
|
24
48
|
super(locale);
|
|
25
|
-
/**
|
|
26
|
-
* Tracks information about DOM focus in the form.
|
|
27
|
-
*/ this.focusTracker = new FocusTracker();
|
|
28
|
-
/**
|
|
29
|
-
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
30
|
-
*/ this.keystrokes = new KeystrokeHandler();
|
|
31
|
-
/**
|
|
32
|
-
* A collection of views that can be focused in the form.
|
|
33
|
-
*/ this._focusables = new ViewCollection();
|
|
34
49
|
const t = locale.t;
|
|
35
50
|
this._validators = validators;
|
|
36
51
|
this.idInputView = this._createIdInput();
|
|
@@ -63,8 +78,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
63
78
|
});
|
|
64
79
|
}
|
|
65
80
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
* @inheritDoc
|
|
82
|
+
*/ render() {
|
|
68
83
|
super.render();
|
|
69
84
|
submitHandler({
|
|
70
85
|
view: this
|
|
@@ -83,20 +98,20 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
83
98
|
this.keystrokes.listenTo(this.element);
|
|
84
99
|
}
|
|
85
100
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
101
|
+
* @inheritDoc
|
|
102
|
+
*/ destroy() {
|
|
88
103
|
super.destroy();
|
|
89
104
|
this.focusTracker.destroy();
|
|
90
105
|
this.keystrokes.destroy();
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
* Focuses the fist {@link #_focusables} in the form.
|
|
109
|
+
*/ focus() {
|
|
95
110
|
this._focusCycler.focusFirst();
|
|
96
111
|
}
|
|
97
112
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
* Validates the form and returns `false` when some fields are invalid.
|
|
114
|
+
*/ isValid() {
|
|
100
115
|
this.resetFormStatus();
|
|
101
116
|
for (const validator of this._validators){
|
|
102
117
|
const errorText = validator(this);
|
|
@@ -110,16 +125,16 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
110
125
|
return true;
|
|
111
126
|
}
|
|
112
127
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
* Cleans up the supplementary error and information text of the {@link #idInputView}
|
|
129
|
+
* bringing them back to the state when the form has been displayed for the first time.
|
|
130
|
+
*
|
|
131
|
+
* See {@link #isValid}.
|
|
132
|
+
*/ resetFormStatus() {
|
|
118
133
|
this.idInputView.errorText = null;
|
|
119
134
|
}
|
|
120
135
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
136
|
+
* Creates header and form view.
|
|
137
|
+
*/ _createViewChildren() {
|
|
123
138
|
const children = this.createCollection();
|
|
124
139
|
const t = this.t;
|
|
125
140
|
children.add(new FormHeaderView(this.locale, {
|
|
@@ -129,8 +144,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
129
144
|
return children;
|
|
130
145
|
}
|
|
131
146
|
/**
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
* Creates form content view with input and button.
|
|
148
|
+
*/ _createFormContentView() {
|
|
134
149
|
const view = new View(this.locale);
|
|
135
150
|
const children = this.createCollection();
|
|
136
151
|
const classList = [
|
|
@@ -150,10 +165,10 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
150
165
|
return view;
|
|
151
166
|
}
|
|
152
167
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
168
|
+
* Creates a labeled input view.
|
|
169
|
+
*
|
|
170
|
+
* @returns Labeled field view instance.
|
|
171
|
+
*/ _createIdInput() {
|
|
157
172
|
const t = this.locale.t;
|
|
158
173
|
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
|
|
159
174
|
labeledInput.label = t('Bookmark name');
|
|
@@ -161,12 +176,12 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
161
176
|
return labeledInput;
|
|
162
177
|
}
|
|
163
178
|
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
179
|
+
* Creates a button view.
|
|
180
|
+
*
|
|
181
|
+
* @param label The button label.
|
|
182
|
+
* @param className The additional button CSS class name.
|
|
183
|
+
* @returns The button view instance.
|
|
184
|
+
*/ _createButton(label, className) {
|
|
170
185
|
const button = new ButtonView(this.locale);
|
|
171
186
|
button.set({
|
|
172
187
|
label,
|
|
@@ -180,11 +195,11 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
180
195
|
return button;
|
|
181
196
|
}
|
|
182
197
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
* The native DOM `value` of the {@link #idInputView} element.
|
|
199
|
+
*
|
|
200
|
+
* **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
|
|
201
|
+
* which works one way only and may not represent the actual state of the component in the DOM.
|
|
202
|
+
*/ get id() {
|
|
188
203
|
const { element } = this.idInputView.fieldView;
|
|
189
204
|
if (!element) {
|
|
190
205
|
return null;
|
|
@@ -198,18 +213,30 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
198
213
|
* removing or editing the bookmark.
|
|
199
214
|
*/ class BookmarkActionsView extends View {
|
|
200
215
|
/**
|
|
201
|
-
|
|
202
|
-
|
|
216
|
+
* Tracks information about DOM focus in the actions.
|
|
217
|
+
*/ focusTracker = new FocusTracker();
|
|
218
|
+
/**
|
|
219
|
+
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
220
|
+
*/ keystrokes = new KeystrokeHandler();
|
|
221
|
+
/**
|
|
222
|
+
* The bookmark preview view.
|
|
223
|
+
*/ bookmarkPreviewView;
|
|
224
|
+
/**
|
|
225
|
+
* The remove button view.
|
|
226
|
+
*/ removeButtonView;
|
|
227
|
+
/**
|
|
228
|
+
* The edit bookmark button view.
|
|
229
|
+
*/ editButtonView;
|
|
230
|
+
/**
|
|
231
|
+
* A collection of views that can be focused in the view.
|
|
232
|
+
*/ _focusables = new ViewCollection();
|
|
233
|
+
/**
|
|
234
|
+
* Helps cycling over {@link #_focusables} in the view.
|
|
235
|
+
*/ _focusCycler;
|
|
236
|
+
/**
|
|
237
|
+
* @inheritDoc
|
|
238
|
+
*/ constructor(locale){
|
|
203
239
|
super(locale);
|
|
204
|
-
/**
|
|
205
|
-
* Tracks information about DOM focus in the actions.
|
|
206
|
-
*/ this.focusTracker = new FocusTracker();
|
|
207
|
-
/**
|
|
208
|
-
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
209
|
-
*/ this.keystrokes = new KeystrokeHandler();
|
|
210
|
-
/**
|
|
211
|
-
* A collection of views that can be focused in the view.
|
|
212
|
-
*/ this._focusables = new ViewCollection();
|
|
213
240
|
const t = locale.t;
|
|
214
241
|
this.bookmarkPreviewView = this._createBookmarkPreviewView();
|
|
215
242
|
this.removeButtonView = this._createButton(t('Remove bookmark'), icons.remove, 'remove', this.bookmarkPreviewView);
|
|
@@ -245,8 +272,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
245
272
|
});
|
|
246
273
|
}
|
|
247
274
|
/**
|
|
248
|
-
|
|
249
|
-
|
|
275
|
+
* @inheritDoc
|
|
276
|
+
*/ render() {
|
|
250
277
|
super.render();
|
|
251
278
|
const childViews = [
|
|
252
279
|
this.editButtonView,
|
|
@@ -262,26 +289,26 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
262
289
|
this.keystrokes.listenTo(this.element);
|
|
263
290
|
}
|
|
264
291
|
/**
|
|
265
|
-
|
|
266
|
-
|
|
292
|
+
* @inheritDoc
|
|
293
|
+
*/ destroy() {
|
|
267
294
|
super.destroy();
|
|
268
295
|
this.focusTracker.destroy();
|
|
269
296
|
this.keystrokes.destroy();
|
|
270
297
|
}
|
|
271
298
|
/**
|
|
272
|
-
|
|
273
|
-
|
|
299
|
+
* Focuses the fist {@link #_focusables} in the actions.
|
|
300
|
+
*/ focus() {
|
|
274
301
|
this._focusCycler.focusFirst();
|
|
275
302
|
}
|
|
276
303
|
/**
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
304
|
+
* Creates a button view.
|
|
305
|
+
*
|
|
306
|
+
* @param label The button label.
|
|
307
|
+
* @param icon The button icon.
|
|
308
|
+
* @param eventName An event name that the `ButtonView#execute` event will be delegated to.
|
|
309
|
+
* @param additionalLabel An additional label outside the button.
|
|
310
|
+
* @returns The button view instance.
|
|
311
|
+
*/ _createButton(label, icon, eventName, additionalLabel) {
|
|
285
312
|
const button = new ButtonView(this.locale);
|
|
286
313
|
button.set({
|
|
287
314
|
label,
|
|
@@ -300,10 +327,10 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
300
327
|
return button;
|
|
301
328
|
}
|
|
302
329
|
/**
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
330
|
+
* Creates a bookmark name preview label.
|
|
331
|
+
*
|
|
332
|
+
* @returns The label view instance.
|
|
333
|
+
*/ _createBookmarkPreviewView() {
|
|
307
334
|
const label = new LabelView(this.locale);
|
|
308
335
|
label.extendTemplate({
|
|
309
336
|
attributes: {
|
|
@@ -354,32 +381,32 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
354
381
|
* ```
|
|
355
382
|
*/ class InsertBookmarkCommand extends Command {
|
|
356
383
|
/**
|
|
357
|
-
|
|
358
|
-
|
|
384
|
+
* @inheritDoc
|
|
385
|
+
*/ refresh() {
|
|
359
386
|
const model = this.editor.model;
|
|
360
387
|
const selection = model.document.selection;
|
|
361
388
|
const position = this._getPositionToInsertBookmark(selection);
|
|
362
389
|
this.isEnabled = !!position;
|
|
363
390
|
}
|
|
364
391
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
392
|
+
* Executes the command.
|
|
393
|
+
*
|
|
394
|
+
* @fires execute
|
|
395
|
+
* @param options Command options.
|
|
396
|
+
* @param options.bookmarkId The value of the `bookmarkId` attribute.
|
|
397
|
+
*/ execute(options) {
|
|
371
398
|
if (!options) {
|
|
372
399
|
return;
|
|
373
400
|
}
|
|
374
401
|
const { bookmarkId } = options;
|
|
375
402
|
if (!isBookmarkIdValid(bookmarkId)) {
|
|
376
403
|
/**
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
404
|
+
* Insert bookmark command can be executed only with a valid name.
|
|
405
|
+
*
|
|
406
|
+
* A valid bookmark name must be a non-empty string and must not contain any spaces.
|
|
407
|
+
*
|
|
408
|
+
* @error insert-bookmark-command-executed-with-invalid-name
|
|
409
|
+
*/ logWarning('insert-bookmark-command-executed-with-invalid-name');
|
|
383
410
|
return;
|
|
384
411
|
}
|
|
385
412
|
const editor = this.editor;
|
|
@@ -409,9 +436,9 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
409
436
|
});
|
|
410
437
|
}
|
|
411
438
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
439
|
+
* Returns the position where the bookmark can be inserted. And if it is not possible to insert a bookmark,
|
|
440
|
+
* check if it is possible to insert a paragraph.
|
|
441
|
+
*/ _getPositionToInsertBookmark(selection) {
|
|
415
442
|
const model = this.editor.model;
|
|
416
443
|
const schema = model.schema;
|
|
417
444
|
const firstRange = selection.getFirstRange();
|
|
@@ -456,8 +483,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
456
483
|
* ```
|
|
457
484
|
*/ class UpdateBookmarkCommand extends Command {
|
|
458
485
|
/**
|
|
459
|
-
|
|
460
|
-
|
|
486
|
+
* @inheritDoc
|
|
487
|
+
*/ refresh() {
|
|
461
488
|
const model = this.editor.model;
|
|
462
489
|
const selection = model.document.selection;
|
|
463
490
|
const selectedBookmark = getSelectedBookmark(selection);
|
|
@@ -465,24 +492,24 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
465
492
|
this.value = selectedBookmark ? selectedBookmark.getAttribute('bookmarkId') : undefined;
|
|
466
493
|
}
|
|
467
494
|
/**
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
495
|
+
* Executes the command.
|
|
496
|
+
*
|
|
497
|
+
* @fires execute
|
|
498
|
+
* @param options Command options.
|
|
499
|
+
* @param options.bookmarkId The new value of the `bookmarkId` attribute to set.
|
|
500
|
+
*/ execute(options) {
|
|
474
501
|
if (!options) {
|
|
475
502
|
return;
|
|
476
503
|
}
|
|
477
504
|
const { bookmarkId } = options;
|
|
478
505
|
if (!isBookmarkIdValid(bookmarkId)) {
|
|
479
506
|
/**
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
507
|
+
* Update bookmark command can be executed only with a valid name.
|
|
508
|
+
*
|
|
509
|
+
* A valid bookmark name must be a non-empty string and must not contain any spaces.
|
|
510
|
+
*
|
|
511
|
+
* @error update-bookmark-command-executed-with-invalid-name
|
|
512
|
+
*/ logWarning('update-bookmark-command-executed-with-invalid-name');
|
|
486
513
|
return;
|
|
487
514
|
}
|
|
488
515
|
const model = this.editor.model;
|
|
@@ -508,25 +535,22 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
508
535
|
/**
|
|
509
536
|
* The bookmark editing plugin.
|
|
510
537
|
*/ class BookmarkEditing extends Plugin {
|
|
511
|
-
constructor(){
|
|
512
|
-
super(...arguments);
|
|
513
|
-
/**
|
|
514
|
-
* A collection of bookmarks elements in the document.
|
|
515
|
-
*/ this._bookmarkElements = new Map();
|
|
516
|
-
}
|
|
517
538
|
/**
|
|
518
|
-
|
|
519
|
-
|
|
539
|
+
* A collection of bookmarks elements in the document.
|
|
540
|
+
*/ _bookmarkElements = new Map();
|
|
541
|
+
/**
|
|
542
|
+
* @inheritDoc
|
|
543
|
+
*/ static get pluginName() {
|
|
520
544
|
return 'BookmarkEditing';
|
|
521
545
|
}
|
|
522
546
|
/**
|
|
523
|
-
|
|
524
|
-
|
|
547
|
+
* @inheritDoc
|
|
548
|
+
*/ static get isOfficialPlugin() {
|
|
525
549
|
return true;
|
|
526
550
|
}
|
|
527
551
|
/**
|
|
528
|
-
|
|
529
|
-
|
|
552
|
+
* @inheritDoc
|
|
553
|
+
*/ init() {
|
|
530
554
|
const { editor } = this;
|
|
531
555
|
this._defineSchema();
|
|
532
556
|
this._defineConverters();
|
|
@@ -537,8 +561,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
537
561
|
});
|
|
538
562
|
}
|
|
539
563
|
/**
|
|
540
|
-
|
|
541
|
-
|
|
564
|
+
* Returns the model element for the given bookmark ID if it exists.
|
|
565
|
+
*/ getElementForBookmarkId(bookmarkId) {
|
|
542
566
|
for (const [element, id] of this._bookmarkElements){
|
|
543
567
|
if (id == bookmarkId) {
|
|
544
568
|
return element;
|
|
@@ -547,8 +571,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
547
571
|
return null;
|
|
548
572
|
}
|
|
549
573
|
/**
|
|
550
|
-
|
|
551
|
-
|
|
574
|
+
* Defines the schema for the bookmark feature.
|
|
575
|
+
*/ _defineSchema() {
|
|
552
576
|
const schema = this.editor.model.schema;
|
|
553
577
|
schema.register('bookmark', {
|
|
554
578
|
inheritAllFrom: '$inlineObject',
|
|
@@ -560,8 +584,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
560
584
|
});
|
|
561
585
|
}
|
|
562
586
|
/**
|
|
563
|
-
|
|
564
|
-
|
|
587
|
+
* Defines the converters for the bookmark feature.
|
|
588
|
+
*/ _defineConverters() {
|
|
565
589
|
const { editor } = this;
|
|
566
590
|
const { conversion, t } = editor;
|
|
567
591
|
editor.data.htmlProcessor.domConverter.registerInlineObjectMatcher((element)=>upcastMatcher(element));
|
|
@@ -609,8 +633,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
609
633
|
conversion.for('upcast').add((dispatcher)=>dispatcher.on('element:a', dataViewModelAnchorInsertion(editor)));
|
|
610
634
|
}
|
|
611
635
|
/**
|
|
612
|
-
|
|
613
|
-
|
|
636
|
+
* Creates a UI element for the `bookmark` representation in editing view.
|
|
637
|
+
*/ _createBookmarkUIElement(writer) {
|
|
614
638
|
return writer.createUIElement('span', {
|
|
615
639
|
class: 'ck-bookmark__icon'
|
|
616
640
|
}, function(domDocument) {
|
|
@@ -626,8 +650,8 @@ import { FocusTracker, KeystrokeHandler, logWarning } from '@ckeditor/ckeditor5-
|
|
|
626
650
|
});
|
|
627
651
|
}
|
|
628
652
|
/**
|
|
629
|
-
|
|
630
|
-
|
|
653
|
+
* Tracking the added or removed bookmark elements.
|
|
654
|
+
*/ _trackBookmarkElements() {
|
|
631
655
|
this._bookmarkElements.forEach((id, element)=>{
|
|
632
656
|
if (element.root.rootName === '$graveyard') {
|
|
633
657
|
this._bookmarkElements.delete(element);
|
|
@@ -727,36 +751,36 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
727
751
|
* It registers the `'bookmark'` UI button in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
|
728
752
|
* which inserts the `bookmark` element upon selection.
|
|
729
753
|
*/ class BookmarkUI extends Plugin {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
|
|
741
|
-
|
|
754
|
+
/**
|
|
755
|
+
* The actions view displayed inside of the balloon.
|
|
756
|
+
*/ actionsView = null;
|
|
757
|
+
/**
|
|
758
|
+
* The form view displayed inside the balloon.
|
|
759
|
+
*/ formView = null;
|
|
760
|
+
/**
|
|
761
|
+
* The contextual balloon plugin instance.
|
|
762
|
+
*/ _balloon;
|
|
763
|
+
/**
|
|
764
|
+
* @inheritDoc
|
|
765
|
+
*/ static get requires() {
|
|
742
766
|
return [
|
|
743
767
|
BookmarkEditing,
|
|
744
768
|
ContextualBalloon
|
|
745
769
|
];
|
|
746
770
|
}
|
|
747
771
|
/**
|
|
748
|
-
|
|
749
|
-
|
|
772
|
+
* @inheritDoc
|
|
773
|
+
*/ static get pluginName() {
|
|
750
774
|
return 'BookmarkUI';
|
|
751
775
|
}
|
|
752
776
|
/**
|
|
753
|
-
|
|
754
|
-
|
|
777
|
+
* @inheritDoc
|
|
778
|
+
*/ static get isOfficialPlugin() {
|
|
755
779
|
return true;
|
|
756
780
|
}
|
|
757
781
|
/**
|
|
758
|
-
|
|
759
|
-
|
|
782
|
+
* @inheritDoc
|
|
783
|
+
*/ init() {
|
|
760
784
|
const editor = this.editor;
|
|
761
785
|
editor.editing.view.addObserver(ClickObserver);
|
|
762
786
|
this._balloon = editor.plugins.get(ContextualBalloon);
|
|
@@ -789,8 +813,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
789
813
|
});
|
|
790
814
|
}
|
|
791
815
|
/**
|
|
792
|
-
|
|
793
|
-
|
|
816
|
+
* @inheritDoc
|
|
817
|
+
*/ destroy() {
|
|
794
818
|
super.destroy();
|
|
795
819
|
// Destroy created UI components as they are not automatically destroyed (see ckeditor5#1341).
|
|
796
820
|
if (this.formView) {
|
|
@@ -801,16 +825,16 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
801
825
|
}
|
|
802
826
|
}
|
|
803
827
|
/**
|
|
804
|
-
|
|
805
|
-
|
|
828
|
+
* Creates views.
|
|
829
|
+
*/ _createViews() {
|
|
806
830
|
this.actionsView = this._createActionsView();
|
|
807
831
|
this.formView = this._createFormView();
|
|
808
832
|
// Attach lifecycle actions to the the balloon.
|
|
809
833
|
this._enableUserBalloonInteractions();
|
|
810
834
|
}
|
|
811
835
|
/**
|
|
812
|
-
|
|
813
|
-
|
|
836
|
+
* Creates the {@link module:bookmark/ui/bookmarkactionsview~BookmarkActionsView} instance.
|
|
837
|
+
*/ _createActionsView() {
|
|
814
838
|
const editor = this.editor;
|
|
815
839
|
const actionsView = new BookmarkActionsView(editor.locale);
|
|
816
840
|
const updateBookmarkCommand = editor.commands.get('updateBookmark');
|
|
@@ -835,8 +859,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
835
859
|
return actionsView;
|
|
836
860
|
}
|
|
837
861
|
/**
|
|
838
|
-
|
|
839
|
-
|
|
862
|
+
* Creates the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} instance.
|
|
863
|
+
*/ _createFormView() {
|
|
840
864
|
const editor = this.editor;
|
|
841
865
|
const locale = editor.locale;
|
|
842
866
|
const insertBookmarkCommand = editor.commands.get('insertBookmark');
|
|
@@ -879,9 +903,9 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
879
903
|
return formView;
|
|
880
904
|
}
|
|
881
905
|
/**
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
906
|
+
* Creates a toolbar Bookmark button. Clicking this button will show
|
|
907
|
+
* a {@link #_balloon} attached to the selection.
|
|
908
|
+
*/ _createToolbarBookmarkButton() {
|
|
885
909
|
const editor = this.editor;
|
|
886
910
|
editor.ui.componentFactory.add('bookmark', ()=>{
|
|
887
911
|
const buttonView = this._createButton(ButtonView);
|
|
@@ -895,8 +919,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
895
919
|
});
|
|
896
920
|
}
|
|
897
921
|
/**
|
|
898
|
-
|
|
899
|
-
|
|
922
|
+
* Creates a button for `bookmark` command to use either in toolbar or in menu bar.
|
|
923
|
+
*/ _createButton(ButtonClass) {
|
|
900
924
|
const editor = this.editor;
|
|
901
925
|
const locale = editor.locale;
|
|
902
926
|
const view = new ButtonClass(locale);
|
|
@@ -917,9 +941,9 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
917
941
|
return view;
|
|
918
942
|
}
|
|
919
943
|
/**
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
944
|
+
* Attaches actions that control whether the balloon panel containing the
|
|
945
|
+
* {@link #formView} should be displayed.
|
|
946
|
+
*/ _enableBalloonActivators() {
|
|
923
947
|
const editor = this.editor;
|
|
924
948
|
const viewDocument = editor.editing.view.document;
|
|
925
949
|
// Handle click on view document and show panel when selection is placed inside the bookmark element.
|
|
@@ -933,9 +957,9 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
933
957
|
});
|
|
934
958
|
}
|
|
935
959
|
/**
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
960
|
+
* Attaches actions that control whether the balloon panel containing the
|
|
961
|
+
* {@link #formView} is visible or not.
|
|
962
|
+
*/ _enableUserBalloonInteractions() {
|
|
939
963
|
// Focus the form if the balloon is visible and the Tab key has been pressed.
|
|
940
964
|
this.editor.keystrokes.set('Tab', (data, cancel)=>{
|
|
941
965
|
if (this._areActionsVisible && !this.actionsView.focusTracker.isFocused) {
|
|
@@ -965,17 +989,17 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
965
989
|
});
|
|
966
990
|
}
|
|
967
991
|
/**
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
992
|
+
* Updates the button label. If bookmark is selected label is set to 'Update' otherwise
|
|
993
|
+
* it is 'Insert'.
|
|
994
|
+
*/ _updateFormButtonLabel(isBookmarkSelected) {
|
|
971
995
|
const t = this.editor.locale.t;
|
|
972
996
|
this.formView.buttonView.label = isBookmarkSelected ? t('Update') : t('Insert');
|
|
973
997
|
}
|
|
974
998
|
/**
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
999
|
+
* Adds the {@link #actionsView} to the {@link #_balloon}.
|
|
1000
|
+
*
|
|
1001
|
+
* @internal
|
|
1002
|
+
*/ _addActionsView() {
|
|
979
1003
|
if (!this.actionsView) {
|
|
980
1004
|
this._createViews();
|
|
981
1005
|
}
|
|
@@ -988,8 +1012,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
988
1012
|
});
|
|
989
1013
|
}
|
|
990
1014
|
/**
|
|
991
|
-
|
|
992
|
-
|
|
1015
|
+
* Adds the {@link #formView} to the {@link #_balloon}.
|
|
1016
|
+
*/ _addFormView() {
|
|
993
1017
|
if (!this.formView) {
|
|
994
1018
|
this._createViews();
|
|
995
1019
|
}
|
|
@@ -1012,8 +1036,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1012
1036
|
this.formView.enableCssTransitions();
|
|
1013
1037
|
}
|
|
1014
1038
|
/**
|
|
1015
|
-
|
|
1016
|
-
|
|
1039
|
+
* Closes the form view. Decides whether the balloon should be hidden completely.
|
|
1040
|
+
*/ _closeFormView() {
|
|
1017
1041
|
const updateBookmarkCommand = this.editor.commands.get('updateBookmark');
|
|
1018
1042
|
if (updateBookmarkCommand.value !== undefined) {
|
|
1019
1043
|
this._removeFormView();
|
|
@@ -1022,8 +1046,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1022
1046
|
}
|
|
1023
1047
|
}
|
|
1024
1048
|
/**
|
|
1025
|
-
|
|
1026
|
-
|
|
1049
|
+
* Removes the {@link #formView} from the {@link #_balloon}.
|
|
1050
|
+
*/ _removeFormView() {
|
|
1027
1051
|
if (this._isFormInPanel) {
|
|
1028
1052
|
// Blur the input element before removing it from DOM to prevent issues in some browsers.
|
|
1029
1053
|
// See https://github.com/ckeditor/ckeditor5/issues/1501.
|
|
@@ -1038,8 +1062,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1038
1062
|
}
|
|
1039
1063
|
}
|
|
1040
1064
|
/**
|
|
1041
|
-
|
|
1042
|
-
|
|
1065
|
+
* Shows the correct UI type. It is either {@link #formView} or {@link #actionsView}.
|
|
1066
|
+
*/ _showUI(forceVisible = false) {
|
|
1043
1067
|
if (!this.formView) {
|
|
1044
1068
|
this._createViews();
|
|
1045
1069
|
}
|
|
@@ -1069,10 +1093,10 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1069
1093
|
this._startUpdatingUI();
|
|
1070
1094
|
}
|
|
1071
1095
|
/**
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1096
|
+
* Removes the {@link #formView} from the {@link #_balloon}.
|
|
1097
|
+
*
|
|
1098
|
+
* See {@link #_addFormView}, {@link #_addActionsView}.
|
|
1099
|
+
*/ _hideUI() {
|
|
1076
1100
|
if (!this._isUIInPanel) {
|
|
1077
1101
|
return;
|
|
1078
1102
|
}
|
|
@@ -1089,11 +1113,11 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1089
1113
|
this._hideFakeVisualSelection();
|
|
1090
1114
|
}
|
|
1091
1115
|
/**
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1116
|
+
* Makes the UI react to the {@link module:ui/editorui/editorui~EditorUI#event:update} event to
|
|
1117
|
+
* reposition itself when the editor UI should be refreshed.
|
|
1118
|
+
*
|
|
1119
|
+
* See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
|
|
1120
|
+
*/ _startUpdatingUI() {
|
|
1097
1121
|
const editor = this.editor;
|
|
1098
1122
|
const viewDocument = editor.editing.view.document;
|
|
1099
1123
|
let prevSelectedBookmark = this._getSelectedBookmarkElement();
|
|
@@ -1129,37 +1153,37 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1129
1153
|
this.listenTo(this._balloon, 'change:visibleView', update);
|
|
1130
1154
|
}
|
|
1131
1155
|
/**
|
|
1132
|
-
|
|
1133
|
-
|
|
1156
|
+
* Returns `true` when {@link #formView} is in the {@link #_balloon}.
|
|
1157
|
+
*/ get _isFormInPanel() {
|
|
1134
1158
|
return !!this.formView && this._balloon.hasView(this.formView);
|
|
1135
1159
|
}
|
|
1136
1160
|
/**
|
|
1137
|
-
|
|
1138
|
-
|
|
1161
|
+
* Returns `true` when {@link #actionsView} is in the {@link #_balloon}.
|
|
1162
|
+
*/ get _areActionsInPanel() {
|
|
1139
1163
|
return !!this.actionsView && this._balloon.hasView(this.actionsView);
|
|
1140
1164
|
}
|
|
1141
1165
|
/**
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1166
|
+
* Returns `true` when {@link #actionsView} is in the {@link #_balloon} and it is
|
|
1167
|
+
* currently visible.
|
|
1168
|
+
*/ get _areActionsVisible() {
|
|
1145
1169
|
return !!this.actionsView && this._balloon.visibleView === this.actionsView;
|
|
1146
1170
|
}
|
|
1147
1171
|
/**
|
|
1148
|
-
|
|
1149
|
-
|
|
1172
|
+
* Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon}.
|
|
1173
|
+
*/ get _isUIInPanel() {
|
|
1150
1174
|
return this._isFormInPanel || this._areActionsInPanel;
|
|
1151
1175
|
}
|
|
1152
1176
|
/**
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1177
|
+
* Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon} and it is
|
|
1178
|
+
* currently visible.
|
|
1179
|
+
*/ get _isUIVisible() {
|
|
1156
1180
|
const visibleView = this._balloon.visibleView;
|
|
1157
1181
|
return !!this.formView && visibleView == this.formView || this._areActionsVisible;
|
|
1158
1182
|
}
|
|
1159
1183
|
/**
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1184
|
+
* Returns positioning options for the {@link #_balloon}. They control the way the balloon is attached
|
|
1185
|
+
* to the target element or selection.
|
|
1186
|
+
*/ _getBalloonPositionData() {
|
|
1163
1187
|
const view = this.editor.editing.view;
|
|
1164
1188
|
const model = this.editor.model;
|
|
1165
1189
|
let target;
|
|
@@ -1182,10 +1206,10 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1182
1206
|
};
|
|
1183
1207
|
}
|
|
1184
1208
|
/**
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1209
|
+
* Returns the bookmark {@link module:engine/view/attributeelement~AttributeElement} under
|
|
1210
|
+
* the {@link module:engine/view/document~Document editing view's} selection or `null`
|
|
1211
|
+
* if there is none.
|
|
1212
|
+
*/ _getSelectedBookmarkElement() {
|
|
1189
1213
|
const selection = this.editor.model.document.selection;
|
|
1190
1214
|
const element = selection.getSelectedElement();
|
|
1191
1215
|
if (element && element.is('element', 'bookmark')) {
|
|
@@ -1194,10 +1218,10 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1194
1218
|
return null;
|
|
1195
1219
|
}
|
|
1196
1220
|
/**
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1221
|
+
* Displays a fake visual selection when the contextual balloon is displayed.
|
|
1222
|
+
*
|
|
1223
|
+
* This adds a 'bookmark-ui' marker into the document that is rendered as a highlight on selected text fragment.
|
|
1224
|
+
*/ _showFakeVisualSelection() {
|
|
1201
1225
|
const model = this.editor.model;
|
|
1202
1226
|
model.change((writer)=>{
|
|
1203
1227
|
const range = model.document.selection.getFirstRange();
|
|
@@ -1226,8 +1250,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1226
1250
|
});
|
|
1227
1251
|
}
|
|
1228
1252
|
/**
|
|
1229
|
-
|
|
1230
|
-
|
|
1253
|
+
* Hides the fake visual selection created in {@link #_showFakeVisualSelection}.
|
|
1254
|
+
*/ _hideFakeVisualSelection() {
|
|
1231
1255
|
const model = this.editor.model;
|
|
1232
1256
|
if (model.markers.has(VISUAL_SELECTION_MARKER_NAME)) {
|
|
1233
1257
|
model.change((writer)=>{
|
|
@@ -1272,13 +1296,13 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1272
1296
|
* For a detailed overview, check the {@glink features/bookmarks Bookmarks} feature guide.
|
|
1273
1297
|
*/ class Bookmark extends Plugin {
|
|
1274
1298
|
/**
|
|
1275
|
-
|
|
1276
|
-
|
|
1299
|
+
* @inheritDoc
|
|
1300
|
+
*/ static get pluginName() {
|
|
1277
1301
|
return 'Bookmark';
|
|
1278
1302
|
}
|
|
1279
1303
|
/**
|
|
1280
|
-
|
|
1281
|
-
|
|
1304
|
+
* @inheritDoc
|
|
1305
|
+
*/ static get requires() {
|
|
1282
1306
|
return [
|
|
1283
1307
|
BookmarkEditing,
|
|
1284
1308
|
BookmarkUI,
|
|
@@ -1286,8 +1310,8 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
|
|
|
1286
1310
|
];
|
|
1287
1311
|
}
|
|
1288
1312
|
/**
|
|
1289
|
-
|
|
1290
|
-
|
|
1313
|
+
* @inheritDoc
|
|
1314
|
+
*/ static get isOfficialPlugin() {
|
|
1291
1315
|
return true;
|
|
1292
1316
|
}
|
|
1293
1317
|
}
|