@huanban/rulego-editor-ui 1.3.18 → 1.4.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.
- package/README.md +13 -5
- package/dist/components/ContextMenu.d.ts +8 -100
- package/dist/components/DebugConsole.d.ts +1 -1
- package/dist/components/PropertyPanel.d.ts +0 -117
- package/dist/components/Sidebar.d.ts +0 -87
- package/dist/components/Toolbar.d.ts +5 -74
- package/dist/components/WorkflowExplorer.d.ts +45 -0
- package/dist/components/safeIcon.d.ts +0 -5
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +4 -37
- package/dist/index.esm.js +393 -232
- package/dist/index.umd.js +2 -2
- package/dist/style.css +1 -0
- package/package.json +11 -6
- package/dist/index.cjs.js +0 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i18nText as
|
|
2
|
-
class
|
|
1
|
+
import { getEditorToolbarIconSvg as v, i18nText as g, isComponentFieldOption as x, clampContextMenuPosition as w, formatJsonBounded as k, redactSensitive as N, ExplorerTreeStore as I, DEFAULT_VIRTUAL_WINDOW_THRESHOLD as S, DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT as L, DEFAULT_VIRTUAL_WINDOW_OVERSCAN as A, calculateVirtualWindow as T } from "@huanban/rulego-editor-core";
|
|
2
|
+
class G {
|
|
3
3
|
constructor(e, t) {
|
|
4
4
|
this.collapsedGroups = /* @__PURE__ */ new Set(), this.searchKeyword = "", this.rootEl = null, this.unsubscribe = null, this.container = e, this.core = t.core, this.options = {
|
|
5
5
|
core: t.core,
|
|
@@ -8,10 +8,10 @@ class C {
|
|
|
8
8
|
searchPlaceholder: t.searchPlaceholder || this.text("sidebar.searchPlaceholder", "搜索组件..."),
|
|
9
9
|
width: t.width ?? "220px"
|
|
10
10
|
}, this.mount(), this.unsubscribe = this.core.store.select(
|
|
11
|
-
(
|
|
11
|
+
(s) => s.componentGroups
|
|
12
12
|
).subscribe(
|
|
13
|
-
(
|
|
14
|
-
this.renderGroups(
|
|
13
|
+
(s) => {
|
|
14
|
+
this.renderGroups(s);
|
|
15
15
|
}
|
|
16
16
|
);
|
|
17
17
|
}
|
|
@@ -23,16 +23,16 @@ class C {
|
|
|
23
23
|
*/
|
|
24
24
|
mount() {
|
|
25
25
|
if (this.rootEl = document.createElement("div"), this.rootEl.className = "rulego-sidebar", this.rootEl.style.width = this.options.width, this.options.searchable) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
this.searchKeyword =
|
|
33
|
-
const
|
|
34
|
-
this.renderGroups(
|
|
35
|
-
}),
|
|
26
|
+
const s = document.createElement("div");
|
|
27
|
+
s.className = "rulego-sidebar__search-wrapper";
|
|
28
|
+
const n = document.createElement("span");
|
|
29
|
+
n.className = "rulego-sidebar__search-icon", n.setAttribute("aria-hidden", "true"), n.innerHTML = v("search") || "";
|
|
30
|
+
const i = document.createElement("input");
|
|
31
|
+
i.type = "text", i.className = "rulego-sidebar__search", i.placeholder = this.options.searchPlaceholder, i.addEventListener("input", (o) => {
|
|
32
|
+
this.searchKeyword = o.target.value.toLowerCase();
|
|
33
|
+
const l = this.core.store.getState().componentGroups;
|
|
34
|
+
this.renderGroups(l);
|
|
35
|
+
}), s.appendChild(n), s.appendChild(i), this.rootEl.appendChild(s);
|
|
36
36
|
}
|
|
37
37
|
const e = document.createElement("div");
|
|
38
38
|
e.className = "rulego-sidebar__groups", this.rootEl.appendChild(e), this.container.appendChild(this.rootEl);
|
|
@@ -57,15 +57,15 @@ class C {
|
|
|
57
57
|
const t = this.rootEl.querySelector(".rulego-sidebar__groups");
|
|
58
58
|
if (!t) return;
|
|
59
59
|
t.replaceChildren();
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
|
|
60
|
+
const s = this.filterGroups(e);
|
|
61
|
+
if (s.length === 0) {
|
|
62
|
+
const n = document.createElement("div");
|
|
63
|
+
n.className = "rulego-sidebar__empty", n.textContent = this.text("sidebar.noResults", "无匹配组件"), t.appendChild(n);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
for (const
|
|
67
|
-
const
|
|
68
|
-
t.appendChild(
|
|
66
|
+
for (const n of s) {
|
|
67
|
+
const i = this.createGroupElement(n);
|
|
68
|
+
t.appendChild(i);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -76,25 +76,25 @@ class C {
|
|
|
76
76
|
createGroupElement(e) {
|
|
77
77
|
const t = document.createElement("div");
|
|
78
78
|
t.className = "rulego-sidebar__group";
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
79
|
+
const s = document.createElement("div");
|
|
80
|
+
s.className = "rulego-sidebar__group-header", s.style.borderLeftColor = e.color || "#ccc";
|
|
81
|
+
const n = this.collapsedGroups.has(e.category), i = document.createElement("span");
|
|
82
|
+
i.className = `rulego-sidebar__arrow ${n ? "rulego-sidebar__arrow--collapsed" : ""}`, i.textContent = "▼";
|
|
83
|
+
const o = document.createElement("span");
|
|
84
|
+
o.className = "rulego-sidebar__group-label", o.textContent = this.text(`category.${e.category}`, e.label || e.category);
|
|
85
|
+
const l = document.createElement("span");
|
|
86
|
+
if (l.className = "rulego-sidebar__group-count", l.textContent = `${e.components.length}`, s.appendChild(i), s.appendChild(o), s.appendChild(l), s.addEventListener("click", () => {
|
|
87
87
|
this.collapsedGroups.has(e.category) ? this.collapsedGroups.delete(e.category) : this.collapsedGroups.add(e.category);
|
|
88
|
-
const
|
|
89
|
-
this.renderGroups(
|
|
90
|
-
}), t.appendChild(
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
for (const
|
|
94
|
-
const
|
|
95
|
-
|
|
88
|
+
const d = this.core.store.getState().componentGroups;
|
|
89
|
+
this.renderGroups(d);
|
|
90
|
+
}), t.appendChild(s), !n) {
|
|
91
|
+
const d = document.createElement("div");
|
|
92
|
+
d.className = "rulego-sidebar__component-list";
|
|
93
|
+
for (const r of e.components) {
|
|
94
|
+
const a = this.createComponentElement(r, e.color);
|
|
95
|
+
d.appendChild(a);
|
|
96
96
|
}
|
|
97
|
-
t.appendChild(
|
|
97
|
+
t.appendChild(d);
|
|
98
98
|
}
|
|
99
99
|
return t;
|
|
100
100
|
}
|
|
@@ -105,23 +105,23 @@ class C {
|
|
|
105
105
|
* @returns 组件 HTMLElement
|
|
106
106
|
*/
|
|
107
107
|
createComponentElement(e, t) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
|
|
108
|
+
const s = document.createElement("div");
|
|
109
|
+
s.className = "rulego-sidebar__component", s.setAttribute("draggable", "true");
|
|
110
|
+
const n = this.componentLabel(e), i = this.text(`fields.${e.type}`, e.desc || n);
|
|
111
|
+
s.title = i || n;
|
|
112
|
+
const o = document.createElement("span");
|
|
113
|
+
o.className = "rulego-sidebar__component-color", o.style.backgroundColor = e.color || t || "#ccc";
|
|
114
|
+
const l = document.createElement("span");
|
|
115
|
+
return l.className = "rulego-sidebar__component-name", l.textContent = n, s.appendChild(o), s.appendChild(l), s.addEventListener("dragstart", (d) => {
|
|
116
|
+
d.dataTransfer && (d.dataTransfer.setData("application/rulego-component", JSON.stringify({
|
|
117
117
|
type: e.type,
|
|
118
118
|
category: e.category,
|
|
119
|
-
label:
|
|
119
|
+
label: n,
|
|
120
120
|
color: e.color || t
|
|
121
|
-
})),
|
|
122
|
-
}),
|
|
123
|
-
|
|
124
|
-
}),
|
|
121
|
+
})), d.dataTransfer.effectAllowed = "copy"), s.classList.add("rulego-sidebar__component--dragging");
|
|
122
|
+
}), s.addEventListener("dragend", () => {
|
|
123
|
+
s.classList.remove("rulego-sidebar__component--dragging");
|
|
124
|
+
}), s;
|
|
125
125
|
}
|
|
126
126
|
// ============================================================
|
|
127
127
|
// 搜索过滤
|
|
@@ -134,9 +134,9 @@ class C {
|
|
|
134
134
|
filterGroups(e) {
|
|
135
135
|
return this.searchKeyword ? e.map((t) => ({
|
|
136
136
|
...t,
|
|
137
|
-
components: t.components.filter((
|
|
138
|
-
const
|
|
139
|
-
return
|
|
137
|
+
components: t.components.filter((s) => {
|
|
138
|
+
const n = this.componentLabel(s).toLowerCase(), i = this.text(`fields.${s.type}`, s.desc || "").toLowerCase();
|
|
139
|
+
return n.includes(this.searchKeyword) || s.type.toLowerCase().includes(this.searchKeyword) || i.includes(this.searchKeyword);
|
|
140
140
|
})
|
|
141
141
|
})).filter((t) => t.components.length > 0) : e;
|
|
142
142
|
}
|
|
@@ -172,56 +172,60 @@ class C {
|
|
|
172
172
|
return this.rootEl;
|
|
173
173
|
}
|
|
174
174
|
text(e, t) {
|
|
175
|
-
return
|
|
175
|
+
return g(this.core.i18n, e, t);
|
|
176
176
|
}
|
|
177
177
|
componentLabel(e) {
|
|
178
178
|
return this.text(`components.${e.type}`, e.label || e.type.split("/").pop() || e.type);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function f(h, e) {
|
|
182
182
|
if (e) {
|
|
183
183
|
if (typeof e == "string") {
|
|
184
|
-
|
|
184
|
+
h.textContent = e;
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
if (e.kind === "text") {
|
|
188
|
-
|
|
188
|
+
h.textContent = e.value;
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
|
-
e.kind === "trusted-svg" &&
|
|
191
|
+
e.kind === "trusted-svg" && B(h, e.svg);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function B(h, e) {
|
|
195
195
|
const t = document.createElement("template");
|
|
196
196
|
t.innerHTML = e;
|
|
197
|
-
const
|
|
198
|
-
if (!
|
|
199
|
-
|
|
197
|
+
const s = t.content.firstElementChild;
|
|
198
|
+
if (!s || s.tagName.toLowerCase() !== "svg") {
|
|
199
|
+
h.textContent = "";
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
|
-
|
|
202
|
+
C(s), h.replaceChildren(s);
|
|
203
203
|
}
|
|
204
|
-
function h
|
|
205
|
-
for (const e of Array.from(
|
|
206
|
-
const t = e.name.toLowerCase(),
|
|
207
|
-
(t.startsWith("on") ||
|
|
204
|
+
function C(h) {
|
|
205
|
+
for (const e of Array.from(h.attributes)) {
|
|
206
|
+
const t = e.name.toLowerCase(), s = e.value.trim().toLowerCase();
|
|
207
|
+
(t.startsWith("on") || s.startsWith("javascript:") || s.startsWith("data:text/html")) && h.removeAttribute(e.name);
|
|
208
208
|
}
|
|
209
|
-
for (const e of Array.from(
|
|
209
|
+
for (const e of Array.from(h.children)) {
|
|
210
210
|
const t = e.tagName.toLowerCase();
|
|
211
211
|
if (t === "script" || t === "foreignobject") {
|
|
212
212
|
e.remove();
|
|
213
213
|
continue;
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
C(e);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
class
|
|
218
|
+
class $ {
|
|
219
219
|
constructor(e, t) {
|
|
220
220
|
this.rootEl = null, this.unsubscribe = null, this.buttonElements = /* @__PURE__ */ new Map(), this.container = e, this.core = t.core, this.options = {
|
|
221
221
|
core: t.core,
|
|
222
222
|
extraButtons: t.extraButtons ?? [],
|
|
223
223
|
showZoom: t.showZoom ?? !0,
|
|
224
|
-
height: t.height ?? "40px"
|
|
224
|
+
height: t.height ?? "40px",
|
|
225
|
+
onSave: t.onSave,
|
|
226
|
+
onDelete: t.onDelete,
|
|
227
|
+
onFullscreen: t.onFullscreen,
|
|
228
|
+
onAutoLayout: t.onAutoLayout
|
|
225
229
|
}, this.mount(), this.unsubscribe = this.core.store.subscribe(() => {
|
|
226
230
|
this.updateButtonStates();
|
|
227
231
|
});
|
|
@@ -245,18 +249,18 @@ class f {
|
|
|
245
249
|
}), e.push(...this.options.extraButtons));
|
|
246
250
|
for (const t of e) {
|
|
247
251
|
if (t.divider) {
|
|
248
|
-
const
|
|
249
|
-
|
|
252
|
+
const n = document.createElement("span");
|
|
253
|
+
n.className = "rulego-toolbar__divider", this.rootEl.appendChild(n);
|
|
250
254
|
}
|
|
251
255
|
if (!t.icon && t.divider) continue;
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
+
const s = document.createElement("button");
|
|
257
|
+
if (s.className = "rulego-toolbar__button", s.title = t.title, f(s, t.icon), t.label) {
|
|
258
|
+
const n = document.createElement("span");
|
|
259
|
+
n.className = "rulego-toolbar__button-label", n.textContent = t.label, s.appendChild(n);
|
|
256
260
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}), this.buttonElements.set(t.id,
|
|
261
|
+
s.addEventListener("click", (n) => {
|
|
262
|
+
n.preventDefault(), n.stopPropagation(), t.onClick();
|
|
263
|
+
}), this.buttonElements.set(t.id, s), this.rootEl.appendChild(s);
|
|
260
264
|
}
|
|
261
265
|
this.container.appendChild(this.rootEl), this.updateButtonStates();
|
|
262
266
|
}
|
|
@@ -277,70 +281,84 @@ class f {
|
|
|
277
281
|
const e = [
|
|
278
282
|
{
|
|
279
283
|
id: "undo",
|
|
280
|
-
icon: "
|
|
284
|
+
icon: this.toolbarIcon("undo"),
|
|
281
285
|
title: this.text("toolbar.undo", "撤销"),
|
|
282
286
|
disabled: () => !this.core.store.getState().canUndo,
|
|
283
|
-
onClick: () =>
|
|
287
|
+
onClick: () => {
|
|
288
|
+
this.core.history.undo();
|
|
289
|
+
}
|
|
284
290
|
},
|
|
285
291
|
{
|
|
286
292
|
id: "redo",
|
|
287
|
-
icon: "
|
|
293
|
+
icon: this.toolbarIcon("redo"),
|
|
288
294
|
title: this.text("toolbar.redo", "重做"),
|
|
289
295
|
disabled: () => !this.core.store.getState().canRedo,
|
|
290
296
|
onClick: () => {
|
|
297
|
+
this.core.history.redo();
|
|
291
298
|
}
|
|
292
299
|
},
|
|
293
300
|
{
|
|
294
301
|
id: "delete",
|
|
295
|
-
icon: "
|
|
302
|
+
icon: this.toolbarIcon("delete"),
|
|
296
303
|
title: this.text("toolbar.delete", "删除选中"),
|
|
297
304
|
divider: !0,
|
|
298
|
-
onClick: () =>
|
|
305
|
+
onClick: () => {
|
|
306
|
+
this.options.onDelete ? this.options.onDelete() : this.core.eventBus.emit("editor:delete-selected");
|
|
307
|
+
}
|
|
299
308
|
},
|
|
300
309
|
{
|
|
301
310
|
id: "save",
|
|
302
|
-
icon: "
|
|
303
|
-
title: this.text("toolbar.save", "保存"),
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
311
|
+
icon: this.toolbarIcon("save"),
|
|
312
|
+
title: this.options.onSave ? this.text("toolbar.save", "保存") : this.text("toolbar.saveHostRequired", "请先配置宿主保存回调"),
|
|
313
|
+
disabled: () => !this.options.onSave,
|
|
314
|
+
onClick: () => {
|
|
315
|
+
var t, s;
|
|
316
|
+
(s = (t = this.options).onSave) == null || s.call(t);
|
|
317
|
+
}
|
|
308
318
|
},
|
|
309
319
|
{
|
|
310
320
|
id: "fullscreen",
|
|
311
|
-
icon: "
|
|
321
|
+
icon: this.toolbarIcon("fullscreen"),
|
|
312
322
|
title: this.text("toolbar.fullscreen", "全屏"),
|
|
313
|
-
onClick: () =>
|
|
323
|
+
onClick: () => {
|
|
324
|
+
this.options.onFullscreen ? this.options.onFullscreen() : this.core.eventBus.emit("editor:fullscreen");
|
|
325
|
+
}
|
|
314
326
|
}
|
|
315
327
|
];
|
|
316
328
|
return this.options.showZoom && e.push(
|
|
317
329
|
{
|
|
318
330
|
id: "zoom-in",
|
|
319
|
-
icon: "
|
|
331
|
+
icon: this.toolbarIcon("zoom-in"),
|
|
320
332
|
title: this.text("toolbar.zoomIn", "放大"),
|
|
321
333
|
divider: !0,
|
|
322
334
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 1.1 })
|
|
323
335
|
},
|
|
324
336
|
{
|
|
325
337
|
id: "zoom-out",
|
|
326
|
-
icon: "
|
|
338
|
+
icon: this.toolbarIcon("zoom-out"),
|
|
327
339
|
title: this.text("toolbar.zoomOut", "缩小"),
|
|
328
340
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 0.9 })
|
|
329
341
|
},
|
|
330
342
|
{
|
|
331
343
|
id: "zoom-fit",
|
|
332
|
-
icon: "
|
|
344
|
+
icon: this.toolbarIcon("fit"),
|
|
333
345
|
title: this.text("toolbar.fitView", "适应画布"),
|
|
334
346
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 1 })
|
|
335
347
|
}
|
|
336
348
|
), e.push({
|
|
337
349
|
id: "auto-layout",
|
|
338
|
-
icon: "
|
|
350
|
+
icon: this.toolbarIcon("auto-layout"),
|
|
339
351
|
title: this.text("toolbar.autoLayout", "自动排版"),
|
|
340
352
|
divider: !0,
|
|
341
|
-
onClick: () =>
|
|
353
|
+
onClick: () => {
|
|
354
|
+
this.options.onAutoLayout ? this.options.onAutoLayout() : this.core.eventBus.emit("editor:auto-layout");
|
|
355
|
+
}
|
|
342
356
|
}), e;
|
|
343
357
|
}
|
|
358
|
+
toolbarIcon(e) {
|
|
359
|
+
const t = v(e);
|
|
360
|
+
return t ? { kind: "trusted-svg", svg: t } : e;
|
|
361
|
+
}
|
|
344
362
|
// ============================================================
|
|
345
363
|
// 状态更新
|
|
346
364
|
// ============================================================
|
|
@@ -349,8 +367,8 @@ class f {
|
|
|
349
367
|
*/
|
|
350
368
|
updateButtonStates() {
|
|
351
369
|
for (const [e, t] of this.buttonElements) {
|
|
352
|
-
const
|
|
353
|
-
|
|
370
|
+
const s = this.getBuiltinButtons().find((n) => n.id === e);
|
|
371
|
+
s && typeof s.disabled == "function" && (t.disabled = s.disabled(), t.classList.toggle("rulego-toolbar__button--disabled", t.disabled));
|
|
354
372
|
}
|
|
355
373
|
}
|
|
356
374
|
// ============================================================
|
|
@@ -363,7 +381,7 @@ class f {
|
|
|
363
381
|
return this.rootEl;
|
|
364
382
|
}
|
|
365
383
|
text(e, t) {
|
|
366
|
-
return
|
|
384
|
+
return g(this.core.i18n, e, t);
|
|
367
385
|
}
|
|
368
386
|
/**
|
|
369
387
|
* 动态添加自定义按钮
|
|
@@ -372,12 +390,12 @@ class f {
|
|
|
372
390
|
addButton(e) {
|
|
373
391
|
if (!this.rootEl) return;
|
|
374
392
|
const t = document.createElement("button");
|
|
375
|
-
t.className = "rulego-toolbar__button", t.title = e.title,
|
|
376
|
-
|
|
393
|
+
t.className = "rulego-toolbar__button", t.title = e.title, f(t, e.icon), t.addEventListener("click", (s) => {
|
|
394
|
+
s.preventDefault(), e.onClick();
|
|
377
395
|
}), this.buttonElements.set(e.id, t), this.rootEl.appendChild(t);
|
|
378
396
|
}
|
|
379
397
|
}
|
|
380
|
-
class
|
|
398
|
+
class P {
|
|
381
399
|
constructor(e, t) {
|
|
382
400
|
this.rootEl = null, this.formContainer = null, this.titleEl = null, this.unsubscribe = null, this.eventCleanups = [], this.currentNodeId = null, this.container = e, this.core = t.core, this.options = {
|
|
383
401
|
core: t.core,
|
|
@@ -404,8 +422,8 @@ class v {
|
|
|
404
422
|
*/
|
|
405
423
|
bindEvents() {
|
|
406
424
|
this.unsubscribe = this.core.store.subscribe((t) => {
|
|
407
|
-
const
|
|
408
|
-
|
|
425
|
+
const s = t.currentNodeView, n = t.currentNodeModel;
|
|
426
|
+
s && n && Object.keys(n).length > 0 && this.showPanel(s, n);
|
|
409
427
|
});
|
|
410
428
|
const e = this.core.eventBus.on("blank:click", () => {
|
|
411
429
|
this.clearPanel();
|
|
@@ -431,9 +449,9 @@ class v {
|
|
|
431
449
|
*/
|
|
432
450
|
showPanel(e, t) {
|
|
433
451
|
if (!(!this.rootEl || !this.formContainer || !this.titleEl) && (this.rootEl.style.display = "flex", this.titleEl.textContent = e.label || this.options.title, this.formContainer.replaceChildren(), this.renderBasicInfo(t), e.fields && e.fields.length > 0))
|
|
434
|
-
for (const
|
|
435
|
-
const
|
|
436
|
-
this.formContainer.appendChild(
|
|
452
|
+
for (const s of e.fields) {
|
|
453
|
+
const n = this.createFieldElement(s, t);
|
|
454
|
+
this.formContainer.appendChild(n);
|
|
437
455
|
}
|
|
438
456
|
}
|
|
439
457
|
/**
|
|
@@ -453,7 +471,7 @@ class v {
|
|
|
453
471
|
if (!this.formContainer) return;
|
|
454
472
|
const t = document.createElement("div");
|
|
455
473
|
t.className = "rulego-property-panel__section";
|
|
456
|
-
const
|
|
474
|
+
const s = this.createTextField({
|
|
457
475
|
name: "name",
|
|
458
476
|
type: "string",
|
|
459
477
|
defaultValue: "",
|
|
@@ -462,7 +480,7 @@ class v {
|
|
|
462
480
|
validate: "",
|
|
463
481
|
fields: null
|
|
464
482
|
}, e);
|
|
465
|
-
t.appendChild(
|
|
483
|
+
t.appendChild(s), this.formContainer.appendChild(t);
|
|
466
484
|
}
|
|
467
485
|
/**
|
|
468
486
|
* 创建单个表单字段元素
|
|
@@ -471,90 +489,90 @@ class v {
|
|
|
471
489
|
* @returns 字段 wrapper HTMLElement
|
|
472
490
|
*/
|
|
473
491
|
createFieldElement(e, t) {
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
let
|
|
492
|
+
const s = document.createElement("div");
|
|
493
|
+
s.className = "rulego-property-panel__field";
|
|
494
|
+
const n = document.createElement("label");
|
|
495
|
+
n.className = "rulego-property-panel__label", n.textContent = e.label || e.name, e.desc && (n.title = e.desc), s.appendChild(n);
|
|
496
|
+
let i;
|
|
479
497
|
switch (e.type) {
|
|
480
498
|
case "bool":
|
|
481
|
-
|
|
499
|
+
i = this.createBoolField(e, t);
|
|
482
500
|
break;
|
|
483
501
|
case "select":
|
|
484
|
-
|
|
502
|
+
i = this.createSelectField(e, t);
|
|
485
503
|
break;
|
|
486
504
|
case "code":
|
|
487
505
|
case "json":
|
|
488
|
-
|
|
506
|
+
i = this.createTextareaField(e, t);
|
|
489
507
|
break;
|
|
490
508
|
case "int":
|
|
491
|
-
|
|
509
|
+
i = this.createNumberField(e, t);
|
|
492
510
|
break;
|
|
493
511
|
default:
|
|
494
|
-
|
|
512
|
+
i = this.createTextField(e, t);
|
|
495
513
|
break;
|
|
496
514
|
}
|
|
497
|
-
if (
|
|
498
|
-
const
|
|
499
|
-
|
|
515
|
+
if (s.appendChild(i), e.desc) {
|
|
516
|
+
const o = document.createElement("span");
|
|
517
|
+
o.className = "rulego-property-panel__desc", o.textContent = e.desc, s.appendChild(o);
|
|
500
518
|
}
|
|
501
|
-
return
|
|
519
|
+
return s;
|
|
502
520
|
}
|
|
503
521
|
/**
|
|
504
522
|
* 文本输入框
|
|
505
523
|
*/
|
|
506
524
|
createTextField(e, t) {
|
|
507
|
-
const
|
|
508
|
-
return
|
|
509
|
-
this.handleFieldChange(e.name,
|
|
510
|
-
}),
|
|
525
|
+
const s = document.createElement("input");
|
|
526
|
+
return s.type = "text", s.className = "rulego-property-panel__input", s.name = e.name, s.value = String(this.getModelValue(e, t) ?? ""), s.placeholder = e.desc || "", s.addEventListener("change", () => {
|
|
527
|
+
this.handleFieldChange(e.name, s.value);
|
|
528
|
+
}), s;
|
|
511
529
|
}
|
|
512
530
|
/**
|
|
513
531
|
* 数值输入框
|
|
514
532
|
*/
|
|
515
533
|
createNumberField(e, t) {
|
|
516
|
-
const
|
|
517
|
-
return
|
|
518
|
-
this.handleFieldChange(e.name, Number(
|
|
519
|
-
}),
|
|
534
|
+
const s = document.createElement("input");
|
|
535
|
+
return s.type = "number", s.className = "rulego-property-panel__input", s.name = e.name, s.value = String(this.getModelValue(e, t) ?? 0), s.addEventListener("change", () => {
|
|
536
|
+
this.handleFieldChange(e.name, Number(s.value));
|
|
537
|
+
}), s;
|
|
520
538
|
}
|
|
521
539
|
/**
|
|
522
540
|
* 布尔开关
|
|
523
541
|
*/
|
|
524
542
|
createBoolField(e, t) {
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
return
|
|
531
|
-
this.handleFieldChange(e.name,
|
|
532
|
-
}),
|
|
543
|
+
const s = document.createElement("div");
|
|
544
|
+
s.className = "rulego-property-panel__switch-wrapper";
|
|
545
|
+
const n = `field-${e.name}-${Date.now()}`, i = document.createElement("input");
|
|
546
|
+
i.type = "checkbox", i.className = "rulego-property-panel__checkbox", i.id = n, i.checked = !!this.getModelValue(e, t);
|
|
547
|
+
const o = document.createElement("label");
|
|
548
|
+
return o.className = "rulego-property-panel__switch", o.htmlFor = n, i.addEventListener("change", () => {
|
|
549
|
+
this.handleFieldChange(e.name, i.checked);
|
|
550
|
+
}), s.appendChild(i), s.appendChild(o), s;
|
|
533
551
|
}
|
|
534
552
|
/**
|
|
535
553
|
* 下拉选择
|
|
536
554
|
*/
|
|
537
555
|
createSelectField(e, t) {
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
const
|
|
556
|
+
const s = document.createElement("select");
|
|
557
|
+
s.className = "rulego-property-panel__select", s.name = e.name;
|
|
558
|
+
const n = String(this.getModelValue(e, t) ?? "");
|
|
541
559
|
if (e.options && e.options.length > 0)
|
|
542
|
-
for (const
|
|
543
|
-
const
|
|
544
|
-
|
|
560
|
+
for (const i of e.options.filter(x)) {
|
|
561
|
+
const o = document.createElement("option"), l = String(i.value ?? "");
|
|
562
|
+
o.value = l, o.textContent = i.label, l === n && (o.selected = !0), s.appendChild(o);
|
|
545
563
|
}
|
|
546
|
-
return
|
|
547
|
-
this.handleFieldChange(e.name,
|
|
548
|
-
}),
|
|
564
|
+
return s.addEventListener("change", () => {
|
|
565
|
+
this.handleFieldChange(e.name, s.value);
|
|
566
|
+
}), s;
|
|
549
567
|
}
|
|
550
568
|
/**
|
|
551
569
|
* 多行文本 / 代码编辑器
|
|
552
570
|
*/
|
|
553
571
|
createTextareaField(e, t) {
|
|
554
|
-
const
|
|
555
|
-
return
|
|
556
|
-
this.handleFieldChange(e.name,
|
|
557
|
-
}),
|
|
572
|
+
const s = document.createElement("textarea");
|
|
573
|
+
return s.className = "rulego-property-panel__textarea", s.name = e.name, s.rows = 6, s.value = String(this.getModelValue(e, t) ?? ""), s.placeholder = e.desc || "", (e.type === "code" || e.type === "json") && (s.spellcheck = !1, s.style.fontFamily = "monospace"), s.addEventListener("change", () => {
|
|
574
|
+
this.handleFieldChange(e.name, s.value);
|
|
575
|
+
}), s;
|
|
558
576
|
}
|
|
559
577
|
// ============================================================
|
|
560
578
|
// 数据处理
|
|
@@ -566,8 +584,8 @@ class v {
|
|
|
566
584
|
* @returns 字段值
|
|
567
585
|
*/
|
|
568
586
|
getModelValue(e, t) {
|
|
569
|
-
const
|
|
570
|
-
return
|
|
587
|
+
const s = t.configuration;
|
|
588
|
+
return s && e.name in s ? s[e.name] : e.name in t ? t[e.name] : e.defaultValue;
|
|
571
589
|
}
|
|
572
590
|
/**
|
|
573
591
|
* 处理字段变更, 通知 EditorCore
|
|
@@ -602,8 +620,8 @@ class v {
|
|
|
602
620
|
* @param model - 节点模型
|
|
603
621
|
* @param nodeId - 节点 ID
|
|
604
622
|
*/
|
|
605
|
-
show(e, t,
|
|
606
|
-
|
|
623
|
+
show(e, t, s) {
|
|
624
|
+
s && (this.currentNodeId = s), this.showPanel(e, t);
|
|
607
625
|
}
|
|
608
626
|
/**
|
|
609
627
|
* 手动隐藏面板
|
|
@@ -612,14 +630,14 @@ class v {
|
|
|
612
630
|
this.clearPanel();
|
|
613
631
|
}
|
|
614
632
|
text(e, t) {
|
|
615
|
-
return
|
|
633
|
+
return g(this.core.i18n, e, t);
|
|
616
634
|
}
|
|
617
635
|
}
|
|
618
|
-
class
|
|
636
|
+
class V {
|
|
619
637
|
constructor(e, t) {
|
|
620
|
-
this.menuEl = null, this.currentContext = null, this.outsideClickHandler = null, this.container = e, this.core = t.core;
|
|
621
|
-
const
|
|
622
|
-
this.items = [...
|
|
638
|
+
this.menuEl = null, this.currentContext = null, this.outsideClickHandler = null, this.contextMenuHandler = null, this.escapeKeyHandler = null, this.positionFrame = null, this.container = e, this.core = t.core, this.options = t;
|
|
639
|
+
const s = t.includeBuiltin !== !1 ? this.getBuiltinItems() : [];
|
|
640
|
+
this.items = [...s, ...t.items ?? []], this.mount(), this.bindEvents();
|
|
623
641
|
}
|
|
624
642
|
// ============================================================
|
|
625
643
|
// 生命周期
|
|
@@ -634,19 +652,19 @@ class y {
|
|
|
634
652
|
* 绑定事件
|
|
635
653
|
*/
|
|
636
654
|
bindEvents() {
|
|
637
|
-
this.
|
|
655
|
+
this.contextMenuHandler = (e) => {
|
|
638
656
|
e.preventDefault(), this.handleContextMenu(e);
|
|
639
|
-
}), this.outsideClickHandler = (e) => {
|
|
657
|
+
}, this.container.addEventListener("contextmenu", this.contextMenuHandler), this.outsideClickHandler = (e) => {
|
|
640
658
|
this.menuEl && !this.menuEl.contains(e.target) && this.hide();
|
|
641
|
-
}, document.addEventListener("click", this.outsideClickHandler),
|
|
659
|
+
}, document.addEventListener("click", this.outsideClickHandler), this.escapeKeyHandler = (e) => {
|
|
642
660
|
e.key === "Escape" && this.hide();
|
|
643
|
-
});
|
|
661
|
+
}, document.addEventListener("keydown", this.escapeKeyHandler);
|
|
644
662
|
}
|
|
645
663
|
/**
|
|
646
664
|
* 销毁菜单
|
|
647
665
|
*/
|
|
648
666
|
destroy() {
|
|
649
|
-
this.outsideClickHandler && (document.removeEventListener("click", this.outsideClickHandler), this.outsideClickHandler = null), this.menuEl && this.menuEl.parentNode && this.menuEl.parentNode.removeChild(this.menuEl), this.menuEl = null;
|
|
667
|
+
this.hide(), this.contextMenuHandler && (this.container.removeEventListener("contextmenu", this.contextMenuHandler), this.contextMenuHandler = null), this.outsideClickHandler && (document.removeEventListener("click", this.outsideClickHandler), this.outsideClickHandler = null), this.escapeKeyHandler && (document.removeEventListener("keydown", this.escapeKeyHandler), this.escapeKeyHandler = null), this.menuEl && this.menuEl.parentNode && this.menuEl.parentNode.removeChild(this.menuEl), this.menuEl = null;
|
|
650
668
|
}
|
|
651
669
|
// ============================================================
|
|
652
670
|
// 右键处理
|
|
@@ -655,29 +673,33 @@ class y {
|
|
|
655
673
|
* 处理右键事件
|
|
656
674
|
*/
|
|
657
675
|
handleContextMenu(e) {
|
|
658
|
-
const t = e.target,
|
|
659
|
-
this.currentContext =
|
|
660
|
-
const
|
|
661
|
-
const
|
|
662
|
-
return
|
|
676
|
+
const t = e.target, s = this.resolveContext(t, e);
|
|
677
|
+
this.currentContext = s;
|
|
678
|
+
const n = this.items.filter((i) => {
|
|
679
|
+
const o = Array.isArray(i.target) ? i.target : [i.target];
|
|
680
|
+
return o.includes(s.type) || o.includes("all");
|
|
663
681
|
});
|
|
664
|
-
|
|
682
|
+
if (n.length === 0) {
|
|
683
|
+
this.hide();
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
this.renderMenu(n, e.clientX, e.clientY);
|
|
665
687
|
}
|
|
666
688
|
/**
|
|
667
689
|
* 解析右键目标的上下文
|
|
668
690
|
*/
|
|
669
691
|
resolveContext(e, t) {
|
|
670
|
-
const
|
|
671
|
-
if (
|
|
692
|
+
const s = e.closest(".lf-node");
|
|
693
|
+
if (s)
|
|
672
694
|
return {
|
|
673
695
|
type: "node",
|
|
674
|
-
id:
|
|
696
|
+
id: s.getAttribute("data-node-id") || void 0,
|
|
675
697
|
position: { x: t.clientX, y: t.clientY }
|
|
676
698
|
};
|
|
677
|
-
const
|
|
678
|
-
return
|
|
699
|
+
const n = e.closest(".lf-edge");
|
|
700
|
+
return n ? {
|
|
679
701
|
type: "edge",
|
|
680
|
-
id:
|
|
702
|
+
id: n.getAttribute("data-edge-id") || void 0,
|
|
681
703
|
position: { x: t.clientX, y: t.clientY }
|
|
682
704
|
} : {
|
|
683
705
|
type: "canvas",
|
|
@@ -690,37 +712,48 @@ class y {
|
|
|
690
712
|
/**
|
|
691
713
|
* 渲染并显示菜单
|
|
692
714
|
*/
|
|
693
|
-
renderMenu(e, t,
|
|
694
|
-
if (this.menuEl)
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
const l = document.createElement("span");
|
|
702
|
-
l.className = "rulego-context-menu__icon", d(l, s.icon), o.appendChild(l);
|
|
703
|
-
}
|
|
715
|
+
renderMenu(e, t, s) {
|
|
716
|
+
if (!this.menuEl) return;
|
|
717
|
+
this.cancelPendingPosition(), this.menuEl.replaceChildren();
|
|
718
|
+
for (const o of e) {
|
|
719
|
+
const l = document.createElement("div");
|
|
720
|
+
l.className = "rulego-context-menu__item";
|
|
721
|
+
const d = typeof o.disabled == "function" ? o.disabled() : o.disabled;
|
|
722
|
+
if (d && l.classList.add("rulego-context-menu__item--disabled"), o.icon) {
|
|
704
723
|
const a = document.createElement("span");
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
724
|
+
a.className = "rulego-context-menu__icon", f(a, o.icon), l.appendChild(a);
|
|
725
|
+
}
|
|
726
|
+
const r = document.createElement("span");
|
|
727
|
+
if (r.className = "rulego-context-menu__label", r.textContent = o.label, l.appendChild(r), d || l.addEventListener("click", () => {
|
|
728
|
+
this.currentContext && o.onClick(this.currentContext), this.hide();
|
|
729
|
+
}), this.menuEl.appendChild(l), o.separator) {
|
|
730
|
+
const a = document.createElement("div");
|
|
731
|
+
a.className = "rulego-context-menu__separator", this.menuEl.appendChild(a);
|
|
711
732
|
}
|
|
712
|
-
this.menuEl.style.left = `${t}px`, this.menuEl.style.top = `${n}px`, this.menuEl.style.display = "block", requestAnimationFrame(() => {
|
|
713
|
-
if (!this.menuEl) return;
|
|
714
|
-
const s = this.menuEl.getBoundingClientRect();
|
|
715
|
-
s.right > window.innerWidth && (this.menuEl.style.left = `${t - s.width}px`), s.bottom > window.innerHeight && (this.menuEl.style.top = `${n - s.height}px`);
|
|
716
|
-
});
|
|
717
733
|
}
|
|
734
|
+
this.menuEl.style.left = `${t}px`, this.menuEl.style.top = `${s}px`, this.menuEl.style.visibility = "hidden", this.menuEl.style.display = "block";
|
|
735
|
+
let n = !1;
|
|
736
|
+
const i = requestAnimationFrame(() => {
|
|
737
|
+
n = !0, this.positionFrame = null;
|
|
738
|
+
const o = this.menuEl;
|
|
739
|
+
if (!o) return;
|
|
740
|
+
const l = o.getBoundingClientRect(), d = w(
|
|
741
|
+
{ left: t, top: s },
|
|
742
|
+
{ width: l.width, height: l.height },
|
|
743
|
+
{ width: window.innerWidth, height: window.innerHeight }
|
|
744
|
+
);
|
|
745
|
+
o.style.left = `${d.left}px`, o.style.top = `${d.top}px`, o.style.visibility = "visible";
|
|
746
|
+
});
|
|
747
|
+
this.positionFrame = n ? null : i;
|
|
718
748
|
}
|
|
719
749
|
/**
|
|
720
750
|
* 隐藏菜单
|
|
721
751
|
*/
|
|
722
752
|
hide() {
|
|
723
|
-
this.menuEl && (this.menuEl.style.display = "none"), this.currentContext = null;
|
|
753
|
+
this.cancelPendingPosition(), this.menuEl && (this.menuEl.style.display = "none", this.menuEl.style.visibility = ""), this.currentContext = null;
|
|
754
|
+
}
|
|
755
|
+
cancelPendingPosition() {
|
|
756
|
+
this.positionFrame !== null && (cancelAnimationFrame(this.positionFrame), this.positionFrame = null);
|
|
724
757
|
}
|
|
725
758
|
// ============================================================
|
|
726
759
|
// 内置菜单项
|
|
@@ -733,7 +766,7 @@ class y {
|
|
|
733
766
|
{
|
|
734
767
|
id: "edit",
|
|
735
768
|
label: this.text("contextMenu.edit", "编辑"),
|
|
736
|
-
icon: "
|
|
769
|
+
icon: this.toolbarIcon("edit"),
|
|
737
770
|
target: "node",
|
|
738
771
|
onClick: (e) => {
|
|
739
772
|
e.id && this.core.eventBus.emit("editor:show-edit-panel");
|
|
@@ -742,27 +775,33 @@ class y {
|
|
|
742
775
|
{
|
|
743
776
|
id: "delete",
|
|
744
777
|
label: this.text("contextMenu.delete", "删除"),
|
|
745
|
-
icon: "
|
|
778
|
+
icon: this.toolbarIcon("delete"),
|
|
746
779
|
target: ["node", "edge"],
|
|
747
780
|
separator: !0,
|
|
748
781
|
onClick: (e) => {
|
|
749
|
-
e.id && this.core.eventBus.emit("node:delete", { id: e.id });
|
|
782
|
+
e.id && this.core.eventBus.emit(e.type === "edge" ? "edge:delete" : "node:delete", { id: e.id });
|
|
750
783
|
}
|
|
751
784
|
},
|
|
752
785
|
{
|
|
753
786
|
id: "copy",
|
|
754
787
|
label: this.text("contextMenu.copy", "复制"),
|
|
755
|
-
icon: "
|
|
788
|
+
icon: this.toolbarIcon("copy"),
|
|
756
789
|
target: "node",
|
|
757
|
-
|
|
790
|
+
disabled: () => !this.options.onCopy,
|
|
791
|
+
onClick: (e) => {
|
|
792
|
+
var t, s;
|
|
793
|
+
(s = (t = this.options).onCopy) == null || s.call(t, e);
|
|
758
794
|
}
|
|
759
795
|
},
|
|
760
796
|
{
|
|
761
797
|
id: "select-all",
|
|
762
798
|
label: this.text("contextMenu.selectAll", "全选"),
|
|
763
|
-
icon: "
|
|
799
|
+
icon: this.toolbarIcon("select-all"),
|
|
764
800
|
target: "canvas",
|
|
765
|
-
|
|
801
|
+
disabled: () => !this.options.onSelectAll,
|
|
802
|
+
onClick: (e) => {
|
|
803
|
+
var t, s;
|
|
804
|
+
(s = (t = this.options).onSelectAll) == null || s.call(t, e);
|
|
766
805
|
}
|
|
767
806
|
}
|
|
768
807
|
];
|
|
@@ -778,7 +817,11 @@ class y {
|
|
|
778
817
|
this.items.push(e);
|
|
779
818
|
}
|
|
780
819
|
text(e, t) {
|
|
781
|
-
return
|
|
820
|
+
return g(this.core.i18n, e, t);
|
|
821
|
+
}
|
|
822
|
+
toolbarIcon(e) {
|
|
823
|
+
const t = v(e);
|
|
824
|
+
return t ? { kind: "trusted-svg", svg: t } : e;
|
|
782
825
|
}
|
|
783
826
|
/**
|
|
784
827
|
* 移除菜单项
|
|
@@ -794,13 +837,13 @@ class y {
|
|
|
794
837
|
return this.menuEl;
|
|
795
838
|
}
|
|
796
839
|
}
|
|
797
|
-
class
|
|
840
|
+
class D {
|
|
798
841
|
constructor(e, t) {
|
|
799
|
-
this.logs = [], this.consoleEl = null, this.listEl = null, this.container = e, this.core = t.core, this.maxLogs = t.maxLogs || 1e3, this.mount(), this.bindEvents();
|
|
842
|
+
this.logs = [], this.consoleEl = null, this.listEl = null, this.unsubscribe = null, this.container = e, this.core = t.core, this.maxLogs = t.maxLogs || 1e3, this.mount(), this.bindEvents();
|
|
800
843
|
}
|
|
801
844
|
t(e, t) {
|
|
802
|
-
const
|
|
803
|
-
return
|
|
845
|
+
const s = this.core.i18n.t(e);
|
|
846
|
+
return s && s !== e ? s : t;
|
|
804
847
|
}
|
|
805
848
|
mount() {
|
|
806
849
|
this.consoleEl = document.createElement("div"), this.consoleEl.className = "rulego-debug-console";
|
|
@@ -808,13 +851,13 @@ class x {
|
|
|
808
851
|
e.className = "rulego-debug-console__header";
|
|
809
852
|
const t = document.createElement("span");
|
|
810
853
|
t.className = "rulego-debug-console__title", t.textContent = this.t("editor.debugConsole.title", "调试控制台");
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
const
|
|
814
|
-
|
|
854
|
+
const s = document.createElement("button");
|
|
855
|
+
s.className = "rulego-debug-console__clear", s.textContent = this.t("editor.debugConsole.clear", "清除"), e.append(t, s);
|
|
856
|
+
const n = document.createElement("div");
|
|
857
|
+
n.className = "rulego-debug-console__list", this.consoleEl.append(e, n), this.listEl = n, this.container.appendChild(this.consoleEl), s.addEventListener("click", () => this.clear());
|
|
815
858
|
}
|
|
816
859
|
bindEvents() {
|
|
817
|
-
this.core.eventBus.on("debug:log", (e) => {
|
|
860
|
+
this.unsubscribe = this.core.eventBus.on("debug:log", (e) => {
|
|
818
861
|
this.appendLog(e);
|
|
819
862
|
});
|
|
820
863
|
}
|
|
@@ -822,21 +865,139 @@ class x {
|
|
|
822
865
|
if (this.logs.push(e), this.logs.length > this.maxLogs && (this.logs.shift(), this.listEl && this.listEl.firstElementChild && this.listEl.removeChild(this.listEl.firstElementChild)), !this.listEl) return;
|
|
823
866
|
const t = document.createElement("div");
|
|
824
867
|
t.className = "rulego-debug-console__item";
|
|
825
|
-
const
|
|
826
|
-
t.textContent = `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${
|
|
868
|
+
const s = typeof e == "string" ? e : k(N(e), { maxChars: 2e4, space: 0 });
|
|
869
|
+
t.textContent = `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${s}`, this.listEl.appendChild(t), this.listEl.scrollTop = this.listEl.scrollHeight;
|
|
827
870
|
}
|
|
828
871
|
clear() {
|
|
829
872
|
this.logs = [], this.listEl && this.listEl.replaceChildren();
|
|
830
873
|
}
|
|
831
874
|
destroy() {
|
|
832
|
-
|
|
875
|
+
var e;
|
|
876
|
+
(e = this.unsubscribe) == null || e.call(this), this.unsubscribe = null, this.consoleEl && this.consoleEl.parentNode && this.consoleEl.parentNode.removeChild(this.consoleEl), this.consoleEl = null, this.listEl = null, this.logs = [];
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const F = 28;
|
|
880
|
+
function y(h, e, t = 0) {
|
|
881
|
+
const s = [];
|
|
882
|
+
return h.forEach((n) => {
|
|
883
|
+
var i;
|
|
884
|
+
s.push({ node: n, depth: t }), (i = n.children) != null && i.length && e.has(n.key) && s.push(...y(n.children, e, t + 1));
|
|
885
|
+
}), s;
|
|
886
|
+
}
|
|
887
|
+
function H(h, e = "") {
|
|
888
|
+
e.split(/\s+/).filter(Boolean).forEach((t) => h.classList.add(t));
|
|
889
|
+
}
|
|
890
|
+
class W {
|
|
891
|
+
constructor(e, t = {}) {
|
|
892
|
+
this.rootEl = null, this.searchInputEl = null, this.treeEl = null, this.unsubscribe = null, this.virtualScrollTop = 0, this.autoScrolledActiveChainId = null, this.destroyed = !1, this.container = e, this.options = { ...t }, this.ownedStore = t.store ? null : new I({
|
|
893
|
+
workflows: t.workflows,
|
|
894
|
+
activeChainId: t.activeChainId,
|
|
895
|
+
keyword: t.keyword,
|
|
896
|
+
persistence: t.persistence
|
|
897
|
+
}), this.store = t.store || this.ownedStore, t.store && (t.workflows && this.store.setWorkflows(t.workflows), t.activeChainId !== void 0 && this.store.setActiveChainId(t.activeChainId), t.keyword !== void 0 && this.store.setKeyword(t.keyword)), this.mount();
|
|
898
|
+
}
|
|
899
|
+
getState() {
|
|
900
|
+
return this.store.getState();
|
|
901
|
+
}
|
|
902
|
+
getStore() {
|
|
903
|
+
return this.store;
|
|
904
|
+
}
|
|
905
|
+
setWorkflows(e) {
|
|
906
|
+
this.destroyed || this.store.setWorkflows(e);
|
|
907
|
+
}
|
|
908
|
+
setActiveChainId(e) {
|
|
909
|
+
this.destroyed || this.store.setActiveChainId(e);
|
|
910
|
+
}
|
|
911
|
+
setKeyword(e) {
|
|
912
|
+
var t, s;
|
|
913
|
+
this.destroyed || (this.store.setKeyword(e), (s = (t = this.options).onKeywordChange) == null || s.call(t, String(e || "")));
|
|
914
|
+
}
|
|
915
|
+
destroy() {
|
|
916
|
+
var e, t, s;
|
|
917
|
+
this.destroyed || (this.destroyed = !0, (e = this.unsubscribe) == null || e.call(this), this.unsubscribe = null, (t = this.ownedStore) == null || t.destroy(), (s = this.rootEl) == null || s.remove(), this.rootEl = null, this.searchInputEl = null, this.treeEl = null);
|
|
918
|
+
}
|
|
919
|
+
mount() {
|
|
920
|
+
this.rootEl = document.createElement("section"), this.rootEl.className = "huanban_workflow_explorer", H(this.rootEl, this.options.className), this.rootEl.setAttribute("aria-label", "规则链资源");
|
|
921
|
+
const e = document.createElement("div");
|
|
922
|
+
e.className = "huanban_workflow_explorer__search";
|
|
923
|
+
const t = document.createElement("span");
|
|
924
|
+
t.className = "huanban_workflow_explorer__search_icon", t.setAttribute("aria-hidden", "true"), this.searchInputEl = document.createElement("input"), this.searchInputEl.type = "search", this.searchInputEl.value = this.store.getState().keyword, this.searchInputEl.placeholder = this.options.placeholder || "搜索规则链", this.searchInputEl.setAttribute("aria-label", this.searchInputEl.placeholder), this.searchInputEl.addEventListener("input", () => {
|
|
925
|
+
var s;
|
|
926
|
+
this.setKeyword(((s = this.searchInputEl) == null ? void 0 : s.value) || "");
|
|
927
|
+
}), e.append(t, this.searchInputEl), this.rootEl.appendChild(e), this.treeEl = document.createElement("div"), this.treeEl.className = "huanban_workflow_explorer__tree", this.treeEl.setAttribute("role", "tree"), this.treeEl.addEventListener("scroll", () => {
|
|
928
|
+
if (!this.treeEl || this.destroyed) return;
|
|
929
|
+
const s = this.treeEl.scrollTop;
|
|
930
|
+
s !== this.virtualScrollTop && (this.virtualScrollTop = s, this.renderState(this.store.getState()));
|
|
931
|
+
}), this.rootEl.appendChild(this.treeEl), this.container.appendChild(this.rootEl), this.unsubscribe = this.store.subscribe((s) => this.renderState(s)), this.renderState(this.store.getState());
|
|
932
|
+
}
|
|
933
|
+
renderState(e) {
|
|
934
|
+
if (this.destroyed || !this.treeEl) return;
|
|
935
|
+
this.searchInputEl && this.searchInputEl.value !== e.keyword && (this.searchInputEl.value = e.keyword);
|
|
936
|
+
const t = y(e.tree, new Set(e.expandedKeys));
|
|
937
|
+
if (t.length === 0) {
|
|
938
|
+
this.virtualScrollTop = 0, this.autoScrolledActiveChainId = null, this.treeEl.scrollTop !== 0 && (this.treeEl.scrollTop = 0), this.treeEl.classList.remove("is-virtualized"), this.treeEl.removeAttribute("data-explorer-virtualized"), this.treeEl.removeAttribute("data-explorer-virtual-total"), this.treeEl.style.removeProperty("height");
|
|
939
|
+
const u = document.createElement("div");
|
|
940
|
+
u.className = "huanban_workflow_explorer__empty", u.textContent = this.options.emptyText || "暂无规则链", this.treeEl.replaceChildren(u);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
const s = this.options.virtualization, n = (s == null ? void 0 : s.enabled) !== !1, i = Math.max(1, (s == null ? void 0 : s.threshold) ?? S), o = Math.max(1, (s == null ? void 0 : s.itemHeight) ?? F), l = Math.max(1, (s == null ? void 0 : s.viewportHeight) ?? L), d = Math.max(0, (s == null ? void 0 : s.overscan) ?? A), r = n && t.length > i;
|
|
944
|
+
if (r || (this.virtualScrollTop = 0, this.autoScrolledActiveChainId = null, this.treeEl.scrollTop !== 0 && (this.treeEl.scrollTop = 0)), e.activeChainId || (this.autoScrolledActiveChainId = null), r && e.activeChainId && e.activeChainId !== this.autoScrolledActiveChainId) {
|
|
945
|
+
const u = t.findIndex((p) => {
|
|
946
|
+
var c;
|
|
947
|
+
return p.node.kind === "chain" && ((c = p.node.chain) == null ? void 0 : c.id) === e.activeChainId;
|
|
948
|
+
});
|
|
949
|
+
if (u >= 0) {
|
|
950
|
+
const p = Math.floor(this.virtualScrollTop / o), c = Math.ceil((this.virtualScrollTop + l) / o);
|
|
951
|
+
u < p ? this.virtualScrollTop = u * o : u >= c && (this.virtualScrollTop = (u + 1) * o - l), this.autoScrolledActiveChainId = e.activeChainId;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
const a = T({
|
|
955
|
+
total: t.length,
|
|
956
|
+
itemHeight: o,
|
|
957
|
+
viewportHeight: l,
|
|
958
|
+
scrollTop: this.virtualScrollTop,
|
|
959
|
+
overscan: d
|
|
960
|
+
});
|
|
961
|
+
this.treeEl.classList.toggle("is-virtualized", r), r ? (this.treeEl.dataset.explorerVirtualized = "true", this.treeEl.dataset.explorerVirtualTotal = String(t.length), this.treeEl.style.height = `${a.viewportHeight}px`) : (this.treeEl.removeAttribute("data-explorer-virtualized"), this.treeEl.removeAttribute("data-explorer-virtual-total"), this.treeEl.style.removeProperty("height"));
|
|
962
|
+
const E = r ? t.slice(a.start, a.end) : t, m = document.createDocumentFragment();
|
|
963
|
+
if (r) {
|
|
964
|
+
const u = document.createElement("div");
|
|
965
|
+
u.className = "huanban_workflow_explorer__virtual-canvas", u.style.height = `${a.totalHeight}px`;
|
|
966
|
+
const p = document.createElement("div");
|
|
967
|
+
p.className = "huanban_workflow_explorer__virtual-items", p.style.transform = `translateY(${a.offsetTop}px)`, E.forEach(({ node: c, depth: b }, _) => p.appendChild(this.createRow(c, b, e, a.start + _, t.length))), u.appendChild(p), m.appendChild(u), this.treeEl.scrollTop !== a.scrollTop && (this.treeEl.scrollTop = a.scrollTop);
|
|
968
|
+
} else
|
|
969
|
+
E.forEach(({ node: u, depth: p }, c) => m.appendChild(this.createRow(u, p, e, c, t.length)));
|
|
970
|
+
this.treeEl.replaceChildren(m);
|
|
971
|
+
}
|
|
972
|
+
createRow(e, t, s, n, i) {
|
|
973
|
+
var u, p;
|
|
974
|
+
const o = !!((u = e.children) != null && u.length), l = s.expandedKeys.includes(e.key), d = e.kind === "chain" && ((p = e.chain) == null ? void 0 : p.id) === s.activeChainId, r = document.createElement("button");
|
|
975
|
+
r.type = "button", r.className = `huanban_workflow_explorer__row is-${e.kind}${d ? " is-active" : ""}`, r.style.paddingInlineStart = `${8 + t * 14}px`, r.setAttribute("role", "treeitem"), r.setAttribute("aria-level", String(t + 1)), r.setAttribute("aria-posinset", String(n + 1)), r.setAttribute("aria-setsize", String(i)), o && r.setAttribute("aria-expanded", String(l)), e.kind === "chain" && r.setAttribute("aria-selected", String(d)), r.title = e.chain ? `${e.chain.name}
|
|
976
|
+
${e.chain.id}` : e.label;
|
|
977
|
+
const a = document.createElement("span");
|
|
978
|
+
a.className = `huanban_workflow_explorer__chevron${o && l ? " is-open" : ""}`, a.setAttribute("aria-hidden", "true");
|
|
979
|
+
const E = document.createElement("span");
|
|
980
|
+
E.className = `huanban_workflow_explorer__kind is-${e.kind}`, E.setAttribute("aria-hidden", "true");
|
|
981
|
+
const m = document.createElement("span");
|
|
982
|
+
if (m.className = "huanban_workflow_explorer__label", m.textContent = e.label, r.append(a, E, m), e.kind === "chain" && e.chain) {
|
|
983
|
+
const c = document.createElement("span");
|
|
984
|
+
c.className = `huanban_workflow_explorer__status ${e.chain.disabled ? "is-offline" : "is-online"}`, c.title = e.chain.disabled ? "已下线" : "运行中", c.setAttribute("aria-label", c.title), r.appendChild(c);
|
|
985
|
+
}
|
|
986
|
+
if (e.count !== void 0) {
|
|
987
|
+
const c = document.createElement("span");
|
|
988
|
+
c.className = "huanban_workflow_explorer__count", c.textContent = String(e.count), r.appendChild(c);
|
|
989
|
+
}
|
|
990
|
+
return r.addEventListener("click", () => {
|
|
991
|
+
var c, b;
|
|
992
|
+
o ? this.store.setExpanded(e.key, !l) : e.chain && ((b = (c = this.options).onOpen) == null || b.call(c, e.chain));
|
|
993
|
+
}), r;
|
|
833
994
|
}
|
|
834
995
|
}
|
|
835
996
|
export {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
997
|
+
V as ContextMenu,
|
|
998
|
+
D as DebugConsole,
|
|
999
|
+
P as PropertyPanel,
|
|
1000
|
+
G as Sidebar,
|
|
1001
|
+
$ as Toolbar,
|
|
1002
|
+
W as WorkflowExplorer
|
|
841
1003
|
};
|
|
842
|
-
//# sourceMappingURL=index.esm.js.map
|