@huanban/rulego-editor-ui 1.4.2 → 2.1.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/index.esm.js CHANGED
@@ -1,221 +1,319 @@
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 {
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.collapsedGroups = /* @__PURE__ */ new Set(), this.searchKeyword = "", this.rootEl = null, this.unsubscribe = null, this.container = e, this.core = t.core, this.options = {
5
- core: t.core,
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 ?? !1,
8
- searchPlaceholder: t.searchPlaceholder || this.text("sidebar.searchPlaceholder", "搜索组件..."),
9
- width: t.width ?? "220px"
10
- }, this.mount(), this.unsubscribe = this.core.store.select(
11
- (s) => s.componentGroups
12
- ).subscribe(
13
- (s) => {
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
- * 挂载侧边栏 DOM 到容器
23
- */
24
- mount() {
25
- if (this.rootEl = document.createElement("div"), this.rootEl.className = "rulego-sidebar", this.rootEl.style.width = this.options.width, this.options.searchable) {
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-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);
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
- const e = document.createElement("div");
38
- e.className = "rulego-sidebar__groups", this.rootEl.appendChild(e), this.container.appendChild(this.rootEl);
39
- const t = this.core.store.getState().componentGroups;
40
- t && t.length > 0 && this.renderGroups(t);
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 u, a, p;
70
+ const r = f(n);
71
+ return !((u = n.type) != null && u.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 || ((p = (a = i.subgroups) == null ? void 0 : a.find((m) => m.components.some((h) => h.type === n.type))) == null ? void 0 : p.id),
76
+ categorySubgroups: [...n.categorySubgroups || [], ...o],
77
+ label: n.label || n.type,
78
+ desc: n.desc || ""
79
+ }), (m) => this.text(m, m))]);
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
- * 销毁侧边栏, 清理所有 DOM 和事件
44
- */
45
- destroy() {
46
- this.unsubscribe && (this.unsubscribe(), this.unsubscribe = null), this.rootEl && this.rootEl.parentNode && this.rootEl.parentNode.removeChild(this.rootEl), this.rootEl = null;
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((u) => u.id === n.id);
121
+ return r ? [{ ...n, components: r.components }] : [];
122
+ }) }] : [];
123
+ });
47
124
  }
48
- // ============================================================
49
- // 渲染
50
- // ============================================================
51
- /**
52
- * 渲染所有组件分组
53
- * @param groups - 原始组件分组列表
54
- */
55
- renderGroups(e) {
56
- if (!this.rootEl) return;
57
- const t = this.rootEl.querySelector(".rulego-sidebar__groups");
58
- if (!t) return;
59
- t.replaceChildren();
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
- return;
65
- }
66
- for (const n of s) {
67
- const i = this.createGroupElement(n);
68
- t.appendChild(i);
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 u = this.isExpanded(e);
149
+ if (r.setAttribute("aria-expanded", String(u)), 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 p = document.createElement("span");
156
+ p.className = "rulego-sidebar__group-count", p.textContent = String(s);
157
+ const m = document.createElement("span");
158
+ return m.className = `rulego-sidebar__arrow${u ? " is-expanded" : ""}`, m.setAttribute("aria-hidden", "true"), m.textContent = "›", r.append(a, p, m), r.addEventListener("click", () => {
159
+ this.setExpansion(e, !this.isExpanded(e)), this.refresh();
160
+ }), r;
70
161
  }
71
- /**
72
- * 创建单个分组 DOM 元素
73
- * @param group - 组件分组定义
74
- * @returns 分组 HTMLElement
75
- */
76
- createGroupElement(e) {
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-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
- 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
- * 创建单个组件 DOM 元素 (可拖拽)
103
- * @param comp - 组件定义
104
- * @param groupColor - 分组颜色
105
- * @returns 组件 HTMLElement
106
- */
107
- createComponentElement(e, t) {
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
- 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 u = o.key === "Home" ? 0 : o.key === "End" ? n.length - 1 : o.key === "ArrowDown" ? r + 1 : o.key === "ArrowUp" ? r - 1 : -1;
186
+ if (!n[u]) {
187
+ ["ArrowDown", "ArrowUp", "Home", "End"].includes(o.key) && (o.preventDefault(), o.stopPropagation());
188
+ return;
189
+ }
190
+ o.preventDefault(), o.stopPropagation(), n[u].focus();
191
+ }), i;
125
192
  }
