@ckeditor/ckeditor5-bookmark 44.3.0-alpha.7 → 45.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) 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/be.js +1 -0
  7. package/build/translations/bg.js +1 -1
  8. package/build/translations/bn.js +1 -1
  9. package/build/translations/bs.js +1 -1
  10. package/build/translations/ca.js +1 -1
  11. package/build/translations/cs.js +1 -1
  12. package/build/translations/da.js +1 -1
  13. package/build/translations/de-ch.js +1 -1
  14. package/build/translations/de.js +1 -1
  15. package/build/translations/el.js +1 -1
  16. package/build/translations/en-au.js +1 -1
  17. package/build/translations/en-gb.js +1 -1
  18. package/build/translations/eo.js +1 -1
  19. package/build/translations/es-co.js +1 -1
  20. package/build/translations/es.js +1 -1
  21. package/build/translations/et.js +1 -1
  22. package/build/translations/eu.js +1 -1
  23. package/build/translations/fa.js +1 -1
  24. package/build/translations/fi.js +1 -1
  25. package/build/translations/fr.js +1 -1
  26. package/build/translations/gl.js +1 -1
  27. package/build/translations/gu.js +1 -1
  28. package/build/translations/he.js +1 -1
  29. package/build/translations/hi.js +1 -1
  30. package/build/translations/hr.js +1 -1
  31. package/build/translations/hu.js +1 -1
  32. package/build/translations/hy.js +1 -1
  33. package/build/translations/id.js +1 -1
  34. package/build/translations/it.js +1 -1
  35. package/build/translations/ja.js +1 -1
  36. package/build/translations/jv.js +1 -1
  37. package/build/translations/kk.js +1 -1
  38. package/build/translations/km.js +1 -1
  39. package/build/translations/kn.js +1 -1
  40. package/build/translations/ko.js +1 -1
  41. package/build/translations/ku.js +1 -1
  42. package/build/translations/lt.js +1 -1
  43. package/build/translations/lv.js +1 -1
  44. package/build/translations/ms.js +1 -1
  45. package/build/translations/nb.js +1 -1
  46. package/build/translations/ne.js +1 -1
  47. package/build/translations/nl.js +1 -1
  48. package/build/translations/no.js +1 -1
  49. package/build/translations/oc.js +1 -1
  50. package/build/translations/pl.js +1 -1
  51. package/build/translations/pt-br.js +1 -1
  52. package/build/translations/pt.js +1 -1
  53. package/build/translations/ro.js +1 -1
  54. package/build/translations/ru.js +1 -1
  55. package/build/translations/si.js +1 -1
  56. package/build/translations/sk.js +1 -1
  57. package/build/translations/sl.js +1 -1
  58. package/build/translations/sq.js +1 -1
  59. package/build/translations/sr-latn.js +1 -1
  60. package/build/translations/sr.js +1 -1
  61. package/build/translations/sv.js +1 -1
  62. package/build/translations/th.js +1 -1
  63. package/build/translations/ti.js +1 -1
  64. package/build/translations/tk.js +1 -1
  65. package/build/translations/tr.js +1 -1
  66. package/build/translations/tt.js +1 -1
  67. package/build/translations/ug.js +1 -1
  68. package/build/translations/uk.js +1 -1
  69. package/build/translations/ur.js +1 -1
  70. package/build/translations/uz.js +1 -1
  71. package/build/translations/vi.js +1 -1
  72. package/build/translations/zh-cn.js +1 -1
  73. package/build/translations/zh.js +1 -1
  74. package/ckeditor5-metadata.json +1 -1
  75. package/dist/index-editor.css +56 -101
  76. package/dist/index.css +59 -119
  77. package/dist/index.css.map +1 -1
  78. package/dist/index.js +282 -389
  79. package/dist/index.js.map +1 -1
  80. package/dist/translations/af.js +1 -1
  81. package/dist/translations/af.umd.js +1 -1
  82. package/dist/translations/ar.js +1 -1
  83. package/dist/translations/ar.umd.js +1 -1
  84. package/dist/translations/ast.js +1 -1
  85. package/dist/translations/ast.umd.js +1 -1
  86. package/dist/translations/az.js +1 -1
  87. package/dist/translations/az.umd.js +1 -1
  88. package/dist/translations/be.d.ts +8 -0
  89. package/dist/translations/be.js +5 -0
  90. package/dist/translations/be.umd.js +11 -0
  91. package/dist/translations/bg.js +1 -1
  92. package/dist/translations/bg.umd.js +1 -1
  93. package/dist/translations/bn.js +1 -1
  94. package/dist/translations/bn.umd.js +1 -1
  95. package/dist/translations/bs.js +1 -1
  96. package/dist/translations/bs.umd.js +1 -1
  97. package/dist/translations/ca.js +1 -1
  98. package/dist/translations/ca.umd.js +1 -1
  99. package/dist/translations/cs.js +1 -1
  100. package/dist/translations/cs.umd.js +1 -1
  101. package/dist/translations/da.js +1 -1
  102. package/dist/translations/da.umd.js +1 -1
  103. package/dist/translations/de-ch.js +1 -1
  104. package/dist/translations/de-ch.umd.js +1 -1
  105. package/dist/translations/de.js +1 -1
  106. package/dist/translations/de.umd.js +1 -1
  107. package/dist/translations/el.js +1 -1
  108. package/dist/translations/el.umd.js +1 -1
  109. package/dist/translations/en-au.js +1 -1
  110. package/dist/translations/en-au.umd.js +1 -1
  111. package/dist/translations/en-gb.js +1 -1
  112. package/dist/translations/en-gb.umd.js +1 -1
  113. package/dist/translations/en.js +1 -1
  114. package/dist/translations/en.umd.js +1 -1
  115. package/dist/translations/eo.js +1 -1
  116. package/dist/translations/eo.umd.js +1 -1
  117. package/dist/translations/es-co.js +1 -1
  118. package/dist/translations/es-co.umd.js +1 -1
  119. package/dist/translations/es.js +1 -1
  120. package/dist/translations/es.umd.js +1 -1
  121. package/dist/translations/et.js +1 -1
  122. package/dist/translations/et.umd.js +1 -1
  123. package/dist/translations/eu.js +1 -1
  124. package/dist/translations/eu.umd.js +1 -1
  125. package/dist/translations/fa.js +1 -1
  126. package/dist/translations/fa.umd.js +1 -1
  127. package/dist/translations/fi.js +1 -1
  128. package/dist/translations/fi.umd.js +1 -1
  129. package/dist/translations/fr.js +1 -1
  130. package/dist/translations/fr.umd.js +1 -1
  131. package/dist/translations/gl.js +1 -1
  132. package/dist/translations/gl.umd.js +1 -1
  133. package/dist/translations/gu.js +1 -1
  134. package/dist/translations/gu.umd.js +1 -1
  135. package/dist/translations/he.js +1 -1
  136. package/dist/translations/he.umd.js +1 -1
  137. package/dist/translations/hi.js +1 -1
  138. package/dist/translations/hi.umd.js +1 -1
  139. package/dist/translations/hr.js +1 -1
  140. package/dist/translations/hr.umd.js +1 -1
  141. package/dist/translations/hu.js +1 -1
  142. package/dist/translations/hu.umd.js +1 -1
  143. package/dist/translations/hy.js +1 -1
  144. package/dist/translations/hy.umd.js +1 -1
  145. package/dist/translations/id.js +1 -1
  146. package/dist/translations/id.umd.js +1 -1
  147. package/dist/translations/it.js +1 -1
  148. package/dist/translations/it.umd.js +1 -1
  149. package/dist/translations/ja.js +1 -1
  150. package/dist/translations/ja.umd.js +1 -1
  151. package/dist/translations/jv.js +1 -1
  152. package/dist/translations/jv.umd.js +1 -1
  153. package/dist/translations/kk.js +1 -1
  154. package/dist/translations/kk.umd.js +1 -1
  155. package/dist/translations/km.js +1 -1
  156. package/dist/translations/km.umd.js +1 -1
  157. package/dist/translations/kn.js +1 -1
  158. package/dist/translations/kn.umd.js +1 -1
  159. package/dist/translations/ko.js +1 -1
  160. package/dist/translations/ko.umd.js +1 -1
  161. package/dist/translations/ku.js +1 -1
  162. package/dist/translations/ku.umd.js +1 -1
  163. package/dist/translations/lt.js +1 -1
  164. package/dist/translations/lt.umd.js +1 -1
  165. package/dist/translations/lv.js +1 -1
  166. package/dist/translations/lv.umd.js +1 -1
  167. package/dist/translations/ms.js +1 -1
  168. package/dist/translations/ms.umd.js +1 -1
  169. package/dist/translations/nb.js +1 -1
  170. package/dist/translations/nb.umd.js +1 -1
  171. package/dist/translations/ne.js +1 -1
  172. package/dist/translations/ne.umd.js +1 -1
  173. package/dist/translations/nl.js +1 -1
  174. package/dist/translations/nl.umd.js +1 -1
  175. package/dist/translations/no.js +1 -1
  176. package/dist/translations/no.umd.js +1 -1
  177. package/dist/translations/oc.js +1 -1
  178. package/dist/translations/oc.umd.js +1 -1
  179. package/dist/translations/pl.js +1 -1
  180. package/dist/translations/pl.umd.js +1 -1
  181. package/dist/translations/pt-br.js +1 -1
  182. package/dist/translations/pt-br.umd.js +1 -1
  183. package/dist/translations/pt.js +1 -1
  184. package/dist/translations/pt.umd.js +1 -1
  185. package/dist/translations/ro.js +1 -1
  186. package/dist/translations/ro.umd.js +1 -1
  187. package/dist/translations/ru.js +1 -1
  188. package/dist/translations/ru.umd.js +1 -1
  189. package/dist/translations/si.js +1 -1
  190. package/dist/translations/si.umd.js +1 -1
  191. package/dist/translations/sk.js +1 -1
  192. package/dist/translations/sk.umd.js +1 -1
  193. package/dist/translations/sl.js +1 -1
  194. package/dist/translations/sl.umd.js +1 -1
  195. package/dist/translations/sq.js +1 -1
  196. package/dist/translations/sq.umd.js +1 -1
  197. package/dist/translations/sr-latn.js +1 -1
  198. package/dist/translations/sr-latn.umd.js +1 -1
  199. package/dist/translations/sr.js +1 -1
  200. package/dist/translations/sr.umd.js +1 -1
  201. package/dist/translations/sv.js +1 -1
  202. package/dist/translations/sv.umd.js +1 -1
  203. package/dist/translations/th.js +1 -1
  204. package/dist/translations/th.umd.js +1 -1
  205. package/dist/translations/ti.js +1 -1
  206. package/dist/translations/ti.umd.js +1 -1
  207. package/dist/translations/tk.js +1 -1
  208. package/dist/translations/tk.umd.js +1 -1
  209. package/dist/translations/tr.js +1 -1
  210. package/dist/translations/tr.umd.js +1 -1
  211. package/dist/translations/tt.js +1 -1
  212. package/dist/translations/tt.umd.js +1 -1
  213. package/dist/translations/ug.js +1 -1
  214. package/dist/translations/ug.umd.js +1 -1
  215. package/dist/translations/uk.js +1 -1
  216. package/dist/translations/uk.umd.js +1 -1
  217. package/dist/translations/ur.js +1 -1
  218. package/dist/translations/ur.umd.js +1 -1
  219. package/dist/translations/uz.js +1 -1
  220. package/dist/translations/uz.umd.js +1 -1
  221. package/dist/translations/vi.js +1 -1
  222. package/dist/translations/vi.umd.js +1 -1
  223. package/dist/translations/zh-cn.js +1 -1
  224. package/dist/translations/zh-cn.umd.js +1 -1
  225. package/dist/translations/zh.js +1 -1
  226. package/dist/translations/zh.umd.js +1 -1
  227. package/lang/contexts.json +5 -3
  228. package/lang/translations/af.po +16 -8
  229. package/lang/translations/ar.po +16 -8
  230. package/lang/translations/ast.po +16 -8
  231. package/lang/translations/az.po +16 -8
  232. package/lang/translations/be.po +64 -0
  233. package/lang/translations/bg.po +16 -8
  234. package/lang/translations/bn.po +16 -8
  235. package/lang/translations/bs.po +16 -8
  236. package/lang/translations/ca.po +16 -8
  237. package/lang/translations/cs.po +16 -8
  238. package/lang/translations/da.po +16 -8
  239. package/lang/translations/de-ch.po +16 -8
  240. package/lang/translations/de.po +16 -8
  241. package/lang/translations/el.po +16 -8
  242. package/lang/translations/en-au.po +16 -8
  243. package/lang/translations/en-gb.po +16 -8
  244. package/lang/translations/en.po +16 -8
  245. package/lang/translations/eo.po +16 -8
  246. package/lang/translations/es-co.po +16 -8
  247. package/lang/translations/es.po +16 -8
  248. package/lang/translations/et.po +16 -8
  249. package/lang/translations/eu.po +16 -8
  250. package/lang/translations/fa.po +16 -8
  251. package/lang/translations/fi.po +16 -8
  252. package/lang/translations/fr.po +16 -8
  253. package/lang/translations/gl.po +16 -8
  254. package/lang/translations/gu.po +16 -8
  255. package/lang/translations/he.po +16 -8
  256. package/lang/translations/hi.po +16 -8
  257. package/lang/translations/hr.po +16 -8
  258. package/lang/translations/hu.po +16 -8
  259. package/lang/translations/hy.po +16 -8
  260. package/lang/translations/id.po +16 -8
  261. package/lang/translations/it.po +16 -8
  262. package/lang/translations/ja.po +16 -8
  263. package/lang/translations/jv.po +16 -8
  264. package/lang/translations/kk.po +16 -8
  265. package/lang/translations/km.po +16 -8
  266. package/lang/translations/kn.po +16 -8
  267. package/lang/translations/ko.po +16 -8
  268. package/lang/translations/ku.po +16 -8
  269. package/lang/translations/lt.po +16 -8
  270. package/lang/translations/lv.po +16 -8
  271. package/lang/translations/ms.po +16 -8
  272. package/lang/translations/nb.po +16 -8
  273. package/lang/translations/ne.po +16 -8
  274. package/lang/translations/nl.po +16 -8
  275. package/lang/translations/no.po +16 -8
  276. package/lang/translations/oc.po +16 -8
  277. package/lang/translations/pl.po +16 -8
  278. package/lang/translations/pt-br.po +16 -8
  279. package/lang/translations/pt.po +16 -8
  280. package/lang/translations/ro.po +16 -8
  281. package/lang/translations/ru.po +16 -8
  282. package/lang/translations/si.po +16 -8
  283. package/lang/translations/sk.po +16 -8
  284. package/lang/translations/sl.po +16 -8
  285. package/lang/translations/sq.po +16 -8
  286. package/lang/translations/sr-latn.po +16 -8
  287. package/lang/translations/sr.po +16 -8
  288. package/lang/translations/sv.po +16 -8
  289. package/lang/translations/th.po +16 -8
  290. package/lang/translations/ti.po +16 -8
  291. package/lang/translations/tk.po +16 -8
  292. package/lang/translations/tr.po +16 -8
  293. package/lang/translations/tt.po +16 -8
  294. package/lang/translations/ug.po +16 -8
  295. package/lang/translations/uk.po +16 -8
  296. package/lang/translations/ur.po +16 -8
  297. package/lang/translations/uz.po +16 -8
  298. package/lang/translations/vi.po +16 -8
  299. package/lang/translations/zh-cn.po +16 -8
  300. package/lang/translations/zh.po +16 -8
  301. package/package.json +8 -7
  302. package/src/bookmarkconfig.d.ts +24 -0
  303. package/src/bookmarkediting.d.ts +9 -1
  304. package/src/bookmarkediting.js +23 -9
  305. package/src/bookmarkui.d.ts +24 -57
  306. package/src/bookmarkui.js +207 -212
  307. package/src/ui/bookmarkformview.d.ts +24 -14
  308. package/src/ui/bookmarkformview.js +103 -62
  309. package/theme/bookmark.css +0 -46
  310. package/theme/bookmarkform.css +0 -38
  311. package/theme/bookmarktoolbar.css +4 -0
  312. package/src/ui/bookmarkactionsview.d.ts +0 -102
  313. package/src/ui/bookmarkactionsview.js +0 -154
  314. package/theme/bookmarkactions.css +0 -44
