@ckeditor/ckeditor5-bookmark 0.0.1 → 44.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +4 -5
- package/README.md +31 -3
- package/build/bookmark.js +5 -0
- package/build/translations/af.js +1 -0
- package/build/translations/ar.js +1 -0
- package/build/translations/ast.js +1 -0
- package/build/translations/az.js +1 -0
- package/build/translations/bg.js +1 -0
- package/build/translations/bn.js +1 -0
- package/build/translations/bs.js +1 -0
- package/build/translations/ca.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.js +1 -0
- package/build/translations/de-ch.js +1 -0
- package/build/translations/de.js +1 -0
- package/build/translations/el.js +1 -0
- package/build/translations/en-au.js +1 -0
- package/build/translations/en-gb.js +1 -0
- package/build/translations/eo.js +1 -0
- package/build/translations/es-co.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.js +1 -0
- package/build/translations/eu.js +1 -0
- package/build/translations/fa.js +1 -0
- package/build/translations/fi.js +1 -0
- package/build/translations/fr.js +1 -0
- package/build/translations/gl.js +1 -0
- package/build/translations/gu.js +1 -0
- package/build/translations/he.js +1 -0
- package/build/translations/hi.js +1 -0
- package/build/translations/hr.js +1 -0
- package/build/translations/hu.js +1 -0
- package/build/translations/hy.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/jv.js +1 -0
- package/build/translations/kk.js +1 -0
- package/build/translations/km.js +1 -0
- package/build/translations/kn.js +1 -0
- package/build/translations/ko.js +1 -0
- package/build/translations/ku.js +1 -0
- package/build/translations/lt.js +1 -0
- package/build/translations/lv.js +1 -0
- package/build/translations/ms.js +1 -0
- package/build/translations/nb.js +1 -0
- package/build/translations/ne.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/no.js +1 -0
- package/build/translations/oc.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/pt.js +1 -0
- package/build/translations/ro.js +1 -0
- package/build/translations/ru.js +1 -0
- package/build/translations/si.js +1 -0
- package/build/translations/sk.js +1 -0
- package/build/translations/sl.js +1 -0
- package/build/translations/sq.js +1 -0
- package/build/translations/sr-latn.js +1 -0
- package/build/translations/sr.js +1 -0
- package/build/translations/sv.js +1 -0
- package/build/translations/th.js +1 -0
- package/build/translations/ti.js +1 -0
- package/build/translations/tk.js +1 -0
- package/build/translations/tr.js +1 -0
- package/build/translations/tt.js +1 -0
- package/build/translations/ug.js +1 -0
- package/build/translations/uk.js +1 -0
- package/build/translations/ur.js +1 -0
- package/build/translations/uz.js +1 -0
- package/build/translations/vi.js +1 -0
- package/build/translations/zh-cn.js +1 -0
- package/build/translations/zh.js +1 -0
- package/ckeditor5-metadata.json +24 -0
- package/dist/augmentation.d.ts +28 -0
- package/dist/bookmark.d.ts +34 -0
- package/dist/bookmarkconfig.d.ts +52 -0
- package/dist/bookmarkediting.d.ts +55 -0
- package/dist/bookmarkui.d.ts +170 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +150 -0
- package/dist/index.css +195 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1320 -0
- package/dist/index.js.map +1 -0
- package/dist/insertbookmarkcommand.d.ts +42 -0
- package/dist/translations/af.d.ts +8 -0
- package/dist/translations/af.js +5 -0
- package/dist/translations/af.umd.js +11 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/ar.umd.js +11 -0
- package/dist/translations/ast.d.ts +8 -0
- package/dist/translations/ast.js +5 -0
- package/dist/translations/ast.umd.js +11 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/az.umd.js +11 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bg.umd.js +11 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/bn.umd.js +11 -0
- package/dist/translations/bs.d.ts +8 -0
- package/dist/translations/bs.js +5 -0
- package/dist/translations/bs.umd.js +11 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/ca.umd.js +11 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/cs.umd.js +11 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/da.umd.js +11 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de-ch.umd.js +11 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/de.umd.js +11 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/el.umd.js +11 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-au.umd.js +11 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en-gb.umd.js +11 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/en.umd.js +11 -0
- package/dist/translations/eo.d.ts +8 -0
- package/dist/translations/eo.js +5 -0
- package/dist/translations/eo.umd.js +11 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es-co.umd.js +11 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/es.umd.js +11 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/et.umd.js +11 -0
- package/dist/translations/eu.d.ts +8 -0
- package/dist/translations/eu.js +5 -0
- package/dist/translations/eu.umd.js +11 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fa.umd.js +11 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fi.umd.js +11 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/fr.umd.js +11 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/gl.umd.js +11 -0
- package/dist/translations/gu.d.ts +8 -0
- package/dist/translations/gu.js +5 -0
- package/dist/translations/gu.umd.js +11 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/he.umd.js +11 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hi.umd.js +11 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hr.umd.js +11 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hu.umd.js +11 -0
- package/dist/translations/hy.d.ts +8 -0
- package/dist/translations/hy.js +5 -0
- package/dist/translations/hy.umd.js +11 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/id.umd.js +11 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/it.umd.js +11 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ja.umd.js +11 -0
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/jv.umd.js +11 -0
- package/dist/translations/kk.d.ts +8 -0
- package/dist/translations/kk.js +5 -0
- package/dist/translations/kk.umd.js +11 -0
- package/dist/translations/km.d.ts +8 -0
- package/dist/translations/km.js +5 -0
- package/dist/translations/km.umd.js +11 -0
- package/dist/translations/kn.d.ts +8 -0
- package/dist/translations/kn.js +5 -0
- package/dist/translations/kn.umd.js +11 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ko.umd.js +11 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/ku.umd.js +11 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lt.umd.js +11 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/lv.umd.js +11 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/ms.umd.js +11 -0
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/nb.umd.js +11 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/ne.umd.js +11 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/nl.umd.js +11 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/no.umd.js +11 -0
- package/dist/translations/oc.d.ts +8 -0
- package/dist/translations/oc.js +5 -0
- package/dist/translations/oc.umd.js +11 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pl.umd.js +11 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt-br.umd.js +11 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/pt.umd.js +11 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ro.umd.js +11 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/ru.umd.js +11 -0
- package/dist/translations/si.d.ts +8 -0
- package/dist/translations/si.js +5 -0
- package/dist/translations/si.umd.js +11 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sk.umd.js +11 -0
- package/dist/translations/sl.d.ts +8 -0
- package/dist/translations/sl.js +5 -0
- package/dist/translations/sl.umd.js +11 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sq.umd.js +11 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr-latn.umd.js +11 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sr.umd.js +11 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/sv.umd.js +11 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/th.umd.js +11 -0
- package/dist/translations/ti.d.ts +8 -0
- package/dist/translations/ti.js +5 -0
- package/dist/translations/ti.umd.js +11 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tk.umd.js +11 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tr.umd.js +11 -0
- package/dist/translations/tt.d.ts +8 -0
- package/dist/translations/tt.js +5 -0
- package/dist/translations/tt.umd.js +11 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/ug.umd.js +11 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/uk.umd.js +11 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/ur.umd.js +11 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/uz.umd.js +11 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/vi.umd.js +11 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh-cn.umd.js +11 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/translations/zh.umd.js +11 -0
- package/dist/ui/bookmarkactionsview.d.ts +106 -0
- package/dist/ui/bookmarkformview.d.ts +122 -0
- package/dist/updatebookmarkcommand.d.ts +46 -0
- package/dist/utils.d.ts +15 -0
- package/lang/contexts.json +13 -0
- package/lang/translations/af.po +56 -0
- package/lang/translations/ar.po +56 -0
- package/lang/translations/ast.po +56 -0
- package/lang/translations/az.po +56 -0
- package/lang/translations/bg.po +56 -0
- package/lang/translations/bn.po +56 -0
- package/lang/translations/bs.po +56 -0
- package/lang/translations/ca.po +56 -0
- package/lang/translations/cs.po +56 -0
- package/lang/translations/da.po +56 -0
- package/lang/translations/de-ch.po +56 -0
- package/lang/translations/de.po +56 -0
- package/lang/translations/el.po +56 -0
- package/lang/translations/en-au.po +56 -0
- package/lang/translations/en-gb.po +56 -0
- package/lang/translations/en.po +56 -0
- package/lang/translations/eo.po +56 -0
- package/lang/translations/es-co.po +56 -0
- package/lang/translations/es.po +56 -0
- package/lang/translations/et.po +56 -0
- package/lang/translations/eu.po +56 -0
- package/lang/translations/fa.po +56 -0
- package/lang/translations/fi.po +56 -0
- package/lang/translations/fr.po +56 -0
- package/lang/translations/gl.po +56 -0
- package/lang/translations/gu.po +56 -0
- package/lang/translations/he.po +56 -0
- package/lang/translations/hi.po +56 -0
- package/lang/translations/hr.po +56 -0
- package/lang/translations/hu.po +56 -0
- package/lang/translations/hy.po +56 -0
- package/lang/translations/id.po +56 -0
- package/lang/translations/it.po +56 -0
- package/lang/translations/ja.po +56 -0
- package/lang/translations/jv.po +56 -0
- package/lang/translations/kk.po +56 -0
- package/lang/translations/km.po +56 -0
- package/lang/translations/kn.po +56 -0
- package/lang/translations/ko.po +56 -0
- package/lang/translations/ku.po +56 -0
- package/lang/translations/lt.po +56 -0
- package/lang/translations/lv.po +56 -0
- package/lang/translations/ms.po +56 -0
- package/lang/translations/nb.po +56 -0
- package/lang/translations/ne.po +56 -0
- package/lang/translations/nl.po +56 -0
- package/lang/translations/no.po +56 -0
- package/lang/translations/oc.po +56 -0
- package/lang/translations/pl.po +56 -0
- package/lang/translations/pt-br.po +56 -0
- package/lang/translations/pt.po +56 -0
- package/lang/translations/ro.po +56 -0
- package/lang/translations/ru.po +56 -0
- package/lang/translations/si.po +56 -0
- package/lang/translations/sk.po +56 -0
- package/lang/translations/sl.po +56 -0
- package/lang/translations/sq.po +56 -0
- package/lang/translations/sr-latn.po +56 -0
- package/lang/translations/sr.po +56 -0
- package/lang/translations/sv.po +56 -0
- package/lang/translations/th.po +56 -0
- package/lang/translations/ti.po +56 -0
- package/lang/translations/tk.po +56 -0
- package/lang/translations/tr.po +56 -0
- package/lang/translations/tt.po +56 -0
- package/lang/translations/ug.po +56 -0
- package/lang/translations/uk.po +56 -0
- package/lang/translations/ur.po +56 -0
- package/lang/translations/uz.po +56 -0
- package/lang/translations/vi.po +56 -0
- package/lang/translations/zh-cn.po +56 -0
- package/lang/translations/zh.po +56 -0
- package/package.json +32 -3
- package/src/augmentation.d.ts +24 -0
- package/src/augmentation.js +5 -0
- package/src/bookmark.d.ts +30 -0
- package/src/bookmark.js +36 -0
- package/src/bookmarkconfig.d.ts +48 -0
- package/src/bookmarkconfig.js +5 -0
- package/src/bookmarkediting.d.ts +51 -0
- package/src/bookmarkediting.js +211 -0
- package/src/bookmarkui.d.ts +166 -0
- package/src/bookmarkui.js +582 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +13 -0
- package/src/insertbookmarkcommand.d.ts +38 -0
- package/src/insertbookmarkcommand.js +113 -0
- package/src/ui/bookmarkactionsview.d.ts +102 -0
- package/src/ui/bookmarkactionsview.js +154 -0
- package/src/ui/bookmarkformview.d.ts +118 -0
- package/src/ui/bookmarkformview.js +203 -0
- package/src/updatebookmarkcommand.d.ts +42 -0
- package/src/updatebookmarkcommand.js +75 -0
- package/src/utils.d.ts +11 -0
- package/src/utils.js +19 -0
- package/theme/bookmark.css +50 -0
- package/theme/bookmarkactions.css +44 -0
- package/theme/bookmarkform.css +42 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module bookmark/bookmarkediting
|
7
|
+
*/
|
8
|
+
import { Plugin, icons } from 'ckeditor5/src/core.js';
|
9
|
+
import { toWidget } from 'ckeditor5/src/widget.js';
|
10
|
+
import { IconView } from 'ckeditor5/src/ui.js';
|
11
|
+
import InsertBookmarkCommand from './insertbookmarkcommand.js';
|
12
|
+
import UpdateBookmarkCommand from './updatebookmarkcommand.js';
|
13
|
+
import '../theme/bookmark.css';
|
14
|
+
/**
|
15
|
+
* The bookmark editing plugin.
|
16
|
+
*/
|
17
|
+
export default class BookmarkEditing extends Plugin {
|
18
|
+
constructor() {
|
19
|
+
super(...arguments);
|
20
|
+
/**
|
21
|
+
* A collection of bookmarks elements in the document.
|
22
|
+
*/
|
23
|
+
this._bookmarkElements = new Map();
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* @inheritDoc
|
27
|
+
*/
|
28
|
+
static get pluginName() {
|
29
|
+
return 'BookmarkEditing';
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* @inheritDoc
|
33
|
+
*/
|
34
|
+
static get isOfficialPlugin() {
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* @inheritDoc
|
39
|
+
*/
|
40
|
+
init() {
|
41
|
+
const { editor } = this;
|
42
|
+
this._defineSchema();
|
43
|
+
this._defineConverters();
|
44
|
+
editor.commands.add('insertBookmark', new InsertBookmarkCommand(editor));
|
45
|
+
editor.commands.add('updateBookmark', new UpdateBookmarkCommand(editor));
|
46
|
+
this.listenTo(editor.model.document, 'change:data', () => {
|
47
|
+
this._trackBookmarkElements();
|
48
|
+
});
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* Returns the model element for the given bookmark ID if it exists.
|
52
|
+
*/
|
53
|
+
getElementForBookmarkId(bookmarkId) {
|
54
|
+
for (const [element, id] of this._bookmarkElements) {
|
55
|
+
if (id == bookmarkId) {
|
56
|
+
return element;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return null;
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* Defines the schema for the bookmark feature.
|
63
|
+
*/
|
64
|
+
_defineSchema() {
|
65
|
+
const schema = this.editor.model.schema;
|
66
|
+
schema.register('bookmark', {
|
67
|
+
inheritAllFrom: '$inlineObject',
|
68
|
+
allowAttributes: 'bookmarkId',
|
69
|
+
disallowAttributes: ['linkHref', 'htmlA']
|
70
|
+
});
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Defines the converters for the bookmark feature.
|
74
|
+
*/
|
75
|
+
_defineConverters() {
|
76
|
+
const { editor } = this;
|
77
|
+
const { conversion, t } = editor;
|
78
|
+
editor.data.htmlProcessor.domConverter.registerInlineObjectMatcher(element => upcastMatcher(element));
|
79
|
+
// Register an inline object matcher so that bookmarks <a>s are correctly recognized as inline elements in editing pipeline.
|
80
|
+
// This prevents converting spaces around bookmarks to ` `s.
|
81
|
+
editor.editing.view.domConverter.registerInlineObjectMatcher(element => upcastMatcher(element, false));
|
82
|
+
conversion.for('dataDowncast').elementToElement({
|
83
|
+
model: {
|
84
|
+
name: 'bookmark',
|
85
|
+
attributes: ['bookmarkId']
|
86
|
+
},
|
87
|
+
view: (modelElement, { writer }) => {
|
88
|
+
const emptyElement = writer.createEmptyElement('a', {
|
89
|
+
'id': modelElement.getAttribute('bookmarkId')
|
90
|
+
});
|
91
|
+
// `getFillerOffset` is not needed to set here, because `emptyElement` has already covered it.
|
92
|
+
return emptyElement;
|
93
|
+
}
|
94
|
+
});
|
95
|
+
conversion.for('editingDowncast').elementToElement({
|
96
|
+
model: {
|
97
|
+
name: 'bookmark',
|
98
|
+
attributes: ['bookmarkId']
|
99
|
+
},
|
100
|
+
view: (modelElement, { writer }) => {
|
101
|
+
const id = modelElement.getAttribute('bookmarkId');
|
102
|
+
const containerElement = writer.createContainerElement('a', {
|
103
|
+
id,
|
104
|
+
class: 'ck-bookmark'
|
105
|
+
}, [this._createBookmarkUIElement(writer)]);
|
106
|
+
this._bookmarkElements.set(modelElement, id);
|
107
|
+
// `getFillerOffset` is not needed to set here, because `toWidget` has already covered it.
|
108
|
+
const labelCreator = () => `${id} ${t('bookmark widget')}`;
|
109
|
+
return toWidget(containerElement, writer, { label: labelCreator });
|
110
|
+
}
|
111
|
+
});
|
112
|
+
conversion.for('upcast').add(dispatcher => dispatcher.on('element:a', dataViewModelAnchorInsertion(editor)));
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* Creates a UI element for the `bookmark` representation in editing view.
|
116
|
+
*/
|
117
|
+
_createBookmarkUIElement(writer) {
|
118
|
+
return writer.createUIElement('span', { class: 'ck-bookmark__icon' }, function (domDocument) {
|
119
|
+
const domElement = this.toDomElement(domDocument);
|
120
|
+
const icon = new IconView();
|
121
|
+
icon.set({
|
122
|
+
content: icons.bookmarkInline,
|
123
|
+
isColorInherited: false
|
124
|
+
});
|
125
|
+
icon.render();
|
126
|
+
domElement.appendChild(icon.element);
|
127
|
+
return domElement;
|
128
|
+
});
|
129
|
+
}
|
130
|
+
/**
|
131
|
+
* Tracking the added or removed bookmark elements.
|
132
|
+
*/
|
133
|
+
_trackBookmarkElements() {
|
134
|
+
this._bookmarkElements.forEach((id, element) => {
|
135
|
+
if (element.root.rootName === '$graveyard') {
|
136
|
+
this._bookmarkElements.delete(element);
|
137
|
+
}
|
138
|
+
});
|
139
|
+
}
|
140
|
+
}
|
141
|
+
/**
|
142
|
+
* A helper function to match an `anchor` element which must contain `id` or `name` attribute but without `href` attribute,
|
143
|
+
* also when `expectEmpty` is set to `true` but the element is not empty matcher should not match any element.
|
144
|
+
*
|
145
|
+
* @param element The element to be checked.
|
146
|
+
* @param expectEmpty Default set to `true`, when set to `false` matcher expects that `anchor` is not empty;
|
147
|
+
* in editing pipeline it's not empty because it contains the `UIElement`.
|
148
|
+
*/
|
149
|
+
function upcastMatcher(element, expectEmpty = true) {
|
150
|
+
const isAnchorElement = element.name === 'a';
|
151
|
+
if (!isAnchorElement) {
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
if (expectEmpty && !element.isEmpty) {
|
155
|
+
return null;
|
156
|
+
}
|
157
|
+
const hasIdAttribute = element.hasAttribute('id');
|
158
|
+
const hasNameAttribute = element.hasAttribute('name');
|
159
|
+
const hasHrefAttribute = element.hasAttribute('href');
|
160
|
+
if (hasIdAttribute && !hasHrefAttribute) {
|
161
|
+
return { name: true, attributes: ['id'] };
|
162
|
+
}
|
163
|
+
if (hasNameAttribute && !hasHrefAttribute) {
|
164
|
+
return { name: true, attributes: ['name'] };
|
165
|
+
}
|
166
|
+
return null;
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* A view-to-model converter that handles converting pointed or wrapped anchors with `id` and/or `name` attributes.
|
170
|
+
*
|
171
|
+
* @returns Returns a conversion callback.
|
172
|
+
*/
|
173
|
+
function dataViewModelAnchorInsertion(editor) {
|
174
|
+
return (evt, data, conversionApi) => {
|
175
|
+
const viewItem = data.viewItem;
|
176
|
+
const match = upcastMatcher(viewItem, false);
|
177
|
+
if (!match || !conversionApi.consumable.test(viewItem, match)) {
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
const enableNonEmptyAnchorConversion = isEnabledNonEmptyAnchorConversion(editor);
|
181
|
+
if (!enableNonEmptyAnchorConversion && !viewItem.isEmpty) {
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
const modelWriter = conversionApi.writer;
|
185
|
+
const anchorId = viewItem.getAttribute('id');
|
186
|
+
const anchorName = viewItem.getAttribute('name');
|
187
|
+
const bookmarkId = anchorId || anchorName;
|
188
|
+
const bookmark = modelWriter.createElement('bookmark', { bookmarkId });
|
189
|
+
if (!conversionApi.safeInsert(bookmark, data.modelCursor)) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
conversionApi.consumable.consume(viewItem, match);
|
193
|
+
if (anchorId === anchorName) {
|
194
|
+
conversionApi.consumable.consume(viewItem, { attributes: ['name'] });
|
195
|
+
}
|
196
|
+
conversionApi.updateConversionResult(bookmark, data);
|
197
|
+
// Convert children uses the result of `bookmark` insertion to convert the `anchor` content
|
198
|
+
// after the bookmark element (not inside it).
|
199
|
+
const { modelCursor, modelRange } = conversionApi.convertChildren(viewItem, data.modelCursor);
|
200
|
+
data.modelCursor = modelCursor;
|
201
|
+
data.modelRange = modelWriter.createRange(data.modelRange.start, modelRange.end);
|
202
|
+
};
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* Normalize the bookmark configuration option `enableNonEmptyAnchorConversion`.
|
206
|
+
*/
|
207
|
+
function isEnabledNonEmptyAnchorConversion(editor) {
|
208
|
+
const enableNonEmptyAnchorConversion = editor.config.get('bookmark.enableNonEmptyAnchorConversion');
|
209
|
+
// When not defined, option `enableNonEmptyAnchorConversion` by default is set to `true`.
|
210
|
+
return enableNonEmptyAnchorConversion !== undefined ? enableNonEmptyAnchorConversion : true;
|
211
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module bookmark/bookmarkui
|
7
|
+
*/
|
8
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
9
|
+
import { ContextualBalloon, type ViewWithCssTransitionDisabler } from 'ckeditor5/src/ui.js';
|
10
|
+
import BookmarkFormView from './ui/bookmarkformview.js';
|
11
|
+
import BookmarkActionsView from './ui/bookmarkactionsview.js';
|
12
|
+
import BookmarkEditing from './bookmarkediting.js';
|
13
|
+
/**
|
14
|
+
* The UI plugin of the bookmark feature.
|
15
|
+
*
|
16
|
+
* It registers the `'bookmark'` UI button in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
|
17
|
+
* which inserts the `bookmark` element upon selection.
|
18
|
+
*/
|
19
|
+
export default class BookmarkUI extends Plugin {
|
20
|
+
/**
|
21
|
+
* The actions view displayed inside of the balloon.
|
22
|
+
*/
|
23
|
+
actionsView: BookmarkActionsView | null;
|
24
|
+
/**
|
25
|
+
* The form view displayed inside the balloon.
|
26
|
+
*/
|
27
|
+
formView: BookmarkFormView & ViewWithCssTransitionDisabler | null;
|
28
|
+
/**
|
29
|
+
* The contextual balloon plugin instance.
|
30
|
+
*/
|
31
|
+
private _balloon;
|
32
|
+
/**
|
33
|
+
* @inheritDoc
|
34
|
+
*/
|
35
|
+
static get requires(): readonly [typeof BookmarkEditing, typeof ContextualBalloon];
|
36
|
+
/**
|
37
|
+
* @inheritDoc
|
38
|
+
*/
|
39
|
+
static get pluginName(): "BookmarkUI";
|
40
|
+
/**
|
41
|
+
* @inheritDoc
|
42
|
+
*/
|
43
|
+
static get isOfficialPlugin(): true;
|
44
|
+
/**
|
45
|
+
* @inheritDoc
|
46
|
+
*/
|
47
|
+
init(): void;
|
48
|
+
/**
|
49
|
+
* @inheritDoc
|
50
|
+
*/
|
51
|
+
destroy(): void;
|
52
|
+
/**
|
53
|
+
* Creates views.
|
54
|
+
*/
|
55
|
+
private _createViews;
|
56
|
+
/**
|
57
|
+
* Creates the {@link module:bookmark/ui/bookmarkactionsview~BookmarkActionsView} instance.
|
58
|
+
*/
|
59
|
+
private _createActionsView;
|
60
|
+
/**
|
61
|
+
* Creates the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} instance.
|
62
|
+
*/
|
63
|
+
private _createFormView;
|
64
|
+
/**
|
65
|
+
* Creates a toolbar Bookmark button. Clicking this button will show
|
66
|
+
* a {@link #_balloon} attached to the selection.
|
67
|
+
*/
|
68
|
+
private _createToolbarBookmarkButton;
|
69
|
+
/**
|
70
|
+
* Creates a button for `bookmark` command to use either in toolbar or in menu bar.
|
71
|
+
*/
|
72
|
+
private _createButton;
|
73
|
+
/**
|
74
|
+
* Attaches actions that control whether the balloon panel containing the
|
75
|
+
* {@link #formView} should be displayed.
|
76
|
+
*/
|
77
|
+
private _enableBalloonActivators;
|
78
|
+
/**
|
79
|
+
* Attaches actions that control whether the balloon panel containing the
|
80
|
+
* {@link #formView} is visible or not.
|
81
|
+
*/
|
82
|
+
private _enableUserBalloonInteractions;
|
83
|
+
/**
|
84
|
+
* Updates the button label. If bookmark is selected label is set to 'Update' otherwise
|
85
|
+
* it is 'Insert'.
|
86
|
+
*/
|
87
|
+
private _updateFormButtonLabel;
|
88
|
+
/**
|
89
|
+
* Adds the {@link #actionsView} to the {@link #_balloon}.
|
90
|
+
*
|
91
|
+
* @internal
|
92
|
+
*/
|
93
|
+
_addActionsView(): void;
|
94
|
+
/**
|
95
|
+
* Adds the {@link #formView} to the {@link #_balloon}.
|
96
|
+
*/
|
97
|
+
private _addFormView;
|
98
|
+
/**
|
99
|
+
* Closes the form view. Decides whether the balloon should be hidden completely.
|
100
|
+
*/
|
101
|
+
private _closeFormView;
|
102
|
+
/**
|
103
|
+
* Removes the {@link #formView} from the {@link #_balloon}.
|
104
|
+
*/
|
105
|
+
private _removeFormView;
|
106
|
+
/**
|
107
|
+
* Shows the correct UI type. It is either {@link #formView} or {@link #actionsView}.
|
108
|
+
*/
|
109
|
+
private _showUI;
|
110
|
+
/**
|
111
|
+
* Removes the {@link #formView} from the {@link #_balloon}.
|
112
|
+
*
|
113
|
+
* See {@link #_addFormView}, {@link #_addActionsView}.
|
114
|
+
*/
|
115
|
+
private _hideUI;
|
116
|
+
/**
|
117
|
+
* Makes the UI react to the {@link module:ui/editorui/editorui~EditorUI#event:update} event to
|
118
|
+
* reposition itself when the editor UI should be refreshed.
|
119
|
+
*
|
120
|
+
* See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
|
121
|
+
*/
|
122
|
+
private _startUpdatingUI;
|
123
|
+
/**
|
124
|
+
* Returns `true` when {@link #formView} is in the {@link #_balloon}.
|
125
|
+
*/
|
126
|
+
private get _isFormInPanel();
|
127
|
+
/**
|
128
|
+
* Returns `true` when {@link #actionsView} is in the {@link #_balloon}.
|
129
|
+
*/
|
130
|
+
private get _areActionsInPanel();
|
131
|
+
/**
|
132
|
+
* Returns `true` when {@link #actionsView} is in the {@link #_balloon} and it is
|
133
|
+
* currently visible.
|
134
|
+
*/
|
135
|
+
private get _areActionsVisible();
|
136
|
+
/**
|
137
|
+
* Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon}.
|
138
|
+
*/
|
139
|
+
private get _isUIInPanel();
|
140
|
+
/**
|
141
|
+
* Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon} and it is
|
142
|
+
* currently visible.
|
143
|
+
*/
|
144
|
+
private get _isUIVisible();
|
145
|
+
/**
|
146
|
+
* Returns positioning options for the {@link #_balloon}. They control the way the balloon is attached
|
147
|
+
* to the target element or selection.
|
148
|
+
*/
|
149
|
+
private _getBalloonPositionData;
|
150
|
+
/**
|
151
|
+
* Returns the bookmark {@link module:engine/view/attributeelement~AttributeElement} under
|
152
|
+
* the {@link module:engine/view/document~Document editing view's} selection or `null`
|
153
|
+
* if there is none.
|
154
|
+
*/
|
155
|
+
private _getSelectedBookmarkElement;
|
156
|
+
/**
|
157
|
+
* Displays a fake visual selection when the contextual balloon is displayed.
|
158
|
+
*
|
159
|
+
* This adds a 'bookmark-ui' marker into the document that is rendered as a highlight on selected text fragment.
|
160
|
+
*/
|
161
|
+
private _showFakeVisualSelection;
|
162
|
+
/**
|
163
|
+
* Hides the fake visual selection created in {@link #_showFakeVisualSelection}.
|
164
|
+
*/
|
165
|
+
private _hideFakeVisualSelection;
|
166
|
+
}
|