@ckeditor/ckeditor5-ckbox 0.0.0-internal-20241017.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 (309) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +24 -0
  4. package/build/ckbox.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/az.js +1 -0
  7. package/build/translations/bg.js +1 -0
  8. package/build/translations/bn.js +1 -0
  9. package/build/translations/ca.js +1 -0
  10. package/build/translations/cs.js +1 -0
  11. package/build/translations/da.js +1 -0
  12. package/build/translations/de.js +1 -0
  13. package/build/translations/el.js +1 -0
  14. package/build/translations/en-au.js +1 -0
  15. package/build/translations/es-co.js +1 -0
  16. package/build/translations/es.js +1 -0
  17. package/build/translations/et.js +1 -0
  18. package/build/translations/fa.js +1 -0
  19. package/build/translations/fi.js +1 -0
  20. package/build/translations/fr.js +1 -0
  21. package/build/translations/gl.js +1 -0
  22. package/build/translations/he.js +1 -0
  23. package/build/translations/hi.js +1 -0
  24. package/build/translations/hr.js +1 -0
  25. package/build/translations/hu.js +1 -0
  26. package/build/translations/id.js +1 -0
  27. package/build/translations/it.js +1 -0
  28. package/build/translations/ja.js +1 -0
  29. package/build/translations/ko.js +1 -0
  30. package/build/translations/lt.js +1 -0
  31. package/build/translations/lv.js +1 -0
  32. package/build/translations/ms.js +1 -0
  33. package/build/translations/nl.js +1 -0
  34. package/build/translations/no.js +1 -0
  35. package/build/translations/pl.js +1 -0
  36. package/build/translations/pt-br.js +1 -0
  37. package/build/translations/pt.js +1 -0
  38. package/build/translations/ro.js +1 -0
  39. package/build/translations/ru.js +1 -0
  40. package/build/translations/sk.js +1 -0
  41. package/build/translations/sq.js +1 -0
  42. package/build/translations/sr-latn.js +1 -0
  43. package/build/translations/sr.js +1 -0
  44. package/build/translations/sv.js +1 -0
  45. package/build/translations/th.js +1 -0
  46. package/build/translations/tr.js +1 -0
  47. package/build/translations/ug.js +1 -0
  48. package/build/translations/uk.js +1 -0
  49. package/build/translations/ur.js +1 -0
  50. package/build/translations/uz.js +1 -0
  51. package/build/translations/vi.js +1 -0
  52. package/build/translations/zh-cn.js +1 -0
  53. package/build/translations/zh.js +1 -0
  54. package/ckeditor5-metadata.json +58 -0
  55. package/dist/augmentation.d.ts +36 -0
  56. package/dist/ckbox.d.ts +41 -0
  57. package/dist/ckboxcommand.d.ts +130 -0
  58. package/dist/ckboxconfig.d.ts +434 -0
  59. package/dist/ckboxediting.d.ts +65 -0
  60. package/dist/ckboximageedit/ckboximageeditcommand.d.ts +109 -0
  61. package/dist/ckboximageedit/ckboximageeditediting.d.ts +36 -0
  62. package/dist/ckboximageedit/ckboximageeditui.d.ts +32 -0
  63. package/dist/ckboximageedit/utils.d.ts +14 -0
  64. package/dist/ckboximageedit.d.ts +32 -0
  65. package/dist/ckboxui.d.ts +60 -0
  66. package/dist/ckboxuploadadapter.d.ts +41 -0
  67. package/dist/ckboxutils.d.ts +58 -0
  68. package/dist/index-content.css +4 -0
  69. package/dist/index-editor.css +46 -0
  70. package/dist/index.css +55 -0
  71. package/dist/index.css.map +1 -0
  72. package/dist/index.d.ts +21 -0
  73. package/dist/index.js +1787 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/translations/ar.d.ts +8 -0
  76. package/dist/translations/ar.js +5 -0
  77. package/dist/translations/ar.umd.js +11 -0
  78. package/dist/translations/az.d.ts +8 -0
  79. package/dist/translations/az.js +5 -0
  80. package/dist/translations/az.umd.js +11 -0
  81. package/dist/translations/bg.d.ts +8 -0
  82. package/dist/translations/bg.js +5 -0
  83. package/dist/translations/bg.umd.js +11 -0
  84. package/dist/translations/bn.d.ts +8 -0
  85. package/dist/translations/bn.js +5 -0
  86. package/dist/translations/bn.umd.js +11 -0
  87. package/dist/translations/ca.d.ts +8 -0
  88. package/dist/translations/ca.js +5 -0
  89. package/dist/translations/ca.umd.js +11 -0
  90. package/dist/translations/cs.d.ts +8 -0
  91. package/dist/translations/cs.js +5 -0
  92. package/dist/translations/cs.umd.js +11 -0
  93. package/dist/translations/da.d.ts +8 -0
  94. package/dist/translations/da.js +5 -0
  95. package/dist/translations/da.umd.js +11 -0
  96. package/dist/translations/de.d.ts +8 -0
  97. package/dist/translations/de.js +5 -0
  98. package/dist/translations/de.umd.js +11 -0
  99. package/dist/translations/el.d.ts +8 -0
  100. package/dist/translations/el.js +5 -0
  101. package/dist/translations/el.umd.js +11 -0
  102. package/dist/translations/en-au.d.ts +8 -0
  103. package/dist/translations/en-au.js +5 -0
  104. package/dist/translations/en-au.umd.js +11 -0
  105. package/dist/translations/en.d.ts +8 -0
  106. package/dist/translations/en.js +5 -0
  107. package/dist/translations/en.umd.js +11 -0
  108. package/dist/translations/es-co.d.ts +8 -0
  109. package/dist/translations/es-co.js +5 -0
  110. package/dist/translations/es-co.umd.js +11 -0
  111. package/dist/translations/es.d.ts +8 -0
  112. package/dist/translations/es.js +5 -0
  113. package/dist/translations/es.umd.js +11 -0
  114. package/dist/translations/et.d.ts +8 -0
  115. package/dist/translations/et.js +5 -0
  116. package/dist/translations/et.umd.js +11 -0
  117. package/dist/translations/fa.d.ts +8 -0
  118. package/dist/translations/fa.js +5 -0
  119. package/dist/translations/fa.umd.js +11 -0
  120. package/dist/translations/fi.d.ts +8 -0
  121. package/dist/translations/fi.js +5 -0
  122. package/dist/translations/fi.umd.js +11 -0
  123. package/dist/translations/fr.d.ts +8 -0
  124. package/dist/translations/fr.js +5 -0
  125. package/dist/translations/fr.umd.js +11 -0
  126. package/dist/translations/gl.d.ts +8 -0
  127. package/dist/translations/gl.js +5 -0
  128. package/dist/translations/gl.umd.js +11 -0
  129. package/dist/translations/he.d.ts +8 -0
  130. package/dist/translations/he.js +5 -0
  131. package/dist/translations/he.umd.js +11 -0
  132. package/dist/translations/hi.d.ts +8 -0
  133. package/dist/translations/hi.js +5 -0
  134. package/dist/translations/hi.umd.js +11 -0
  135. package/dist/translations/hr.d.ts +8 -0
  136. package/dist/translations/hr.js +5 -0
  137. package/dist/translations/hr.umd.js +11 -0
  138. package/dist/translations/hu.d.ts +8 -0
  139. package/dist/translations/hu.js +5 -0
  140. package/dist/translations/hu.umd.js +11 -0
  141. package/dist/translations/id.d.ts +8 -0
  142. package/dist/translations/id.js +5 -0
  143. package/dist/translations/id.umd.js +11 -0
  144. package/dist/translations/it.d.ts +8 -0
  145. package/dist/translations/it.js +5 -0
  146. package/dist/translations/it.umd.js +11 -0
  147. package/dist/translations/ja.d.ts +8 -0
  148. package/dist/translations/ja.js +5 -0
  149. package/dist/translations/ja.umd.js +11 -0
  150. package/dist/translations/ko.d.ts +8 -0
  151. package/dist/translations/ko.js +5 -0
  152. package/dist/translations/ko.umd.js +11 -0
  153. package/dist/translations/lt.d.ts +8 -0
  154. package/dist/translations/lt.js +5 -0
  155. package/dist/translations/lt.umd.js +11 -0
  156. package/dist/translations/lv.d.ts +8 -0
  157. package/dist/translations/lv.js +5 -0
  158. package/dist/translations/lv.umd.js +11 -0
  159. package/dist/translations/ms.d.ts +8 -0
  160. package/dist/translations/ms.js +5 -0
  161. package/dist/translations/ms.umd.js +11 -0
  162. package/dist/translations/nl.d.ts +8 -0
  163. package/dist/translations/nl.js +5 -0
  164. package/dist/translations/nl.umd.js +11 -0
  165. package/dist/translations/no.d.ts +8 -0
  166. package/dist/translations/no.js +5 -0
  167. package/dist/translations/no.umd.js +11 -0
  168. package/dist/translations/pl.d.ts +8 -0
  169. package/dist/translations/pl.js +5 -0
  170. package/dist/translations/pl.umd.js +11 -0
  171. package/dist/translations/pt-br.d.ts +8 -0
  172. package/dist/translations/pt-br.js +5 -0
  173. package/dist/translations/pt-br.umd.js +11 -0
  174. package/dist/translations/pt.d.ts +8 -0
  175. package/dist/translations/pt.js +5 -0
  176. package/dist/translations/pt.umd.js +11 -0
  177. package/dist/translations/ro.d.ts +8 -0
  178. package/dist/translations/ro.js +5 -0
  179. package/dist/translations/ro.umd.js +11 -0
  180. package/dist/translations/ru.d.ts +8 -0
  181. package/dist/translations/ru.js +5 -0
  182. package/dist/translations/ru.umd.js +11 -0
  183. package/dist/translations/sk.d.ts +8 -0
  184. package/dist/translations/sk.js +5 -0
  185. package/dist/translations/sk.umd.js +11 -0
  186. package/dist/translations/sq.d.ts +8 -0
  187. package/dist/translations/sq.js +5 -0
  188. package/dist/translations/sq.umd.js +11 -0
  189. package/dist/translations/sr-latn.d.ts +8 -0
  190. package/dist/translations/sr-latn.js +5 -0
  191. package/dist/translations/sr-latn.umd.js +11 -0
  192. package/dist/translations/sr.d.ts +8 -0
  193. package/dist/translations/sr.js +5 -0
  194. package/dist/translations/sr.umd.js +11 -0
  195. package/dist/translations/sv.d.ts +8 -0
  196. package/dist/translations/sv.js +5 -0
  197. package/dist/translations/sv.umd.js +11 -0
  198. package/dist/translations/th.d.ts +8 -0
  199. package/dist/translations/th.js +5 -0
  200. package/dist/translations/th.umd.js +11 -0
  201. package/dist/translations/tr.d.ts +8 -0
  202. package/dist/translations/tr.js +5 -0
  203. package/dist/translations/tr.umd.js +11 -0
  204. package/dist/translations/ug.d.ts +8 -0
  205. package/dist/translations/ug.js +5 -0
  206. package/dist/translations/ug.umd.js +11 -0
  207. package/dist/translations/uk.d.ts +8 -0
  208. package/dist/translations/uk.js +5 -0
  209. package/dist/translations/uk.umd.js +11 -0
  210. package/dist/translations/ur.d.ts +8 -0
  211. package/dist/translations/ur.js +5 -0
  212. package/dist/translations/ur.umd.js +11 -0
  213. package/dist/translations/uz.d.ts +8 -0
  214. package/dist/translations/uz.js +5 -0
  215. package/dist/translations/uz.umd.js +11 -0
  216. package/dist/translations/vi.d.ts +8 -0
  217. package/dist/translations/vi.js +5 -0
  218. package/dist/translations/vi.umd.js +11 -0
  219. package/dist/translations/zh-cn.d.ts +8 -0
  220. package/dist/translations/zh-cn.js +5 -0
  221. package/dist/translations/zh-cn.umd.js +11 -0
  222. package/dist/translations/zh.d.ts +8 -0
  223. package/dist/translations/zh.js +5 -0
  224. package/dist/translations/zh.umd.js +11 -0
  225. package/dist/utils.d.ts +67 -0
  226. package/lang/contexts.json +10 -0
  227. package/lang/translations/ar.po +50 -0
  228. package/lang/translations/az.po +50 -0
  229. package/lang/translations/bg.po +50 -0
  230. package/lang/translations/bn.po +50 -0
  231. package/lang/translations/ca.po +50 -0
  232. package/lang/translations/cs.po +50 -0
  233. package/lang/translations/da.po +50 -0
  234. package/lang/translations/de.po +50 -0
  235. package/lang/translations/el.po +50 -0
  236. package/lang/translations/en-au.po +50 -0
  237. package/lang/translations/en.po +50 -0
  238. package/lang/translations/es-co.po +50 -0
  239. package/lang/translations/es.po +50 -0
  240. package/lang/translations/et.po +50 -0
  241. package/lang/translations/fa.po +50 -0
  242. package/lang/translations/fi.po +50 -0
  243. package/lang/translations/fr.po +50 -0
  244. package/lang/translations/gl.po +50 -0
  245. package/lang/translations/he.po +50 -0
  246. package/lang/translations/hi.po +50 -0
  247. package/lang/translations/hr.po +50 -0
  248. package/lang/translations/hu.po +50 -0
  249. package/lang/translations/id.po +50 -0
  250. package/lang/translations/it.po +50 -0
  251. package/lang/translations/ja.po +50 -0
  252. package/lang/translations/ko.po +50 -0
  253. package/lang/translations/lt.po +50 -0
  254. package/lang/translations/lv.po +50 -0
  255. package/lang/translations/ms.po +50 -0
  256. package/lang/translations/nl.po +50 -0
  257. package/lang/translations/no.po +50 -0
  258. package/lang/translations/pl.po +50 -0
  259. package/lang/translations/pt-br.po +50 -0
  260. package/lang/translations/pt.po +50 -0
  261. package/lang/translations/ro.po +50 -0
  262. package/lang/translations/ru.po +50 -0
  263. package/lang/translations/sk.po +50 -0
  264. package/lang/translations/sq.po +50 -0
  265. package/lang/translations/sr-latn.po +50 -0
  266. package/lang/translations/sr.po +50 -0
  267. package/lang/translations/sv.po +50 -0
  268. package/lang/translations/th.po +50 -0
  269. package/lang/translations/tr.po +50 -0
  270. package/lang/translations/ug.po +50 -0
  271. package/lang/translations/uk.po +50 -0
  272. package/lang/translations/ur.po +50 -0
  273. package/lang/translations/uz.po +50 -0
  274. package/lang/translations/vi.po +50 -0
  275. package/lang/translations/zh-cn.po +50 -0
  276. package/lang/translations/zh.po +50 -0
  277. package/package.json +45 -0
  278. package/src/augmentation.d.ts +32 -0
  279. package/src/augmentation.js +5 -0
  280. package/src/ckbox.d.ts +37 -0
  281. package/src/ckbox.js +43 -0
  282. package/src/ckboxcommand.d.ts +126 -0
  283. package/src/ckboxcommand.js +364 -0
  284. package/src/ckboxconfig.d.ts +430 -0
  285. package/src/ckboxconfig.js +5 -0
  286. package/src/ckboxediting.d.ts +61 -0
  287. package/src/ckboxediting.js +389 -0
  288. package/src/ckboximageedit/ckboximageeditcommand.d.ts +105 -0
  289. package/src/ckboximageedit/ckboximageeditcommand.js +310 -0
  290. package/src/ckboximageedit/ckboximageeditediting.d.ts +32 -0
  291. package/src/ckboximageedit/ckboximageeditediting.js +42 -0
  292. package/src/ckboximageedit/ckboximageeditui.d.ts +28 -0
  293. package/src/ckboximageedit/ckboximageeditui.js +57 -0
  294. package/src/ckboximageedit/utils.d.ts +10 -0
  295. package/src/ckboximageedit/utils.js +48 -0
  296. package/src/ckboximageedit.d.ts +28 -0
  297. package/src/ckboximageedit.js +34 -0
  298. package/src/ckboxui.d.ts +56 -0
  299. package/src/ckboxui.js +136 -0
  300. package/src/ckboxuploadadapter.d.ts +37 -0
  301. package/src/ckboxuploadadapter.js +136 -0
  302. package/src/ckboxutils.d.ts +54 -0
  303. package/src/ckboxutils.js +189 -0
  304. package/src/index.d.ts +17 -0
  305. package/src/index.js +14 -0
  306. package/src/utils.d.ts +63 -0
  307. package/src/utils.js +175 -0
  308. package/theme/ckboximageedit.css +53 -0
  309. package/theme/icons/ckbox-image-edit.svg +1 -0
