@huanban/rulego-editor-react 1.0.15 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ComponentSidebar.d.ts +77 -0
- package/dist/components/ContextMenu.d.ts +102 -0
- package/dist/components/DataViewDialog.d.ts +41 -0
- package/dist/components/DebugPanel.d.ts +92 -0
- package/dist/components/EdgePropertyDrawer.d.ts +48 -0
- package/dist/components/EditorToolbar.d.ts +99 -0
- package/dist/components/ImportExportDialog.d.ts +45 -0
- package/dist/components/MiniMap.d.ts +75 -0
- package/dist/components/NodePropertyDrawer.d.ts +83 -0
- package/dist/components/RuleChainSettings.d.ts +74 -0
- package/dist/components/RuleGoEditor.d.ts +185 -0
- package/dist/components/SearchPanel.d.ts +52 -0
- package/dist/components/ValidationPanel.d.ts +57 -0
- package/dist/components/WorkflowInfoPanel.d.ts +57 -0
- package/dist/components/WorkflowList.d.ts +91 -0
- package/dist/hooks/useClipboard.d.ts +89 -0
- package/dist/hooks/useEditorCore.d.ts +104 -0
- package/dist/hooks/useEditorI18n.d.ts +33 -0
- package/dist/hooks/useEditorTheme.d.ts +37 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +73 -0
- package/dist/index.cjs.js +338 -214
- package/dist/index.d.ts +104 -0
- package/dist/index.esm.js +13105 -12662
- package/package.json +9 -9
- package/LICENSE +0 -190
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hooks/useEditorCore.ts
|
|
3
|
+
* @description React Hook — 将 EditorCore 桥接到 React 状态系统
|
|
4
|
+
*
|
|
5
|
+
* 兼容性:
|
|
6
|
+
* - React 16.8+ (hooks 引入版本)
|
|
7
|
+
* - React 17.x
|
|
8
|
+
* - React 18.x / 19.x
|
|
9
|
+
* - Next.js Pages Router 和 App Router
|
|
10
|
+
*
|
|
11
|
+
* 设计决策:
|
|
12
|
+
* - 使用 useEffect + useState 而非 React 18 的 useSyncExternalStore,
|
|
13
|
+
* 以确保对 React 16.8+ 的兼容性
|
|
14
|
+
* - 对于 Next.js SSR, EditorCore 实例仅在 useEffect 中创建 (客户端)
|
|
15
|
+
*
|
|
16
|
+
* 使用方式:
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useEditorCore } from '@huanban/rulego-editor-react'
|
|
19
|
+
*
|
|
20
|
+
* function MyEditor() {
|
|
21
|
+
* const {
|
|
22
|
+
* core,
|
|
23
|
+
* isReady,
|
|
24
|
+
* isDirty,
|
|
25
|
+
* selectedNode,
|
|
26
|
+
* componentGroups,
|
|
27
|
+
* on,
|
|
28
|
+
* loadData,
|
|
29
|
+
* } = useEditorCore({ url: 'http://127.0.0.1:9090' }) // 通过 url 参数传入实际地址
|
|
30
|
+
*
|
|
31
|
+
* return <div ref={canvasRef} />
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Next.js 兼容用法:
|
|
36
|
+
* ```tsx
|
|
37
|
+
* // 在 Next.js 中, 使用动态导入避免 SSR 报错
|
|
38
|
+
* import dynamic from 'next/dynamic'
|
|
39
|
+
* const Editor = dynamic(() => import('./Editor'), { ssr: false })
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see EditorCore — 编辑器核心引擎
|
|
43
|
+
*/
|
|
44
|
+
import { EditorCore } from '@huanban/rulego-editor-core';
|
|
45
|
+
import type { EditorOptions, EditorEventMap, EditorEventName, RuleChainData, RuleNodeConfig, RuleConnectionConfig, ComponentDefinition, ComponentGroup } from '@huanban/rulego-editor-core';
|
|
46
|
+
/**
|
|
47
|
+
* Hook 内部管理的状态
|
|
48
|
+
*/
|
|
49
|
+
interface EditorState {
|
|
50
|
+
/** 编辑器是否就绪 */
|
|
51
|
+
isReady: boolean;
|
|
52
|
+
/** 数据是否已修改 */
|
|
53
|
+
isDirty: boolean;
|
|
54
|
+
/** 是否正在加载 */
|
|
55
|
+
isLoading: boolean;
|
|
56
|
+
/** 当前选中的节点 */
|
|
57
|
+
selectedNode: RuleNodeConfig | null;
|
|
58
|
+
/** 当前选中的边 */
|
|
59
|
+
selectedEdge: RuleConnectionConfig | null;
|
|
60
|
+
/** 组件分组 */
|
|
61
|
+
componentGroups: ComponentGroup[];
|
|
62
|
+
/** 当前编辑的节点视图 */
|
|
63
|
+
currentNodeView: ComponentDefinition | null;
|
|
64
|
+
/** 当前编辑的节点模型 */
|
|
65
|
+
currentNodeModel: Record<string, unknown>;
|
|
66
|
+
/** 当前编辑的边模型 */
|
|
67
|
+
currentEdgeModel: Record<string, unknown>;
|
|
68
|
+
/** 是否可撤销 */
|
|
69
|
+
canUndo: boolean;
|
|
70
|
+
/** 是否可重做 */
|
|
71
|
+
canRedo: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* useEditorCore 返回的 Hook 接口
|
|
75
|
+
*/
|
|
76
|
+
export interface UseEditorCoreReturn extends EditorState {
|
|
77
|
+
/** EditorCore 原始实例 */
|
|
78
|
+
core: EditorCore | null;
|
|
79
|
+
/** 加载规则链数据 */
|
|
80
|
+
loadData: (data: RuleChainData) => void;
|
|
81
|
+
/** 监听事件 (在组件卸载时自动清理) */
|
|
82
|
+
on: <E extends EditorEventName>(event: E, handler: (payload: EditorEventMap[E]) => void) => void;
|
|
83
|
+
/** 发送事件 */
|
|
84
|
+
emit: <E extends EditorEventName>(event: E, ...args: EditorEventMap[E] extends void ? [] : [EditorEventMap[E]]) => void;
|
|
85
|
+
/** 初始化 (传入 LogicFlow 实例) */
|
|
86
|
+
init: (lfInstance: unknown) => void;
|
|
87
|
+
/** 手动触发保存 */
|
|
88
|
+
save: () => void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* React Hook — 创建和管理 EditorCore
|
|
92
|
+
*
|
|
93
|
+
* @param options - 编辑器选项 (仅在首次渲染时使用)
|
|
94
|
+
* @returns 编辑器状态和操作方法
|
|
95
|
+
*
|
|
96
|
+
* 内部原理:
|
|
97
|
+
* - 使用 useRef 持有 EditorCore 实例 (避免重复创建)
|
|
98
|
+
* - 使用 useState 维护状态 (确保 React 重渲染)
|
|
99
|
+
* - 使用 useEffect 进行状态订阅和清理
|
|
100
|
+
* - 避免使用 React 18 专有 API, 确保 16.8+ 兼容性
|
|
101
|
+
*/
|
|
102
|
+
export declare function useEditorCore(options?: Partial<EditorOptions>): UseEditorCoreReturn;
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=useEditorCore.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hooks/useEditorI18n.ts
|
|
3
|
+
* @description React Hook — 国际化
|
|
4
|
+
*
|
|
5
|
+
* 兼容 React 16.8+, 不使用 React 18 专有 API。
|
|
6
|
+
*
|
|
7
|
+
* 使用方式:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const { t, locale, setLocale } = useEditorI18n(core)
|
|
10
|
+
*
|
|
11
|
+
* return <button>{t('toolbar.save')}</button>
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
15
|
+
/**
|
|
16
|
+
* useEditorI18n 返回类型
|
|
17
|
+
*/
|
|
18
|
+
export interface UseEditorI18nReturn {
|
|
19
|
+
/** 翻译函数 */
|
|
20
|
+
t: (key: string, params?: Record<string, string>) => string;
|
|
21
|
+
/** 当前语言 */
|
|
22
|
+
locale: string;
|
|
23
|
+
/** 切换语言 */
|
|
24
|
+
setLocale: (locale: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 国际化 Hook
|
|
28
|
+
*
|
|
29
|
+
* @param core - EditorCore 实例 (可空, SSR 安全)
|
|
30
|
+
* @returns 翻译函数和语言操作
|
|
31
|
+
*/
|
|
32
|
+
export declare function useEditorI18n(core: EditorCore | null): UseEditorI18nReturn;
|
|
33
|
+
//# sourceMappingURL=useEditorI18n.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hooks/useEditorTheme.ts
|
|
3
|
+
* @description React Hook — 主题管理
|
|
4
|
+
*
|
|
5
|
+
* 兼容 React 16.8+, 不使用 React 18 专有 API。
|
|
6
|
+
*
|
|
7
|
+
* 使用方式:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const { currentTheme, setTheme, themes } = useEditorTheme(core)
|
|
10
|
+
*
|
|
11
|
+
* return (
|
|
12
|
+
* <select value={currentTheme} onChange={e => setTheme(e.target.value)}>
|
|
13
|
+
* {themes.map(t => <option key={t}>{t}</option>)}
|
|
14
|
+
* </select>
|
|
15
|
+
* )
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
19
|
+
/**
|
|
20
|
+
* useEditorTheme 返回类型
|
|
21
|
+
*/
|
|
22
|
+
export interface UseEditorThemeReturn {
|
|
23
|
+
/** 当前主题名称 */
|
|
24
|
+
currentTheme: string;
|
|
25
|
+
/** 可用主题列表 */
|
|
26
|
+
themes: string[];
|
|
27
|
+
/** 切换主题 */
|
|
28
|
+
setTheme: (name: string) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 主题管理 Hook
|
|
32
|
+
*
|
|
33
|
+
* @param core - EditorCore 实例 (可空, SSR 安全)
|
|
34
|
+
* @returns 主题状态和操作
|
|
35
|
+
*/
|
|
36
|
+
export declare function useEditorTheme(core: EditorCore | null): UseEditorThemeReturn;
|
|
37
|
+
//# sourceMappingURL=useEditorTheme.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** 快捷键配置 */
|
|
2
|
+
export interface ShortcutConfig {
|
|
3
|
+
/** 按键(小写,如 's', 'z', 'delete', 'backspace') */
|
|
4
|
+
key: string;
|
|
5
|
+
/** 是否需要 Ctrl/Cmd(自动适配 Mac) */
|
|
6
|
+
ctrl?: boolean;
|
|
7
|
+
/** 是否需要 Shift */
|
|
8
|
+
shift?: boolean;
|
|
9
|
+
/** 是否需要 Alt/Option */
|
|
10
|
+
alt?: boolean;
|
|
11
|
+
/** 是否在 input/textarea 焦点时也生效(默认 false) */
|
|
12
|
+
enableInInput?: boolean;
|
|
13
|
+
/** 描述文本(用于帮助界面) */
|
|
14
|
+
description?: string;
|
|
15
|
+
/** 处理函数 */
|
|
16
|
+
handler: (e: KeyboardEvent) => void;
|
|
17
|
+
}
|
|
18
|
+
/** useKeyboardShortcuts 配置 */
|
|
19
|
+
export interface UseKeyboardShortcutsOptions {
|
|
20
|
+
/** 快捷键列表 */
|
|
21
|
+
shortcuts: ShortcutConfig[];
|
|
22
|
+
/** 是否启用(默认 true) */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/** 事件目标元素(默认 document) */
|
|
25
|
+
target?: HTMLElement | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* useKeyboardShortcuts — 键盘快捷键 Hook
|
|
29
|
+
*
|
|
30
|
+
* 自动处理 Mac/Windows 快捷键差异,支持组合键。
|
|
31
|
+
*
|
|
32
|
+
* @param options - 快捷键配置
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* useKeyboardShortcuts({
|
|
37
|
+
* shortcuts: [
|
|
38
|
+
* { key: 's', ctrl: true, description: '保存', handler: () => save() },
|
|
39
|
+
* { key: 'z', ctrl: true, description: '撤销', handler: () => undo() },
|
|
40
|
+
* { key: 'z', ctrl: true, shift: true, description: '重做', handler: () => redo() },
|
|
41
|
+
* { key: 'delete', description: '删除', handler: () => deleteSelected() },
|
|
42
|
+
* ],
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function useKeyboardShortcuts(options: UseKeyboardShortcutsOptions): void;
|
|
47
|
+
/**
|
|
48
|
+
* 获取快捷键显示文本
|
|
49
|
+
*
|
|
50
|
+
* @param config - 快捷键配置
|
|
51
|
+
* @returns 可读的快捷键文本(如 "⌘S" 或 "Ctrl+S")
|
|
52
|
+
*/
|
|
53
|
+
export declare function getShortcutLabel(config: ShortcutConfig): string;
|
|
54
|
+
/**
|
|
55
|
+
* 生成编辑器默认快捷键
|
|
56
|
+
*
|
|
57
|
+
* @param handlers - 操作回调
|
|
58
|
+
* @returns 快捷键配置列表
|
|
59
|
+
*/
|
|
60
|
+
export declare function getDefaultEditorShortcuts(handlers: {
|
|
61
|
+
onSave?: () => void;
|
|
62
|
+
onUndo?: () => void;
|
|
63
|
+
onRedo?: () => void;
|
|
64
|
+
onDelete?: () => void;
|
|
65
|
+
onCopy?: () => void;
|
|
66
|
+
onPaste?: () => void;
|
|
67
|
+
onSelectAll?: () => void;
|
|
68
|
+
onFitView?: () => void;
|
|
69
|
+
onZoomIn?: () => void;
|
|
70
|
+
onZoomOut?: () => void;
|
|
71
|
+
onEscape?: () => void;
|
|
72
|
+
}): ShortcutConfig[];
|
|
73
|
+
//# sourceMappingURL=useKeyboardShortcuts.d.ts.map
|