@xbeeant/form-engine-designer 0.0.2 → 0.0.4
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/es/Canvas.js +42 -46
- package/dist/es/Canvas.js.map +1 -1
- package/dist/es/Designer.js +121 -98
- package/dist/es/Designer.js.map +1 -1
- package/dist/es/DesignerContext.js +86 -73
- package/dist/es/DesignerContext.js.map +1 -1
- package/dist/es/Palette.js +3 -3
- package/dist/es/Palette.js.map +1 -1
- package/dist/es/PropertyPanel.js +97 -97
- package/dist/es/PropertyPanel.js.map +1 -1
- package/dist/es/catalog.js +19 -11
- package/dist/es/catalog.js.map +1 -1
- package/dist/es/designer-context.js +110 -0
- package/dist/es/designer-context.js.map +1 -0
- package/dist/es/history.js +73 -0
- package/dist/es/history.js.map +1 -0
- package/dist/es/index.js +3 -3
- package/dist/es/property/basic-property.js +6 -0
- package/dist/es/property/basic-property.js.map +1 -1
- package/dist/es/property-panel.js +294 -0
- package/dist/es/property-panel.js.map +1 -0
- package/dist/es/resizable-panel.js +103 -0
- package/dist/es/resizable-panel.js.map +1 -0
- package/dist/es/schema-utils.js +286 -0
- package/dist/es/schema-utils.js.map +1 -0
- package/dist/es/widgets/BindEditor.js +60 -49
- package/dist/es/widgets/BindEditor.js.map +1 -1
- package/dist/es/widgets/CodeEditor.js +41 -49
- package/dist/es/widgets/CodeEditor.js.map +1 -1
- package/dist/es/widgets/DefaultEditor.js +25 -30
- package/dist/es/widgets/DefaultEditor.js.map +1 -1
- package/dist/es/widgets/DependenciesEditor.js +21 -21
- package/dist/es/widgets/DependenciesEditor.js.map +1 -1
- package/dist/es/widgets/EnumEditor.js +25 -31
- package/dist/es/widgets/EnumEditor.js.map +1 -1
- package/dist/es/widgets/ExpressionSwitch.js +32 -30
- package/dist/es/widgets/ExpressionSwitch.js.map +1 -1
- package/dist/es/widgets/ReactionsEditor.js +103 -103
- package/dist/es/widgets/ReactionsEditor.js.map +1 -1
- package/dist/es/widgets/RemoteDataEditor.js +63 -63
- package/dist/es/widgets/RemoteDataEditor.js.map +1 -1
- package/dist/es/widgets/ValidateEditor.js +49 -49
- package/dist/es/widgets/ValidateEditor.js.map +1 -1
- package/dist/es/widgets/bind-editor.js +78 -0
- package/dist/es/widgets/bind-editor.js.map +1 -0
- package/dist/es/widgets/code-editor.js +76 -0
- package/dist/es/widgets/code-editor.js.map +1 -0
- package/dist/es/widgets/default-editor.js +50 -0
- package/dist/es/widgets/default-editor.js.map +1 -0
- package/dist/es/widgets/dependencies-editor.js +36 -0
- package/dist/es/widgets/dependencies-editor.js.map +1 -0
- package/dist/es/widgets/enum-editor.js +43 -0
- package/dist/es/widgets/enum-editor.js.map +1 -0
- package/dist/es/widgets/expression-builder.js +367 -0
- package/dist/es/widgets/expression-builder.js.map +1 -0
- package/dist/es/widgets/expression-model.js +340 -0
- package/dist/es/widgets/expression-model.js.map +1 -0
- package/dist/es/widgets/expression-switch.js +49 -0
- package/dist/es/widgets/expression-switch.js.map +1 -0
- package/dist/es/widgets/index.js +13 -13
- package/dist/es/widgets/index.js.map +1 -1
- package/dist/es/widgets/options-editor.js +102 -0
- package/dist/es/widgets/options-editor.js.map +1 -0
- package/dist/es/widgets/reactions-editor.js +401 -0
- package/dist/es/widgets/reactions-editor.js.map +1 -0
- package/dist/es/widgets/reactions-model.js +107 -0
- package/dist/es/widgets/reactions-model.js.map +1 -0
- package/dist/es/widgets/remote-data-editor.js +314 -0
- package/dist/es/widgets/remote-data-editor.js.map +1 -0
- package/dist/es/widgets/use-form-data-fields.js +16 -0
- package/dist/es/widgets/use-form-data-fields.js.map +1 -0
- package/dist/es/widgets/validate-editor.js +118 -0
- package/dist/es/widgets/validate-editor.js.map +1 -0
- package/package.json +4 -5
- package/dist/es/react/src/components/FormController.js +0 -154
- package/dist/es/react/src/components/FormController.js.map +0 -1
- package/dist/es/react/src/components/NexusField.js +0 -99
- package/dist/es/react/src/components/NexusField.js.map +0 -1
- package/dist/es/react/src/components/NexusForm.js +0 -121
- package/dist/es/react/src/components/NexusForm.js.map +0 -1
- package/dist/es/react/src/components/NexusFormProvider.js +0 -19
- package/dist/es/react/src/components/NexusFormProvider.js.map +0 -1
- package/dist/es/react/src/components/NexusLayout.js +0 -49
- package/dist/es/react/src/components/NexusLayout.js.map +0 -1
- package/dist/es/react/src/components/NexusObject.js +0 -65
- package/dist/es/react/src/components/NexusObject.js.map +0 -1
- package/dist/es/react/src/contexts/FieldInheritContext.js +0 -6
- package/dist/es/react/src/contexts/FieldInheritContext.js.map +0 -1
- package/dist/es/react/src/contexts/GridContext.js +0 -6
- package/dist/es/react/src/contexts/GridContext.js.map +0 -1
- package/dist/es/react/src/contexts/LayoutConfigContext.js +0 -6
- package/dist/es/react/src/contexts/LayoutConfigContext.js.map +0 -1
- package/dist/es/react/src/contexts/NexusContext.js +0 -13
- package/dist/es/react/src/contexts/NexusContext.js.map +0 -1
- package/dist/es/react/src/hooks/useForm.js +0 -10
- package/dist/es/react/src/hooks/useForm.js.map +0 -1
- package/dist/es/react/src/utils/renderTreeNode.js +0 -18
- package/dist/es/react/src/utils/renderTreeNode.js.map +0 -1
- package/dist/es/react/src/utils/resolveColSpan.js +0 -10
- package/dist/es/react/src/utils/resolveColSpan.js.map +0 -1
- package/dist/es/schemaUtils.test.js +0 -188
- package/dist/es/schemaUtils.test.js.map +0 -1
- package/dist/es/vite-env.d.js +0 -2
- package/dist/es/vite-env.d.js.map +0 -1
- package/dist/es/widgets/expressionModel.test.js +0 -193
- package/dist/es/widgets/expressionModel.test.js.map +0 -1
- package/src/Canvas.tsx +0 -1111
- package/src/Designer.css +0 -206
- package/src/Designer.tsx +0 -254
- package/src/DesignerContext.tsx +0 -192
- package/src/Palette.tsx +0 -261
- package/src/PropertyPanel.tsx +0 -486
- package/src/ResizablePanel.tsx +0 -210
- package/src/catalog.ts +0 -526
- package/src/index.ts +0 -25
- package/src/property/basic-property.ts +0 -126
- package/src/schemaUtils.test.ts +0 -261
- package/src/schemaUtils.ts +0 -627
- package/src/types.ts +0 -38
- package/src/vite-env.d.ts +0 -1
- package/src/widgets/BindEditor.tsx +0 -105
- package/src/widgets/CodeEditor.tsx +0 -114
- package/src/widgets/DefaultEditor.tsx +0 -73
- package/src/widgets/DependenciesEditor.tsx +0 -56
- package/src/widgets/EnumEditor.tsx +0 -66
- package/src/widgets/ExpressionBuilder.tsx +0 -509
- package/src/widgets/ExpressionSwitch.tsx +0 -62
- package/src/widgets/OptionsEditor.tsx +0 -141
- package/src/widgets/ReactionsEditor.tsx +0 -532
- package/src/widgets/RemoteDataEditor.tsx +0 -382
- package/src/widgets/ValidateEditor.tsx +0 -162
- package/src/widgets/expressionModel.test.ts +0 -262
- package/src/widgets/expressionModel.ts +0 -573
- package/src/widgets/index.ts +0 -45
- package/src/widgets/reactionsModel.ts +0 -190
- package/src/widgets/useFormDataFields.ts +0 -21
- /package/dist/es/{form-engine-designer.css → index.css} +0 -0
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// reactionsModel — ReactionsEditor 的纯数据模型(无 React / DOM 依赖)
|
|
3
|
-
// Reaction ↔ 可编辑卡片(Card)之间的双向转换,以及补丁值解析
|
|
4
|
-
// ============================================================================
|
|
5
|
-
|
|
6
|
-
import type { Reaction } from '@xbeeant/form-engine';
|
|
7
|
-
|
|
8
|
-
export const BOOLEAN_STATE_KEYS = new Set([
|
|
9
|
-
'visible',
|
|
10
|
-
'hidden',
|
|
11
|
-
'disabled',
|
|
12
|
-
'readOnly',
|
|
13
|
-
'required',
|
|
14
|
-
'loading',
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export const PROPS_KEY = '__props';
|
|
18
|
-
|
|
19
|
-
export const STATE_KEY_OPTIONS: Array<{ label: string; value: string }> = [
|
|
20
|
-
{ label: '计算值(value)', value: 'value' },
|
|
21
|
-
{ label: '显示(visible)', value: 'visible' },
|
|
22
|
-
{ label: '隐藏(hidden)', value: 'hidden' },
|
|
23
|
-
{ label: '禁用(disabled)', value: 'disabled' },
|
|
24
|
-
{ label: '只读(readOnly)', value: 'readOnly' },
|
|
25
|
-
{ label: '必填(required)', value: 'required' },
|
|
26
|
-
{ label: '加载中(loading)', value: 'loading' },
|
|
27
|
-
{ label: '标题(title)', value: 'title' },
|
|
28
|
-
{ label: '描述(description)', value: 'description' },
|
|
29
|
-
{ label: '组件属性(props.*)', value: PROPS_KEY },
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
export interface PatchRow {
|
|
33
|
-
key: string;
|
|
34
|
-
value: unknown;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface Card {
|
|
38
|
-
id: string;
|
|
39
|
-
deps: string;
|
|
40
|
-
when: string;
|
|
41
|
-
fulfillEnabled: boolean;
|
|
42
|
-
fulfillRows: PatchRow[];
|
|
43
|
-
fulfillSchema: string;
|
|
44
|
-
otherwiseEnabled: boolean;
|
|
45
|
-
otherwiseRows: PatchRow[];
|
|
46
|
-
otherwiseSchema: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function genId(): string {
|
|
50
|
-
return Math.random().toString(36).slice(2, 8);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** 文本 → 补丁值:true/false 转布尔、数字转 number,其余(含 {{ }} 表达式)保留字符串 */
|
|
54
|
-
export function parsePatchValue(text: string): unknown {
|
|
55
|
-
const t = text.trim();
|
|
56
|
-
if (t === 'true') {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
if (t === 'false') {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
if (/^-?\d+(\.\d+)?$/.test(t)) {
|
|
63
|
-
return Number(t);
|
|
64
|
-
}
|
|
65
|
-
return text;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function rowsToState(
|
|
69
|
-
rows: PatchRow[],
|
|
70
|
-
): Record<string, unknown> | undefined {
|
|
71
|
-
const state: Record<string, unknown> = {};
|
|
72
|
-
for (const r of rows) {
|
|
73
|
-
const key = r.key.trim();
|
|
74
|
-
if (!key) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (r.value === undefined || r.value === '') {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
state[key] = r.value;
|
|
81
|
-
}
|
|
82
|
-
return Object.keys(state).length > 0 ? state : undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function stateToRows(state: object | undefined): PatchRow[] {
|
|
86
|
-
return state
|
|
87
|
-
? Object.entries(state).map(([key, value]) => ({ key, value }))
|
|
88
|
-
: [];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function parseSchemaText(
|
|
92
|
-
text: string,
|
|
93
|
-
): Record<string, unknown> | undefined {
|
|
94
|
-
const t = text.trim();
|
|
95
|
-
if (!t) {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
const parsed = JSON.parse(t) as unknown;
|
|
100
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
101
|
-
return parsed as Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
} catch {
|
|
104
|
-
// 非法 JSON:忽略本次提交,等待用户修正
|
|
105
|
-
}
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function schemaToText(
|
|
110
|
-
schema: Record<string, unknown> | undefined,
|
|
111
|
-
): string {
|
|
112
|
-
if (!schema || Object.keys(schema).length === 0) {
|
|
113
|
-
return '';
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
return JSON.stringify(schema, null, 2);
|
|
117
|
-
} catch {
|
|
118
|
-
return '';
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function reactionToCard(r: Reaction): Card {
|
|
123
|
-
return {
|
|
124
|
-
id: genId(),
|
|
125
|
-
deps: (r.dependencies ?? []).join(', '),
|
|
126
|
-
when: r.when ?? '',
|
|
127
|
-
fulfillEnabled: !!r.fulfill,
|
|
128
|
-
fulfillRows: stateToRows(r.fulfill?.state),
|
|
129
|
-
fulfillSchema: schemaToText(r.fulfill?.schema),
|
|
130
|
-
otherwiseEnabled: !!r.otherwise,
|
|
131
|
-
otherwiseRows: stateToRows(r.otherwise?.state),
|
|
132
|
-
otherwiseSchema: schemaToText(r.otherwise?.schema),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function buildBranch(
|
|
137
|
-
card: Card,
|
|
138
|
-
branch: 'fulfill' | 'otherwise',
|
|
139
|
-
):
|
|
140
|
-
| { state?: Record<string, unknown>; schema?: Record<string, unknown> }
|
|
141
|
-
| undefined {
|
|
142
|
-
const enabled =
|
|
143
|
-
branch === 'fulfill' ? card.fulfillEnabled : card.otherwiseEnabled;
|
|
144
|
-
if (!enabled) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
const rows = branch === 'fulfill' ? card.fulfillRows : card.otherwiseRows;
|
|
148
|
-
const schemaText =
|
|
149
|
-
branch === 'fulfill' ? card.fulfillSchema : card.otherwiseSchema;
|
|
150
|
-
const state = rowsToState(rows);
|
|
151
|
-
const schema = parseSchemaText(schemaText);
|
|
152
|
-
if (state === undefined && schema === undefined) {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
...(state !== undefined ? { state } : {}),
|
|
157
|
-
...(schema !== undefined ? { schema } : {}),
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function cardToReaction(card: Card): Reaction {
|
|
162
|
-
const reaction: Reaction = {
|
|
163
|
-
dependencies: card.deps
|
|
164
|
-
.split(',')
|
|
165
|
-
.map((s) => s.trim())
|
|
166
|
-
.filter(Boolean),
|
|
167
|
-
};
|
|
168
|
-
const when = card.when.trim();
|
|
169
|
-
if (when) {
|
|
170
|
-
reaction.when = when;
|
|
171
|
-
}
|
|
172
|
-
const fulfill = buildBranch(card, 'fulfill');
|
|
173
|
-
const otherwise = buildBranch(card, 'otherwise');
|
|
174
|
-
if (fulfill) {
|
|
175
|
-
reaction.fulfill = fulfill;
|
|
176
|
-
}
|
|
177
|
-
if (otherwise) {
|
|
178
|
-
reaction.otherwise = otherwise;
|
|
179
|
-
}
|
|
180
|
-
return reaction;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function toManualReactions(value: unknown): Reaction[] {
|
|
184
|
-
if (!Array.isArray(value)) {
|
|
185
|
-
return [];
|
|
186
|
-
}
|
|
187
|
-
return value.filter(
|
|
188
|
-
(r): r is Reaction => !!r && (r as Reaction)._autoExpr !== true,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// useFormDataFields — 从当前设计器 schema 收集 formData 字段(供变量/依赖选择)
|
|
3
|
-
// ============================================================================
|
|
4
|
-
|
|
5
|
-
import { useMemo } from 'react';
|
|
6
|
-
import { useDesigner } from '../DesignerContext';
|
|
7
|
-
import { collectDataFieldOptions, collectDataFieldPaths } from '../schemaUtils';
|
|
8
|
-
|
|
9
|
-
export function useFormDataFields(): string[] {
|
|
10
|
-
const { schema } = useDesigner();
|
|
11
|
-
return useMemo(() => collectDataFieldPaths(schema), [schema]);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** 带字段标题的选项列表:显示 title,值为路径 key(供 dependencies 等选择器) */
|
|
15
|
-
export function useFormDataFieldOptions(): Array<{
|
|
16
|
-
value: string;
|
|
17
|
-
label: string;
|
|
18
|
-
}> {
|
|
19
|
-
const { schema } = useDesigner();
|
|
20
|
-
return useMemo(() => collectDataFieldOptions(schema), [schema]);
|
|
21
|
-
}
|
|
File without changes
|