package/src/bookmarkui.js CHANGED
@@ -2,15 +2,13 @@
2
2
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- /**
6
- * @module bookmark/bookmarkui
7
- */
8
- import { Plugin, icons } from 'ckeditor5/src/core.js';
9
- import { ButtonView, ContextualBalloon, CssTransitionDisablerMixin, MenuBarMenuListItemButtonView, clickOutsideHandler } from 'ckeditor5/src/ui.js';
10
- import { ClickObserver } from 'ckeditor5/src/engine.js';
5
+ import { Plugin } from 'ckeditor5/src/core.js';
6
+ import { ButtonView, ContextualBalloon, CssTransitionDisablerMixin, MenuBarMenuListItemButtonView, clickOutsideHandler, LabelView, BalloonPanelView } from 'ckeditor5/src/ui.js';
7
+ import { IconBookmark, IconRemove, IconBookmarkMedium, IconBookmarkSmall, IconPencil } from 'ckeditor5/src/icons.js';
8
+ import { isWidget, WidgetToolbarRepository } from 'ckeditor5/src/widget.js';
11
9
  import BookmarkFormView from './ui/bookmarkformview.js';
12
- import BookmarkActionsView from './ui/bookmarkactionsview.js';
13
10
  import BookmarkEditing from './bookmarkediting.js';
