@huanban/rulego-editor-ui 1.4.1 → 2.0.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/dist/components/ContextMenu.d.ts +1 -0
- package/dist/components/Sidebar.d.ts +40 -13
- package/dist/index.cjs +4 -2
- package/dist/index.esm.js +402 -302
- package/dist/index.umd.js +4 -2
- package/dist/style.css +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,221 +1,319 @@
|
|
|
1
|
-
import { getEditorToolbarIconSvg as v,
|
|
2
|
-
|
|
1
|
+
import { i18nText as y, getEditorToolbarIconSvg as _, localizeComponentDefinition as F, normalizeComponentCategory as H, buildComponentPalette as w, hasDeclaredSubgroups as k, DEFAULT_COMPONENT_CATEGORY_ORDER as v, resolveIconUrl as D, safeCssColor as S, resolveComponentIconUrl as N, normalizeIconTheme as K, getThemeRuntimeVariables as P, isComponentFieldOption as O, clampContextMenuPosition as $, formatJsonBounded as R, redactSensitive as V, ExplorerTreeStore as W, DEFAULT_VIRTUAL_WINDOW_THRESHOLD as q, DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT as G, DEFAULT_VIRTUAL_WINDOW_OVERSCAN as z, calculateVirtualWindow as U } from "@huanban/rulego-editor-core";
|
|
2
|
+
const j = (c) => JSON.stringify(["category", c]), I = (c, e) => JSON.stringify(["subgroup", c, e]), J = JSON.stringify(["recent"]);
|
|
3
|
+
function x(c) {
|
|
4
|
+
if (!/[<&]/.test(c) || typeof document > "u") return c;
|
|
5
|
+
const e = document.createElement("template");
|
|
6
|
+
return e.innerHTML = c, e.content.querySelectorAll("script, style").forEach((t) => t.remove()), e.content.querySelectorAll("br, p, div, li").forEach((t) => t.append(" ")), (e.content.textContent || "").replace(/\s+/g, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
function A(c, e) {
|
|
9
|
+
return c.label || c.type;
|
|
10
|
+
}
|
|
11
|
+
function f(c) {
|
|
12
|
+
return JSON.stringify([c.type, c.isSharedNode ? c.sharedNodeId ?? "" : ""]);
|
|
13
|
+
}
|
|
14
|
+
function B(c, e) {
|
|
15
|
+
return x(c.desc || "");
|
|
16
|
+
}
|
|
17
|
+
function T(c) {
|
|
18
|
+
return v.includes(c) ? c : "other";
|
|
19
|
+
}
|
|
20
|
+
let Y = 0;
|
|
21
|
+
class te {
|
|
3
22
|
constructor(e, t) {
|
|
4
|
-
this.
|
|
5
|
-
|
|
23
|
+
this.id = `rulego-sidebar-${++Y}`, this.rootEl = null, this.groupsEl = null, this.searchInput = null, this.clearButton = null, this.toggleButton = null, this.managerButton = null, this.unsubscribe = [], this.expanded = /* @__PURE__ */ new Map(), this.searchExpanded = /* @__PURE__ */ new Map(), this.displayGroups = [], this.iconTheme = "default", this.text = (s, i = "") => {
|
|
24
|
+
const o = y(this.core.i18n, s, i);
|
|
25
|
+
return o === s ? i : o;
|
|
26
|
+
}, this.core = t.core, this.options = {
|
|
27
|
+
...t,
|
|
6
28
|
searchable: t.searchable ?? !0,
|
|
7
|
-
defaultCollapsed: t.defaultCollapsed ?? !
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}, this.mount(), this.
|
|
11
|
-
(s) => s.componentGroups
|
|
12
|
-
|
|
13
|
-
(
|
|
14
|
-
this.renderGroups(s);
|
|
15
|
-
}
|
|
29
|
+
defaultCollapsed: t.defaultCollapsed ?? !0,
|
|
30
|
+
showRecent: t.showRecent ?? !0,
|
|
31
|
+
showNodeMgt: t.showNodeMgt ?? !0
|
|
32
|
+
}, this.searchKeyword = t.search || "", this.mount(e), this.refresh(), this.unsubscribe.push(
|
|
33
|
+
this.core.store.select((s) => s.componentGroups).subscribe(() => this.refresh()),
|
|
34
|
+
this.core.i18n.onLocaleChange(() => this.refresh()),
|
|
35
|
+
this.core.theme.onChange(() => this.refresh())
|
|
16
36
|
);
|
|
17
37
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
get query() {
|
|
39
|
+
return this.searchKeyword.trim().toLowerCase().replace(/\s+/g, " ");
|
|
40
|
+
}
|
|
41
|
+
icon(e) {
|
|
42
|
+
const t = document.createElement("span");
|
|
43
|
+
return t.className = "rulego-sidebar__control-icon", t.setAttribute("aria-hidden", "true"), t.innerHTML = _(e) || "", t;
|
|
44
|
+
}
|
|
45
|
+
mount(e) {
|
|
46
|
+
this.rootEl = document.createElement("aside"), this.rootEl.className = "rulego-sidebar", this.rootEl.tabIndex = -1, this.rootEl.style.width = this.options.width ?? "220px";
|
|
47
|
+
const t = document.createElement("div");
|
|
48
|
+
if (t.className = "rulego-sidebar__search-wrapper", this.options.searchable) {
|
|
26
49
|
const s = document.createElement("div");
|
|
27
|
-
s.className = "rulego-sidebar__search-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const l = this.core.store.getState().componentGroups;
|
|
34
|
-
this.renderGroups(l);
|
|
35
|
-
}), s.appendChild(n), s.appendChild(i), this.rootEl.appendChild(s);
|
|
50
|
+
s.className = "rulego-sidebar__search-field", this.searchInput = document.createElement("input"), this.searchInput.type = "search", this.searchInput.className = "rulego-sidebar__search", this.searchInput.addEventListener("input", () => this.setSearch(this.searchInput.value)), this.searchInput.addEventListener("keydown", (i) => {
|
|
51
|
+
i.stopPropagation(), i.key === "Escape" && (i.preventDefault(), this.setSearch(""));
|
|
52
|
+
}), this.clearButton = document.createElement("button"), this.clearButton.type = "button", this.clearButton.className = "rulego-sidebar__clear", this.clearButton.append(this.icon("error")), this.clearButton.addEventListener("click", () => {
|
|
53
|
+
var i;
|
|
54
|
+
this.setSearch(""), (i = this.searchInput) == null || i.focus();
|
|
55
|
+
}), s.append(this.icon("search"), this.searchInput, this.clearButton), t.append(s);
|
|
36
56
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
57
|
+
this.toggleButton = document.createElement("button"), this.toggleButton.type = "button", this.toggleButton.className = "rulego-sidebar__toggle-all", this.toggleButton.dataset.sidebarToggle = "all", this.toggleButton.addEventListener("click", () => {
|
|
58
|
+
this.visibleKeys().some((s) => this.isExpanded(s)) ? this.collapseAll() : this.expandAll();
|
|
59
|
+
}), t.append(this.toggleButton), this.options.showNodeMgt && (this.managerButton = document.createElement("button"), this.managerButton.type = "button", this.managerButton.className = "rulego-sidebar__manage", this.managerButton.disabled = !this.options.onOpenNodeMgt, this.managerButton.append(this.icon("settings")), this.managerButton.addEventListener("click", () => {
|
|
60
|
+
var s, i;
|
|
61
|
+
return (i = (s = this.options).onOpenNodeMgt) == null ? void 0 : i.call(s);
|
|
62
|
+
}), t.append(this.managerButton)), this.groupsEl = document.createElement("div"), this.groupsEl.className = "rulego-sidebar__groups", this.options.searchable && this.rootEl.append(t), this.rootEl.append(this.groupsEl), e.append(this.rootEl);
|
|
63
|
+
}
|
|
64
|
+
buildGroups() {
|
|
65
|
+
const e = /* @__PURE__ */ new Set(), s = (this.core.store.getState().componentGroups || []).flatMap((i) => {
|
|
66
|
+
if (i.disabled) return [];
|
|
67
|
+
const o = (i.subgroups || []).map(({ components: n, ...r }) => r);
|
|
68
|
+
return i.components.flatMap((n) => {
|
|
69
|
+
var p, a, u;
|
|
70
|
+
const r = f(n);
|
|
71
|
+
return !((p = n.type) != null && p.trim()) || e.has(r) ? [] : (e.add(r), [F(H({
|
|
72
|
+
...n,
|
|
73
|
+
category: n.category || i.category,
|
|
74
|
+
categoryLabel: n.categoryLabel || i.label,
|
|
75
|
+
subgroup: n.subgroup || ((u = (a = i.subgroups) == null ? void 0 : a.find((g) => g.components.some((h) => h.type === n.type))) == null ? void 0 : u.id),
|
|
76
|
+
categorySubgroups: [...n.categorySubgroups || [], ...o],
|
|
77
|
+
label: n.label || n.type,
|
|
78
|
+
desc: n.desc || ""
|
|
79
|
+
}), (g) => this.text(g, g))]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return w(s, "", {
|
|
83
|
+
categoryOrder: v,
|
|
84
|
+
subgroupCategories: k,
|
|
85
|
+
categoryLabel: (i, o) => {
|
|
86
|
+
var n;
|
|
87
|
+
return this.text(`category.${i}.label`, this.text(`category.${i}`, String(((n = o[0]) == null ? void 0 : n.categoryLabel) || i)));
|
|
88
|
+
}
|
|
89
|
+
}).map((i) => ({
|
|
90
|
+
...i,
|
|
91
|
+
key: j(i.category),
|
|
92
|
+
subgroups: i.subgroups.map((o) => ({
|
|
93
|
+
...o,
|
|
94
|
+
label: o.id ? o.label : this.text("category.other", "Other"),
|
|
95
|
+
description: x(o.description || "")
|
|
96
|
+
}))
|
|
97
|
+
}));
|
|
41
98
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
99
|
+
filterGroups(e) {
|
|
100
|
+
if (!this.query) return e;
|
|
101
|
+
const t = /* @__PURE__ */ new Map();
|
|
102
|
+
for (const i of e) for (const o of i.subgroups) for (const n of o.components)
|
|
103
|
+
t.set(f(n), [
|
|
104
|
+
A(n, this.text),
|
|
105
|
+
B(n, this.text),
|
|
106
|
+
x(n.desc),
|
|
107
|
+
i.label,
|
|
108
|
+
o.label,
|
|
109
|
+
o.description || "",
|
|
110
|
+
...Array.isArray(n.keywords) ? n.keywords.map(String) : [String(n.keywords || "")]
|
|
111
|
+
]);
|
|
112
|
+
const s = w(e.flatMap((i) => i.components), this.query, {
|
|
113
|
+
categoryOrder: v,
|
|
114
|
+
subgroupCategories: k,
|
|
115
|
+
componentSearchText: (i) => t.get(f(i))
|
|
116
|
+
});
|
|
117
|
+
return e.flatMap((i) => {
|
|
118
|
+
const o = s.find((n) => n.category === i.category);
|
|
119
|
+
return o ? [{ ...i, components: o.components, subgroups: i.subgroups.flatMap((n) => {
|
|
120
|
+
const r = o.subgroups.find((p) => p.id === n.id);
|
|
121
|
+
return r ? [{ ...n, components: r.components }] : [];
|
|
122
|
+
}) }] : [];
|
|
123
|
+
});
|
|
47
124
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
125
|
+
hasSubgroups(e) {
|
|
126
|
+
return e.subgroups.some((t) => !!t.id);
|
|
127
|
+
}
|
|
128
|
+
visibleKeys() {
|
|
129
|
+
return this.displayGroups.flatMap((e) => [
|
|
130
|
+
e.key,
|
|
131
|
+
...this.hasSubgroups(e) ? e.subgroups.map((t) => I(e.category, t.id)) : []
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
isExpanded(e) {
|
|
135
|
+
return this.query ? this.searchExpanded.get(e) ?? !0 : this.expanded.get(e) ?? !this.options.defaultCollapsed;
|
|
136
|
+
}
|
|
137
|
+
allExpanded() {
|
|
138
|
+
const e = this.visibleKeys();
|
|
139
|
+
return e.length > 0 && e.every((t) => this.isExpanded(t));
|
|
140
|
+
}
|
|
141
|
+
setExpansion(e, t) {
|
|
142
|
+
(this.query ? this.searchExpanded : this.expanded).set(e, t);
|
|
143
|
+
}
|
|
144
|
+
createHeader(e, t, s, i = !1, o = "", n = "other") {
|
|
145
|
+
const r = document.createElement("button");
|
|
146
|
+
r.type = "button", r.className = i ? "rulego-sidebar__subgroup-header" : "rulego-sidebar__group-header", r.dataset.sidebarFocus = e, r.title = [t, o].filter(Boolean).join(`
|
|
147
|
+
`);
|
|
148
|
+
const p = this.isExpanded(e);
|
|
149
|
+
if (r.setAttribute("aria-expanded", String(p)), r.setAttribute("aria-controls", this.panelId(e)), !i) {
|
|
150
|
+
const h = document.createElement("img");
|
|
151
|
+
h.className = "rulego-sidebar__group-icon", h.src = D(`images/${T(n)}-dark.svg`, { theme: this.iconTheme }), h.alt = "", h.draggable = !1, r.append(h);
|
|
69
152
|
}
|
|
153
|
+
const a = document.createElement("span");
|
|
154
|
+
a.className = "rulego-sidebar__group-label", a.textContent = t;
|
|
155
|
+
const u = document.createElement("span");
|
|
156
|
+
u.className = "rulego-sidebar__group-count", u.textContent = String(s);
|
|
157
|
+
const g = document.createElement("span");
|
|
158
|
+
return g.className = `rulego-sidebar__arrow${p ? " is-expanded" : ""}`, g.setAttribute("aria-hidden", "true"), g.textContent = "›", r.append(a, u, g), r.addEventListener("click", () => {
|
|
159
|
+
this.setExpansion(e, !this.isExpanded(e)), this.refresh();
|
|
160
|
+
}), r;
|
|
70
161
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const t = document.createElement("div");
|
|
78
|
-
t.className = "rulego-sidebar__group";
|
|
162
|
+
panelId(e) {
|
|
163
|
+
return `${this.id}-${encodeURIComponent(e)}`;
|
|
164
|
+
}
|
|
165
|
+
createGroup(e) {
|
|
166
|
+
const t = document.createElement("section");
|
|
167
|
+
t.className = "rulego-sidebar__group", e.recent ? t.dataset.sidebarRecent = "true" : t.dataset.sidebarCategory = e.category, t.append(this.createHeader(e.key, e.label, e.components.length, !1, "", e.category));
|
|
79
168
|
const s = document.createElement("div");
|
|
80
|
-
s.className = "rulego-sidebar__group-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.collapsedGroups.has(e.category) ? this.collapsedGroups.delete(e.category) : this.collapsedGroups.add(e.category);
|
|
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
|
-
}
|
|
97
|
-
t.appendChild(d);
|
|
169
|
+
if (s.className = "rulego-sidebar__group-content", s.id = this.panelId(e.key), s.hidden = !this.isExpanded(e.key), t.append(s), s.hidden) return t;
|
|
170
|
+
if (!this.hasSubgroups(e)) s.append(this.createList(e.components, e.key, e.label));
|
|
171
|
+
else for (const i of e.subgroups) {
|
|
172
|
+
const o = I(e.category, i.id), n = document.createElement("section");
|
|
173
|
+
n.className = "rulego-sidebar__subgroup", n.append(this.createHeader(o, i.label, i.components.length, !0, i.description));
|
|
174
|
+
const r = document.createElement("div");
|
|
175
|
+
r.id = this.panelId(o), r.hidden = !this.isExpanded(o), r.hidden || r.append(this.createList(i.components, o, i.label)), n.append(r), s.append(n);
|
|
98
176
|
}
|
|
99
177
|
return t;
|
|
100
178
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
type: e.type,
|
|
118
|
-
category: e.category,
|
|
119
|
-
label: n,
|
|
120
|
-
color: e.color || t
|
|
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;
|
|
179
|
+
createList(e, t, s) {
|
|
180
|
+
const i = document.createElement("div");
|
|
181
|
+
return i.className = "rulego-sidebar__component-list", i.setAttribute("role", "group"), i.setAttribute("aria-label", s), e.forEach((o) => i.append(this.createComponent(o, t))), i.addEventListener("keydown", (o) => {
|
|
182
|
+
if (o.altKey || o.ctrlKey || o.metaKey || o.isComposing) return;
|
|
183
|
+
const n = [...i.querySelectorAll(".rulego-sidebar__component")], r = n.indexOf(o.target);
|
|
184
|
+
if (r < 0) return;
|
|
185
|
+
const p = o.key === "Home" ? 0 : o.key === "End" ? n.length - 1 : o.key === "ArrowDown" ? r + 1 : o.key === "ArrowUp" ? r - 1 : -1;
|
|
186
|
+
if (!n[p]) {
|
|
187
|
+
["ArrowDown", "ArrowUp", "Home", "End"].includes(o.key) && (o.preventDefault(), o.stopPropagation());
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
o.preventDefault(), o.stopPropagation(), n[p].focus();
|
|
191
|
+
}), i;
|
|
125
192
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
193
|
+
createComponent(e, t) {
|
|
194
|
+
const s = document.createElement("button");
|
|
195
|
+
s.type = "button", s.className = "rulego-sidebar__component", s.draggable = !0, s.dataset.componentType = e.type, s.dataset.sidebarFocus = JSON.stringify([t, f(e)]);
|
|
196
|
+
const i = A(e, this.text), o = B(e, this.text);
|
|
197
|
+
s.title = [i, e.type, o].filter(Boolean).join(`
|
|
198
|
+
`), s.setAttribute("aria-label", i), o && s.setAttribute("aria-description", o);
|
|
199
|
+
const n = T(e.category), r = e.themeColorMode === "theme" ? void 0 : e.background;
|
|
200
|
+
s.style.setProperty("--rulego-component-accent", S(e.color || r, `var(--rg-node-${n}-stroke, var(--rge-primary))`)), s.style.setProperty("--rulego-component-bg", S(r, `var(--rg-node-${n}-bg, var(--rg-input-bg))`));
|
|
201
|
+
const p = document.createElement("span");
|
|
202
|
+
p.className = "rulego-sidebar__component-icon", p.setAttribute("aria-hidden", "true");
|
|
203
|
+
const a = document.createElement("img"), u = N({ ...e, icon: void 0 }, { theme: this.iconTheme });
|
|
204
|
+
a.src = N(e, { theme: this.iconTheme }), a.alt = "", a.draggable = !1, a.addEventListener("error", () => {
|
|
205
|
+
a.getAttribute("src") !== u && (a.src = u);
|
|
206
|
+
}), p.append(a);
|
|
207
|
+
const g = document.createElement("span");
|
|
208
|
+
g.className = "rulego-sidebar__component-name", g.textContent = i, s.append(p, g);
|
|
209
|
+
for (const h of ["input", "output"]) {
|
|
210
|
+
if (h === "input" ? e.notInput : e.notOutput) continue;
|
|
211
|
+
const d = document.createElement("span");
|
|
212
|
+
d.className = `rulego-sidebar__port rulego-sidebar__port--${h}`, d.setAttribute("aria-hidden", "true"), s.append(d);
|
|
213
|
+
}
|
|
214
|
+
return s.addEventListener("click", () => {
|
|
215
|
+
var h, d;
|
|
216
|
+
return (d = (h = this.options).onDragStart) == null ? void 0 : d.call(h, e);
|
|
217
|
+
}), s.addEventListener("keydown", (h) => {
|
|
218
|
+
var d, m;
|
|
219
|
+
h.key !== "Enter" && h.key !== " " || (h.preventDefault(), h.stopPropagation(), !h.repeat && !h.isComposing && ((m = (d = this.options).onDragStart) == null || m.call(d, e)));
|
|
220
|
+
}), s.addEventListener("dragstart", (h) => {
|
|
221
|
+
var m, l, b, E;
|
|
222
|
+
const d = JSON.stringify(e);
|
|
223
|
+
(m = h.dataTransfer) == null || m.setData("application/rulego-component", d), (l = h.dataTransfer) == null || l.setData("application/json", d), h.dataTransfer && (h.dataTransfer.effectAllowed = "copy"), s.classList.add("rulego-sidebar__component--dragging"), (E = (b = this.options).onDragStart) == null || E.call(b, e);
|
|
224
|
+
}), s.addEventListener("dragend", () => s.classList.remove("rulego-sidebar__component--dragging")), s;
|
|
142
225
|
}
|
|
143
|
-
// ============================================================
|
|
144
|
-
// 公共 API
|
|
145
|
-
// ============================================================
|
|
146
|
-
/**
|
|
147
|
-
* 手动触发刷新
|
|
148
|
-
*/
|
|
149
226
|
refresh() {
|
|
150
|
-
|
|
151
|
-
this.
|
|
227
|
+
var h, d, m;
|
|
228
|
+
if (!this.rootEl || !this.groupsEl) return;
|
|
229
|
+
this.iconTheme = K(this.options.theme || this.core.theme.getTheme()), this.rootEl.dataset.theme = this.iconTheme, this.rootEl.dataset.rgTheme = this.iconTheme;
|
|
230
|
+
const e = { ...P(this.iconTheme), ...this.options.theme ? {} : (h = this.core.theme.getThemeDefinition()) == null ? void 0 : h.variables };
|
|
231
|
+
for (const [l, b] of Object.entries(e)) this.rootEl.style.setProperty(l, b);
|
|
232
|
+
this.rootEl.setAttribute("aria-label", this.text("editor.sidebar.ariaLabel"));
|
|
233
|
+
const t = this.core.i18n.getLocale().toLowerCase().startsWith("en");
|
|
234
|
+
this.searchInput && (this.searchInput.value = this.searchKeyword, this.searchInput.placeholder = this.options.searchPlaceholder ?? this.text("sidebar.searchPlaceholder"), this.searchInput.setAttribute("aria-label", this.text("sidebar.searchPlaceholder"))), this.clearButton && (this.clearButton.hidden = !this.searchKeyword.length, this.clearButton.title = this.text("editorShell.clearSearch", t ? "Clear search" : "清空搜索"), this.clearButton.setAttribute("aria-label", this.clearButton.title)), this.managerButton && (this.managerButton.title = this.text("editor.toolbar.componentManage"), this.managerButton.setAttribute("aria-label", this.managerButton.title));
|
|
235
|
+
const s = this.buildGroups(), i = this.filterGroups(s), o = new Map(s.flatMap((l) => l.components).map((l) => [l.type, l])), n = this.options.showRecent && !this.query ? [...new Set(this.options.recentComponentTypes || [])].flatMap((l) => o.has(l) ? [o.get(l)] : []) : [];
|
|
236
|
+
this.displayGroups = n.length ? [{
|
|
237
|
+
key: J,
|
|
238
|
+
recent: !0,
|
|
239
|
+
category: "common",
|
|
240
|
+
color: "",
|
|
241
|
+
label: this.text("editor.sidebar.recentComponents"),
|
|
242
|
+
components: n,
|
|
243
|
+
subgroups: []
|
|
244
|
+
}, ...i] : i;
|
|
245
|
+
const r = this.allExpanded(), p = this.visibleKeys().some((l) => this.isExpanded(l));
|
|
246
|
+
this.toggleButton && (this.toggleButton.disabled = !this.displayGroups.length, this.toggleButton.title = this.text(p ? "editor.sidebar.collapseAll" : "editor.sidebar.expandAll"), this.toggleButton.setAttribute("aria-label", this.toggleButton.title), this.toggleButton.setAttribute("aria-pressed", p && !r ? "mixed" : String(r)), this.toggleButton.replaceChildren(this.icon(p ? "collapse-all" : "expand-all")));
|
|
247
|
+
const a = document.activeElement, u = a && this.groupsEl.contains(a) ? a.dataset.sidebarFocus : void 0, g = this.groupsEl.scrollTop;
|
|
248
|
+
if (this.groupsEl.replaceChildren(...this.displayGroups.map((l) => this.createGroup(l))), !i.length) {
|
|
249
|
+
const l = document.createElement("div");
|
|
250
|
+
l.className = "rulego-sidebar__empty", l.setAttribute("role", "status"), l.setAttribute("aria-live", "polite"), l.append(this.icon("package"));
|
|
251
|
+
const b = document.createElement("p");
|
|
252
|
+
b.textContent = this.query ? this.text("sidebar.noResults") : this.text("editorShell.noComponents", t ? "No components available" : "暂无可用组件"), l.append(b), this.groupsEl.append(l);
|
|
253
|
+
}
|
|
254
|
+
u && ((m = [...this.groupsEl.querySelectorAll("[data-sidebar-focus]")].find((b) => b.dataset.sidebarFocus === u) || this.searchInput || ((d = this.toggleButton) != null && d.isConnected ? this.toggleButton : this.rootEl)) == null || m.focus({ preventScroll: !0 })), this.groupsEl.scrollTop = g;
|
|
255
|
+
}
|
|
256
|
+
/** Search state is temporary; clearing restores the browsing expansion state. */
|
|
257
|
+
setSearch(e) {
|
|
258
|
+
var i, o;
|
|
259
|
+
const t = this.query, s = this.searchKeyword !== e;
|
|
260
|
+
this.searchKeyword = e, t !== this.query && this.searchExpanded.clear(), this.refresh(), this.groupsEl && t !== this.query && (this.groupsEl.scrollTop = 0), s && ((o = (i = this.options).onSearchChange) == null || o.call(i, e));
|
|
261
|
+
}
|
|
262
|
+
setRecentComponentTypes(e) {
|
|
263
|
+
this.options.recentComponentTypes = [...e], this.refresh();
|
|
152
264
|
}
|
|
153
|
-
/**
|
|
154
|
-
* 展开所有分组
|
|
155
|
-
*/
|
|
156
265
|
expandAll() {
|
|
157
|
-
this.
|
|
266
|
+
this.visibleKeys().forEach((e) => this.setExpansion(e, !0)), this.refresh();
|
|
158
267
|
}
|
|
159
|
-
/**
|
|
160
|
-
* 折叠所有分组
|
|
161
|
-
*/
|
|
162
268
|
collapseAll() {
|
|
163
|
-
|
|
164
|
-
for (const t of e)
|
|
165
|
-
this.collapsedGroups.add(t.category);
|
|
166
|
-
this.refresh();
|
|
269
|
+
this.visibleKeys().forEach((e) => this.setExpansion(e, !1)), this.refresh();
|
|
167
270
|
}
|
|
168
|
-
/**
|
|
169
|
-
* 获取根 DOM 元素
|
|
170
|
-
*/
|
|
171
271
|
getElement() {
|
|
172
272
|
return this.rootEl;
|
|
173
273
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
componentLabel(e) {
|
|
178
|
-
return this.text(`components.${e.type}`, e.label || e.type.split("/").pop() || e.type);
|
|
274
|
+
destroy() {
|
|
275
|
+
var e;
|
|
276
|
+
this.unsubscribe.splice(0).forEach((t) => t()), (e = this.rootEl) == null || e.remove(), this.rootEl = null, this.groupsEl = null, this.searchInput = null, this.clearButton = null, this.toggleButton = null, this.managerButton = null;
|
|
179
277
|
}
|
|
180
278
|
}
|
|
181
|
-
function
|
|
279
|
+
function C(c, e) {
|
|
182
280
|
if (e) {
|
|
183
281
|
if (typeof e == "string") {
|
|
184
|
-
|
|
282
|
+
c.textContent = e;
|
|
185
283
|
return;
|
|
186
284
|
}
|
|
187
285
|
if (e.kind === "text") {
|
|
188
|
-
|
|
286
|
+
c.textContent = e.value;
|
|
189
287
|
return;
|
|
190
288
|
}
|
|
191
|
-
e.kind === "trusted-svg" &&
|
|
289
|
+
e.kind === "trusted-svg" && X(c, e.svg);
|
|
192
290
|
}
|
|
193
291
|
}
|
|
194
|
-
function
|
|
292
|
+
function X(c, e) {
|
|
195
293
|
const t = document.createElement("template");
|
|
196
294
|
t.innerHTML = e;
|
|
197
295
|
const s = t.content.firstElementChild;
|
|
198
296
|
if (!s || s.tagName.toLowerCase() !== "svg") {
|
|
199
|
-
|
|
297
|
+
c.textContent = "";
|
|
200
298
|
return;
|
|
201
299
|
}
|
|
202
|
-
|
|
300
|
+
L(s), c.replaceChildren(s);
|
|
203
301
|
}
|
|
204
|
-
function
|
|
205
|
-
for (const e of Array.from(
|
|
302
|
+
function L(c) {
|
|
303
|
+
for (const e of Array.from(c.attributes)) {
|
|
206
304
|
const t = e.name.toLowerCase(), s = e.value.trim().toLowerCase();
|
|
207
|
-
(t.startsWith("on") || s.startsWith("javascript:") || s.startsWith("data:text/html")) &&
|
|
305
|
+
(t.startsWith("on") || s.startsWith("javascript:") || s.startsWith("data:text/html")) && c.removeAttribute(e.name);
|
|
208
306
|
}
|
|
209
|
-
for (const e of Array.from(
|
|
307
|
+
for (const e of Array.from(c.children)) {
|
|
210
308
|
const t = e.tagName.toLowerCase();
|
|
211
309
|
if (t === "script" || t === "foreignobject") {
|
|
212
310
|
e.remove();
|
|
213
311
|
continue;
|
|
214
312
|
}
|
|
215
|
-
|
|
313
|
+
L(e);
|
|
216
314
|
}
|
|
217
315
|
}
|
|
218
|
-
class
|
|
316
|
+
class se {
|
|
219
317
|
constructor(e, t) {
|
|
220
318
|
this.rootEl = null, this.unsubscribe = null, this.buttonElements = /* @__PURE__ */ new Map(), this.container = e, this.core = t.core, this.options = {
|
|
221
319
|
core: t.core,
|
|
@@ -249,17 +347,17 @@ class $ {
|
|
|
249
347
|
}), e.push(...this.options.extraButtons));
|
|
250
348
|
for (const t of e) {
|
|
251
349
|
if (t.divider) {
|
|
252
|
-
const
|
|
253
|
-
|
|
350
|
+
const i = document.createElement("span");
|
|
351
|
+
i.className = "rulego-toolbar__divider", this.rootEl.appendChild(i);
|
|
254
352
|
}
|
|
255
353
|
if (!t.icon && t.divider) continue;
|
|
256
354
|
const s = document.createElement("button");
|
|
257
|
-
if (s.className = "rulego-toolbar__button", s.title = t.title,
|
|
258
|
-
const
|
|
259
|
-
|
|
355
|
+
if (s.className = "rulego-toolbar__button", s.title = t.title, C(s, t.icon), t.label) {
|
|
356
|
+
const i = document.createElement("span");
|
|
357
|
+
i.className = "rulego-toolbar__button-label", i.textContent = t.label, s.appendChild(i);
|
|
260
358
|
}
|
|
261
|
-
s.addEventListener("click", (
|
|
262
|
-
|
|
359
|
+
s.addEventListener("click", (i) => {
|
|
360
|
+
i.preventDefault(), i.stopPropagation(), t.onClick();
|
|
263
361
|
}), this.buttonElements.set(t.id, s), this.rootEl.appendChild(s);
|
|
264
362
|
}
|
|
265
363
|
this.container.appendChild(this.rootEl), this.updateButtonStates();
|
|
@@ -356,7 +454,7 @@ class $ {
|
|
|
356
454
|
}), e;
|
|
357
455
|
}
|
|
358
456
|
toolbarIcon(e) {
|
|
359
|
-
const t =
|
|
457
|
+
const t = _(e);
|
|
360
458
|
return t ? { kind: "trusted-svg", svg: t } : e;
|
|
361
459
|
}
|
|
362
460
|
// ============================================================
|
|
@@ -367,7 +465,7 @@ class $ {
|
|
|
367
465
|
*/
|
|
368
466
|
updateButtonStates() {
|
|
369
467
|
for (const [e, t] of this.buttonElements) {
|
|
370
|
-
const s = this.getBuiltinButtons().find((
|
|
468
|
+
const s = this.getBuiltinButtons().find((i) => i.id === e);
|
|
371
469
|
s && typeof s.disabled == "function" && (t.disabled = s.disabled(), t.classList.toggle("rulego-toolbar__button--disabled", t.disabled));
|
|
372
470
|
}
|
|
373
471
|
}
|
|
@@ -381,7 +479,7 @@ class $ {
|
|
|
381
479
|
return this.rootEl;
|
|
382
480
|
}
|
|
383
481
|
text(e, t) {
|
|
384
|
-
return
|
|
482
|
+
return y(this.core.i18n, e, t);
|
|
385
483
|
}
|
|
386
484
|
/**
|
|
387
485
|
* 动态添加自定义按钮
|
|
@@ -390,12 +488,12 @@ class $ {
|
|
|
390
488
|
addButton(e) {
|
|
391
489
|
if (!this.rootEl) return;
|
|
392
490
|
const t = document.createElement("button");
|
|
393
|
-
t.className = "rulego-toolbar__button", t.title = e.title,
|
|
491
|
+
t.className = "rulego-toolbar__button", t.title = e.title, C(t, e.icon), t.addEventListener("click", (s) => {
|
|
394
492
|
s.preventDefault(), e.onClick();
|
|
395
493
|
}), this.buttonElements.set(e.id, t), this.rootEl.appendChild(t);
|
|
396
494
|
}
|
|
397
495
|
}
|
|
398
|
-
class
|
|
496
|
+
class ie {
|
|
399
497
|
constructor(e, t) {
|
|
400
498
|
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 = {
|
|
401
499
|
core: t.core,
|
|
@@ -422,8 +520,8 @@ class P {
|
|
|
422
520
|
*/
|
|
423
521
|
bindEvents() {
|
|
424
522
|
this.unsubscribe = this.core.store.subscribe((t) => {
|
|
425
|
-
const s = t.currentNodeView,
|
|
426
|
-
s &&
|
|
523
|
+
const s = t.currentNodeView, i = t.currentNodeModel;
|
|
524
|
+
s && i && Object.keys(i).length > 0 && this.showPanel(s, i);
|
|
427
525
|
});
|
|
428
526
|
const e = this.core.eventBus.on("blank:click", () => {
|
|
429
527
|
this.clearPanel();
|
|
@@ -450,8 +548,8 @@ class P {
|
|
|
450
548
|
showPanel(e, t) {
|
|
451
549
|
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))
|
|
452
550
|
for (const s of e.fields) {
|
|
453
|
-
const
|
|
454
|
-
this.formContainer.appendChild(
|
|
551
|
+
const i = this.createFieldElement(s, t);
|
|
552
|
+
this.formContainer.appendChild(i);
|
|
455
553
|
}
|
|
456
554
|
}
|
|
457
555
|
/**
|
|
@@ -491,30 +589,30 @@ class P {
|
|
|
491
589
|
createFieldElement(e, t) {
|
|
492
590
|
const s = document.createElement("div");
|
|
493
591
|
s.className = "rulego-property-panel__field";
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
let
|
|
592
|
+
const i = document.createElement("label");
|
|
593
|
+
i.className = "rulego-property-panel__label", i.textContent = e.label || e.name, e.desc && (i.title = e.desc), s.appendChild(i);
|
|
594
|
+
let o;
|
|
497
595
|
switch (e.type) {
|
|
498
596
|
case "bool":
|
|
499
|
-
|
|
597
|
+
o = this.createBoolField(e, t);
|
|
500
598
|
break;
|
|
501
599
|
case "select":
|
|
502
|
-
|
|
600
|
+
o = this.createSelectField(e, t);
|
|
503
601
|
break;
|
|
504
602
|
case "code":
|
|
505
603
|
case "json":
|
|
506
|
-
|
|
604
|
+
o = this.createTextareaField(e, t);
|
|
507
605
|
break;
|
|
508
606
|
case "int":
|
|
509
|
-
|
|
607
|
+
o = this.createNumberField(e, t);
|
|
510
608
|
break;
|
|
511
609
|
default:
|
|
512
|
-
|
|
610
|
+
o = this.createTextField(e, t);
|
|
513
611
|
break;
|
|
514
612
|
}
|
|
515
|
-
if (s.appendChild(
|
|
516
|
-
const
|
|
517
|
-
|
|
613
|
+
if (s.appendChild(o), e.desc) {
|
|
614
|
+
const n = document.createElement("span");
|
|
615
|
+
n.className = "rulego-property-panel__desc", n.textContent = e.desc, s.appendChild(n);
|
|
518
616
|
}
|
|
519
617
|
return s;
|
|
520
618
|
}
|
|
@@ -542,12 +640,12 @@ class P {
|
|
|
542
640
|
createBoolField(e, t) {
|
|
543
641
|
const s = document.createElement("div");
|
|
544
642
|
s.className = "rulego-property-panel__switch-wrapper";
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
return
|
|
549
|
-
this.handleFieldChange(e.name,
|
|
550
|
-
}), s.appendChild(
|
|
643
|
+
const i = `field-${e.name}-${Date.now()}`, o = document.createElement("input");
|
|
644
|
+
o.type = "checkbox", o.className = "rulego-property-panel__checkbox", o.id = i, o.checked = !!this.getModelValue(e, t);
|
|
645
|
+
const n = document.createElement("label");
|
|
646
|
+
return n.className = "rulego-property-panel__switch", n.htmlFor = i, o.addEventListener("change", () => {
|
|
647
|
+
this.handleFieldChange(e.name, o.checked);
|
|
648
|
+
}), s.appendChild(o), s.appendChild(n), s;
|
|
551
649
|
}
|
|
552
650
|
/**
|
|
553
651
|
* 下拉选择
|
|
@@ -555,11 +653,11 @@ class P {
|
|
|
555
653
|
createSelectField(e, t) {
|
|
556
654
|
const s = document.createElement("select");
|
|
557
655
|
s.className = "rulego-property-panel__select", s.name = e.name;
|
|
558
|
-
const
|
|
656
|
+
const i = String(this.getModelValue(e, t) ?? "");
|
|
559
657
|
if (e.options && e.options.length > 0)
|
|
560
|
-
for (const
|
|
561
|
-
const
|
|
562
|
-
|
|
658
|
+
for (const o of e.options.filter(O)) {
|
|
659
|
+
const n = document.createElement("option"), r = String(o.value ?? "");
|
|
660
|
+
n.value = r, n.textContent = o.label, r === i && (n.selected = !0), s.appendChild(n);
|
|
563
661
|
}
|
|
564
662
|
return s.addEventListener("change", () => {
|
|
565
663
|
this.handleFieldChange(e.name, s.value);
|
|
@@ -630,12 +728,12 @@ class P {
|
|
|
630
728
|
this.clearPanel();
|
|
631
729
|
}
|
|
632
730
|
text(e, t) {
|
|
633
|
-
return
|
|
731
|
+
return y(this.core.i18n, e, t);
|
|
634
732
|
}
|
|
635
733
|
}
|
|
636
|
-
class
|
|
734
|
+
class ne {
|
|
637
735
|
constructor(e, t) {
|
|
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;
|
|
736
|
+
this.menuEl = null, this.currentContext = null, this.outsideClickHandler = null, this.contextMenuHandler = null, this.escapeKeyHandler = null, this.positionFrame = null, this.releaseTheme = null, this.container = e, this.core = t.core, this.options = t;
|
|
639
737
|
const s = t.includeBuiltin !== !1 ? this.getBuiltinItems() : [];
|
|
640
738
|
this.items = [...s, ...t.items ?? []], this.mount(), this.bindEvents();
|
|
641
739
|
}
|
|
@@ -646,7 +744,8 @@ class V {
|
|
|
646
744
|
* 创建菜单 DOM (初始隐藏)
|
|
647
745
|
*/
|
|
648
746
|
mount() {
|
|
649
|
-
|
|
747
|
+
var e, t;
|
|
748
|
+
this.menuEl = document.createElement("div"), this.menuEl.className = "rulego-context-menu", this.menuEl.style.display = "none", this.releaseTheme = ((t = (e = this.core.theme) == null ? void 0 : e.bindElement) == null ? void 0 : t.call(e, this.menuEl)) || null, document.body.appendChild(this.menuEl);
|
|
650
749
|
}
|
|
651
750
|
/**
|
|
652
751
|
* 绑定事件
|
|
@@ -664,7 +763,8 @@ class V {
|
|
|
664
763
|
* 销毁菜单
|
|
665
764
|
*/
|
|
666
765
|
destroy() {
|
|
667
|
-
|
|
766
|
+
var e;
|
|
767
|
+
this.hide(), (e = this.releaseTheme) == null || e.call(this), this.releaseTheme = null, 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;
|
|
668
768
|
}
|
|
669
769
|
// ============================================================
|
|
670
770
|
// 右键处理
|
|
@@ -675,15 +775,15 @@ class V {
|
|
|
675
775
|
handleContextMenu(e) {
|
|
676
776
|
const t = e.target, s = this.resolveContext(t, e);
|
|
677
777
|
this.currentContext = s;
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
return
|
|
778
|
+
const i = this.items.filter((o) => {
|
|
779
|
+
const n = Array.isArray(o.target) ? o.target : [o.target];
|
|
780
|
+
return n.includes(s.type) || n.includes("all");
|
|
681
781
|
});
|
|
682
|
-
if (
|
|
782
|
+
if (i.length === 0) {
|
|
683
783
|
this.hide();
|
|
684
784
|
return;
|
|
685
785
|
}
|
|
686
|
-
this.renderMenu(
|
|
786
|
+
this.renderMenu(i, e.clientX, e.clientY);
|
|
687
787
|
}
|
|
688
788
|
/**
|
|
689
789
|
* 解析右键目标的上下文
|
|
@@ -696,10 +796,10 @@ class V {
|
|
|
696
796
|
id: s.getAttribute("data-node-id") || void 0,
|
|
697
797
|
position: { x: t.clientX, y: t.clientY }
|
|
698
798
|
};
|
|
699
|
-
const
|
|
700
|
-
return
|
|
799
|
+
const i = e.closest(".lf-edge");
|
|
800
|
+
return i ? {
|
|
701
801
|
type: "edge",
|
|
702
|
-
id:
|
|
802
|
+
id: i.getAttribute("data-edge-id") || void 0,
|
|
703
803
|
position: { x: t.clientX, y: t.clientY }
|
|
704
804
|
} : {
|
|
705
805
|
type: "canvas",
|
|
@@ -715,36 +815,36 @@ class V {
|
|
|
715
815
|
renderMenu(e, t, s) {
|
|
716
816
|
if (!this.menuEl) return;
|
|
717
817
|
this.cancelPendingPosition(), this.menuEl.replaceChildren();
|
|
718
|
-
for (const
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
if (
|
|
723
|
-
const
|
|
724
|
-
|
|
818
|
+
for (const n of e) {
|
|
819
|
+
const r = document.createElement("div");
|
|
820
|
+
r.className = "rulego-context-menu__item";
|
|
821
|
+
const p = typeof n.disabled == "function" ? n.disabled() : n.disabled;
|
|
822
|
+
if (p && r.classList.add("rulego-context-menu__item--disabled"), n.icon) {
|
|
823
|
+
const u = document.createElement("span");
|
|
824
|
+
u.className = "rulego-context-menu__icon", C(u, n.icon), r.appendChild(u);
|
|
725
825
|
}
|
|
726
|
-
const
|
|
727
|
-
if (
|
|
728
|
-
this.currentContext &&
|
|
729
|
-
}), this.menuEl.appendChild(
|
|
730
|
-
const
|
|
731
|
-
|
|
826
|
+
const a = document.createElement("span");
|
|
827
|
+
if (a.className = "rulego-context-menu__label", a.textContent = n.label, r.appendChild(a), p || r.addEventListener("click", () => {
|
|
828
|
+
this.currentContext && n.onClick(this.currentContext), this.hide();
|
|
829
|
+
}), this.menuEl.appendChild(r), n.separator) {
|
|
830
|
+
const u = document.createElement("div");
|
|
831
|
+
u.className = "rulego-context-menu__separator", this.menuEl.appendChild(u);
|
|
732
832
|
}
|
|
733
833
|
}
|
|
734
834
|
this.menuEl.style.left = `${t}px`, this.menuEl.style.top = `${s}px`, this.menuEl.style.visibility = "hidden", this.menuEl.style.display = "block";
|
|
735
|
-
let
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
const
|
|
739
|
-
if (!
|
|
740
|
-
const
|
|
835
|
+
let i = !1;
|
|
836
|
+
const o = requestAnimationFrame(() => {
|
|
837
|
+
i = !0, this.positionFrame = null;
|
|
838
|
+
const n = this.menuEl;
|
|
839
|
+
if (!n) return;
|
|
840
|
+
const r = n.getBoundingClientRect(), p = $(
|
|
741
841
|
{ left: t, top: s },
|
|
742
|
-
{ width:
|
|
842
|
+
{ width: r.width, height: r.height },
|
|
743
843
|
{ width: window.innerWidth, height: window.innerHeight }
|
|
744
844
|
);
|
|
745
|
-
|
|
845
|
+
n.style.left = `${p.left}px`, n.style.top = `${p.top}px`, n.style.visibility = "visible";
|
|
746
846
|
});
|
|
747
|
-
this.positionFrame =
|
|
847
|
+
this.positionFrame = i ? null : o;
|
|
748
848
|
}
|
|
749
849
|
/**
|
|
750
850
|
* 隐藏菜单
|
|
@@ -817,10 +917,10 @@ class V {
|
|
|
817
917
|
this.items.push(e);
|
|
818
918
|
}
|
|
819
919
|
text(e, t) {
|
|
820
|
-
return
|
|
920
|
+
return y(this.core.i18n, e, t);
|
|
821
921
|
}
|
|
822
922
|
toolbarIcon(e) {
|
|
823
|
-
const t =
|
|
923
|
+
const t = _(e);
|
|
824
924
|
return t ? { kind: "trusted-svg", svg: t } : e;
|
|
825
925
|
}
|
|
826
926
|
/**
|
|
@@ -837,7 +937,7 @@ class V {
|
|
|
837
937
|
return this.menuEl;
|
|
838
938
|
}
|
|
839
939
|
}
|
|
840
|
-
class
|
|
940
|
+
class oe {
|
|
841
941
|
constructor(e, t) {
|
|
842
942
|
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();
|
|
843
943
|
}
|
|
@@ -853,8 +953,8 @@ class D {
|
|
|
853
953
|
t.className = "rulego-debug-console__title", t.textContent = this.t("editor.debugConsole.title", "调试控制台");
|
|
854
954
|
const s = document.createElement("button");
|
|
855
955
|
s.className = "rulego-debug-console__clear", s.textContent = this.t("editor.debugConsole.clear", "清除"), e.append(t, s);
|
|
856
|
-
const
|
|
857
|
-
|
|
956
|
+
const i = document.createElement("div");
|
|
957
|
+
i.className = "rulego-debug-console__list", this.consoleEl.append(e, i), this.listEl = i, this.container.appendChild(this.consoleEl), s.addEventListener("click", () => this.clear());
|
|
858
958
|
}
|
|
859
959
|
bindEvents() {
|
|
860
960
|
this.unsubscribe = this.core.eventBus.on("debug:log", (e) => {
|
|
@@ -865,7 +965,7 @@ class D {
|
|
|
865
965
|
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;
|
|
866
966
|
const t = document.createElement("div");
|
|
867
967
|
t.className = "rulego-debug-console__item";
|
|
868
|
-
const s = typeof e == "string" ? e :
|
|
968
|
+
const s = typeof e == "string" ? e : R(V(e), { maxChars: 2e4, space: 0 });
|
|
869
969
|
t.textContent = `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${s}`, this.listEl.appendChild(t), this.listEl.scrollTop = this.listEl.scrollHeight;
|
|
870
970
|
}
|
|
871
971
|
clear() {
|
|
@@ -876,20 +976,20 @@ class D {
|
|
|
876
976
|
(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
977
|
}
|
|
878
978
|
}
|
|
879
|
-
const
|
|
880
|
-
function
|
|
979
|
+
const Z = 28;
|
|
980
|
+
function M(c, e, t = 0) {
|
|
881
981
|
const s = [];
|
|
882
|
-
return
|
|
883
|
-
var
|
|
884
|
-
s.push({ node:
|
|
982
|
+
return c.forEach((i) => {
|
|
983
|
+
var o;
|
|
984
|
+
s.push({ node: i, depth: t }), (o = i.children) != null && o.length && e.has(i.key) && s.push(...M(i.children, e, t + 1));
|
|
885
985
|
}), s;
|
|
886
986
|
}
|
|
887
|
-
function
|
|
888
|
-
e.split(/\s+/).filter(Boolean).forEach((t) =>
|
|
987
|
+
function Q(c, e = "") {
|
|
988
|
+
e.split(/\s+/).filter(Boolean).forEach((t) => c.classList.add(t));
|
|
889
989
|
}
|
|
890
|
-
class
|
|
990
|
+
class re {
|
|
891
991
|
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
|
|
992
|
+
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 W({
|
|
893
993
|
workflows: t.workflows,
|
|
894
994
|
activeChainId: t.activeChainId,
|
|
895
995
|
keyword: t.keyword,
|
|
@@ -917,7 +1017,7 @@ class W {
|
|
|
917
1017
|
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
1018
|
}
|
|
919
1019
|
mount() {
|
|
920
|
-
this.rootEl = document.createElement("section"), this.rootEl.className = "huanban_workflow_explorer",
|
|
1020
|
+
this.rootEl = document.createElement("section"), this.rootEl.className = "huanban_workflow_explorer", Q(this.rootEl, this.options.className), this.rootEl.setAttribute("aria-label", "规则链资源");
|
|
921
1021
|
const e = document.createElement("div");
|
|
922
1022
|
e.className = "huanban_workflow_explorer__search";
|
|
923
1023
|
const t = document.createElement("span");
|
|
@@ -933,71 +1033,71 @@ class W {
|
|
|
933
1033
|
renderState(e) {
|
|
934
1034
|
if (this.destroyed || !this.treeEl) return;
|
|
935
1035
|
this.searchInputEl && this.searchInputEl.value !== e.keyword && (this.searchInputEl.value = e.keyword);
|
|
936
|
-
const t =
|
|
1036
|
+
const t = M(e.tree, new Set(e.expandedKeys));
|
|
937
1037
|
if (t.length === 0) {
|
|
938
1038
|
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
|
|
940
|
-
|
|
1039
|
+
const d = document.createElement("div");
|
|
1040
|
+
d.className = "huanban_workflow_explorer__empty", d.textContent = this.options.emptyText || "暂无规则链", this.treeEl.replaceChildren(d);
|
|
941
1041
|
return;
|
|
942
1042
|
}
|
|
943
|
-
const s = this.options.virtualization,
|
|
944
|
-
if (
|
|
945
|
-
const
|
|
946
|
-
var
|
|
947
|
-
return
|
|
1043
|
+
const s = this.options.virtualization, i = (s == null ? void 0 : s.enabled) !== !1, o = Math.max(1, (s == null ? void 0 : s.threshold) ?? q), n = Math.max(1, (s == null ? void 0 : s.itemHeight) ?? Z), r = Math.max(1, (s == null ? void 0 : s.viewportHeight) ?? G), p = Math.max(0, (s == null ? void 0 : s.overscan) ?? z), a = i && t.length > o;
|
|
1044
|
+
if (a || (this.virtualScrollTop = 0, this.autoScrolledActiveChainId = null, this.treeEl.scrollTop !== 0 && (this.treeEl.scrollTop = 0)), e.activeChainId || (this.autoScrolledActiveChainId = null), a && e.activeChainId && e.activeChainId !== this.autoScrolledActiveChainId) {
|
|
1045
|
+
const d = t.findIndex((m) => {
|
|
1046
|
+
var l;
|
|
1047
|
+
return m.node.kind === "chain" && ((l = m.node.chain) == null ? void 0 : l.id) === e.activeChainId;
|
|
948
1048
|
});
|
|
949
|
-
if (
|
|
950
|
-
const
|
|
951
|
-
|
|
1049
|
+
if (d >= 0) {
|
|
1050
|
+
const m = Math.floor(this.virtualScrollTop / n), l = Math.ceil((this.virtualScrollTop + r) / n);
|
|
1051
|
+
d < m ? this.virtualScrollTop = d * n : d >= l && (this.virtualScrollTop = (d + 1) * n - r), this.autoScrolledActiveChainId = e.activeChainId;
|
|
952
1052
|
}
|
|
953
1053
|
}
|
|
954
|
-
const
|
|
1054
|
+
const u = U({
|
|
955
1055
|
total: t.length,
|
|
956
|
-
itemHeight:
|
|
957
|
-
viewportHeight:
|
|
1056
|
+
itemHeight: n,
|
|
1057
|
+
viewportHeight: r,
|
|
958
1058
|
scrollTop: this.virtualScrollTop,
|
|
959
|
-
overscan:
|
|
1059
|
+
overscan: p
|
|
960
1060
|
});
|
|
961
|
-
this.treeEl.classList.toggle("is-virtualized",
|
|
962
|
-
const
|
|
963
|
-
if (
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
const
|
|
967
|
-
|
|
1061
|
+
this.treeEl.classList.toggle("is-virtualized", a), a ? (this.treeEl.dataset.explorerVirtualized = "true", this.treeEl.dataset.explorerVirtualTotal = String(t.length), this.treeEl.style.height = `${u.viewportHeight}px`) : (this.treeEl.removeAttribute("data-explorer-virtualized"), this.treeEl.removeAttribute("data-explorer-virtual-total"), this.treeEl.style.removeProperty("height"));
|
|
1062
|
+
const g = a ? t.slice(u.start, u.end) : t, h = document.createDocumentFragment();
|
|
1063
|
+
if (a) {
|
|
1064
|
+
const d = document.createElement("div");
|
|
1065
|
+
d.className = "huanban_workflow_explorer__virtual-canvas", d.style.height = `${u.totalHeight}px`;
|
|
1066
|
+
const m = document.createElement("div");
|
|
1067
|
+
m.className = "huanban_workflow_explorer__virtual-items", m.style.transform = `translateY(${u.offsetTop}px)`, g.forEach(({ node: l, depth: b }, E) => m.appendChild(this.createRow(l, b, e, u.start + E, t.length))), d.appendChild(m), h.appendChild(d), this.treeEl.scrollTop !== u.scrollTop && (this.treeEl.scrollTop = u.scrollTop);
|
|
968
1068
|
} else
|
|
969
|
-
|
|
970
|
-
this.treeEl.replaceChildren(
|
|
1069
|
+
g.forEach(({ node: d, depth: m }, l) => h.appendChild(this.createRow(d, m, e, l, t.length)));
|
|
1070
|
+
this.treeEl.replaceChildren(h);
|
|
971
1071
|
}
|
|
972
|
-
createRow(e, t, s,
|
|
973
|
-
var
|
|
974
|
-
const
|
|
975
|
-
|
|
1072
|
+
createRow(e, t, s, i, o) {
|
|
1073
|
+
var d, m;
|
|
1074
|
+
const n = !!((d = e.children) != null && d.length), r = s.expandedKeys.includes(e.key), p = e.kind === "chain" && ((m = e.chain) == null ? void 0 : m.id) === s.activeChainId, a = document.createElement("button");
|
|
1075
|
+
a.type = "button", a.className = `huanban_workflow_explorer__row is-${e.kind}${p ? " is-active" : ""}`, a.style.paddingInlineStart = `${8 + t * 14}px`, a.setAttribute("role", "treeitem"), a.setAttribute("aria-level", String(t + 1)), a.setAttribute("aria-posinset", String(i + 1)), a.setAttribute("aria-setsize", String(o)), n && a.setAttribute("aria-expanded", String(r)), e.kind === "chain" && a.setAttribute("aria-selected", String(p)), a.title = e.chain ? `${e.chain.name}
|
|
976
1076
|
${e.chain.id}` : e.label;
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
const
|
|
982
|
-
if (
|
|
983
|
-
const
|
|
984
|
-
|
|
1077
|
+
const u = document.createElement("span");
|
|
1078
|
+
u.className = `huanban_workflow_explorer__chevron${n && r ? " is-open" : ""}`, u.setAttribute("aria-hidden", "true");
|
|
1079
|
+
const g = document.createElement("span");
|
|
1080
|
+
g.className = `huanban_workflow_explorer__kind is-${e.kind}`, g.setAttribute("aria-hidden", "true");
|
|
1081
|
+
const h = document.createElement("span");
|
|
1082
|
+
if (h.className = "huanban_workflow_explorer__label", h.textContent = e.label, a.append(u, g, h), e.kind === "chain" && e.chain) {
|
|
1083
|
+
const l = document.createElement("span");
|
|
1084
|
+
l.className = `huanban_workflow_explorer__status ${e.chain.disabled ? "is-offline" : "is-online"}`, l.title = e.chain.disabled ? "已下线" : "运行中", l.setAttribute("aria-label", l.title), a.appendChild(l);
|
|
985
1085
|
}
|
|
986
1086
|
if (e.count !== void 0) {
|
|
987
|
-
const
|
|
988
|
-
|
|
1087
|
+
const l = document.createElement("span");
|
|
1088
|
+
l.className = "huanban_workflow_explorer__count", l.textContent = String(e.count), a.appendChild(l);
|
|
989
1089
|
}
|
|
990
|
-
return
|
|
991
|
-
var
|
|
992
|
-
|
|
993
|
-
}),
|
|
1090
|
+
return a.addEventListener("click", () => {
|
|
1091
|
+
var l, b;
|
|
1092
|
+
n ? this.store.setExpanded(e.key, !r) : e.chain && ((b = (l = this.options).onOpen) == null || b.call(l, e.chain));
|
|
1093
|
+
}), a;
|
|
994
1094
|
}
|
|
995
1095
|
}
|
|
996
1096
|
export {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1097
|
+
ne as ContextMenu,
|
|
1098
|
+
oe as DebugConsole,
|
|
1099
|
+
ie as PropertyPanel,
|
|
1100
|
+
te as Sidebar,
|
|
1101
|
+
se as Toolbar,
|
|
1102
|
+
re as WorkflowExplorer
|
|
1003
1103
|
};
|