@ckeditor/ckeditor5-editor-inline 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 ADDED
@@ -0,0 +1,4 @@
1
+ Changelog
2
+ =========
3
+
4
+ All changes in the package are documented in https://github.com/ckeditor/ckeditor5/blob/master/CHANGELOG.md.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ Software License Agreement
2
+ ==========================
3
+
4
+ **Inline editor implementation** – https://github.com/ckeditor/ckeditor5-editor-inline <br>
5
+ Copyright (c) 2003–2024, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
+
7
+ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
+
9
+ Sources of Intellectual Property Included in CKEditor
10
+ -----------------------------------------------------
11
+
12
+ Where not otherwise indicated, all CKEditor content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor will incorporate work done by developers outside of CKSource with their express permission.
13
+
14
+ The following libraries are included in CKEditor under the [MIT license](https://opensource.org/licenses/MIT):
15
+
16
+ * Lodash - Copyright (c) JS Foundation and other contributors https://js.foundation/. Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors http://underscorejs.org/.
17
+
18
+ Trademarks
19
+ ----------
20
+
21
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ CKEditor&nbsp;5 inline editor implementation
2
+ ========================================
3
+
4
+ [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-editor-inline.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-inline)
5
+ [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5?branch=master)
6
+ [![Build Status](https://travis-ci.com/ckeditor/ckeditor5.svg?branch=master)](https://app.travis-ci.com/github/ckeditor/ckeditor5)
7
+
8
+ The inline editor implementation for CKEditor&nbsp;5.
9
+
10
+ This package exposes the [`InlineEditor`](https://ckeditor.com/docs/ckeditor5/latest/api/module_editor-inline_inlineeditor-InlineEditor.html) class. Follow there to learn more about this type of editor and how to initialize it.
11
+
12
+ This package contains the source version of the inline editor. This kind of editor implementation is also available as a ready-to-use [inline build](https://www.npmjs.com/package/@ckeditor/ckeditor5-build-inline). Read more about [CKEditor&nbsp;5 predefined builds](https://ckeditor.com/docs/ckeditor5/latest/getting-started/legacy/advanced/alternative-setups/predefined-builds.html) in the CKEditor&nbsp;5 documentation.
13
+
14
+ ## Documentation
15
+
16
+ See the [`@ckeditor/ckeditor5-editor-inline` package](https://ckeditor.com/docs/ckeditor5/latest/api/editor-inline.html) page in [CKEditor&nbsp;5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install ckeditor5
22
+ ```
23
+
24
+ ## License
25
+
26
+ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html). For full details about the license, please check the `LICENSE.md` file or [https://ckeditor.com/legal/ckeditor-oss-license](https://ckeditor.com/legal/ckeditor-oss-license).
@@ -0,0 +1,4 @@
1
+ /*!
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */(()=>{var t={693:(t,e,o)=>{"use strict";o.d(e,{A:()=>a});var r=o(758),n=o.n(r),i=o(935),s=o.n(i)()(n());s.push([t.id,".ck.ck-menu-bar{border:none;border-bottom:1px solid var(--ck-color-toolbar-border)}",""]);const a=s},935:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var o="",r=void 0!==e[5];return e[4]&&(o+="@supports (".concat(e[4],") {")),e[2]&&(o+="@media ".concat(e[2]," {")),r&&(o+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),o+=t(e),r&&(o+="}"),e[2]&&(o+="}"),e[4]&&(o+="}"),o})).join("")},e.i=function(t,o,r,n,i){"string"==typeof t&&(t=[[null,t,void 0]]);var s={};if(r)for(var a=0;a<this.length;a++){var l=this[a][0];null!=l&&(s[l]=!0)}for(var c=0;c<t.length;c++){var u=[].concat(t[c]);r&&s[u[0]]||(void 0!==i&&(void 0===u[5]||(u[1]="@layer".concat(u[5].length>0?" ".concat(u[5]):""," {").concat(u[1],"}")),u[5]=i),o&&(u[2]?(u[1]="@media ".concat(u[2]," {").concat(u[1],"}"),u[2]=o):u[2]=o),n&&(u[4]?(u[1]="@supports (".concat(u[4],") {").concat(u[1],"}"),u[4]=n):u[4]="".concat(n)),e.push(u))}},e}},758:t=>{"use strict";t.exports=function(t){return t[1]}},591:t=>{"use strict";var e=[];function o(t){for(var o=-1,r=0;r<e.length;r++)if(e[r].identifier===t){o=r;break}return o}function r(t,r){for(var i={},s=[],a=0;a<t.length;a++){var l=t[a],c=r.base?l[0]+r.base:l[0],u=i[c]||0,d="".concat(c," ").concat(u);i[c]=u+1;var h=o(d),p={css:l[1],media:l[2],sourceMap:l[3],supports:l[4],layer:l[5]};if(-1!==h)e[h].references++,e[h].updater(p);else{var f=n(p,r);r.byIndex=a,e.splice(a,0,{identifier:d,updater:f,references:1})}s.push(d)}return s}function n(t,e){var o=e.domAPI(e);o.update(t);return function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;o.update(t=e)}else o.remove()}}t.exports=function(t,n){var i=r(t=t||[],n=n||{});return function(t){t=t||[];for(var s=0;s<i.length;s++){var a=o(i[s]);e[a].references--}for(var l=r(t,n),c=0;c<i.length;c++){var u=o(i[c]);0===e[u].references&&(e[u].updater(),e.splice(u,1))}i=l}}},128:t=>{"use strict";var e={};t.exports=function(t,o){var r=function(t){if(void 0===e[t]){var o=document.querySelector(t);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(t){o=null}e[t]=o}return e[t]}(t);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(o)}},51:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},21:t=>{"use strict";t.exports=function(t,e){Object.keys(e).forEach((function(o){t.setAttribute(o,e[o])}))}},639:t=>{"use strict";var e,o=(e=[],function(t,o){return e[t]=o,e.filter(Boolean).join("\n")});function r(t,e,r,n){var i;if(r)i="";else{i="",n.supports&&(i+="@supports (".concat(n.supports,") {")),n.media&&(i+="@media ".concat(n.media," {"));var s=void 0!==n.layer;s&&(i+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),i+=n.css,s&&(i+="}"),n.media&&(i+="}"),n.supports&&(i+="}")}if(t.styleSheet)t.styleSheet.cssText=o(e,i);else{var a=document.createTextNode(i),l=t.childNodes;l[e]&&t.removeChild(l[e]),l.length?t.insertBefore(a,l[e]):t.appendChild(a)}}var n={singleton:null,singletonCounter:0};t.exports=function(t){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var e=n.singletonCounter++,o=n.singleton||(n.singleton=t.insertStyleElement(t));return{update:function(t){r(o,e,!1,t)},remove:function(t){r(o,e,!0,t)}}}},782:(t,e,o)=>{t.exports=o(237)("./src/core.js")},783:(t,e,o)=>{t.exports=o(237)("./src/engine.js")},311:(t,e,o)=>{t.exports=o(237)("./src/ui.js")},584:(t,e,o)=>{t.exports=o(237)("./src/utils.js")},237:t=>{"use strict";t.exports=CKEditor5.dll}},e={};function o(r){var n=e[r];if(void 0!==n)return n.exports;var i=e[r]={id:r,exports:{}};return t[r](i,i.exports,o),i.exports}o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},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,{InlineEditor:()=>G});var t=o(782),e=o(584),n=o(311),i=o(783);class s extends n.EditorUI{constructor(t,e){super(t),this.view=e,this._toolbarConfig=(0,n.normalizeToolbarConfig)(t.config.get("toolbar"))}get element(){return this.view.editable.element}init(){const t=this.editor,e=this.view,o=t.editing.view,r=e.editable,n=o.document.getRoot();r.name=n.rootName,e.render();const i=r.element;this.setEditableElement(r.name,i),r.bind("isFocused").to(this.focusTracker),o.attachDomRoot(i),this._initPlaceholder(),this._initToolbar(),e.menuBarView&&this._initMenuBar(e.menuBarView),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,o=e.editable.element,r=e.toolbar;e.panel.bind("isVisible").to(this.focusTracker,"isFocused"),e.bind("viewportTopOffset").to(this,"viewportOffset",(({top:t})=>t||0)),e.listenTo(t.ui,"update",(()=>{e.panel.isVisible&&e.panel.pin({target:o,positions:e.panelPositions})})),r.fillFromConfig(this._toolbarConfig,this.componentFactory),this.addToolbar(r)}_initPlaceholder(){const t=this.editor,e=t.editing.view,o=e.document.getRoot(),r=t.config.get("placeholder");if(r){const t="string"==typeof r?r:r[o.rootName];t&&(o.placeholder=t)}(0,i.enablePlaceholder)({view:e,element:o,isDirectHost:!1,keepOnFocus:!0})}}var a=o(591),l=o.n(a),c=o(639),u=o.n(c),d=o(128),h=o.n(d),p=o(21),f=o.n(p),b=o(51),v=o.n(b),g=o(693),m={attributes:{"data-cke":!0}};m.setAttributes=f(),m.insert=h().bind(null,"head"),m.domAPI=u(),m.insertStyleElement=v();l()(g.A,m);g.A&&g.A.locals&&g.A.locals;const w=(0,e.toUnit)("px");class y extends n.EditorUIView{constructor(t,e,o,r={}){super(t),this.toolbar=new n.ToolbarView(t,{shouldGroupWhenFull:r.shouldToolbarGroupWhenFull,isFloating:!0}),r.useMenuBar&&(this.menuBarView=new n.MenuBarView(t)),this.set("viewportTopOffset",0),this.panel=new n.BalloonPanelView(t),this.panelPositions=this._getPanelPositions(),this.panel.extendTemplate({attributes:{class:"ck-toolbar-container"}}),this.editable=new n.InlineEditableUIView(t,e,o,{label:r.label}),this._resizeObserver=null}render(){super.render(),this.body.add(this.panel),this.registerChild(this.editable),this.menuBarView?this.panel.content.addMany([this.menuBarView,this.toolbar]):this.panel.content.add(this.toolbar);if(this.toolbar.options.shouldGroupWhenFull){const t=this.editable.element;this._resizeObserver=new e.ResizeObserver(t,(()=>{this.toolbar.maxWidth=w(new e.Rect(t).width)}))}}destroy(){super.destroy(),this._resizeObserver&&this._resizeObserver.destroy()}_getPanelPositionTop(t,e){let o;return o=t.top>e.height+this.viewportTopOffset?t.top-e.height:t.bottom>e.height+this.viewportTopOffset+50?this.viewportTopOffset:t.bottom,o}_getPanelPositions(){const t=[(t,e)=>({top:this._getPanelPositionTop(t,e),left:t.left,name:"toolbar_west",config:{withArrow:!1}}),(t,e)=>({top:this._getPanelPositionTop(t,e),left:t.left+t.width-e.width,name:"toolbar_east",config:{withArrow:!1}})];return"ltr"===this.locale.uiLanguageDirection?t:t.reverse()}}const O=function(t){return null!=t&&"object"==typeof t};const T="object"==typeof global&&global&&global.Object===Object&&global;var E="object"==typeof self&&self&&self.Object===Object&&self;const j=(T||E||Function("return this")()).Symbol;var x=Object.prototype,P=x.hasOwnProperty,_=x.toString,S=j?j.toStringTag:void 0;const F=function(t){var e=P.call(t,S),o=t[S];try{t[S]=void 0;var r=!0}catch(t){}var n=_.call(t);return r&&(e?t[S]=o:delete t[S]),n};var C=Object.prototype.toString;const A=function(t){return C.call(t)};var B=j?j.toStringTag:void 0;const M=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":B&&B in Object(t)?F(t):A(t)};const V=function(t,e){return function(o){return t(e(o))}}(Object.getPrototypeOf,Object);var I=Function.prototype,D=Object.prototype,k=I.toString,N=D.hasOwnProperty,R=k.call(Object);const z=function(t){if(!O(t)||"[object Object]"!=M(t))return!1;var e=V(t);if(null===e)return!0;var o=N.call(e,"constructor")&&e.constructor;return"function"==typeof o&&o instanceof o&&k.call(o)==R};const W=function(t){return O(t)&&1===t.nodeType&&!z(t)};class G extends((0,t.ElementApiMixin)(t.Editor)){static get editorName(){return"InlineEditor"}constructor(o,r={}){if(!K(o)&&void 0!==r.initialData)throw new e.CKEditorError("editor-create-initial-data",null);super(r),this.config.define("menuBar.isVisible",!1),void 0===this.config.get("initialData")&&this.config.set("initialData",function(t){return K(t)?(0,e.getDataFromElement)(t):t}(o)),this.model.document.createRoot(),K(o)&&(this.sourceElement=o,(0,t.secureSourceElement)(this,o));const n=!this.config.get("toolbar.shouldNotGroupWhenFull"),i=this.config.get("menuBar"),a=new y(this.locale,this.editing.view,this.sourceElement,{shouldToolbarGroupWhenFull:n,useMenuBar:i.isVisible,label:this.config.get("label")});this.ui=new s(this,a),(0,t.attachToForm)(this)}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 n=new this(t,o);r(n.initPlugins().then((()=>n.ui.init())).then((()=>n.data.init(n.config.get("initialData")))).then((()=>n.fire("ready"))).then((()=>n)))}))}}function K(t){return W(t)}})(),(window.CKEditor5=window.CKEditor5||{}).editorInline=r})();
@@ -0,0 +1,4 @@
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
+ */
@@ -0,0 +1,8 @@
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
+ .ck.ck-menu-bar{
6
+ border:none;
7
+ border-bottom:1px solid var(--ck-color-toolbar-border);
8
+ }
package/dist/index.css ADDED
@@ -0,0 +1,15 @@
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
+ * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+
10
+ .ck.ck-menu-bar {
11
+ border: none;
12
+ border-bottom: 1px solid var(--ck-color-toolbar-border);
13
+ }
14
+
15
+ /*# sourceMappingURL=index.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../theme/inlineeditor.css","index.css"],"names":[],"mappings":";;;;AAAA,CAAA;ACCA,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ;AAC3E,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;AAC5E,CAAC,CDAC;;AAEF,CAAA,EAAA,CAAA,EAAA,CAAA,IAAA,CAAA,GAAA,CAAA;ACCA,CDAC,MAAA,CAAA,CAAA,IAAY;ACCb,CDAC,MAAA,CAAA,MAAA,CAAA,CAAA,GAAA,CAAA,KAAA,CAAA,GAAA,CAAA,CAAA,CAAA,EAAA,CAAA,KAAA,CAAA,OAAA,CAAA,MAAA,CAAuD;AACxD;;ACEA,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC","file":"index.css.map","sourcesContent":["/*\n * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n.ck.ck-menu-bar {\n\tborder: none;\n\tborder-bottom: 1px solid var(--ck-color-toolbar-border);\n}\n","/*\n * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n.ck.ck-menu-bar {\n\tborder: none;\n\tborder-bottom: 1px solid var(--ck-color-toolbar-border);\n}\n\n/*# sourceMappingURL=index.css.map */"]}
@@ -0,0 +1,12 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module editor-inline
11
+ */
12
+ export { default as InlineEditor } from './inlineeditor.js';
package/dist/index.js ADDED
@@ -0,0 +1,488 @@
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 { ElementApiMixin, Editor, secureSourceElement, attachToForm } from '@ckeditor/ckeditor5-core/dist/index.js';
6
+ import { ResizeObserver, Rect, toUnit, CKEditorError, getDataFromElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
7
+ import { EditorUI, normalizeToolbarConfig, EditorUIView, ToolbarView, MenuBarView, BalloonPanelView, InlineEditableUIView } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
+ import { enablePlaceholder } from '@ckeditor/ckeditor5-engine/dist/index.js';
9
+ import { isElement as isElement$1 } from 'lodash-es';
10
+
11
+ /**
12
+ * The inline editor UI class.
13
+ *
14
+ * @extends module:ui/editorui/editorui~EditorUI
15
+ */ class InlineEditorUI extends EditorUI {
16
+ /**
17
+ * The main (top–most) view of the editor UI.
18
+ */ view;
19
+ /**
20
+ * A normalized `config.toolbar` object.
21
+ */ _toolbarConfig;
22
+ /**
23
+ * Creates an instance of the inline editor UI class.
24
+ *
25
+ * @param editor The editor instance.
26
+ * @param view The view of the UI.
27
+ */ constructor(editor, view){
28
+ super(editor);
29
+ this.view = view;
30
+ this._toolbarConfig = normalizeToolbarConfig(editor.config.get('toolbar'));
31
+ }
32
+ /**
33
+ * @inheritDoc
34
+ */ get element() {
35
+ return this.view.editable.element;
36
+ }
37
+ /**
38
+ * Initializes the UI.
39
+ */ init() {
40
+ const editor = this.editor;
41
+ const view = this.view;
42
+ const editingView = editor.editing.view;
43
+ const editable = view.editable;
44
+ const editingRoot = editingView.document.getRoot();
45
+ // The editable UI and editing root should share the same name. Then name is used
46
+ // to recognize the particular editable, for instance in ARIA attributes.
47
+ editable.name = editingRoot.rootName;
48
+ view.render();
49
+ // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
50
+ // But it can be available earlier if a DOM element has been passed to InlineEditor.create().
51
+ const editableElement = editable.element;
52
+ // Register the editable UI view in the editor. A single editor instance can aggregate multiple
53
+ // editable areas (roots) but the inline editor has only one.
54
+ this.setEditableElement(editable.name, editableElement);
55
+ // Let the editable UI element respond to the changes in the global editor focus
56
+ // tracker. It has been added to the same tracker a few lines above but, in reality, there are
57
+ // many focusable areas in the editor, like balloons, toolbars or dropdowns and as long
58
+ // as they have focus, the editable should act like it is focused too (although technically
59
+ // it isn't), e.g. by setting the proper CSS class, visually announcing focus to the user.
60
+ // Doing otherwise will result in editable focus styles disappearing, once e.g. the
61
+ // toolbar gets focused.
62
+ editable.bind('isFocused').to(this.focusTracker);
63
+ // Bind the editable UI element to the editing view, making it an end– and entry–point
64
+ // of the editor's engine. This is where the engine meets the UI.
65
+ editingView.attachDomRoot(editableElement);
66
+ this._initPlaceholder();
67
+ this._initToolbar();
68
+ if (view.menuBarView) {
69
+ this._initMenuBar(view.menuBarView);
70
+ }
71
+ this.fire('ready');
72
+ }
73
+ /**
74
+ * @inheritDoc
75
+ */ destroy() {
76
+ super.destroy();
77
+ const view = this.view;
78
+ const editingView = this.editor.editing.view;
79
+ editingView.detachDomRoot(view.editable.name);
80
+ view.destroy();
81
+ }
82
+ /**
83
+ * Initializes the inline editor toolbar and its panel.
84
+ */ _initToolbar() {
85
+ const editor = this.editor;
86
+ const view = this.view;
87
+ const editableElement = view.editable.element;
88
+ const toolbar = view.toolbar;
89
+ // Set–up the view#panel.
90
+ view.panel.bind('isVisible').to(this.focusTracker, 'isFocused');
91
+ view.bind('viewportTopOffset').to(this, 'viewportOffset', ({ top })=>top || 0);
92
+ // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
93
+ view.listenTo(editor.ui, 'update', ()=>{
94
+ // Don't pin if the panel is not already visible. It prevents the panel
95
+ // showing up when there's no focus in the UI.
96
+ if (view.panel.isVisible) {
97
+ view.panel.pin({
98
+ target: editableElement,
99
+ positions: view.panelPositions
100
+ });
101
+ }
102
+ });
103
+ toolbar.fillFromConfig(this._toolbarConfig, this.componentFactory);
104
+ // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
105
+ this.addToolbar(toolbar);
106
+ }
107
+ /**
108
+ * Enable the placeholder text on the editing root.
109
+ */ _initPlaceholder() {
110
+ const editor = this.editor;
111
+ const editingView = editor.editing.view;
112
+ const editingRoot = editingView.document.getRoot();
113
+ const placeholder = editor.config.get('placeholder');
114
+ if (placeholder) {
115
+ const placeholderText = typeof placeholder === 'string' ? placeholder : placeholder[editingRoot.rootName];
116
+ if (placeholderText) {
117
+ editingRoot.placeholder = placeholderText;
118
+ }
119
+ }
120
+ enablePlaceholder({
121
+ view: editingView,
122
+ element: editingRoot,
123
+ isDirectHost: false,
124
+ keepOnFocus: true
125
+ });
126
+ }
127
+ }
128
+
129
+ const toPx = /* #__PURE__ */ toUnit('px');
130
+ /**
131
+ * Inline editor UI view. Uses an nline editable and a floating toolbar.
132
+ */ class InlineEditorUIView extends EditorUIView {
133
+ /**
134
+ * A floating toolbar view instance.
135
+ */ toolbar;
136
+ /**
137
+ * A balloon panel view instance.
138
+ */ panel;
139
+ /**
140
+ * A set of positioning functions used by the {@link #panel} to float around
141
+ * {@link #element editableElement}.
142
+ *
143
+ * The positioning functions are as follows:
144
+ *
145
+ * * West:
146
+ *
147
+ * ```
148
+ * [ Panel ]
149
+ * +------------------+
150
+ * | #editableElement |
151
+ * +------------------+
152
+ *
153
+ * +------------------+
154
+ * | #editableElement |
155
+ * |[ Panel ] |
156
+ * | |
157
+ * +------------------+
158
+ *
159
+ * +------------------+
160
+ * | #editableElement |
161
+ * +------------------+
162
+ * [ Panel ]
163
+ * ```
164
+ *
165
+ * * East:
166
+ *
167
+ * ```
168
+ * [ Panel ]
169
+ * +------------------+
170
+ * | #editableElement |
171
+ * +------------------+
172
+ *
173
+ * +------------------+
174
+ * | #editableElement |
175
+ * | [ Panel ]|
176
+ * | |
177
+ * +------------------+
178
+ *
179
+ * +------------------+
180
+ * | #editableElement |
181
+ * +------------------+
182
+ * [ Panel ]
183
+ * ```
184
+ *
185
+ * See: {@link module:utils/dom/position~Options#positions}.
186
+ */ panelPositions;
187
+ /**
188
+ * Editable UI view.
189
+ */ editable;
190
+ /**
191
+ * An instance of the resize observer that helps dynamically determine the geometry of the toolbar
192
+ * and manage items that do not fit into a single row.
193
+ *
194
+ * **Note:** Created in {@link #render}.
195
+ */ _resizeObserver;
196
+ /**
197
+ * Creates an instance of the inline editor UI view.
198
+ *
199
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
200
+ * @param editingView The editing view instance this view is related to.
201
+ * @param editableElement The editable element. If not specified, it will be automatically created by
202
+ * {@link module:ui/editableui/editableuiview~EditableUIView}. Otherwise, the given element will be used.
203
+ * @param options Configuration options for the view instance.
204
+ * @param options.shouldToolbarGroupWhenFull When set `true` enables automatic items grouping
205
+ * in the main {@link module:editor-inline/inlineeditoruiview~InlineEditorUIView#toolbar toolbar}.
206
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
207
+ * @param options.label When set, this value will be used as an accessible `aria-label` of the
208
+ * {@link module:ui/editableui/editableuiview~EditableUIView editable view}.
209
+ */ constructor(locale, editingView, editableElement, options = {}){
210
+ super(locale);
211
+ this.toolbar = new ToolbarView(locale, {
212
+ shouldGroupWhenFull: options.shouldToolbarGroupWhenFull,
213
+ isFloating: true
214
+ });
215
+ if (options.useMenuBar) {
216
+ this.menuBarView = new MenuBarView(locale);
217
+ }
218
+ this.set('viewportTopOffset', 0);
219
+ this.panel = new BalloonPanelView(locale);
220
+ this.panelPositions = this._getPanelPositions();
221
+ this.panel.extendTemplate({
222
+ attributes: {
223
+ class: 'ck-toolbar-container'
224
+ }
225
+ });
226
+ this.editable = new InlineEditableUIView(locale, editingView, editableElement, {
227
+ label: options.label
228
+ });
229
+ this._resizeObserver = null;
230
+ }
231
+ /**
232
+ * @inheritDoc
233
+ */ render() {
234
+ super.render();
235
+ this.body.add(this.panel);
236
+ this.registerChild(this.editable);
237
+ if (this.menuBarView) {
238
+ // Set toolbar as a child of a stickyPanel and makes toolbar sticky.
239
+ this.panel.content.addMany([
240
+ this.menuBarView,
241
+ this.toolbar
242
+ ]);
243
+ } else {
244
+ this.panel.content.add(this.toolbar);
245
+ }
246
+ const options = this.toolbar.options;
247
+ // Set toolbar's max-width on the initialization and update it on the editable resize,
248
+ // if 'shouldToolbarGroupWhenFull' in config is set to 'true'.
249
+ if (options.shouldGroupWhenFull) {
250
+ const editableElement = this.editable.element;
251
+ this._resizeObserver = new ResizeObserver(editableElement, ()=>{
252
+ this.toolbar.maxWidth = toPx(new Rect(editableElement).width);
253
+ });
254
+ }
255
+ }
256
+ /**
257
+ * @inheritDoc
258
+ */ destroy() {
259
+ super.destroy();
260
+ if (this._resizeObserver) {
261
+ this._resizeObserver.destroy();
262
+ }
263
+ }
264
+ /**
265
+ * Determines the panel top position of the {@link #panel} in {@link #panelPositions}.
266
+ *
267
+ * @param editableRect Rect of the {@link #element}.
268
+ * @param panelRect Rect of the {@link #panel}.
269
+ */ _getPanelPositionTop(editableRect, panelRect) {
270
+ let top;
271
+ if (editableRect.top > panelRect.height + this.viewportTopOffset) {
272
+ top = editableRect.top - panelRect.height;
273
+ } else if (editableRect.bottom > panelRect.height + this.viewportTopOffset + 50) {
274
+ top = this.viewportTopOffset;
275
+ } else {
276
+ top = editableRect.bottom;
277
+ }
278
+ return top;
279
+ }
280
+ /**
281
+ * Returns the positions for {@link #panelPositions}.
282
+ *
283
+ * See: {@link module:utils/dom/position~Options#positions}.
284
+ */ _getPanelPositions() {
285
+ const positions = [
286
+ (editableRect, panelRect)=>{
287
+ return {
288
+ top: this._getPanelPositionTop(editableRect, panelRect),
289
+ left: editableRect.left,
290
+ name: 'toolbar_west',
291
+ config: {
292
+ withArrow: false
293
+ }
294
+ };
295
+ },
296
+ (editableRect, panelRect)=>{
297
+ return {
298
+ top: this._getPanelPositionTop(editableRect, panelRect),
299
+ left: editableRect.left + editableRect.width - panelRect.width,
300
+ name: 'toolbar_east',
301
+ config: {
302
+ withArrow: false
303
+ }
304
+ };
305
+ }
306
+ ];
307
+ if (this.locale.uiLanguageDirection === 'ltr') {
308
+ return positions;
309
+ } else {
310
+ return positions.reverse();
311
+ }
312
+ }
313
+ }
314
+
315
+ /**
316
+ * The inline editor implementation. It uses an inline editable and a floating toolbar.
317
+ * See the {@glink examples/builds/inline-editor demo}.
318
+ *
319
+ * In order to create a inline editor instance, use the static
320
+ * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method.
321
+ */ class InlineEditor extends /* #__PURE__ */ ElementApiMixin(Editor) {
322
+ /**
323
+ * @inheritdoc
324
+ */ static get editorName() {
325
+ return 'InlineEditor';
326
+ }
327
+ /**
328
+ * @inheritDoc
329
+ */ ui;
330
+ /**
331
+ * Creates an instance of the inline editor.
332
+ *
333
+ * **Note:** Do not use the constructor to create editor instances. Use the static
334
+ * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`} method instead.
335
+ *
336
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
337
+ * (on which the editor will be initialized) or initial data for the editor. For more information see
338
+ * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}.
339
+ * @param config The editor configuration.
340
+ */ constructor(sourceElementOrData, config = {}){
341
+ // If both `config.initialData` and initial data parameter in `create()` are set, then throw.
342
+ if (!isElement(sourceElementOrData) && config.initialData !== undefined) {
343
+ // Documented in core/editor/editorconfig.jsdoc.
344
+ // eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
345
+ throw new CKEditorError('editor-create-initial-data', null);
346
+ }
347
+ super(config);
348
+ this.config.define('menuBar.isVisible', false);
349
+ if (this.config.get('initialData') === undefined) {
350
+ this.config.set('initialData', getInitialData(sourceElementOrData));
351
+ }
352
+ this.model.document.createRoot();
353
+ if (isElement(sourceElementOrData)) {
354
+ this.sourceElement = sourceElementOrData;
355
+ secureSourceElement(this, sourceElementOrData);
356
+ }
357
+ const shouldToolbarGroupWhenFull = !this.config.get('toolbar.shouldNotGroupWhenFull');
358
+ const menuBarConfig = this.config.get('menuBar');
359
+ const view = new InlineEditorUIView(this.locale, this.editing.view, this.sourceElement, {
360
+ shouldToolbarGroupWhenFull,
361
+ useMenuBar: menuBarConfig.isVisible,
362
+ label: this.config.get('label')
363
+ });
364
+ this.ui = new InlineEditorUI(this, view);
365
+ attachToForm(this);
366
+ }
367
+ /**
368
+ * Destroys the editor instance, releasing all resources used by it.
369
+ *
370
+ * Updates the original editor element with the data if the
371
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
372
+ * configuration option is set to `true`.
373
+ */ destroy() {
374
+ // Cache the data, then destroy.
375
+ // It's safe to assume that the model->view conversion will not work after super.destroy().
376
+ const data = this.getData();
377
+ this.ui.destroy();
378
+ return super.destroy().then(()=>{
379
+ if (this.sourceElement) {
380
+ this.updateSourceElement(data);
381
+ }
382
+ });
383
+ }
384
+ /**
385
+ * Creates a new inline editor instance.
386
+ *
387
+ * There are three general ways how the editor can be initialized.
388
+ *
389
+ * # Using an existing DOM element (and loading data from it)
390
+ *
391
+ * You can initialize the editor using an existing DOM element:
392
+ *
393
+ * ```ts
394
+ * InlineEditor
395
+ * .create( document.querySelector( '#editor' ) )
396
+ * .then( editor => {
397
+ * console.log( 'Editor was initialized', editor );
398
+ * } )
399
+ * .catch( err => {
400
+ * console.error( err.stack );
401
+ * } );
402
+ * ```
403
+ *
404
+ * The element's content will be used as the editor data and the element will become the editable element.
405
+ *
406
+ * # Creating a detached editor
407
+ *
408
+ * Alternatively, you can initialize the editor by passing the initial data directly as a `String`.
409
+ * In this case, the editor will render an element that must be inserted into the DOM for the editor to work properly:
410
+ *
411
+ * ```ts
412
+ * InlineEditor
413
+ * .create( '<p>Hello world!</p>' )
414
+ * .then( editor => {
415
+ * console.log( 'Editor was initialized', editor );
416
+ *
417
+ * // Initial data was provided so the editor UI element needs to be added manually to the DOM.
418
+ * document.body.appendChild( editor.ui.element );
419
+ * } )
420
+ * .catch( err => {
421
+ * console.error( err.stack );
422
+ * } );
423
+ * ```
424
+ *
425
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
426
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
427
+ *
428
+ * # Using an existing DOM element (and data provided in `config.initialData`)
429
+ *
430
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
431
+ *
432
+ * ```ts
433
+ * InlineEditor
434
+ * .create( document.querySelector( '#editor' ), {
435
+ * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
436
+ * } )
437
+ * .then( editor => {
438
+ * console.log( 'Editor was initialized', editor );
439
+ * } )
440
+ * .catch( err => {
441
+ * console.error( err.stack );
442
+ * } );
443
+ * ```
444
+ *
445
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
446
+ * makes it difficult to set the content of the source element.
447
+ *
448
+ * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
449
+ *
450
+ * # Configuring the editor
451
+ *
452
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
453
+ * customizing plugins, toolbar and more.
454
+ *
455
+ * @param sourceElementOrData The DOM element that will be the source for the created editor
456
+ * or the editor's initial data.
457
+ *
458
+ * If a DOM element is passed, its content will be automatically loaded to the editor upon initialization.
459
+ * The editor data will be set back to the original element once the editor is destroyed only if the
460
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy}
461
+ * option is set to `true`.
462
+ *
463
+ * If the initial data is passed, a detached editor will be created. In this case you need to insert it into the DOM manually.
464
+ * It is available under the {@link module:editor-inline/inlineeditorui~InlineEditorUI#element `editor.ui.element`} property.
465
+ *
466
+ * @param config The editor configuration.
467
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
468
+ */ static create(sourceElementOrData, config = {}) {
469
+ return new Promise((resolve)=>{
470
+ if (isElement(sourceElementOrData) && sourceElementOrData.tagName === 'TEXTAREA') {
471
+ // Documented in core/editor/editor.js
472
+ // eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
473
+ throw new CKEditorError('editor-wrong-element', null);
474
+ }
475
+ const editor = new this(sourceElementOrData, config);
476
+ resolve(editor.initPlugins().then(()=>editor.ui.init()).then(()=>editor.data.init(editor.config.get('initialData'))).then(()=>editor.fire('ready')).then(()=>editor));
477
+ });
478
+ }
479
+ }
480
+ function getInitialData(sourceElementOrData) {
481
+ return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
482
+ }
483
+ function isElement(value) {
484
+ return isElement$1(value);
485
+ }
486
+
487
+ export { InlineEditor };
488
+ //# sourceMappingURL=index.js.map