@editora/ui-editor 0.1.4
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/LICENSE +21 -0
- package/dist/index.cjs.js +8 -0
- package/dist/index.esm.js +197 -0
- package/package.json +47 -0
- package/src/components/ui-block-controls.ts +10 -0
- package/src/components/ui-command-palette.ts +34 -0
- package/src/components/ui-context-menu.ts +61 -0
- package/src/components/ui-floating-toolbar.ts +49 -0
- package/src/components/ui-plugin-panel.ts +21 -0
- package/src/components/ui-selection-popup.ts +38 -0
- package/src/index.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ajay Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@editora/ui-core");class r extends i.ElementBase{constructor(){super(),this._portalEl=null,this._cleanup=void 0}static get observedAttributes(){return["anchor-id","open"]}connectedCallback(){super.connectedCallback()}attributeChangedCallback(){this.render()}showForAnchorId(t){this.setAttribute("anchor-id",t),this.setAttribute("open","")}hide(){this.removeAttribute("open")}render(){const t=this.getAttribute("anchor-id"),s=this.hasAttribute("open");if(this.setContent("<slot></slot>"),s&&t){const o=document.getElementById(t);if(!o){if(this._cleanup){try{this._cleanup()}catch{}this._cleanup=void 0}this._portalEl=null;return}this._portalEl||(this._portalEl=document.createElement("div")),this._portalEl.innerHTML="";const e=document.createElement("div");e.className="floating-toolbar";const n=this.querySelector('[slot="toolbar"]');n&&e.appendChild(n.cloneNode(!0)),this._portalEl.appendChild(e),this._cleanup=i.showPortalFor(o,this._portalEl,"top")}else this._cleanup&&(this._cleanup(),this._cleanup=void 0),this._portalEl=null}}typeof customElements<"u"&&!customElements.get("ui-floating-toolbar")&&customElements.define("ui-floating-toolbar",r);const m=`
|
|
2
|
+
.palette { width: 520px; max-width: 90vw; background: white; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,0.12); padding: 8px; }
|
|
3
|
+
.list { max-height: 300px; overflow: auto; }
|
|
4
|
+
.item { padding: 8px; cursor: pointer; }
|
|
5
|
+
`;class c extends i.ElementBase{static get observedAttributes(){return["open"]}constructor(){super()}open(){this.setAttribute("open","")}close(){this.removeAttribute("open")}render(){if(!this.hasAttribute("open")){this.setContent("");return}const s=`<div class="palette" role="dialog" aria-modal="true">
|
|
6
|
+
<input part="search" placeholder="Type a command..." />
|
|
7
|
+
<div class="list"><slot></slot></div>
|
|
8
|
+
</div>`;this.setContent(`<style>${m}</style>${s}`),Array.from(this.querySelectorAll('[slot="command"]')).forEach((e,n)=>{e.addEventListener("click",()=>this.dispatchEvent(new CustomEvent("select",{detail:{index:n}})))})}}typeof customElements<"u"&&!customElements.get("ui-command-palette")&&customElements.define("ui-command-palette",c);class a extends i.ElementBase{constructor(){super(),this._portalEl=null,this._cleanup=void 0}static get observedAttributes(){return["anchor-id","open"]}openFor(t){this.setAttribute("anchor-id",t),this.setAttribute("open","")}close(){this.removeAttribute("open")}openAt(t,s){const o={getBoundingClientRect:()=>({top:s,bottom:s,left:t,right:t,width:0,height:0})};this.setAttribute("open",""),this._portalEl||(this._portalEl=document.createElement("div")),this._portalEl.innerHTML="";const e=document.createElement("div");e.className="context-menu";const n=this.querySelector('[slot="content"]');n&&e.appendChild(n.cloneNode(!0)),this._portalEl.appendChild(e),this._cleanup=i.showPortalFor(o,this._portalEl,{placement:"bottom",shift:!0})}render(){const t=this.getAttribute("anchor-id"),s=this.hasAttribute("open");if(this.setContent("<slot></slot>"),s&&t){const o=document.getElementById(t);if(!o){if(this._cleanup){try{this._cleanup()}catch{}this._cleanup=void 0}this._portalEl=null;return}this._portalEl||(this._portalEl=document.createElement("div")),this._portalEl.innerHTML="";const e=document.createElement("div");e.className="context-menu";const n=this.querySelector('[slot="content"]');n&&e.appendChild(n.cloneNode(!0)),this._portalEl.appendChild(e),this._cleanup=i.showPortalFor(o,this._portalEl,"bottom")}else this._cleanup&&(this._cleanup(),this._cleanup=void 0),this._portalEl=null}}typeof customElements<"u"&&!customElements.get("ui-context-menu")&&customElements.define("ui-context-menu",a);class u extends i.ElementBase{static get observedAttributes(){return["open","position"]}constructor(){super()}open(){this.setAttribute("open","")}close(){this.removeAttribute("open")}render(){const t=this.hasAttribute("open"),s=this.getAttribute("position")||"right";if(!t){this.setContent("");return}const o=`<div class="panel panel-${s}"><slot></slot></div>`;this.setContent(o)}}typeof customElements<"u"&&!customElements.get("ui-plugin-panel")&&customElements.define("ui-plugin-panel",u);class p extends i.ElementBase{constructor(){super()}render(){this.setContent('<div class="block-controls"><slot></slot></div>')}}typeof customElements<"u"&&!customElements.get("ui-block-controls")&&customElements.define("ui-block-controls",p);class h extends i.ElementBase{constructor(){super(),this._portalEl=null,this._cleanup=void 0}static get observedAttributes(){return["anchor-id","open"]}openFor(t){this.setAttribute("anchor-id",t),this.setAttribute("open","")}close(){this.removeAttribute("open")}render(){const t=this.getAttribute("anchor-id"),s=this.hasAttribute("open");if(this.setContent("<slot></slot>"),s&&t){const o=document.getElementById(t);if(!o)return;this._portalEl||(this._portalEl=document.createElement("div")),this._portalEl.innerHTML="";const e=document.createElement("div");e.className="selection-popup";const n=this.querySelector('[slot="content"]');n&&e.appendChild(n.cloneNode(!0)),this._portalEl.appendChild(e),this._cleanup=i.showPortalFor(o,this._portalEl,"top")}else this._cleanup&&(this._cleanup(),this._cleanup=void 0),this._portalEl=null}}typeof customElements<"u"&&!customElements.get("ui-selection-popup")&&customElements.define("ui-selection-popup",h);exports.UIBlockControls=p;exports.UICommandPalette=c;exports.UIContextMenu=a;exports.UIFloatingToolbar=r;exports.UIPluginPanel=u;exports.UISelectionPopup=h;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ElementBase as i, showPortalFor as r } from "@editora/ui-core";
|
|
2
|
+
class a extends i {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(), this._portalEl = null, this._cleanup = void 0;
|
|
5
|
+
}
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ["anchor-id", "open"];
|
|
8
|
+
}
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
super.connectedCallback();
|
|
11
|
+
}
|
|
12
|
+
attributeChangedCallback() {
|
|
13
|
+
this.render();
|
|
14
|
+
}
|
|
15
|
+
showForAnchorId(t) {
|
|
16
|
+
this.setAttribute("anchor-id", t), this.setAttribute("open", "");
|
|
17
|
+
}
|
|
18
|
+
hide() {
|
|
19
|
+
this.removeAttribute("open");
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
const t = this.getAttribute("anchor-id"), s = this.hasAttribute("open");
|
|
23
|
+
if (this.setContent("<slot></slot>"), s && t) {
|
|
24
|
+
const o = document.getElementById(t);
|
|
25
|
+
if (!o) {
|
|
26
|
+
if (this._cleanup) {
|
|
27
|
+
try {
|
|
28
|
+
this._cleanup();
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
this._cleanup = void 0;
|
|
32
|
+
}
|
|
33
|
+
this._portalEl = null;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._portalEl || (this._portalEl = document.createElement("div")), this._portalEl.innerHTML = "";
|
|
37
|
+
const e = document.createElement("div");
|
|
38
|
+
e.className = "floating-toolbar";
|
|
39
|
+
const n = this.querySelector('[slot="toolbar"]');
|
|
40
|
+
n && e.appendChild(n.cloneNode(!0)), this._portalEl.appendChild(e), this._cleanup = r(o, this._portalEl, "top");
|
|
41
|
+
} else
|
|
42
|
+
this._cleanup && (this._cleanup(), this._cleanup = void 0), this._portalEl = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
typeof customElements < "u" && !customElements.get("ui-floating-toolbar") && customElements.define("ui-floating-toolbar", a);
|
|
46
|
+
const p = `
|
|
47
|
+
.palette { width: 520px; max-width: 90vw; background: white; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,0.12); padding: 8px; }
|
|
48
|
+
.list { max-height: 300px; overflow: auto; }
|
|
49
|
+
.item { padding: 8px; cursor: pointer; }
|
|
50
|
+
`;
|
|
51
|
+
class u extends i {
|
|
52
|
+
static get observedAttributes() {
|
|
53
|
+
return ["open"];
|
|
54
|
+
}
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
}
|
|
58
|
+
open() {
|
|
59
|
+
this.setAttribute("open", "");
|
|
60
|
+
}
|
|
61
|
+
close() {
|
|
62
|
+
this.removeAttribute("open");
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
if (!this.hasAttribute("open")) {
|
|
66
|
+
this.setContent("");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const s = `<div class="palette" role="dialog" aria-modal="true">
|
|
70
|
+
<input part="search" placeholder="Type a command..." />
|
|
71
|
+
<div class="list"><slot></slot></div>
|
|
72
|
+
</div>`;
|
|
73
|
+
this.setContent(`<style>${p}</style>${s}`), Array.from(this.querySelectorAll('[slot="command"]')).forEach((e, n) => {
|
|
74
|
+
e.addEventListener("click", () => this.dispatchEvent(new CustomEvent("select", { detail: { index: n } })));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
typeof customElements < "u" && !customElements.get("ui-command-palette") && customElements.define("ui-command-palette", u);
|
|
79
|
+
class h extends i {
|
|
80
|
+
constructor() {
|
|
81
|
+
super(), this._portalEl = null, this._cleanup = void 0;
|
|
82
|
+
}
|
|
83
|
+
static get observedAttributes() {
|
|
84
|
+
return ["anchor-id", "open"];
|
|
85
|
+
}
|
|
86
|
+
openFor(t) {
|
|
87
|
+
this.setAttribute("anchor-id", t), this.setAttribute("open", "");
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
this.removeAttribute("open");
|
|
91
|
+
}
|
|
92
|
+
// open the context menu at arbitrary client coordinates (uses a virtual anchor)
|
|
93
|
+
openAt(t, s) {
|
|
94
|
+
const o = {
|
|
95
|
+
getBoundingClientRect: () => ({ top: s, bottom: s, left: t, right: t, width: 0, height: 0 })
|
|
96
|
+
};
|
|
97
|
+
this.setAttribute("open", ""), this._portalEl || (this._portalEl = document.createElement("div")), this._portalEl.innerHTML = "";
|
|
98
|
+
const e = document.createElement("div");
|
|
99
|
+
e.className = "context-menu";
|
|
100
|
+
const n = this.querySelector('[slot="content"]');
|
|
101
|
+
n && e.appendChild(n.cloneNode(!0)), this._portalEl.appendChild(e), this._cleanup = r(o, this._portalEl, { placement: "bottom", shift: !0 });
|
|
102
|
+
}
|
|
103
|
+
render() {
|
|
104
|
+
const t = this.getAttribute("anchor-id"), s = this.hasAttribute("open");
|
|
105
|
+
if (this.setContent("<slot></slot>"), s && t) {
|
|
106
|
+
const o = document.getElementById(t);
|
|
107
|
+
if (!o) {
|
|
108
|
+
if (this._cleanup) {
|
|
109
|
+
try {
|
|
110
|
+
this._cleanup();
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
this._cleanup = void 0;
|
|
114
|
+
}
|
|
115
|
+
this._portalEl = null;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this._portalEl || (this._portalEl = document.createElement("div")), this._portalEl.innerHTML = "";
|
|
119
|
+
const e = document.createElement("div");
|
|
120
|
+
e.className = "context-menu";
|
|
121
|
+
const n = this.querySelector('[slot="content"]');
|
|
122
|
+
n && e.appendChild(n.cloneNode(!0)), this._portalEl.appendChild(e), this._cleanup = r(o, this._portalEl, "bottom");
|
|
123
|
+
} else
|
|
124
|
+
this._cleanup && (this._cleanup(), this._cleanup = void 0), this._portalEl = null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
typeof customElements < "u" && !customElements.get("ui-context-menu") && customElements.define("ui-context-menu", h);
|
|
128
|
+
class d extends i {
|
|
129
|
+
static get observedAttributes() {
|
|
130
|
+
return ["open", "position"];
|
|
131
|
+
}
|
|
132
|
+
constructor() {
|
|
133
|
+
super();
|
|
134
|
+
}
|
|
135
|
+
open() {
|
|
136
|
+
this.setAttribute("open", "");
|
|
137
|
+
}
|
|
138
|
+
close() {
|
|
139
|
+
this.removeAttribute("open");
|
|
140
|
+
}
|
|
141
|
+
render() {
|
|
142
|
+
const t = this.hasAttribute("open"), s = this.getAttribute("position") || "right";
|
|
143
|
+
if (!t) {
|
|
144
|
+
this.setContent("");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const o = `<div class="panel panel-${s}"><slot></slot></div>`;
|
|
148
|
+
this.setContent(o);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
typeof customElements < "u" && !customElements.get("ui-plugin-panel") && customElements.define("ui-plugin-panel", d);
|
|
152
|
+
class m extends i {
|
|
153
|
+
constructor() {
|
|
154
|
+
super();
|
|
155
|
+
}
|
|
156
|
+
render() {
|
|
157
|
+
this.setContent('<div class="block-controls"><slot></slot></div>');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
typeof customElements < "u" && !customElements.get("ui-block-controls") && customElements.define("ui-block-controls", m);
|
|
161
|
+
class E extends i {
|
|
162
|
+
constructor() {
|
|
163
|
+
super(), this._portalEl = null, this._cleanup = void 0;
|
|
164
|
+
}
|
|
165
|
+
static get observedAttributes() {
|
|
166
|
+
return ["anchor-id", "open"];
|
|
167
|
+
}
|
|
168
|
+
openFor(t) {
|
|
169
|
+
this.setAttribute("anchor-id", t), this.setAttribute("open", "");
|
|
170
|
+
}
|
|
171
|
+
close() {
|
|
172
|
+
this.removeAttribute("open");
|
|
173
|
+
}
|
|
174
|
+
render() {
|
|
175
|
+
const t = this.getAttribute("anchor-id"), s = this.hasAttribute("open");
|
|
176
|
+
if (this.setContent("<slot></slot>"), s && t) {
|
|
177
|
+
const o = document.getElementById(t);
|
|
178
|
+
if (!o)
|
|
179
|
+
return;
|
|
180
|
+
this._portalEl || (this._portalEl = document.createElement("div")), this._portalEl.innerHTML = "";
|
|
181
|
+
const e = document.createElement("div");
|
|
182
|
+
e.className = "selection-popup";
|
|
183
|
+
const n = this.querySelector('[slot="content"]');
|
|
184
|
+
n && e.appendChild(n.cloneNode(!0)), this._portalEl.appendChild(e), this._cleanup = r(o, this._portalEl, "top");
|
|
185
|
+
} else
|
|
186
|
+
this._cleanup && (this._cleanup(), this._cleanup = void 0), this._portalEl = null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
typeof customElements < "u" && !customElements.get("ui-selection-popup") && customElements.define("ui-selection-popup", E);
|
|
190
|
+
export {
|
|
191
|
+
m as UIBlockControls,
|
|
192
|
+
u as UICommandPalette,
|
|
193
|
+
h as UIContextMenu,
|
|
194
|
+
a as UIFloatingToolbar,
|
|
195
|
+
d as UIPluginPanel,
|
|
196
|
+
E as UISelectionPopup
|
|
197
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@editora/ui-editor",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Editor-focused UI extensions for Editora (floating toolbar, command palette, context menus)",
|
|
5
|
+
"author": "Ajay Kumar <ajaykr089@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ajaykr089/Editora.git",
|
|
10
|
+
"directory": "packages/ui-editor"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://editora-ecosystem.netlify.app/docs/ui-react",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ajaykr089/Editora/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "dist/index.cjs.js",
|
|
17
|
+
"module": "dist/index.esm.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"dev": "vite build --watch",
|
|
26
|
+
"prepare": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@editora/ui-core": "^0.1.17"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@editora/ui-core": "^0.1.17"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"vite": "^4.5.14"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.esm.js",
|
|
42
|
+
"require": "./dist/index.cjs.js",
|
|
43
|
+
"default": "./dist/index.esm.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "7883627e823aa99dd5ecb66a5201116df972f88b"
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
|
|
3
|
+
export class UIBlockControls extends ElementBase {
|
|
4
|
+
constructor() { super(); }
|
|
5
|
+
protected render() { this.setContent(`<div class="block-controls"><slot></slot></div>`); }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-block-controls')) {
|
|
9
|
+
customElements.define('ui-block-controls', UIBlockControls);
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
|
|
3
|
+
const style = `
|
|
4
|
+
.palette { width: 520px; max-width: 90vw; background: white; border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,0.12); padding: 8px; }
|
|
5
|
+
.list { max-height: 300px; overflow: auto; }
|
|
6
|
+
.item { padding: 8px; cursor: pointer; }
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export class UICommandPalette extends ElementBase {
|
|
10
|
+
static get observedAttributes() { return ['open']; }
|
|
11
|
+
constructor() { super(); }
|
|
12
|
+
|
|
13
|
+
open() { this.setAttribute('open',''); }
|
|
14
|
+
close() { this.removeAttribute('open'); }
|
|
15
|
+
|
|
16
|
+
protected render() {
|
|
17
|
+
const open = this.hasAttribute('open');
|
|
18
|
+
if (!open) { this.setContent(''); return; }
|
|
19
|
+
const html = `<div class="palette" role="dialog" aria-modal="true">
|
|
20
|
+
<input part="search" placeholder="Type a command..." />
|
|
21
|
+
<div class="list"><slot></slot></div>
|
|
22
|
+
</div>`;
|
|
23
|
+
this.setContent(`<style>${style}</style>${html}`);
|
|
24
|
+
// wire clicks from slotted items
|
|
25
|
+
const items = Array.from(this.querySelectorAll('[slot="command"]'));
|
|
26
|
+
items.forEach((it, i) => {
|
|
27
|
+
(it as HTMLElement).addEventListener('click', () => this.dispatchEvent(new CustomEvent('select', { detail: { index: i } })));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-command-palette')) {
|
|
33
|
+
customElements.define('ui-command-palette', UICommandPalette);
|
|
34
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
import { showPortalFor } from '@editora/ui-core';
|
|
3
|
+
|
|
4
|
+
export class UIContextMenu extends ElementBase {
|
|
5
|
+
static get observedAttributes() { return ['anchor-id','open']; }
|
|
6
|
+
private _portalEl: HTMLElement | null = null;
|
|
7
|
+
private _cleanup: (() => void) | undefined = undefined;
|
|
8
|
+
|
|
9
|
+
constructor() { super(); }
|
|
10
|
+
|
|
11
|
+
openFor(anchorId: string) { this.setAttribute('anchor-id', anchorId); this.setAttribute('open',''); }
|
|
12
|
+
close() { this.removeAttribute('open'); }
|
|
13
|
+
|
|
14
|
+
// open the context menu at arbitrary client coordinates (uses a virtual anchor)
|
|
15
|
+
openAt(x: number, y: number) {
|
|
16
|
+
// create a very small virtual rect centered at the provided point
|
|
17
|
+
const virtual: any = {
|
|
18
|
+
getBoundingClientRect: () => ({ top: y, bottom: y, left: x, right: x, width: 0, height: 0 })
|
|
19
|
+
};
|
|
20
|
+
this.setAttribute('open','');
|
|
21
|
+
if (!this._portalEl) this._portalEl = document.createElement('div');
|
|
22
|
+
this._portalEl.innerHTML = '';
|
|
23
|
+
const panel = document.createElement('div');
|
|
24
|
+
panel.className = 'context-menu';
|
|
25
|
+
const sl = this.querySelector('[slot="content"]');
|
|
26
|
+
if (sl) panel.appendChild(sl.cloneNode(true));
|
|
27
|
+
this._portalEl.appendChild(panel);
|
|
28
|
+
this._cleanup = showPortalFor(virtual, this._portalEl, { placement: 'bottom', shift: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected render() {
|
|
32
|
+
const anchorId = this.getAttribute('anchor-id');
|
|
33
|
+
const open = this.hasAttribute('open');
|
|
34
|
+
this.setContent(`<slot></slot>`);
|
|
35
|
+
if (open && anchorId) {
|
|
36
|
+
const anchor = document.getElementById(anchorId);
|
|
37
|
+
// anchor missing -> ensure any previous portal is cleaned up and bail out
|
|
38
|
+
if (!anchor) {
|
|
39
|
+
if (this._cleanup) { try { this._cleanup(); } catch (e) {} this._cleanup = undefined; }
|
|
40
|
+
this._portalEl = null;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!this._portalEl) this._portalEl = document.createElement('div');
|
|
45
|
+
this._portalEl.innerHTML = '';
|
|
46
|
+
const panel = document.createElement('div');
|
|
47
|
+
panel.className = 'context-menu';
|
|
48
|
+
const sl = this.querySelector('[slot="content"]');
|
|
49
|
+
if (sl) panel.appendChild(sl.cloneNode(true));
|
|
50
|
+
this._portalEl.appendChild(panel);
|
|
51
|
+
this._cleanup = showPortalFor(anchor as HTMLElement, this._portalEl, 'bottom');
|
|
52
|
+
} else {
|
|
53
|
+
if (this._cleanup) { this._cleanup(); this._cleanup = undefined; }
|
|
54
|
+
this._portalEl = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-context-menu')) {
|
|
60
|
+
customElements.define('ui-context-menu', UIContextMenu);
|
|
61
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
import { showPortalFor } from '@editora/ui-core';
|
|
3
|
+
|
|
4
|
+
export class UIFloatingToolbar extends ElementBase {
|
|
5
|
+
static get observedAttributes() { return ['anchor-id','open']; }
|
|
6
|
+
private _portalEl: HTMLElement | null = null;
|
|
7
|
+
private _cleanup: (() => void) | undefined = undefined;
|
|
8
|
+
|
|
9
|
+
constructor() { super(); }
|
|
10
|
+
|
|
11
|
+
connectedCallback() { super.connectedCallback(); }
|
|
12
|
+
|
|
13
|
+
attributeChangedCallback() { this.render(); }
|
|
14
|
+
|
|
15
|
+
showForAnchorId(id: string) { this.setAttribute('anchor-id', id); this.setAttribute('open',''); }
|
|
16
|
+
hide() { this.removeAttribute('open'); }
|
|
17
|
+
|
|
18
|
+
protected render() {
|
|
19
|
+
const anchorId = this.getAttribute('anchor-id');
|
|
20
|
+
const open = this.hasAttribute('open');
|
|
21
|
+
this.setContent(`<slot></slot>`);
|
|
22
|
+
if (open && anchorId) {
|
|
23
|
+
const anchor = document.getElementById(anchorId);
|
|
24
|
+
// if anchor not present, cleanup any previous portal and bail out
|
|
25
|
+
if (!anchor) {
|
|
26
|
+
if (this._cleanup) { try { this._cleanup(); } catch (e) {} this._cleanup = undefined; }
|
|
27
|
+
this._portalEl = null;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!this._portalEl) this._portalEl = document.createElement('div');
|
|
32
|
+
this._portalEl.innerHTML = '';
|
|
33
|
+
const panel = document.createElement('div');
|
|
34
|
+
panel.className = 'floating-toolbar';
|
|
35
|
+
// clone slot content into panel
|
|
36
|
+
const sl = this.querySelector('[slot="toolbar"]');
|
|
37
|
+
if (sl) panel.appendChild(sl.cloneNode(true));
|
|
38
|
+
this._portalEl.appendChild(panel);
|
|
39
|
+
this._cleanup = showPortalFor(anchor as HTMLElement, this._portalEl, 'top');
|
|
40
|
+
} else {
|
|
41
|
+
if (this._cleanup) { this._cleanup(); this._cleanup = undefined; }
|
|
42
|
+
this._portalEl = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-floating-toolbar')) {
|
|
48
|
+
customElements.define('ui-floating-toolbar', UIFloatingToolbar);
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
|
|
3
|
+
export class UIPluginPanel extends ElementBase {
|
|
4
|
+
static get observedAttributes() { return ['open','position']; }
|
|
5
|
+
constructor() { super(); }
|
|
6
|
+
|
|
7
|
+
open() { this.setAttribute('open',''); }
|
|
8
|
+
close() { this.removeAttribute('open'); }
|
|
9
|
+
|
|
10
|
+
protected render() {
|
|
11
|
+
const open = this.hasAttribute('open');
|
|
12
|
+
const position = this.getAttribute('position') || 'right';
|
|
13
|
+
if (!open) { this.setContent(''); return; }
|
|
14
|
+
const html = `<div class="panel panel-${position}"><slot></slot></div>`;
|
|
15
|
+
this.setContent(html);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-plugin-panel')) {
|
|
20
|
+
customElements.define('ui-plugin-panel', UIPluginPanel);
|
|
21
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ElementBase } from '@editora/ui-core';
|
|
2
|
+
import { showPortalFor } from '@editora/ui-core';
|
|
3
|
+
|
|
4
|
+
export class UISelectionPopup extends ElementBase {
|
|
5
|
+
static get observedAttributes() { return ['anchor-id','open']; }
|
|
6
|
+
private _portalEl: HTMLElement | null = null;
|
|
7
|
+
private _cleanup: (() => void) | undefined = undefined;
|
|
8
|
+
|
|
9
|
+
constructor() { super(); }
|
|
10
|
+
|
|
11
|
+
openFor(anchorId: string) { this.setAttribute('anchor-id', anchorId); this.setAttribute('open',''); }
|
|
12
|
+
close() { this.removeAttribute('open'); }
|
|
13
|
+
|
|
14
|
+
protected render() {
|
|
15
|
+
const anchorId = this.getAttribute('anchor-id');
|
|
16
|
+
const open = this.hasAttribute('open');
|
|
17
|
+
this.setContent(`<slot></slot>`);
|
|
18
|
+
if (open && anchorId) {
|
|
19
|
+
const anchor = document.getElementById(anchorId);
|
|
20
|
+
if (!anchor) return;
|
|
21
|
+
if (!this._portalEl) this._portalEl = document.createElement('div');
|
|
22
|
+
this._portalEl.innerHTML = '';
|
|
23
|
+
const panel = document.createElement('div');
|
|
24
|
+
panel.className = 'selection-popup';
|
|
25
|
+
const sl = this.querySelector('[slot="content"]');
|
|
26
|
+
if (sl) panel.appendChild(sl.cloneNode(true));
|
|
27
|
+
this._portalEl.appendChild(panel);
|
|
28
|
+
this._cleanup = showPortalFor(anchor as HTMLElement, this._portalEl, 'top');
|
|
29
|
+
} else {
|
|
30
|
+
if (this._cleanup) { this._cleanup(); this._cleanup = undefined; }
|
|
31
|
+
this._portalEl = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof customElements !== 'undefined' && !customElements.get('ui-selection-popup')) {
|
|
37
|
+
customElements.define('ui-selection-popup', UISelectionPopup);
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './components/ui-floating-toolbar';
|
|
2
|
+
export * from './components/ui-command-palette';
|
|
3
|
+
export * from './components/ui-context-menu';
|
|
4
|
+
export * from './components/ui-plugin-panel';
|
|
5
|
+
export * from './components/ui-block-controls';
|
|
6
|
+
export * from './components/ui-selection-popup';
|