@huanban/rulego-editor-ui 1.4.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,7 @@ export declare class ContextMenu {
36
36
  private contextMenuHandler;
37
37
  private escapeKeyHandler;
38
38
  private positionFrame;
39
+ private releaseTheme;
39
40
  private options;
40
41
  constructor(container: HTMLElement, options: ContextMenuOptions);
41
42
  private mount;
@@ -1,30 +1,57 @@
1
- import type { EditorCore } from '@huanban/rulego-editor-core';
1
+ import { type ComponentDefinition, type EditorCore } from '@huanban/rulego-editor-core';
2
2
  export interface SidebarOptions {
3
3
  core: EditorCore;
4
4
  searchable?: boolean;
5
5
  defaultCollapsed?: boolean;
6
6
  searchPlaceholder?: string;
7
+ search?: string;
8
+ onSearchChange?: (search: string) => void;
9
+ recentComponentTypes?: string[];
10
+ showRecent?: boolean;
11
+ showNodeMgt?: boolean;
12
+ onOpenNodeMgt?: () => void;
13
+ onDragStart?: (component: ComponentDefinition) => void;
14
+ theme?: string;
7
15
  width?: string;
8
16
  }
9
17
  export declare class Sidebar {
10
- private container;
11
- private core;
12
- private options;
13
- private collapsedGroups;
14
- private searchKeyword;
18
+ private readonly id;
19
+ private readonly core;
20
+ private readonly options;
15
21
  private rootEl;
16
- private unsubscribe;
22
+ private groupsEl;
23
+ private searchInput;
24
+ private clearButton;
25
+ private toggleButton;
26
+ private managerButton;
27
+ private readonly unsubscribe;
28
+ private readonly expanded;
29
+ private readonly searchExpanded;
30
+ private searchKeyword;
31
+ private displayGroups;
32
+ private iconTheme;
17
33
  constructor(container: HTMLElement, options: SidebarOptions);
34
+ private get query();
35
+ private text;
36
+ private icon;
18
37
  private mount;
19
- destroy(): void;
20
- private renderGroups;
21
- private createGroupElement;
22
- private createComponentElement;
38
+ private buildGroups;
23
39
  private filterGroups;
40
+ private hasSubgroups;
41
+ private visibleKeys;
42
+ private isExpanded;
43
+ private allExpanded;
44
+ private setExpansion;
45
+ private createHeader;
46
+ private panelId;
47
+ private createGroup;
48
+ private createList;
49
+ private createComponent;
24
50
  refresh(): void;
51
+ setSearch(search: string): void;
52
+ setRecentComponentTypes(types: string[]): void;
25
53
  expandAll(): void;
26
54
  collapseAll(): void;
27
55
  getElement(): HTMLElement | null;
28
- private text;
29
- private componentLabel;
56
+ destroy(): void;
30
57
  }
package/dist/index.cjs CHANGED
@@ -1,2 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@huanban/rulego-editor-core");class _{constructor(e,t){this.collapsedGroups=new Set,this.searchKeyword="",this.rootEl=null,this.unsubscribe=null,this.container=e,this.core=t.core,this.options={core:t.core,searchable:t.searchable??!0,defaultCollapsed:t.defaultCollapsed??!1,searchPlaceholder:t.searchPlaceholder||this.text("sidebar.searchPlaceholder","搜索组件..."),width:t.width??"220px"},this.mount(),this.unsubscribe=this.core.store.select(s=>s.componentGroups).subscribe(s=>{this.renderGroups(s)})}mount(){if(this.rootEl=document.createElement("div"),this.rootEl.className="rulego-sidebar",this.rootEl.style.width=this.options.width,this.options.searchable){const s=document.createElement("div");s.className="rulego-sidebar__search-wrapper";const o=document.createElement("span");o.className="rulego-sidebar__search-icon",o.setAttribute("aria-hidden","true"),o.innerHTML=p.getEditorToolbarIconSvg("search")||"";const i=document.createElement("input");i.type="text",i.className="rulego-sidebar__search",i.placeholder=this.options.searchPlaceholder,i.addEventListener("input",n=>{this.searchKeyword=n.target.value.toLowerCase();const l=this.core.store.getState().componentGroups;this.renderGroups(l)}),s.appendChild(o),s.appendChild(i),this.rootEl.appendChild(s)}const e=document.createElement("div");e.className="rulego-sidebar__groups",this.rootEl.appendChild(e),this.container.appendChild(this.rootEl);const t=this.core.store.getState().componentGroups;t&&t.length>0&&this.renderGroups(t)}destroy(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.rootEl&&this.rootEl.parentNode&&this.rootEl.parentNode.removeChild(this.rootEl),this.rootEl=null}renderGroups(e){if(!this.rootEl)return;const t=this.rootEl.querySelector(".rulego-sidebar__groups");if(!t)return;t.replaceChildren();const s=this.filterGroups(e);if(s.length===0){const o=document.createElement("div");o.className="rulego-sidebar__empty",o.textContent=this.text("sidebar.noResults","无匹配组件"),t.appendChild(o);return}for(const o of s){const i=this.createGroupElement(o);t.appendChild(i)}}createGroupElement(e){const t=document.createElement("div");t.className="rulego-sidebar__group";const s=document.createElement("div");s.className="rulego-sidebar__group-header",s.style.borderLeftColor=e.color||"#ccc";const o=this.collapsedGroups.has(e.category),i=document.createElement("span");i.className=`rulego-sidebar__arrow ${o?"rulego-sidebar__arrow--collapsed":""}`,i.textContent="▼";const n=document.createElement("span");n.className="rulego-sidebar__group-label",n.textContent=this.text(`category.${e.category}`,e.label||e.category);const l=document.createElement("span");if(l.className="rulego-sidebar__group-count",l.textContent=`${e.components.length}`,s.appendChild(i),s.appendChild(n),s.appendChild(l),s.addEventListener("click",()=>{this.collapsedGroups.has(e.category)?this.collapsedGroups.delete(e.category):this.collapsedGroups.add(e.category);const d=this.core.store.getState().componentGroups;this.renderGroups(d)}),t.appendChild(s),!o){const d=document.createElement("div");d.className="rulego-sidebar__component-list";for(const r of e.components){const a=this.createComponentElement(r,e.color);d.appendChild(a)}t.appendChild(d)}return t}createComponentElement(e,t){const s=document.createElement("div");s.className="rulego-sidebar__component",s.setAttribute("draggable","true");const o=this.componentLabel(e),i=this.text(`fields.${e.type}`,e.desc||o);s.title=i||o;const n=document.createElement("span");n.className="rulego-sidebar__component-color",n.style.backgroundColor=e.color||t||"#ccc";const l=document.createElement("span");return l.className="rulego-sidebar__component-name",l.textContent=o,s.appendChild(n),s.appendChild(l),s.addEventListener("dragstart",d=>{d.dataTransfer&&(d.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:o,color:e.color||t})),d.dataTransfer.effectAllowed="copy"),s.classList.add("rulego-sidebar__component--dragging")}),s.addEventListener("dragend",()=>{s.classList.remove("rulego-sidebar__component--dragging")}),s}filterGroups(e){return this.searchKeyword?e.map(t=>({...t,components:t.components.filter(s=>{const o=this.componentLabel(s).toLowerCase(),i=this.text(`fields.${s.type}`,s.desc||"").toLowerCase();return o.includes(this.searchKeyword)||s.type.toLowerCase().includes(this.searchKeyword)||i.includes(this.searchKeyword)})})).filter(t=>t.components.length>0):e}refresh(){const e=this.core.store.getState().componentGroups;this.renderGroups(e)}expandAll(){this.collapsedGroups.clear(),this.refresh()}collapseAll(){const e=this.core.store.getState().componentGroups;for(const t of e)this.collapsedGroups.add(t.category);this.refresh()}getElement(){return this.rootEl}text(e,t){return p.i18nText(this.core.i18n,e,t)}componentLabel(e){return this.text(`components.${e.type}`,e.label||e.type.split("/").pop()||e.type)}}function f(h,e){if(e){if(typeof e=="string"){h.textContent=e;return}if(e.kind==="text"){h.textContent=e.value;return}e.kind==="trusted-svg"&&x(h,e.svg)}}function x(h,e){const t=document.createElement("template");t.innerHTML=e;const s=t.content.firstElementChild;if(!s||s.tagName.toLowerCase()!=="svg"){h.textContent="";return}v(s),h.replaceChildren(s)}function v(h){for(const e of Array.from(h.attributes)){const t=e.name.toLowerCase(),s=e.value.trim().toLowerCase();(t.startsWith("on")||s.startsWith("javascript:")||s.startsWith("data:text/html"))&&h.removeAttribute(e.name)}for(const e of Array.from(h.children)){const t=e.tagName.toLowerCase();if(t==="script"||t==="foreignobject"){e.remove();continue}v(e)}}class w{constructor(e,t){this.rootEl=null,this.unsubscribe=null,this.buttonElements=new Map,this.container=e,this.core=t.core,this.options={core:t.core,extraButtons:t.extraButtons??[],showZoom:t.showZoom??!0,height:t.height??"40px",onSave:t.onSave,onDelete:t.onDelete,onFullscreen:t.onFullscreen,onAutoLayout:t.onAutoLayout},this.mount(),this.unsubscribe=this.core.store.subscribe(()=>{this.updateButtonStates()})}mount(){this.rootEl=document.createElement("div"),this.rootEl.className="rulego-toolbar",this.rootEl.style.height=this.options.height;const e=this.getBuiltinButtons();this.options.extraButtons.length>0&&(e.push({id:"__divider_extra",icon:"",title:"",divider:!0,onClick:()=>{}}),e.push(...this.options.extraButtons));for(const t of e){if(t.divider){const o=document.createElement("span");o.className="rulego-toolbar__divider",this.rootEl.appendChild(o)}if(!t.icon&&t.divider)continue;const s=document.createElement("button");if(s.className="rulego-toolbar__button",s.title=t.title,f(s,t.icon),t.label){const o=document.createElement("span");o.className="rulego-toolbar__button-label",o.textContent=t.label,s.appendChild(o)}s.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),t.onClick()}),this.buttonElements.set(t.id,s),this.rootEl.appendChild(s)}this.container.appendChild(this.rootEl),this.updateButtonStates()}destroy(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.rootEl&&this.rootEl.parentNode&&this.rootEl.parentNode.removeChild(this.rootEl),this.rootEl=null,this.buttonElements.clear()}getBuiltinButtons(){const e=[{id:"undo",icon:this.toolbarIcon("undo"),title:this.text("toolbar.undo","撤销"),disabled:()=>!this.core.store.getState().canUndo,onClick:()=>{this.core.history.undo()}},{id:"redo",icon:this.toolbarIcon("redo"),title:this.text("toolbar.redo","重做"),disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{this.core.history.redo()}},{id:"delete",icon:this.toolbarIcon("delete"),title:this.text("toolbar.delete","删除选中"),divider:!0,onClick:()=>{this.options.onDelete?this.options.onDelete():this.core.eventBus.emit("editor:delete-selected")}},{id:"save",icon:this.toolbarIcon("save"),title:this.options.onSave?this.text("toolbar.save","保存"):this.text("toolbar.saveHostRequired","请先配置宿主保存回调"),disabled:()=>!this.options.onSave,onClick:()=>{var t,s;(s=(t=this.options).onSave)==null||s.call(t)}},{id:"fullscreen",icon:this.toolbarIcon("fullscreen"),title:this.text("toolbar.fullscreen","全屏"),onClick:()=>{this.options.onFullscreen?this.options.onFullscreen():this.core.eventBus.emit("editor:fullscreen")}}];return this.options.showZoom&&e.push({id:"zoom-in",icon:this.toolbarIcon("zoom-in"),title:this.text("toolbar.zoomIn","放大"),divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:this.toolbarIcon("zoom-out"),title:this.text("toolbar.zoomOut","缩小"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:this.toolbarIcon("fit"),title:this.text("toolbar.fitView","适应画布"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),e.push({id:"auto-layout",icon:this.toolbarIcon("auto-layout"),title:this.text("toolbar.autoLayout","自动排版"),divider:!0,onClick:()=>{this.options.onAutoLayout?this.options.onAutoLayout():this.core.eventBus.emit("editor:auto-layout")}}),e}toolbarIcon(e){const t=p.getEditorToolbarIconSvg(e);return t?{kind:"trusted-svg",svg:t}:e}updateButtonStates(){for(const[e,t]of this.buttonElements){const s=this.getBuiltinButtons().find(o=>o.id===e);s&&typeof s.disabled=="function"&&(t.disabled=s.disabled(),t.classList.toggle("rulego-toolbar__button--disabled",t.disabled))}}getElement(){return this.rootEl}text(e,t){return p.i18nText(this.core.i18n,e,t)}addButton(e){if(!this.rootEl)return;const t=document.createElement("button");t.className="rulego-toolbar__button",t.title=e.title,f(t,e.icon),t.addEventListener("click",s=>{s.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class k{constructor(e,t){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={core:t.core,title:t.title||this.text("panel.title","属性编辑"),width:t.width??"320px",position:t.position??"right"},this.mount(),this.bindEvents()}mount(){this.rootEl=document.createElement("div"),this.rootEl.className=`rulego-property-panel rulego-property-panel--${this.options.position}`,this.rootEl.style.width=this.options.width;const e=document.createElement("div");e.className="rulego-property-panel__header",this.titleEl=document.createElement("h3"),this.titleEl.className="rulego-property-panel__title",this.titleEl.textContent=this.options.title;const t=document.createElement("button");t.className="rulego-property-panel__close",t.textContent="✕",t.addEventListener("click",()=>this.clearPanel()),e.appendChild(this.titleEl),e.appendChild(t),this.rootEl.appendChild(e),this.formContainer=document.createElement("div"),this.formContainer.className="rulego-property-panel__form",this.rootEl.appendChild(this.formContainer),this.rootEl.style.display="none",this.container.appendChild(this.rootEl)}bindEvents(){this.unsubscribe=this.core.store.subscribe(t=>{const s=t.currentNodeView,o=t.currentNodeModel;s&&o&&Object.keys(o).length>0&&this.showPanel(s,o)});const e=this.core.eventBus.on("blank:click",()=>{this.clearPanel()});this.eventCleanups.push(e)}destroy(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null);for(const e of this.eventCleanups)e();this.eventCleanups=[],this.rootEl&&this.rootEl.parentNode&&this.rootEl.parentNode.removeChild(this.rootEl),this.rootEl=null,this.formContainer=null}showPanel(e,t){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))for(const s of e.fields){const o=this.createFieldElement(s,t);this.formContainer.appendChild(o)}}clearPanel(){!this.rootEl||!this.formContainer||(this.formContainer.replaceChildren(),this.rootEl.style.display="none",this.currentNodeId=null)}renderBasicInfo(e){if(!this.formContainer)return;const t=document.createElement("div");t.className="rulego-property-panel__section";const s=this.createTextField({name:"name",type:"string",defaultValue:"",label:this.text("panel.nodeName","节点名称"),desc:"",validate:"",fields:null},e);t.appendChild(s),this.formContainer.appendChild(t)}createFieldElement(e,t){const s=document.createElement("div");s.className="rulego-property-panel__field";const o=document.createElement("label");o.className="rulego-property-panel__label",o.textContent=e.label||e.name,e.desc&&(o.title=e.desc),s.appendChild(o);let i;switch(e.type){case"bool":i=this.createBoolField(e,t);break;case"select":i=this.createSelectField(e,t);break;case"code":case"json":i=this.createTextareaField(e,t);break;case"int":i=this.createNumberField(e,t);break;default:i=this.createTextField(e,t);break}if(s.appendChild(i),e.desc){const n=document.createElement("span");n.className="rulego-property-panel__desc",n.textContent=e.desc,s.appendChild(n)}return s}createTextField(e,t){const s=document.createElement("input");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",()=>{this.handleFieldChange(e.name,s.value)}),s}createNumberField(e,t){const s=document.createElement("input");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",()=>{this.handleFieldChange(e.name,Number(s.value))}),s}createBoolField(e,t){const s=document.createElement("div");s.className="rulego-property-panel__switch-wrapper";const o=`field-${e.name}-${Date.now()}`,i=document.createElement("input");i.type="checkbox",i.className="rulego-property-panel__checkbox",i.id=o,i.checked=!!this.getModelValue(e,t);const n=document.createElement("label");return n.className="rulego-property-panel__switch",n.htmlFor=o,i.addEventListener("change",()=>{this.handleFieldChange(e.name,i.checked)}),s.appendChild(i),s.appendChild(n),s}createSelectField(e,t){const s=document.createElement("select");s.className="rulego-property-panel__select",s.name=e.name;const o=String(this.getModelValue(e,t)??"");if(e.options&&e.options.length>0)for(const i of e.options.filter(p.isComponentFieldOption)){const n=document.createElement("option"),l=String(i.value??"");n.value=l,n.textContent=i.label,l===o&&(n.selected=!0),s.appendChild(n)}return s.addEventListener("change",()=>{this.handleFieldChange(e.name,s.value)}),s}createTextareaField(e,t){const s=document.createElement("textarea");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",()=>{this.handleFieldChange(e.name,s.value)}),s}getModelValue(e,t){const s=t.configuration;return s&&e.name in s?s[e.name]:e.name in t?t[e.name]:e.defaultValue}handleFieldChange(e,t){this.core.eventBus.emit("node:property-update",{id:this.currentNodeId||"",properties:{[e]:t}}),this.core.store.setState({isDirty:!0})}getElement(){return this.rootEl}setCurrentNodeId(e){this.currentNodeId=e}show(e,t,s){s&&(this.currentNodeId=s),this.showPanel(e,t)}hide(){this.clearPanel()}text(e,t){return p.i18nText(this.core.i18n,e,t)}}class N{constructor(e,t){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;const s=t.includeBuiltin!==!1?this.getBuiltinItems():[];this.items=[...s,...t.items??[]],this.mount(),this.bindEvents()}mount(){this.menuEl=document.createElement("div"),this.menuEl.className="rulego-context-menu",this.menuEl.style.display="none",document.body.appendChild(this.menuEl)}bindEvents(){this.contextMenuHandler=e=>{e.preventDefault(),this.handleContextMenu(e)},this.container.addEventListener("contextmenu",this.contextMenuHandler),this.outsideClickHandler=e=>{this.menuEl&&!this.menuEl.contains(e.target)&&this.hide()},document.addEventListener("click",this.outsideClickHandler),this.escapeKeyHandler=e=>{e.key==="Escape"&&this.hide()},document.addEventListener("keydown",this.escapeKeyHandler)}destroy(){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}handleContextMenu(e){const t=e.target,s=this.resolveContext(t,e);this.currentContext=s;const o=this.items.filter(i=>{const n=Array.isArray(i.target)?i.target:[i.target];return n.includes(s.type)||n.includes("all")});if(o.length===0){this.hide();return}this.renderMenu(o,e.clientX,e.clientY)}resolveContext(e,t){const s=e.closest(".lf-node");if(s)return{type:"node",id:s.getAttribute("data-node-id")||void 0,position:{x:t.clientX,y:t.clientY}};const o=e.closest(".lf-edge");return o?{type:"edge",id:o.getAttribute("data-edge-id")||void 0,position:{x:t.clientX,y:t.clientY}}:{type:"canvas",position:{x:t.clientX,y:t.clientY}}}renderMenu(e,t,s){if(!this.menuEl)return;this.cancelPendingPosition(),this.menuEl.replaceChildren();for(const n of e){const l=document.createElement("div");l.className="rulego-context-menu__item";const d=typeof n.disabled=="function"?n.disabled():n.disabled;if(d&&l.classList.add("rulego-context-menu__item--disabled"),n.icon){const a=document.createElement("span");a.className="rulego-context-menu__icon",f(a,n.icon),l.appendChild(a)}const r=document.createElement("span");if(r.className="rulego-context-menu__label",r.textContent=n.label,l.appendChild(r),d||l.addEventListener("click",()=>{this.currentContext&&n.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(l),n.separator){const a=document.createElement("div");a.className="rulego-context-menu__separator",this.menuEl.appendChild(a)}}this.menuEl.style.left=`${t}px`,this.menuEl.style.top=`${s}px`,this.menuEl.style.visibility="hidden",this.menuEl.style.display="block";let o=!1;const i=requestAnimationFrame(()=>{o=!0,this.positionFrame=null;const n=this.menuEl;if(!n)return;const l=n.getBoundingClientRect(),d=p.clampContextMenuPosition({left:t,top:s},{width:l.width,height:l.height},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${d.left}px`,n.style.top=`${d.top}px`,n.style.visibility="visible"});this.positionFrame=o?null:i}hide(){this.cancelPendingPosition(),this.menuEl&&(this.menuEl.style.display="none",this.menuEl.style.visibility=""),this.currentContext=null}cancelPendingPosition(){this.positionFrame!==null&&(cancelAnimationFrame(this.positionFrame),this.positionFrame=null)}getBuiltinItems(){return[{id:"edit",label:this.text("contextMenu.edit","编辑"),icon:this.toolbarIcon("edit"),target:"node",onClick:e=>{e.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:this.text("contextMenu.delete","删除"),icon:this.toolbarIcon("delete"),target:["node","edge"],separator:!0,onClick:e=>{e.id&&this.core.eventBus.emit(e.type==="edge"?"edge:delete":"node:delete",{id:e.id})}},{id:"copy",label:this.text("contextMenu.copy","复制"),icon:this.toolbarIcon("copy"),target:"node",disabled:()=>!this.options.onCopy,onClick:e=>{var t,s;(s=(t=this.options).onCopy)==null||s.call(t,e)}},{id:"select-all",label:this.text("contextMenu.selectAll","全选"),icon:this.toolbarIcon("select-all"),target:"canvas",disabled:()=>!this.options.onSelectAll,onClick:e=>{var t,s;(s=(t=this.options).onSelectAll)==null||s.call(t,e)}}]}addItem(e){this.items.push(e)}text(e,t){return p.i18nText(this.core.i18n,e,t)}toolbarIcon(e){const t=p.getEditorToolbarIconSvg(e);return t?{kind:"trusted-svg",svg:t}:e}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}class S{constructor(e,t){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()}t(e,t){const s=this.core.i18n.t(e);return s&&s!==e?s:t}mount(){this.consoleEl=document.createElement("div"),this.consoleEl.className="rulego-debug-console";const e=document.createElement("div");e.className="rulego-debug-console__header";const t=document.createElement("span");t.className="rulego-debug-console__title",t.textContent=this.t("editor.debugConsole.title","调试控制台");const s=document.createElement("button");s.className="rulego-debug-console__clear",s.textContent=this.t("editor.debugConsole.clear","清除"),e.append(t,s);const o=document.createElement("div");o.className="rulego-debug-console__list",this.consoleEl.append(e,o),this.listEl=o,this.container.appendChild(this.consoleEl),s.addEventListener("click",()=>this.clear())}bindEvents(){this.unsubscribe=this.core.eventBus.on("debug:log",e=>{this.appendLog(e)})}appendLog(e){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;const t=document.createElement("div");t.className="rulego-debug-console__item";const s=typeof e=="string"?e:p.formatJsonBounded(p.redactSensitive(e),{maxChars:2e4,space:0});t.textContent=`[${new Date().toLocaleTimeString()}] ${s}`,this.listEl.appendChild(t),this.listEl.scrollTop=this.listEl.scrollHeight}clear(){this.logs=[],this.listEl&&this.listEl.replaceChildren()}destroy(){var e;(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=[]}}const I=28;function C(h,e,t=0){const s=[];return h.forEach(o=>{var i;s.push({node:o,depth:t}),(i=o.children)!=null&&i.length&&e.has(o.key)&&s.push(...C(o.children,e,t+1))}),s}function L(h,e=""){e.split(/\s+/).filter(Boolean).forEach(t=>h.classList.add(t))}class T{constructor(e,t={}){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 p.ExplorerTreeStore({workflows:t.workflows,activeChainId:t.activeChainId,keyword:t.keyword,persistence:t.persistence}),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()}getState(){return this.store.getState()}getStore(){return this.store}setWorkflows(e){this.destroyed||this.store.setWorkflows(e)}setActiveChainId(e){this.destroyed||this.store.setActiveChainId(e)}setKeyword(e){var t,s;this.destroyed||(this.store.setKeyword(e),(s=(t=this.options).onKeywordChange)==null||s.call(t,String(e||"")))}destroy(){var e,t,s;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)}mount(){this.rootEl=document.createElement("section"),this.rootEl.className="huanban_workflow_explorer",L(this.rootEl,this.options.className),this.rootEl.setAttribute("aria-label","规则链资源");const e=document.createElement("div");e.className="huanban_workflow_explorer__search";const t=document.createElement("span");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",()=>{var s;this.setKeyword(((s=this.searchInputEl)==null?void 0:s.value)||"")}),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",()=>{if(!this.treeEl||this.destroyed)return;const s=this.treeEl.scrollTop;s!==this.virtualScrollTop&&(this.virtualScrollTop=s,this.renderState(this.store.getState()))}),this.rootEl.appendChild(this.treeEl),this.container.appendChild(this.rootEl),this.unsubscribe=this.store.subscribe(s=>this.renderState(s)),this.renderState(this.store.getState())}renderState(e){if(this.destroyed||!this.treeEl)return;this.searchInputEl&&this.searchInputEl.value!==e.keyword&&(this.searchInputEl.value=e.keyword);const t=C(e.tree,new Set(e.expandedKeys));if(t.length===0){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");const u=document.createElement("div");u.className="huanban_workflow_explorer__empty",u.textContent=this.options.emptyText||"暂无规则链",this.treeEl.replaceChildren(u);return}const s=this.options.virtualization,o=(s==null?void 0:s.enabled)!==!1,i=Math.max(1,(s==null?void 0:s.threshold)??p.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),n=Math.max(1,(s==null?void 0:s.itemHeight)??I),l=Math.max(1,(s==null?void 0:s.viewportHeight)??p.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),d=Math.max(0,(s==null?void 0:s.overscan)??p.DEFAULT_VIRTUAL_WINDOW_OVERSCAN),r=o&&t.length>i;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){const u=t.findIndex(m=>{var c;return m.node.kind==="chain"&&((c=m.node.chain)==null?void 0:c.id)===e.activeChainId});if(u>=0){const m=Math.floor(this.virtualScrollTop/n),c=Math.ceil((this.virtualScrollTop+l)/n);u<m?this.virtualScrollTop=u*n:u>=c&&(this.virtualScrollTop=(u+1)*n-l),this.autoScrolledActiveChainId=e.activeChainId}}const a=p.calculateVirtualWindow({total:t.length,itemHeight:n,viewportHeight:l,scrollTop:this.virtualScrollTop,overscan:d});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"));const b=r?t.slice(a.start,a.end):t,E=document.createDocumentFragment();if(r){const u=document.createElement("div");u.className="huanban_workflow_explorer__virtual-canvas",u.style.height=`${a.totalHeight}px`;const m=document.createElement("div");m.className="huanban_workflow_explorer__virtual-items",m.style.transform=`translateY(${a.offsetTop}px)`,b.forEach(({node:c,depth:g},y)=>m.appendChild(this.createRow(c,g,e,a.start+y,t.length))),u.appendChild(m),E.appendChild(u),this.treeEl.scrollTop!==a.scrollTop&&(this.treeEl.scrollTop=a.scrollTop)}else b.forEach(({node:u,depth:m},c)=>E.appendChild(this.createRow(u,m,e,c,t.length)));this.treeEl.replaceChildren(E)}createRow(e,t,s,o,i){var u,m;const n=!!((u=e.children)!=null&&u.length),l=s.expandedKeys.includes(e.key),d=e.kind==="chain"&&((m=e.chain)==null?void 0:m.id)===s.activeChainId,r=document.createElement("button");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(o+1)),r.setAttribute("aria-setsize",String(i)),n&&r.setAttribute("aria-expanded",String(l)),e.kind==="chain"&&r.setAttribute("aria-selected",String(d)),r.title=e.chain?`${e.chain.name}
2
- ${e.chain.id}`:e.label;const a=document.createElement("span");a.className=`huanban_workflow_explorer__chevron${n&&l?" is-open":""}`,a.setAttribute("aria-hidden","true");const b=document.createElement("span");b.className=`huanban_workflow_explorer__kind is-${e.kind}`,b.setAttribute("aria-hidden","true");const E=document.createElement("span");if(E.className="huanban_workflow_explorer__label",E.textContent=e.label,r.append(a,b,E),e.kind==="chain"&&e.chain){const c=document.createElement("span");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)}if(e.count!==void 0){const c=document.createElement("span");c.className="huanban_workflow_explorer__count",c.textContent=String(e.count),r.appendChild(c)}return r.addEventListener("click",()=>{var c,g;n?this.store.setExpanded(e.key,!l):e.chain&&((g=(c=this.options).onOpen)==null||g.call(c,e.chain))}),r}}exports.ContextMenu=N;exports.DebugConsole=S;exports.PropertyPanel=k;exports.Sidebar=_;exports.Toolbar=w;exports.WorkflowExplorer=T;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@huanban/rulego-editor-core"),I=c=>JSON.stringify(["category",c]),x=(c,e)=>JSON.stringify(["subgroup",c,e]),T=JSON.stringify(["recent"]);function v(c){if(!/[<&]/.test(c)||typeof document>"u")return c;const e=document.createElement("template");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()}function _(c,e){return c.label||c.type}function y(c){return JSON.stringify([c.type,c.isSharedNode?c.sharedNodeId??"":""])}function w(c,e){return v(c.desc||"")}function k(c){return p.DEFAULT_COMPONENT_CATEGORY_ORDER.includes(c)?c:"other"}let A=0;class B{constructor(e,t){this.id=`rulego-sidebar-${++A}`,this.rootEl=null,this.groupsEl=null,this.searchInput=null,this.clearButton=null,this.toggleButton=null,this.managerButton=null,this.unsubscribe=[],this.expanded=new Map,this.searchExpanded=new Map,this.displayGroups=[],this.iconTheme="default",this.text=(s,i="")=>{const o=p.i18nText(this.core.i18n,s,i);return o===s?i:o},this.core=t.core,this.options={...t,searchable:t.searchable??!0,defaultCollapsed:t.defaultCollapsed??!0,showRecent:t.showRecent??!0,showNodeMgt:t.showNodeMgt??!0},this.searchKeyword=t.search||"",this.mount(e),this.refresh(),this.unsubscribe.push(this.core.store.select(s=>s.componentGroups).subscribe(()=>this.refresh()),this.core.i18n.onLocaleChange(()=>this.refresh()),this.core.theme.onChange(()=>this.refresh()))}get query(){return this.searchKeyword.trim().toLowerCase().replace(/\s+/g," ")}icon(e){const t=document.createElement("span");return t.className="rulego-sidebar__control-icon",t.setAttribute("aria-hidden","true"),t.innerHTML=p.getEditorToolbarIconSvg(e)||"",t}mount(e){this.rootEl=document.createElement("aside"),this.rootEl.className="rulego-sidebar",this.rootEl.tabIndex=-1,this.rootEl.style.width=this.options.width??"220px";const t=document.createElement("div");if(t.className="rulego-sidebar__search-wrapper",this.options.searchable){const s=document.createElement("div");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=>{i.stopPropagation(),i.key==="Escape"&&(i.preventDefault(),this.setSearch(""))}),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",()=>{var i;this.setSearch(""),(i=this.searchInput)==null||i.focus()}),s.append(this.icon("search"),this.searchInput,this.clearButton),t.append(s)}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",()=>{this.visibleKeys().some(s=>this.isExpanded(s))?this.collapseAll():this.expandAll()}),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",()=>{var s,i;return(i=(s=this.options).onOpenNodeMgt)==null?void 0:i.call(s)}),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)}buildGroups(){const e=new Set,s=(this.core.store.getState().componentGroups||[]).flatMap(i=>{if(i.disabled)return[];const o=(i.subgroups||[]).map(({components:n,...r})=>r);return i.components.flatMap(n=>{var m,a,u;const r=y(n);return!((m=n.type)!=null&&m.trim())||e.has(r)?[]:(e.add(r),[p.localizeComponentDefinition(p.normalizeComponentCategory({...n,category:n.category||i.category,categoryLabel:n.categoryLabel||i.label,subgroup:n.subgroup||((u=(a=i.subgroups)==null?void 0:a.find(b=>b.components.some(h=>h.type===n.type)))==null?void 0:u.id),categorySubgroups:[...n.categorySubgroups||[],...o],label:n.label||n.type,desc:n.desc||""}),b=>this.text(b,b))])})});return p.buildComponentPalette(s,"",{categoryOrder:p.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:p.hasDeclaredSubgroups,categoryLabel:(i,o)=>{var n;return this.text(`category.${i}.label`,this.text(`category.${i}`,String(((n=o[0])==null?void 0:n.categoryLabel)||i)))}}).map(i=>({...i,key:I(i.category),subgroups:i.subgroups.map(o=>({...o,label:o.id?o.label:this.text("category.other","Other"),description:v(o.description||"")}))}))}filterGroups(e){if(!this.query)return e;const t=new Map;for(const i of e)for(const o of i.subgroups)for(const n of o.components)t.set(y(n),[_(n,this.text),w(n,this.text),v(n.desc),i.label,o.label,o.description||"",...Array.isArray(n.keywords)?n.keywords.map(String):[String(n.keywords||"")]]);const s=p.buildComponentPalette(e.flatMap(i=>i.components),this.query,{categoryOrder:p.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:p.hasDeclaredSubgroups,componentSearchText:i=>t.get(y(i))});return e.flatMap(i=>{const o=s.find(n=>n.category===i.category);return o?[{...i,components:o.components,subgroups:i.subgroups.flatMap(n=>{const r=o.subgroups.find(m=>m.id===n.id);return r?[{...n,components:r.components}]:[]})}]:[]})}hasSubgroups(e){return e.subgroups.some(t=>!!t.id)}visibleKeys(){return this.displayGroups.flatMap(e=>[e.key,...this.hasSubgroups(e)?e.subgroups.map(t=>x(e.category,t.id)):[]])}isExpanded(e){return this.query?this.searchExpanded.get(e)??!0:this.expanded.get(e)??!this.options.defaultCollapsed}allExpanded(){const e=this.visibleKeys();return e.length>0&&e.every(t=>this.isExpanded(t))}setExpansion(e,t){(this.query?this.searchExpanded:this.expanded).set(e,t)}createHeader(e,t,s,i=!1,o="",n="other"){const r=document.createElement("button");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(`
2
+ `);const m=this.isExpanded(e);if(r.setAttribute("aria-expanded",String(m)),r.setAttribute("aria-controls",this.panelId(e)),!i){const h=document.createElement("img");h.className="rulego-sidebar__group-icon",h.src=p.resolveIconUrl(`images/${k(n)}-dark.svg`,{theme:this.iconTheme}),h.alt="",h.draggable=!1,r.append(h)}const a=document.createElement("span");a.className="rulego-sidebar__group-label",a.textContent=t;const u=document.createElement("span");u.className="rulego-sidebar__group-count",u.textContent=String(s);const b=document.createElement("span");return b.className=`rulego-sidebar__arrow${m?" is-expanded":""}`,b.setAttribute("aria-hidden","true"),b.textContent="›",r.append(a,u,b),r.addEventListener("click",()=>{this.setExpansion(e,!this.isExpanded(e)),this.refresh()}),r}panelId(e){return`${this.id}-${encodeURIComponent(e)}`}createGroup(e){const t=document.createElement("section");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));const s=document.createElement("div");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;if(!this.hasSubgroups(e))s.append(this.createList(e.components,e.key,e.label));else for(const i of e.subgroups){const o=x(e.category,i.id),n=document.createElement("section");n.className="rulego-sidebar__subgroup",n.append(this.createHeader(o,i.label,i.components.length,!0,i.description));const r=document.createElement("div");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)}return t}createList(e,t,s){const i=document.createElement("div");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=>{if(o.altKey||o.ctrlKey||o.metaKey||o.isComposing)return;const n=[...i.querySelectorAll(".rulego-sidebar__component")],r=n.indexOf(o.target);if(r<0)return;const m=o.key==="Home"?0:o.key==="End"?n.length-1:o.key==="ArrowDown"?r+1:o.key==="ArrowUp"?r-1:-1;if(!n[m]){["ArrowDown","ArrowUp","Home","End"].includes(o.key)&&(o.preventDefault(),o.stopPropagation());return}o.preventDefault(),o.stopPropagation(),n[m].focus()}),i}createComponent(e,t){const s=document.createElement("button");s.type="button",s.className="rulego-sidebar__component",s.draggable=!0,s.dataset.componentType=e.type,s.dataset.sidebarFocus=JSON.stringify([t,y(e)]);const i=_(e,this.text),o=w(e,this.text);s.title=[i,e.type,o].filter(Boolean).join(`
3
+ `),s.setAttribute("aria-label",i),o&&s.setAttribute("aria-description",o);const n=k(e.category),r=e.themeColorMode==="theme"?void 0:e.background;s.style.setProperty("--rulego-component-accent",p.safeCssColor(e.color||r,`var(--rg-node-${n}-stroke, var(--rge-primary))`)),s.style.setProperty("--rulego-component-bg",p.safeCssColor(r,`var(--rg-node-${n}-bg, var(--rg-input-bg))`));const m=document.createElement("span");m.className="rulego-sidebar__component-icon",m.setAttribute("aria-hidden","true");const a=document.createElement("img"),u=p.resolveComponentIconUrl({...e,icon:void 0},{theme:this.iconTheme});a.src=p.resolveComponentIconUrl(e,{theme:this.iconTheme}),a.alt="",a.draggable=!1,a.addEventListener("error",()=>{a.getAttribute("src")!==u&&(a.src=u)}),m.append(a);const b=document.createElement("span");b.className="rulego-sidebar__component-name",b.textContent=i,s.append(m,b);for(const h of["input","output"]){if(h==="input"?e.notInput:e.notOutput)continue;const d=document.createElement("span");d.className=`rulego-sidebar__port rulego-sidebar__port--${h}`,d.setAttribute("aria-hidden","true"),s.append(d)}return s.addEventListener("click",()=>{var h,d;return(d=(h=this.options).onDragStart)==null?void 0:d.call(h,e)}),s.addEventListener("keydown",h=>{var d,g;h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),h.stopPropagation(),!h.repeat&&!h.isComposing&&((g=(d=this.options).onDragStart)==null||g.call(d,e)))}),s.addEventListener("dragstart",h=>{var g,l,E,f;const d=JSON.stringify(e);(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"),(f=(E=this.options).onDragStart)==null||f.call(E,e)}),s.addEventListener("dragend",()=>s.classList.remove("rulego-sidebar__component--dragging")),s}refresh(){var h,d,g;if(!this.rootEl||!this.groupsEl)return;this.iconTheme=p.normalizeIconTheme(this.options.theme||this.core.theme.getTheme()),this.rootEl.dataset.theme=this.iconTheme,this.rootEl.dataset.rgTheme=this.iconTheme;const e={...p.getThemeRuntimeVariables(this.iconTheme),...this.options.theme?{}:(h=this.core.theme.getThemeDefinition())==null?void 0:h.variables};for(const[l,E]of Object.entries(e))this.rootEl.style.setProperty(l,E);this.rootEl.setAttribute("aria-label",this.text("editor.sidebar.ariaLabel"));const t=this.core.i18n.getLocale().toLowerCase().startsWith("en");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));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)]:[]):[];this.displayGroups=n.length?[{key:T,recent:!0,category:"common",color:"",label:this.text("editor.sidebar.recentComponents"),components:n,subgroups:[]},...i]:i;const r=this.allExpanded(),m=this.visibleKeys().some(l=>this.isExpanded(l));this.toggleButton&&(this.toggleButton.disabled=!this.displayGroups.length,this.toggleButton.title=this.text(m?"editor.sidebar.collapseAll":"editor.sidebar.expandAll"),this.toggleButton.setAttribute("aria-label",this.toggleButton.title),this.toggleButton.setAttribute("aria-pressed",m&&!r?"mixed":String(r)),this.toggleButton.replaceChildren(this.icon(m?"collapse-all":"expand-all")));const a=document.activeElement,u=a&&this.groupsEl.contains(a)?a.dataset.sidebarFocus:void 0,b=this.groupsEl.scrollTop;if(this.groupsEl.replaceChildren(...this.displayGroups.map(l=>this.createGroup(l))),!i.length){const l=document.createElement("div");l.className="rulego-sidebar__empty",l.setAttribute("role","status"),l.setAttribute("aria-live","polite"),l.append(this.icon("package"));const E=document.createElement("p");E.textContent=this.query?this.text("sidebar.noResults"):this.text("editorShell.noComponents",t?"No components available":"暂无可用组件"),l.append(E),this.groupsEl.append(l)}u&&((g=[...this.groupsEl.querySelectorAll("[data-sidebar-focus]")].find(E=>E.dataset.sidebarFocus===u)||this.searchInput||((d=this.toggleButton)!=null&&d.isConnected?this.toggleButton:this.rootEl))==null||g.focus({preventScroll:!0})),this.groupsEl.scrollTop=b}setSearch(e){var i,o;const t=this.query,s=this.searchKeyword!==e;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))}setRecentComponentTypes(e){this.options.recentComponentTypes=[...e],this.refresh()}expandAll(){this.visibleKeys().forEach(e=>this.setExpansion(e,!0)),this.refresh()}collapseAll(){this.visibleKeys().forEach(e=>this.setExpansion(e,!1)),this.refresh()}getElement(){return this.rootEl}destroy(){var e;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}}function C(c,e){if(e){if(typeof e=="string"){c.textContent=e;return}if(e.kind==="text"){c.textContent=e.value;return}e.kind==="trusted-svg"&&L(c,e.svg)}}function L(c,e){const t=document.createElement("template");t.innerHTML=e;const s=t.content.firstElementChild;if(!s||s.tagName.toLowerCase()!=="svg"){c.textContent="";return}S(s),c.replaceChildren(s)}function S(c){for(const e of Array.from(c.attributes)){const t=e.name.toLowerCase(),s=e.value.trim().toLowerCase();(t.startsWith("on")||s.startsWith("javascript:")||s.startsWith("data:text/html"))&&c.removeAttribute(e.name)}for(const e of Array.from(c.children)){const t=e.tagName.toLowerCase();if(t==="script"||t==="foreignobject"){e.remove();continue}S(e)}}class M{constructor(e,t){this.rootEl=null,this.unsubscribe=null,this.buttonElements=new Map,this.container=e,this.core=t.core,this.options={core:t.core,extraButtons:t.extraButtons??[],showZoom:t.showZoom??!0,height:t.height??"40px",onSave:t.onSave,onDelete:t.onDelete,onFullscreen:t.onFullscreen,onAutoLayout:t.onAutoLayout},this.mount(),this.unsubscribe=this.core.store.subscribe(()=>{this.updateButtonStates()})}mount(){this.rootEl=document.createElement("div"),this.rootEl.className="rulego-toolbar",this.rootEl.style.height=this.options.height;const e=this.getBuiltinButtons();this.options.extraButtons.length>0&&(e.push({id:"__divider_extra",icon:"",title:"",divider:!0,onClick:()=>{}}),e.push(...this.options.extraButtons));for(const t of e){if(t.divider){const i=document.createElement("span");i.className="rulego-toolbar__divider",this.rootEl.appendChild(i)}if(!t.icon&&t.divider)continue;const s=document.createElement("button");if(s.className="rulego-toolbar__button",s.title=t.title,C(s,t.icon),t.label){const i=document.createElement("span");i.className="rulego-toolbar__button-label",i.textContent=t.label,s.appendChild(i)}s.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),t.onClick()}),this.buttonElements.set(t.id,s),this.rootEl.appendChild(s)}this.container.appendChild(this.rootEl),this.updateButtonStates()}destroy(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.rootEl&&this.rootEl.parentNode&&this.rootEl.parentNode.removeChild(this.rootEl),this.rootEl=null,this.buttonElements.clear()}getBuiltinButtons(){const e=[{id:"undo",icon:this.toolbarIcon("undo"),title:this.text("toolbar.undo","撤销"),disabled:()=>!this.core.store.getState().canUndo,onClick:()=>{this.core.history.undo()}},{id:"redo",icon:this.toolbarIcon("redo"),title:this.text("toolbar.redo","重做"),disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{this.core.history.redo()}},{id:"delete",icon:this.toolbarIcon("delete"),title:this.text("toolbar.delete","删除选中"),divider:!0,onClick:()=>{this.options.onDelete?this.options.onDelete():this.core.eventBus.emit("editor:delete-selected")}},{id:"save",icon:this.toolbarIcon("save"),title:this.options.onSave?this.text("toolbar.save","保存"):this.text("toolbar.saveHostRequired","请先配置宿主保存回调"),disabled:()=>!this.options.onSave,onClick:()=>{var t,s;(s=(t=this.options).onSave)==null||s.call(t)}},{id:"fullscreen",icon:this.toolbarIcon("fullscreen"),title:this.text("toolbar.fullscreen","全屏"),onClick:()=>{this.options.onFullscreen?this.options.onFullscreen():this.core.eventBus.emit("editor:fullscreen")}}];return this.options.showZoom&&e.push({id:"zoom-in",icon:this.toolbarIcon("zoom-in"),title:this.text("toolbar.zoomIn","放大"),divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:this.toolbarIcon("zoom-out"),title:this.text("toolbar.zoomOut","缩小"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:this.toolbarIcon("fit"),title:this.text("toolbar.fitView","适应画布"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),e.push({id:"auto-layout",icon:this.toolbarIcon("auto-layout"),title:this.text("toolbar.autoLayout","自动排版"),divider:!0,onClick:()=>{this.options.onAutoLayout?this.options.onAutoLayout():this.core.eventBus.emit("editor:auto-layout")}}),e}toolbarIcon(e){const t=p.getEditorToolbarIconSvg(e);return t?{kind:"trusted-svg",svg:t}:e}updateButtonStates(){for(const[e,t]of this.buttonElements){const s=this.getBuiltinButtons().find(i=>i.id===e);s&&typeof s.disabled=="function"&&(t.disabled=s.disabled(),t.classList.toggle("rulego-toolbar__button--disabled",t.disabled))}}getElement(){return this.rootEl}text(e,t){return p.i18nText(this.core.i18n,e,t)}addButton(e){if(!this.rootEl)return;const t=document.createElement("button");t.className="rulego-toolbar__button",t.title=e.title,C(t,e.icon),t.addEventListener("click",s=>{s.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class F{constructor(e,t){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={core:t.core,title:t.title||this.text("panel.title","属性编辑"),width:t.width??"320px",position:t.position??"right"},this.mount(),this.bindEvents()}mount(){this.rootEl=document.createElement("div"),this.rootEl.className=`rulego-property-panel rulego-property-panel--${this.options.position}`,this.rootEl.style.width=this.options.width;const e=document.createElement("div");e.className="rulego-property-panel__header",this.titleEl=document.createElement("h3"),this.titleEl.className="rulego-property-panel__title",this.titleEl.textContent=this.options.title;const t=document.createElement("button");t.className="rulego-property-panel__close",t.textContent="✕",t.addEventListener("click",()=>this.clearPanel()),e.appendChild(this.titleEl),e.appendChild(t),this.rootEl.appendChild(e),this.formContainer=document.createElement("div"),this.formContainer.className="rulego-property-panel__form",this.rootEl.appendChild(this.formContainer),this.rootEl.style.display="none",this.container.appendChild(this.rootEl)}bindEvents(){this.unsubscribe=this.core.store.subscribe(t=>{const s=t.currentNodeView,i=t.currentNodeModel;s&&i&&Object.keys(i).length>0&&this.showPanel(s,i)});const e=this.core.eventBus.on("blank:click",()=>{this.clearPanel()});this.eventCleanups.push(e)}destroy(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null);for(const e of this.eventCleanups)e();this.eventCleanups=[],this.rootEl&&this.rootEl.parentNode&&this.rootEl.parentNode.removeChild(this.rootEl),this.rootEl=null,this.formContainer=null}showPanel(e,t){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))for(const s of e.fields){const i=this.createFieldElement(s,t);this.formContainer.appendChild(i)}}clearPanel(){!this.rootEl||!this.formContainer||(this.formContainer.replaceChildren(),this.rootEl.style.display="none",this.currentNodeId=null)}renderBasicInfo(e){if(!this.formContainer)return;const t=document.createElement("div");t.className="rulego-property-panel__section";const s=this.createTextField({name:"name",type:"string",defaultValue:"",label:this.text("panel.nodeName","节点名称"),desc:"",validate:"",fields:null},e);t.appendChild(s),this.formContainer.appendChild(t)}createFieldElement(e,t){const s=document.createElement("div");s.className="rulego-property-panel__field";const i=document.createElement("label");i.className="rulego-property-panel__label",i.textContent=e.label||e.name,e.desc&&(i.title=e.desc),s.appendChild(i);let o;switch(e.type){case"bool":o=this.createBoolField(e,t);break;case"select":o=this.createSelectField(e,t);break;case"code":case"json":o=this.createTextareaField(e,t);break;case"int":o=this.createNumberField(e,t);break;default:o=this.createTextField(e,t);break}if(s.appendChild(o),e.desc){const n=document.createElement("span");n.className="rulego-property-panel__desc",n.textContent=e.desc,s.appendChild(n)}return s}createTextField(e,t){const s=document.createElement("input");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",()=>{this.handleFieldChange(e.name,s.value)}),s}createNumberField(e,t){const s=document.createElement("input");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",()=>{this.handleFieldChange(e.name,Number(s.value))}),s}createBoolField(e,t){const s=document.createElement("div");s.className="rulego-property-panel__switch-wrapper";const i=`field-${e.name}-${Date.now()}`,o=document.createElement("input");o.type="checkbox",o.className="rulego-property-panel__checkbox",o.id=i,o.checked=!!this.getModelValue(e,t);const n=document.createElement("label");return n.className="rulego-property-panel__switch",n.htmlFor=i,o.addEventListener("change",()=>{this.handleFieldChange(e.name,o.checked)}),s.appendChild(o),s.appendChild(n),s}createSelectField(e,t){const s=document.createElement("select");s.className="rulego-property-panel__select",s.name=e.name;const i=String(this.getModelValue(e,t)??"");if(e.options&&e.options.length>0)for(const o of e.options.filter(p.isComponentFieldOption)){const n=document.createElement("option"),r=String(o.value??"");n.value=r,n.textContent=o.label,r===i&&(n.selected=!0),s.appendChild(n)}return s.addEventListener("change",()=>{this.handleFieldChange(e.name,s.value)}),s}createTextareaField(e,t){const s=document.createElement("textarea");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",()=>{this.handleFieldChange(e.name,s.value)}),s}getModelValue(e,t){const s=t.configuration;return s&&e.name in s?s[e.name]:e.name in t?t[e.name]:e.defaultValue}handleFieldChange(e,t){this.core.eventBus.emit("node:property-update",{id:this.currentNodeId||"",properties:{[e]:t}}),this.core.store.setState({isDirty:!0})}getElement(){return this.rootEl}setCurrentNodeId(e){this.currentNodeId=e}show(e,t,s){s&&(this.currentNodeId=s),this.showPanel(e,t)}hide(){this.clearPanel()}text(e,t){return p.i18nText(this.core.i18n,e,t)}}class D{constructor(e,t){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;const s=t.includeBuiltin!==!1?this.getBuiltinItems():[];this.items=[...s,...t.items??[]],this.mount(),this.bindEvents()}mount(){var e,t;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)}bindEvents(){this.contextMenuHandler=e=>{e.preventDefault(),this.handleContextMenu(e)},this.container.addEventListener("contextmenu",this.contextMenuHandler),this.outsideClickHandler=e=>{this.menuEl&&!this.menuEl.contains(e.target)&&this.hide()},document.addEventListener("click",this.outsideClickHandler),this.escapeKeyHandler=e=>{e.key==="Escape"&&this.hide()},document.addEventListener("keydown",this.escapeKeyHandler)}destroy(){var e;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}handleContextMenu(e){const t=e.target,s=this.resolveContext(t,e);this.currentContext=s;const i=this.items.filter(o=>{const n=Array.isArray(o.target)?o.target:[o.target];return n.includes(s.type)||n.includes("all")});if(i.length===0){this.hide();return}this.renderMenu(i,e.clientX,e.clientY)}resolveContext(e,t){const s=e.closest(".lf-node");if(s)return{type:"node",id:s.getAttribute("data-node-id")||void 0,position:{x:t.clientX,y:t.clientY}};const i=e.closest(".lf-edge");return i?{type:"edge",id:i.getAttribute("data-edge-id")||void 0,position:{x:t.clientX,y:t.clientY}}:{type:"canvas",position:{x:t.clientX,y:t.clientY}}}renderMenu(e,t,s){if(!this.menuEl)return;this.cancelPendingPosition(),this.menuEl.replaceChildren();for(const n of e){const r=document.createElement("div");r.className="rulego-context-menu__item";const m=typeof n.disabled=="function"?n.disabled():n.disabled;if(m&&r.classList.add("rulego-context-menu__item--disabled"),n.icon){const u=document.createElement("span");u.className="rulego-context-menu__icon",C(u,n.icon),r.appendChild(u)}const a=document.createElement("span");if(a.className="rulego-context-menu__label",a.textContent=n.label,r.appendChild(a),m||r.addEventListener("click",()=>{this.currentContext&&n.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(r),n.separator){const u=document.createElement("div");u.className="rulego-context-menu__separator",this.menuEl.appendChild(u)}}this.menuEl.style.left=`${t}px`,this.menuEl.style.top=`${s}px`,this.menuEl.style.visibility="hidden",this.menuEl.style.display="block";let i=!1;const o=requestAnimationFrame(()=>{i=!0,this.positionFrame=null;const n=this.menuEl;if(!n)return;const r=n.getBoundingClientRect(),m=p.clampContextMenuPosition({left:t,top:s},{width:r.width,height:r.height},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${m.left}px`,n.style.top=`${m.top}px`,n.style.visibility="visible"});this.positionFrame=i?null:o}hide(){this.cancelPendingPosition(),this.menuEl&&(this.menuEl.style.display="none",this.menuEl.style.visibility=""),this.currentContext=null}cancelPendingPosition(){this.positionFrame!==null&&(cancelAnimationFrame(this.positionFrame),this.positionFrame=null)}getBuiltinItems(){return[{id:"edit",label:this.text("contextMenu.edit","编辑"),icon:this.toolbarIcon("edit"),target:"node",onClick:e=>{e.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:this.text("contextMenu.delete","删除"),icon:this.toolbarIcon("delete"),target:["node","edge"],separator:!0,onClick:e=>{e.id&&this.core.eventBus.emit(e.type==="edge"?"edge:delete":"node:delete",{id:e.id})}},{id:"copy",label:this.text("contextMenu.copy","复制"),icon:this.toolbarIcon("copy"),target:"node",disabled:()=>!this.options.onCopy,onClick:e=>{var t,s;(s=(t=this.options).onCopy)==null||s.call(t,e)}},{id:"select-all",label:this.text("contextMenu.selectAll","全选"),icon:this.toolbarIcon("select-all"),target:"canvas",disabled:()=>!this.options.onSelectAll,onClick:e=>{var t,s;(s=(t=this.options).onSelectAll)==null||s.call(t,e)}}]}addItem(e){this.items.push(e)}text(e,t){return p.i18nText(this.core.i18n,e,t)}toolbarIcon(e){const t=p.getEditorToolbarIconSvg(e);return t?{kind:"trusted-svg",svg:t}:e}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}class H{constructor(e,t){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()}t(e,t){const s=this.core.i18n.t(e);return s&&s!==e?s:t}mount(){this.consoleEl=document.createElement("div"),this.consoleEl.className="rulego-debug-console";const e=document.createElement("div");e.className="rulego-debug-console__header";const t=document.createElement("span");t.className="rulego-debug-console__title",t.textContent=this.t("editor.debugConsole.title","调试控制台");const s=document.createElement("button");s.className="rulego-debug-console__clear",s.textContent=this.t("editor.debugConsole.clear","清除"),e.append(t,s);const i=document.createElement("div");i.className="rulego-debug-console__list",this.consoleEl.append(e,i),this.listEl=i,this.container.appendChild(this.consoleEl),s.addEventListener("click",()=>this.clear())}bindEvents(){this.unsubscribe=this.core.eventBus.on("debug:log",e=>{this.appendLog(e)})}appendLog(e){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;const t=document.createElement("div");t.className="rulego-debug-console__item";const s=typeof e=="string"?e:p.formatJsonBounded(p.redactSensitive(e),{maxChars:2e4,space:0});t.textContent=`[${new Date().toLocaleTimeString()}] ${s}`,this.listEl.appendChild(t),this.listEl.scrollTop=this.listEl.scrollHeight}clear(){this.logs=[],this.listEl&&this.listEl.replaceChildren()}destroy(){var e;(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=[]}}const O=28;function N(c,e,t=0){const s=[];return c.forEach(i=>{var o;s.push({node:i,depth:t}),(o=i.children)!=null&&o.length&&e.has(i.key)&&s.push(...N(i.children,e,t+1))}),s}function P(c,e=""){e.split(/\s+/).filter(Boolean).forEach(t=>c.classList.add(t))}class R{constructor(e,t={}){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 p.ExplorerTreeStore({workflows:t.workflows,activeChainId:t.activeChainId,keyword:t.keyword,persistence:t.persistence}),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()}getState(){return this.store.getState()}getStore(){return this.store}setWorkflows(e){this.destroyed||this.store.setWorkflows(e)}setActiveChainId(e){this.destroyed||this.store.setActiveChainId(e)}setKeyword(e){var t,s;this.destroyed||(this.store.setKeyword(e),(s=(t=this.options).onKeywordChange)==null||s.call(t,String(e||"")))}destroy(){var e,t,s;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)}mount(){this.rootEl=document.createElement("section"),this.rootEl.className="huanban_workflow_explorer",P(this.rootEl,this.options.className),this.rootEl.setAttribute("aria-label","规则链资源");const e=document.createElement("div");e.className="huanban_workflow_explorer__search";const t=document.createElement("span");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",()=>{var s;this.setKeyword(((s=this.searchInputEl)==null?void 0:s.value)||"")}),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",()=>{if(!this.treeEl||this.destroyed)return;const s=this.treeEl.scrollTop;s!==this.virtualScrollTop&&(this.virtualScrollTop=s,this.renderState(this.store.getState()))}),this.rootEl.appendChild(this.treeEl),this.container.appendChild(this.rootEl),this.unsubscribe=this.store.subscribe(s=>this.renderState(s)),this.renderState(this.store.getState())}renderState(e){if(this.destroyed||!this.treeEl)return;this.searchInputEl&&this.searchInputEl.value!==e.keyword&&(this.searchInputEl.value=e.keyword);const t=N(e.tree,new Set(e.expandedKeys));if(t.length===0){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");const d=document.createElement("div");d.className="huanban_workflow_explorer__empty",d.textContent=this.options.emptyText||"暂无规则链",this.treeEl.replaceChildren(d);return}const s=this.options.virtualization,i=(s==null?void 0:s.enabled)!==!1,o=Math.max(1,(s==null?void 0:s.threshold)??p.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),n=Math.max(1,(s==null?void 0:s.itemHeight)??O),r=Math.max(1,(s==null?void 0:s.viewportHeight)??p.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),m=Math.max(0,(s==null?void 0:s.overscan)??p.DEFAULT_VIRTUAL_WINDOW_OVERSCAN),a=i&&t.length>o;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){const d=t.findIndex(g=>{var l;return g.node.kind==="chain"&&((l=g.node.chain)==null?void 0:l.id)===e.activeChainId});if(d>=0){const g=Math.floor(this.virtualScrollTop/n),l=Math.ceil((this.virtualScrollTop+r)/n);d<g?this.virtualScrollTop=d*n:d>=l&&(this.virtualScrollTop=(d+1)*n-r),this.autoScrolledActiveChainId=e.activeChainId}}const u=p.calculateVirtualWindow({total:t.length,itemHeight:n,viewportHeight:r,scrollTop:this.virtualScrollTop,overscan:m});this.treeEl.classList.toggle("is-virtualized",a),a?(this.treeEl.dataset.explorerVirtualized="true",this.treeEl.dataset.explorerVirtualTotal=String(t.length),this.treeEl.style.height=`${u.viewportHeight}px`):(this.treeEl.removeAttribute("data-explorer-virtualized"),this.treeEl.removeAttribute("data-explorer-virtual-total"),this.treeEl.style.removeProperty("height"));const b=a?t.slice(u.start,u.end):t,h=document.createDocumentFragment();if(a){const d=document.createElement("div");d.className="huanban_workflow_explorer__virtual-canvas",d.style.height=`${u.totalHeight}px`;const g=document.createElement("div");g.className="huanban_workflow_explorer__virtual-items",g.style.transform=`translateY(${u.offsetTop}px)`,b.forEach(({node:l,depth:E},f)=>g.appendChild(this.createRow(l,E,e,u.start+f,t.length))),d.appendChild(g),h.appendChild(d),this.treeEl.scrollTop!==u.scrollTop&&(this.treeEl.scrollTop=u.scrollTop)}else b.forEach(({node:d,depth:g},l)=>h.appendChild(this.createRow(d,g,e,l,t.length)));this.treeEl.replaceChildren(h)}createRow(e,t,s,i,o){var d,g;const n=!!((d=e.children)!=null&&d.length),r=s.expandedKeys.includes(e.key),m=e.kind==="chain"&&((g=e.chain)==null?void 0:g.id)===s.activeChainId,a=document.createElement("button");a.type="button",a.className=`huanban_workflow_explorer__row is-${e.kind}${m?" 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(m)),a.title=e.chain?`${e.chain.name}
4
+ ${e.chain.id}`:e.label;const u=document.createElement("span");u.className=`huanban_workflow_explorer__chevron${n&&r?" is-open":""}`,u.setAttribute("aria-hidden","true");const b=document.createElement("span");b.className=`huanban_workflow_explorer__kind is-${e.kind}`,b.setAttribute("aria-hidden","true");const h=document.createElement("span");if(h.className="huanban_workflow_explorer__label",h.textContent=e.label,a.append(u,b,h),e.kind==="chain"&&e.chain){const l=document.createElement("span");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)}if(e.count!==void 0){const l=document.createElement("span");l.className="huanban_workflow_explorer__count",l.textContent=String(e.count),a.appendChild(l)}return a.addEventListener("click",()=>{var l,E;n?this.store.setExpanded(e.key,!r):e.chain&&((E=(l=this.options).onOpen)==null||E.call(l,e.chain))}),a}}exports.ContextMenu=D;exports.DebugConsole=H;exports.PropertyPanel=F;exports.Sidebar=B;exports.Toolbar=M;exports.WorkflowExplorer=R;