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