@huanban/rulego-editor-ui 1.1.0 → 1.1.2
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/LICENSE +190 -0
- package/dist/components/ContextMenu.d.ts +4 -2
- package/dist/components/DebugConsole.d.ts +21 -0
- package/dist/components/PropertyPanel.d.ts +1 -0
- package/dist/components/Sidebar.d.ts +2 -0
- package/dist/components/Toolbar.d.ts +4 -2
- package/dist/components/safeIcon.d.ts +13 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +219 -125
- package/dist/index.umd.js +1 -1
- package/package.json +11 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024 OpenClaw
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
25
|
+
import { type SafeIcon } from './safeIcon';
|
|
25
26
|
/**
|
|
26
27
|
* 菜单项类型
|
|
27
28
|
*/
|
|
@@ -34,8 +35,8 @@ export interface MenuItem {
|
|
|
34
35
|
id: string;
|
|
35
36
|
/** 显示文本 */
|
|
36
37
|
label: string;
|
|
37
|
-
/**
|
|
38
|
-
icon?: string;
|
|
38
|
+
/** 图标。字符串按纯文本渲染;SVG 必须显式传 trusted-svg。 */
|
|
39
|
+
icon?: string | SafeIcon;
|
|
39
40
|
/** 适用的目标类型 */
|
|
40
41
|
target: MenuItemType | MenuItemType[];
|
|
41
42
|
/** 是否禁用 (可动态) */
|
|
@@ -132,6 +133,7 @@ export declare class ContextMenu {
|
|
|
132
133
|
* @param item - 菜单项定义
|
|
133
134
|
*/
|
|
134
135
|
addItem(item: MenuItem): void;
|
|
136
|
+
private text;
|
|
135
137
|
/**
|
|
136
138
|
* 移除菜单项
|
|
137
139
|
* @param id - 菜单项 ID
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
2
|
+
export interface DebugConsoleOptions {
|
|
3
|
+
core: EditorCore;
|
|
4
|
+
maxLogs?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class DebugConsole {
|
|
7
|
+
private container;
|
|
8
|
+
private core;
|
|
9
|
+
private maxLogs;
|
|
10
|
+
private logs;
|
|
11
|
+
private consoleEl;
|
|
12
|
+
private listEl;
|
|
13
|
+
constructor(container: HTMLElement, options: DebugConsoleOptions);
|
|
14
|
+
private t;
|
|
15
|
+
private mount;
|
|
16
|
+
private bindEvents;
|
|
17
|
+
appendLog(msg: any): void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=DebugConsole.d.ts.map
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
22
|
+
import { type SafeIcon } from './safeIcon';
|
|
22
23
|
/**
|
|
23
24
|
* 工具栏按钮定义
|
|
24
25
|
*/
|
|
@@ -27,8 +28,8 @@ export interface ToolbarButton {
|
|
|
27
28
|
id: string;
|
|
28
29
|
/** 按钮显示文本 (可选, 图标模式下可不设) */
|
|
29
30
|
label?: string;
|
|
30
|
-
/**
|
|
31
|
-
icon: string;
|
|
31
|
+
/** 按钮图标。字符串按纯文本渲染;SVG 必须显式传 trusted-svg。 */
|
|
32
|
+
icon: string | SafeIcon;
|
|
32
33
|
/** 提示文本 (tooltip) */
|
|
33
34
|
title: string;
|
|
34
35
|
/** 是否禁用 (可以是函数, 动态判断) */
|
|
@@ -96,6 +97,7 @@ export declare class Toolbar {
|
|
|
96
97
|
* 获取根 DOM 元素
|
|
97
98
|
*/
|
|
98
99
|
getElement(): HTMLElement | null;
|
|
100
|
+
private text;
|
|
99
101
|
/**
|
|
100
102
|
* 动态添加自定义按钮
|
|
101
103
|
* @param button - 按钮定义
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file components/safeIcon.ts
|
|
3
|
+
* @description Safe icon rendering for DOM UI components.
|
|
4
|
+
*/
|
|
5
|
+
export type SafeIcon = {
|
|
6
|
+
kind: 'text';
|
|
7
|
+
value: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'trusted-svg';
|
|
10
|
+
svg: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function appendSafeIcon(parent: HTMLElement, icon: SafeIcon | string | undefined): void;
|
|
13
|
+
//# sourceMappingURL=safeIcon.d.ts.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class u{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.core.i18n.t("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.innerHTML="🔍";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 l=this.core.store.getState().componentGroups;this.renderGroups(l)}),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.innerHTML="";const n=this.filterGroups(e);if(n.length===0){const o=document.createElement("div");o.className="rulego-sidebar__empty",o.textContent=this.core.i18n.t("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=e.label;const l=document.createElement("span");if(l.className="rulego-sidebar__group-count",l.textContent=`${e.components.length}`,n.appendChild(s),n.appendChild(i),n.appendChild(l),n.addEventListener("click",()=>{this.collapsedGroups.has(e.category)?this.collapsedGroups.delete(e.category):this.collapsedGroups.add(e.category);const r=this.core.store.getState().componentGroups;this.renderGroups(r)}),t.appendChild(n),!o){const r=document.createElement("div");r.className="rulego-sidebar__component-list";for(const c of e.components){const d=this.createComponentElement(c,e.color);r.appendChild(d)}t.appendChild(r)}return t}createComponentElement(e,t){const n=document.createElement("div");n.className="rulego-sidebar__component",n.setAttribute("draggable","true"),n.title=e.desc||e.label;const o=document.createElement("span");o.className="rulego-sidebar__component-color",o.style.backgroundColor=e.color||t||"#ccc";const s=document.createElement("span");return s.className="rulego-sidebar__component-name",s.textContent=e.label,n.appendChild(o),n.appendChild(s),n.addEventListener("dragstart",i=>{i.dataTransfer&&(i.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:e.label,color:e.color||t})),i.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=>n.label.toLowerCase().includes(this.searchKeyword)||n.type.toLowerCase().includes(this.searchKeyword)||n.desc&&n.desc.toLowerCase().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}}class h{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,n.innerHTML=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=this.core.i18n,t=[{id:"undo",icon:"↩",title:e.t("toolbar.undo")||"撤销",disabled:()=>!this.core.store.getState().canUndo,onClick:()=>this.core.eventBus.emit("editor:reset")},{id:"redo",icon:"↪",title:e.t("toolbar.redo")||"重做",disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{}},{id:"delete",icon:"🗑",title:e.t("toolbar.delete")||"删除选中",divider:!0,onClick:()=>this.core.eventBus.emit("editor:delete-selected")},{id:"save",icon:"💾",title:e.t("toolbar.save")||"保存",onClick:()=>this.core.eventBus.emit("editor:save",{data:{},success:!1})},{id:"fullscreen",icon:"⛶",title:e.t("toolbar.fullscreen")||"全屏",onClick:()=>this.core.eventBus.emit("editor:fullscreen")}];return this.options.showZoom&&t.push({id:"zoom-in",icon:"🔍+",title:e.t("toolbar.zoomIn")||"放大",divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:"🔍-",title:e.t("toolbar.zoomOut")||"缩小",onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:"🔲",title:e.t("toolbar.fitView")||"适应画布",onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),t.push({id:"auto-layout",icon:"📐",title:e.t("toolbar.autoLayout")||"自动排版",divider:!0,onClick:()=>this.core.eventBus.emit("editor:auto-layout")}),t}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}addButton(e){if(!this.rootEl)return;const t=document.createElement("button");t.className="rulego-toolbar__button",t.title=e.title,t.innerHTML=e.icon,t.addEventListener("click",n=>{n.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class p{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.core.i18n.t("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.innerHTML="",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.innerHTML="",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.core.i18n.t("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()}}class m{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.innerHTML="";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 r=document.createElement("span");r.className="rulego-context-menu__icon",r.innerHTML=o.icon,s.appendChild(r)}const l=document.createElement("span");if(l.className="rulego-context-menu__label",l.textContent=o.label,s.appendChild(l),i||s.addEventListener("click",()=>{this.currentContext&&o.onClick(this.currentContext),this.hide()}),this.menuEl.appendChild(s),o.separator){const r=document.createElement("div");r.className="rulego-context-menu__separator",this.menuEl.appendChild(r)}}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(){const e=this.core.i18n;return[{id:"edit",label:e.t("contextMenu.edit")||"编辑",icon:"✏️",target:"node",onClick:t=>{t.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:e.t("contextMenu.delete")||"删除",icon:"🗑️",target:["node","edge"],separator:!0,onClick:t=>{t.id&&this.core.eventBus.emit("node:delete",{id:t.id})}},{id:"copy",label:e.t("contextMenu.copy")||"复制",icon:"📋",target:"node",onClick:()=>{}},{id:"select-all",label:e.t("contextMenu.selectAll")||"全选",icon:"⬜",target:"canvas",onClick:()=>{}}]}addItem(e){this.items.push(e)}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}exports.ContextMenu=m;exports.PropertyPanel=p;exports.Sidebar=u;exports.Toolbar=h;
|
|
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
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,10 @@ export { Sidebar } from './components/Sidebar';
|
|
|
38
38
|
export type { SidebarOptions } from './components/Sidebar';
|
|
39
39
|
export { Toolbar } from './components/Toolbar';
|
|
40
40
|
export type { ToolbarOptions, ToolbarButton } from './components/Toolbar';
|
|
41
|
+
export type { SafeIcon } from './components/safeIcon';
|
|
41
42
|
export { PropertyPanel } from './components/PropertyPanel';
|
|
42
43
|
export type { PropertyPanelOptions } from './components/PropertyPanel';
|
|
43
44
|
export { ContextMenu } from './components/ContextMenu';
|
|
44
45
|
export type { ContextMenuOptions, MenuItem, MenuItemType, MenuContext, } from './components/ContextMenu';
|
|
46
|
+
export { DebugConsole, type DebugConsoleOptions } from './components/DebugConsole';
|
|
45
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { i18nText as c, formatJsonBounded as m, redactSensitive as E } from "@huanban/rulego-editor-core";
|
|
2
|
+
class C {
|
|
2
3
|
constructor(e, t) {
|
|
3
4
|
this.collapsedGroups = /* @__PURE__ */ new Set(), this.searchKeyword = "", this.rootEl = null, this.unsubscribe = null, this.container = e, this.core = t.core, this.options = {
|
|
4
5
|
core: t.core,
|
|
5
6
|
searchable: t.searchable ?? !0,
|
|
6
7
|
defaultCollapsed: t.defaultCollapsed ?? !1,
|
|
7
|
-
searchPlaceholder: t.searchPlaceholder || this.
|
|
8
|
+
searchPlaceholder: t.searchPlaceholder || this.text("sidebar.searchPlaceholder", "搜索组件..."),
|
|
8
9
|
width: t.width ?? "220px"
|
|
9
10
|
}, this.mount(), this.unsubscribe = this.core.store.select(
|
|
10
11
|
(n) => n.componentGroups
|
|
@@ -24,14 +25,14 @@ class u {
|
|
|
24
25
|
if (this.rootEl = document.createElement("div"), this.rootEl.className = "rulego-sidebar", this.rootEl.style.width = this.options.width, this.options.searchable) {
|
|
25
26
|
const n = document.createElement("div");
|
|
26
27
|
n.className = "rulego-sidebar__search-wrapper";
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
28
|
+
const s = document.createElement("span");
|
|
29
|
+
s.className = "rulego-sidebar__search-icon", s.textContent = "🔍";
|
|
30
|
+
const o = document.createElement("input");
|
|
31
|
+
o.type = "text", o.className = "rulego-sidebar__search", o.placeholder = this.options.searchPlaceholder, o.addEventListener("input", (i) => {
|
|
31
32
|
this.searchKeyword = i.target.value.toLowerCase();
|
|
32
|
-
const
|
|
33
|
-
this.renderGroups(
|
|
34
|
-
}), n.appendChild(
|
|
33
|
+
const a = this.core.store.getState().componentGroups;
|
|
34
|
+
this.renderGroups(a);
|
|
35
|
+
}), n.appendChild(s), n.appendChild(o), this.rootEl.appendChild(n);
|
|
35
36
|
}
|
|
36
37
|
const e = document.createElement("div");
|
|
37
38
|
e.className = "rulego-sidebar__groups", this.rootEl.appendChild(e), this.container.appendChild(this.rootEl);
|
|
@@ -55,16 +56,16 @@ class u {
|
|
|
55
56
|
if (!this.rootEl) return;
|
|
56
57
|
const t = this.rootEl.querySelector(".rulego-sidebar__groups");
|
|
57
58
|
if (!t) return;
|
|
58
|
-
t.
|
|
59
|
+
t.replaceChildren();
|
|
59
60
|
const n = this.filterGroups(e);
|
|
60
61
|
if (n.length === 0) {
|
|
61
|
-
const
|
|
62
|
-
|
|
62
|
+
const s = document.createElement("div");
|
|
63
|
+
s.className = "rulego-sidebar__empty", s.textContent = this.text("sidebar.noResults", "无匹配组件"), t.appendChild(s);
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
65
|
-
for (const
|
|
66
|
-
const
|
|
67
|
-
t.appendChild(
|
|
66
|
+
for (const s of n) {
|
|
67
|
+
const o = this.createGroupElement(s);
|
|
68
|
+
t.appendChild(o);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
@@ -77,23 +78,23 @@ class u {
|
|
|
77
78
|
t.className = "rulego-sidebar__group";
|
|
78
79
|
const n = document.createElement("div");
|
|
79
80
|
n.className = "rulego-sidebar__group-header", n.style.borderLeftColor = e.color || "#ccc";
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const s = this.collapsedGroups.has(e.category), o = document.createElement("span");
|
|
82
|
+
o.className = `rulego-sidebar__arrow ${s ? "rulego-sidebar__arrow--collapsed" : ""}`, o.textContent = "▼";
|
|
82
83
|
const i = document.createElement("span");
|
|
83
|
-
i.className = "rulego-sidebar__group-label", i.textContent = e.label;
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
84
|
+
i.className = "rulego-sidebar__group-label", i.textContent = this.text(`category.${e.category}`, e.label || e.category);
|
|
85
|
+
const a = document.createElement("span");
|
|
86
|
+
if (a.className = "rulego-sidebar__group-count", a.textContent = `${e.components.length}`, n.appendChild(o), n.appendChild(i), n.appendChild(a), n.addEventListener("click", () => {
|
|
86
87
|
this.collapsedGroups.has(e.category) ? this.collapsedGroups.delete(e.category) : this.collapsedGroups.add(e.category);
|
|
87
|
-
const
|
|
88
|
-
this.renderGroups(
|
|
89
|
-
}), t.appendChild(n), !
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
for (const
|
|
93
|
-
const
|
|
94
|
-
|
|
88
|
+
const l = this.core.store.getState().componentGroups;
|
|
89
|
+
this.renderGroups(l);
|
|
90
|
+
}), t.appendChild(n), !s) {
|
|
91
|
+
const l = document.createElement("div");
|
|
92
|
+
l.className = "rulego-sidebar__component-list";
|
|
93
|
+
for (const u of e.components) {
|
|
94
|
+
const p = this.createComponentElement(u, e.color);
|
|
95
|
+
l.appendChild(p);
|
|
95
96
|
}
|
|
96
|
-
t.appendChild(
|
|
97
|
+
t.appendChild(l);
|
|
97
98
|
}
|
|
98
99
|
return t;
|
|
99
100
|
}
|
|
@@ -105,17 +106,19 @@ class u {
|
|
|
105
106
|
*/
|
|
106
107
|
createComponentElement(e, t) {
|
|
107
108
|
const n = document.createElement("div");
|
|
108
|
-
n.className = "rulego-sidebar__component", n.setAttribute("draggable", "true")
|
|
109
|
-
const o =
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
n.className = "rulego-sidebar__component", n.setAttribute("draggable", "true");
|
|
110
|
+
const s = this.componentLabel(e), o = this.text(`fields.${e.type}`, e.desc || s);
|
|
111
|
+
n.title = o || s;
|
|
112
|
+
const i = document.createElement("span");
|
|
113
|
+
i.className = "rulego-sidebar__component-color", i.style.backgroundColor = e.color || t || "#ccc";
|
|
114
|
+
const a = document.createElement("span");
|
|
115
|
+
return a.className = "rulego-sidebar__component-name", a.textContent = s, n.appendChild(i), n.appendChild(a), n.addEventListener("dragstart", (l) => {
|
|
116
|
+
l.dataTransfer && (l.dataTransfer.setData("application/rulego-component", JSON.stringify({
|
|
114
117
|
type: e.type,
|
|
115
118
|
category: e.category,
|
|
116
|
-
label:
|
|
119
|
+
label: s,
|
|
117
120
|
color: e.color || t
|
|
118
|
-
})),
|
|
121
|
+
})), l.dataTransfer.effectAllowed = "copy"), n.classList.add("rulego-sidebar__component--dragging");
|
|
119
122
|
}), n.addEventListener("dragend", () => {
|
|
120
123
|
n.classList.remove("rulego-sidebar__component--dragging");
|
|
121
124
|
}), n;
|
|
@@ -131,9 +134,10 @@ class u {
|
|
|
131
134
|
filterGroups(e) {
|
|
132
135
|
return this.searchKeyword ? e.map((t) => ({
|
|
133
136
|
...t,
|
|
134
|
-
components: t.components.filter(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
components: t.components.filter((n) => {
|
|
138
|
+
const s = this.componentLabel(n).toLowerCase(), o = this.text(`fields.${n.type}`, n.desc || "").toLowerCase();
|
|
139
|
+
return s.includes(this.searchKeyword) || n.type.toLowerCase().includes(this.searchKeyword) || o.includes(this.searchKeyword);
|
|
140
|
+
})
|
|
137
141
|
})).filter((t) => t.components.length > 0) : e;
|
|
138
142
|
}
|
|
139
143
|
// ============================================================
|
|
@@ -167,8 +171,51 @@ class u {
|
|
|
167
171
|
getElement() {
|
|
168
172
|
return this.rootEl;
|
|
169
173
|
}
|
|
174
|
+
text(e, t) {
|
|
175
|
+
return c(this.core.i18n, e, t);
|
|
176
|
+
}
|
|
177
|
+
componentLabel(e) {
|
|
178
|
+
return this.text(`components.${e.type}`, e.label || e.type.split("/").pop() || e.type);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function d(r, e) {
|
|
182
|
+
if (e) {
|
|
183
|
+
if (typeof e == "string") {
|
|
184
|
+
r.textContent = e;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (e.kind === "text") {
|
|
188
|
+
r.textContent = e.value;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
e.kind === "trusted-svg" && g(r, e.svg);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function g(r, e) {
|
|
195
|
+
const t = document.createElement("template");
|
|
196
|
+
t.innerHTML = e;
|
|
197
|
+
const n = t.content.firstElementChild;
|
|
198
|
+
if (!n || n.tagName.toLowerCase() !== "svg") {
|
|
199
|
+
r.textContent = "";
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
h(n), r.replaceChildren(n);
|
|
203
|
+
}
|
|
204
|
+
function h(r) {
|
|
205
|
+
for (const e of Array.from(r.attributes)) {
|
|
206
|
+
const t = e.name.toLowerCase(), n = e.value.trim().toLowerCase();
|
|
207
|
+
(t.startsWith("on") || n.startsWith("javascript:") || n.startsWith("data:text/html")) && r.removeAttribute(e.name);
|
|
208
|
+
}
|
|
209
|
+
for (const e of Array.from(r.children)) {
|
|
210
|
+
const t = e.tagName.toLowerCase();
|
|
211
|
+
if (t === "script" || t === "foreignobject") {
|
|
212
|
+
e.remove();
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
h(e);
|
|
216
|
+
}
|
|
170
217
|
}
|
|
171
|
-
class
|
|
218
|
+
class f {
|
|
172
219
|
constructor(e, t) {
|
|
173
220
|
this.rootEl = null, this.unsubscribe = null, this.buttonElements = /* @__PURE__ */ new Map(), this.container = e, this.core = t.core, this.options = {
|
|
174
221
|
core: t.core,
|
|
@@ -198,17 +245,17 @@ class h {
|
|
|
198
245
|
}), e.push(...this.options.extraButtons));
|
|
199
246
|
for (const t of e) {
|
|
200
247
|
if (t.divider) {
|
|
201
|
-
const
|
|
202
|
-
|
|
248
|
+
const s = document.createElement("span");
|
|
249
|
+
s.className = "rulego-toolbar__divider", this.rootEl.appendChild(s);
|
|
203
250
|
}
|
|
204
251
|
if (!t.icon && t.divider) continue;
|
|
205
252
|
const n = document.createElement("button");
|
|
206
|
-
if (n.className = "rulego-toolbar__button", n.title = t.title, n
|
|
207
|
-
const
|
|
208
|
-
|
|
253
|
+
if (n.className = "rulego-toolbar__button", n.title = t.title, d(n, t.icon), t.label) {
|
|
254
|
+
const s = document.createElement("span");
|
|
255
|
+
s.className = "rulego-toolbar__button-label", s.textContent = t.label, n.appendChild(s);
|
|
209
256
|
}
|
|
210
|
-
n.addEventListener("click", (
|
|
211
|
-
|
|
257
|
+
n.addEventListener("click", (s) => {
|
|
258
|
+
s.preventDefault(), s.stopPropagation(), t.onClick();
|
|
212
259
|
}), this.buttonElements.set(t.id, n), this.rootEl.appendChild(n);
|
|
213
260
|
}
|
|
214
261
|
this.container.appendChild(this.rootEl), this.updateButtonStates();
|
|
@@ -227,18 +274,18 @@ class h {
|
|
|
227
274
|
* @returns 内置按钮定义数组
|
|
228
275
|
*/
|
|
229
276
|
getBuiltinButtons() {
|
|
230
|
-
const e =
|
|
277
|
+
const e = [
|
|
231
278
|
{
|
|
232
279
|
id: "undo",
|
|
233
280
|
icon: "↩",
|
|
234
|
-
title:
|
|
281
|
+
title: this.text("toolbar.undo", "撤销"),
|
|
235
282
|
disabled: () => !this.core.store.getState().canUndo,
|
|
236
283
|
onClick: () => this.core.eventBus.emit("editor:reset")
|
|
237
284
|
},
|
|
238
285
|
{
|
|
239
286
|
id: "redo",
|
|
240
287
|
icon: "↪",
|
|
241
|
-
title:
|
|
288
|
+
title: this.text("toolbar.redo", "重做"),
|
|
242
289
|
disabled: () => !this.core.store.getState().canRedo,
|
|
243
290
|
onClick: () => {
|
|
244
291
|
}
|
|
@@ -246,14 +293,14 @@ class h {
|
|
|
246
293
|
{
|
|
247
294
|
id: "delete",
|
|
248
295
|
icon: "🗑",
|
|
249
|
-
title:
|
|
296
|
+
title: this.text("toolbar.delete", "删除选中"),
|
|
250
297
|
divider: !0,
|
|
251
298
|
onClick: () => this.core.eventBus.emit("editor:delete-selected")
|
|
252
299
|
},
|
|
253
300
|
{
|
|
254
301
|
id: "save",
|
|
255
302
|
icon: "💾",
|
|
256
|
-
title:
|
|
303
|
+
title: this.text("toolbar.save", "保存"),
|
|
257
304
|
onClick: () => this.core.eventBus.emit("editor:save", {
|
|
258
305
|
data: {},
|
|
259
306
|
success: !1
|
|
@@ -262,37 +309,37 @@ class h {
|
|
|
262
309
|
{
|
|
263
310
|
id: "fullscreen",
|
|
264
311
|
icon: "⛶",
|
|
265
|
-
title:
|
|
312
|
+
title: this.text("toolbar.fullscreen", "全屏"),
|
|
266
313
|
onClick: () => this.core.eventBus.emit("editor:fullscreen")
|
|
267
314
|
}
|
|
268
315
|
];
|
|
269
|
-
return this.options.showZoom &&
|
|
316
|
+
return this.options.showZoom && e.push(
|
|
270
317
|
{
|
|
271
318
|
id: "zoom-in",
|
|
272
319
|
icon: "🔍+",
|
|
273
|
-
title:
|
|
320
|
+
title: this.text("toolbar.zoomIn", "放大"),
|
|
274
321
|
divider: !0,
|
|
275
322
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 1.1 })
|
|
276
323
|
},
|
|
277
324
|
{
|
|
278
325
|
id: "zoom-out",
|
|
279
326
|
icon: "🔍-",
|
|
280
|
-
title:
|
|
327
|
+
title: this.text("toolbar.zoomOut", "缩小"),
|
|
281
328
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 0.9 })
|
|
282
329
|
},
|
|
283
330
|
{
|
|
284
331
|
id: "zoom-fit",
|
|
285
332
|
icon: "🔲",
|
|
286
|
-
title:
|
|
333
|
+
title: this.text("toolbar.fitView", "适应画布"),
|
|
287
334
|
onClick: () => this.core.eventBus.emit("canvas:zoom", { scale: 1 })
|
|
288
335
|
}
|
|
289
|
-
),
|
|
336
|
+
), e.push({
|
|
290
337
|
id: "auto-layout",
|
|
291
338
|
icon: "📐",
|
|
292
|
-
title:
|
|
339
|
+
title: this.text("toolbar.autoLayout", "自动排版"),
|
|
293
340
|
divider: !0,
|
|
294
341
|
onClick: () => this.core.eventBus.emit("editor:auto-layout")
|
|
295
|
-
}),
|
|
342
|
+
}), e;
|
|
296
343
|
}
|
|
297
344
|
// ============================================================
|
|
298
345
|
// 状态更新
|
|
@@ -302,7 +349,7 @@ class h {
|
|
|
302
349
|
*/
|
|
303
350
|
updateButtonStates() {
|
|
304
351
|
for (const [e, t] of this.buttonElements) {
|
|
305
|
-
const n = this.getBuiltinButtons().find((
|
|
352
|
+
const n = this.getBuiltinButtons().find((s) => s.id === e);
|
|
306
353
|
n && typeof n.disabled == "function" && (t.disabled = n.disabled(), t.classList.toggle("rulego-toolbar__button--disabled", t.disabled));
|
|
307
354
|
}
|
|
308
355
|
}
|
|
@@ -315,6 +362,9 @@ class h {
|
|
|
315
362
|
getElement() {
|
|
316
363
|
return this.rootEl;
|
|
317
364
|
}
|
|
365
|
+
text(e, t) {
|
|
366
|
+
return c(this.core.i18n, e, t);
|
|
367
|
+
}
|
|
318
368
|
/**
|
|
319
369
|
* 动态添加自定义按钮
|
|
320
370
|
* @param button - 按钮定义
|
|
@@ -322,16 +372,16 @@ class h {
|
|
|
322
372
|
addButton(e) {
|
|
323
373
|
if (!this.rootEl) return;
|
|
324
374
|
const t = document.createElement("button");
|
|
325
|
-
t.className = "rulego-toolbar__button", t.title = e.title, t
|
|
375
|
+
t.className = "rulego-toolbar__button", t.title = e.title, d(t, e.icon), t.addEventListener("click", (n) => {
|
|
326
376
|
n.preventDefault(), e.onClick();
|
|
327
377
|
}), this.buttonElements.set(e.id, t), this.rootEl.appendChild(t);
|
|
328
378
|
}
|
|
329
379
|
}
|
|
330
|
-
class
|
|
380
|
+
class v {
|
|
331
381
|
constructor(e, t) {
|
|
332
382
|
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 = {
|
|
333
383
|
core: t.core,
|
|
334
|
-
title: t.title || this.
|
|
384
|
+
title: t.title || this.text("panel.title", "属性编辑"),
|
|
335
385
|
width: t.width ?? "320px",
|
|
336
386
|
position: t.position ?? "right"
|
|
337
387
|
}, this.mount(), this.bindEvents();
|
|
@@ -354,8 +404,8 @@ class p {
|
|
|
354
404
|
*/
|
|
355
405
|
bindEvents() {
|
|
356
406
|
this.unsubscribe = this.core.store.subscribe((t) => {
|
|
357
|
-
const n = t.currentNodeView,
|
|
358
|
-
n &&
|
|
407
|
+
const n = t.currentNodeView, s = t.currentNodeModel;
|
|
408
|
+
n && s && Object.keys(s).length > 0 && this.showPanel(n, s);
|
|
359
409
|
});
|
|
360
410
|
const e = this.core.eventBus.on("blank:click", () => {
|
|
361
411
|
this.clearPanel();
|
|
@@ -380,17 +430,17 @@ class p {
|
|
|
380
430
|
* @param model - 当前节点模型数据
|
|
381
431
|
*/
|
|
382
432
|
showPanel(e, t) {
|
|
383
|
-
if (!(!this.rootEl || !this.formContainer || !this.titleEl) && (this.rootEl.style.display = "flex", this.titleEl.textContent = e.label || this.options.title, this.formContainer.
|
|
433
|
+
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))
|
|
384
434
|
for (const n of e.fields) {
|
|
385
|
-
const
|
|
386
|
-
this.formContainer.appendChild(
|
|
435
|
+
const s = this.createFieldElement(n, t);
|
|
436
|
+
this.formContainer.appendChild(s);
|
|
387
437
|
}
|
|
388
438
|
}
|
|
389
439
|
/**
|
|
390
440
|
* 清空面板并隐藏
|
|
391
441
|
*/
|
|
392
442
|
clearPanel() {
|
|
393
|
-
!this.rootEl || !this.formContainer || (this.formContainer.
|
|
443
|
+
!this.rootEl || !this.formContainer || (this.formContainer.replaceChildren(), this.rootEl.style.display = "none", this.currentNodeId = null);
|
|
394
444
|
}
|
|
395
445
|
// ============================================================
|
|
396
446
|
// 表单渲染
|
|
@@ -407,7 +457,7 @@ class p {
|
|
|
407
457
|
name: "name",
|
|
408
458
|
type: "string",
|
|
409
459
|
defaultValue: "",
|
|
410
|
-
label: this.
|
|
460
|
+
label: this.text("panel.nodeName", "节点名称"),
|
|
411
461
|
desc: "",
|
|
412
462
|
validate: "",
|
|
413
463
|
fields: null
|
|
@@ -423,28 +473,28 @@ class p {
|
|
|
423
473
|
createFieldElement(e, t) {
|
|
424
474
|
const n = document.createElement("div");
|
|
425
475
|
n.className = "rulego-property-panel__field";
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
let
|
|
476
|
+
const s = document.createElement("label");
|
|
477
|
+
s.className = "rulego-property-panel__label", s.textContent = e.label || e.name, e.desc && (s.title = e.desc), n.appendChild(s);
|
|
478
|
+
let o;
|
|
429
479
|
switch (e.type) {
|
|
430
480
|
case "bool":
|
|
431
|
-
|
|
481
|
+
o = this.createBoolField(e, t);
|
|
432
482
|
break;
|
|
433
483
|
case "select":
|
|
434
|
-
|
|
484
|
+
o = this.createSelectField(e, t);
|
|
435
485
|
break;
|
|
436
486
|
case "code":
|
|
437
487
|
case "json":
|
|
438
|
-
|
|
488
|
+
o = this.createTextareaField(e, t);
|
|
439
489
|
break;
|
|
440
490
|
case "int":
|
|
441
|
-
|
|
491
|
+
o = this.createNumberField(e, t);
|
|
442
492
|
break;
|
|
443
493
|
default:
|
|
444
|
-
|
|
494
|
+
o = this.createTextField(e, t);
|
|
445
495
|
break;
|
|
446
496
|
}
|
|
447
|
-
if (n.appendChild(
|
|
497
|
+
if (n.appendChild(o), e.desc) {
|
|
448
498
|
const i = document.createElement("span");
|
|
449
499
|
i.className = "rulego-property-panel__desc", i.textContent = e.desc, n.appendChild(i);
|
|
450
500
|
}
|
|
@@ -474,12 +524,12 @@ class p {
|
|
|
474
524
|
createBoolField(e, t) {
|
|
475
525
|
const n = document.createElement("div");
|
|
476
526
|
n.className = "rulego-property-panel__switch-wrapper";
|
|
477
|
-
const
|
|
478
|
-
|
|
527
|
+
const s = `field-${e.name}-${Date.now()}`, o = document.createElement("input");
|
|
528
|
+
o.type = "checkbox", o.className = "rulego-property-panel__checkbox", o.id = s, o.checked = !!this.getModelValue(e, t);
|
|
479
529
|
const i = document.createElement("label");
|
|
480
|
-
return i.className = "rulego-property-panel__switch", i.htmlFor =
|
|
481
|
-
this.handleFieldChange(e.name,
|
|
482
|
-
}), n.appendChild(
|
|
530
|
+
return i.className = "rulego-property-panel__switch", i.htmlFor = s, o.addEventListener("change", () => {
|
|
531
|
+
this.handleFieldChange(e.name, o.checked);
|
|
532
|
+
}), n.appendChild(o), n.appendChild(i), n;
|
|
483
533
|
}
|
|
484
534
|
/**
|
|
485
535
|
* 下拉选择
|
|
@@ -487,11 +537,11 @@ class p {
|
|
|
487
537
|
createSelectField(e, t) {
|
|
488
538
|
const n = document.createElement("select");
|
|
489
539
|
n.className = "rulego-property-panel__select", n.name = e.name;
|
|
490
|
-
const
|
|
540
|
+
const s = String(this.getModelValue(e, t) ?? "");
|
|
491
541
|
if (e.options && e.options.length > 0)
|
|
492
|
-
for (const
|
|
542
|
+
for (const o of e.options) {
|
|
493
543
|
const i = document.createElement("option");
|
|
494
|
-
i.value =
|
|
544
|
+
i.value = o.value, i.textContent = o.label, o.value === s && (i.selected = !0), n.appendChild(i);
|
|
495
545
|
}
|
|
496
546
|
return n.addEventListener("change", () => {
|
|
497
547
|
this.handleFieldChange(e.name, n.value);
|
|
@@ -561,8 +611,11 @@ class p {
|
|
|
561
611
|
hide() {
|
|
562
612
|
this.clearPanel();
|
|
563
613
|
}
|
|
614
|
+
text(e, t) {
|
|
615
|
+
return c(this.core.i18n, e, t);
|
|
616
|
+
}
|
|
564
617
|
}
|
|
565
|
-
class
|
|
618
|
+
class y {
|
|
566
619
|
constructor(e, t) {
|
|
567
620
|
this.menuEl = null, this.currentContext = null, this.outsideClickHandler = null, this.container = e, this.core = t.core;
|
|
568
621
|
const n = t.includeBuiltin !== !1 ? this.getBuiltinItems() : [];
|
|
@@ -604,11 +657,11 @@ class m {
|
|
|
604
657
|
handleContextMenu(e) {
|
|
605
658
|
const t = e.target, n = this.resolveContext(t, e);
|
|
606
659
|
this.currentContext = n;
|
|
607
|
-
const
|
|
608
|
-
const i = Array.isArray(
|
|
660
|
+
const s = this.items.filter((o) => {
|
|
661
|
+
const i = Array.isArray(o.target) ? o.target : [o.target];
|
|
609
662
|
return i.includes(n.type) || i.includes("all");
|
|
610
663
|
});
|
|
611
|
-
|
|
664
|
+
s.length !== 0 && this.renderMenu(s, e.clientX, e.clientY);
|
|
612
665
|
}
|
|
613
666
|
/**
|
|
614
667
|
* 解析右键目标的上下文
|
|
@@ -621,10 +674,10 @@ class m {
|
|
|
621
674
|
id: n.getAttribute("data-node-id") || void 0,
|
|
622
675
|
position: { x: t.clientX, y: t.clientY }
|
|
623
676
|
};
|
|
624
|
-
const
|
|
625
|
-
return
|
|
677
|
+
const s = e.closest(".lf-edge");
|
|
678
|
+
return s ? {
|
|
626
679
|
type: "edge",
|
|
627
|
-
id:
|
|
680
|
+
id: s.getAttribute("data-edge-id") || void 0,
|
|
628
681
|
position: { x: t.clientX, y: t.clientY }
|
|
629
682
|
} : {
|
|
630
683
|
type: "canvas",
|
|
@@ -639,27 +692,27 @@ class m {
|
|
|
639
692
|
*/
|
|
640
693
|
renderMenu(e, t, n) {
|
|
641
694
|
if (this.menuEl) {
|
|
642
|
-
this.menuEl.
|
|
643
|
-
for (const
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
const i = typeof
|
|
647
|
-
if (i &&
|
|
648
|
-
const
|
|
649
|
-
|
|
695
|
+
this.menuEl.replaceChildren();
|
|
696
|
+
for (const s of e) {
|
|
697
|
+
const o = document.createElement("div");
|
|
698
|
+
o.className = "rulego-context-menu__item";
|
|
699
|
+
const i = typeof s.disabled == "function" ? s.disabled() : s.disabled;
|
|
700
|
+
if (i && o.classList.add("rulego-context-menu__item--disabled"), s.icon) {
|
|
701
|
+
const l = document.createElement("span");
|
|
702
|
+
l.className = "rulego-context-menu__icon", d(l, s.icon), o.appendChild(l);
|
|
650
703
|
}
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
this.currentContext &&
|
|
654
|
-
}), this.menuEl.appendChild(
|
|
655
|
-
const
|
|
656
|
-
|
|
704
|
+
const a = document.createElement("span");
|
|
705
|
+
if (a.className = "rulego-context-menu__label", a.textContent = s.label, o.appendChild(a), i || o.addEventListener("click", () => {
|
|
706
|
+
this.currentContext && s.onClick(this.currentContext), this.hide();
|
|
707
|
+
}), this.menuEl.appendChild(o), s.separator) {
|
|
708
|
+
const l = document.createElement("div");
|
|
709
|
+
l.className = "rulego-context-menu__separator", this.menuEl.appendChild(l);
|
|
657
710
|
}
|
|
658
711
|
}
|
|
659
712
|
this.menuEl.style.left = `${t}px`, this.menuEl.style.top = `${n}px`, this.menuEl.style.display = "block", requestAnimationFrame(() => {
|
|
660
713
|
if (!this.menuEl) return;
|
|
661
|
-
const
|
|
662
|
-
|
|
714
|
+
const s = this.menuEl.getBoundingClientRect();
|
|
715
|
+
s.right > window.innerWidth && (this.menuEl.style.left = `${t - s.width}px`), s.bottom > window.innerHeight && (this.menuEl.style.top = `${n - s.height}px`);
|
|
663
716
|
});
|
|
664
717
|
}
|
|
665
718
|
}
|
|
@@ -676,30 +729,29 @@ class m {
|
|
|
676
729
|
* 获取内置菜单项
|
|
677
730
|
*/
|
|
678
731
|
getBuiltinItems() {
|
|
679
|
-
const e = this.core.i18n;
|
|
680
732
|
return [
|
|
681
733
|
{
|
|
682
734
|
id: "edit",
|
|
683
|
-
label:
|
|
735
|
+
label: this.text("contextMenu.edit", "编辑"),
|
|
684
736
|
icon: "✏️",
|
|
685
737
|
target: "node",
|
|
686
|
-
onClick: (
|
|
687
|
-
|
|
738
|
+
onClick: (e) => {
|
|
739
|
+
e.id && this.core.eventBus.emit("editor:show-edit-panel");
|
|
688
740
|
}
|
|
689
741
|
},
|
|
690
742
|
{
|
|
691
743
|
id: "delete",
|
|
692
|
-
label:
|
|
744
|
+
label: this.text("contextMenu.delete", "删除"),
|
|
693
745
|
icon: "🗑️",
|
|
694
746
|
target: ["node", "edge"],
|
|
695
747
|
separator: !0,
|
|
696
|
-
onClick: (
|
|
697
|
-
|
|
748
|
+
onClick: (e) => {
|
|
749
|
+
e.id && this.core.eventBus.emit("node:delete", { id: e.id });
|
|
698
750
|
}
|
|
699
751
|
},
|
|
700
752
|
{
|
|
701
753
|
id: "copy",
|
|
702
|
-
label:
|
|
754
|
+
label: this.text("contextMenu.copy", "复制"),
|
|
703
755
|
icon: "📋",
|
|
704
756
|
target: "node",
|
|
705
757
|
onClick: () => {
|
|
@@ -707,7 +759,7 @@ class m {
|
|
|
707
759
|
},
|
|
708
760
|
{
|
|
709
761
|
id: "select-all",
|
|
710
|
-
label:
|
|
762
|
+
label: this.text("contextMenu.selectAll", "全选"),
|
|
711
763
|
icon: "⬜",
|
|
712
764
|
target: "canvas",
|
|
713
765
|
onClick: () => {
|
|
@@ -725,6 +777,9 @@ class m {
|
|
|
725
777
|
addItem(e) {
|
|
726
778
|
this.items.push(e);
|
|
727
779
|
}
|
|
780
|
+
text(e, t) {
|
|
781
|
+
return c(this.core.i18n, e, t);
|
|
782
|
+
}
|
|
728
783
|
/**
|
|
729
784
|
* 移除菜单项
|
|
730
785
|
* @param id - 菜单项 ID
|
|
@@ -739,10 +794,49 @@ class m {
|
|
|
739
794
|
return this.menuEl;
|
|
740
795
|
}
|
|
741
796
|
}
|
|
797
|
+
class x {
|
|
798
|
+
constructor(e, t) {
|
|
799
|
+
this.logs = [], this.consoleEl = null, this.listEl = null, this.container = e, this.core = t.core, this.maxLogs = t.maxLogs || 1e3, this.mount(), this.bindEvents();
|
|
800
|
+
}
|
|
801
|
+
t(e, t) {
|
|
802
|
+
const n = this.core.i18n.t(e);
|
|
803
|
+
return n && n !== e ? n : t;
|
|
804
|
+
}
|
|
805
|
+
mount() {
|
|
806
|
+
this.consoleEl = document.createElement("div"), this.consoleEl.className = "rulego-debug-console";
|
|
807
|
+
const e = document.createElement("div");
|
|
808
|
+
e.className = "rulego-debug-console__header";
|
|
809
|
+
const t = document.createElement("span");
|
|
810
|
+
t.className = "rulego-debug-console__title", t.textContent = this.t("editor.debugConsole.title", "调试控制台");
|
|
811
|
+
const n = document.createElement("button");
|
|
812
|
+
n.className = "rulego-debug-console__clear", n.textContent = this.t("editor.debugConsole.clear", "清除"), e.append(t, n);
|
|
813
|
+
const s = document.createElement("div");
|
|
814
|
+
s.className = "rulego-debug-console__list", this.consoleEl.append(e, s), this.listEl = s, this.container.appendChild(this.consoleEl), n.addEventListener("click", () => this.clear());
|
|
815
|
+
}
|
|
816
|
+
bindEvents() {
|
|
817
|
+
this.core.eventBus.on("debug:log", (e) => {
|
|
818
|
+
this.appendLog(e);
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
appendLog(e) {
|
|
822
|
+
if (this.logs.push(e), this.logs.length > this.maxLogs && (this.logs.shift(), this.listEl && this.listEl.firstElementChild && this.listEl.removeChild(this.listEl.firstElementChild)), !this.listEl) return;
|
|
823
|
+
const t = document.createElement("div");
|
|
824
|
+
t.className = "rulego-debug-console__item";
|
|
825
|
+
const n = typeof e == "string" ? e : m(E(e), { maxChars: 2e4, space: 0 });
|
|
826
|
+
t.textContent = `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] ${n}`, this.listEl.appendChild(t), this.listEl.scrollTop = this.listEl.scrollHeight;
|
|
827
|
+
}
|
|
828
|
+
clear() {
|
|
829
|
+
this.logs = [], this.listEl && this.listEl.replaceChildren();
|
|
830
|
+
}
|
|
831
|
+
destroy() {
|
|
832
|
+
this.consoleEl && this.consoleEl.parentNode && this.consoleEl.parentNode.removeChild(this.consoleEl);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
742
835
|
export {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
836
|
+
y as ContextMenu,
|
|
837
|
+
x as DebugConsole,
|
|
838
|
+
v as PropertyPanel,
|
|
839
|
+
C as Sidebar,
|
|
840
|
+
f as Toolbar
|
|
747
841
|
};
|
|
748
842
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.RuleGoEditorUI={}))})(this,function(r){"use strict";class c{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.core.i18n.t("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.innerHTML="🔍";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.innerHTML="";const n=this.filterGroups(e);if(n.length===0){const o=document.createElement("div");o.className="rulego-sidebar__empty",o.textContent=this.core.i18n.t("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=e.label;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 m of e.components){const E=this.createComponentElement(m,e.color);l.appendChild(E)}t.appendChild(l)}return t}createComponentElement(e,t){const n=document.createElement("div");n.className="rulego-sidebar__component",n.setAttribute("draggable","true"),n.title=e.desc||e.label;const o=document.createElement("span");o.className="rulego-sidebar__component-color",o.style.backgroundColor=e.color||t||"#ccc";const s=document.createElement("span");return s.className="rulego-sidebar__component-name",s.textContent=e.label,n.appendChild(o),n.appendChild(s),n.addEventListener("dragstart",i=>{i.dataTransfer&&(i.dataTransfer.setData("application/rulego-component",JSON.stringify({type:e.type,category:e.category,label:e.label,color:e.color||t})),i.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=>n.label.toLowerCase().includes(this.searchKeyword)||n.type.toLowerCase().includes(this.searchKeyword)||n.desc&&n.desc.toLowerCase().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}}class u{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,n.innerHTML=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=this.core.i18n,t=[{id:"undo",icon:"↩",title:e.t("toolbar.undo")||"撤销",disabled:()=>!this.core.store.getState().canUndo,onClick:()=>this.core.eventBus.emit("editor:reset")},{id:"redo",icon:"↪",title:e.t("toolbar.redo")||"重做",disabled:()=>!this.core.store.getState().canRedo,onClick:()=>{}},{id:"delete",icon:"🗑",title:e.t("toolbar.delete")||"删除选中",divider:!0,onClick:()=>this.core.eventBus.emit("editor:delete-selected")},{id:"save",icon:"💾",title:e.t("toolbar.save")||"保存",onClick:()=>this.core.eventBus.emit("editor:save",{data:{},success:!1})},{id:"fullscreen",icon:"⛶",title:e.t("toolbar.fullscreen")||"全屏",onClick:()=>this.core.eventBus.emit("editor:fullscreen")}];return this.options.showZoom&&t.push({id:"zoom-in",icon:"🔍+",title:e.t("toolbar.zoomIn")||"放大",divider:!0,onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1.1})},{id:"zoom-out",icon:"🔍-",title:e.t("toolbar.zoomOut")||"缩小",onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:.9})},{id:"zoom-fit",icon:"🔲",title:e.t("toolbar.fitView")||"适应画布",onClick:()=>this.core.eventBus.emit("canvas:zoom",{scale:1})}),t.push({id:"auto-layout",icon:"📐",title:e.t("toolbar.autoLayout")||"自动排版",divider:!0,onClick:()=>this.core.eventBus.emit("editor:auto-layout")}),t}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}addButton(e){if(!this.rootEl)return;const t=document.createElement("button");t.className="rulego-toolbar__button",t.title=e.title,t.innerHTML=e.icon,t.addEventListener("click",n=>{n.preventDefault(),e.onClick()}),this.buttonElements.set(e.id,t),this.rootEl.appendChild(t)}}class h{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.core.i18n.t("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.innerHTML="",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.innerHTML="",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.core.i18n.t("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()}}class p{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.innerHTML="";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",l.innerHTML=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(){const e=this.core.i18n;return[{id:"edit",label:e.t("contextMenu.edit")||"编辑",icon:"✏️",target:"node",onClick:t=>{t.id&&this.core.eventBus.emit("editor:show-edit-panel")}},{id:"delete",label:e.t("contextMenu.delete")||"删除",icon:"🗑️",target:["node","edge"],separator:!0,onClick:t=>{t.id&&this.core.eventBus.emit("node:delete",{id:t.id})}},{id:"copy",label:e.t("contextMenu.copy")||"复制",icon:"📋",target:"node",onClick:()=>{}},{id:"select-all",label:e.t("contextMenu.selectAll")||"全选",icon:"⬜",target:"canvas",onClick:()=>{}}]}addItem(e){this.items.push(e)}removeItem(e){this.items=this.items.filter(t=>t.id!==e)}getElement(){return this.menuEl}}r.ContextMenu=p,r.PropertyPanel=h,r.Sidebar=c,r.Toolbar=u,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
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
2
|
//# sourceMappingURL=index.umd.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huanban/rulego-editor-ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "RuleGo 编辑器 UI Kit - 纯 DOM 组件 (零框架依赖)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -31,19 +31,13 @@
|
|
|
31
31
|
"directory": "packages/editor-ui"
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/openclaw/rulego-editor#readme",
|
|
34
|
-
"scripts": {
|
|
35
|
-
"dev": "vite build --watch",
|
|
36
|
-
"build": "vite build && tsc --emitDeclarationOnly --outDir dist",
|
|
37
|
-
"lint": "tsc --noEmit",
|
|
38
|
-
"clean": "rm -rf dist"
|
|
39
|
-
},
|
|
40
34
|
"peerDependencies": {
|
|
41
35
|
"@huanban/rulego-editor-core": ">=0.1.0"
|
|
42
36
|
},
|
|
43
37
|
"devDependencies": {
|
|
44
|
-
"@huanban/rulego-editor-core": "workspace:*",
|
|
45
38
|
"typescript": "^5.4.0",
|
|
46
|
-
"vite": "^5.4.0"
|
|
39
|
+
"vite": "^5.4.0",
|
|
40
|
+
"@huanban/rulego-editor-core": "1.1.2"
|
|
47
41
|
},
|
|
48
42
|
"keywords": [
|
|
49
43
|
"rulego",
|
|
@@ -54,5 +48,11 @@
|
|
|
54
48
|
"property-panel"
|
|
55
49
|
],
|
|
56
50
|
"author": "HuanBan Team",
|
|
57
|
-
"license": "Apache-2.0"
|
|
58
|
-
|
|
51
|
+
"license": "Apache-2.0",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "vite build --watch",
|
|
54
|
+
"build": "vite build && tsc --emitDeclarationOnly --outDir dist",
|
|
55
|
+
"lint": "tsc --noEmit",
|
|
56
|
+
"clean": "rm -rf dist"
|
|
57
|
+
}
|
|
58
|
+
}
|