@huanban/rulego-editor-ui 1.3.17 → 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.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@huanban/rulego-editor-core")):typeof define=="function"&&define.amd?define(["exports","@huanban/rulego-editor-core"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c.RuleGoEditorUI={},c.RuleGoEditorCore))})(this,function(c,d){"use strict";class p{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(n=>n.componentGroups).subscribe(n=>{this.renderGroups(n)})}mount(){if(this.rootEl=document.createElement("div"),this.rootEl.className="rulego-sidebar",this.rootEl.style.width=this.options.width,this.options.searchable){const n=document.createElement("div");n.className="rulego-sidebar__search-wrapper";const s=document.createElement("span");s.className="rulego-sidebar__search-icon",s.textContent="🔍";const o=document.createElement("input");o.type="text",o.className="rulego-sidebar__search",o.placeholder=this.options.searchPlaceholder,o.addEventListener("input",i=>{this.searchKeyword=i.target.value.toLowerCase();const a=this.core.store.getState().componentGroups;this.renderGroups(a)}),n.appendChild(s),n.appendChild(o),this.rootEl.appendChild(n)}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 n=this.filterGroups(e);if(n.length===0){const s=document.createElement("div");s.className="rulego-sidebar__empty",s.textContent=this.text("sidebar.noResults","无匹配组件"),t.appendChild(s);return}for(const s of n){const o=this.createGroupElement(s);t.appendChild(o)}}createGroupElement(e){const t=document.createElement("div");t.className="rulego-sidebar__group";const n=document.createElement("div");n.className="rulego-sidebar__group-header",n.style.borderLeftColor=e.color||"#ccc";const s=this.collapsedGroups.has(e.category),o=document.createElement("span");o.className=`rulego-sidebar__arrow ${s?"rulego-sidebar__arrow--collapsed":""}`,o.textContent="▼";const i=document.createElement("span");i.className="rulego-sidebar__group-label",i.textContent=this.text(`category.${e.category}`,e.label||e.category);const a=document.createElement("span");if(a.className="rulego-sidebar__group-count",a.textContent=`${e.components.length}`,n.appendChild(o),n.appendChild(i),n.appendChild(a),n.addEventListener("click",()=>{this.collapsedGroups.has(e.category)?this.collapsedGroups.delete(e.category):this.collapsedGroups.add(e.category);const l=this.core.store.getState().componentGroups;this.renderGroups(l)}),t.appendChild(n),!s){const l=document.createElement("div");l.className="rulego-sidebar__component-list";for(const C of e.components){const v=this.createComponentElement(C,e.color);l.appendChild(v)}t.appendChild(l)}return t}createComponentElement(e,t){const n=document.createElement("div");n.className="rulego-sidebar__component",n.setAttribute("draggable","true");const s=this.componentLabel(e),o=this.text(`fields.${e.type}`,e.desc||s);n.title=o||s;const i=document.createElement("span");i.className="rulego-sidebar__component-color",i.style.backgroundColor=e.color||t||"#ccc";const a=document.createElement("span");return a.className="rulego-sidebar__component-name",a.textContent=s,n.appendChild(i),n.appendChild(a),n.addEventListener("dragstart",l=>{l.dataTransfer&&(l.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:s,color:e.color||t})),l.dataTransfer.effectAllowed="copy"),n.classList.add("rulego-sidebar__component--dragging")}),n.addEventListener("dragend",()=>{n.classList.remove("rulego-sidebar__component--dragging")}),n}filterGroups(e){return this.searchKeyword?e.map(t=>({...t,components:t.components.filter(n=>{const s=this.componentLabel(n).toLowerCase(),o=this.text(`fields.${n.type}`,n.desc||"").toLowerCase();return s.includes(this.searchKeyword)||n.type.toLowerCase().includes(this.searchKeyword)||o.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 d.i18nText(this.core.i18n,e,t)}componentLabel(e){return this.text(`components.${e.type}`,e.label||e.type.split("/").pop()||e.type)}}function h(r,e){if(e){if(typeof e=="string"){r.textContent=e;return}if(e.kind==="text"){r.textContent=e.value;return}e.kind==="trusted-svg"&&m(r,e.svg)}}function m(r,e){const t=document.createElement("template");t.innerHTML=e;const n=t.content.firstElementChild;if(!n||n.tagName.toLowerCase()!=="svg"){r.textContent="";return}u(n),r.replaceChildren(n)}function u(r){for(const e of Array.from(r.attributes)){const t=e.name.toLowerCase(),n=e.value.trim().toLowerCase();(t.startsWith("on")||n.startsWith("javascript:")||n.startsWith("data:text/html"))&&r.removeAttribute(e.name)}for(const e of Array.from(r.children)){const t=e.tagName.toLowerCase();if(t==="script"||t==="foreignobject"){e.remove();continue}u(e)}}class E{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"},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 s=document.createElement("span");s.className="rulego-toolbar__divider",this.rootEl.appendChild(s)}if(!t.icon&&t.divider)continue;const n=document.createElement("button");if(n.className="rulego-toolbar__button",n.title=t.title,h(n,t.icon),t.label){const s=document.createElement("span");s.className="rulego-toolbar__button-label",s.textContent=t.label,n.appendChild(s)}n.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),t.onClick()}),this.buttonElements.set(t.id,n),this.rootEl.appendChild(n)}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:"↩",title:this.text("toolbar.undo","撤销"),disabled:()=>!this.core.store.getState().canUndo,onClick:()=>this.core.eventBus.emit("editor:reset")},{id:"redo",icon:"↪",title:this.text("toolbar.redo","重做"),disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{}},{id:"delete",icon:"🗑",title:this.text("toolbar.delete","删除选中"),divider:!0,onClick:()=>this.core.eventBus.emit("editor:delete-selected")},{id:"save",icon:"💾",title:this.text("toolbar.save","保存"),onClick:()=>this.core.eventBus.emit("editor:save",{data:{},success:!1})},{id:"fullscreen",icon:"⛶",title:this.text("toolbar.fullscreen","全屏"),onClick:()=>this.core.eventBus.emit("editor:fullscreen")}];return this.options.showZoom&&e.push({id:"zoom-in",icon:"🔍+",title:this.text("toolbar.zoomIn","放大"),divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:"🔍-",title:this.text("toolbar.zoomOut","缩小"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:"🔲",title:this.text("toolbar.fitView","适应画布"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),e.push({id:"auto-layout",icon:"📐",title:this.text("toolbar.autoLayout","自动排版"),divider:!0,onClick:()=>this.core.eventBus.emit("editor:auto-layout")}),e}updateButtonStates(){for(const[e,t]of this.buttonElements){const n=this.getBuiltinButtons().find(s=>s.id===e);n&&typeof n.disabled=="function"&&(t.disabled=n.disabled(),t.classList.toggle("rulego-toolbar__button--disabled",t.disabled))}}getElement(){return this.rootEl}text(e,t){return d.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,h(t,e.icon),t.addEventListener("click",n=>{n.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class g{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 n=t.currentNodeView,s=t.currentNodeModel;n&&s&&Object.keys(s).length>0&&this.showPanel(n,s)});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 n of e.fields){const s=this.createFieldElement(n,t);this.formContainer.appendChild(s)}}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 n=this.createTextField({name:"name",type:"string",defaultValue:"",label:this.text("panel.nodeName","节点名称"),desc:"",validate:"",fields:null},e);t.appendChild(n),this.formContainer.appendChild(t)}createFieldElement(e,t){const n=document.createElement("div");n.className="rulego-property-panel__field";const s=document.createElement("label");s.className="rulego-property-panel__label",s.textContent=e.label||e.name,e.desc&&(s.title=e.desc),n.appendChild(s);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(n.appendChild(o),e.desc){const i=document.createElement("span");i.className="rulego-property-panel__desc",i.textContent=e.desc,n.appendChild(i)}return n}createTextField(e,t){const n=document.createElement("input");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",()=>{this.handleFieldChange(e.name,n.value)}),n}createNumberField(e,t){const n=document.createElement("input");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",()=>{this.handleFieldChange(e.name,Number(n.value))}),n}createBoolField(e,t){const n=document.createElement("div");n.className="rulego-property-panel__switch-wrapper";const s=`field-${e.name}-${Date.now()}`,o=document.createElement("input");o.type="checkbox",o.className="rulego-property-panel__checkbox",o.id=s,o.checked=!!this.getModelValue(e,t);const i=document.createElement("label");return i.className="rulego-property-panel__switch",i.htmlFor=s,o.addEventListener("change",()=>{this.handleFieldChange(e.name,o.checked)}),n.appendChild(o),n.appendChild(i),n}createSelectField(e,t){const n=document.createElement("select");n.className="rulego-property-panel__select",n.name=e.name;const s=String(this.getModelValue(e,t)??"");if(e.options&&e.options.length>0)for(const o of e.options){const i=document.createElement("option");i.value=o.value,i.textContent=o.label,o.value===s&&(i.selected=!0),n.appendChild(i)}return n.addEventListener("change",()=>{this.handleFieldChange(e.name,n.value)}),n}createTextareaField(e,t){const n=document.createElement("textarea");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",()=>{this.handleFieldChange(e.name,n.value)}),n}getModelValue(e,t){const n=t.configuration;return n&&e.name in n?n[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,n){n&&(this.currentNodeId=n),this.showPanel(e,t)}hide(){this.clearPanel()}text(e,t){return d.i18nText(this.core.i18n,e,t)}}class b{constructor(e,t){this.menuEl=null,this.currentContext=null,this.outsideClickHandler=null,this.container=e,this.core=t.core;const n=t.includeBuiltin!==!1?this.getBuiltinItems():[];this.items=[...n,...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.container.addEventListener("contextmenu",e=>{e.preventDefault(),this.handleContextMenu(e)}),this.outsideClickHandler=e=>{this.menuEl&&!this.menuEl.contains(e.target)&&this.hide()},document.addEventListener("click",this.outsideClickHandler),document.addEventListener("keydown",e=>{e.key==="Escape"&&this.hide()})}destroy(){this.outsideClickHandler&&(document.removeEventListener("click",this.outsideClickHandler),this.outsideClickHandler=null),this.menuEl&&this.menuEl.parentNode&&this.menuEl.parentNode.removeChild(this.menuEl),this.menuEl=null}handleContextMenu(e){const t=e.target,n=this.resolveContext(t,e);this.currentContext=n;const s=this.items.filter(o=>{const i=Array.isArray(o.target)?o.target:[o.target];return i.includes(n.type)||i.includes("all")});s.length!==0&&this.renderMenu(s,e.clientX,e.clientY)}resolveContext(e,t){const n=e.closest(".lf-node");if(n)return{type:"node",id:n.getAttribute("data-node-id")||void 0,position:{x:t.clientX,y:t.clientY}};const s=e.closest(".lf-edge");return s?{type:"edge",id:s.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,n){if(this.menuEl){this.menuEl.replaceChildren();for(const s of e){const o=document.createElement("div");o.className="rulego-context-menu__item";const i=typeof s.disabled=="function"?s.disabled():s.disabled;if(i&&o.classList.add("rulego-context-menu__item--disabled"),s.icon){const l=document.createElement("span");l.className="rulego-context-menu__icon",h(l,s.icon),o.appendChild(l)}const a=document.createElement("span");if(a.className="rulego-context-menu__label",a.textContent=s.label,o.appendChild(a),i||o.addEventListener("click",()=>{this.currentContext&&s.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(o),s.separator){const l=document.createElement("div");l.className="rulego-context-menu__separator",this.menuEl.appendChild(l)}}this.menuEl.style.left=`${t}px`,this.menuEl.style.top=`${n}px`,this.menuEl.style.display="block",requestAnimationFrame(()=>{if(!this.menuEl)return;const s=this.menuEl.getBoundingClientRect();s.right>window.innerWidth&&(this.menuEl.style.left=`${t-s.width}px`),s.bottom>window.innerHeight&&(this.menuEl.style.top=`${n-s.height}px`)})}}hide(){this.menuEl&&(this.menuEl.style.display="none"),this.currentContext=null}getBuiltinItems(){return[{id:"edit",label:this.text("contextMenu.edit","编辑"),icon:"✏️",target:"node",onClick:e=>{e.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:this.text("contextMenu.delete","删除"),icon:"🗑️",target:["node","edge"],separator:!0,onClick:e=>{e.id&&this.core.eventBus.emit("node:delete",{id:e.id})}},{id:"copy",label:this.text("contextMenu.copy","复制"),icon:"📋",target:"node",onClick:()=>{}},{id:"select-all",label:this.text("contextMenu.selectAll","全选"),icon:"⬜",target:"canvas",onClick:()=>{}}]}addItem(e){this.items.push(e)}text(e,t){return d.i18nText(this.core.i18n,e,t)}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}class f{constructor(e,t){this.logs=[],this.consoleEl=null,this.listEl=null,this.container=e,this.core=t.core,this.maxLogs=t.maxLogs||1e3,this.mount(),this.bindEvents()}t(e,t){const n=this.core.i18n.t(e);return n&&n!==e?n: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 n=document.createElement("button");n.className="rulego-debug-console__clear",n.textContent=this.t("editor.debugConsole.clear","清除"),e.append(t,n);const s=document.createElement("div");s.className="rulego-debug-console__list",this.consoleEl.append(e,s),this.listEl=s,this.container.appendChild(this.consoleEl),n.addEventListener("click",()=>this.clear())}bindEvents(){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 n=typeof e=="string"?e:d.formatJsonBounded(d.redactSensitive(e),{maxChars:2e4,space:0});t.textContent=`[${new Date().toLocaleTimeString()}] ${n}`,this.listEl.appendChild(t),this.listEl.scrollTop=this.listEl.scrollHeight}clear(){this.logs=[],this.listEl&&this.listEl.replaceChildren()}destroy(){this.consoleEl&&this.consoleEl.parentNode&&this.consoleEl.parentNode.removeChild(this.consoleEl)}}c.ContextMenu=b,c.DebugConsole=f,c.PropertyPanel=g,c.Sidebar=p,c.Toolbar=E,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
2
- //# sourceMappingURL=index.umd.js.map
1
+ (function(E,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@huanban/rulego-editor-core")):typeof define=="function"&&define.amd?define(["exports","@huanban/rulego-editor-core"],h):(E=typeof globalThis<"u"?globalThis:E||self,h(E.RuleGoEditorUI={},E.RuleGoEditorCore))})(this,function(E,h){"use strict";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 n=document.createElement("span");n.className="rulego-sidebar__search-icon",n.setAttribute("aria-hidden","true"),n.innerHTML=h.getEditorToolbarIconSvg("search")||"";const o=document.createElement("input");o.type="text",o.className="rulego-sidebar__search",o.placeholder=this.options.searchPlaceholder,o.addEventListener("input",i=>{this.searchKeyword=i.target.value.toLowerCase();const l=this.core.store.getState().componentGroups;this.renderGroups(l)}),s.appendChild(n),s.appendChild(o),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 n=document.createElement("div");n.className="rulego-sidebar__empty",n.textContent=this.text("sidebar.noResults","无匹配组件"),t.appendChild(n);return}for(const n of s){const o=this.createGroupElement(n);t.appendChild(o)}}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 n=this.collapsedGroups.has(e.category),o=document.createElement("span");o.className=`rulego-sidebar__arrow ${n?"rulego-sidebar__arrow--collapsed":""}`,o.textContent="▼";const i=document.createElement("span");i.className="rulego-sidebar__group-label",i.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(o),s.appendChild(i),s.appendChild(l),s.addEventListener("click",()=>{this.collapsedGroups.has(e.category)?this.collapsedGroups.delete(e.category):this.collapsedGroups.add(e.category);const u=this.core.store.getState().componentGroups;this.renderGroups(u)}),t.appendChild(s),!n){const u=document.createElement("div");u.className="rulego-sidebar__component-list";for(const r of e.components){const a=this.createComponentElement(r,e.color);u.appendChild(a)}t.appendChild(u)}return t}createComponentElement(e,t){const s=document.createElement("div");s.className="rulego-sidebar__component",s.setAttribute("draggable","true");const n=this.componentLabel(e),o=this.text(`fields.${e.type}`,e.desc||n);s.title=o||n;const i=document.createElement("span");i.className="rulego-sidebar__component-color",i.style.backgroundColor=e.color||t||"#ccc";const l=document.createElement("span");return l.className="rulego-sidebar__component-name",l.textContent=n,s.appendChild(i),s.appendChild(l),s.addEventListener("dragstart",u=>{u.dataTransfer&&(u.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:n,color:e.color||t})),u.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 n=this.componentLabel(s).toLowerCase(),o=this.text(`fields.${s.type}`,s.desc||"").toLowerCase();return n.includes(this.searchKeyword)||s.type.toLowerCase().includes(this.searchKeyword)||o.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 h.i18nText(this.core.i18n,e,t)}componentLabel(e){return this.text(`components.${e.type}`,e.label||e.type.split("/").pop()||e.type)}}function v(d,e){if(e){if(typeof e=="string"){d.textContent=e;return}if(e.kind==="text"){d.textContent=e.value;return}e.kind==="trusted-svg"&&x(d,e.svg)}}function x(d,e){const t=document.createElement("template");t.innerHTML=e;const s=t.content.firstElementChild;if(!s||s.tagName.toLowerCase()!=="svg"){d.textContent="";return}C(s),d.replaceChildren(s)}function C(d){for(const e of Array.from(d.attributes)){const t=e.name.toLowerCase(),s=e.value.trim().toLowerCase();(t.startsWith("on")||s.startsWith("javascript:")||s.startsWith("data:text/html"))&&d.removeAttribute(e.name)}for(const e of Array.from(d.children)){const t=e.tagName.toLowerCase();if(t==="script"||t==="foreignobject"){e.remove();continue}C(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 n=document.createElement("span");n.className="rulego-toolbar__divider",this.rootEl.appendChild(n)}if(!t.icon&&t.divider)continue;const s=document.createElement("button");if(s.className="rulego-toolbar__button",s.title=t.title,v(s,t.icon),t.label){const n=document.createElement("span");n.className="rulego-toolbar__button-label",n.textContent=t.label,s.appendChild(n)}s.addEventListener("click",n=>{n.preventDefault(),n.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=h.getEditorToolbarIconSvg(e);return t?{kind:"trusted-svg",svg:t}:e}updateButtonStates(){for(const[e,t]of this.buttonElements){const s=this.getBuiltinButtons().find(n=>n.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 h.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,v(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,n=t.currentNodeModel;s&&n&&Object.keys(n).length>0&&this.showPanel(s,n)});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 n=this.createFieldElement(s,t);this.formContainer.appendChild(n)}}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 n=document.createElement("label");n.className="rulego-property-panel__label",n.textContent=e.label||e.name,e.desc&&(n.title=e.desc),s.appendChild(n);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 i=document.createElement("span");i.className="rulego-property-panel__desc",i.textContent=e.desc,s.appendChild(i)}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 n=`field-${e.name}-${Date.now()}`,o=document.createElement("input");o.type="checkbox",o.className="rulego-property-panel__checkbox",o.id=n,o.checked=!!this.getModelValue(e,t);const i=document.createElement("label");return i.className="rulego-property-panel__switch",i.htmlFor=n,o.addEventListener("change",()=>{this.handleFieldChange(e.name,o.checked)}),s.appendChild(o),s.appendChild(i),s}createSelectField(e,t){const s=document.createElement("select");s.className="rulego-property-panel__select",s.name=e.name;const n=String(this.getModelValue(e,t)??"");if(e.options&&e.options.length>0)for(const o of e.options.filter(h.isComponentFieldOption)){const i=document.createElement("option"),l=String(o.value??"");i.value=l,i.textContent=o.label,l===n&&(i.selected=!0),s.appendChild(i)}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 h.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 n=this.items.filter(o=>{const i=Array.isArray(o.target)?o.target:[o.target];return i.includes(s.type)||i.includes("all")});if(n.length===0){this.hide();return}this.renderMenu(n,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 n=e.closest(".lf-edge");return n?{type:"edge",id:n.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 i of e){const l=document.createElement("div");l.className="rulego-context-menu__item";const u=typeof i.disabled=="function"?i.disabled():i.disabled;if(u&&l.classList.add("rulego-context-menu__item--disabled"),i.icon){const a=document.createElement("span");a.className="rulego-context-menu__icon",v(a,i.icon),l.appendChild(a)}const r=document.createElement("span");if(r.className="rulego-context-menu__label",r.textContent=i.label,l.appendChild(r),u||l.addEventListener("click",()=>{this.currentContext&&i.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(l),i.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 n=!1;const o=requestAnimationFrame(()=>{n=!0,this.positionFrame=null;const i=this.menuEl;if(!i)return;const l=i.getBoundingClientRect(),u=h.clampContextMenuPosition({left:t,top:s},{width:l.width,height:l.height},{width:window.innerWidth,height:window.innerHeight});i.style.left=`${u.left}px`,i.style.top=`${u.top}px`,i.style.visibility="visible"});this.positionFrame=n?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 h.i18nText(this.core.i18n,e,t)}toolbarIcon(e){const t=h.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 n=document.createElement("div");n.className="rulego-debug-console__list",this.consoleEl.append(e,n),this.listEl=n,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:h.formatJsonBounded(h.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 y(d,e,t=0){const s=[];return d.forEach(n=>{var o;s.push({node:n,depth:t}),(o=n.children)!=null&&o.length&&e.has(n.key)&&s.push(...y(n.children,e,t+1))}),s}function L(d,e=""){e.split(/\s+/).filter(Boolean).forEach(t=>d.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 h.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=y(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 p=document.createElement("div");p.className="huanban_workflow_explorer__empty",p.textContent=this.options.emptyText||"暂无规则链",this.treeEl.replaceChildren(p);return}const s=this.options.virtualization,n=(s==null?void 0:s.enabled)!==!1,o=Math.max(1,(s==null?void 0:s.threshold)??h.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),i=Math.max(1,(s==null?void 0:s.itemHeight)??I),l=Math.max(1,(s==null?void 0:s.viewportHeight)??h.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),u=Math.max(0,(s==null?void 0:s.overscan)??h.DEFAULT_VIRTUAL_WINDOW_OVERSCAN),r=n&&t.length>o;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 p=t.findIndex(m=>{var c;return m.node.kind==="chain"&&((c=m.node.chain)==null?void 0:c.id)===e.activeChainId});if(p>=0){const m=Math.floor(this.virtualScrollTop/i),c=Math.ceil((this.virtualScrollTop+l)/i);p<m?this.virtualScrollTop=p*i:p>=c&&(this.virtualScrollTop=(p+1)*i-l),this.autoScrolledActiveChainId=e.activeChainId}}const a=h.calculateVirtualWindow({total:t.length,itemHeight:i,viewportHeight:l,scrollTop:this.virtualScrollTop,overscan:u});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 f=r?t.slice(a.start,a.end):t,b=document.createDocumentFragment();if(r){const p=document.createElement("div");p.className="huanban_workflow_explorer__virtual-canvas",p.style.height=`${a.totalHeight}px`;const m=document.createElement("div");m.className="huanban_workflow_explorer__virtual-items",m.style.transform=`translateY(${a.offsetTop}px)`,f.forEach(({node:c,depth:g},A)=>m.appendChild(this.createRow(c,g,e,a.start+A,t.length))),p.appendChild(m),b.appendChild(p),this.treeEl.scrollTop!==a.scrollTop&&(this.treeEl.scrollTop=a.scrollTop)}else f.forEach(({node:p,depth:m},c)=>b.appendChild(this.createRow(p,m,e,c,t.length)));this.treeEl.replaceChildren(b)}createRow(e,t,s,n,o){var p,m;const i=!!((p=e.children)!=null&&p.length),l=s.expandedKeys.includes(e.key),u=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}${u?" 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(o)),i&&r.setAttribute("aria-expanded",String(l)),e.kind==="chain"&&r.setAttribute("aria-selected",String(u)),r.title=e.chain?`${e.chain.name}
2
+ ${e.chain.id}`:e.label;const a=document.createElement("span");a.className=`huanban_workflow_explorer__chevron${i&&l?" is-open":""}`,a.setAttribute("aria-hidden","true");const f=document.createElement("span");f.className=`huanban_workflow_explorer__kind is-${e.kind}`,f.setAttribute("aria-hidden","true");const b=document.createElement("span");if(b.className="huanban_workflow_explorer__label",b.textContent=e.label,r.append(a,f,b),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;i?this.store.setExpanded(e.key,!l):e.chain&&((g=(c=this.options).onOpen)==null||g.call(c,e.chain))}),r}}E.ContextMenu=N,E.DebugConsole=S,E.PropertyPanel=k,E.Sidebar=_,E.Toolbar=w,E.WorkflowExplorer=T,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ [class^=rulego-],[class*=" rulego-"]{font-family:var(--rg-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);line-height:var(--rg-leading-tight, 1.45)}@media (prefers-reduced-motion: reduce){[class^=rulego-],[class*=" rulego-"],[class^=rulego-] *,[class*=" rulego-"] *,[class^=rulego-] *:before,[class^=rulego-] *:after,[class*=" rulego-"] *:before,[class*=" rulego-"] *:after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}}.rulego-sidebar{display:flex;flex-direction:column;height:100%;background:var(--rg-sidebar-bg, #ffffff);border-right:1px solid var(--rg-border-color, #e8e8e8);overflow:hidden;font-family:var(--rg-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);font-size:13px;transition:background-color .3s ease}.rulego-sidebar__search-wrapper{display:flex;align-items:center;padding:10px 12px;border-bottom:1px solid var(--rg-border-color, #e8e8e8);gap:6px}.rulego-sidebar__search-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;opacity:.5;flex-shrink:0}.rulego-sidebar__search-icon svg{display:block;width:16px;height:16px}.rulego-sidebar__search{width:100%;border:1px solid var(--rg-border-color, #d9d9d9);border-radius:6px;padding:6px 10px;font-size:12px;outline:none;background:var(--rg-input-bg, #fafafa);color:var(--rg-text-color, #333);transition:border-color .2s,box-shadow .2s}.rulego-sidebar__search:focus{border-color:var(--rg-primary-color, #4a90d9);box-shadow:0 0 0 2px #4a90d926}.rulego-sidebar__groups{flex:1;overflow-y:auto;padding:6px 0}.rulego-sidebar__empty{padding:24px 16px;text-align:center;color:var(--rg-text-secondary, #999);font-size:12px}.rulego-sidebar__group{margin-bottom:2px}.rulego-sidebar__group-header{display:flex;align-items:center;padding:8px 12px;cursor:pointer;-webkit-user-select:none;user-select:none;border-left:3px solid transparent;transition:background-color .15s;gap:6px}.rulego-sidebar__group-header:hover{background:var(--rg-hover-bg, #f5f5f5)}.rulego-sidebar__arrow{font-size:10px;transition:transform .2s;color:var(--rg-text-secondary, #999)}.rulego-sidebar__arrow--collapsed{transform:rotate(-90deg)}.rulego-sidebar__group-label{flex:1;font-weight:600;color:var(--rg-text-color, #333);font-size:12px}.rulego-sidebar__group-count{font-size:11px;color:var(--rg-text-secondary, #999);background:var(--rg-badge-bg, #f0f0f0);padding:1px 6px;border-radius:10px;min-width:20px;text-align:center}.rulego-sidebar__component-list{padding:2px 8px 4px 20px}.rulego-sidebar__component{display:flex;align-items:center;padding:6px 10px;margin:2px 0;border-radius:4px;cursor:grab;transition:background-color .15s,transform .1s;gap:8px}.rulego-sidebar__component:hover{background:var(--rg-hover-bg, #f0f7ff);transform:translate(2px)}.rulego-sidebar__component--dragging{opacity:.5;cursor:grabbing}.rulego-sidebar__component-color{width:4px;height:18px;border-radius:2px;flex-shrink:0}.rulego-sidebar__component-name{font-size:12px;color:var(--rg-text-color, #333);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.huanban_workflow_explorer{display:flex;flex-direction:column;min-height:0;height:100%;color:var(--rg-text-color, #20242a);background:var(--rg-sidebar-bg, #ffffff);font-family:var(--rg-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);font-size:12px}.huanban_workflow_explorer__search{position:relative;display:flex;align-items:center;min-height:34px;padding:5px 8px;border-bottom:1px solid var(--rg-border-color, #e8e8e8)}.huanban_workflow_explorer__search input{width:100%;height:26px;box-sizing:border-box;border:1px solid var(--rg-border-color, #d9d9d9);border-radius:5px;padding:0 10px 0 25px;color:inherit;background:var(--rg-input-bg, #fafafa);outline:none;font:inherit}.huanban_workflow_explorer__search input:focus{border-color:var(--rg-primary-color, #4a90d9);box-shadow:0 0 0 2px #4a90d924}.huanban_workflow_explorer__search_icon{position:absolute;left:16px;width:9px;height:9px;border:1.5px solid var(--rg-text-secondary, #697386);border-radius:50%;pointer-events:none}.huanban_workflow_explorer__search_icon:after{content:"";position:absolute;right:-4px;bottom:-2px;width:5px;height:1.5px;background:var(--rg-text-secondary, #697386);transform:rotate(45deg)}.huanban_workflow_explorer__tree{min-height:0;flex:1;overflow:auto;padding:4px 0}.huanban_workflow_explorer__row{display:flex;align-items:center;gap:5px;width:100%;height:28px;min-height:28px;box-sizing:border-box;border:0;border-left:2px solid transparent;padding-top:0;padding-right:8px;padding-bottom:0;color:inherit;background:transparent;font:inherit;text-align:left;cursor:pointer}.huanban_workflow_explorer__row:hover{background:var(--rg-hover-bg, #f5f5f5)}.huanban_workflow_explorer__row:focus-visible{outline:2px solid var(--rg-primary-color, #4a90d9);outline-offset:-2px}.huanban_workflow_explorer__row.is-active{border-left-color:var(--rg-primary-color, #4a90d9);color:var(--rg-primary-color, #4a90d9);background:var(--rg-active-bg, #eef6ff)}.huanban_workflow_explorer__row.is-section{font-weight:600}.huanban_workflow_explorer__chevron{width:8px;height:8px;flex:0 0 8px;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;opacity:.72;transform:rotate(-45deg);transition:transform .14s ease}.huanban_workflow_explorer__chevron.is-open{transform:rotate(45deg)}.huanban_workflow_explorer__row.is-chain .huanban_workflow_explorer__chevron{visibility:hidden}.huanban_workflow_explorer__kind{position:relative;width:13px;height:11px;flex:0 0 13px;border:1px solid var(--rg-text-secondary, #697386);border-radius:2px;opacity:.85}.huanban_workflow_explorer__kind.is-section,.huanban_workflow_explorer__kind.is-category{border-color:var(--rg-primary-color, #4a90d9);background:#4a90d91f}.huanban_workflow_explorer__kind.is-section:before,.huanban_workflow_explorer__kind.is-category:before{content:"";position:absolute;top:-4px;left:1px;width:6px;height:3px;border:1px solid var(--rg-primary-color, #4a90d9);border-bottom:0;border-radius:2px 2px 0 0;background:inherit}.huanban_workflow_explorer__kind.is-chain{border-color:var(--rg-primary-color, #4a90d9);border-radius:50%}.huanban_workflow_explorer__kind.is-chain:after{content:"";position:absolute;top:4px;left:3px;width:5px;height:1px;background:var(--rg-primary-color, #4a90d9)}.huanban_workflow_explorer__label{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.huanban_workflow_explorer__count{min-width:20px;padding:1px 6px;border-radius:999px;color:var(--rg-text-secondary, #697386);background:var(--rg-badge-bg, #f0f0f0);font-size:10px;line-height:16px;text-align:center;font-variant-numeric:tabular-nums}.huanban_workflow_explorer__status{width:7px;height:7px;flex:0 0 7px;border-radius:50%}.huanban_workflow_explorer__status.is-online{background:var(--rg-success-color, #24a148)}.huanban_workflow_explorer__status.is-offline{background:var(--rg-text-secondary, #a7adb7)}.huanban_workflow_explorer__empty{padding:22px 12px;color:var(--rg-text-secondary, #999);text-align:center}.huanban_workflow_explorer__virtual-canvas{position:relative;width:100%}.huanban_workflow_explorer__virtual-items{width:100%}.huanban_workflow_explorer__tree.is-virtualized .huanban_workflow_explorer__virtual-items{position:absolute;inset:0 0 auto;will-change:transform}.rulego-toolbar{display:flex;align-items:center;padding:0 var(--rg-space-md, 12px);background:var(--rg-toolbar-bg, #ffffff);border-bottom:1px solid var(--rg-border-color, #e8e8e8);gap:4px;flex-shrink:0;transition:background-color var(--rg-duration, .16s) var(--rg-ease-out, ease-out)}.rulego-toolbar__button{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;border-radius:6px;background:transparent;cursor:pointer;font-size:16px;color:var(--rg-text-color, #555);transition:background-color var(--rg-duration, .16s) var(--rg-ease-out, ease-out),color var(--rg-duration, .16s) var(--rg-ease-out, ease-out),transform var(--rg-duration-fast, .1s) var(--rg-ease-out, ease-out);gap:var(--rg-space-2xs, 4px)}.rulego-toolbar__button:hover:not(:disabled){background:var(--rg-hover-bg, #f0f0f0);color:var(--rg-primary-color, #4a90d9);transform:scale(1.05)}.rulego-toolbar__button:active:not(:disabled){transform:scale(.95)}.rulego-toolbar__button:disabled,.rulego-toolbar__button--disabled{opacity:.35;cursor:not-allowed}.rulego-toolbar__button-label{font-size:var(--rg-font-size-sm, 12px);margin-left:var(--rg-space-3xs, 2px)}.rulego-toolbar__button>svg{display:block;width:var(--rg-icon-size, 16px);height:var(--rg-icon-size, 16px);flex:0 0 var(--rg-icon-size, 16px)}.rulego-toolbar__divider{width:1px;height:20px;background:var(--rg-border-color, #e0e0e0);margin:0 var(--rg-space-xs, 6px)}.rulego-property-panel{display:flex;flex-direction:column;height:100%;background:var(--rg-panel-bg, #ffffff);border-left:1px solid var(--rg-border-color, #e8e8e8);overflow:hidden;font-family:var(--rg-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);font-size:13px;transition:background-color .3s ease}.rulego-property-panel--left{border-left:none;border-right:1px solid var(--rg-border-color, #e8e8e8)}.rulego-property-panel__header{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-bottom:1px solid var(--rg-border-color, #e8e8e8);flex-shrink:0}.rulego-property-panel__title{margin:0;font-size:14px;font-weight:600;color:var(--rg-text-color, #333)}.rulego-property-panel__close{border:none;background:none;cursor:pointer;font-size:16px;color:var(--rg-text-secondary, #999);padding:2px 6px;border-radius:4px;transition:background-color .15s,color .15s}.rulego-property-panel__close:hover{background:var(--rg-hover-bg, #f5f5f5);color:var(--rg-danger-color, #ff4d4f)}.rulego-property-panel__form{flex:1;overflow-y:auto;padding:12px 16px}.rulego-property-panel__section{margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid var(--rg-border-color, #f0f0f0)}.rulego-property-panel__field{margin-bottom:14px}.rulego-property-panel__label{display:block;margin-bottom:4px;font-size:12px;font-weight:500;color:var(--rg-text-color, #333)}.rulego-property-panel__desc{display:block;margin-top:3px;font-size:11px;color:var(--rg-text-secondary, #aaa);line-height:1.4}.rulego-property-panel__input,.rulego-property-panel__select{width:100%;padding:6px 10px;border:1px solid var(--rg-border-color, #d9d9d9);border-radius:6px;font-size:12px;background:var(--rg-input-bg, #fafafa);color:var(--rg-text-color, #333);outline:none;box-sizing:border-box;transition:border-color .2s,box-shadow .2s}.rulego-property-panel__input:focus,.rulego-property-panel__select:focus{border-color:var(--rg-primary-color, #4a90d9);box-shadow:0 0 0 2px #4a90d926}.rulego-property-panel__textarea{width:100%;padding:8px 10px;border:1px solid var(--rg-border-color, #d9d9d9);border-radius:6px;font-size:12px;background:var(--rg-input-bg, #fafafa);color:var(--rg-text-color, #333);outline:none;resize:vertical;min-height:80px;box-sizing:border-box;line-height:1.5;transition:border-color .2s,box-shadow .2s}.rulego-property-panel__textarea:focus{border-color:var(--rg-primary-color, #4a90d9);box-shadow:0 0 0 2px #4a90d926}.rulego-property-panel__switch-wrapper{display:flex;align-items:center}.rulego-property-panel__checkbox{display:none}.rulego-property-panel__switch{width:36px;height:20px;background:var(--rg-switch-off-bg, #ccc);border-radius:10px;position:relative;cursor:pointer;transition:background-color .2s}.rulego-property-panel__switch:after{content:"";width:16px;height:16px;background:#fff;border-radius:50%;position:absolute;top:2px;left:2px;transition:transform .2s;box-shadow:0 1px 3px #0003}.rulego-property-panel__checkbox:checked+.rulego-property-panel__switch{background:var(--rg-primary-color, #4a90d9)}.rulego-property-panel__checkbox:checked+.rulego-property-panel__switch:after{transform:translate(16px)}.rulego-context-menu{position:fixed;z-index:var(--hb-z-floating, 10000);min-width:160px;background:var(--rg-panel-bg, #ffffff);border:1px solid var(--rg-border-color, #e0e0e0);border-radius:8px;box-shadow:var(--rg-shadow-md, 0 6px 16px rgba(0, 0, 0, .12));padding:4px 0;font-family:var(--rg-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);font-size:13px;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}.rulego-context-menu__item{display:flex;align-items:center;padding:8px 14px;cursor:pointer;transition:background-color .12s;gap:8px}.rulego-context-menu__item:hover:not(.rulego-context-menu__item--disabled){background:var(--rg-hover-bg, #f0f7ff)}.rulego-context-menu__item--disabled{opacity:.4;cursor:not-allowed}.rulego-context-menu__icon{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;text-align:center;font-size:14px;flex-shrink:0}.rulego-context-menu__icon svg{display:block;width:16px;height:16px}.rulego-context-menu__label{flex:1;color:var(--rg-text-color, #333)}.rulego-context-menu__separator{height:1px;background:var(--rg-border-color, #eee);margin:4px 8px}.rulego-debug-console{display:flex;flex-direction:column;height:200px;background:var(--rg-panel-bg, rgba(255, 255, 255, .85));-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border-top:1px solid var(--rg-border-color, #e8e8e8);font-family:var(--rg-font-mono, ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace);font-size:12px}.rulego-debug-console__header{display:flex;justify-content:space-between;align-items:center;padding:6px 12px;background:var(--rg-toolbar-bg, #f5f5f5);border-bottom:1px solid var(--rg-border-color, #e8e8e8)}.rulego-debug-console__list{flex:1;overflow-y:auto;padding:8px;background:var(--rg-console-bg, #1e1e1e);color:var(--rg-console-text, #d4d4d4)}.rulego-debug-console__item{padding:2px 0;word-wrap:break-word;white-space:pre-wrap;border-bottom:1px solid rgba(255,255,255,.1)}:root{--hb-panel-bg: hsla(230, 20%, 100%, .85);--hb-panel-backdrop: blur(12px);--hb-panel-border: 1px solid hsla(230, 20%, 90%, .5);--hb-text-primary: hsla(230, 20%, 20%, 1);--hb-text-secondary: hsla(230, 10%, 40%, 1);--hb-node-bg: hsla(230, 20%, 95%, .8);--hb-node-normal-border: hsla(230, 20%, 80%, 1);--hb-node-selected-border: hsla(230, 80%, 60%, 1);--hb-node-processing: hsla(190, 80%, 50%, 1)}[data-theme=dark]{--hb-panel-bg: hsla(230, 20%, 10%, .85);--hb-panel-border: 1px solid hsla(230, 20%, 20%, .5);--hb-text-primary: hsla(230, 20%, 90%, 1);--hb-text-secondary: hsla(230, 10%, 60%, 1);--hb-node-bg: hsla(230, 20%, 15%, .8);--hb-node-normal-border: hsla(230, 20%, 30%, 1)}.hb-glass-panel{background:var(--hb-panel-bg);backdrop-filter:var(--hb-panel-backdrop);-webkit-backdrop-filter:var(--hb-panel-backdrop);border:var(--hb-panel-border);color:var(--hb-text-primary);border-radius:8px;box-shadow:0 4px 20px #0000000d}.hb-node-form{display:flex;flex-direction:column;gap:12px}
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@huanban/rulego-editor-ui",
3
- "version": "1.3.17",
3
+ "version": "1.4.0",
4
4
  "description": "RuleGo 编辑器 UI Kit - 纯 DOM 组件 (零框架依赖)",
5
5
  "type": "module",
6
- "main": "dist/index.cjs.js",
6
+ "main": "dist/index.cjs",
7
7
  "module": "dist/index.esm.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./dist/index.esm.js",
12
- "require": "./dist/index.cjs.js",
12
+ "require": "./dist/index.cjs",
13
13
  "types": "./dist/index.d.ts"
14
14
  },
15
15
  "./style.css": "./dist/style.css"
16
16
  },
17
17
  "files": [
18
18
  "dist/**/*.js",
19
+ "dist/**/*.cjs",
19
20
  "dist/**/*.d.ts",
20
21
  "dist/**/*.css",
21
22
  "!dist/**/*.js.map",
23
+ "!dist/**/*.cjs.map",
22
24
  "!dist/**/*.d.ts.map"
23
25
  ],
24
26
  "publishConfig": {
@@ -34,16 +36,19 @@
34
36
  "scripts": {
35
37
  "dev": "vite build --watch",
36
38
  "build": "vite build && tsc --emitDeclarationOnly --outDir dist",
39
+ "test": "vitest run",
37
40
  "lint": "tsc --noEmit",
38
41
  "clean": "rm -rf dist"
39
42
  },
40
43
  "peerDependencies": {
41
- "@huanban/rulego-editor-core": ">=0.1.0"
44
+ "@huanban/rulego-editor-core": ">=1.4.0 <2"
42
45
  },
43
46
  "devDependencies": {
44
- "@huanban/rulego-editor-core": "1.3.17",
47
+ "@huanban/rulego-editor-core": "1.4.0",
48
+ "jsdom": "16.7.0",
45
49
  "typescript": "^5.4.0",
46
- "vite": "^5.4.0"
50
+ "vite": "^5.4.0",
51
+ "vitest": "^2.0.0"
47
52
  },
48
53
  "keywords": [
49
54
  "rulego",
package/dist/index.cjs.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@huanban/rulego-editor-core");class m{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(n=>n.componentGroups).subscribe(n=>{this.renderGroups(n)})}mount(){if(this.rootEl=document.createElement("div"),this.rootEl.className="rulego-sidebar",this.rootEl.style.width=this.options.width,this.options.searchable){const n=document.createElement("div");n.className="rulego-sidebar__search-wrapper";const o=document.createElement("span");o.className="rulego-sidebar__search-icon",o.textContent="🔍";const s=document.createElement("input");s.type="text",s.className="rulego-sidebar__search",s.placeholder=this.options.searchPlaceholder,s.addEventListener("input",i=>{this.searchKeyword=i.target.value.toLowerCase();const a=this.core.store.getState().componentGroups;this.renderGroups(a)}),n.appendChild(o),n.appendChild(s),this.rootEl.appendChild(n)}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 n=this.filterGroups(e);if(n.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 n){const s=this.createGroupElement(o);t.appendChild(s)}}createGroupElement(e){const t=document.createElement("div");t.className="rulego-sidebar__group";const n=document.createElement("div");n.className="rulego-sidebar__group-header",n.style.borderLeftColor=e.color||"#ccc";const o=this.collapsedGroups.has(e.category),s=document.createElement("span");s.className=`rulego-sidebar__arrow ${o?"rulego-sidebar__arrow--collapsed":""}`,s.textContent="▼";const i=document.createElement("span");i.className="rulego-sidebar__group-label",i.textContent=this.text(`category.${e.category}`,e.label||e.category);const a=document.createElement("span");if(a.className="rulego-sidebar__group-count",a.textContent=`${e.components.length}`,n.appendChild(s),n.appendChild(i),n.appendChild(a),n.addEventListener("click",()=>{this.collapsedGroups.has(e.category)?this.collapsedGroups.delete(e.category):this.collapsedGroups.add(e.category);const l=this.core.store.getState().componentGroups;this.renderGroups(l)}),t.appendChild(n),!o){const l=document.createElement("div");l.className="rulego-sidebar__component-list";for(const u of e.components){const p=this.createComponentElement(u,e.color);l.appendChild(p)}t.appendChild(l)}return t}createComponentElement(e,t){const n=document.createElement("div");n.className="rulego-sidebar__component",n.setAttribute("draggable","true");const o=this.componentLabel(e),s=this.text(`fields.${e.type}`,e.desc||o);n.title=s||o;const i=document.createElement("span");i.className="rulego-sidebar__component-color",i.style.backgroundColor=e.color||t||"#ccc";const a=document.createElement("span");return a.className="rulego-sidebar__component-name",a.textContent=o,n.appendChild(i),n.appendChild(a),n.addEventListener("dragstart",l=>{l.dataTransfer&&(l.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:o,color:e.color||t})),l.dataTransfer.effectAllowed="copy"),n.classList.add("rulego-sidebar__component--dragging")}),n.addEventListener("dragend",()=>{n.classList.remove("rulego-sidebar__component--dragging")}),n}filterGroups(e){return this.searchKeyword?e.map(t=>({...t,components:t.components.filter(n=>{const o=this.componentLabel(n).toLowerCase(),s=this.text(`fields.${n.type}`,n.desc||"").toLowerCase();return o.includes(this.searchKeyword)||n.type.toLowerCase().includes(this.searchKeyword)||s.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 c.i18nText(this.core.i18n,e,t)}componentLabel(e){return this.text(`components.${e.type}`,e.label||e.type.split("/").pop()||e.type)}}function d(r,e){if(e){if(typeof e=="string"){r.textContent=e;return}if(e.kind==="text"){r.textContent=e.value;return}e.kind==="trusted-svg"&&E(r,e.svg)}}function E(r,e){const t=document.createElement("template");t.innerHTML=e;const n=t.content.firstElementChild;if(!n||n.tagName.toLowerCase()!=="svg"){r.textContent="";return}h(n),r.replaceChildren(n)}function h(r){for(const e of Array.from(r.attributes)){const t=e.name.toLowerCase(),n=e.value.trim().toLowerCase();(t.startsWith("on")||n.startsWith("javascript:")||n.startsWith("data:text/html"))&&r.removeAttribute(e.name)}for(const e of Array.from(r.children)){const t=e.tagName.toLowerCase();if(t==="script"||t==="foreignobject"){e.remove();continue}h(e)}}class g{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"},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 n=document.createElement("button");if(n.className="rulego-toolbar__button",n.title=t.title,d(n,t.icon),t.label){const o=document.createElement("span");o.className="rulego-toolbar__button-label",o.textContent=t.label,n.appendChild(o)}n.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),t.onClick()}),this.buttonElements.set(t.id,n),this.rootEl.appendChild(n)}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:"↩",title:this.text("toolbar.undo","撤销"),disabled:()=>!this.core.store.getState().canUndo,onClick:()=>this.core.eventBus.emit("editor:reset")},{id:"redo",icon:"↪",title:this.text("toolbar.redo","重做"),disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{}},{id:"delete",icon:"🗑",title:this.text("toolbar.delete","删除选中"),divider:!0,onClick:()=>this.core.eventBus.emit("editor:delete-selected")},{id:"save",icon:"💾",title:this.text("toolbar.save","保存"),onClick:()=>this.core.eventBus.emit("editor:save",{data:{},success:!1})},{id:"fullscreen",icon:"⛶",title:this.text("toolbar.fullscreen","全屏"),onClick:()=>this.core.eventBus.emit("editor:fullscreen")}];return this.options.showZoom&&e.push({id:"zoom-in",icon:"🔍+",title:this.text("toolbar.zoomIn","放大"),divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:"🔍-",title:this.text("toolbar.zoomOut","缩小"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:"🔲",title:this.text("toolbar.fitView","适应画布"),onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),e.push({id:"auto-layout",icon:"📐",title:this.text("toolbar.autoLayout","自动排版"),divider:!0,onClick:()=>this.core.eventBus.emit("editor:auto-layout")}),e}updateButtonStates(){for(const[e,t]of this.buttonElements){const n=this.getBuiltinButtons().find(o=>o.id===e);n&&typeof n.disabled=="function"&&(t.disabled=n.disabled(),t.classList.toggle("rulego-toolbar__button--disabled",t.disabled))}}getElement(){return this.rootEl}text(e,t){return c.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,d(t,e.icon),t.addEventListener("click",n=>{n.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class b{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 n=t.currentNodeView,o=t.currentNodeModel;n&&o&&Object.keys(o).length>0&&this.showPanel(n,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 n of e.fields){const o=this.createFieldElement(n,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 n=this.createTextField({name:"name",type:"string",defaultValue:"",label:this.text("panel.nodeName","节点名称"),desc:"",validate:"",fields:null},e);t.appendChild(n),this.formContainer.appendChild(t)}createFieldElement(e,t){const n=document.createElement("div");n.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),n.appendChild(o);let s;switch(e.type){case"bool":s=this.createBoolField(e,t);break;case"select":s=this.createSelectField(e,t);break;case"code":case"json":s=this.createTextareaField(e,t);break;case"int":s=this.createNumberField(e,t);break;default:s=this.createTextField(e,t);break}if(n.appendChild(s),e.desc){const i=document.createElement("span");i.className="rulego-property-panel__desc",i.textContent=e.desc,n.appendChild(i)}return n}createTextField(e,t){const n=document.createElement("input");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",()=>{this.handleFieldChange(e.name,n.value)}),n}createNumberField(e,t){const n=document.createElement("input");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",()=>{this.handleFieldChange(e.name,Number(n.value))}),n}createBoolField(e,t){const n=document.createElement("div");n.className="rulego-property-panel__switch-wrapper";const o=`field-${e.name}-${Date.now()}`,s=document.createElement("input");s.type="checkbox",s.className="rulego-property-panel__checkbox",s.id=o,s.checked=!!this.getModelValue(e,t);const i=document.createElement("label");return i.className="rulego-property-panel__switch",i.htmlFor=o,s.addEventListener("change",()=>{this.handleFieldChange(e.name,s.checked)}),n.appendChild(s),n.appendChild(i),n}createSelectField(e,t){const n=document.createElement("select");n.className="rulego-property-panel__select",n.name=e.name;const o=String(this.getModelValue(e,t)??"");if(e.options&&e.options.length>0)for(const s of e.options){const i=document.createElement("option");i.value=s.value,i.textContent=s.label,s.value===o&&(i.selected=!0),n.appendChild(i)}return n.addEventListener("change",()=>{this.handleFieldChange(e.name,n.value)}),n}createTextareaField(e,t){const n=document.createElement("textarea");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",()=>{this.handleFieldChange(e.name,n.value)}),n}getModelValue(e,t){const n=t.configuration;return n&&e.name in n?n[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,n){n&&(this.currentNodeId=n),this.showPanel(e,t)}hide(){this.clearPanel()}text(e,t){return c.i18nText(this.core.i18n,e,t)}}class C{constructor(e,t){this.menuEl=null,this.currentContext=null,this.outsideClickHandler=null,this.container=e,this.core=t.core;const n=t.includeBuiltin!==!1?this.getBuiltinItems():[];this.items=[...n,...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.container.addEventListener("contextmenu",e=>{e.preventDefault(),this.handleContextMenu(e)}),this.outsideClickHandler=e=>{this.menuEl&&!this.menuEl.contains(e.target)&&this.hide()},document.addEventListener("click",this.outsideClickHandler),document.addEventListener("keydown",e=>{e.key==="Escape"&&this.hide()})}destroy(){this.outsideClickHandler&&(document.removeEventListener("click",this.outsideClickHandler),this.outsideClickHandler=null),this.menuEl&&this.menuEl.parentNode&&this.menuEl.parentNode.removeChild(this.menuEl),this.menuEl=null}handleContextMenu(e){const t=e.target,n=this.resolveContext(t,e);this.currentContext=n;const o=this.items.filter(s=>{const i=Array.isArray(s.target)?s.target:[s.target];return i.includes(n.type)||i.includes("all")});o.length!==0&&this.renderMenu(o,e.clientX,e.clientY)}resolveContext(e,t){const n=e.closest(".lf-node");if(n)return{type:"node",id:n.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,n){if(this.menuEl){this.menuEl.replaceChildren();for(const o of e){const s=document.createElement("div");s.className="rulego-context-menu__item";const i=typeof o.disabled=="function"?o.disabled():o.disabled;if(i&&s.classList.add("rulego-context-menu__item--disabled"),o.icon){const l=document.createElement("span");l.className="rulego-context-menu__icon",d(l,o.icon),s.appendChild(l)}const a=document.createElement("span");if(a.className="rulego-context-menu__label",a.textContent=o.label,s.appendChild(a),i||s.addEventListener("click",()=>{this.currentContext&&o.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(s),o.separator){const l=document.createElement("div");l.className="rulego-context-menu__separator",this.menuEl.appendChild(l)}}this.menuEl.style.left=`${t}px`,this.menuEl.style.top=`${n}px`,this.menuEl.style.display="block",requestAnimationFrame(()=>{if(!this.menuEl)return;const o=this.menuEl.getBoundingClientRect();o.right>window.innerWidth&&(this.menuEl.style.left=`${t-o.width}px`),o.bottom>window.innerHeight&&(this.menuEl.style.top=`${n-o.height}px`)})}}hide(){this.menuEl&&(this.menuEl.style.display="none"),this.currentContext=null}getBuiltinItems(){return[{id:"edit",label:this.text("contextMenu.edit","编辑"),icon:"✏️",target:"node",onClick:e=>{e.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:this.text("contextMenu.delete","删除"),icon:"🗑️",target:["node","edge"],separator:!0,onClick:e=>{e.id&&this.core.eventBus.emit("node:delete",{id:e.id})}},{id:"copy",label:this.text("contextMenu.copy","复制"),icon:"📋",target:"node",onClick:()=>{}},{id:"select-all",label:this.text("contextMenu.selectAll","全选"),icon:"⬜",target:"canvas",onClick:()=>{}}]}addItem(e){this.items.push(e)}text(e,t){return c.i18nText(this.core.i18n,e,t)}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}class f{constructor(e,t){this.logs=[],this.consoleEl=null,this.listEl=null,this.container=e,this.core=t.core,this.maxLogs=t.maxLogs||1e3,this.mount(),this.bindEvents()}t(e,t){const n=this.core.i18n.t(e);return n&&n!==e?n: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 n=document.createElement("button");n.className="rulego-debug-console__clear",n.textContent=this.t("editor.debugConsole.clear","清除"),e.append(t,n);const o=document.createElement("div");o.className="rulego-debug-console__list",this.consoleEl.append(e,o),this.listEl=o,this.container.appendChild(this.consoleEl),n.addEventListener("click",()=>this.clear())}bindEvents(){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 n=typeof e=="string"?e:c.formatJsonBounded(c.redactSensitive(e),{maxChars:2e4,space:0});t.textContent=`[${new Date().toLocaleTimeString()}] ${n}`,this.listEl.appendChild(t),this.listEl.scrollTop=this.listEl.scrollHeight}clear(){this.logs=[],this.listEl&&this.listEl.replaceChildren()}destroy(){this.consoleEl&&this.consoleEl.parentNode&&this.consoleEl.parentNode.removeChild(this.consoleEl)}}exports.ContextMenu=C;exports.DebugConsole=f;exports.PropertyPanel=b;exports.Sidebar=m;exports.Toolbar=g;
2
- //# sourceMappingURL=index.cjs.js.map