11
+ import '../theme/bookmarktoolbar.css';
14
12
  const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
15
13
  /**
16
14
  * The UI plugin of the bookmark feature.
@@ -19,22 +17,19 @@ const VISUAL_SELECTION_MARKER_NAME = 'bookmark-ui';
19
17
  * which inserts the `bookmark` element upon selection.
20
18
  */
21
19
  export default class BookmarkUI extends Plugin {
22
- constructor() {
23
- super(...arguments);
24
- /**
25
- * The actions view displayed inside of the balloon.
26
- */
27
- this.actionsView = null;
28
- /**
29
- * The form view displayed inside the balloon.
30
- */
31
- this.formView = null;
32
- }
20
+ /**
21
+ * The form view displayed inside the balloon.
22
+ */
23
+ formView = null;
24
+ /**
25
+ * The contextual balloon plugin instance.
26
+ */
27
+ _balloon;
33
28
  /**
34
29
  * @inheritDoc
35
30
  */
36
31
  static get requires() {
37
- return [BookmarkEditing, ContextualBalloon];
32
+ return [BookmarkEditing, ContextualBalloon, WidgetToolbarRepository];
38
33
  }
39
34
  /**
40
35
  * @inheritDoc
@@ -53,11 +48,13 @@ export default class BookmarkUI extends Plugin {
53
48
  */
54
49
  init() {
55
50
  const editor = this.editor;
56
- editor.editing.view.addObserver(ClickObserver);
57
51
  this._balloon = editor.plugins.get(ContextualBalloon);
52
+ // Register the link provider in link plugin to display the link form.
53
+ if (editor.plugins.has('LinkUI')) {
54
+ this._registerLinkProvider();
55
+ }
58
56
  // Create toolbar buttons.
59
- this._createToolbarBookmarkButton();
60
- this._enableBalloonActivators();
57
+ this._registerComponents();
61
58
  // Renders a fake visual selection marker on an expanded selection.
62
59
  editor.conversion.for('editingDowncast').markerToHighlight({
63
60
  model: VISUAL_SELECTION_MARKER_NAME,
@@ -78,6 +75,35 @@ export default class BookmarkUI extends Plugin {
78
75
  }
79
76
  });
80
77
  }
78
+ /**
79
+ * @inheritDoc
80
+ */
81
+ afterInit() {
82
+ const editor = this.editor;
83
+ const t = editor.locale.t;
84
+ const widgetToolbarRepository = this.editor.plugins.get(WidgetToolbarRepository);
85
+ const defaultPositions = BalloonPanelView.defaultPositions;
86
+ widgetToolbarRepository.register('bookmark', {
87
+ ariaLabel: t('Bookmark toolbar'),
88
+ items: editor.config.get('bookmark.toolbar'),
89
+ getRelatedElement: getSelectedBookmarkWidget,
90
+ // Override positions to the same list as for balloon panel default
91
+ // so widget toolbar will try to use same position as form view.
92
+ positions: [
93
+ defaultPositions.southArrowNorth,
94
+ defaultPositions.southArrowNorthMiddleWest,
95
+ defaultPositions.southArrowNorthMiddleEast,
96
+ defaultPositions.southArrowNorthWest,
97
+ defaultPositions.southArrowNorthEast,
98
+ defaultPositions.northArrowSouth,
99
+ defaultPositions.northArrowSouthMiddleWest,
100
+ defaultPositions.northArrowSouthMiddleEast,
101
+ defaultPositions.northArrowSouthWest,
102
+ defaultPositions.northArrowSouthEast,
103
+ defaultPositions.viewportStickyNorth
104
+ ]
105
+ });
106
+ }
81
107
  /**
82
108
  * @inheritDoc
83
109
  */
@@ -87,61 +113,36 @@ export default class BookmarkUI extends Plugin {
87
113
  if (this.formView) {
88
114
  this.formView.destroy();
89
115
  }
90
- if (this.actionsView) {
91
- this.actionsView.destroy();
92
- }
93
116
  }
94
117
  /**
95
118
  * Creates views.
96
119
  */
97
120
  _createViews() {
98
- this.actionsView = this._createActionsView();
99
121
  this.formView = this._createFormView();
100
122
  // Attach lifecycle actions to the the balloon.
101
123
  this._enableUserBalloonInteractions();
102
124
  }
103
- /**
104
- * Creates the {@link module:bookmark/ui/bookmarkactionsview~BookmarkActionsView} instance.
105
- */
106
- _createActionsView() {
107
- const editor = this.editor;
108
- const actionsView = new BookmarkActionsView(editor.locale);
109
- const updateBookmarkCommand = editor.commands.get('updateBookmark');
110
- const deleteCommand = editor.commands.get('delete');
111
- actionsView.bind('id').to(updateBookmarkCommand, 'value');
112
- actionsView.editButtonView.bind('isEnabled').to(updateBookmarkCommand);
113
- actionsView.removeButtonView.bind('isEnabled').to(deleteCommand);
114
- // Display edit form view after clicking on the "Edit" button.
115
- this.listenTo(actionsView, 'edit', () => {
116
- this._addFormView();
117
- });
118
- // Execute remove command after clicking on the "Remove" button.
119
- this.listenTo(actionsView, 'remove', () => {
120
- this._hideUI();
121
- editor.execute('delete');
122
- });
123
- // Close the panel on esc key press when the **actions have focus**.
124
- actionsView.keystrokes.set('Esc', (data, cancel) => {
125
- this._hideUI();
126
- cancel();
127
- });
128
- return actionsView;
129
- }
130
125
  /**
131
126
  * Creates the {@link module:bookmark/ui/bookmarkformview~BookmarkFormView} instance.
132
127
  */
133
128
  _createFormView() {
134
129
  const editor = this.editor;
135
130
  const locale = editor.locale;
131
+ const t = locale.t;
136
132
  const insertBookmarkCommand = editor.commands.get('insertBookmark');
137
133
  const updateBookmarkCommand = editor.commands.get('updateBookmark');
138
134
  const commands = [insertBookmarkCommand, updateBookmarkCommand];
139
135
  const formView = new (CssTransitionDisablerMixin(BookmarkFormView))(locale, getFormValidators(editor));
140
136
  formView.idInputView.fieldView.bind('value').to(updateBookmarkCommand, 'value');
137
+ formView.saveButtonView.bind('label').to(updateBookmarkCommand, 'value', value => value ? t('Save') : t('Insert'));
141
138
  // Form elements should be read-only when corresponding commands are disabled.
142
139
  formView.idInputView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
143
140
  // Disable the "save" button if the command is disabled.
144
- formView.buttonView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
141
+ formView.saveButtonView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
142
+ // Close the panel on form after clicking back button.
143
+ this.listenTo(formView, 'cancel', () => {
144
+ this._hideFormView();
145
+ });
145
146
  // Execute link command after clicking the "Save" button.
146
147
  this.listenTo(formView, 'submit', () => {
147
148
  if (formView.isValid()) {
@@ -152,41 +153,134 @@ export default class BookmarkUI extends Plugin {
152
153
  else {
153
154
  editor.execute('insertBookmark', { bookmarkId: value });
154
155
  }
155
- this._closeFormView();
156
+ this._hideFormView();
156
157
  }
157
158
  });
158
159
  // Update balloon position when form error changes.
159
160
  this.listenTo(formView.idInputView, 'change:errorText', () => {
160
161
  editor.ui.update();
161
162
  });
162
- // Close the panel on esc key press when the **form has focus**.
163
- formView.keystrokes.set('Esc', (data, cancel) => {
164
- this._closeFormView();
165
- cancel();
166
- });
167
163
  return formView;
168
164
  }
165
+ /**
166
+ * Creates link form menu list entry, so it'll be possible to access
167
+ * the list of the bookmarks from the link form.
168
+ */
169
+ _registerLinkProvider() {
170
+ const t = this.editor.locale.t;
171
+ const linksUI = this.editor.plugins.get('LinkUI');
172
+ const bookmarkEditing = this.editor.plugins.get(BookmarkEditing);
173
+ const getListItems = () => Array
174
+ .from(bookmarkEditing.getAllBookmarkNames())
175
+ .sort((a, b) => a.localeCompare(b))
176
+ .map((bookmarkId) => ({
177
+ id: bookmarkId,
178
+ href: `#${bookmarkId}`,
179
+ label: bookmarkId,
180
+ icon: IconBookmarkMedium
181
+ }));
182
+ const getItem = (href) => {
183
+ const bookmark = [...bookmarkEditing.getAllBookmarkNames()].find(item => `#${item}` === href);
184
+ if (!bookmark) {
185
+ return null;
186
+ }
187
+ return {
188
+ href,
189
+ label: bookmark,
190
+ icon: IconBookmarkSmall,
191
+ tooltip: t('Scroll to bookmark')
192
+ };
193
+ };
194
+ linksUI.registerLinksListProvider({
195
+ label: t('Bookmarks'),
196
+ emptyListPlaceholder: t('No bookmarks available.'),
197
+ navigate: ({ href }) => this._scrollToBookmark(href),
198
+ getListItems,
199
+ getItem
200
+ });
201
+ }
202
+ /**
203
+ * Scrolls the editor to the bookmark with the given id.
204
+ */
205
+ _scrollToBookmark(href) {
206
+ const bookmarkEditing = this.editor.plugins.get(BookmarkEditing);
207
+ const bookmarkElement = bookmarkEditing.getElementForBookmarkId(href.slice(1));
208
+ if (!bookmarkElement) {
209
+ return false;
210
+ }
211
+ this.editor.model.change(writer => {
212
+ writer.setSelection(bookmarkElement, 'on');
213
+ });
214
+ this.editor.editing.view.scrollToTheSelection({
215
+ alignToTop: true,
216
+ forceScroll: true
217
+ });
218
+ return true;
219
+ }
169
220
  /**
170
221
  * Creates a toolbar Bookmark button. Clicking this button will show
171
222
  * a {@link #_balloon} attached to the selection.
172
223
  */
173
- _createToolbarBookmarkButton() {
224
+ _registerComponents() {
174
225
  const editor = this.editor;
175
226
  editor.ui.componentFactory.add('bookmark', () => {
176
- const buttonView = this._createButton(ButtonView);
227
+ const buttonView = this._createBookmarkButton(ButtonView);
177
228
  buttonView.set({
178
229
  tooltip: true
179
230
  });
180
231
  return buttonView;
181
232
  });
182
233
  editor.ui.componentFactory.add('menuBar:bookmark', () => {
183
- return this._createButton(MenuBarMenuListItemButtonView);
234
+ return this._createBookmarkButton(MenuBarMenuListItemButtonView);
235
+ });
236
+ // Bookmark toolbar buttons.
237
+ editor.ui.componentFactory.add('bookmarkPreview', locale => {
238
+ const updateBookmarkCommand = editor.commands.get('updateBookmark');
239
+ const label = new LabelView(locale);
240
+ label.extendTemplate({
241
+ attributes: {
242
+ class: ['ck-bookmark-toolbar__preview']
243
+ }
244
+ });
245
+ label.bind('text').to(updateBookmarkCommand, 'value');
246
+ return label;
247
+ });
248
+ editor.ui.componentFactory.add('editBookmark', locale => {
249
+ const updateBookmarkCommand = editor.commands.get('updateBookmark');
250
+ const button = new ButtonView(locale);
251
+ const t = locale.t;
252
+ button.set({
253
+ label: t('Edit bookmark'),
254
+ icon: IconPencil,
255
+ tooltip: true
256
+ });
257
+ button.bind('isEnabled').to(updateBookmarkCommand);
258
+ this.listenTo(button, 'execute', () => {
259
+ this._showFormView();
260
+ });
261
+ return button;
262
+ });
263
+ editor.ui.componentFactory.add('removeBookmark', locale => {
264
+ const deleteCommand = editor.commands.get('delete');
265
+ const button = new ButtonView(locale);
266
+ const t = locale.t;
267
+ button.set({
268
+ label: t('Remove bookmark'),
269
+ icon: IconRemove,
270
+ tooltip: true
271
+ });
272
+ button.bind('isEnabled').to(deleteCommand);
273
+ this.listenTo(button, 'execute', () => {
274
+ editor.execute('delete');
275
+ editor.editing.view.focus();
276
+ });
277
+ return button;
184
278
  });
185
279
  }
186
280
  /**
187
281
  * Creates a button for `bookmark` command to use either in toolbar or in menu bar.
188
282
  */
189
- _createButton(ButtonClass) {
283
+ _createBookmarkButton(ButtonClass) {
190
284
  const editor = this.editor;
191
285
  const locale = editor.locale;
192
286
  const view = new ButtonClass(locale);
@@ -195,85 +289,32 @@ export default class BookmarkUI extends Plugin {
195
289
  const t = locale.t;
196
290
  view.set({
197
291
  label: t('Bookmark'),
198
- icon: icons.bookmark
292
+ icon: IconBookmark
199
293
  });
200
294
  // Execute the command.
201
- this.listenTo(view, 'execute', () => this._showUI(true));
295
+ this.listenTo(view, 'execute', () => this._showFormView());
202
296
  view.bind('isEnabled').toMany([insertCommand, updateCommand], 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
203
297
  view.bind('isOn').to(updateCommand, 'value', value => !!value);
204
298
  return view;
205
299
  }
206
- /**
207
- * Attaches actions that control whether the balloon panel containing the
208
- * {@link #formView} should be displayed.
209
- */
210
- _enableBalloonActivators() {
211
- const editor = this.editor;
212
- const viewDocument = editor.editing.view.document;
213
- // Handle click on view document and show panel when selection is placed inside the bookmark element.
214
- // Keep panel open until selection will be inside the same bookmark element.
215
- this.listenTo(viewDocument, 'click', () => {
216
- const bookmark = this._getSelectedBookmarkElement();
217
- if (bookmark) {
218
- // Then show panel but keep focus inside editor editable.
219
- this._showUI();
220
- }
221
- });
222
- }
223
300
  /**
224
301
  * Attaches actions that control whether the balloon panel containing the
225
302
  * {@link #formView} is visible or not.
226
303
  */
227
304
  _enableUserBalloonInteractions() {
228
- // Focus the form if the balloon is visible and the Tab key has been pressed.
229
- this.editor.keystrokes.set('Tab', (data, cancel) => {
230
- if (this._areActionsVisible && !this.actionsView.focusTracker.isFocused) {
231
- this.actionsView.focus();
232
- cancel();
233
- }
234
- }, {
235
- // Use the high priority because the bookmark UI navigation is more important
236
- // than other feature's actions, e.g. list indentation.
237
- priority: 'high'
238
- });
239
305
  // Close the panel on the Esc key press when the editable has focus and the balloon is visible.
240
306
  this.editor.keystrokes.set('Esc', (data, cancel) => {
241
- if (this._isUIVisible) {
242
- this._hideUI();
307
+ if (this._isFormVisible) {
308
+ this._hideFormView();
243
309
  cancel();
244
310
  }
245
311
  });
246
312
  // Close on click outside of balloon panel element.
247
313
  clickOutsideHandler({
248
314
  emitter: this.formView,
249
- activator: () => this._isUIInPanel,
315
+ activator: () => this._isFormInPanel,
250
316
  contextElements: () => [this._balloon.view.element],
251
- callback: () => this._hideUI()
252
- });
253
- }
254
- /**
255
- * Updates the button label. If bookmark is selected label is set to 'Update' otherwise
256
- * it is 'Insert'.
257
- */
258
- _updateFormButtonLabel(isBookmarkSelected) {
259
- const t = this.editor.locale.t;
260
- this.formView.buttonView.label = isBookmarkSelected ? t('Update') : t('Insert');
261
- }
262
- /**
263
- * Adds the {@link #actionsView} to the {@link #_balloon}.
264
- *
265
- * @internal
266
- */
267
- _addActionsView() {
268
- if (!this.actionsView) {
269
- this._createViews();
270
- }
271
- if (this._areActionsInPanel) {
272
- return;
273
- }
274
- this._balloon.add({
275
- view: this.actionsView,
276
- position: this._getBalloonPositionData()
317
+ callback: () => this._hideFormView()
277
318
  });
278
319
  }
279
320
  /**
@@ -286,14 +327,14 @@ export default class BookmarkUI extends Plugin {
286
327
  if (this._isFormInPanel) {
287
328
  return;
288
329
  }
289
- const editor = this.editor;
290
- const updateBookmarkCommand = editor.commands.get('updateBookmark');
330
+ const updateBookmarkCommand = this.editor.commands.get('updateBookmark');
291
331
  this.formView.disableCssTransitions();
292
332
  this.formView.resetFormStatus();
293
333
  this._balloon.add({
294
334
  view: this.formView,
295
335
  position: this._getBalloonPositionData()
296
336
  });
337
+ this.formView.backButtonView.isVisible = updateBookmarkCommand.isEnabled;
297
338
  this.formView.idInputView.fieldView.value = updateBookmarkCommand.value || '';
298
339
  // Select input when form view is currently visible.
299
340
  if (this._balloon.visibleView === this.formView) {
@@ -301,78 +342,42 @@ export default class BookmarkUI extends Plugin {
301
342
  }
302
343
  this.formView.enableCssTransitions();
303
344
  }
304
- /**
305
- * Closes the form view. Decides whether the balloon should be hidden completely.
306
- */
307
- _closeFormView() {
308
- const updateBookmarkCommand = this.editor.commands.get('updateBookmark');
309
- if (updateBookmarkCommand.value !== undefined) {
310
- this._removeFormView();
311
- }
312
- else {
313
- this._hideUI();
314
- }
315
- }
316
345
  /**
317
346
  * Removes the {@link #formView} from the {@link #_balloon}.
318
347
  */
319
348
  _removeFormView() {
320
- if (this._isFormInPanel) {
321
- // Blur the input element before removing it from DOM to prevent issues in some browsers.
322
- // See https://github.com/ckeditor/ckeditor5/issues/1501.
323
- this.formView.buttonView.focus();
324
- // Reset the ID field to update the state of the submit button.
325
- this.formView.idInputView.fieldView.reset();
326
- this._balloon.remove(this.formView);
327
- // Because the form has an input which has focus, the focus must be brought back
328
- // to the editor. Otherwise, it would be lost.
329
- this.editor.editing.view.focus();
330
- this._hideFakeVisualSelection();
331
- }
349
+ // Blur the input element before removing it from DOM to prevent issues in some browsers.
350
+ // See https://github.com/ckeditor/ckeditor5/issues/1501.
351
+ this.formView.saveButtonView.focus();
352
+ // Reset the ID field to update the state of the submit button.
353
+ this.formView.idInputView.fieldView.reset();
354
+ this._balloon.remove(this.formView);
355
+ // Because the form has an input which has focus, the focus must be brought back
356
+ // to the editor. Otherwise, it would be lost.
357
+ this.editor.editing.view.focus();
358
+ this._hideFakeVisualSelection();
332
359
  }
333
360
  /**
334
- * Shows the correct UI type. It is either {@link #formView} or {@link #actionsView}.
361
+ * Shows the {@link #formView}.
335
362
  */
336
- _showUI(forceVisible = false) {
363
+ _showFormView() {
337
364
  if (!this.formView) {
338
365
  this._createViews();
339
366
  }
340
- // When there's no bookmark under the selection, go straight to the editing UI.
341
367
  if (!this._getSelectedBookmarkElement()) {
342
- // Show visual selection on a text without a bookmark when the contextual balloon is displayed.
343
368
  this._showFakeVisualSelection();
344
- this._addActionsView();
345
- // Be sure panel with bookmark is visible.
346
- if (forceVisible) {
347
- this._balloon.showStack('main');
348
- }
349
- this._addFormView();
350
- }
351
- // If there's a bookmark under the selection...
352
- else {
353
- // Go to the editing UI if actions are already visible.
354
- if (this._areActionsVisible) {
355
- this._addFormView();
356
- }
357
- // Otherwise display just the actions UI.
358
- else {
359
- this._addActionsView();
360
- }
361
- // Be sure panel with bookmark is visible.
362
- if (forceVisible) {
363
- this._balloon.showStack('main');
364
- }
365
369
  }
370
+ this._addFormView();
371
+ // Be sure panel with bookmark is visible.
372
+ this._balloon.showStack('main');
366
373
  // Begin responding to ui#update once the UI is added.
367
374
  this._startUpdatingUI();
368
375
  }
369
376
  /**
370
377
  * Removes the {@link #formView} from the {@link #_balloon}.
371
- *
372
- * See {@link #_addFormView}, {@link #_addActionsView}.
373
378
  */
374
- _hideUI() {
375
- if (!this._isUIInPanel) {
379
+ _hideFormView() {
380
+ if (!this._isFormInPanel) {
376
381
  return;
377
382
  }
378
383
  const editor = this.editor;
@@ -383,22 +388,19 @@ export default class BookmarkUI extends Plugin {
383
388
  editor.editing.view.focus();
384
389
  // Remove form first because it's on top of the stack.
385
390
  this._removeFormView();
386
- // Then remove the actions view because it's beneath the form.
387
- this._balloon.remove(this.actionsView);
388
391
  this._hideFakeVisualSelection();
389
392
  }
390
393
  /**
391
394
  * Makes the UI react to the {@link module:ui/editorui/editorui~EditorUI#event:update} event to
392
395
  * reposition itself when the editor UI should be refreshed.
393
396
  *
394
- * See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
397
+ * See: {@link #_hideFormView} to learn when the UI stops reacting to the `update` event.
395
398
  */
396
399
  _startUpdatingUI() {
397
400
  const editor = this.editor;
398
401
  const viewDocument = editor.editing.view.document;
399
402
  let prevSelectedBookmark = this._getSelectedBookmarkElement();
400
403
  let prevSelectionParent = getSelectionParent();
401
- this._updateFormButtonLabel(!!prevSelectedBookmark);
402
404
  const update = () => {
403
405
  const selectedBookmark = this._getSelectedBookmarkElement();
404
406
  const selectionParent = getSelectionParent();
@@ -410,21 +412,20 @@ export default class BookmarkUI extends Plugin {
410
412
  // else modified the document.
411
413
  // * the selection has expanded (e.g. displaying bookmark actions then pressing SHIFT+Right arrow).
412
414
  //
413
- if ((prevSelectedBookmark && !selectedBookmark) ||
414
- (!prevSelectedBookmark && selectionParent !== prevSelectionParent)) {
415
- this._hideUI();
415
+ if (prevSelectedBookmark && !selectedBookmark ||
416
+ !prevSelectedBookmark && selectionParent !== prevSelectionParent) {
417
+ this._hideFormView();
416
418
  }
417
419
  // Update the position of the panel when:
418
420
  // * bookmark panel is in the visible stack
419
421
  // * the selection remains on the original bookmark element,
420
422
  // * there was no bookmark element in the first place, i.e. creating a new bookmark
421
- else if (this._isUIVisible) {
423
+ else if (this._isFormVisible) {
422
424
  // If still in a bookmark element, simply update the position of the balloon.
423
425
  // If there was no bookmark (e.g. inserting one), the balloon must be moved
424
426
  // to the new position in the editing view (a new native DOM range).
425
427
  this._balloon.updatePosition(this._getBalloonPositionData());
426
428
  }
427
- this._updateFormButtonLabel(!!prevSelectedBookmark);
428
429
  prevSelectedBookmark = selectedBookmark;
429
430
  prevSelectionParent = selectionParent;
430
431
  };
@@ -443,31 +444,10 @@ export default class BookmarkUI extends Plugin {
443
444
  return !!this.formView && this._balloon.hasView(this.formView);
444
445
  }
445
446
  /**
446
- * Returns `true` when {@link #actionsView} is in the {@link #_balloon}.
447
- */
448
- get _areActionsInPanel() {
449
- return !!this.actionsView && this._balloon.hasView(this.actionsView);
450
- }
451
- /**
452
- * Returns `true` when {@link #actionsView} is in the {@link #_balloon} and it is
453
- * currently visible.
447
+ * Returns `true` when {@link #formView} is in the {@link #_balloon} and it is currently visible.
454
448
  */
455
- get _areActionsVisible() {
456
- return !!this.actionsView && this._balloon.visibleView === this.actionsView;
457
- }
458
- /**
459
- * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon}.
460
- */
461
- get _isUIInPanel() {
462
- return this._isFormInPanel || this._areActionsInPanel;
463
- }
464
- /**
465
- * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon} and it is
466
- * currently visible.
467
- */
468
- get _isUIVisible() {
469
- const visibleView = this._balloon.visibleView;
470
- return !!this.formView && visibleView == this.formView || this._areActionsVisible;
449
+ get _isFormVisible() {
450
+ return !!this.formView && this._balloon.visibleView == this.formView;
471
451
  }
472
452
  /**
473
453
  * Returns positioning options for the {@link #_balloon}. They control the way the balloon is attached
@@ -492,7 +472,12 @@ export default class BookmarkUI extends Plugin {
492
472
  return domConverter.mapViewToDom(viewElement);
493
473
  };
494
474
  }
495
- return target && { target };
475
+ if (!target) {
476
+ return;
477
+ }
478
+ return {
479
+ target
480
+ };
496
481
  }
497
482
  /**
498
483
  * Returns the bookmark {@link module:engine/view/attributeelement~AttributeElement} under
@@ -580,3 +565,13 @@ function getFormValidators(editor) {
580
565
  }
581
566
  ];
582
567
  }
568
+ /**
569
+ * Returns the currently selected bookmark view element.
570
+ */
571
+ function getSelectedBookmarkWidget(selection) {
572
+ const element = selection.getSelectedElement();
573
+ if (!element || !isWidget(element) || !element.getCustomProperty('bookmark')) {
574
+ return null;
575
+ }
576
+ return element;
577
+ }