@ckeditor/ckeditor5-bookmark 0.0.0-nightly-next-20260105.0 → 0.0.0-nightly-next-20260106.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/ckeditor5-metadata.json +1 -1
- package/{src → dist}/augmentation.d.ts +4 -0
- package/{src → dist}/bookmark.d.ts +6 -2
- package/{src → dist}/bookmarkconfig.d.ts +4 -0
- package/{src → dist}/bookmarkediting.d.ts +6 -2
- package/{src → dist}/bookmarkui.d.ts +7 -3
- package/{src → dist}/index.d.ts +4 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/{src → dist}/insertbookmarkcommand.d.ts +5 -1
- package/{src → dist}/ui/bookmarkformview.d.ts +6 -2
- package/{src → dist}/updatebookmarkcommand.d.ts +5 -1
- package/{src → dist}/utils.d.ts +4 -0
- package/package.json +25 -34
- package/build/bookmark.js +0 -5
- package/build/translations/af.js +0 -1
- package/build/translations/ar.js +0 -1
- package/build/translations/ast.js +0 -1
- package/build/translations/az.js +0 -1
- package/build/translations/be.js +0 -1
- package/build/translations/bg.js +0 -1
- package/build/translations/bn.js +0 -1
- package/build/translations/bs.js +0 -1
- package/build/translations/ca.js +0 -1
- package/build/translations/cs.js +0 -1
- package/build/translations/da.js +0 -1
- package/build/translations/de-ch.js +0 -1
- package/build/translations/de.js +0 -1
- package/build/translations/el.js +0 -1
- package/build/translations/en-au.js +0 -1
- package/build/translations/en-gb.js +0 -1
- package/build/translations/eo.js +0 -1
- package/build/translations/es-co.js +0 -1
- package/build/translations/es.js +0 -1
- package/build/translations/et.js +0 -1
- package/build/translations/eu.js +0 -1
- package/build/translations/fa.js +0 -1
- package/build/translations/fi.js +0 -1
- package/build/translations/fr.js +0 -1
- package/build/translations/gl.js +0 -1
- package/build/translations/gu.js +0 -1
- package/build/translations/he.js +0 -1
- package/build/translations/hi.js +0 -1
- package/build/translations/hr.js +0 -1
- package/build/translations/hu.js +0 -1
- package/build/translations/hy.js +0 -1
- package/build/translations/id.js +0 -1
- package/build/translations/it.js +0 -1
- package/build/translations/ja.js +0 -1
- package/build/translations/jv.js +0 -1
- package/build/translations/kk.js +0 -1
- package/build/translations/km.js +0 -1
- package/build/translations/kn.js +0 -1
- package/build/translations/ko.js +0 -1
- package/build/translations/ku.js +0 -1
- package/build/translations/lt.js +0 -1
- package/build/translations/lv.js +0 -1
- package/build/translations/ms.js +0 -1
- package/build/translations/nb.js +0 -1
- package/build/translations/ne.js +0 -1
- package/build/translations/nl.js +0 -1
- package/build/translations/no.js +0 -1
- package/build/translations/oc.js +0 -1
- package/build/translations/pl.js +0 -1
- package/build/translations/pt-br.js +0 -1
- package/build/translations/pt.js +0 -1
- package/build/translations/ro.js +0 -1
- package/build/translations/ru.js +0 -1
- package/build/translations/si.js +0 -1
- package/build/translations/sk.js +0 -1
- package/build/translations/sl.js +0 -1
- package/build/translations/sq.js +0 -1
- package/build/translations/sr-latn.js +0 -1
- package/build/translations/sr.js +0 -1
- package/build/translations/sv.js +0 -1
- package/build/translations/th.js +0 -1
- package/build/translations/ti.js +0 -1
- package/build/translations/tk.js +0 -1
- package/build/translations/tr.js +0 -1
- package/build/translations/tt.js +0 -1
- package/build/translations/ug.js +0 -1
- package/build/translations/uk.js +0 -1
- package/build/translations/ur.js +0 -1
- package/build/translations/uz.js +0 -1
- package/build/translations/vi.js +0 -1
- package/build/translations/zh-cn.js +0 -1
- package/build/translations/zh.js +0 -1
- package/src/augmentation.js +0 -5
- package/src/bookmark.js +0 -36
- package/src/bookmarkconfig.js +0 -5
- package/src/bookmarkediting.js +0 -238
- package/src/bookmarkui.js +0 -591
- package/src/index.js +0 -15
- package/src/insertbookmarkcommand.js +0 -113
- package/src/ui/bookmarkformview.js +0 -244
- package/src/updatebookmarkcommand.js +0 -75
- package/src/utils.js +0 -21
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
import { logWarning } from 'ckeditor5/src/utils.js';
|
|
6
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
7
|
-
import { isBookmarkIdValid } from './utils.js';
|
|
8
|
-
/**
|
|
9
|
-
* The insert bookmark command.
|
|
10
|
-
*
|
|
11
|
-
* The command is registered by {@link module:bookmark/bookmarkediting~BookmarkEditing} as `'insertBookmark'`.
|
|
12
|
-
*
|
|
13
|
-
* To insert a bookmark element at place where is the current collapsed selection or where is the beginning of document selection,
|
|
14
|
-
* execute the command passing the bookmark id as a parameter:
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* editor.execute( 'insertBookmark', { bookmarkId: 'foo_bar' } );
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class InsertBookmarkCommand extends Command {
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
refresh() {
|
|
25
|
-
const model = this.editor.model;
|
|
26
|
-
const selection = model.document.selection;
|
|
27
|
-
const position = this._getPositionToInsertBookmark(selection);
|
|
28
|
-
this.isEnabled = !!position;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Executes the command.
|
|
32
|
-
*
|
|
33
|
-
* @fires execute
|
|
34
|
-
* @param options Command options.
|
|
35
|
-
* @param options.bookmarkId The value of the `bookmarkId` attribute.
|
|
36
|
-
*/
|
|
37
|
-
execute(options) {
|
|
38
|
-
if (!options) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const { bookmarkId } = options;
|
|
42
|
-
if (!isBookmarkIdValid(bookmarkId)) {
|
|
43
|
-
/**
|
|
44
|
-
* Insert bookmark command can be executed only with a valid name.
|
|
45
|
-
*
|
|
46
|
-
* A valid bookmark name must be a non-empty string and must not contain any spaces.
|
|
47
|
-
*
|
|
48
|
-
* @error insert-bookmark-command-executed-with-invalid-name
|
|
49
|
-
*/
|
|
50
|
-
logWarning('insert-bookmark-command-executed-with-invalid-name');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const editor = this.editor;
|
|
54
|
-
const model = editor.model;
|
|
55
|
-
const selection = model.document.selection;
|
|
56
|
-
model.change(writer => {
|
|
57
|
-
let position = this._getPositionToInsertBookmark(selection);
|
|
58
|
-
const isBookmarkAllowed = model.schema.checkChild(position, 'bookmark');
|
|
59
|
-
// If the position does not allow for `bookmark` but allows for a `paragraph`
|
|
60
|
-
// then insert a `paragraph` then we will insert a `bookmark` inside.
|
|
61
|
-
if (!isBookmarkAllowed) {
|
|
62
|
-
const newPosition = editor.execute('insertParagraph', { position });
|
|
63
|
-
if (!newPosition) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
position = newPosition;
|
|
67
|
-
}
|
|
68
|
-
const bookmarkElement = writer.createElement('bookmark', {
|
|
69
|
-
...Object.fromEntries(selection.getAttributes()),
|
|
70
|
-
bookmarkId
|
|
71
|
-
});
|
|
72
|
-
model.insertObject(bookmarkElement, position, null, { setSelection: 'on' });
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Returns the position where the bookmark can be inserted. And if it is not possible to insert a bookmark,
|
|
77
|
-
* check if it is possible to insert a paragraph.
|
|
78
|
-
*/
|
|
79
|
-
_getPositionToInsertBookmark(selection) {
|
|
80
|
-
const model = this.editor.model;
|
|
81
|
-
const schema = model.schema;
|
|
82
|
-
const firstRange = selection.getFirstRange();
|
|
83
|
-
const startPosition = firstRange.start;
|
|
84
|
-
// Return position if it is allowed to insert bookmark or if it is allowed to insert paragraph.
|
|
85
|
-
if (isBookmarkAllowed(startPosition, schema)) {
|
|
86
|
-
return startPosition;
|
|
87
|
-
}
|
|
88
|
-
for (const { previousPosition, item } of firstRange) {
|
|
89
|
-
// When the table cell is selected (from the outside) we look for the first paragraph-like element inside.
|
|
90
|
-
if (item.is('element') &&
|
|
91
|
-
schema.checkChild(item, '$text') &&
|
|
92
|
-
isBookmarkAllowed(item, schema)) {
|
|
93
|
-
return model.createPositionAt(item, 0);
|
|
94
|
-
}
|
|
95
|
-
if (isBookmarkAllowed(previousPosition, schema)) {
|
|
96
|
-
return previousPosition;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Verify if the given position allows for bookmark insertion. Verify if auto-paragraphing could help.
|
|
104
|
-
*/
|
|
105
|
-
function isBookmarkAllowed(position, schema) {
|
|
106
|
-
if (schema.checkChild(position, 'bookmark')) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
if (!schema.checkChild(position, 'paragraph')) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
return schema.checkChild('paragraph', 'bookmark');
|
|
113
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module bookmark/ui/bookmarkformview
|
|
7
|
-
*/
|
|
8
|
-
import { ButtonView, FocusCycler, FormRowView, LabeledFieldView, View, ViewCollection, createLabeledInputText, submitHandler, FormHeaderView } from 'ckeditor5/src/ui.js';
|
|
9
|
-
import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils.js';
|
|
10
|
-
import { IconPreviousArrow } from '@ckeditor/ckeditor5-icons';
|
|
11
|
-
// See: #8833.
|
|
12
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
13
|
-
import '@ckeditor/ckeditor5-ui/theme/components/responsive-form/responsiveform.css';
|
|
14
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
15
|
-
import '@ckeditor/ckeditor5-ui/theme/components/form/form.css';
|
|
16
|
-
import '../../theme/bookmarkform.css';
|
|
17
|
-
/**
|
|
18
|
-
* The bookmark form view controller class.
|
|
19
|
-
*
|
|
20
|
-
* See {@link module:bookmark/ui/bookmarkformview~BookmarkFormView}.
|
|
21
|
-
*/
|
|
22
|
-
export class BookmarkFormView extends View {
|
|
23
|
-
/**
|
|
24
|
-
* Tracks information about DOM focus in the form.
|
|
25
|
-
*/
|
|
26
|
-
focusTracker = new FocusTracker();
|
|
27
|
-
/**
|
|
28
|
-
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
29
|
-
*/
|
|
30
|
-
keystrokes = new KeystrokeHandler();
|
|
31
|
-
/**
|
|
32
|
-
* The ID input view.
|
|
33
|
-
*/
|
|
34
|
-
idInputView;
|
|
35
|
-
/**
|
|
36
|
-
* The Back button view displayed in the header.
|
|
37
|
-
*/
|
|
38
|
-
backButtonView;
|
|
39
|
-
/**
|
|
40
|
-
* A button used to submit the form.
|
|
41
|
-
*/
|
|
42
|
-
saveButtonView;
|
|
43
|
-
/**
|
|
44
|
-
* A collection of form child views in the form.
|
|
45
|
-
*/
|
|
46
|
-
children;
|
|
47
|
-
/**
|
|
48
|
-
* An array of form validators used by {@link #isValid}.
|
|
49
|
-
*/
|
|
50
|
-
_validators;
|
|
51
|
-
/**
|
|
52
|
-
* A collection of views that can be focused in the form.
|
|
53
|
-
*/
|
|
54
|
-
_focusables = new ViewCollection();
|
|
55
|
-
/**
|
|
56
|
-
* Helps cycling over {@link #_focusables} in the form.
|
|
57
|
-
*/
|
|
58
|
-
_focusCycler;
|
|
59
|
-
/**
|
|
60
|
-
* Creates an instance of the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} class.
|
|
61
|
-
*
|
|
62
|
-
* Also see {@link #render}.
|
|
63
|
-
*
|
|
64
|
-
* @param locale The localization services instance.
|
|
65
|
-
* @param validators Form validators used by {@link #isValid}.
|
|
66
|
-
*/
|
|
67
|
-
constructor(locale, validators) {
|
|
68
|
-
super(locale);
|
|
69
|
-
this._validators = validators;
|
|
70
|
-
// Create buttons.
|
|
71
|
-
this.backButtonView = this._createBackButton();
|
|
72
|
-
this.saveButtonView = this._createSaveButton();
|
|
73
|
-
// Create input fields.
|
|
74
|
-
this.idInputView = this._createIdInput();
|
|
75
|
-
this.children = this.createCollection([this._createHeaderView()]);
|
|
76
|
-
this.children.add(new FormRowView(locale, {
|
|
77
|
-
children: [
|
|
78
|
-
this.idInputView,
|
|
79
|
-
this.saveButtonView
|
|
80
|
-
],
|
|
81
|
-
class: [
|
|
82
|
-
'ck-form__row_with-submit',
|
|
83
|
-
'ck-form__row_large-top-padding'
|
|
84
|
-
]
|
|
85
|
-
}));
|
|
86
|
-
// Close the panel on esc key press when the **form has focus**.
|
|
87
|
-
this.keystrokes.set('Esc', (data, cancel) => {
|
|
88
|
-
this.fire('cancel');
|
|
89
|
-
cancel();
|
|
90
|
-
});
|
|
91
|
-
this._focusCycler = new FocusCycler({
|
|
92
|
-
focusables: this._focusables,
|
|
93
|
-
focusTracker: this.focusTracker,
|
|
94
|
-
keystrokeHandler: this.keystrokes,
|
|
95
|
-
actions: {
|
|
96
|
-
// Navigate form fields backwards using the Shift + Tab keystroke.
|
|
97
|
-
focusPrevious: 'shift + tab',
|
|
98
|
-
// Navigate form fields forwards using the Tab key.
|
|
99
|
-
focusNext: 'tab'
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
this.setTemplate({
|
|
103
|
-
tag: 'form',
|
|
104
|
-
attributes: {
|
|
105
|
-
class: [
|
|
106
|
-
'ck',
|
|
107
|
-
'ck-form',
|
|
108
|
-
'ck-bookmark-form',
|
|
109
|
-
'ck-responsive-form'
|
|
110
|
-
],
|
|
111
|
-
// https://github.com/ckeditor/ckeditor5-link/issues/90
|
|
112
|
-
tabindex: '-1'
|
|
113
|
-
},
|
|
114
|
-
children: this.children
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @inheritDoc
|
|
119
|
-
*/
|
|
120
|
-
render() {
|
|
121
|
-
super.render();
|
|
122
|
-
submitHandler({
|
|
123
|
-
view: this
|
|
124
|
-
});
|
|
125
|
-
const childViews = [
|
|
126
|
-
this.backButtonView,
|
|
127
|
-
this.idInputView,
|
|
128
|
-
this.saveButtonView
|
|
129
|
-
];
|
|
130
|
-
childViews.forEach(v => {
|
|
131
|
-
// Register the view as focusable.
|
|
132
|
-
this._focusables.add(v);
|
|
133
|
-
// Register the view in the focus tracker.
|
|
134
|
-
this.focusTracker.add(v.element);
|
|
135
|
-
});
|
|
136
|
-
// Start listening for the keystrokes coming from #element.
|
|
137
|
-
this.keystrokes.listenTo(this.element);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* @inheritDoc
|
|
141
|
-
*/
|
|
142
|
-
destroy() {
|
|
143
|
-
super.destroy();
|
|
144
|
-
this.focusTracker.destroy();
|
|
145
|
-
this.keystrokes.destroy();
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Focuses the fist {@link #_focusables} in the form.
|
|
149
|
-
*/
|
|
150
|
-
focus() {
|
|
151
|
-
this.idInputView.focus();
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Validates the form and returns `false` when some fields are invalid.
|
|
155
|
-
*/
|
|
156
|
-
isValid() {
|
|
157
|
-
this.resetFormStatus();
|
|
158
|
-
for (const validator of this._validators) {
|
|
159
|
-
const errorText = validator(this);
|
|
160
|
-
// One error per field is enough.
|
|
161
|
-
if (errorText) {
|
|
162
|
-
// Apply updated error.
|
|
163
|
-
this.idInputView.errorText = errorText;
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Cleans up the supplementary error and information text of the {@link #idInputView}
|
|
171
|
-
* bringing them back to the state when the form has been displayed for the first time.
|
|
172
|
-
*
|
|
173
|
-
* See {@link #isValid}.
|
|
174
|
-
*/
|
|
175
|
-
resetFormStatus() {
|
|
176
|
-
this.idInputView.errorText = null;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Creates a back button view that cancels the form.
|
|
180
|
-
*/
|
|
181
|
-
_createBackButton() {
|
|
182
|
-
const t = this.locale.t;
|
|
183
|
-
const backButton = new ButtonView(this.locale);
|
|
184
|
-
backButton.set({
|
|
185
|
-
class: 'ck-button-back',
|
|
186
|
-
label: t('Back'),
|
|
187
|
-
icon: IconPreviousArrow,
|
|
188
|
-
tooltip: true
|
|
189
|
-
});
|
|
190
|
-
backButton.delegate('execute').to(this, 'cancel');
|
|
191
|
-
return backButton;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Creates a save button view that saves the bookmark.
|
|
195
|
-
*/
|
|
196
|
-
_createSaveButton() {
|
|
197
|
-
const t = this.locale.t;
|
|
198
|
-
const saveButton = new ButtonView(this.locale);
|
|
199
|
-
saveButton.set({
|
|
200
|
-
label: t('Save'),
|
|
201
|
-
withText: true,
|
|
202
|
-
type: 'submit',
|
|
203
|
-
class: 'ck-button-action ck-button-bold'
|
|
204
|
-
});
|
|
205
|
-
return saveButton;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Creates a header view for the form.
|
|
209
|
-
*/
|
|
210
|
-
_createHeaderView() {
|
|
211
|
-
const t = this.locale.t;
|
|
212
|
-
const header = new FormHeaderView(this.locale, {
|
|
213
|
-
label: t('Bookmark')
|
|
214
|
-
});
|
|
215
|
-
header.children.add(this.backButtonView, 0);
|
|
216
|
-
return header;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Creates a labeled input view.
|
|
220
|
-
*
|
|
221
|
-
* @returns Labeled field view instance.
|
|
222
|
-
*/
|
|
223
|
-
_createIdInput() {
|
|
224
|
-
const t = this.locale.t;
|
|
225
|
-
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
|
|
226
|
-
labeledInput.label = t('Bookmark name');
|
|
227
|
-
labeledInput.infoText = t('Enter the bookmark name without spaces.');
|
|
228
|
-
labeledInput.class = 'ck-labeled-field-view_full-width';
|
|
229
|
-
return labeledInput;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* The native DOM `value` of the {@link #idInputView} element.
|
|
233
|
-
*
|
|
234
|
-
* **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
|
|
235
|
-
* which works one way only and may not represent the actual state of the component in the DOM.
|
|
236
|
-
*/
|
|
237
|
-
get id() {
|
|
238
|
-
const { element } = this.idInputView.fieldView;
|
|
239
|
-
if (!element) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
return element.value.trim();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module bookmark/updatebookmarkcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from 'ckeditor5/src/core.js';
|
|
9
|
-
import { logWarning } from 'ckeditor5/src/utils.js';
|
|
10
|
-
import { isBookmarkIdValid } from './utils.js';
|
|
11
|
-
/**
|
|
12
|
-
* The update bookmark command.
|
|
13
|
-
*
|
|
14
|
-
* The command is registered by {@link module:bookmark/bookmarkediting~BookmarkEditing} as `'updateBookmark'`.
|
|
15
|
-
*
|
|
16
|
-
* To update the `bookmarkId` of current selected bookmark element, execute the command passing the bookmark id as a parameter:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* editor.execute( 'updateBookmark', { bookmarkId: 'newId' } );
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export class UpdateBookmarkCommand extends Command {
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
refresh() {
|
|
27
|
-
const model = this.editor.model;
|
|
28
|
-
const selection = model.document.selection;
|
|
29
|
-
const selectedBookmark = getSelectedBookmark(selection);
|
|
30
|
-
this.isEnabled = !!selectedBookmark;
|
|
31
|
-
this.value = selectedBookmark ? selectedBookmark.getAttribute('bookmarkId') : undefined;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Executes the command.
|
|
35
|
-
*
|
|
36
|
-
* @fires execute
|
|
37
|
-
* @param options Command options.
|
|
38
|
-
* @param options.bookmarkId The new value of the `bookmarkId` attribute to set.
|
|
39
|
-
*/
|
|
40
|
-
execute(options) {
|
|
41
|
-
if (!options) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const { bookmarkId } = options;
|
|
45
|
-
if (!isBookmarkIdValid(bookmarkId)) {
|
|
46
|
-
/**
|
|
47
|
-
* Update bookmark command can be executed only with a valid name.
|
|
48
|
-
*
|
|
49
|
-
* A valid bookmark name must be a non-empty string and must not contain any spaces.
|
|
50
|
-
*
|
|
51
|
-
* @error update-bookmark-command-executed-with-invalid-name
|
|
52
|
-
*/
|
|
53
|
-
logWarning('update-bookmark-command-executed-with-invalid-name');
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const model = this.editor.model;
|
|
57
|
-
const selection = model.document.selection;
|
|
58
|
-
const selectedBookmark = getSelectedBookmark(selection);
|
|
59
|
-
if (selectedBookmark) {
|
|
60
|
-
model.change(writer => {
|
|
61
|
-
writer.setAttribute('bookmarkId', bookmarkId, selectedBookmark);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns the selected `bookmark` element in the model, if any.
|
|
68
|
-
*/
|
|
69
|
-
function getSelectedBookmark(selection) {
|
|
70
|
-
const element = selection.getSelectedElement();
|
|
71
|
-
if (!!element && element.is('element', 'bookmark')) {
|
|
72
|
-
return element;
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
package/src/utils.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module bookmark/utils
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns `true` if the bookmark id is valid; otherwise, returns `false`.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export function isBookmarkIdValid(id) {
|
|
14
|
-
if (!id || typeof id !== 'string') {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (/\s/.test(id)) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|