@ckeditor/ckeditor5-editor-decoupled 36.0.1 → 37.0.0-alpha.1

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.
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
- */(()=>{var t={704:(t,e,o)=>{t.exports=o(79)("./src/core.js")},492:(t,e,o)=>{t.exports=o(79)("./src/engine.js")},273:(t,e,o)=>{t.exports=o(79)("./src/ui.js")},209:(t,e,o)=>{t.exports=o(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function o(r){var i=e[r];if(void 0!==i)return i.exports;var n=e[r]={exports:{}};return t[r](n,n.exports,o),n.exports}o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";o.r(r),o.d(r,{DecoupledEditor:()=>_});var t=o(704),e=o(209),i=o(273),n=o(492);class s extends i.EditorUI{constructor(t,e){super(t),this.view=e}init(){const t=this.editor,e=this.view,o=t.editing.view,r=e.editable,i=o.document.getRoot();r.name=i.rootName,e.render();const n=r.element;this.setEditableElement(r.name,n),e.editable.bind("isFocused").to(this.focusTracker),o.attachDomRoot(n),this._initPlaceholder(),this._initToolbar(),this.fire("ready")}destroy(){super.destroy();const t=this.view;this.editor.editing.view.detachDomRoot(t.editable.name),t.destroy()}_initToolbar(){const t=this.editor,e=this.view;e.toolbar.fillFromConfig(t.config.get("toolbar"),this.componentFactory),this.addToolbar(e.toolbar)}_initPlaceholder(){const t=this.editor,e=t.editing.view,o=e.document.getRoot(),r=t.sourceElement,i=t.config.get("placeholder")||r&&"textarea"===r.tagName.toLowerCase()&&r.getAttribute("placeholder");i&&(0,n.enablePlaceholder)({view:e,element:o,text:i,isDirectHost:!1,keepOnFocus:!0})}}class l extends i.EditorUIView{constructor(t,e,o={}){super(t);const r=t.t;this.toolbar=new i.ToolbarView(t,{shouldGroupWhenFull:o.shouldToolbarGroupWhenFull}),this.editable=new i.InlineEditableUIView(t,e,o.editableElement,{label:t=>r("Rich Text Editor. Editing area: %0",t.name)}),this.toolbar.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:t.uiLanguageDirection}})}render(){super.render(),this.registerChild([this.toolbar,this.editable])}}const a=function(t){return null!=t&&"object"==typeof t};const c="object"==typeof global&&global&&global.Object===Object&&global;var d="object"==typeof self&&self&&self.Object===Object&&self;const u=(c||d||Function("return this")()).Symbol;var h=Object.prototype,b=h.hasOwnProperty,p=h.toString,g=u?u.toStringTag:void 0;const f=function(t){var e=b.call(t,g),o=t[g];try{t[g]=void 0;var r=!0}catch(t){}var i=p.call(t);return r&&(e?t[g]=o:delete t[g]),i};var m=Object.prototype.toString;const v=function(t){return m.call(t)};var y="[object Null]",w="[object Undefined]",E=u?u.toStringTag:void 0;const j=function(t){return null==t?void 0===t?w:y:E&&E in Object(t)?f(t):v(t)};const O=function(t,e){return function(o){return t(e(o))}}(Object.getPrototypeOf,Object);var x="[object Object]",T=Function.prototype,D=Object.prototype,S=T.toString,P=D.hasOwnProperty,F=S.call(Object);const C=function(t){if(!a(t)||j(t)!=x)return!1;var e=O(t);if(null===e)return!0;var o=P.call(e,"constructor")&&e.constructor;return"function"==typeof o&&o instanceof o&&S.call(o)==F};const R=function(t){return a(t)&&1===t.nodeType&&!C(t)};class _ extends((0,t.DataApiMixin)((0,t.ElementApiMixin)(t.Editor))){constructor(o,r={}){if(!A(o)&&void 0!==r.initialData)throw new e.CKEditorError("editor-create-initial-data",null);super(r),void 0===this.config.get("initialData")&&this.config.set("initialData",function(t){return A(t)?(0,e.getDataFromElement)(t):t}(o)),A(o)&&(this.sourceElement=o,(0,t.secureSourceElement)(this)),this.model.document.createRoot();const i=!this.config.get("toolbar.shouldNotGroupWhenFull"),n=new l(this.locale,this.editing.view,{editableElement:this.sourceElement,shouldToolbarGroupWhenFull:i});this.ui=new s(this,n)}destroy(){const t=this.getData();return this.ui.destroy(),super.destroy().then((()=>{this.sourceElement&&this.updateSourceElement(t)}))}static create(t,o={}){return new Promise((r=>{if(A(t)&&"TEXTAREA"===t.tagName)throw new e.CKEditorError("editor-wrong-element",null);const i=new this(t,o);r(i.initPlugins().then((()=>i.ui.init())).then((()=>i.data.init(i.config.get("initialData")))).then((()=>i.fire("ready"))).then((()=>i)))}))}}function A(t){return R(t)}})(),(window.CKEditor5=window.CKEditor5||{}).editorDecoupled=r})();
4
+ */(()=>{var t={704:(t,e,o)=>{t.exports=o(79)("./src/core.js")},492:(t,e,o)=>{t.exports=o(79)("./src/engine.js")},273:(t,e,o)=>{t.exports=o(79)("./src/ui.js")},209:(t,e,o)=>{t.exports=o(79)("./src/utils.js")},79:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function o(r){var i=e[r];if(void 0!==i)return i.exports;var n=e[r]={exports:{}};return t[r](n,n.exports,o),n.exports}o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";o.r(r),o.d(r,{DecoupledEditor:()=>_});var t=o(704),e=o(209),i=o(273),n=o(492);class s extends i.EditorUI{constructor(t,e){super(t),this.view=e}init(){const t=this.editor,e=this.view,o=t.editing.view,r=e.editable,i=o.document.getRoot();r.name=i.rootName,e.render();const n=r.element;this.setEditableElement(r.name,n),e.editable.bind("isFocused").to(this.focusTracker),o.attachDomRoot(n),this._initPlaceholder(),this._initToolbar(),this.fire("ready")}destroy(){super.destroy();const t=this.view;this.editor.editing.view.detachDomRoot(t.editable.name),t.destroy()}_initToolbar(){const t=this.editor,e=this.view;e.toolbar.fillFromConfig(t.config.get("toolbar"),this.componentFactory),this.addToolbar(e.toolbar)}_initPlaceholder(){const t=this.editor,e=t.editing.view,o=e.document.getRoot(),r=(t.sourceElement,t.config.get("placeholder"));if(r){const t="string"==typeof r?r:r[o.rootName];t&&(0,n.enablePlaceholder)({view:e,element:o,text:t,isDirectHost:!1,keepOnFocus:!0})}}}class l extends i.EditorUIView{constructor(t,e,o={}){super(t);const r=t.t;this.toolbar=new i.ToolbarView(t,{shouldGroupWhenFull:o.shouldToolbarGroupWhenFull}),this.editable=new i.InlineEditableUIView(t,e,o.editableElement,{label:t=>r("Rich Text Editor. Editing area: %0",t.name)}),this.toolbar.extendTemplate({attributes:{class:["ck-reset_all","ck-rounded-corners"],dir:t.uiLanguageDirection}})}render(){super.render(),this.registerChild([this.toolbar,this.editable])}}const c=function(t){return null!=t&&"object"==typeof t};const a="object"==typeof global&&global&&global.Object===Object&&global;var d="object"==typeof self&&self&&self.Object===Object&&self;const u=(a||d||Function("return this")()).Symbol;var h=Object.prototype,b=h.hasOwnProperty,p=h.toString,f=u?u.toStringTag:void 0;const g=function(t){var e=b.call(t,f),o=t[f];try{t[f]=void 0;var r=!0}catch(t){}var i=p.call(t);return r&&(e?t[f]=o:delete t[f]),i};var m=Object.prototype.toString;const v=function(t){return m.call(t)};var y="[object Null]",w="[object Undefined]",E=u?u.toStringTag:void 0;const j=function(t){return null==t?void 0===t?w:y:E&&E in Object(t)?g(t):v(t)};const O=function(t,e){return function(o){return t(e(o))}}(Object.getPrototypeOf,Object);var x="[object Object]",T=Function.prototype,D=Object.prototype,S=T.toString,P=D.hasOwnProperty,F=S.call(Object);const C=function(t){if(!c(t)||j(t)!=x)return!1;var e=O(t);if(null===e)return!0;var o=P.call(e,"constructor")&&e.constructor;return"function"==typeof o&&o instanceof o&&S.call(o)==F};const R=function(t){return c(t)&&1===t.nodeType&&!C(t)};class _ extends((0,t.DataApiMixin)((0,t.ElementApiMixin)(t.Editor))){constructor(o,r={}){if(!K(o)&&void 0!==r.initialData)throw new e.CKEditorError("editor-create-initial-data",null);super(r),void 0===this.config.get("initialData")&&this.config.set("initialData",function(t){return K(t)?(0,e.getDataFromElement)(t):t}(o)),K(o)&&(this.sourceElement=o,(0,t.secureSourceElement)(this,o)),this.model.document.createRoot();const i=!this.config.get("toolbar.shouldNotGroupWhenFull"),n=new l(this.locale,this.editing.view,{editableElement:this.sourceElement,shouldToolbarGroupWhenFull:i});this.ui=new s(this,n)}destroy(){const t=this.getData();return this.ui.destroy(),super.destroy().then((()=>{this.sourceElement&&this.updateSourceElement(t)}))}static create(t,o={}){return new Promise((r=>{if(K(t)&&"TEXTAREA"===t.tagName)throw new e.CKEditorError("editor-wrong-element",null);const i=new this(t,o);r(i.initPlugins().then((()=>i.ui.init())).then((()=>i.data.init(i.config.get("initialData")))).then((()=>i.fire("ready"))).then((()=>i)))}))}}function K(t){return R(t)}})(),(window.CKEditor5=window.CKEditor5||{}).editorDecoupled=r})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-editor-decoupled",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.1",
4
4
  "description": "Decoupled editor implementation for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -11,23 +11,23 @@
11
11
  ],
12
12
  "main": "src/index.js",
13
13
  "dependencies": {
14
- "ckeditor5": "^36.0.1",
14
+ "ckeditor5": "^37.0.0-alpha.1",
15
15
  "lodash-es": "^4.17.15"
16
16
  },
17
17
  "devDependencies": {
18
- "@ckeditor/ckeditor5-basic-styles": "^36.0.1",
19
- "@ckeditor/ckeditor5-core": "^36.0.1",
20
- "@ckeditor/ckeditor5-dev-utils": "^32.0.0",
21
- "@ckeditor/ckeditor5-engine": "^36.0.1",
22
- "@ckeditor/ckeditor5-enter": "^36.0.1",
23
- "@ckeditor/ckeditor5-heading": "^36.0.1",
24
- "@ckeditor/ckeditor5-image": "^36.0.1",
25
- "@ckeditor/ckeditor5-paragraph": "^36.0.1",
26
- "@ckeditor/ckeditor5-theme-lark": "^36.0.1",
27
- "@ckeditor/ckeditor5-typing": "^36.0.1",
28
- "@ckeditor/ckeditor5-ui": "^36.0.1",
29
- "@ckeditor/ckeditor5-undo": "^36.0.1",
30
- "@ckeditor/ckeditor5-utils": "^36.0.1",
18
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.1",
19
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.1",
20
+ "@ckeditor/ckeditor5-dev-utils": "^35.0.0",
21
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.1",
22
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.1",
23
+ "@ckeditor/ckeditor5-heading": "^37.0.0-alpha.1",
24
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.1",
25
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.1",
26
+ "@ckeditor/ckeditor5-theme-lark": "^37.0.0-alpha.1",
27
+ "@ckeditor/ckeditor5-typing": "^37.0.0-alpha.1",
28
+ "@ckeditor/ckeditor5-ui": "^37.0.0-alpha.1",
29
+ "@ckeditor/ckeditor5-undo": "^37.0.0-alpha.1",
30
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.1",
31
31
  "typescript": "^4.8.4",
32
32
  "webpack": "^5.58.1",
33
33
  "webpack-cli": "^4.9.0"
@@ -56,7 +56,8 @@
56
56
  ],
57
57
  "scripts": {
58
58
  "dll:build": "webpack",
59
- "build": "tsc -p ./tsconfig.release.json",
59
+ "build": "tsc -p ./tsconfig.json",
60
60
  "postversion": "npm run build"
61
- }
61
+ },
62
+ "types": "src/index.d.ts"
62
63
  }
@@ -0,0 +1,196 @@
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 editor-decoupled/decouplededitor
7
+ */
8
+ import { Editor, type EditorConfig } from 'ckeditor5/src/core';
9
+ import DecoupledEditorUI from './decouplededitorui';
10
+ declare const DecoupledEditor_base: import("ckeditor5/src/utils").Mixed<import("ckeditor5/src/utils").Mixed<typeof Editor, import("ckeditor5/src/core").ElementApi>, import("ckeditor5/src/core").DataApi>;
11
+ /**
12
+ * The {@glink installation/getting-started/predefined-builds#document-editor decoupled editor} implementation.
13
+ * It provides an inline editable and a toolbar. However, unlike other editors,
14
+ * it does not render these components anywhere in the DOM unless configured.
15
+ *
16
+ * This type of an editor is dedicated to integrations which require a customized UI with an open
17
+ * structure, allowing developers to specify the exact location of the interface.
18
+ *
19
+ * See the document editor {@glink examples/builds/document-editor demo} to learn about possible use cases
20
+ * for the decoupled editor.
21
+ *
22
+ * In order to create a decoupled editor instance, use the static
23
+ * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`} method.
24
+ *
25
+ * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
26
+ *
27
+ * # Decoupled editor and document editor build
28
+ *
29
+ * The decoupled editor can be used directly from source (if you installed the
30
+ * [`@ckeditor/ckeditor5-editor-decoupled`](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-decoupled) package)
31
+ * but it is also available in the
32
+ * {@glink installation/getting-started/predefined-builds#document-editor document editor build}.
33
+ *
34
+ * {@glink installation/getting-started/predefined-builds Builds}
35
+ * are ready-to-use editors with plugins bundled in. When using the editor from
36
+ * source you need to take care of loading all plugins by yourself
37
+ * (through the {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`} option).
38
+ * Using the editor from source gives much better flexibility and allows for easier customization.
39
+ *
40
+ * Read more about initializing the editor from source or as a build in
41
+ * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}.
42
+ */
43
+ export default class DecoupledEditor extends DecoupledEditor_base {
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ readonly ui: DecoupledEditorUI;
48
+ /**
49
+ * Creates an instance of the decoupled editor.
50
+ *
51
+ * **Note:** Do not use the constructor to create editor instances. Use the static
52
+ * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`} method instead.
53
+ *
54
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
55
+ * (on which the editor will be initialized) or initial data for the editor. For more information see
56
+ * {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}.
57
+ * @param config The editor configuration.
58
+ */
59
+ protected constructor(sourceElementOrData: HTMLElement | string, config?: EditorConfig);
60
+ /**
61
+ * Destroys the editor instance, releasing all resources used by it.
62
+ *
63
+ * Updates the original editor element with the data if the
64
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
65
+ * configuration option is set to `true`.
66
+ *
67
+ * **Note**: The decoupled editor does not remove the toolbar and editable when destroyed. You can
68
+ * do that yourself in the destruction chain:
69
+ *
70
+ * ```ts
71
+ * editor.destroy()
72
+ * .then( () => {
73
+ * // Remove the toolbar from DOM.
74
+ * editor.ui.view.toolbar.element.remove();
75
+ *
76
+ * // Remove the editable from DOM.
77
+ * editor.ui.view.editable.element.remove();
78
+ *
79
+ * console.log( 'Editor was destroyed' );
80
+ * } );
81
+ * ```
82
+ */
83
+ destroy(): Promise<unknown>;
84
+ /**
85
+ * Creates a new decoupled editor instance.
86
+ *
87
+ * **Note:** remember that `DecoupledEditor` does not append the toolbar element to your web page, so you have to do it manually
88
+ * after the editor has been initialized.
89
+ *
90
+ * There are two ways how the editor can be initialized.
91
+ *
92
+ * # Using an existing DOM element (and loading data from it)
93
+ *
94
+ * You can initialize the editor using an existing DOM element:
95
+ *
96
+ * ```ts
97
+ * DecoupledEditor
98
+ * .create( document.querySelector( '#editor' ) )
99
+ * .then( editor => {
100
+ * console.log( 'Editor was initialized', editor );
101
+ *
102
+ * // Append the toolbar to the <body> element.
103
+ * document.body.appendChild( editor.ui.view.toolbar.element );
104
+ * } )
105
+ * .catch( err => {
106
+ * console.error( err.stack );
107
+ * } );
108
+ * ```
109
+ *
110
+ * The element's content will be used as the editor data and the element will become the editable element.
111
+ *
112
+ * # Creating a detached editor
113
+ *
114
+ * Alternatively, you can initialize the editor by passing the initial data directly as a string.
115
+ * In this case, you will have to manually append both the toolbar element and the editable element to your web page.
116
+ *
117
+ * ```ts
118
+ * DecoupledEditor
119
+ * .create( '<p>Hello world!</p>' )
120
+ * .then( editor => {
121
+ * console.log( 'Editor was initialized', editor );
122
+ *
123
+ * // Append the toolbar to the <body> element.
124
+ * document.body.appendChild( editor.ui.view.toolbar.element );
125
+ *
126
+ * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
127
+ * document.body.appendChild( editor.ui.getEditableElement() );
128
+ * } )
129
+ * .catch( err => {
130
+ * console.error( err.stack );
131
+ * } );
132
+ * ```
133
+ *
134
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
135
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
136
+ *
137
+ * # Using an existing DOM element (and data provided in `config.initialData`)
138
+ *
139
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
140
+ *
141
+ * ```ts
142
+ * DecoupledEditor
143
+ * .create( document.querySelector( '#editor' ), {
144
+ * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
145
+ * } )
146
+ * .then( editor => {
147
+ * console.log( 'Editor was initialized', editor );
148
+ *
149
+ * // Append the toolbar to the <body> element.
150
+ * document.body.appendChild( editor.ui.view.toolbar.element );
151
+ * } )
152
+ * .catch( err => {
153
+ * console.error( err.stack );
154
+ * } );
155
+ * ```
156
+ *
157
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
158
+ * makes it difficult to set the content of the source element.
159
+ *
160
+ * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
161
+ *
162
+ * # Configuring the editor
163
+ *
164
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
165
+ * customizing plugins, toolbar and more.
166
+ *
167
+ * # Using the editor from source
168
+ *
169
+ * The code samples listed in the previous sections of this documentation assume that you are using an
170
+ * {@glink installation/getting-started/predefined-builds editor build}
171
+ * (for example – `@ckeditor/ckeditor5-build-decoupled`).
172
+ *
173
+ * If you want to use the decoupled editor from source (`@ckeditor/ckeditor5-editor-decoupled/src/decouplededitor`),
174
+ * you need to define the list of
175
+ * {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
176
+ * {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
177
+ * source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
178
+ *
179
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
180
+ * or the editor's initial data.
181
+ *
182
+ * If a DOM element is passed, its content will be automatically loaded to the editor upon initialization.
183
+ * The editor data will be set back to the original element once the editor is destroyed only if the
184
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
185
+ * option is set to `true`.
186
+ *
187
+ * If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
188
+ * It is available via
189
+ * {@link module:editor-decoupled/decouplededitorui~DecoupledEditorUI#getEditableElement `editor.ui.getEditableElement()`}.
190
+ *
191
+ * @param config The editor configuration.
192
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
193
+ */
194
+ static create(sourceElementOrData: HTMLElement | string, config?: EditorConfig): Promise<DecoupledEditor>;
195
+ }
196
+ export {};
@@ -24,6 +24,8 @@ import { isElement as _isElement } from 'lodash-es';
24
24
  * In order to create a decoupled editor instance, use the static
25
25
  * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`} method.
26
26
  *
27
+ * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
28
+ *
27
29
  * # Decoupled editor and document editor build
28
30
  *
29
31
  * The decoupled editor can be used directly from source (if you installed the
@@ -65,7 +67,7 @@ export default class DecoupledEditor extends DataApiMixin(ElementApiMixin(Editor
65
67
  }
66
68
  if (isElement(sourceElementOrData)) {
67
69
  this.sourceElement = sourceElementOrData;
68
- secureSourceElement(this);
70
+ secureSourceElement(this, sourceElementOrData);
69
71
  }
70
72
  this.model.document.createRoot();
71
73
  const shouldToolbarGroupWhenFull = !this.config.get('toolbar.shouldNotGroupWhenFull');
@@ -113,8 +115,8 @@ export default class DecoupledEditor extends DataApiMixin(ElementApiMixin(Editor
113
115
  /**
114
116
  * Creates a new decoupled editor instance.
115
117
  *
116
- * Remember that `DecoupledEditor` does not append the toolbar element to your web page so you have to do it manually after the editor
117
- * has been initialized.
118
+ * **Note:** remember that `DecoupledEditor` does not append the toolbar element to your web page, so you have to do it manually
119
+ * after the editor has been initialized.
118
120
  *
119
121
  * There are two ways how the editor can be initialized.
120
122
  *
@@ -203,7 +205,7 @@ export default class DecoupledEditor extends DataApiMixin(ElementApiMixin(Editor
203
205
  * you need to define the list of
204
206
  * {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
205
207
  * {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
206
- * source in the {@glink installation/advanced/alternative-setups/integrating-from-source dedicated guide}.
208
+ * source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
207
209
  *
208
210
  * @param sourceElementOrData The DOM element that will be the source for the created editor
209
211
  * or the editor's initial data.
@@ -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 editor-decoupled/decouplededitorui
7
+ */
8
+ import { type Editor } from 'ckeditor5/src/core';
9
+ import { EditorUI } from 'ckeditor5/src/ui';
10
+ import type DecoupledEditorUIView from './decouplededitoruiview';
11
+ /**
12
+ * The decoupled editor UI class.
13
+ */
14
+ export default class DecoupledEditorUI extends EditorUI {
15
+ /**
16
+ * The main (top–most) view of the editor UI.
17
+ */
18
+ readonly view: DecoupledEditorUIView;
19
+ /**
20
+ * Creates an instance of the decoupled editor UI class.
21
+ *
22
+ * @param editor The editor instance.
23
+ * @param view The view of the UI.
24
+ */
25
+ constructor(editor: Editor, view: DecoupledEditorUIView);
26
+ /**
27
+ * Initializes the UI.
28
+ */
29
+ init(): void;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ destroy(): void;
34
+ /**
35
+ * Initializes the inline editor toolbar and its panel.
36
+ */
37
+ private _initToolbar;
38
+ /**
39
+ * Enable the placeholder text on the editing root, if any was configured.
40
+ */
41
+ private _initPlaceholder;
42
+ }
@@ -81,16 +81,18 @@ export default class DecoupledEditorUI extends EditorUI {
81
81
  const editingView = editor.editing.view;
82
82
  const editingRoot = editingView.document.getRoot();
83
83
  const sourceElement = editor.sourceElement;
84
- const placeholderText = editor.config.get('placeholder') ||
85
- sourceElement && sourceElement.tagName.toLowerCase() === 'textarea' && sourceElement.getAttribute('placeholder');
86
- if (placeholderText) {
87
- enablePlaceholder({
88
- view: editingView,
89
- element: editingRoot,
90
- text: placeholderText,
91
- isDirectHost: false,
92
- keepOnFocus: true
93
- });
84
+ const placeholder = editor.config.get('placeholder');
85
+ if (placeholder) {
86
+ const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
87
+ if (placeholderText) {
88
+ enablePlaceholder({
89
+ view: editingView,
90
+ element: editingRoot,
91
+ text: placeholderText,
92
+ isDirectHost: false,
93
+ keepOnFocus: true
94
+ });
95
+ }
94
96
  }
95
97
  }
96
98
  }
@@ -0,0 +1,49 @@
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 editor-decoupled/decouplededitoruiview
7
+ */
8
+ import { EditorUIView, InlineEditableUIView, ToolbarView } from 'ckeditor5/src/ui';
9
+ import type { Locale } from 'ckeditor5/src/utils';
10
+ import type { View } from 'ckeditor5/src/engine';
11
+ /**
12
+ * The decoupled editor UI view. It is a virtual view providing an inline
13
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#editable} and a
14
+ * {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar}, but without any
15
+ * specific arrangement of the components in the DOM.
16
+ *
17
+ * See {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
18
+ * to learn more about this view.
19
+ */
20
+ export default class DecoupledEditorUIView extends EditorUIView {
21
+ /**
22
+ * The main toolbar of the decoupled editor UI.
23
+ */
24
+ readonly toolbar: ToolbarView;
25
+ /**
26
+ * The editable of the decoupled editor UI.
27
+ */
28
+ readonly editable: InlineEditableUIView;
29
+ /**
30
+ * Creates an instance of the decoupled editor UI view.
31
+ *
32
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
33
+ * @param editingView The editing view instance this view is related to.
34
+ * @param options Configuration options for the view instance.
35
+ * @param options.editableElement The editable element. If not specified, it will be automatically created by
36
+ * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
37
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
38
+ * in the main {@link module:editor-decoupled/decouplededitoruiview~DecoupledEditorUIView#toolbar toolbar}.
39
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
40
+ */
41
+ constructor(locale: Locale, editingView: View, options?: {
42
+ editableElement?: HTMLElement;
43
+ shouldToolbarGroupWhenFull?: boolean;
44
+ });
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ render(): void;
49
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,8 @@
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 editor-decoupled
7
+ */
8
+ export { default as DecoupledEditor } from './decouplededitor';