@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.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +21 -0
- package/README.md +24 -0
- package/build/ckbox.js +5 -0
- package/build/translations/ar.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/ca.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.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/es-co.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.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/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/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/ko.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/nl.js +1 -0
- package/build/translations/no.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/sk.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/tr.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 +58 -0
- package/dist/augmentation.d.ts +36 -0
- package/dist/ckbox.d.ts +41 -0
- package/dist/ckboxcommand.d.ts +130 -0
- package/dist/ckboxconfig.d.ts +434 -0
- package/dist/ckboxediting.d.ts +65 -0
- package/dist/ckboximageedit/ckboximageeditcommand.d.ts +109 -0
- package/dist/ckboximageedit/ckboximageeditediting.d.ts +36 -0
- package/dist/ckboximageedit/ckboximageeditui.d.ts +32 -0
- package/dist/ckboximageedit/utils.d.ts +14 -0
- package/dist/ckboximageedit.d.ts +32 -0
- package/dist/ckboxui.d.ts +60 -0
- package/dist/ckboxuploadadapter.d.ts +41 -0
- package/dist/ckboxutils.d.ts +58 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +46 -0
- package/dist/index.css +55 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1787 -0
- package/dist/index.js.map +1 -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/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/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.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.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/en.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/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/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/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/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ko.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/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/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/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sk.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/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tr.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/utils.d.ts +67 -0
- package/lang/contexts.json +10 -0
- package/lang/translations/ar.po +50 -0
- package/lang/translations/az.po +50 -0
- package/lang/translations/bg.po +50 -0
- package/lang/translations/bn.po +50 -0
- package/lang/translations/ca.po +50 -0
- package/lang/translations/cs.po +50 -0
- package/lang/translations/da.po +50 -0
- package/lang/translations/de.po +50 -0
- package/lang/translations/el.po +50 -0
- package/lang/translations/en-au.po +50 -0
- package/lang/translations/en.po +50 -0
- package/lang/translations/es-co.po +50 -0
- package/lang/translations/es.po +50 -0
- package/lang/translations/et.po +50 -0
- package/lang/translations/fa.po +50 -0
- package/lang/translations/fi.po +50 -0
- package/lang/translations/fr.po +50 -0
- package/lang/translations/gl.po +50 -0
- package/lang/translations/he.po +50 -0
- package/lang/translations/hi.po +50 -0
- package/lang/translations/hr.po +50 -0
- package/lang/translations/hu.po +50 -0
- package/lang/translations/id.po +50 -0
- package/lang/translations/it.po +50 -0
- package/lang/translations/ja.po +50 -0
- package/lang/translations/ko.po +50 -0
- package/lang/translations/lt.po +50 -0
- package/lang/translations/lv.po +50 -0
- package/lang/translations/ms.po +50 -0
- package/lang/translations/nl.po +50 -0
- package/lang/translations/no.po +50 -0
- package/lang/translations/pl.po +50 -0
- package/lang/translations/pt-br.po +50 -0
- package/lang/translations/pt.po +50 -0
- package/lang/translations/ro.po +50 -0
- package/lang/translations/ru.po +50 -0
- package/lang/translations/sk.po +50 -0
- package/lang/translations/sq.po +50 -0
- package/lang/translations/sr-latn.po +50 -0
- package/lang/translations/sr.po +50 -0
- package/lang/translations/sv.po +50 -0
- package/lang/translations/th.po +50 -0
- package/lang/translations/tr.po +50 -0
- package/lang/translations/ug.po +50 -0
- package/lang/translations/uk.po +50 -0
- package/lang/translations/ur.po +50 -0
- package/lang/translations/uz.po +50 -0
- package/lang/translations/vi.po +50 -0
- package/lang/translations/zh-cn.po +50 -0
- package/lang/translations/zh.po +50 -0
- package/package.json +45 -0
- package/src/augmentation.d.ts +32 -0
- package/src/augmentation.js +5 -0
- package/src/ckbox.d.ts +37 -0
- package/src/ckbox.js +43 -0
- package/src/ckboxcommand.d.ts +126 -0
- package/src/ckboxcommand.js +364 -0
- package/src/ckboxconfig.d.ts +430 -0
- package/src/ckboxconfig.js +5 -0
- package/src/ckboxediting.d.ts +61 -0
- package/src/ckboxediting.js +389 -0
- package/src/ckboximageedit/ckboximageeditcommand.d.ts +105 -0
- package/src/ckboximageedit/ckboximageeditcommand.js +310 -0
- package/src/ckboximageedit/ckboximageeditediting.d.ts +32 -0
- package/src/ckboximageedit/ckboximageeditediting.js +42 -0
- package/src/ckboximageedit/ckboximageeditui.d.ts +28 -0
- package/src/ckboximageedit/ckboximageeditui.js +57 -0
- package/src/ckboximageedit/utils.d.ts +10 -0
- package/src/ckboximageedit/utils.js +48 -0
- package/src/ckboximageedit.d.ts +28 -0
- package/src/ckboximageedit.js +34 -0
- package/src/ckboxui.d.ts +56 -0
- package/src/ckboxui.js +136 -0
- package/src/ckboxuploadadapter.d.ts +37 -0
- package/src/ckboxuploadadapter.js +136 -0
- package/src/ckboxutils.d.ts +54 -0
- package/src/ckboxutils.js +189 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +14 -0
- package/src/utils.d.ts +63 -0
- package/src/utils.js +175 -0
- package/theme/ckboximageedit.css +53 -0
- 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
|
+
}
|
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
|
+
}
|