@@ -0,0 +1,32 @@
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
+ import type { CKBox, CKBoxCommand, CKBoxConfig, CKBoxEditing, CKBoxImageEdit, CKBoxImageEditEditing, CKBoxImageEditCommand, CKBoxImageEditUI } from './index.js';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the {@link module:ckbox/ckbox~CKBox CKBox feature}.
10
+ *
11
+ * Read more in {@link module:ckbox/ckboxconfig~CKBoxConfig}.
12
+ */
13
+ ckbox?: CKBoxConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [CKBox.pluginName]: CKBox;
17
+ [CKBoxEditing.pluginName]: CKBoxEditing;
18
+ [CKBoxImageEdit.pluginName]: CKBoxImageEdit;
19
+ [CKBoxImageEditEditing.pluginName]: CKBoxImageEditEditing;
20
+ [CKBoxImageEditUI.pluginName]: CKBoxImageEditUI;
21
+ }
22
+ interface CommandsMap {
23
+ ckbox: CKBoxCommand;
24
+ ckboxImageEdit: CKBoxImageEditCommand;
25
+ }
26
+ }
27
+ declare global {
28
+ var CKBox: {
29
+ mount(wrapper: Element, options: Record<string, unknown>): void;
30
+ mountImageEditor(wrapper: Element, options: Record<string, unknown>): void;
31
+ };
32
+ }
@@ -0,0 +1,5 @@
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
+ export {};
package/src/ckbox.d.ts ADDED
@@ -0,0 +1,37 @@
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 ckbox/ckbox
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import CKBoxUI from './ckboxui.js';
10
+ import CKBoxEditing from './ckboxediting.js';
11
+ /**
12
+ * The CKBox feature, a bridge between the CKEditor 5 WYSIWYG editor and the CKBox file manager and uploader.
13
+ *
14
+ * This is a "glue" plugin which enables:
15
+ *
16
+ * * {@link module:ckbox/ckboxediting~CKBoxEditing},
17
+ * * {@link module:ckbox/ckboxui~CKBoxUI},
18
+ *
19
+ * See the {@glink features/file-management/ckbox CKBox integration} guide to learn how to configure and use this feature.
20
+ *
21
+ * Check out the {@glink features/images/image-upload/image-upload Image upload} guide to learn about other ways to upload
22
+ * images into CKEditor 5.
23
+ */
24
+ export default class CKBox extends Plugin {
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get pluginName(): "CKBox";
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get isOfficialPlugin(): true;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get requires(): readonly [typeof CKBoxEditing, typeof CKBoxUI];
37
+ }
package/src/ckbox.js ADDED
@@ -0,0 +1,43 @@
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 ckbox/ckbox
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import CKBoxUI from './ckboxui.js';
10
+ import CKBoxEditing from './ckboxediting.js';
11
+ /**
12
+ * The CKBox feature, a bridge between the CKEditor 5 WYSIWYG editor and the CKBox file manager and uploader.
13
+ *
14
+ * This is a "glue" plugin which enables:
15
+ *
16
+ * * {@link module:ckbox/ckboxediting~CKBoxEditing},
17
+ * * {@link module:ckbox/ckboxui~CKBoxUI},
18
+ *
19
+ * See the {@glink features/file-management/ckbox CKBox integration} guide to learn how to configure and use this feature.
20
+ *
21
+ * Check out the {@glink features/images/image-upload/image-upload Image upload} guide to learn about other ways to upload
22
+ * images into CKEditor 5.
23
+ */
24
+ export default class CKBox extends Plugin {
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get pluginName() {
29
+ return 'CKBox';
30
+ }
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get isOfficialPlugin() {
35
+ return true;
36
+ }
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ static get requires() {
41
+ return [CKBoxEditing, CKBoxUI];
42
+ }
43
+ }
@@ -0,0 +1,126 @@
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
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
6
+ import type { CKBoxAssetDefinition, CKBoxAssetImageAttributesDefinition, CKBoxRawAssetDefinition } from './ckboxconfig.js';
7
+ /**
8
+ * The CKBox command. It is used by the {@link module:ckbox/ckboxediting~CKBoxEditing CKBox editing feature} to open the CKBox file manager.
9
+ * The file manager allows inserting an image or a link to a file into the editor content.
10
+ *
11
+ * ```ts
12
+ * editor.execute( 'ckbox' );
13
+ * ```
14
+ *
15
+ * **Note:** This command uses other features to perform the following tasks:
16
+ * - To insert images it uses the {@link module:image/image/insertimagecommand~InsertImageCommand 'insertImage'} command from the
17
+ * {@link module:image/image~Image Image feature}.
18
+ * - To insert links to other files it uses the {@link module:link/linkcommand~LinkCommand 'link'} command from the
19
+ * {@link module:link/link~Link Link feature}.
20
+ */
21
+ export default class CKBoxCommand extends Command {
22
+ value: boolean;
23
+ /**
24
+ * A set of all chosen assets. They are stored temporarily and they are automatically removed 1 second after being chosen.
25
+ * Chosen assets have to be "remembered" for a while to be able to map the given asset with the element inserted into the model.
26
+ * This association map is then used to set the ID on the model element.
27
+ *
28
+ * All chosen assets are automatically removed after the timeout, because (theoretically) it may happen that they will never be
29
+ * inserted into the model, even if the {@link module:link/linkcommand~LinkCommand `'link'`} command or the
30
+ * {@link module:image/image/insertimagecommand~InsertImageCommand `'insertImage'`} command is enabled. Such a case may arise when
31
+ * another plugin blocks the command execution. Then, in order not to keep the chosen (but not inserted) assets forever, we delete
32
+ * them automatically to prevent memory leakage. The 1 second timeout is enough to insert the asset into the model and extract the
33
+ * ID from the chosen asset.
34
+ *
35
+ * The assets are stored only if
36
+ * the {@link module:ckbox/ckboxconfig~CKBoxConfig#ignoreDataId `config.ckbox.ignoreDataId`} option is set to `false` (by default).
37
+ *
38
+ * @internal
39
+ */
40
+ readonly _chosenAssets: Set<CKBoxAssetDefinition>;
41
+ /**
42
+ * The DOM element that acts as a mounting point for the CKBox dialog.
43
+ */
44
+ private _wrapper;
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ constructor(editor: Editor);
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ refresh(): void;
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ execute(): void;
57
+ /**
58
+ * Indicates if the CKBox dialog is already opened.
59
+ *
60
+ * @protected
61
+ * @returns {Boolean}
62
+ */
63
+ private _getValue;
64
+ /**
65
+ * Checks whether the command can be enabled in the current context.
66
+ */
67
+ private _checkEnabled;
68
+ /**
69
+ * Creates the options object for the CKBox dialog.
70
+ *
71
+ * @returns The object with properties:
72
+ * - theme The theme for CKBox dialog.
73
+ * - language The language for CKBox dialog.
74
+ * - tokenUrl The token endpoint URL.
75
+ * - serviceOrigin The base URL of the API service.
76
+ * - forceDemoLabel Whether to force "Powered by CKBox" link.
77
+ * - assets.onChoose The callback function invoked after choosing the assets.
78
+ * - dialog.onClose The callback function invoked after closing the CKBox dialog.
79
+ * - dialog.width The dialog width in pixels.
80
+ * - dialog.height The dialog height in pixels.
81
+ * - categories.icons Allows setting custom icons for categories.
82
+ * - view.openLastView Sets if the last view visited by the user will be reopened
83
+ * on the next startup.
84
+ * - view.startupFolderId Sets the ID of the folder that will be opened on startup.
85
+ * - view.startupCategoryId Sets the ID of the category that will be opened on startup.
86
+ * - view.hideMaximizeButton Sets whether to hide the ‘Maximize’ button.
87
+ * - view.componentsHideTimeout Sets timeout after which upload components are hidden
88
+ * after completed upload.
89
+ * - view.dialogMinimizeTimeout Sets timeout after which upload dialog is minimized
90
+ * after completed upload.
91
+ */
92
+ private _prepareOptions;
93
+ /**
94
+ * Initializes various event listeners for the `ckbox:*` events, because all functionality of the `ckbox` command is event-based.
95
+ */
96
+ private _initListeners;
97
+ /**
98
+ * Inserts the asset into the model.
99
+ *
100
+ * @param asset The asset to be inserted.
101
+ * @param isLastAsset Indicates if the current asset is the last one from the chosen set.
102
+ * @param writer An instance of the model writer.
103
+ * @param isSingleAsset It's true when only one asset is processed.
104
+ */
105
+ private _insertAsset;
106
+ /**
107
+ * Inserts the image by calling the `insertImage` command.
108
+ *
109
+ * @param asset The asset to be inserted.
110
+ */
111
+ private _insertImage;
112
+ /**
113
+ * Inserts the link to the asset by calling the `link` command.
114
+ *
115
+ * @param asset The asset to be inserted.
116
+ * @param writer An instance of the model writer.
117
+ * @param isSingleAsset It's true when only one asset is processed.
118
+ */
119
+ private _insertLink;
120
+ }
121
+ /**
122
+ * Parses the assets attributes into the internal data format.
123
+ *
124
+ * @internal
125
+ */
126
+ export declare function prepareImageAssetAttributes(asset: CKBoxRawAssetDefinition): CKBoxAssetImageAttributesDefinition;
@@ -0,0 +1,364 @@
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
+ import { Command } from 'ckeditor5/src/core.js';
6
+ import { createElement, toMap } from 'ckeditor5/src/utils.js';
7
+ import { blurHashToDataUrl, getImageUrls } from './utils.js';
8
+ // Defines the waiting time (in milliseconds) for inserting the chosen asset into the model. The chosen asset is temporarily stored in the
9
+ // `CKBoxCommand#_chosenAssets` and it is removed from there automatically after this time. See `CKBoxCommand#_chosenAssets` for more
10
+ // details.
11
+ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
12
+ /**
13
+ * The CKBox command. It is used by the {@link module:ckbox/ckboxediting~CKBoxEditing CKBox editing feature} to open the CKBox file manager.
14
+ * The file manager allows inserting an image or a link to a file into the editor content.
15
+ *
16
+ * ```ts
17
+ * editor.execute( 'ckbox' );
18
+ * ```
19
+ *
20
+ * **Note:** This command uses other features to perform the following tasks:
21
+ * - To insert images it uses the {@link module:image/image/insertimagecommand~InsertImageCommand 'insertImage'} command from the
22
+ * {@link module:image/image~Image Image feature}.
23
+ * - To insert links to other files it uses the {@link module:link/linkcommand~LinkCommand 'link'} command from the
24
+ * {@link module:link/link~Link Link feature}.
25
+ */
26
+ export default class CKBoxCommand extends Command {
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ constructor(editor) {
31
+ super(editor);
32
+ /**
33
+ * A set of all chosen assets. They are stored temporarily and they are automatically removed 1 second after being chosen.
34
+ * Chosen assets have to be "remembered" for a while to be able to map the given asset with the element inserted into the model.
35
+ * This association map is then used to set the ID on the model element.
36
+ *
37
+ * All chosen assets are automatically removed after the timeout, because (theoretically) it may happen that they will never be
38
+ * inserted into the model, even if the {@link module:link/linkcommand~LinkCommand `'link'`} command or the
39
+ * {@link module:image/image/insertimagecommand~InsertImageCommand `'insertImage'`} command is enabled. Such a case may arise when
40
+ * another plugin blocks the command execution. Then, in order not to keep the chosen (but not inserted) assets forever, we delete
41
+ * them automatically to prevent memory leakage. The 1 second timeout is enough to insert the asset into the model and extract the
42
+ * ID from the chosen asset.
43
+ *
44
+ * The assets are stored only if
45
+ * the {@link module:ckbox/ckboxconfig~CKBoxConfig#ignoreDataId `config.ckbox.ignoreDataId`} option is set to `false` (by default).
46
+ *
47
+ * @internal
48
+ */
49
+ this._chosenAssets = new Set();
50
+ /**
51
+ * The DOM element that acts as a mounting point for the CKBox dialog.
52
+ */
53
+ this._wrapper = null;
54
+ this._initListeners();
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ refresh() {
60
+ this.value = this._getValue();
61
+ this.isEnabled = this._checkEnabled();
62
+ }
63
+ /**
64
+ * @inheritDoc
65
+ */
66
+ execute() {
67
+ this.fire('ckbox:open');
68
+ }
69
+ /**
70
+ * Indicates if the CKBox dialog is already opened.
71
+ *
72
+ * @protected
73
+ * @returns {Boolean}
74
+ */
75
+ _getValue() {
76
+ return this._wrapper !== null;
77
+ }
78
+ /**
79
+ * Checks whether the command can be enabled in the current context.
80
+ */
81
+ _checkEnabled() {
82
+ const imageCommand = this.editor.commands.get('insertImage');
83
+ const linkCommand = this.editor.commands.get('link');
84
+ if (!imageCommand.isEnabled && !linkCommand.isEnabled) {
85
+ return false;
86
+ }
87
+ return true;
88
+ }
89
+ /**
90
+ * Creates the options object for the CKBox dialog.
91
+ *
92
+ * @returns The object with properties:
93
+ * - theme The theme for CKBox dialog.
94
+ * - language The language for CKBox dialog.
95
+ * - tokenUrl The token endpoint URL.
96
+ * - serviceOrigin The base URL of the API service.
97
+ * - forceDemoLabel Whether to force "Powered by CKBox" link.
98
+ * - assets.onChoose The callback function invoked after choosing the assets.
99
+ * - dialog.onClose The callback function invoked after closing the CKBox dialog.
100
+ * - dialog.width The dialog width in pixels.
101
+ * - dialog.height The dialog height in pixels.
102
+ * - categories.icons Allows setting custom icons for categories.
103
+ * - view.openLastView Sets if the last view visited by the user will be reopened
104
+ * on the next startup.
105
+ * - view.startupFolderId Sets the ID of the folder that will be opened on startup.
106
+ * - view.startupCategoryId Sets the ID of the category that will be opened on startup.
107
+ * - view.hideMaximizeButton Sets whether to hide the ‘Maximize’ button.
108
+ * - view.componentsHideTimeout Sets timeout after which upload components are hidden
109
+ * after completed upload.
110
+ * - view.dialogMinimizeTimeout Sets timeout after which upload dialog is minimized
111
+ * after completed upload.
112
+ */
113
+ _prepareOptions() {
114
+ const editor = this.editor;
115
+ const ckboxConfig = editor.config.get('ckbox');
116
+ const dialog = ckboxConfig.dialog;
117
+ const categories = ckboxConfig.categories;
118
+ const view = ckboxConfig.view;
119
+ const upload = ckboxConfig.upload;
120
+ return {
121
+ theme: ckboxConfig.theme,
122
+ language: ckboxConfig.language,
123
+ tokenUrl: ckboxConfig.tokenUrl,
124
+ serviceOrigin: ckboxConfig.serviceOrigin,
125
+ forceDemoLabel: ckboxConfig.forceDemoLabel,
126
+ choosableFileExtensions: ckboxConfig.choosableFileExtensions,
127
+ assets: {
128
+ onChoose: (assets) => this.fire('ckbox:choose', assets)
129
+ },
130
+ dialog: {
131
+ onClose: () => this.fire('ckbox:close'),
132
+ width: dialog && dialog.width,
133
+ height: dialog && dialog.height
134
+ },
135
+ categories: categories && {
136
+ icons: categories.icons
137
+ },
138
+ view: view && {
139
+ openLastView: view.openLastView,
140
+ startupFolderId: view.startupFolderId,
141
+ startupCategoryId: view.startupCategoryId,
142
+ hideMaximizeButton: view.hideMaximizeButton
143
+ },
144
+ upload: upload && {
145
+ componentsHideTimeout: upload.componentsHideTimeout,
146
+ dialogMinimizeTimeout: upload.dialogMinimizeTimeout
147
+ }
148
+ };
149
+ }
150
+ /**
151
+ * Initializes various event listeners for the `ckbox:*` events, because all functionality of the `ckbox` command is event-based.
152
+ */
153
+ _initListeners() {
154
+ const editor = this.editor;
155
+ const model = editor.model;
156
+ const shouldInsertDataId = !editor.config.get('ckbox.ignoreDataId');
157
+ // Refresh the command after firing the `ckbox:*` event.
158
+ this.on('ckbox', () => {
159
+ this.refresh();
160
+ }, { priority: 'low' });
161
+ // Handle opening of the CKBox dialog.
162
+ this.on('ckbox:open', () => {
163
+ if (!this.isEnabled || this.value) {
164
+ return;
165
+ }
166
+ this._wrapper = createElement(document, 'div', { class: 'ck ckbox-wrapper' });
167
+ document.body.appendChild(this._wrapper);
168
+ window.CKBox.mount(this._wrapper, this._prepareOptions());
169
+ });
170
+ // Handle closing of the CKBox dialog.
171
+ this.on('ckbox:close', () => {
172
+ if (!this.value) {
173
+ return;
174
+ }
175
+ this._wrapper.remove();
176
+ this._wrapper = null;
177
+ editor.editing.view.focus();
178
+ });
179
+ // Handle choosing the assets.
180
+ this.on('ckbox:choose', (evt, assets) => {
181
+ if (!this.isEnabled) {
182
+ return;
183
+ }
184
+ const imageCommand = editor.commands.get('insertImage');
185
+ const linkCommand = editor.commands.get('link');
186
+ const assetsToProcess = prepareAssets({
187
+ assets,
188
+ isImageAllowed: imageCommand.isEnabled,
189
+ isLinkAllowed: linkCommand.isEnabled
190
+ });
191
+ const assetsCount = assetsToProcess.length;
192
+ if (assetsCount === 0) {
193
+ return;
194
+ }
195
+ // All assets are inserted in one undo step.
196
+ model.change(writer => {
197
+ for (const asset of assetsToProcess) {
198
+ const isLastAsset = asset === assetsToProcess[assetsCount - 1];
199
+ const isSingleAsset = assetsCount === 1;
200
+ this._insertAsset(asset, isLastAsset, writer, isSingleAsset);
201
+ // If asset ID must be set for the inserted model element, store the asset temporarily and remove it automatically
202
+ // after the timeout.
203
+ if (shouldInsertDataId) {
204
+ setTimeout(() => this._chosenAssets.delete(asset), ASSET_INSERTION_WAIT_TIMEOUT);
205
+ this._chosenAssets.add(asset);
206
+ }
207
+ }
208
+ });
209
+ editor.editing.view.focus();
210
+ });
211
+ // Clean up after the editor is destroyed.
212
+ this.listenTo(editor, 'destroy', () => {
213
+ this.fire('ckbox:close');
214
+ this._chosenAssets.clear();
215
+ });
216
+ }
217
+ /**
218
+ * Inserts the asset into the model.
219
+ *
220
+ * @param asset The asset to be inserted.
221
+ * @param isLastAsset Indicates if the current asset is the last one from the chosen set.
222
+ * @param writer An instance of the model writer.
223
+ * @param isSingleAsset It's true when only one asset is processed.
224
+ */
225
+ _insertAsset(asset, isLastAsset, writer, isSingleAsset) {
226
+ const editor = this.editor;
227
+ const model = editor.model;
228
+ const selection = model.document.selection;
229
+ // Remove the `linkHref` attribute to not affect the asset to be inserted.
230
+ writer.removeSelectionAttribute('linkHref');
231
+ if (asset.type === 'image') {
232
+ this._insertImage(asset);
233
+ }
234
+ else {
235
+ this._insertLink(asset, writer, isSingleAsset);
236
+ }
237
+ // Except for the last chosen asset, move the selection to the end of the current range to avoid overwriting other, already
238
+ // inserted assets.
239
+ if (!isLastAsset) {
240
+ writer.setSelection(selection.getLastPosition());
241
+ }
242
+ }
243
+ /**
244
+ * Inserts the image by calling the `insertImage` command.
245
+ *
246
+ * @param asset The asset to be inserted.
247
+ */
248
+ _insertImage(asset) {
249
+ const editor = this.editor;
250
+ const { imageFallbackUrl, imageSources, imageTextAlternative, imageWidth, imageHeight, imagePlaceholder } = asset.attributes;
251
+ editor.execute('insertImage', {
252
+ source: {
253
+ src: imageFallbackUrl,
254
+ sources: imageSources,
255
+ alt: imageTextAlternative,
256
+ width: imageWidth,
257
+ height: imageHeight,
258
+ ...(imagePlaceholder ? { placeholder: imagePlaceholder } : null)
259
+ }
260
+ });
261
+ }
262
+ /**
263
+ * Inserts the link to the asset by calling the `link` command.
264
+ *
265
+ * @param asset The asset to be inserted.
266
+ * @param writer An instance of the model writer.
267
+ * @param isSingleAsset It's true when only one asset is processed.
268
+ */
269
+ _insertLink(asset, writer, isSingleAsset) {
270
+ const editor = this.editor;
271
+ const model = editor.model;
272
+ const selection = model.document.selection;
273
+ const { linkName, linkHref } = asset.attributes;
274
+ // If the selection is collapsed, insert the asset name as the link label and select it.
275
+ if (selection.isCollapsed) {
276
+ const selectionAttributes = toMap(selection.getAttributes());
277
+ const textNode = writer.createText(linkName, selectionAttributes);
278
+ if (!isSingleAsset) {
279
+ const selectionLastPosition = selection.getLastPosition();
280
+ const parentElement = selectionLastPosition.parent;
281
+ // Insert new `paragraph` when selection is not in an empty `paragraph`.
282
+ if (!(parentElement.name === 'paragraph' && parentElement.isEmpty)) {
283
+ editor.execute('insertParagraph', {
284
+ position: selectionLastPosition
285
+ });
286
+ }
287
+ const range = model.insertContent(textNode);
288
+ writer.setSelection(range);
289
+ editor.execute('link', linkHref);
290
+ return;
291
+ }
292
+ const range = model.insertContent(textNode);
293
+ writer.setSelection(range);
294
+ }
295
+ editor.execute('link', linkHref);
296
+ }
297
+ }
298
+ /**
299
+ * Parses the chosen assets into the internal data format. Filters out chosen assets that are not allowed.
300
+ */
301
+ function prepareAssets({ assets, isImageAllowed, isLinkAllowed }) {
302
+ return assets
303
+ .map(asset => isImage(asset) ?
304
+ {
305
+ id: asset.data.id,
306
+ type: 'image',
307
+ attributes: prepareImageAssetAttributes(asset)
308
+ } :
309
+ {
310
+ id: asset.data.id,
311
+ type: 'link',
312
+ attributes: prepareLinkAssetAttributes(asset)
313
+ })
314
+ .filter(asset => asset.type === 'image' ? isImageAllowed : isLinkAllowed);
315
+ }
316
+ /**
317
+ * Parses the assets attributes into the internal data format.
318
+ *
319
+ * @internal
320
+ */
321
+ export function prepareImageAssetAttributes(asset) {
322
+ const { imageFallbackUrl, imageSources } = getImageUrls(asset.data.imageUrls);
323
+ const { description, width, height, blurHash } = asset.data.metadata;
324
+ const imagePlaceholder = blurHashToDataUrl(blurHash);
325
+ return {
326
+ imageFallbackUrl,
327
+ imageSources,
328
+ imageTextAlternative: description || '',
329
+ imageWidth: width,
330
+ imageHeight: height,
331
+ ...(imagePlaceholder ? { imagePlaceholder } : null)
332
+ };
333
+ }
334
+ /**
335
+ * Parses the assets attributes into the internal data format.
336
+ *
337
+ * @param origin The base URL for assets inserted into the editor.
338
+ */
339
+ function prepareLinkAssetAttributes(asset) {
340
+ return {
341
+ linkName: asset.data.name,
342
+ linkHref: getAssetUrl(asset)
343
+ };
344
+ }
345
+ /**
346
+ * Checks whether the asset is an image.
347
+ */
348
+ function isImage(asset) {
349
+ const metadata = asset.data.metadata;
350
+ if (!metadata) {
351
+ return false;
352
+ }
353
+ return metadata.width && metadata.height;
354
+ }
355
+ /**
356
+ * Creates the URL for the asset.
357
+ *
358
+ * @param origin The base URL for assets inserted into the editor.
359
+ */
360
+ function getAssetUrl(asset) {
361
+ const url = new URL(asset.data.url);
362
+ url.searchParams.set('download', 'true');
363
+ return url.toString();
364
+ }