@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/README.md +13 -5
- package/dist/components/ContextMenu.d.ts +8 -100
- package/dist/components/DebugConsole.d.ts +1 -1
- package/dist/components/PropertyPanel.d.ts +0 -117
- package/dist/components/Sidebar.d.ts +0 -87
- package/dist/components/Toolbar.d.ts +5 -74
- package/dist/components/WorkflowExplorer.d.ts +45 -0
- package/dist/components/safeIcon.d.ts +0 -5
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +4 -37
- package/dist/index.esm.js +393 -232
- package/dist/index.umd.js +2 -2
- package/dist/style.css +1 -0
- package/package.json +11 -6
- package/dist/index.cjs.js +0 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @description @huanban/editor-ui 包入口 — 纯 DOM UI 组件集合
|
|
4
|
-
*
|
|
5
|
-
* 本包提供零框架依赖的 UI 组件, 适用于:
|
|
6
|
-
* - 原生 JS 项目直接使用
|
|
7
|
-
* - 作为 @huanban/rulego-editor-vue 和 @huanban/rulego-editor-react 的底层 UI 复用层
|
|
8
|
-
* - 需要自定义 UI 的高级用户作为参考实现
|
|
9
|
-
*
|
|
10
|
-
* 使用方式 (原生 JS):
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { EditorCore } from '@huanban/rulego-editor-core'
|
|
13
|
-
* import { Sidebar, Toolbar, PropertyPanel, ContextMenu } from '@huanban/editor-ui'
|
|
14
|
-
* import '@huanban/editor-ui/style.css'
|
|
15
|
-
*
|
|
16
|
-
* const core = new EditorCore(options)
|
|
17
|
-
* const sidebar = new Sidebar(sidebarEl, { core })
|
|
18
|
-
* const toolbar = new Toolbar(toolbarEl, { core })
|
|
19
|
-
* const panel = new PropertyPanel(panelEl, { core })
|
|
20
|
-
* const menu = new ContextMenu(canvasEl, { core })
|
|
21
|
-
*
|
|
22
|
-
* // 卸载时
|
|
23
|
-
* sidebar.destroy(); toolbar.destroy(); panel.destroy(); menu.destroy()
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* 使用方式 (按需引入):
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // 只需要侧边栏
|
|
29
|
-
* import { Sidebar } from '@huanban/editor-ui'
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @see Sidebar — 组件分类侧边栏
|
|
33
|
-
* @see Toolbar — 编辑器工具栏
|
|
34
|
-
* @see PropertyPanel — 节点属性编辑面板
|
|
35
|
-
* @see ContextMenu — 右键上下文菜单
|
|
36
|
-
*/
|
|
1
|
+
import './styles/index.css';
|
|
2
|
+
import './styles/theme.css';
|
|
37
3
|
export { Sidebar } from './components/Sidebar';
|
|
38
4
|
export type { SidebarOptions } from './components/Sidebar';
|
|
39
5
|
export { Toolbar } from './components/Toolbar';
|
|
@@ -44,4 +10,5 @@ export type { PropertyPanelOptions } from './components/PropertyPanel';
|
|
|
44
10
|
export { ContextMenu } from './components/ContextMenu';
|
|
45
11
|
export type { ContextMenuOptions, MenuItem, MenuItemType, MenuContext, } from './components/ContextMenu';
|
|
46
12
|
export { DebugConsole, type DebugConsoleOptions } from './components/DebugConsole';
|
|
47
|
-
|
|
13
|
+
export { WorkflowExplorer } from './components/WorkflowExplorer';
|
|
14
|
+
export type { WorkflowExplorerOptions } from './components/WorkflowExplorer';
|