jch-config-editor 0.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/README.md +260 -0
- package/dist/components/Canvas/index.d.ts +4 -0
- package/dist/components/Canvas/index.js +759 -0
- package/dist/components/ConfigEditor/index.d.ts +33 -0
- package/dist/components/ConfigEditor/index.js +146 -0
- package/dist/components/MaterialPanel/index.d.ts +2 -0
- package/dist/components/MaterialPanel/index.js +102 -0
- package/dist/components/NodeRenderer/index.d.ts +13 -0
- package/dist/components/NodeRenderer/index.js +375 -0
- package/dist/components/PropertyPanel/index.d.ts +4 -0
- package/dist/components/PropertyPanel/index.js +542 -0
- package/dist/config-editor.css +1 -0
- package/dist/config-editor.es.js +3421 -0
- package/dist/config-editor.es.js.map +1 -0
- package/dist/config-editor.umd.js +20 -0
- package/dist/config-editor.umd.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +12 -0
- package/dist/jch-config-editor.css +1 -0
- package/dist/store/editorStore.d.ts +35 -0
- package/dist/store/editorStore.js +304 -0
- package/dist/types/index.d.ts +164 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/initData.d.ts +4 -0
- package/dist/utils/initData.js +164 -0
- package/dist/vite.svg +1 -0
- package/package.json +91 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ConfigEditor } from './components/ConfigEditor';
|
|
2
|
+
export { MaterialPanel } from './components/MaterialPanel';
|
|
3
|
+
export { Canvas } from './components/Canvas';
|
|
4
|
+
export { PropertyPanel } from './components/PropertyPanel';
|
|
5
|
+
export { NodeRenderer } from './components/NodeRenderer';
|
|
6
|
+
export { useEditorStore } from './store/editorStore';
|
|
7
|
+
export type { MaterialType, BaseMaterial, ImageMaterial, TextContentStyle, TextMaterial, LineMaterial, Material, NodeStatus, NodeStyle, ControlInfo, ContentInfo, Node, EventType, EditorEvent, ViewportState, EditorState, SchemeJSON, } from './types';
|
|
8
|
+
export { initMaterials, createDefaultNode, createDefaultStatus, } from './utils/initData';
|
|
9
|
+
import './index.css';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// ==================== 核心组件 ====================
|
|
2
|
+
export { ConfigEditor } from './components/ConfigEditor';
|
|
3
|
+
export { MaterialPanel } from './components/MaterialPanel';
|
|
4
|
+
export { Canvas } from './components/Canvas';
|
|
5
|
+
export { PropertyPanel } from './components/PropertyPanel';
|
|
6
|
+
export { NodeRenderer } from './components/NodeRenderer';
|
|
7
|
+
// ==================== Store ====================
|
|
8
|
+
export { useEditorStore } from './store/editorStore';
|
|
9
|
+
// ==================== 工具函数 ====================
|
|
10
|
+
export { initMaterials, createDefaultNode, createDefaultStatus, } from './utils/initData';
|
|
11
|
+
// ==================== 样式 ====================
|
|
12
|
+
import './index.css';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.pointer-events-none{pointer-events:none}.pointer-events-auto{pointer-events:auto}.visible{visibility:visible}.absolute{position:absolute}.relative{position:relative}.inset-0{inset:0}.-bottom-1{bottom:-.25rem}.-left-1{left:-.25rem}.-right-1{right:-.25rem}.-top-1{top:-.25rem}.-top-6{top:-1.5rem}.bottom-4{bottom:1rem}.left-0{left:0}.left-1\/2{left:50%}.right-4{right:1rem}.top-0{top:0}.top-1\/2{top:50%}.top-4{top:1rem}.z-10{z-index:10}.z-50{z-index:50}.mx-auto{margin-left:auto;margin-right:auto}.-ml-2{margin-left:-.5rem}.-mt-2{margin-top:-.5rem}.mb-1{margin-bottom:.25rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.ml-1{margin-left:.25rem}.ml-2{margin-left:.5rem}.mt-2{margin-top:.5rem}.mt-4{margin-top:1rem}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.h-0\.5{height:.125rem}.h-10{height:2.5rem}.h-12{height:3rem}.h-2{height:.5rem}.h-3{height:.75rem}.h-4{height:1rem}.h-48{height:12rem}.h-8{height:2rem}.h-full{height:100%}.max-h-\[400px\]{max-height:400px}.w-10{width:2.5rem}.w-12{width:3rem}.w-2{width:.5rem}.w-3{width:.75rem}.w-4{width:1rem}.w-5{width:1.25rem}.w-8{width:2rem}.w-full{width:100%}.min-w-0{min-width:0px}.flex-1{flex:1 1 0%}.flex-shrink-0{flex-shrink:0}.-translate-x-1\/2{--tw-translate-x: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-crosshair{cursor:crosshair}.cursor-move{cursor:move}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.resize-none{resize:none}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.flex-col{flex-direction:column}.items-center{align-items:center}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-3{gap:.75rem}.gap-4{gap:1rem}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem * var(--tw-space-y-reverse))}.space-y-3>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.75rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.75rem * var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem * var(--tw-space-y-reverse))}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.whitespace-nowrap{white-space:nowrap}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-t{border-top-width:1px}.border-blue-200{--tw-border-opacity: 1;border-color:rgb(191 219 254 / var(--tw-border-opacity, 1))}.border-blue-300{--tw-border-opacity: 1;border-color:rgb(147 197 253 / var(--tw-border-opacity, 1))}.border-blue-500{--tw-border-opacity: 1;border-color:rgb(59 130 246 / var(--tw-border-opacity, 1))}.border-gray-200{--tw-border-opacity: 1;border-color:rgb(229 231 235 / var(--tw-border-opacity, 1))}.border-gray-300{--tw-border-opacity: 1;border-color:rgb(209 213 219 / var(--tw-border-opacity, 1))}.border-white{--tw-border-opacity: 1;border-color:rgb(255 255 255 / var(--tw-border-opacity, 1))}.bg-blue-100{--tw-bg-opacity: 1;background-color:rgb(219 234 254 / var(--tw-bg-opacity, 1))}.bg-blue-50{--tw-bg-opacity: 1;background-color:rgb(239 246 255 / var(--tw-bg-opacity, 1))}.bg-blue-500{--tw-bg-opacity: 1;background-color:rgb(59 130 246 / var(--tw-bg-opacity, 1))}.bg-blue-500\/10{background-color:#3b82f61a}.bg-gray-100{--tw-bg-opacity: 1;background-color:rgb(243 244 246 / var(--tw-bg-opacity, 1))}.bg-gray-200{--tw-bg-opacity: 1;background-color:rgb(229 231 235 / var(--tw-bg-opacity, 1))}.bg-gray-400{--tw-bg-opacity: 1;background-color:rgb(156 163 175 / var(--tw-bg-opacity, 1))}.bg-gray-50{--tw-bg-opacity: 1;background-color:rgb(249 250 251 / var(--tw-bg-opacity, 1))}.bg-white{--tw-bg-opacity: 1;background-color:rgb(255 255 255 / var(--tw-bg-opacity, 1))}.object-contain{-o-object-fit:contain;object-fit:contain}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-4{padding-left:1rem;padding-right:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-8{padding-top:2rem;padding-bottom:2rem}.pr-4{padding-right:1rem}.text-center{text-align:center}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-semibold{font-weight:600}.text-blue-100{--tw-text-opacity: 1;color:rgb(219 234 254 / var(--tw-text-opacity, 1))}.text-blue-200{--tw-text-opacity: 1;color:rgb(191 219 254 / var(--tw-text-opacity, 1))}.text-blue-500{--tw-text-opacity: 1;color:rgb(59 130 246 / var(--tw-text-opacity, 1))}.text-blue-600{--tw-text-opacity: 1;color:rgb(37 99 235 / var(--tw-text-opacity, 1))}.text-blue-700{--tw-text-opacity: 1;color:rgb(29 78 216 / var(--tw-text-opacity, 1))}.text-gray-300{--tw-text-opacity: 1;color:rgb(209 213 219 / var(--tw-text-opacity, 1))}.text-gray-400{--tw-text-opacity: 1;color:rgb(156 163 175 / var(--tw-text-opacity, 1))}.text-gray-500{--tw-text-opacity: 1;color:rgb(107 114 128 / var(--tw-text-opacity, 1))}.text-gray-600{--tw-text-opacity: 1;color:rgb(75 85 99 / var(--tw-text-opacity, 1))}.text-gray-800{--tw-text-opacity: 1;color:rgb(31 41 55 / var(--tw-text-opacity, 1))}.text-white{--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity, 1))}.opacity-50{opacity:.5}.shadow-lg{--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.ring-2{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-4{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-blue-400{--tw-ring-opacity: 1;--tw-ring-color: rgb(96 165 250 / var(--tw-ring-opacity, 1))}.ring-opacity-50{--tw-ring-opacity: .5}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}*{margin:0;padding:0;box-sizing:border-box}html,body,#root{width:100%;height:100%;overflow:hidden}body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}::-webkit-scrollbar{width:6px;height:6px}::-webkit-scrollbar-track{background:#f1f1f1;border-radius:3px}::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.ant-layout{background:#f5f5f5!important}.ant-layout-sider{background:#fff!important}.ant-collapse-ghost>.ant-collapse-item>.ant-collapse-content>.ant-collapse-content-box{padding:8px 0}.ant-list-item{padding:8px 12px!important}.canvas-grid{background-image:linear-gradient(#e8e8e8 1px,transparent 1px),linear-gradient(90deg,#e8e8e8 1px,transparent 1px);background-size:20px 20px}.node-selected{box-shadow:0 0 0 2px #1890ff,0 0 10px #1890ff4d}.dragging{cursor:grabbing!important;opacity:.8}.toolbar-btn{display:flex;height:2rem;width:2rem;align-items:center;justify-content:center;border-radius:.25rem;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.2s}.toolbar-btn:hover{--tw-bg-opacity: 1;background-color:rgb(243 244 246 / var(--tw-bg-opacity, 1))}.toolbar-btn.active{--tw-bg-opacity: 1;background-color:rgb(219 234 254 / var(--tw-bg-opacity, 1));--tw-text-opacity: 1;color:rgb(37 99 235 / var(--tw-text-opacity, 1))}.property-form .ant-form-item{margin-bottom:12px}.property-form .ant-form-item-label{padding-bottom:4px}.material-item{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.2s}.material-item:hover{--tw-bg-opacity: 1;background-color:rgb(249 250 251 / var(--tw-bg-opacity, 1))}.material-item.selected{--tw-bg-opacity: 1;background-color:rgb(239 246 255 / var(--tw-bg-opacity, 1));--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000);--tw-ring-opacity: 1;--tw-ring-color: rgb(96 165 250 / var(--tw-ring-opacity, 1))}.file\:mr-4::file-selector-button{margin-right:1rem}.file\:rounded-full::file-selector-button{border-radius:9999px}.file\:border-0::file-selector-button{border-width:0px}.file\:bg-blue-50::file-selector-button{--tw-bg-opacity: 1;background-color:rgb(239 246 255 / var(--tw-bg-opacity, 1))}.file\:px-4::file-selector-button{padding-left:1rem;padding-right:1rem}.file\:py-2::file-selector-button{padding-top:.5rem;padding-bottom:.5rem}.file\:text-sm::file-selector-button{font-size:.875rem;line-height:1.25rem}.file\:font-semibold::file-selector-button{font-weight:600}.file\:text-blue-700::file-selector-button{--tw-text-opacity: 1;color:rgb(29 78 216 / var(--tw-text-opacity, 1))}.hover\:border-blue-500:hover{--tw-border-opacity: 1;border-color:rgb(59 130 246 / var(--tw-border-opacity, 1))}.hover\:bg-blue-50:hover{--tw-bg-opacity: 1;background-color:rgb(239 246 255 / var(--tw-bg-opacity, 1))}.hover\:bg-gray-100:hover{--tw-bg-opacity: 1;background-color:rgb(243 244 246 / var(--tw-bg-opacity, 1))}.hover\:file\:bg-blue-100::file-selector-button:hover{--tw-bg-opacity: 1;background-color:rgb(219 234 254 / var(--tw-bg-opacity, 1))}.focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:ring-2:focus{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus\:ring-blue-500:focus{--tw-ring-opacity: 1;--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity, 1))}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type StoreApi } from 'zustand';
|
|
2
|
+
import type { EditorState, Node, Material, NodeStatus, EditorEvent, SchemeJSON, NodeStyle, ContentInfo, ControlInfo } from '../types';
|
|
3
|
+
interface EditorStore extends EditorState {
|
|
4
|
+
addNode: (node: Omit<Node, 'id'>, autoSelect?: boolean) => void;
|
|
5
|
+
updateNode: (id: string, updates: Partial<Node>) => void;
|
|
6
|
+
updateNodeStyle: (id: string, style: Partial<NodeStyle>) => void;
|
|
7
|
+
updateNodeContent: (id: string, content: Partial<ContentInfo>) => void;
|
|
8
|
+
updateNodeControl: (id: string, control: Partial<ControlInfo>) => void;
|
|
9
|
+
removeNode: (id: string) => void;
|
|
10
|
+
selectNode: (id: string | null) => void;
|
|
11
|
+
addStatus: (nodeId: string, status: Omit<NodeStatus, 'id'>) => void;
|
|
12
|
+
removeStatus: (nodeId: string, statusId: string) => void;
|
|
13
|
+
updateStatus: (nodeId: string, statusId: string, updates: Partial<NodeStatus>) => void;
|
|
14
|
+
selectStatus: (statusId: string | null) => void;
|
|
15
|
+
evaluateCurrentStatus: (nodeId: string, data: any) => string | undefined;
|
|
16
|
+
addMaterial: (material: Omit<Material, 'id'>) => void;
|
|
17
|
+
updateMaterial: (id: string, updates: Partial<Material>) => void;
|
|
18
|
+
removeMaterial: (id: string) => void;
|
|
19
|
+
setViewport: (viewport: Partial<EditorState['viewport']>) => void;
|
|
20
|
+
setMode: (mode: EditorState['mode']) => void;
|
|
21
|
+
startLineDrawing: (material: Material) => void;
|
|
22
|
+
updateLineDrawing: (endPoint: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
endLineDrawing: () => void;
|
|
27
|
+
cancelLineDrawing: () => void;
|
|
28
|
+
undo: () => void;
|
|
29
|
+
redo: () => void;
|
|
30
|
+
exportScheme: () => SchemeJSON;
|
|
31
|
+
importScheme: (scheme: SchemeJSON) => void;
|
|
32
|
+
recordEvent: (event: EditorEvent) => void;
|
|
33
|
+
}
|
|
34
|
+
export declare const useEditorStore: StoreApi<EditorStore>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { immer } from 'zustand/middleware/immer';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
// 初始状态
|
|
5
|
+
const initialState = {
|
|
6
|
+
nodes: [],
|
|
7
|
+
materials: [],
|
|
8
|
+
selectedNodeId: null,
|
|
9
|
+
selectedStatusId: null,
|
|
10
|
+
viewport: {
|
|
11
|
+
scale: 1,
|
|
12
|
+
positionX: 0,
|
|
13
|
+
positionY: 0,
|
|
14
|
+
},
|
|
15
|
+
history: {
|
|
16
|
+
past: [],
|
|
17
|
+
future: [],
|
|
18
|
+
},
|
|
19
|
+
mode: 'select',
|
|
20
|
+
lineDrawing: {
|
|
21
|
+
isDrawing: false,
|
|
22
|
+
material: null,
|
|
23
|
+
startPoint: null,
|
|
24
|
+
endPoint: null,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
// 创建事件
|
|
28
|
+
const createEvent = (type, targetId, payload) => ({
|
|
29
|
+
id: nanoid(),
|
|
30
|
+
type,
|
|
31
|
+
targetId,
|
|
32
|
+
payload,
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
});
|
|
35
|
+
export const useEditorStore = create()(immer((set, get) => ({
|
|
36
|
+
...initialState,
|
|
37
|
+
// ========== 节点操作 ==========
|
|
38
|
+
addNode: (node, autoSelect = true) => {
|
|
39
|
+
set((state) => {
|
|
40
|
+
const newNode = {
|
|
41
|
+
...node,
|
|
42
|
+
id: nanoid(),
|
|
43
|
+
};
|
|
44
|
+
state.nodes.push(newNode);
|
|
45
|
+
if (autoSelect) {
|
|
46
|
+
state.selectedNodeId = newNode.id;
|
|
47
|
+
state.history.past.push(createEvent('NODE_SELECT', newNode.id));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
updateNode: (id, updates) => {
|
|
52
|
+
set((state) => {
|
|
53
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
54
|
+
if (node) {
|
|
55
|
+
Object.assign(node, updates);
|
|
56
|
+
state.history.past.push(createEvent('PROPERTY_CHANGE', id, updates));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
updateNodeStyle: (id, style) => {
|
|
61
|
+
set((state) => {
|
|
62
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
63
|
+
if (node) {
|
|
64
|
+
Object.assign(node.normalStyle, style);
|
|
65
|
+
state.history.past.push(createEvent('PROPERTY_CHANGE', id, { normalStyle: style }));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
updateNodeContent: (id, content) => {
|
|
70
|
+
set((state) => {
|
|
71
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
72
|
+
if (node) {
|
|
73
|
+
Object.assign(node.contentInfo, content);
|
|
74
|
+
state.history.past.push(createEvent('PROPERTY_CHANGE', id, { contentInfo: content }));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
updateNodeControl: (id, control) => {
|
|
79
|
+
set((state) => {
|
|
80
|
+
const node = state.nodes.find((n) => n.id === id);
|
|
81
|
+
if (node) {
|
|
82
|
+
Object.assign(node.controlInfo, control);
|
|
83
|
+
state.history.past.push(createEvent('PROPERTY_CHANGE', id, { controlInfo: control }));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
removeNode: (id) => {
|
|
88
|
+
set((state) => {
|
|
89
|
+
const index = state.nodes.findIndex((n) => n.id === id);
|
|
90
|
+
if (index !== -1) {
|
|
91
|
+
state.nodes.splice(index, 1);
|
|
92
|
+
if (state.selectedNodeId === id) {
|
|
93
|
+
state.selectedNodeId = null;
|
|
94
|
+
state.selectedStatusId = null;
|
|
95
|
+
}
|
|
96
|
+
state.history.past.push(createEvent('NODE_DELETE', id));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
selectNode: (id) => {
|
|
101
|
+
set((state) => {
|
|
102
|
+
state.selectedNodeId = id;
|
|
103
|
+
state.selectedStatusId = null;
|
|
104
|
+
if (id) {
|
|
105
|
+
state.history.past.push(createEvent('NODE_SELECT', id));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
// ========== 状态操作 ==========
|
|
110
|
+
addStatus: (nodeId, status) => {
|
|
111
|
+
set((state) => {
|
|
112
|
+
const node = state.nodes.find((n) => n.id === nodeId);
|
|
113
|
+
if (!node)
|
|
114
|
+
return;
|
|
115
|
+
const newStatus = {
|
|
116
|
+
...status,
|
|
117
|
+
id: nanoid(),
|
|
118
|
+
};
|
|
119
|
+
node.contentInfo.statusList.push(newStatus);
|
|
120
|
+
state.history.past.push(createEvent('MATERIAL_STATUS_CHANGE', nodeId, { statusId: newStatus.id }));
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
removeStatus: (nodeId, statusId) => {
|
|
124
|
+
set((state) => {
|
|
125
|
+
const node = state.nodes.find((n) => n.id === nodeId);
|
|
126
|
+
if (!node)
|
|
127
|
+
return;
|
|
128
|
+
const index = node.contentInfo.statusList.findIndex((s) => s.id === statusId);
|
|
129
|
+
if (index !== -1) {
|
|
130
|
+
node.contentInfo.statusList.splice(index, 1);
|
|
131
|
+
if (node.contentInfo.currentStatusId === statusId) {
|
|
132
|
+
node.contentInfo.currentStatusId = undefined;
|
|
133
|
+
}
|
|
134
|
+
if (state.selectedStatusId === statusId) {
|
|
135
|
+
state.selectedStatusId = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
updateStatus: (nodeId, statusId, updates) => {
|
|
141
|
+
set((state) => {
|
|
142
|
+
const node = state.nodes.find((n) => n.id === nodeId);
|
|
143
|
+
if (!node)
|
|
144
|
+
return;
|
|
145
|
+
const status = node.contentInfo.statusList.find((s) => s.id === statusId);
|
|
146
|
+
if (status) {
|
|
147
|
+
Object.assign(status, updates);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
selectStatus: (statusId) => {
|
|
152
|
+
set((state) => {
|
|
153
|
+
state.selectedStatusId = statusId;
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
evaluateCurrentStatus: (nodeId, data) => {
|
|
157
|
+
const state = get();
|
|
158
|
+
const node = state.nodes.find((n) => n.id === nodeId);
|
|
159
|
+
if (!node)
|
|
160
|
+
return undefined;
|
|
161
|
+
for (const status of node.contentInfo.statusList) {
|
|
162
|
+
try {
|
|
163
|
+
const fn = new Function('data', 'bindCodes', 'status', status.expression);
|
|
164
|
+
const result = fn(data, status.bindCodes, status);
|
|
165
|
+
if (result === true) {
|
|
166
|
+
return status.id;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.warn('状态表达式执行失败:', status.name, error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
},
|
|
175
|
+
// ========== 物料库操作 ==========
|
|
176
|
+
addMaterial: (material) => {
|
|
177
|
+
set((state) => {
|
|
178
|
+
const newMaterial = {
|
|
179
|
+
...material,
|
|
180
|
+
id: nanoid(),
|
|
181
|
+
};
|
|
182
|
+
state.materials.push(newMaterial);
|
|
183
|
+
state.history.past.push(createEvent('MATERIAL_ADD', newMaterial.id));
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
updateMaterial: (id, updates) => {
|
|
187
|
+
set((state) => {
|
|
188
|
+
const material = state.materials.find((m) => m.id === id);
|
|
189
|
+
if (material) {
|
|
190
|
+
Object.assign(material, updates);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
removeMaterial: (id) => {
|
|
195
|
+
set((state) => {
|
|
196
|
+
const index = state.materials.findIndex((m) => m.id === id);
|
|
197
|
+
if (index !== -1) {
|
|
198
|
+
state.materials.splice(index, 1);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
// ========== 视口操作 ==========
|
|
203
|
+
setViewport: (viewport) => {
|
|
204
|
+
set((state) => {
|
|
205
|
+
Object.assign(state.viewport, viewport);
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
// ========== 模式切换 ==========
|
|
209
|
+
setMode: (mode) => {
|
|
210
|
+
set((state) => {
|
|
211
|
+
state.mode = mode;
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
// ========== 线条绘制操作 ==========
|
|
215
|
+
startLineDrawing: (material) => {
|
|
216
|
+
set((state) => {
|
|
217
|
+
state.mode = 'line-draw';
|
|
218
|
+
state.lineDrawing = {
|
|
219
|
+
isDrawing: true,
|
|
220
|
+
material,
|
|
221
|
+
startPoint: null,
|
|
222
|
+
endPoint: null,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
updateLineDrawing: (endPoint) => {
|
|
227
|
+
set((state) => {
|
|
228
|
+
if (state.lineDrawing.isDrawing) {
|
|
229
|
+
state.lineDrawing.endPoint = endPoint;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
endLineDrawing: () => {
|
|
234
|
+
set((state) => {
|
|
235
|
+
state.mode = 'select';
|
|
236
|
+
state.lineDrawing = {
|
|
237
|
+
isDrawing: false,
|
|
238
|
+
material: null,
|
|
239
|
+
startPoint: null,
|
|
240
|
+
endPoint: null,
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
cancelLineDrawing: () => {
|
|
245
|
+
set((state) => {
|
|
246
|
+
state.mode = 'select';
|
|
247
|
+
state.lineDrawing = {
|
|
248
|
+
isDrawing: false,
|
|
249
|
+
material: null,
|
|
250
|
+
startPoint: null,
|
|
251
|
+
endPoint: null,
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
// ========== 历史操作 ==========
|
|
256
|
+
undo: () => {
|
|
257
|
+
set((state) => {
|
|
258
|
+
const lastEvent = state.history.past.pop();
|
|
259
|
+
if (lastEvent) {
|
|
260
|
+
state.history.future.push(lastEvent);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
redo: () => {
|
|
265
|
+
set((state) => {
|
|
266
|
+
const nextEvent = state.history.future.pop();
|
|
267
|
+
if (nextEvent) {
|
|
268
|
+
state.history.past.push(nextEvent);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
recordEvent: (event) => {
|
|
273
|
+
set((state) => {
|
|
274
|
+
state.history.past.push(event);
|
|
275
|
+
state.history.future = [];
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
// ========== 导入导出 ==========
|
|
279
|
+
exportScheme: () => {
|
|
280
|
+
const state = get();
|
|
281
|
+
return {
|
|
282
|
+
version: '1.1.0',
|
|
283
|
+
nodes: state.nodes,
|
|
284
|
+
materials: state.materials,
|
|
285
|
+
viewport: state.viewport,
|
|
286
|
+
metadata: {
|
|
287
|
+
name: '未命名组态',
|
|
288
|
+
description: '',
|
|
289
|
+
createdAt: new Date().toISOString(),
|
|
290
|
+
updatedAt: new Date().toISOString(),
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
importScheme: (scheme) => {
|
|
295
|
+
set((state) => {
|
|
296
|
+
state.nodes = scheme.nodes || [];
|
|
297
|
+
state.materials = scheme.materials || [];
|
|
298
|
+
state.viewport = scheme.viewport || initialState.viewport;
|
|
299
|
+
state.selectedNodeId = null;
|
|
300
|
+
state.selectedStatusId = null;
|
|
301
|
+
state.history = { past: [], future: [] };
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
})));
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export type MaterialType = 'IMAGE' | 'TEXT' | 'LINE' | 'CUSTOM';
|
|
3
|
+
export interface BaseMaterial {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: MaterialType;
|
|
7
|
+
}
|
|
8
|
+
export interface ImageMaterial extends BaseMaterial {
|
|
9
|
+
type: 'IMAGE';
|
|
10
|
+
src?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TextContentStyle {
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
fontWeight?: 'normal' | 'bold' | number;
|
|
15
|
+
fontFamily?: string;
|
|
16
|
+
color?: string;
|
|
17
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
18
|
+
lineHeight?: number;
|
|
19
|
+
letterSpacing?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface TextMaterial extends BaseMaterial {
|
|
22
|
+
type: 'TEXT';
|
|
23
|
+
content: {
|
|
24
|
+
label?: string;
|
|
25
|
+
value?: string;
|
|
26
|
+
valueSourceCode?: string;
|
|
27
|
+
unit?: string;
|
|
28
|
+
decimals?: number;
|
|
29
|
+
labelStyle?: TextContentStyle;
|
|
30
|
+
valueStyle?: TextContentStyle;
|
|
31
|
+
customStyle?: CSSProperties;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type LineStyleType = 'solid' | 'dashed' | 'center' | 'phantom' | 'dot' | 'dash-dot';
|
|
35
|
+
export interface LineMaterial extends BaseMaterial {
|
|
36
|
+
type: 'LINE';
|
|
37
|
+
config?: {
|
|
38
|
+
thickness?: number;
|
|
39
|
+
lineWeight?: number;
|
|
40
|
+
color?: string;
|
|
41
|
+
dashed?: boolean;
|
|
42
|
+
lineType?: LineStyleType;
|
|
43
|
+
startX?: number;
|
|
44
|
+
startY?: number;
|
|
45
|
+
endX?: number;
|
|
46
|
+
endY?: number;
|
|
47
|
+
direction?: 'horizontal' | 'vertical' | 'diagonal' | 'angled';
|
|
48
|
+
angle?: number;
|
|
49
|
+
length?: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface GroupMaterial extends BaseMaterial {
|
|
53
|
+
type: 'CUSTOM';
|
|
54
|
+
render?: (props: any) => React.ReactNode;
|
|
55
|
+
config?: {
|
|
56
|
+
nodes?: Node[];
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export type Material = ImageMaterial | TextMaterial | LineMaterial | GroupMaterial;
|
|
61
|
+
export interface NodeStatus {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
expression: string;
|
|
65
|
+
material: Material;
|
|
66
|
+
bindCodes?: string[];
|
|
67
|
+
}
|
|
68
|
+
export interface NodeStyle {
|
|
69
|
+
width?: number;
|
|
70
|
+
height?: number;
|
|
71
|
+
x?: number;
|
|
72
|
+
y?: number;
|
|
73
|
+
padding?: number | [number, number] | [number, number, number, number];
|
|
74
|
+
margin?: number | [number, number] | [number, number, number, number];
|
|
75
|
+
background?: string;
|
|
76
|
+
backgroundImage?: string;
|
|
77
|
+
borderRadius?: number;
|
|
78
|
+
border?: string;
|
|
79
|
+
opacity?: number;
|
|
80
|
+
transform?: string;
|
|
81
|
+
zIndex?: number;
|
|
82
|
+
scale?: number;
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
export interface ControlInfo {
|
|
86
|
+
isDraggable?: boolean;
|
|
87
|
+
isClickable?: boolean;
|
|
88
|
+
isResizable?: boolean;
|
|
89
|
+
isSelectable?: boolean;
|
|
90
|
+
onClick?: string;
|
|
91
|
+
onDragStart?: string;
|
|
92
|
+
onDragEnd?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface ContentInfo {
|
|
95
|
+
statusList: NodeStatus[];
|
|
96
|
+
currentStatusId?: string;
|
|
97
|
+
}
|
|
98
|
+
export type NodeType = 'normal' | 'group';
|
|
99
|
+
export interface BaseNode {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
type: NodeType;
|
|
103
|
+
normalStyle: NodeStyle;
|
|
104
|
+
contentInfo: ContentInfo;
|
|
105
|
+
controlInfo: ControlInfo;
|
|
106
|
+
}
|
|
107
|
+
export interface NormalNode extends BaseNode {
|
|
108
|
+
type: 'normal';
|
|
109
|
+
}
|
|
110
|
+
export interface GroupNode extends BaseNode {
|
|
111
|
+
type: 'group';
|
|
112
|
+
children: Node[];
|
|
113
|
+
}
|
|
114
|
+
export type Node = NormalNode | GroupNode;
|
|
115
|
+
export type EventType = 'NODE_SELECT' | 'NODE_DRAG' | 'NODE_CLICK' | 'NODE_RESIZE' | 'NODE_DELETE' | 'CANVAS_ZOOM' | 'CANVAS_PAN' | 'MATERIAL_ADD' | 'MATERIAL_STATUS_CHANGE' | 'PROPERTY_CHANGE' | 'UNDO' | 'REDO';
|
|
116
|
+
export interface EditorEvent {
|
|
117
|
+
id: string;
|
|
118
|
+
type: EventType;
|
|
119
|
+
targetId?: string;
|
|
120
|
+
payload?: any;
|
|
121
|
+
timestamp: number;
|
|
122
|
+
}
|
|
123
|
+
export interface LineDrawingState {
|
|
124
|
+
isDrawing: boolean;
|
|
125
|
+
material: Material | null;
|
|
126
|
+
startPoint: {
|
|
127
|
+
x: number;
|
|
128
|
+
y: number;
|
|
129
|
+
} | null;
|
|
130
|
+
endPoint: {
|
|
131
|
+
x: number;
|
|
132
|
+
y: number;
|
|
133
|
+
} | null;
|
|
134
|
+
}
|
|
135
|
+
export interface ViewportState {
|
|
136
|
+
scale: number;
|
|
137
|
+
positionX: number;
|
|
138
|
+
positionY: number;
|
|
139
|
+
}
|
|
140
|
+
export interface EditorState {
|
|
141
|
+
nodes: Node[];
|
|
142
|
+
materials: Material[];
|
|
143
|
+
selectedNodeId: string | null;
|
|
144
|
+
selectedStatusId: string | null;
|
|
145
|
+
viewport: ViewportState;
|
|
146
|
+
history: {
|
|
147
|
+
past: EditorEvent[];
|
|
148
|
+
future: EditorEvent[];
|
|
149
|
+
};
|
|
150
|
+
mode: 'select' | 'drag' | 'draw' | 'preview' | 'line-draw';
|
|
151
|
+
lineDrawing: LineDrawingState;
|
|
152
|
+
}
|
|
153
|
+
export interface SchemeJSON {
|
|
154
|
+
version: string;
|
|
155
|
+
nodes: Node[];
|
|
156
|
+
materials: Material[];
|
|
157
|
+
viewport: ViewportState;
|
|
158
|
+
metadata?: {
|
|
159
|
+
name?: string;
|
|
160
|
+
description?: string;
|
|
161
|
+
createdAt?: string;
|
|
162
|
+
updatedAt?: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Material, Node, NodeStatus } from '../types';
|
|
2
|
+
export declare const initMaterials: Material[];
|
|
3
|
+
export declare const createDefaultStatus: (material: Material) => NodeStatus;
|
|
4
|
+
export declare const createDefaultNode: (x: number, y: number, material?: Material) => Node;
|