@flowgram.ai/form-core 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/dist/esm/index.js +835 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +677 -0
- package/dist/index.d.ts +677 -0
- package/dist/index.js +909 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,835 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/node/node-contribution.ts
|
|
13
|
+
var NodeContribution = Symbol("NodeContribution");
|
|
14
|
+
|
|
15
|
+
// src/node/node-container-module.ts
|
|
16
|
+
import { ContainerModule } from "inversify";
|
|
17
|
+
|
|
18
|
+
// src/node/node-manager.ts
|
|
19
|
+
import { flow } from "lodash";
|
|
20
|
+
import { injectable, multiInject, optional, postConstruct } from "inversify";
|
|
21
|
+
var MaterialRenderKey = /* @__PURE__ */ ((MaterialRenderKey2) => {
|
|
22
|
+
MaterialRenderKey2["CustomNodeError"] = "Material_CustomNodeError";
|
|
23
|
+
return MaterialRenderKey2;
|
|
24
|
+
})(MaterialRenderKey || {});
|
|
25
|
+
var NodeManager = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.materialRenderRegistry = /* @__PURE__ */ new Map();
|
|
28
|
+
this.pluginRenderRegistry = /* @__PURE__ */ new Map();
|
|
29
|
+
this.nodeRenderHocs = [];
|
|
30
|
+
this.nodeContributions = [];
|
|
31
|
+
}
|
|
32
|
+
registerMaterialRender(key, render) {
|
|
33
|
+
this.materialRenderRegistry.set(key, render);
|
|
34
|
+
}
|
|
35
|
+
getMaterialRender(key) {
|
|
36
|
+
return this.materialRenderRegistry.get(key);
|
|
37
|
+
}
|
|
38
|
+
registerPluginRender(key, render) {
|
|
39
|
+
this.pluginRenderRegistry.set(key, render);
|
|
40
|
+
}
|
|
41
|
+
getPluginRender(key) {
|
|
42
|
+
return this.pluginRenderRegistry.get(key);
|
|
43
|
+
}
|
|
44
|
+
registerNodeErrorRender(render) {
|
|
45
|
+
this.registerMaterialRender("Material_CustomNodeError" /* CustomNodeError */, render);
|
|
46
|
+
}
|
|
47
|
+
get nodeRenderHoc() {
|
|
48
|
+
return flow(this.nodeRenderHocs);
|
|
49
|
+
}
|
|
50
|
+
registerNodeRenderHoc(hoc) {
|
|
51
|
+
this.nodeRenderHocs.push(hoc);
|
|
52
|
+
}
|
|
53
|
+
get nodeErrorRender() {
|
|
54
|
+
return this.materialRenderRegistry.get("Material_CustomNodeError" /* CustomNodeError */);
|
|
55
|
+
}
|
|
56
|
+
init() {
|
|
57
|
+
this.nodeContributions.forEach((contrib) => contrib.onRegister?.(this));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
__decorateClass([
|
|
61
|
+
multiInject(NodeContribution),
|
|
62
|
+
optional()
|
|
63
|
+
], NodeManager.prototype, "nodeContributions", 2);
|
|
64
|
+
__decorateClass([
|
|
65
|
+
postConstruct()
|
|
66
|
+
], NodeManager.prototype, "init", 1);
|
|
67
|
+
NodeManager = __decorateClass([
|
|
68
|
+
injectable()
|
|
69
|
+
], NodeManager);
|
|
70
|
+
|
|
71
|
+
// src/node/node-engine-context.ts
|
|
72
|
+
import { injectable as injectable2 } from "inversify";
|
|
73
|
+
import { Emitter } from "@flowgram.ai/utils";
|
|
74
|
+
var NodeEngineContext = class {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.onChangeEmitter = new Emitter();
|
|
77
|
+
this.onChange = this.onChangeEmitter.event;
|
|
78
|
+
this._readonly = NodeEngineContext.DEFAULT_READONLY;
|
|
79
|
+
this._json = NodeEngineContext.DEFAULT_JSON;
|
|
80
|
+
}
|
|
81
|
+
get json() {
|
|
82
|
+
return this._json;
|
|
83
|
+
}
|
|
84
|
+
get readonly() {
|
|
85
|
+
return this._readonly;
|
|
86
|
+
}
|
|
87
|
+
set readonly(value) {
|
|
88
|
+
this._readonly = value;
|
|
89
|
+
this.fireChange();
|
|
90
|
+
}
|
|
91
|
+
fireChange() {
|
|
92
|
+
this.updateJSON();
|
|
93
|
+
this.onChangeEmitter.fire(this);
|
|
94
|
+
}
|
|
95
|
+
updateJSON() {
|
|
96
|
+
this._json = {
|
|
97
|
+
readonly: this._readonly
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
NodeEngineContext.DEFAULT_READONLY = false;
|
|
102
|
+
NodeEngineContext.DEFAULT_JSON = { readonly: NodeEngineContext.DEFAULT_READONLY };
|
|
103
|
+
NodeEngineContext = __decorateClass([
|
|
104
|
+
injectable2()
|
|
105
|
+
], NodeEngineContext);
|
|
106
|
+
|
|
107
|
+
// src/node/node-engine.ts
|
|
108
|
+
import { injectable as injectable3, inject } from "inversify";
|
|
109
|
+
var NodeEngine = class {
|
|
110
|
+
};
|
|
111
|
+
__decorateClass([
|
|
112
|
+
inject(NodeManager)
|
|
113
|
+
], NodeEngine.prototype, "nodeManager", 2);
|
|
114
|
+
__decorateClass([
|
|
115
|
+
inject(NodeEngineContext)
|
|
116
|
+
], NodeEngine.prototype, "context", 2);
|
|
117
|
+
NodeEngine = __decorateClass([
|
|
118
|
+
injectable3()
|
|
119
|
+
], NodeEngine);
|
|
120
|
+
|
|
121
|
+
// src/node/node-container-module.ts
|
|
122
|
+
var NodeContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
123
|
+
bind(NodeEngine).toSelf().inSingletonScope();
|
|
124
|
+
bind(NodeManager).toSelf().inSingletonScope();
|
|
125
|
+
bind(NodeEngineContext).toSelf().inSingletonScope();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/node/core-plugins.ts
|
|
129
|
+
var PLUGIN_KEY = {
|
|
130
|
+
FORM: "Plugin_Form",
|
|
131
|
+
ERROR: "Plugin_Error"
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/node/core-materials.ts
|
|
135
|
+
var MATERIAL_KEY = {
|
|
136
|
+
NODE_ERROR_RENDER: "node_error_render",
|
|
137
|
+
NODE_PLACEHOLDER_RENDER: "node_placeholder_render"
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/error/flow-node-error-data.ts
|
|
141
|
+
import { EntityData } from "@flowgram.ai/core";
|
|
142
|
+
var FlowNodeErrorData = class extends EntityData {
|
|
143
|
+
getDefaultData() {
|
|
144
|
+
return { error: null };
|
|
145
|
+
}
|
|
146
|
+
setError(e) {
|
|
147
|
+
this.update({ error: e });
|
|
148
|
+
}
|
|
149
|
+
getError() {
|
|
150
|
+
return this.data.error;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
FlowNodeErrorData.type = "FlowNodeErrorData";
|
|
154
|
+
|
|
155
|
+
// src/error/error-container-module.ts
|
|
156
|
+
import { ContainerModule as ContainerModule2 } from "inversify";
|
|
157
|
+
import { bindContributions } from "@flowgram.ai/utils";
|
|
158
|
+
|
|
159
|
+
// src/error/error-node-contribution.ts
|
|
160
|
+
import { injectable as injectable4 } from "inversify";
|
|
161
|
+
|
|
162
|
+
// src/error/renders/error-render.tsx
|
|
163
|
+
import React2, { useCallback, useEffect } from "react";
|
|
164
|
+
import { useRefresh, useService } from "@flowgram.ai/core";
|
|
165
|
+
|
|
166
|
+
// src/error/renders/default-error-render.tsx
|
|
167
|
+
import React from "react";
|
|
168
|
+
var ERROR_STYLE = {
|
|
169
|
+
color: "#f54a45"
|
|
170
|
+
};
|
|
171
|
+
var defaultErrorRender = ({ error }) => /* @__PURE__ */ React.createElement("div", { style: ERROR_STYLE }, error.message);
|
|
172
|
+
|
|
173
|
+
// src/error/renders/error-render.tsx
|
|
174
|
+
var ErrorRender = ({ node, playgroundContext }) => {
|
|
175
|
+
const refresh = useRefresh();
|
|
176
|
+
const nodeErrorData = node.getData(FlowNodeErrorData);
|
|
177
|
+
const nodeError = nodeErrorData.getError();
|
|
178
|
+
const nodeManager = useService(NodeManager);
|
|
179
|
+
const nodeErrorRender = nodeManager.getMaterialRender(MATERIAL_KEY.NODE_ERROR_RENDER);
|
|
180
|
+
const renderError = useCallback(() => {
|
|
181
|
+
if (!nodeErrorRender) {
|
|
182
|
+
return defaultErrorRender({
|
|
183
|
+
error: nodeError,
|
|
184
|
+
context: { node, playgroundContext }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return nodeErrorRender({
|
|
188
|
+
error: nodeError,
|
|
189
|
+
context: { node, playgroundContext }
|
|
190
|
+
});
|
|
191
|
+
}, [nodeError, node, playgroundContext]);
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
const disposable = nodeErrorData.onDataChange(() => {
|
|
194
|
+
refresh();
|
|
195
|
+
});
|
|
196
|
+
return () => {
|
|
197
|
+
disposable.dispose();
|
|
198
|
+
};
|
|
199
|
+
}, []);
|
|
200
|
+
return nodeError ? renderError() : null;
|
|
201
|
+
};
|
|
202
|
+
var errorPluginRender = (props) => /* @__PURE__ */ React2.createElement(ErrorRender, { ...props });
|
|
203
|
+
|
|
204
|
+
// src/error/error-node-contribution.ts
|
|
205
|
+
var ErrorNodeContribution = class {
|
|
206
|
+
onRegister(nodeManager) {
|
|
207
|
+
nodeManager.registerPluginRender(PLUGIN_KEY.ERROR, errorPluginRender);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
ErrorNodeContribution = __decorateClass([
|
|
211
|
+
injectable4()
|
|
212
|
+
], ErrorNodeContribution);
|
|
213
|
+
|
|
214
|
+
// src/error/error-container-module.ts
|
|
215
|
+
var ErrorContainerModule = new ContainerModule2((bind) => {
|
|
216
|
+
bindContributions(bind, ErrorNodeContribution, [NodeContribution]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// src/error/client.ts
|
|
220
|
+
function getNodeError(node) {
|
|
221
|
+
return node.getData(FlowNodeErrorData).getError();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/form/form-core-container-module.ts
|
|
225
|
+
import { ContainerModule as ContainerModule3 } from "inversify";
|
|
226
|
+
import { bindContributions as bindContributions2 } from "@flowgram.ai/utils";
|
|
227
|
+
|
|
228
|
+
// src/form/services/form-context-maker.ts
|
|
229
|
+
import { inject as inject2, injectable as injectable5 } from "inversify";
|
|
230
|
+
import { injectPlaygroundContext } from "@flowgram.ai/core";
|
|
231
|
+
var FormContextMaker = class {
|
|
232
|
+
makeFormItemMaterialContext(formItem, options) {
|
|
233
|
+
return {
|
|
234
|
+
meta: formItem.meta,
|
|
235
|
+
path: formItem.path,
|
|
236
|
+
readonly: this.nodeEngineContext.readonly,
|
|
237
|
+
getFormItemValueByPath: formItem.formModel.getFormItemValueByPath.bind(formItem.formModel),
|
|
238
|
+
onFormValidate: formItem.formModel.onValidate.bind(formItem.formModel),
|
|
239
|
+
form: formItem.formModel,
|
|
240
|
+
node: formItem.formModel.flowNodeEntity,
|
|
241
|
+
playgroundContext: this.playgroundContext,
|
|
242
|
+
index: options?.getIndex()
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
__decorateClass([
|
|
247
|
+
inject2(NodeEngineContext)
|
|
248
|
+
], FormContextMaker.prototype, "nodeEngineContext", 2);
|
|
249
|
+
__decorateClass([
|
|
250
|
+
injectPlaygroundContext()
|
|
251
|
+
], FormContextMaker.prototype, "playgroundContext", 2);
|
|
252
|
+
FormContextMaker = __decorateClass([
|
|
253
|
+
injectable5()
|
|
254
|
+
], FormContextMaker);
|
|
255
|
+
|
|
256
|
+
// src/form/services/form-path-service.ts
|
|
257
|
+
import { injectable as injectable6 } from "inversify";
|
|
258
|
+
var FormPathService = class {
|
|
259
|
+
static normalize(path) {
|
|
260
|
+
if (path === FormPathService.ROOT) {
|
|
261
|
+
return path;
|
|
262
|
+
}
|
|
263
|
+
if (path.endsWith(FormPathService.DIVIDER)) {
|
|
264
|
+
path = path.slice(0, -1);
|
|
265
|
+
}
|
|
266
|
+
return path;
|
|
267
|
+
}
|
|
268
|
+
static join(paths) {
|
|
269
|
+
if (paths[1].startsWith(FormPathService.ROOT)) {
|
|
270
|
+
throw new Error(
|
|
271
|
+
`FormPathService Error: join failed, invalid paths[1], paths[1]= ${paths[1]}`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (paths[0].endsWith(FormPathService.DIVIDER)) {
|
|
275
|
+
return `${paths[0]}${paths[1]}`;
|
|
276
|
+
}
|
|
277
|
+
return paths.join(FormPathService.DIVIDER);
|
|
278
|
+
}
|
|
279
|
+
static toArrayPath(path) {
|
|
280
|
+
return FormPathService.join([path, FormPathService.ARRAY]);
|
|
281
|
+
}
|
|
282
|
+
static parseArrayItemPath(path) {
|
|
283
|
+
const names = path.split("/");
|
|
284
|
+
let i = 0;
|
|
285
|
+
while (i < names.length) {
|
|
286
|
+
const itemIndex = parseInt(names[i]);
|
|
287
|
+
if (!isNaN(itemIndex)) {
|
|
288
|
+
const arrayPath = FormPathService.toArrayPath(
|
|
289
|
+
names.slice(0, i).join(FormPathService.DIVIDER)
|
|
290
|
+
);
|
|
291
|
+
const restPath = names.slice(i + 1).join(FormPathService.DIVIDER);
|
|
292
|
+
const itemMetaPath = FormPathService.join([arrayPath, restPath]);
|
|
293
|
+
return { itemIndex, arrayPath, itemMetaPath };
|
|
294
|
+
}
|
|
295
|
+
i = i + 1;
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
simplify(path) {
|
|
300
|
+
const segments = path.split(FormPathService.DIVIDER);
|
|
301
|
+
const resSegments = [];
|
|
302
|
+
for (let i = 0; i < segments.length; i++) {
|
|
303
|
+
if (!segments[i]) {
|
|
304
|
+
throw new Error("FormPathService: join failed");
|
|
305
|
+
}
|
|
306
|
+
if (segments[i] === FormPathService.RELATIVE_CURRENT) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (segments[i] === FormPathService.RELATIVE_PARENT) {
|
|
310
|
+
resSegments.pop();
|
|
311
|
+
}
|
|
312
|
+
resSegments.push(segments[i]);
|
|
313
|
+
}
|
|
314
|
+
return resSegments.join(FormPathService.DIVIDER);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
FormPathService.ROOT = "/";
|
|
318
|
+
FormPathService.DIVIDER = "/";
|
|
319
|
+
FormPathService.RELATIVE_PARENT = "..";
|
|
320
|
+
FormPathService.RELATIVE_CURRENT = ".";
|
|
321
|
+
FormPathService.ARRAY = "[]";
|
|
322
|
+
FormPathService = __decorateClass([
|
|
323
|
+
injectable6()
|
|
324
|
+
], FormPathService);
|
|
325
|
+
|
|
326
|
+
// src/form/services/form-manager.ts
|
|
327
|
+
import { mapValues } from "lodash";
|
|
328
|
+
import { inject as inject3, injectable as injectable9, multiInject as multiInject2, optional as optional2, postConstruct as postConstruct2 } from "inversify";
|
|
329
|
+
import { injectPlaygroundContext as injectPlaygroundContext2 } from "@flowgram.ai/core";
|
|
330
|
+
|
|
331
|
+
// src/form/models/form-model.ts
|
|
332
|
+
import { injectable as injectable7 } from "inversify";
|
|
333
|
+
import { DisposableCollection } from "@flowgram.ai/utils";
|
|
334
|
+
var FormModelFactory = Symbol("FormModelFactory");
|
|
335
|
+
var FormModelEntity = Symbol("FormModelEntity");
|
|
336
|
+
var FormModel = class {
|
|
337
|
+
constructor() {
|
|
338
|
+
this.toDispose = new DisposableCollection();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
FormModel = __decorateClass([
|
|
342
|
+
injectable7()
|
|
343
|
+
], FormModel);
|
|
344
|
+
|
|
345
|
+
// src/form/models/form-item.ts
|
|
346
|
+
import { DisposableCollection as DisposableCollection2, Emitter as Emitter2 } from "@flowgram.ai/utils";
|
|
347
|
+
var FormItem = class {
|
|
348
|
+
constructor(meta, path, formModel) {
|
|
349
|
+
this.onInitEventEmitter = new Emitter2();
|
|
350
|
+
this.onInit = this.onInitEventEmitter.event;
|
|
351
|
+
this.toDispose = new DisposableCollection2();
|
|
352
|
+
this.onDispose = this.toDispose.onDispose;
|
|
353
|
+
this.meta = meta;
|
|
354
|
+
this.path = path;
|
|
355
|
+
this.formModel = formModel;
|
|
356
|
+
this.toDispose.push(this.onInitEventEmitter);
|
|
357
|
+
}
|
|
358
|
+
set domRef(domRef) {
|
|
359
|
+
this._domRef = domRef;
|
|
360
|
+
}
|
|
361
|
+
get domRef() {
|
|
362
|
+
return this._domRef;
|
|
363
|
+
}
|
|
364
|
+
dispose() {
|
|
365
|
+
this.toDispose.dispose();
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// src/form/models/form-meta.ts
|
|
370
|
+
var FormMeta = class {
|
|
371
|
+
constructor(root, options) {
|
|
372
|
+
this._root = root;
|
|
373
|
+
this._options = options;
|
|
374
|
+
}
|
|
375
|
+
get root() {
|
|
376
|
+
return this._root;
|
|
377
|
+
}
|
|
378
|
+
get options() {
|
|
379
|
+
return this._options;
|
|
380
|
+
}
|
|
381
|
+
static traverse({ formItemMeta, parentPath = "", handle }) {
|
|
382
|
+
if (!formItemMeta) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const isRoot = !parentPath;
|
|
386
|
+
const path = isRoot ? FormPathService.ROOT : formItemMeta.name ? FormPathService.join([parentPath, formItemMeta.name]) : parentPath;
|
|
387
|
+
handle({ formItemMeta, path });
|
|
388
|
+
if (formItemMeta.items) {
|
|
389
|
+
this.traverse({
|
|
390
|
+
formItemMeta: formItemMeta.items,
|
|
391
|
+
handle,
|
|
392
|
+
parentPath: FormPathService.toArrayPath(path)
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
if (formItemMeta.children && formItemMeta.children.length) {
|
|
396
|
+
formItemMeta.children.forEach((child) => {
|
|
397
|
+
this.traverse({ formItemMeta: child, handle, parentPath: path });
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/form/models/form-ability-extension-registry.ts
|
|
404
|
+
import { injectable as injectable8 } from "inversify";
|
|
405
|
+
var FormAbilityExtensionRegistry = class {
|
|
406
|
+
constructor() {
|
|
407
|
+
this.registry = /* @__PURE__ */ new Map();
|
|
408
|
+
}
|
|
409
|
+
register(extension) {
|
|
410
|
+
this.registry.set(extension.key, extension);
|
|
411
|
+
}
|
|
412
|
+
get(key) {
|
|
413
|
+
return this.registry.get(key);
|
|
414
|
+
}
|
|
415
|
+
get objectMap() {
|
|
416
|
+
return Object.fromEntries(this.registry);
|
|
417
|
+
}
|
|
418
|
+
get collection() {
|
|
419
|
+
return Array.from(this.registry.values());
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
FormAbilityExtensionRegistry = __decorateClass([
|
|
423
|
+
injectable8()
|
|
424
|
+
], FormAbilityExtensionRegistry);
|
|
425
|
+
|
|
426
|
+
// src/form/form-contribution.ts
|
|
427
|
+
var FormContribution = Symbol("FormContribution");
|
|
428
|
+
|
|
429
|
+
// src/form/abilities/setter-ability/setter-ability.ts
|
|
430
|
+
var _SetterAbility = class _SetterAbility {
|
|
431
|
+
get type() {
|
|
432
|
+
return _SetterAbility.type;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
_SetterAbility.type = "setter";
|
|
436
|
+
var SetterAbility = _SetterAbility;
|
|
437
|
+
|
|
438
|
+
// src/form/abilities/decorator-ability/decorator-ability.ts
|
|
439
|
+
var _DecoratorAbility = class _DecoratorAbility {
|
|
440
|
+
get type() {
|
|
441
|
+
return _DecoratorAbility.type;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
_DecoratorAbility.type = "decorator";
|
|
445
|
+
var DecoratorAbility = _DecoratorAbility;
|
|
446
|
+
|
|
447
|
+
// src/form/abilities/visibility-ability/visibility-ability.ts
|
|
448
|
+
var _VisibilityAbility = class _VisibilityAbility {
|
|
449
|
+
get type() {
|
|
450
|
+
return _VisibilityAbility.type;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
_VisibilityAbility.type = "visibility";
|
|
454
|
+
var VisibilityAbility = _VisibilityAbility;
|
|
455
|
+
|
|
456
|
+
// src/form/abilities/effect-ability/effect-ability.ts
|
|
457
|
+
var _EffectAbility = class _EffectAbility {
|
|
458
|
+
get type() {
|
|
459
|
+
return _EffectAbility.type;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
_EffectAbility.type = "effect";
|
|
463
|
+
var EffectAbility = _EffectAbility;
|
|
464
|
+
|
|
465
|
+
// src/form/abilities/default-ability/default-ability.ts
|
|
466
|
+
var _DefaultAbility = class _DefaultAbility {
|
|
467
|
+
get type() {
|
|
468
|
+
return _DefaultAbility.type;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
_DefaultAbility.type = "default";
|
|
472
|
+
var DefaultAbility = _DefaultAbility;
|
|
473
|
+
|
|
474
|
+
// src/form/abilities/validation-ability/validation-ability.ts
|
|
475
|
+
var _ValidationAbility = class _ValidationAbility {
|
|
476
|
+
get type() {
|
|
477
|
+
return _ValidationAbility.type;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
_ValidationAbility.type = "validation";
|
|
481
|
+
var ValidationAbility = _ValidationAbility;
|
|
482
|
+
|
|
483
|
+
// src/form/services/form-manager.ts
|
|
484
|
+
var FormManager = class {
|
|
485
|
+
constructor() {
|
|
486
|
+
this.abilityRegistry = /* @__PURE__ */ new Map();
|
|
487
|
+
this.setterHocs = [];
|
|
488
|
+
this.extensionRegistryMap = /* @__PURE__ */ new Map();
|
|
489
|
+
this.formContributions = [];
|
|
490
|
+
}
|
|
491
|
+
get components() {
|
|
492
|
+
return mapValues(
|
|
493
|
+
this.extensionRegistryMap.get(SetterAbility.type)?.objectMap || {},
|
|
494
|
+
(setter) => setter.component
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
get decorators() {
|
|
498
|
+
return mapValues(
|
|
499
|
+
this.extensionRegistryMap.get(DecoratorAbility.type)?.objectMap || {},
|
|
500
|
+
(decorator) => decorator.component
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
registerAbilityExtension(type, extension) {
|
|
504
|
+
if (!this.extensionRegistryMap.get(type)) {
|
|
505
|
+
this.extensionRegistryMap.set(type, new FormAbilityExtensionRegistry());
|
|
506
|
+
}
|
|
507
|
+
const registry = this.extensionRegistryMap.get(type);
|
|
508
|
+
if (!registry) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
registry.register(extension);
|
|
512
|
+
}
|
|
513
|
+
getAbilityExtension(abilityType, extensionKey) {
|
|
514
|
+
return this.extensionRegistryMap.get(abilityType)?.get(extensionKey);
|
|
515
|
+
}
|
|
516
|
+
registerAbility(Ability) {
|
|
517
|
+
const ability = new Ability();
|
|
518
|
+
this.abilityRegistry.set(ability.type, ability);
|
|
519
|
+
}
|
|
520
|
+
registerAbilities(Abilities) {
|
|
521
|
+
Abilities.forEach(this.registerAbility.bind(this));
|
|
522
|
+
}
|
|
523
|
+
getAbility(type) {
|
|
524
|
+
return this.abilityRegistry.get(type);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* @deprecated
|
|
528
|
+
* Setter Hoc and setter are no longer supported in NodeEngineV2
|
|
529
|
+
* @param hoc
|
|
530
|
+
*/
|
|
531
|
+
registerSetterHoc(hoc) {
|
|
532
|
+
this.setterHocs.push(hoc);
|
|
533
|
+
}
|
|
534
|
+
init() {
|
|
535
|
+
this.formContributions.forEach((contrib) => contrib.onRegister?.(this));
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
__decorateClass([
|
|
539
|
+
inject3(FormPathService)
|
|
540
|
+
], FormManager.prototype, "pathManager", 2);
|
|
541
|
+
__decorateClass([
|
|
542
|
+
inject3(FormContextMaker)
|
|
543
|
+
], FormManager.prototype, "formContextMaker", 2);
|
|
544
|
+
__decorateClass([
|
|
545
|
+
injectPlaygroundContext2()
|
|
546
|
+
], FormManager.prototype, "playgroundContext", 2);
|
|
547
|
+
__decorateClass([
|
|
548
|
+
multiInject2(FormContribution),
|
|
549
|
+
optional2()
|
|
550
|
+
], FormManager.prototype, "formContributions", 2);
|
|
551
|
+
__decorateClass([
|
|
552
|
+
postConstruct2()
|
|
553
|
+
], FormManager.prototype, "init", 1);
|
|
554
|
+
FormManager = __decorateClass([
|
|
555
|
+
injectable9()
|
|
556
|
+
], FormManager);
|
|
557
|
+
|
|
558
|
+
// src/form/form-node-contribution.ts
|
|
559
|
+
import { injectable as injectable10 } from "inversify";
|
|
560
|
+
|
|
561
|
+
// src/form/form-render.tsx
|
|
562
|
+
import React3, { useEffect as useEffect2 } from "react";
|
|
563
|
+
import { useRefresh as useRefresh2 } from "@flowgram.ai/utils";
|
|
564
|
+
|
|
565
|
+
// src/form/flow-node-form-data.ts
|
|
566
|
+
import { Disposable, Emitter as Emitter3 } from "@flowgram.ai/utils";
|
|
567
|
+
import { EntityData as EntityData2 } from "@flowgram.ai/core";
|
|
568
|
+
var FlowNodeFormData = class extends EntityData2 {
|
|
569
|
+
constructor(entity, opts) {
|
|
570
|
+
super(entity);
|
|
571
|
+
/**
|
|
572
|
+
* @deprecated rehaje 版表单form Values change 事件
|
|
573
|
+
* @protected
|
|
574
|
+
*/
|
|
575
|
+
this.onDetailChangeEmitter = new Emitter3();
|
|
576
|
+
/**
|
|
577
|
+
* @deprecated 该方法为旧版引擎(rehaje)表单数据变更事件, 新版节点引擎请使用
|
|
578
|
+
* this.getFormModel<FormModelV2>().onFormValuesChange.
|
|
579
|
+
* @protected
|
|
580
|
+
*/
|
|
581
|
+
this.onDetailChange = this.onDetailChangeEmitter.event;
|
|
582
|
+
this.flowNodeEntity = entity;
|
|
583
|
+
this.formModel = opts.formModelFactory(entity);
|
|
584
|
+
this.toDispose.push(this.onDetailChangeEmitter);
|
|
585
|
+
this.toDispose.push(
|
|
586
|
+
Disposable.create(() => {
|
|
587
|
+
this.formModel.dispose();
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
getFormModel() {
|
|
592
|
+
return this.formModel;
|
|
593
|
+
}
|
|
594
|
+
getDefaultData() {
|
|
595
|
+
return {};
|
|
596
|
+
}
|
|
597
|
+
createForm(formMetaOrFormMetaGenerator, initialValue) {
|
|
598
|
+
const errorData = this.flowNodeEntity.getData(FlowNodeErrorData);
|
|
599
|
+
errorData.setError(null);
|
|
600
|
+
try {
|
|
601
|
+
this.formModel.init(formMetaOrFormMetaGenerator, initialValue);
|
|
602
|
+
} catch (e) {
|
|
603
|
+
errorData.setError(e);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
recreateForm(formMetaOrFormMetaGenerator, initialValue) {
|
|
607
|
+
this.createForm(formMetaOrFormMetaGenerator, initialValue);
|
|
608
|
+
}
|
|
609
|
+
toJSON() {
|
|
610
|
+
return this.formModel.toJSON();
|
|
611
|
+
}
|
|
612
|
+
dispose() {
|
|
613
|
+
super.dispose();
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* @deprecated rehaje 版表单form Values change 事件触发函数
|
|
617
|
+
* @protected
|
|
618
|
+
*/
|
|
619
|
+
fireDetaiChange(detailChangeEvent) {
|
|
620
|
+
this.onDetailChangeEmitter.fire(detailChangeEvent);
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
FlowNodeFormData.type = "FlowNodeEntityFormData";
|
|
624
|
+
|
|
625
|
+
// src/form/form-render.tsx
|
|
626
|
+
function getFormModelFromNode(node) {
|
|
627
|
+
return node.getData(FlowNodeFormData)?.getFormModel();
|
|
628
|
+
}
|
|
629
|
+
function FormRender({ node }) {
|
|
630
|
+
const refresh = useRefresh2();
|
|
631
|
+
const formModel = getFormModelFromNode(node);
|
|
632
|
+
useEffect2(() => {
|
|
633
|
+
const disposable = formModel?.onInitialized(() => {
|
|
634
|
+
refresh();
|
|
635
|
+
});
|
|
636
|
+
return () => {
|
|
637
|
+
disposable.dispose();
|
|
638
|
+
};
|
|
639
|
+
}, [formModel]);
|
|
640
|
+
return formModel?.initialized ? formModel.render() : null;
|
|
641
|
+
}
|
|
642
|
+
var formPluginRender = (props) => /* @__PURE__ */ React3.createElement(FormRender, { ...props });
|
|
643
|
+
|
|
644
|
+
// src/form/form-node-contribution.ts
|
|
645
|
+
var FormNodeContribution = class {
|
|
646
|
+
onRegister(nodeManager) {
|
|
647
|
+
nodeManager.registerPluginRender(PLUGIN_KEY.FORM, formPluginRender);
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
FormNodeContribution = __decorateClass([
|
|
651
|
+
injectable10()
|
|
652
|
+
], FormNodeContribution);
|
|
653
|
+
|
|
654
|
+
// src/form/form-core-container-module.ts
|
|
655
|
+
var FormCoreContainerModule = new ContainerModule3((bind) => {
|
|
656
|
+
bind(FormManager).toSelf().inSingletonScope();
|
|
657
|
+
bind(FormPathService).toSelf().inSingletonScope();
|
|
658
|
+
bind(FormContextMaker).toSelf().inSingletonScope();
|
|
659
|
+
bindContributions2(bind, FormNodeContribution, [NodeContribution]);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
// src/form/types/form-model.types.ts
|
|
663
|
+
var FormItemEventName = /* @__PURE__ */ ((FormItemEventName2) => {
|
|
664
|
+
FormItemEventName2["onFormValueChange"] = "onFormValueChange";
|
|
665
|
+
FormItemEventName2["onFormItemInit"] = "onFormItemInit";
|
|
666
|
+
return FormItemEventName2;
|
|
667
|
+
})(FormItemEventName || {});
|
|
668
|
+
|
|
669
|
+
// src/form/types/form-meta.types.ts
|
|
670
|
+
var FORM_VOID = "form-void";
|
|
671
|
+
|
|
672
|
+
// src/form/client/index.ts
|
|
673
|
+
function isNodeFormReady(node) {
|
|
674
|
+
return node.getData(FlowNodeFormData).getFormModel().initialized;
|
|
675
|
+
}
|
|
676
|
+
function getFormModel(node) {
|
|
677
|
+
return node.getData(FlowNodeFormData).formModel;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/client/create-node-container-modules.ts
|
|
681
|
+
function createNodeContainerModules() {
|
|
682
|
+
return [NodeContainerModule, FormCoreContainerModule, ErrorContainerModule];
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/client/node-render.tsx
|
|
686
|
+
import React5, { memo, useCallback as useCallback2, useEffect as useEffect5 } from "react";
|
|
687
|
+
import { PlaygroundContext as PlaygroundContext4, useRefresh as useRefresh5, useService as useService3 } from "@flowgram.ai/core";
|
|
688
|
+
|
|
689
|
+
// src/node-react/context/node-engine-react-context.ts
|
|
690
|
+
import React4 from "react";
|
|
691
|
+
var NodeEngineReactContext = React4.createContext(
|
|
692
|
+
NodeEngineContext.DEFAULT_JSON
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
// src/node-react/hooks/use-node-engine-context.ts
|
|
696
|
+
import { useEffect as useEffect3 } from "react";
|
|
697
|
+
import { useService as useService2, useRefresh as useRefresh3 } from "@flowgram.ai/core";
|
|
698
|
+
function useNodeEngineContext() {
|
|
699
|
+
const refresh = useRefresh3();
|
|
700
|
+
const nodeEngineContext = useService2(NodeEngineContext);
|
|
701
|
+
useEffect3(() => {
|
|
702
|
+
const disposable = nodeEngineContext.onChange(() => {
|
|
703
|
+
refresh();
|
|
704
|
+
});
|
|
705
|
+
return () => {
|
|
706
|
+
disposable.dispose();
|
|
707
|
+
};
|
|
708
|
+
}, []);
|
|
709
|
+
return nodeEngineContext;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// src/node-react/hooks/use-form-Item.ts
|
|
713
|
+
import { useEffect as useEffect4 } from "react";
|
|
714
|
+
import { useEntityFromContext, useRefresh as useRefresh4 } from "@flowgram.ai/core";
|
|
715
|
+
function useFormItem(path) {
|
|
716
|
+
const refresh = useRefresh4();
|
|
717
|
+
const node = useEntityFromContext();
|
|
718
|
+
const formData = node.getData(FlowNodeFormData);
|
|
719
|
+
const formItem = formData.getFormModel().getFormItemByPath(path);
|
|
720
|
+
useEffect4(() => {
|
|
721
|
+
const disposable = formData.onDataChange(() => {
|
|
722
|
+
refresh();
|
|
723
|
+
});
|
|
724
|
+
return () => {
|
|
725
|
+
disposable.dispose();
|
|
726
|
+
};
|
|
727
|
+
}, []);
|
|
728
|
+
return formItem;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// src/client/node-render.tsx
|
|
732
|
+
var PureNodeRender = ({ node }) => {
|
|
733
|
+
const refresh = useRefresh5();
|
|
734
|
+
const nodeErrorData = node.getData(FlowNodeErrorData);
|
|
735
|
+
const formModel = getFormModel(node);
|
|
736
|
+
const isNodeError = !!getNodeError(node);
|
|
737
|
+
const isFormReady = isNodeFormReady(node);
|
|
738
|
+
const playgroundContext = useService3(PlaygroundContext4);
|
|
739
|
+
const nodeManager = useService3(NodeManager);
|
|
740
|
+
const nodeFormRender = nodeManager.getPluginRender(PLUGIN_KEY.FORM);
|
|
741
|
+
const nodeErrorRender = nodeManager.getPluginRender(PLUGIN_KEY.ERROR);
|
|
742
|
+
const nodePlaceholderRender = nodeManager.getMaterialRender(MATERIAL_KEY.NODE_PLACEHOLDER_RENDER);
|
|
743
|
+
const nodeEngineContext = useNodeEngineContext();
|
|
744
|
+
useEffect5(() => {
|
|
745
|
+
const errorDisposable = nodeErrorData.onDataChange(() => {
|
|
746
|
+
refresh();
|
|
747
|
+
});
|
|
748
|
+
const formDisposable = formModel.onInitialized(() => {
|
|
749
|
+
refresh();
|
|
750
|
+
});
|
|
751
|
+
return () => {
|
|
752
|
+
errorDisposable.dispose();
|
|
753
|
+
formDisposable.dispose();
|
|
754
|
+
};
|
|
755
|
+
}, []);
|
|
756
|
+
const renderContent = useCallback2(() => {
|
|
757
|
+
if (!formModel.formMeta) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
if (isNodeError) {
|
|
761
|
+
return nodeErrorRender({ node, playgroundContext });
|
|
762
|
+
}
|
|
763
|
+
if (isFormReady) {
|
|
764
|
+
return nodeFormRender({ node, playgroundContext });
|
|
765
|
+
}
|
|
766
|
+
return nodePlaceholderRender?.({ node, playgroundContext }) || null;
|
|
767
|
+
}, [
|
|
768
|
+
isNodeError,
|
|
769
|
+
isFormReady,
|
|
770
|
+
nodeErrorRender,
|
|
771
|
+
nodeFormRender,
|
|
772
|
+
nodePlaceholderRender,
|
|
773
|
+
node,
|
|
774
|
+
playgroundContext
|
|
775
|
+
]);
|
|
776
|
+
return /* @__PURE__ */ React5.createElement(NodeEngineReactContext.Provider, { value: nodeEngineContext.json }, nodeManager.nodeRenderHoc(renderContent)());
|
|
777
|
+
};
|
|
778
|
+
var NodeRender = memo(PureNodeRender);
|
|
779
|
+
|
|
780
|
+
// src/client/node-material-client.ts
|
|
781
|
+
function registerNodeErrorRender(nodeManager, render) {
|
|
782
|
+
nodeManager.registerMaterialRender(MATERIAL_KEY.NODE_ERROR_RENDER, render);
|
|
783
|
+
}
|
|
784
|
+
function registerNodePlaceholderRender(nodeManager, render) {
|
|
785
|
+
nodeManager.registerMaterialRender(MATERIAL_KEY.NODE_PLACEHOLDER_RENDER, render);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/client/create-node-entity-datas.ts
|
|
789
|
+
function createNodeEntityDatas() {
|
|
790
|
+
return [FlowNodeFormData, FlowNodeErrorData];
|
|
791
|
+
}
|
|
792
|
+
export {
|
|
793
|
+
DecoratorAbility,
|
|
794
|
+
DefaultAbility,
|
|
795
|
+
EffectAbility,
|
|
796
|
+
ErrorContainerModule,
|
|
797
|
+
FORM_VOID,
|
|
798
|
+
FlowNodeErrorData,
|
|
799
|
+
FlowNodeFormData,
|
|
800
|
+
FormAbilityExtensionRegistry,
|
|
801
|
+
FormContextMaker,
|
|
802
|
+
FormContribution,
|
|
803
|
+
FormCoreContainerModule,
|
|
804
|
+
FormItem,
|
|
805
|
+
FormItemEventName,
|
|
806
|
+
FormManager,
|
|
807
|
+
FormMeta,
|
|
808
|
+
FormModel,
|
|
809
|
+
FormModelEntity,
|
|
810
|
+
FormModelFactory,
|
|
811
|
+
FormPathService,
|
|
812
|
+
MATERIAL_KEY,
|
|
813
|
+
MaterialRenderKey,
|
|
814
|
+
NodeContainerModule,
|
|
815
|
+
NodeContribution,
|
|
816
|
+
NodeEngine,
|
|
817
|
+
NodeEngineContext,
|
|
818
|
+
NodeEngineReactContext,
|
|
819
|
+
NodeManager,
|
|
820
|
+
NodeRender,
|
|
821
|
+
PLUGIN_KEY,
|
|
822
|
+
SetterAbility,
|
|
823
|
+
ValidationAbility,
|
|
824
|
+
VisibilityAbility,
|
|
825
|
+
createNodeContainerModules,
|
|
826
|
+
createNodeEntityDatas,
|
|
827
|
+
getFormModel,
|
|
828
|
+
getNodeError,
|
|
829
|
+
isNodeFormReady,
|
|
830
|
+
registerNodeErrorRender,
|
|
831
|
+
registerNodePlaceholderRender,
|
|
832
|
+
useFormItem,
|
|
833
|
+
useNodeEngineContext
|
|
834
|
+
};
|
|
835
|
+
//# sourceMappingURL=index.js.map
|