jch-config-editor 0.1.19 → 0.1.21
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/Canvas/index.d.ts +2 -0
- package/dist/components/Canvas/index.d.ts.map +1 -1
- package/dist/components/ConfigEditor/index.d.ts +1 -1
- package/dist/components/ConfigEditor/index.d.ts.map +1 -1
- package/dist/config-editor.cjs.js +7 -0
- package/dist/config-editor.es.js +6561 -12362
- package/dist/config-editor.umd.js +9 -25
- package/package.json +4 -1
- package/dist/components/Canvas/index.js +0 -759
- package/dist/components/ConfigEditor/index.js +0 -146
- package/dist/components/MaterialPanel/index.js +0 -102
- package/dist/components/NodeRenderer/index.js +0 -375
- package/dist/components/PropertyPanel/index.js +0 -542
- package/dist/config-editor.es.js.map +0 -1
- package/dist/config-editor.umd.js.map +0 -1
- package/dist/index.js +0 -12
- package/dist/jch-config-editor.css +0 -1
- package/dist/store/editorStore.js +0 -304
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/initData.js +0 -164
package/dist/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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';
|
|
@@ -1 +0,0 @@
|
|
|
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!important}.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}.inline-block{display:inline-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))}
|
|
@@ -1,304 +0,0 @@
|
|
|
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
|
-
})));
|
package/dist/test/setup.d.ts
DELETED
package/dist/test/setup.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/initData.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
|
-
// 初始化物料库数据
|
|
3
|
-
export const initMaterials = [
|
|
4
|
-
// 基础形状
|
|
5
|
-
{
|
|
6
|
-
id: nanoid(),
|
|
7
|
-
name: '矩形',
|
|
8
|
-
type: 'IMAGE',
|
|
9
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="60"><rect width="100" height="60" fill="#1890ff" rx="4"/></svg>`)}`,
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
id: nanoid(),
|
|
13
|
-
name: '圆形',
|
|
14
|
-
type: 'IMAGE',
|
|
15
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><circle cx="40" cy="40" r="38" fill="#52c41a"/></svg>`)}`,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: nanoid(),
|
|
19
|
-
name: '圆角矩形',
|
|
20
|
-
type: 'IMAGE',
|
|
21
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="60"><rect width="100" height="60" fill="#faad14" rx="20"/></svg>`)}`,
|
|
22
|
-
},
|
|
23
|
-
// 设备图标
|
|
24
|
-
{
|
|
25
|
-
id: nanoid(),
|
|
26
|
-
name: '阀门',
|
|
27
|
-
type: 'IMAGE',
|
|
28
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><path d="M10 20 L30 10 L50 20 L50 40 L30 50 L10 40 Z" fill="#bfbfbf" stroke="#595959" stroke-width="2"/><circle cx="30" cy="30" r="8" fill="#1890ff"/></svg>`)}`,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: nanoid(),
|
|
32
|
-
name: '泵',
|
|
33
|
-
type: 'IMAGE',
|
|
34
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><circle cx="30" cy="35" r="20" fill="#bfbfbf" stroke="#595959" stroke-width="2"/><rect x="25" y="5" width="10" height="15" fill="#595959"/><path d="M30 20 L30 35 M20 30 Q30 45 40 30" stroke="#595959" stroke-width="2" fill="none"/></svg>`)}`,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: nanoid(),
|
|
38
|
-
name: '罐体',
|
|
39
|
-
type: 'IMAGE',
|
|
40
|
-
src: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="60" height="80"><ellipse cx="30" cy="10" rx="25" ry="10" fill="#d9d9d9" stroke="#595959" stroke-width="2"/><rect x="5" y="10" width="50" height="60" fill="#f0f0f0" stroke="#595959" stroke-width="2"/><ellipse cx="30" cy="70" rx="25" ry="10" fill="#d9d9d9" stroke="#595959" stroke-width="2"/></svg>`)}`,
|
|
41
|
-
},
|
|
42
|
-
// 文本
|
|
43
|
-
{
|
|
44
|
-
id: nanoid(),
|
|
45
|
-
name: '文本标签',
|
|
46
|
-
type: 'TEXT',
|
|
47
|
-
content: {
|
|
48
|
-
label: '标签',
|
|
49
|
-
value: '值',
|
|
50
|
-
labelStyle: {
|
|
51
|
-
fontSize: 14,
|
|
52
|
-
fontWeight: 'bold',
|
|
53
|
-
color: '#262626',
|
|
54
|
-
textAlign: 'left',
|
|
55
|
-
},
|
|
56
|
-
valueStyle: {
|
|
57
|
-
fontSize: 14,
|
|
58
|
-
fontWeight: 'normal',
|
|
59
|
-
color: '#1890ff',
|
|
60
|
-
textAlign: 'left',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
// 线条 - 通用线条物料,通过属性配置实现不同线型
|
|
65
|
-
{
|
|
66
|
-
id: nanoid(),
|
|
67
|
-
name: '线条',
|
|
68
|
-
type: 'LINE',
|
|
69
|
-
config: {
|
|
70
|
-
thickness: 2,
|
|
71
|
-
lineWeight: 2,
|
|
72
|
-
color: '#262626',
|
|
73
|
-
lineType: 'solid',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
// 创建默认状态
|
|
78
|
-
export const createDefaultStatus = (material) => ({
|
|
79
|
-
id: nanoid(),
|
|
80
|
-
name: '默认状态',
|
|
81
|
-
expression: 'return true;',
|
|
82
|
-
material: { ...material, id: nanoid() },
|
|
83
|
-
bindCodes: [],
|
|
84
|
-
});
|
|
85
|
-
// 创建默认节点
|
|
86
|
-
export const createDefaultNode = (x, y, material) => {
|
|
87
|
-
// 如果是群组物料,创建群组节点
|
|
88
|
-
if (material?.type === 'CUSTOM' && material.config?.nodes) {
|
|
89
|
-
const children = material.config.nodes.map((childNode) => ({
|
|
90
|
-
...childNode,
|
|
91
|
-
id: nanoid(), // 重新生成子节点ID
|
|
92
|
-
}));
|
|
93
|
-
// 计算群组边界
|
|
94
|
-
let minX = Infinity, minY = Infinity;
|
|
95
|
-
let maxX = -Infinity, maxY = -Infinity;
|
|
96
|
-
children.forEach((child) => {
|
|
97
|
-
const cx = child.normalStyle.x || 0;
|
|
98
|
-
const cy = child.normalStyle.y || 0;
|
|
99
|
-
const cw = child.normalStyle.width || 0;
|
|
100
|
-
const ch = child.normalStyle.height || 0;
|
|
101
|
-
minX = Math.min(minX, cx);
|
|
102
|
-
minY = Math.min(minY, cy);
|
|
103
|
-
maxX = Math.max(maxX, cx + cw);
|
|
104
|
-
maxY = Math.max(maxY, cy + ch);
|
|
105
|
-
});
|
|
106
|
-
// 调整子节点位置为相对坐标,并移除 scale 避免双重缩放
|
|
107
|
-
const relativeChildren = children.map((child) => ({
|
|
108
|
-
...child,
|
|
109
|
-
normalStyle: {
|
|
110
|
-
...child.normalStyle,
|
|
111
|
-
x: (child.normalStyle.x || 0) - minX,
|
|
112
|
-
y: (child.normalStyle.y || 0) - minY,
|
|
113
|
-
scale: undefined, // 移除 scale,由父级容器统一控制
|
|
114
|
-
},
|
|
115
|
-
}));
|
|
116
|
-
return {
|
|
117
|
-
id: nanoid(),
|
|
118
|
-
name: material.name || '群组节点',
|
|
119
|
-
type: 'group',
|
|
120
|
-
normalStyle: {
|
|
121
|
-
width: maxX - minX,
|
|
122
|
-
height: maxY - minY,
|
|
123
|
-
x,
|
|
124
|
-
y,
|
|
125
|
-
// 不设置背景和边框,由 NodeRenderer 控制
|
|
126
|
-
},
|
|
127
|
-
contentInfo: {
|
|
128
|
-
statusList: [],
|
|
129
|
-
currentStatusId: undefined,
|
|
130
|
-
},
|
|
131
|
-
controlInfo: {
|
|
132
|
-
isDraggable: true,
|
|
133
|
-
isClickable: true,
|
|
134
|
-
isResizable: true,
|
|
135
|
-
isSelectable: true,
|
|
136
|
-
},
|
|
137
|
-
children: relativeChildren,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
// 普通节点
|
|
141
|
-
return {
|
|
142
|
-
id: nanoid(),
|
|
143
|
-
name: '新节点',
|
|
144
|
-
type: 'normal',
|
|
145
|
-
normalStyle: {
|
|
146
|
-
width: 120,
|
|
147
|
-
height: 100,
|
|
148
|
-
x,
|
|
149
|
-
y,
|
|
150
|
-
background: 'transparent',
|
|
151
|
-
padding: 8,
|
|
152
|
-
},
|
|
153
|
-
contentInfo: {
|
|
154
|
-
statusList: material ? [createDefaultStatus(material)] : [],
|
|
155
|
-
currentStatusId: undefined,
|
|
156
|
-
},
|
|
157
|
-
controlInfo: {
|
|
158
|
-
isDraggable: true,
|
|
159
|
-
isClickable: true,
|
|
160
|
-
isResizable: true,
|
|
161
|
-
isSelectable: true,
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
};
|