126
- // ============================================================
127
- // 搜索过滤
128
- // ============================================================
129
- /**
130
- * 根据搜索关键字过滤组件分组
131
- * @param groups - 原始分组列表
132
- * @returns 过滤后的分组列表 (空分组会被移除)
133
- */
134
- filterGroups(e) {
135
- return this.searchKeyword ? e.map((t) => ({
136
- ...t,
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
- })
141
- })).filter((t) => t.components.length > 0) : e;
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 u = document.createElement("span");
202
+ u.className = "rulego-sidebar__component-icon", u.setAttribute("aria-hidden", "true");
203
+ const a = document.createElement("img"), p = 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") !== p && (a.src = p);
206
+ }), u.append(a);
207
+ const m = document.createElement("span");
208
+ m.className = "rulego-sidebar__component-name", m.textContent = i, s.append(u, m);
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, g;
219
+ h.key !== "Enter" && h.key !== " " || (h.preventDefault(), h.stopPropagation(), !h.repeat && !h.isComposing && ((g = (d = this.options).onDragStart) == null || g.call(d, e)));
220
+ }), s.addEventListener("dragstart", (h) => {
221
+ var g, l, b, E;
222
+ const d = JSON.stringify(e);
223
+ (g = h.dataTransfer) == null || g.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
- const e = this.core.store.getState().componentGroups;
151
- this.renderGroups(e);
227
+ var h, d, g;
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(), u = this.visibleKeys().some((l) => this.isExpanded(l));
246
+ this.toggleButton && (this.toggleButton.disabled = !this.displayGroups.length, this.toggleButton.title = this.text(u ? "editor.sidebar.collapseAll" : "editor.sidebar.expandAll"), this.toggleButton.setAttribute("aria-label", this.toggleButton.title), this.toggleButton.setAttribute("aria-pressed", u && !r ? "mixed" : String(r)), this.toggleButton.replaceChildren(this.icon(u ? "collapse-all" : "expand-all")));
247
+ const a = document.activeElement, p = a && this.groupsEl.contains(a) ? a.dataset.sidebarFocus : void 0, m = 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
+ p && ((g = [...this.groupsEl.querySelectorAll("[data-sidebar-focus]")].find((b) => b.dataset.sidebarFocus === p) || this.searchInput || ((d = this.toggleButton) != null && d.isConnected ? this.toggleButton : this.rootEl)) == null || g.focus({ preventScroll: !0 })), this.groupsEl.scrollTop = m;
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.collapsedGroups.clear(), this.refresh();
266
+ this.visibleKeys().forEach((e) => this.setExpansion(e, !0)), this.refresh();
158
267
  }
159
- /**
160
- * 折叠所有分组
161
- */
162
268
  collapseAll() {
163
- const e = this.core.store.getState().componentGroups;
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
- text(e, t) {
175
- return g(this.core.i18n, e, t);
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 f(h, e) {
279
+ function C(c, e) {
182
280
  if (e) {
183
281
  if (typeof e == "string") {
184
- h.textContent = e;
282
+ c.textContent = e;
185
283
  return;
186
284
  }
187
285
  if (e.kind === "text") {
188
- h.textContent = e.value;
286
+ c.textContent = e.value;
189
287
  return;
190
288
  }
191
- e.kind === "trusted-svg" && B(h, e.svg);
289
+ e.kind === "trusted-svg" && X(c, e.svg);
192
290
  }
193
291
  }
194
- function B(h, e) {
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
- h.textContent = "";
297
+ c.textContent = "";
200
298
  return;
201
299
  }
202
- C(s), h.replaceChildren(s);
300
+ L(s), c.replaceChildren(s);
203
301
  }
204
- function C(h) {
205
- for (const e of Array.from(h.attributes)) {
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")) && h.removeAttribute(e.name);
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(h.children)) {
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
- C(e);
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 n = document.createElement("span");
253
- n.className = "rulego-toolbar__divider", this.rootEl.appendChild(n);
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, 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);
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", (n) => {
262
- n.preventDefault(), n.stopPropagation(), t.onClick();
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 = v(e);
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((n) => n.id === e);
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 g(this.core.i18n, e, t);
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, f(t, e.icon), t.addEventListener("click", (s) => {
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 P {
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, n = t.currentNodeModel;
426
- s && n && Object.keys(n).length > 0 && this.showPanel(s, n);
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 n = this.createFieldElement(s, t);
454
- this.formContainer.appendChild(n);
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 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;
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
- i = this.createBoolField(e, t);
597
+ o = this.createBoolField(e, t);
500
598
  break;
501
599
  case "select":
502
- i = this.createSelectField(e, t);
600
+ o = this.createSelectField(e, t);
503
601
  break;
504
602
  case "code":
505
603
  case "json":
506
- i = this.createTextareaField(e, t);
604
+ o = this.createTextareaField(e, t);
507
605
  break;
508
606
  case "int":
509
- i = this.createNumberField(e, t);
607
+ o = this.createNumberField(e, t);
510
608
  break;
511
609
  default:
512
- i = this.createTextField(e, t);
610
+ o = this.createTextField(e, t);
513
611
  break;
514
612
  }
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);
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 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;
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 n = String(this.getModelValue(e, t) ?? "");
656
+ const i = String(this.getModelValue(e, t) ?? "");
559
657
  if (e.options && e.options.length > 0)
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);
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 g(this.core.i18n, e, t);
731
+ return y(this.core.i18n, e, t);
634
732
  }
635
733
  }
636
- class V {
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
- this.menuEl = document.createElement("div"), this.menuEl.className = "rulego-context-menu", this.menuEl.style.display = "none", document.body.appendChild(this.menuEl);
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
- 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;
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 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");
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 (n.length === 0) {
782
+ if (i.length === 0) {
683
783
  this.hide();
684
784
  return;
685
785
  }
686
- this.renderMenu(n, e.clientX, e.clientY);
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 n = e.closest(".lf-edge");
700
- return n ? {
799
+ const i = e.closest(".lf-edge");
800
+ return i ? {
701
801
  type: "edge",
702
- id: n.getAttribute("data-edge-id") || void 0,
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,38 @@ class V {
715
815
  renderMenu(e, t, s) {
716
816
  if (!this.menuEl) return;
717
817
  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) {
723
- const a = document.createElement("span");
724
- a.className = "rulego-context-menu__icon", f(a, o.icon), l.appendChild(a);
818
+ for (const n of e) {
819
+ const r = document.createElement("div");
820
+ r.className = "rulego-context-menu__item";
821
+ const u = typeof n.disabled == "function" ? n.disabled() : n.disabled;
822
+ if (u && r.classList.add("rulego-context-menu__item--disabled"), n.icon) {
823
+ const m = document.createElement("span");
824
+ m.className = "rulego-context-menu__icon", C(m, n.icon), r.appendChild(m);
725
825
  }
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);
826
+ const a = document.createElement("span");
827
+ a.className = "rulego-context-menu__check", a.textContent = n.check ? "✓" : "", r.appendChild(a);
828
+ const p = document.createElement("span");
829
+ if (p.className = "rulego-context-menu__label", p.textContent = n.label, r.appendChild(p), u || r.addEventListener("click", () => {
830
+ this.currentContext && n.onClick(this.currentContext), this.hide();
831
+ }), this.menuEl.appendChild(r), n.separator) {
832
+ const m = document.createElement("div");
833
+ m.className = "rulego-context-menu__separator", this.menuEl.appendChild(m);
732
834
  }
733
835
  }
734
836
  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(
837
+ let i = !1;
838
+ const o = requestAnimationFrame(() => {
839
+ i = !0, this.positionFrame = null;
840
+ const n = this.menuEl;
841
+ if (!n) return;
842
+ const r = n.getBoundingClientRect(), u = $(
741
843
  { left: t, top: s },
742
- { width: l.width, height: l.height },
844
+ { width: r.width, height: r.height },
743
845
  { width: window.innerWidth, height: window.innerHeight }
744
846
  );
745
- o.style.left = `${d.left}px`, o.style.top = `${d.top}px`, o.style.visibility = "visible";
847
+ n.style.left = `${u.left}px`, n.style.top = `${u.top}px`, n.style.visibility = "visible";
746
848
  });
747
- this.positionFrame = n ? null : i;
849
+ this.positionFrame = i ? null : o;
748
850
  }
749
851
  /**
750
852
  * 隐藏菜单
@@ -817,10 +919,10 @@ class V {
817
919
  this.items.push(e);
818
920
  }
819
921
  text(e, t) {
820
- return g(this.core.i18n, e, t);
922
+ return y(this.core.i18n, e, t);
821
923
  }
822
924
  toolbarIcon(e) {
823
- const t = v(e);
925
+ const t = _(e);
824
926
  return t ? { kind: "trusted-svg", svg: t } : e;
825
927
  }
826
928
  /**
@@ -837,7 +939,7 @@ class V {
837
939
  return this.menuEl;
838
940
  }
839
941
  }
840
- class D {
942
+ class oe {
841
943
  constructor(e, t) {
842
944
  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
945
  }
@@ -853,8 +955,8 @@ class D {
853
955
  t.className = "rulego-debug-console__title", t.textContent = this.t("editor.debugConsole.title", "调试控制台");
854
956
  const s = document.createElement("button");
855
957
  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());
958
+ const i = document.createElement("div");
959
+ 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
960
  }
859
961
  bindEvents() {
860
962
  this.unsubscribe = this.core.eventBus.on("debug:log", (e) => {
@@ -865,7 +967,7 @@ class D {
865
967
  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
968
  const t = document.createElement("div");
867
969
  t.className = "rulego-debug-console__item";
868
- const s = typeof e == "string" ? e : k(N(e), { maxChars: 2e4, space: 0 });
970
+ const s = typeof e == "string" ? e : R(V(e), { maxChars: 2e4, space: 0 });
869
971
  t.textContent = `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${s}`, this.listEl.appendChild(t), this.listEl.scrollTop = this.listEl.scrollHeight;
870
972
  }
871
973
  clear() {
@@ -876,20 +978,20 @@ class D {
876
978
  (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
979
  }
878
980
  }
879
- const F = 28;
880
- function y(h, e, t = 0) {
981
+ const Z = 28;
982
+ function M(c, e, t = 0) {
881
983
  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));
984
+ return c.forEach((i) => {
985
+ var o;
986
+ 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
987
  }), s;
886
988
  }
887
- function H(h, e = "") {
888
- e.split(/\s+/).filter(Boolean).forEach((t) => h.classList.add(t));
989
+ function Q(c, e = "") {
990
+ e.split(/\s+/).filter(Boolean).forEach((t) => c.classList.add(t));
889
991
  }
890
- class W {
992
+ class re {
891
993
  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({
994
+ 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
995
  workflows: t.workflows,
894
996
  activeChainId: t.activeChainId,
895
997
  keyword: t.keyword,
@@ -917,7 +1019,7 @@ class W {
917
1019
  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
1020
  }
919
1021
  mount() {
920
- this.rootEl = document.createElement("section"), this.rootEl.className = "huanban_workflow_explorer", H(this.rootEl, this.options.className), this.rootEl.setAttribute("aria-label", "规则链资源");
1022
+ this.rootEl = document.createElement("section"), this.rootEl.className = "huanban_workflow_explorer", Q(this.rootEl, this.options.className), this.rootEl.setAttribute("aria-label", "规则链资源");
921
1023
  const e = document.createElement("div");
922
1024
  e.className = "huanban_workflow_explorer__search";
923
1025
  const t = document.createElement("span");
@@ -933,71 +1035,71 @@ class W {
933
1035
  renderState(e) {
934
1036
  if (this.destroyed || !this.treeEl) return;
935
1037
  this.searchInputEl && this.searchInputEl.value !== e.keyword && (this.searchInputEl.value = e.keyword);
936
- const t = y(e.tree, new Set(e.expandedKeys));
1038
+ const t = M(e.tree, new Set(e.expandedKeys));
937
1039
  if (t.length === 0) {
938
1040
  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);
1041
+ const d = document.createElement("div");
1042
+ d.className = "huanban_workflow_explorer__empty", d.textContent = this.options.emptyText || "暂无规则链", this.treeEl.replaceChildren(d);
941
1043
  return;
942
1044
  }
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;
1045
+ 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), u = Math.max(0, (s == null ? void 0 : s.overscan) ?? z), a = i && t.length > o;
1046
+ 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) {
1047
+ const d = t.findIndex((g) => {
1048
+ var l;
1049
+ return g.node.kind === "chain" && ((l = g.node.chain) == null ? void 0 : l.id) === e.activeChainId;
948
1050
  });
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;
1051
+ if (d >= 0) {
1052
+ const g = Math.floor(this.virtualScrollTop / n), l = Math.ceil((this.virtualScrollTop + r) / n);
1053
+ d < g ? this.virtualScrollTop = d * n : d >= l && (this.virtualScrollTop = (d + 1) * n - r), this.autoScrolledActiveChainId = e.activeChainId;
952
1054
  }
953
1055
  }
954
- const a = T({
1056
+ const p = U({
955
1057
  total: t.length,
956
- itemHeight: o,
957
- viewportHeight: l,
1058
+ itemHeight: n,
1059
+ viewportHeight: r,
958
1060
  scrollTop: this.virtualScrollTop,
959
- overscan: d
1061
+ overscan: u
960
1062
  });
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);
1063
+ this.treeEl.classList.toggle("is-virtualized", a), a ? (this.treeEl.dataset.explorerVirtualized = "true", this.treeEl.dataset.explorerVirtualTotal = String(t.length), this.treeEl.style.height = `${p.viewportHeight}px`) : (this.treeEl.removeAttribute("data-explorer-virtualized"), this.treeEl.removeAttribute("data-explorer-virtual-total"), this.treeEl.style.removeProperty("height"));
1064
+ const m = a ? t.slice(p.start, p.end) : t, h = document.createDocumentFragment();
1065
+ if (a) {
1066
+ const d = document.createElement("div");
1067
+ d.className = "huanban_workflow_explorer__virtual-canvas", d.style.height = `${p.totalHeight}px`;
1068
+ const g = document.createElement("div");
1069
+ g.className = "huanban_workflow_explorer__virtual-items", g.style.transform = `translateY(${p.offsetTop}px)`, m.forEach(({ node: l, depth: b }, E) => g.appendChild(this.createRow(l, b, e, p.start + E, t.length))), d.appendChild(g), h.appendChild(d), this.treeEl.scrollTop !== p.scrollTop && (this.treeEl.scrollTop = p.scrollTop);
968
1070
  } else
969
- E.forEach(({ node: u, depth: p }, c) => m.appendChild(this.createRow(u, p, e, c, t.length)));
970
- this.treeEl.replaceChildren(m);
1071
+ m.forEach(({ node: d, depth: g }, l) => h.appendChild(this.createRow(d, g, e, l, t.length)));
1072
+ this.treeEl.replaceChildren(h);
971
1073
  }
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}
1074
+ createRow(e, t, s, i, o) {
1075
+ var d, g;
1076
+ const n = !!((d = e.children) != null && d.length), r = s.expandedKeys.includes(e.key), u = e.kind === "chain" && ((g = e.chain) == null ? void 0 : g.id) === s.activeChainId, a = document.createElement("button");
1077
+ a.type = "button", a.className = `huanban_workflow_explorer__row is-${e.kind}${u ? " 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(u)), a.title = e.chain ? `${e.chain.name}
976
1078
  ${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");
1079
+ const p = document.createElement("span");
1080
+ p.className = `huanban_workflow_explorer__chevron${n && r ? " is-open" : ""}`, p.setAttribute("aria-hidden", "true");
981
1081
  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);
1082
+ m.className = `huanban_workflow_explorer__kind is-${e.kind}`, m.setAttribute("aria-hidden", "true");
1083
+ const h = document.createElement("span");
1084
+ if (h.className = "huanban_workflow_explorer__label", h.textContent = e.label, a.append(p, m, h), e.kind === "chain" && e.chain) {
1085
+ const l = document.createElement("span");
1086
+ 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
1087
  }
986
1088
  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);
1089
+ const l = document.createElement("span");
1090
+ l.className = "huanban_workflow_explorer__count", l.textContent = String(e.count), a.appendChild(l);
989
1091
  }
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;
1092
+ return a.addEventListener("click", () => {
1093
+ var l, b;
1094
+ n ? this.store.setExpanded(e.key, !r) : e.chain && ((b = (l = this.options).onOpen) == null || b.call(l, e.chain));
1095
+ }), a;
994
1096
  }
995
1097
  }
996
1098
  export {
997
- V as ContextMenu,
998
- D as DebugConsole,
999
- P as PropertyPanel,
1000
- G as Sidebar,
1001
- $ as Toolbar,
1002
- W as WorkflowExplorer
1099
+ ne as ContextMenu,
1100
+ oe as DebugConsole,
1101
+ ie as PropertyPanel,
1102
+ te as Sidebar,
1103
+ se as Toolbar,
1104
+ re as WorkflowExplorer
1003
1105
  };