@ckeditor/ckeditor5-ckfinder 36.0.1 → 37.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.
package/build/ckfinder.js CHANGED
@@ -2,4 +2,4 @@
2
2
  /*!
3
3
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
4
4
  * For licensing, see LICENSE.md.
5
- */(()=>{var e={704:(e,i,t)=>{e.exports=t(79)("./src/core.js")},273:(e,i,t)=>{e.exports=t(79)("./src/ui.js")},209:(e,i,t)=>{e.exports=t(79)("./src/utils.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},i={};function t(n){var o=i[n];if(void 0!==o)return o.exports;var r=i[n]={exports:{}};return e[n](r,r.exports,t),r.exports}t.d=(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},t.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";t.r(n),t.d(n,{CKFinder:()=>c,CKFinderEditing:()=>d,CKFinderUI:()=>o});var e=t(704),i=t(273);class o extends e.Plugin{static get pluginName(){return"CKFinderUI"}init(){const e=this.editor,t=e.ui.componentFactory,n=e.t;t.add("ckfinder",(t=>{const o=e.commands.get("ckfinder"),r=new i.ButtonView(t);return r.set({label:n("Insert image or file"),icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M11.627 16.5zm5.873-.196zm0-7.001V8h-13v8.5h4.341c.191.54.457 1.044.785 1.5H2a1.5 1.5 0 0 1-1.5-1.5v-13A1.5 1.5 0 0 1 2 2h4.5a1.5 1.5 0 0 1 1.06.44L9.122 4H16a1.5 1.5 0 0 1 1.5 1.5v1A1.5 1.5 0 0 1 19 8v2.531a6.027 6.027 0 0 0-1.5-1.228zM16 6.5v-1H8.5l-2-2H2v13h1V8a1.5 1.5 0 0 1 1.5-1.5H16z"/><path d="M14.5 19.5a5 5 0 1 1 0-10 5 5 0 0 1 0 10zM15 14v-2h-1v2h-2v1h2v2h1v-2h2v-1h-2z"/></svg>',tooltip:!0}),r.bind("isEnabled").to(o),r.on("execute",(()=>{e.execute("ckfinder"),e.editing.view.focus()})),r}))}}var r=t(209);class s extends e.Command{constructor(e){super(e),this._affectsData=!1,this.stopListening(this.editor.model.document,"change"),this.listenTo(this.editor.model.document,"change",(()=>this.refresh()),{priority:"low"})}refresh(){const e=this.editor.commands.get("insertImage"),i=this.editor.commands.get("link");this.isEnabled=e.isEnabled||i.isEnabled}execute(){const e=this.editor,i=this.editor.config.get("ckfinder.openerMethod")||"modal";if("popup"!=i&&"modal"!=i)throw new r.CKEditorError("ckfinder-unknown-openermethod",e);const t=this.editor.config.get("ckfinder.options")||{};t.chooseFiles=!0;const n=t.onInit;t.language||(t.language=e.locale.uiLanguage),t.onInit=i=>{n&&n(i),i.on("files:choose",(t=>{const n=t.data.files.toArray(),o=n.filter((e=>!e.isImage())),r=n.filter((e=>e.isImage()));for(const i of o)e.execute("link",i.getUrl());const s=[];for(const e of r){const t=e.getUrl();s.push(t||i.request("file:getProxyUrl",{file:e}))}s.length&&a(e,s)})),i.on("file:choose:resizedImage",(i=>{const t=i.data.resizedUrl;if(t)a(e,[t]);else{const i=e.plugins.get("Notification"),t=e.locale.t;i.showWarning(t("Could not obtain resized image URL."),{title:t("Selecting resized image failed"),namespace:"ckfinder"})}}))},window.CKFinder[i](t)}}function a(e,i){if(e.commands.get("insertImage").isEnabled)e.execute("insertImage",{source:i});else{const i=e.plugins.get("Notification"),t=e.locale.t;i.showWarning(t("Could not insert image at the current position."),{title:t("Inserting image failed"),namespace:"ckfinder"})}}class d extends e.Plugin{static get pluginName(){return"CKFinderEditing"}static get requires(){return[i.Notification,"LinkEditing"]}init(){const e=this.editor;if(!e.plugins.has("ImageBlockEditing")&&!e.plugins.has("ImageInlineEditing"))throw new r.CKEditorError("ckfinder-missing-image-plugin",e);e.commands.add("ckfinder",new s(e))}}class c extends e.Plugin{static get pluginName(){return"CKFinder"}static get requires(){return["Link","CKFinderUploadAdapter",d,o]}}})(),(window.CKEditor5=window.CKEditor5||{}).ckfinder=n})();
5
+ */(()=>{var e={704:(e,i,t)=>{e.exports=t(79)("./src/core.js")},273:(e,i,t)=>{e.exports=t(79)("./src/ui.js")},209:(e,i,t)=>{e.exports=t(79)("./src/utils.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},i={};function t(n){var o=i[n];if(void 0!==o)return o.exports;var r=i[n]={exports:{}};return e[n](r,r.exports,t),r.exports}t.d=(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},t.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";t.r(n),t.d(n,{CKFinder:()=>c,CKFinderEditing:()=>d,CKFinderUI:()=>o});var e=t(704),i=t(273);class o extends e.Plugin{static get pluginName(){return"CKFinderUI"}init(){const e=this.editor,t=e.ui.componentFactory,n=e.t;t.add("ckfinder",(t=>{const o=e.commands.get("ckfinder"),r=new i.ButtonView(t);return r.set({label:n("Insert image or file"),icon:'<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M11.627 16.5zm5.873-.196zm0-7.001V8h-13v8.5h4.341c.191.54.457 1.044.785 1.5H2a1.5 1.5 0 0 1-1.5-1.5v-13A1.5 1.5 0 0 1 2 2h4.5a1.5 1.5 0 0 1 1.06.44L9.122 4H16a1.5 1.5 0 0 1 1.5 1.5v1A1.5 1.5 0 0 1 19 8v2.531a6.027 6.027 0 0 0-1.5-1.228zM16 6.5v-1H8.5l-2-2H2v13h1V8a1.5 1.5 0 0 1 1.5-1.5H16z"/><path d="M14.5 19.5a5 5 0 1 1 0-10 5 5 0 0 1 0 10zM15 14v-2h-1v2h-2v1h2v2h1v-2h2v-1h-2z"/></svg>',tooltip:!0}),r.bind("isEnabled").to(o),r.on("execute",(()=>{e.execute("ckfinder"),e.editing.view.focus()})),r}))}}var r=t(209);class s extends e.Command{constructor(e){super(e),this.affectsData=!1,this.stopListening(this.editor.model.document,"change"),this.listenTo(this.editor.model.document,"change",(()=>this.refresh()),{priority:"low"})}refresh(){const e=this.editor.commands.get("insertImage"),i=this.editor.commands.get("link");this.isEnabled=e.isEnabled||i.isEnabled}execute(){const e=this.editor,i=this.editor.config.get("ckfinder.openerMethod")||"modal";if("popup"!=i&&"modal"!=i)throw new r.CKEditorError("ckfinder-unknown-openermethod",e);const t=this.editor.config.get("ckfinder.options")||{};t.chooseFiles=!0;const n=t.onInit;t.language||(t.language=e.locale.uiLanguage),t.onInit=i=>{n&&n(i),i.on("files:choose",(t=>{const n=t.data.files.toArray(),o=n.filter((e=>!e.isImage())),r=n.filter((e=>e.isImage()));for(const i of o)e.execute("link",i.getUrl());const s=[];for(const e of r){const t=e.getUrl();s.push(t||i.request("file:getProxyUrl",{file:e}))}s.length&&a(e,s)})),i.on("file:choose:resizedImage",(i=>{const t=i.data.resizedUrl;if(t)a(e,[t]);else{const i=e.plugins.get("Notification"),t=e.locale.t;i.showWarning(t("Could not obtain resized image URL."),{title:t("Selecting resized image failed"),namespace:"ckfinder"})}}))},window.CKFinder[i](t)}}function a(e,i){if(e.commands.get("insertImage").isEnabled)e.execute("insertImage",{source:i});else{const i=e.plugins.get("Notification"),t=e.locale.t;i.showWarning(t("Could not insert image at the current position."),{title:t("Inserting image failed"),namespace:"ckfinder"})}}class d extends e.Plugin{static get pluginName(){return"CKFinderEditing"}static get requires(){return[i.Notification,"LinkEditing"]}init(){const e=this.editor;if(!e.plugins.has("ImageBlockEditing")&&!e.plugins.has("ImageInlineEditing"))throw new r.CKEditorError("ckfinder-missing-image-plugin",e);e.commands.add("ckfinder",new s(e))}}class c extends e.Plugin{static get pluginName(){return"CKFinder"}static get requires(){return["Link","CKFinderUploadAdapter",d,o]}}})(),(window.CKEditor5=window.CKEditor5||{}).ckfinder=n})();
@@ -4,7 +4,7 @@
4
4
  "name": "CKFinder",
5
5
  "className": "CKFinder",
6
6
  "description": "An image upload tool. It provides a full, server-side and client-side integration with CKFinder and all its features, including multiple file uploads, image editor and file management.",
7
- "docs": "features/images/image-upload/ckfinder.html",
7
+ "docs": "features/file-management/ckfinder.html",
8
8
  "path": "src/ckfinder.js",
9
9
  "requires": [
10
10
  "CKFinderUploadAdapter",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-ckfinder",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "CKFinder integration for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,21 +12,22 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "^36.0.1"
15
+ "ckeditor5": "^37.0.0-alpha.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-adapter-ckfinder": "^36.0.1",
19
- "@ckeditor/ckeditor5-clipboard": "^36.0.1",
20
- "@ckeditor/ckeditor5-core": "^36.0.1",
21
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
22
- "@ckeditor/ckeditor5-editor-classic": "^36.0.1",
23
- "@ckeditor/ckeditor5-engine": "^36.0.1",
24
- "@ckeditor/ckeditor5-image": "^36.0.1",
25
- "@ckeditor/ckeditor5-link": "^36.0.1",
26
- "@ckeditor/ckeditor5-paragraph": "^36.0.1",
27
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
28
- "@ckeditor/ckeditor5-ui": "^36.0.1",
29
- "@ckeditor/ckeditor5-utils": "^36.0.1",
18
+ "@ckeditor/ckeditor5-adapter-ckfinder": "^37.0.0-alpha.0",
19
+ "@ckeditor/ckeditor5-clipboard": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
21
+ "@ckeditor/ckeditor5-dev-utils": "^34.0.0",
22
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
23
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.0",
25
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.0",
26
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
27
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.0",
28
+ "@ckeditor/ckeditor5-ui": "^37.0.0-alpha.0",
29
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
30
+ "typescript": "^4.8.4",
30
31
  "webpack": "^5.58.1",
31
32
  "webpack-cli": "^4.9.0"
32
33
  },
@@ -45,13 +46,17 @@
45
46
  },
46
47
  "files": [
47
48
  "lang",
48
- "src",
49
+ "src/**/*.js",
50
+ "src/**/*.d.ts",
49
51
  "theme",
50
52
  "build",
51
53
  "ckeditor5-metadata.json",
52
54
  "CHANGELOG.md"
53
55
  ],
54
56
  "scripts": {
55
- "dll:build": "webpack"
56
- }
57
+ "dll:build": "webpack",
58
+ "build": "tsc -p ./tsconfig.release.json",
59
+ "postversion": "npm run build"
60
+ },
61
+ "types": "src/index.d.ts"
57
62
  }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder/ckfinder
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * The CKFinder feature, a bridge between the CKEditor 5 WYSIWYG editor and the
11
+ * [CKFinder](https://ckeditor.com/ckfinder) file manager and uploader.
12
+ *
13
+ * This is a "glue" plugin which enables:
14
+ *
15
+ * * {@link module:ckfinder/ckfinderediting~CKFinderEditing},
16
+ * * {@link module:ckfinder/ckfinderui~CKFinderUI},
17
+ * * {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter}.
18
+ *
19
+ * See the {@glink features/images/image-upload/ckfinder "CKFinder integration" guide} to learn how to configure
20
+ * and use this feature.
21
+ *
22
+ * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload" guide} to learn about
23
+ * other ways to upload images into CKEditor 5.
24
+ */
25
+ export default class CKFinder extends Plugin {
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get pluginName(): 'CKFinder';
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get requires(): PluginDependencies;
34
+ }
35
+ declare module '@ckeditor/ckeditor5-core' {
36
+ interface PluginsMap {
37
+ [CKFinder.pluginName]: CKFinder;
38
+ }
39
+ }
package/src/ckfinder.js CHANGED
@@ -2,16 +2,12 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module ckfinder/ckfinder
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import CKFinderUI from './ckfinderui';
13
10
  import CKFinderEditing from './ckfinderediting';
14
-
15
11
  /**
16
12
  * The CKFinder feature, a bridge between the CKEditor 5 WYSIWYG editor and the
17
13
  * [CKFinder](https://ckeditor.com/ckfinder) file manager and uploader.
@@ -27,93 +23,18 @@ import CKFinderEditing from './ckfinderediting';
27
23
  *
28
24
  * Check out the {@glink features/images/image-upload/image-upload comprehensive "Image upload" guide} to learn about
29
25
  * other ways to upload images into CKEditor 5.
30
- *
31
- * @extends module:core/plugin~Plugin
32
26
  */
33
27
  export default class CKFinder extends Plugin {
34
- /**
35
- * @inheritDoc
36
- */
37
- static get pluginName() {
38
- return 'CKFinder';
39
- }
40
-
41
- /**
42
- * @inheritDoc
43
- */
44
- static get requires() {
45
- return [ 'Link', 'CKFinderUploadAdapter', CKFinderEditing, CKFinderUI ];
46
- }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName() {
32
+ return 'CKFinder';
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ static get requires() {
38
+ return ['Link', 'CKFinderUploadAdapter', CKFinderEditing, CKFinderUI];
39
+ }
47
40
  }
48
-
49
- /**
50
- * The configuration of the {@link module:ckfinder/ckfinder~CKFinder CKFinder feature}.
51
- *
52
- * Read more in {@link module:ckfinder/ckfinder~CKFinderConfig}.
53
- *
54
- * @member {module:ckfinder/ckfinder~CKFinderConfig} module:core/editor/editorconfig~EditorConfig#ckfinder
55
- */
56
-
57
- /**
58
- * The configuration of the {@link module:ckfinder/ckfinder~CKFinder CKFinder feature}
59
- * and its {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter upload adapter}.
60
- *
61
- * ClassicEditor
62
- * .create( editorElement, {
63
- * ckfinder: {
64
- * options: {
65
- * resourceType: 'Images'
66
- * }
67
- * }
68
- * } )
69
- * .then( ... )
70
- * .catch( ... );
71
- *
72
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
73
- *
74
- * @interface CKFinderConfig
75
- */
76
-
77
- /**
78
- * The configuration options passed to the CKFinder file manager instance.
79
- *
80
- * Check the file manager [documentation](https://ckeditor.com/docs/ckfinder/ckfinder3/#!/api/CKFinder.Config-cfg-language)
81
- * for the complete list of options.
82
- *
83
- * @member {Object} module:ckfinder/ckfinder~CKFinderConfig#options
84
- */
85
-
86
- /**
87
- * The type of the CKFinder opener method.
88
- *
89
- * Supported types are:
90
- *
91
- * * `'modal'` &ndash; Opens CKFinder in a modal,
92
- * * `'popup'` &ndash; Opens CKFinder in a new "pop-up" window.
93
- *
94
- * Defaults to `'modal'`.
95
- *
96
- * @member {String} module:ckfinder/ckfinder~CKFinderConfig#openerMethod
97
- */
98
-
99
- /**
100
- * The path (URL) to the connector which handles the file upload in CKFinder file manager.
101
- * When specified, it enables the automatic upload of resources such as images inserted into the content.
102
- *
103
- * For instance, to use CKFinder's
104
- * [quick upload](https://ckeditor.com/docs/ckfinder/ckfinder3-php/commands.html#command_quick_upload)
105
- * command, your can use the following (or similar) path:
106
- *
107
- * ClassicEditor
108
- * .create( editorElement, {
109
- * ckfinder: {
110
- * uploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json'
111
- * }
112
- * } )
113
- * .then( ... )
114
- * .catch( ... );
115
- *
116
- * Used by the {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter upload adapter}.
117
- *
118
- * @member {String} module:ckfinder/ckfinder~CKFinderConfig#uploadUrl
119
- */
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder/ckfindercommand
7
+ */
8
+ import { Command, type Editor } from 'ckeditor5/src/core';
9
+ import './ckfinderconfig';
10
+ /**
11
+ * The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing CKFinder editing feature}
12
+ * to open the CKFinder file manager to insert an image or a link to a file into the editor content.
13
+ *
14
+ * ```ts
15
+ * editor.execute( 'ckfinder' );
16
+ * ```
17
+ *
18
+ * **Note:** This command uses other features to perform tasks:
19
+ * - To insert images the {@link module:image/image/insertimagecommand~InsertImageCommand 'insertImage'} command
20
+ * from the {@link module:image/image~Image Image feature}.
21
+ * - To insert links to files the {@link module:link/linkcommand~LinkCommand 'link'} command
22
+ * from the {@link module:link/link~Link Link feature}.
23
+ */
24
+ export default class CKFinderCommand extends Command {
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ constructor(editor: Editor);
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ refresh(): void;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ execute(): void;
37
+ }
38
+ declare module '@ckeditor/ckeditor5-core' {
39
+ interface CommandsMap {
40
+ ckfinder: CKFinderCommand;
41
+ }
42
+ }
@@ -2,156 +2,122 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /* global window */
7
-
8
6
  /**
9
7
  * @module ckfinder/ckfindercommand
10
8
  */
11
-
12
9
  import { Command } from 'ckeditor5/src/core';
13
10
  import { CKEditorError } from 'ckeditor5/src/utils';
14
-
11
+ import './ckfinderconfig';
15
12
  /**
16
13
  * The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing CKFinder editing feature}
17
14
  * to open the CKFinder file manager to insert an image or a link to a file into the editor content.
18
15
  *
19
- * editor.execute( 'ckfinder' );
16
+ * ```ts
17
+ * editor.execute( 'ckfinder' );
18
+ * ```
20
19
  *
21
20
  * **Note:** This command uses other features to perform tasks:
22
21
  * - To insert images the {@link module:image/image/insertimagecommand~InsertImageCommand 'insertImage'} command
23
22
  * from the {@link module:image/image~Image Image feature}.
24
23
  * - To insert links to files the {@link module:link/linkcommand~LinkCommand 'link'} command
25
24
  * from the {@link module:link/link~Link Link feature}.
26
- *
27
- * @extends module:core/command~Command
28
25
  */
29
26
  export default class CKFinderCommand extends Command {
30
- /**
31
- * @inheritDoc
32
- */
33
- constructor( editor ) {
34
- super( editor );
35
-
36
- // The CKFinder command does not affect data by itself.
37
- this._affectsData = false;
38
-
39
- // Remove default document listener to lower its priority.
40
- this.stopListening( this.editor.model.document, 'change' );
41
-
42
- // Lower this command listener priority to be sure that refresh() will be called after link & image refresh.
43
- this.listenTo( this.editor.model.document, 'change', () => this.refresh(), { priority: 'low' } );
44
- }
45
-
46
- /**
47
- * @inheritDoc
48
- */
49
- refresh() {
50
- const imageCommand = this.editor.commands.get( 'insertImage' );
51
- const linkCommand = this.editor.commands.get( 'link' );
52
-
53
- // The CKFinder command is enabled when one of image or link command is enabled.
54
- this.isEnabled = imageCommand.isEnabled || linkCommand.isEnabled;
55
- }
56
-
57
- /**
58
- * @inheritDoc
59
- */
60
- execute() {
61
- const editor = this.editor;
62
-
63
- const openerMethod = this.editor.config.get( 'ckfinder.openerMethod' ) || 'modal';
64
-
65
- if ( openerMethod != 'popup' && openerMethod != 'modal' ) {
66
- /**
67
- * The `ckfinder.openerMethod` must be one of: "popup" or "modal".
68
- *
69
- * @error ckfinder-unknown-openermethod
70
- */
71
- throw new CKEditorError( 'ckfinder-unknown-openermethod', editor );
72
- }
73
-
74
- const options = this.editor.config.get( 'ckfinder.options' ) || {};
75
-
76
- options.chooseFiles = true;
77
-
78
- // Cache the user-defined onInit method
79
- const originalOnInit = options.onInit;
80
-
81
- // Pass the lang code to the CKFinder if not defined by user.
82
- if ( !options.language ) {
83
- options.language = editor.locale.uiLanguage;
84
- }
85
-
86
- // The onInit method allows to extend CKFinder's behavior. It is used to attach event listeners to file choosing related events.
87
- options.onInit = finder => {
88
- // Call original options.onInit if it was defined by user.
89
- if ( originalOnInit ) {
90
- originalOnInit( finder );
91
- }
92
-
93
- finder.on( 'files:choose', evt => {
94
- const files = evt.data.files.toArray();
95
-
96
- // Insert links
97
- const links = files.filter( file => !file.isImage() );
98
- const images = files.filter( file => file.isImage() );
99
-
100
- for ( const linkFile of links ) {
101
- editor.execute( 'link', linkFile.getUrl() );
102
- }
103
-
104
- const imagesUrls = [];
105
-
106
- for ( const image of images ) {
107
- const url = image.getUrl();
108
-
109
- imagesUrls.push( url ? url : finder.request( 'file:getProxyUrl', { file: image } ) );
110
- }
111
-
112
- if ( imagesUrls.length ) {
113
- insertImages( editor, imagesUrls );
114
- }
115
- } );
116
-
117
- finder.on( 'file:choose:resizedImage', evt => {
118
- const resizedUrl = evt.data.resizedUrl;
119
-
120
- if ( !resizedUrl ) {
121
- const notification = editor.plugins.get( 'Notification' );
122
- const t = editor.locale.t;
123
-
124
- notification.showWarning( t( 'Could not obtain resized image URL.' ), {
125
- title: t( 'Selecting resized image failed' ),
126
- namespace: 'ckfinder'
127
- } );
128
-
129
- return;
130
- }
131
-
132
- insertImages( editor, [ resizedUrl ] );
133
- } );
134
- };
135
-
136
- window.CKFinder[ openerMethod ]( options );
137
- }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ constructor(editor) {
31
+ super(editor);
32
+ // The CKFinder command does not affect data by itself.
33
+ this.affectsData = false;
34
+ // Remove default document listener to lower its priority.
35
+ this.stopListening(this.editor.model.document, 'change');
36
+ // Lower this command listener priority to be sure that refresh() will be called after link & image refresh.
37
+ this.listenTo(this.editor.model.document, 'change', () => this.refresh(), { priority: 'low' });
38
+ }
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ refresh() {
43
+ const imageCommand = this.editor.commands.get('insertImage');
44
+ const linkCommand = this.editor.commands.get('link');
45
+ // The CKFinder command is enabled when one of image or link command is enabled.
46
+ this.isEnabled = imageCommand.isEnabled || linkCommand.isEnabled;
47
+ }
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ execute() {
52
+ const editor = this.editor;
53
+ const openerMethod = this.editor.config.get('ckfinder.openerMethod') || 'modal';
54
+ if (openerMethod != 'popup' && openerMethod != 'modal') {
55
+ /**
56
+ * The `ckfinder.openerMethod` must be one of: "popup" or "modal".
57
+ *
58
+ * @error ckfinder-unknown-openermethod
59
+ */
60
+ throw new CKEditorError('ckfinder-unknown-openermethod', editor);
61
+ }
62
+ const options = this.editor.config.get('ckfinder.options') || {};
63
+ options.chooseFiles = true;
64
+ // Cache the user-defined onInit method
65
+ const originalOnInit = options.onInit;
66
+ // Pass the lang code to the CKFinder if not defined by user.
67
+ if (!options.language) {
68
+ options.language = editor.locale.uiLanguage;
69
+ }
70
+ // The onInit method allows to extend CKFinder's behavior. It is used to attach event listeners to file choosing related events.
71
+ options.onInit = finder => {
72
+ // Call original options.onInit if it was defined by user.
73
+ if (originalOnInit) {
74
+ originalOnInit(finder);
75
+ }
76
+ finder.on('files:choose', (evt) => {
77
+ const files = evt.data.files.toArray();
78
+ // Insert links
79
+ const links = files.filter((file) => !file.isImage());
80
+ const images = files.filter((file) => file.isImage());
81
+ for (const linkFile of links) {
82
+ editor.execute('link', linkFile.getUrl());
83
+ }
84
+ const imagesUrls = [];
85
+ for (const image of images) {
86
+ const url = image.getUrl();
87
+ imagesUrls.push(url ? url : finder.request('file:getProxyUrl', { file: image }));
88
+ }
89
+ if (imagesUrls.length) {
90
+ insertImages(editor, imagesUrls);
91
+ }
92
+ });
93
+ finder.on('file:choose:resizedImage', (evt) => {
94
+ const resizedUrl = evt.data.resizedUrl;
95
+ if (!resizedUrl) {
96
+ const notification = editor.plugins.get('Notification');
97
+ const t = editor.locale.t;
98
+ notification.showWarning(t('Could not obtain resized image URL.'), {
99
+ title: t('Selecting resized image failed'),
100
+ namespace: 'ckfinder'
101
+ });
102
+ return;
103
+ }
104
+ insertImages(editor, [resizedUrl]);
105
+ });
106
+ };
107
+ window.CKFinder[openerMethod](options);
108
+ }
138
109
  }
139
-
140
- function insertImages( editor, urls ) {
141
- const imageCommand = editor.commands.get( 'insertImage' );
142
-
143
- // Check if inserting an image is actually possible - it might be possible to only insert a link.
144
- if ( !imageCommand.isEnabled ) {
145
- const notification = editor.plugins.get( 'Notification' );
146
- const t = editor.locale.t;
147
-
148
- notification.showWarning( t( 'Could not insert image at the current position.' ), {
149
- title: t( 'Inserting image failed' ),
150
- namespace: 'ckfinder'
151
- } );
152
-
153
- return;
154
- }
155
-
156
- editor.execute( 'insertImage', { source: urls } );
110
+ function insertImages(editor, urls) {
111
+ const imageCommand = editor.commands.get('insertImage');
112
+ // Check if inserting an image is actually possible - it might be possible to only insert a link.
113
+ if (!imageCommand.isEnabled) {
114
+ const notification = editor.plugins.get('Notification');
115
+ const t = editor.locale.t;
116
+ notification.showWarning(t('Could not insert image at the current position.'), {
117
+ title: t('Inserting image failed'),
118
+ namespace: 'ckfinder'
119
+ });
120
+ return;
121
+ }
122
+ editor.execute('insertImage', { source: urls });
157
123
  }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder/ckfinder
7
+ */
8
+ /**
9
+ * The configuration of the {@link module:ckfinder/ckfinder~CKFinder CKFinder feature}
10
+ * and its {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter upload adapter}.
11
+ *
12
+ * ```
13
+ * ClassicEditor
14
+ * .create( editorElement, {
15
+ * ckfinder: {
16
+ * options: {
17
+ * resourceType: 'Images'
18
+ * }
19
+ * }
20
+ * } )
21
+ * .then( ... )
22
+ * .catch( ... );
23
+ * ```
24
+ *
25
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
26
+ */
27
+ export interface CKFinderConfig {
28
+ /**
29
+ * The configuration options passed to the CKFinder file manager instance.
30
+ *
31
+ * Check the file manager [documentation](https://ckeditor.com/docs/ckfinder/ckfinder3/#!/api/CKFinder.Config-cfg-language)
32
+ * for the complete list of options.
33
+ */
34
+ options?: CKFinderOptions;
35
+ /**
36
+ * The type of the CKFinder opener method.
37
+ *
38
+ * Supported types are:
39
+ *
40
+ * * `'modal'` &ndash; Opens CKFinder in a modal,
41
+ * * `'popup'` &ndash; Opens CKFinder in a new "pop-up" window.
42
+ *
43
+ * Defaults to `'modal'`.
44
+ */
45
+ openerMethod?: 'modal' | 'popup';
46
+ /**
47
+ * The path (URL) to the connector which handles the file upload in CKFinder file manager.
48
+ * When specified, it enables the automatic upload of resources such as images inserted into the content.
49
+ *
50
+ * For instance, to use CKFinder's
51
+ * [quick upload](https://ckeditor.com/docs/ckfinder/ckfinder3-php/commands.html#command_quick_upload)
52
+ * command, your can use the following (or similar) path:
53
+ *
54
+ * ```ts
55
+ * ClassicEditor
56
+ * .create( editorElement, {
57
+ * ckfinder: {
58
+ * uploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json'
59
+ * }
60
+ * } )
61
+ * .then( ... )
62
+ * .catch( ... );
63
+ * ```
64
+ *
65
+ * Used by the {@link module:adapter-ckfinder/uploadadapter~CKFinderUploadAdapter upload adapter}.
66
+ */
67
+ uploadUrl?: string;
68
+ }
69
+ export interface CKFinderOptions extends Record<string, unknown> {
70
+ chooseFiles?: boolean;
71
+ onInit?: (finder: any) => void;
72
+ language?: string;
73
+ }
74
+ declare module '@ckeditor/ckeditor5-core' {
75
+ interface EditorConfig {
76
+ /**
77
+ * The configuration of the {@link module:ckfinder/ckfinder~CKFinder CKFinder feature}.
78
+ *
79
+ * Read more in {@link module:ckfinder/ckfinder~CKFinderConfig}.
80
+ */
81
+ ckfinder?: CKFinderConfig;
82
+ }
83
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder/ckfinderediting
7
+ */
8
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
9
+ /**
10
+ * The CKFinder editing feature. It introduces the {@link module:ckfinder/ckfindercommand~CKFinderCommand CKFinder command}.
11
+ */
12
+ export default class CKFinderEditing extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): 'CKFinderEditing';
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get requires(): PluginDependencies;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init(): void;
25
+ }
26
+ declare module '@ckeditor/ckeditor5-core' {
27
+ interface PluginsMap {
28
+ [CKFinderEditing.pluginName]: CKFinderEditing;
29
+ }
30
+ }
@@ -2,59 +2,49 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module ckfinder/ckfinderediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { Notification } from 'ckeditor5/src/ui';
12
10
  import { CKEditorError } from 'ckeditor5/src/utils';
13
-
14
11
  import CKFinderCommand from './ckfindercommand';
15
-
16
12
  /**
17
13
  * The CKFinder editing feature. It introduces the {@link module:ckfinder/ckfindercommand~CKFinderCommand CKFinder command}.
18
- *
19
- * @extends module:core/plugin~Plugin
20
14
  */
21
15
  export default class CKFinderEditing extends Plugin {
22
- /**
23
- * @inheritDoc
24
- */
25
- static get pluginName() {
26
- return 'CKFinderEditing';
27
- }
28
-
29
- /**
30
- * @inheritDoc
31
- */
32
- static get requires() {
33
- return [ Notification, 'LinkEditing' ];
34
- }
35
-
36
- /**
37
- * @inheritDoc
38
- */
39
- init() {
40
- const editor = this.editor;
41
-
42
- if ( !editor.plugins.has( 'ImageBlockEditing' ) && !editor.plugins.has( 'ImageInlineEditing' ) ) {
43
- /**
44
- * CKFinder requires at least one plugin providing support for images loaded in the editor. Please
45
- * make sure either:
46
- *
47
- * * {@link module:image/image~Image} (which loads both types of images),
48
- * * or {@link module:image/imageblock~ImageBlock},
49
- * * or {@link module:image/imageinline~ImageInline}.
50
- *
51
- * is loaded in your editor configuration.
52
- *
53
- * @error ckfinder-missing-image-plugin
54
- */
55
- throw new CKEditorError( 'ckfinder-missing-image-plugin', editor );
56
- }
57
-
58
- editor.commands.add( 'ckfinder', new CKFinderCommand( editor ) );
59
- }
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName() {
20
+ return 'CKFinderEditing';
21
+ }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires() {
26
+ return [Notification, 'LinkEditing'];
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init() {
32
+ const editor = this.editor;
33
+ if (!editor.plugins.has('ImageBlockEditing') && !editor.plugins.has('ImageInlineEditing')) {
34
+ /**
35
+ * CKFinder requires at least one plugin providing support for images loaded in the editor. Please
36
+ * make sure either:
37
+ *
38
+ * * {@link module:image/image~Image} (which loads both types of images),
39
+ * * or {@link module:image/imageblock~ImageBlock},
40
+ * * or {@link module:image/imageinline~ImageInline}.
41
+ *
42
+ * is loaded in your editor configuration.
43
+ *
44
+ * @error ckfinder-missing-image-plugin
45
+ */
46
+ throw new CKEditorError('ckfinder-missing-image-plugin', editor);
47
+ }
48
+ editor.commands.add('ckfinder', new CKFinderCommand(editor));
49
+ }
60
50
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder/ckfinderui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ /**
10
+ * The CKFinder UI plugin. It introduces the `'ckfinder'` toolbar button.
11
+ */
12
+ export default class CKFinderUI extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): 'CKFinderUI';
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ init(): void;
21
+ }
package/src/ckfinderui.js CHANGED
@@ -2,56 +2,43 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module ckfinder/ckfinderui
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { ButtonView } from 'ckeditor5/src/ui';
12
-
13
10
  import browseFilesIcon from '../theme/icons/browse-files.svg';
14
-
15
11
  /**
16
12
  * The CKFinder UI plugin. It introduces the `'ckfinder'` toolbar button.
17
- *
18
- * @extends module:core/plugin~Plugin
19
13
  */
20
14
  export default class CKFinderUI extends Plugin {
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName() {
25
- return 'CKFinderUI';
26
- }
27
-
28
- /**
29
- * @inheritDoc
30
- */
31
- init() {
32
- const editor = this.editor;
33
- const componentFactory = editor.ui.componentFactory;
34
- const t = editor.t;
35
-
36
- componentFactory.add( 'ckfinder', locale => {
37
- const command = editor.commands.get( 'ckfinder' );
38
-
39
- const button = new ButtonView( locale );
40
-
41
- button.set( {
42
- label: t( 'Insert image or file' ),
43
- icon: browseFilesIcon,
44
- tooltip: true
45
- } );
46
-
47
- button.bind( 'isEnabled' ).to( command );
48
-
49
- button.on( 'execute', () => {
50
- editor.execute( 'ckfinder' );
51
- editor.editing.view.focus();
52
- } );
53
-
54
- return button;
55
- } );
56
- }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get pluginName() {
19
+ return 'CKFinderUI';
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ init() {
25
+ const editor = this.editor;
26
+ const componentFactory = editor.ui.componentFactory;
27
+ const t = editor.t;
28
+ componentFactory.add('ckfinder', locale => {
29
+ const command = editor.commands.get('ckfinder');
30
+ const button = new ButtonView(locale);
31
+ button.set({
32
+ label: t('Insert image or file'),
33
+ icon: browseFilesIcon,
34
+ tooltip: true
35
+ });
36
+ button.bind('isEnabled').to(command);
37
+ button.on('execute', () => {
38
+ editor.execute('ckfinder');
39
+ editor.editing.view.focus();
40
+ });
41
+ return button;
42
+ });
43
+ }
57
44
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 ckfinder
7
+ */
8
+ export { default as CKFinder } from './ckfinder';
9
+ export { default as CKFinderEditing } from './ckfinderediting';
10
+ export { default as CKFinderUI } from './ckfinderui';
11
+ export type { CKFinderConfig } from './ckfinderconfig';
package/src/index.js CHANGED
@@ -2,11 +2,9 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module ckfinder
8
7
  */
9
-
10
8
  export { default as CKFinder } from './ckfinder';
11
9
  export { default as CKFinderEditing } from './ckfinderediting';
12
10
  export { default as CKFinderUI } from './ckfinderui';