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 ADDED
@@ -0,0 +1,260 @@
1
+ # Config Editor (组态编辑器)
2
+
3
+ [![npm version](https://badge.fury.io/js/@yourscope%2Fconfig-editor.svg)](https://badge.fury.io/js/@yourscope%2Fconfig-editor)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ 一个基于 React 的可视化组态编辑器,适用于 SCADA、工业控制系统和数据可视化场景。
7
+
8
+ ## ✨ 特性
9
+
10
+ - 🎨 **可视化编辑** - 拖拽物料、调整属性、实时预览
11
+ - 📦 **丰富物料库** - 内置基础形状、设备图标、文本、线条等
12
+ - 🔧 **状态系统** - 支持基于表达式的状态切换
13
+ - 🎯 **精确控制** - 位置、尺寸、样式精细调整
14
+ - 💾 **导入导出** - JSON 格式的 scheme 导入导出
15
+ - 🔍 **画布操作** - 缩放、平移、网格对齐
16
+ - ↩️ **历史记录** - 撤销/重做支持
17
+ - 📱 **响应式设计** - 适配不同屏幕尺寸
18
+ - 🔌 **易于集成** - 作为 React 组件轻松嵌入现有项目
19
+
20
+ ## 🚀 安装
21
+
22
+ ```bash
23
+ npm install @yourscope/config-editor
24
+ # 或
25
+ yarn add @yourscope/config-editor
26
+ # 或
27
+ pnpm add @yourscope/config-editor
28
+ ```
29
+
30
+ ### 对等依赖
31
+
32
+ 确保你的项目已安装以下依赖:
33
+
34
+ ```bash
35
+ npm install react react-dom antd @ant-design/icons
36
+ ```
37
+
38
+ ## 📖 使用方法
39
+
40
+ ### 基础用法
41
+
42
+ ```tsx
43
+ import React from 'react';
44
+ import { ConfigEditor } from '@yourscope/config-editor';
45
+ import '@yourscope/config-editor/style.css';
46
+
47
+ const App = () => {
48
+ return (
49
+ <div style={{ height: '100vh' }}>
50
+ <ConfigEditor />
51
+ </div>
52
+ );
53
+ };
54
+
55
+ export default App;
56
+ ```
57
+
58
+ ### 带初始数据
59
+
60
+ ```tsx
61
+ import React from 'react';
62
+ import { ConfigEditor } from '@yourscope/config-editor';
63
+ import type { SchemeJSON } from '@yourscope/config-editor';
64
+
65
+ const initialScheme: SchemeJSON = {
66
+ version: '1.0.0',
67
+ nodes: [
68
+ {
69
+ id: 'node-1',
70
+ name: '泵1',
71
+ normalStyle: {
72
+ width: 80,
73
+ height: 80,
74
+ x: 100,
75
+ y: 100,
76
+ background: 'transparent',
77
+ },
78
+ contentInfo: {
79
+ children: [
80
+ {
81
+ id: 'material-1',
82
+ name: '泵',
83
+ type: 'IMAGE',
84
+ src: 'data:image/svg+xml,...',
85
+ },
86
+ ],
87
+ statusList: [
88
+ {
89
+ id: 'status-1',
90
+ name: '运行中',
91
+ expression: 'return data?.running === true;',
92
+ style: { filter: 'brightness(1.2)' },
93
+ },
94
+ ],
95
+ bindCode: 'pump1',
96
+ },
97
+ controlInfo: {
98
+ isDraggable: true,
99
+ isClickable: true,
100
+ },
101
+ },
102
+ ],
103
+ materials: [],
104
+ viewport: { scale: 1, positionX: 0, positionY: 0 },
105
+ metadata: { name: '示例组态' },
106
+ };
107
+
108
+ const App = () => {
109
+ return (
110
+ <div style={{ height: '100vh' }}>
111
+ <ConfigEditor initialScheme={initialScheme} />
112
+ </div>
113
+ );
114
+ };
115
+
116
+ export default App;
117
+ ```
118
+
119
+ ### 监听变化
120
+
121
+ ```tsx
122
+ const App = () => {
123
+ const handleChange = (scheme: SchemeJSON) => {
124
+ console.log('当前 scheme:', scheme);
125
+ // 保存到服务器或本地存储
126
+ };
127
+
128
+ return (
129
+ <div style={{ height: '100vh' }}>
130
+ <ConfigEditor onChange={handleChange} />
131
+ </div>
132
+ );
133
+ };
134
+ ```
135
+
136
+ ### 只读预览模式
137
+
138
+ ```tsx
139
+ const App = () => {
140
+ return (
141
+ <div style={{ height: '100vh' }}>
142
+ <ConfigEditor
143
+ initialScheme={schemeData}
144
+ readonly={true}
145
+ showMaterialPanel={false}
146
+ showPropertyPanel={false}
147
+ />
148
+ </div>
149
+ );
150
+ };
151
+ ```
152
+
153
+ ## 🔧 API
154
+
155
+ ### ConfigEditor Props
156
+
157
+ | 属性 | 类型 | 默认值 | 说明 |
158
+ |------|------|--------|------|
159
+ | `initialScheme` | `SchemeJSON` | - | 初始 scheme 数据 |
160
+ | `onChange` | `(scheme: SchemeJSON) => void` | - | scheme 变化回调 |
161
+ | `readonly` | `boolean` | `false` | 是否只读模式 |
162
+ | `showHeader` | `boolean` | `true` | 是否显示头部 |
163
+ | `showMaterialPanel` | `boolean` | `true` | 是否显示物料面板 |
164
+ | `showPropertyPanel` | `boolean` | `true` | 是否显示属性面板 |
165
+ | `customMaterials` | `Material[]` | - | 自定义物料列表 |
166
+ | `headerExtra` | `React.ReactNode` | - | 头部自定义内容 |
167
+ | `className` | `string` | - | 自定义类名 |
168
+ | `style` | `React.CSSProperties` | - | 自定义样式 |
169
+
170
+ ### 类型定义
171
+
172
+ ```typescript
173
+ // Scheme JSON 结构
174
+ interface SchemeJSON {
175
+ version: string;
176
+ nodes: Node[];
177
+ materials: Material[];
178
+ viewport: ViewportState;
179
+ metadata?: {
180
+ name?: string;
181
+ description?: string;
182
+ createdAt?: string;
183
+ updatedAt?: string;
184
+ };
185
+ }
186
+
187
+ // 节点
188
+ interface Node {
189
+ id: string;
190
+ name: string;
191
+ normalStyle: NodeStyle;
192
+ contentInfo: ContentInfo;
193
+ controlInfo: ControlInfo;
194
+ }
195
+
196
+ // 物料
197
+ interface Material {
198
+ id: string;
199
+ name: string;
200
+ type: 'IMAGE' | 'TEXT' | 'LINE' | 'CUSTOM';
201
+ // ... 根据类型不同有更多属性
202
+ }
203
+ ```
204
+
205
+ ## 📁 项目结构
206
+
207
+ ```
208
+ config-editor/
209
+ ├── src/
210
+ │ ├── components/
211
+ │ │ ├── ConfigEditor/ # 主编辑器组件
212
+ │ │ ├── MaterialPanel/ # 物料库面板
213
+ │ │ ├── Canvas/ # 画布编辑器
214
+ │ │ ├── PropertyPanel/ # 属性面板
215
+ │ │ └── NodeRenderer/ # 节点渲染器
216
+ │ ├── store/
217
+ │ │ └── editorStore.ts # Zustand 状态管理
218
+ │ ├── types/
219
+ │ │ └── index.ts # TypeScript 类型定义
220
+ │ ├── utils/
221
+ │ │ └── initData.ts # 初始化数据
222
+ │ ├── index.ts # 库入口
223
+ │ └── index.css # 样式
224
+ ├── examples/ # 使用示例
225
+ └── dist/ # 构建输出
226
+ ```
227
+
228
+ ## 🛠️ 开发
229
+
230
+ ```bash
231
+ # 克隆项目
232
+ git clone https://github.com/yourusername/config-editor.git
233
+ cd config-editor
234
+
235
+ # 安装依赖
236
+ pnpm install
237
+
238
+ # 启动开发服务器
239
+ pnpm dev
240
+
241
+ # 构建库
242
+ pnpm build
243
+ ```
244
+
245
+ ## 📦 发布到 npm
246
+
247
+ ```bash
248
+ # 构建项目
249
+ pnpm build
250
+
251
+ # 登录 npm
252
+ npm login
253
+
254
+ # 发布
255
+ npm publish --access public
256
+ ```
257
+
258
+ ## 📄 协议
259
+
260
+ [MIT](LICENSE) © Your Name
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export declare const Canvas: React.FC<{
3
+ defaultTestData?: any;
4
+ }>;