@flowgram.ai/form-materials 0.3.0 → 0.3.2
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/bin/materials.ts +10 -1
- package/dist/esm/index.js +388 -98
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +173 -90
- package/dist/index.d.ts +173 -90
- package/dist/index.js +453 -171
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/config.json +11 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/config.json +11 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/condition-row/constants.ts +4 -0
- package/src/components/constant-input/config.json +1 -1
- package/src/components/constant-input/index.tsx +1 -1
- package/src/components/constant-input/types.ts +1 -1
- package/src/components/display-outputs/index.tsx +7 -1
- package/src/components/display-schema-tag/index.tsx +1 -1
- package/src/components/display-schema-tree/config.json +1 -1
- package/src/components/display-schema-tree/index.tsx +1 -1
- package/src/components/index.ts +2 -0
- package/src/components/json-schema-editor/config.json +1 -1
- package/src/components/type-selector/index.tsx +1 -1
- package/src/components/variable-selector/index.tsx +1 -1
- package/src/components/variable-selector/use-variable-tree.tsx +1 -1
- package/src/effects/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/config.json +5 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/index.ts +1 -0
- package/src/form-plugins/infer-assign-plugin/config.json +7 -0
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/index.ts +2 -0
- package/src/plugins/disable-declaration-plugin/config.json +5 -0
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/{shared → plugins}/json-schema-preset/create-type-preset-plugin.tsx +4 -2
- package/src/{shared → plugins}/json-schema-preset/type-definition/array.tsx +2 -1
- package/src/{shared → plugins}/json-schema-preset/type-definition/object.tsx +2 -1
- package/src/shared/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/config.json +7 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- /package/src/{shared → plugins}/json-schema-preset/config.json +0 -0
- /package/src/{shared → plugins}/json-schema-preset/index.tsx +0 -0
- /package/src/{shared → plugins}/json-schema-preset/manager.ts +0 -0
- /package/src/{shared → plugins}/json-schema-preset/type-definition/boolean.tsx +0 -0
- /package/src/{shared → plugins}/json-schema-preset/type-definition/index.tsx +0 -0
- /package/src/{shared → plugins}/json-schema-preset/type-definition/integer.tsx +0 -0
- /package/src/{shared → plugins}/json-schema-preset/type-definition/number.tsx +0 -0
- /package/src/{shared → plugins}/json-schema-preset/type-definition/string.tsx +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -6,72 +6,10 @@ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
|
|
|
6
6
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
7
7
|
import React10, { useCallback } from "react";
|
|
8
8
|
import { JsonSchemaUtils as JsonSchemaUtils2 } from "@flowgram.ai/json-schema";
|
|
9
|
-
import { ASTMatch, useAvailableVariables } from "@flowgram.ai/editor";
|
|
9
|
+
import { ASTMatch as ASTMatch2, useAvailableVariables } from "@flowgram.ai/editor";
|
|
10
10
|
import { Icon } from "@douyinfe/semi-ui";
|
|
11
11
|
|
|
12
|
-
// src/
|
|
13
|
-
import { isObject } from "lodash";
|
|
14
|
-
function formatLegacyRefOnSubmit(value) {
|
|
15
|
-
if (isObject(value)) {
|
|
16
|
-
if (isLegacyFlowRefValueSchema(value)) {
|
|
17
|
-
return formatLegacyRefToNewRef(value);
|
|
18
|
-
}
|
|
19
|
-
return Object.fromEntries(
|
|
20
|
-
Object.entries(value).map(([key, value2]) => [
|
|
21
|
-
key,
|
|
22
|
-
formatLegacyRefOnSubmit(value2)
|
|
23
|
-
])
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(value)) {
|
|
27
|
-
return value.map(formatLegacyRefOnSubmit);
|
|
28
|
-
}
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
function formatLegacyRefOnInit(value) {
|
|
32
|
-
if (isObject(value)) {
|
|
33
|
-
if (isNewFlowRefValueSchema(value)) {
|
|
34
|
-
return formatNewRefToLegacyRef(value);
|
|
35
|
-
}
|
|
36
|
-
return Object.fromEntries(
|
|
37
|
-
Object.entries(value).map(([key, value2]) => [
|
|
38
|
-
key,
|
|
39
|
-
formatLegacyRefOnInit(value2)
|
|
40
|
-
])
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (Array.isArray(value)) {
|
|
44
|
-
return value.map(formatLegacyRefOnInit);
|
|
45
|
-
}
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
function isLegacyFlowRefValueSchema(value) {
|
|
49
|
-
return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
|
|
50
|
-
}
|
|
51
|
-
function isNewFlowRefValueSchema(value) {
|
|
52
|
-
return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
|
|
53
|
-
}
|
|
54
|
-
function formatLegacyRefToNewRef(value) {
|
|
55
|
-
const keyPath = value.content.split(".");
|
|
56
|
-
if (keyPath[1] === "outputs") {
|
|
57
|
-
return {
|
|
58
|
-
type: "ref",
|
|
59
|
-
content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
type: "ref",
|
|
64
|
-
content: keyPath
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function formatNewRefToLegacyRef(value) {
|
|
68
|
-
return {
|
|
69
|
-
type: "ref",
|
|
70
|
-
content: value.content.join(".")
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// src/shared/json-schema-preset/index.tsx
|
|
12
|
+
// src/plugins/json-schema-preset/index.tsx
|
|
75
13
|
import React9 from "react";
|
|
76
14
|
import {
|
|
77
15
|
JsonSchemaUtils,
|
|
@@ -79,10 +17,10 @@ import {
|
|
|
79
17
|
TypePresetProvider as OriginTypePresetProvider
|
|
80
18
|
} from "@flowgram.ai/json-schema";
|
|
81
19
|
|
|
82
|
-
// src/
|
|
20
|
+
// src/plugins/json-schema-preset/type-definition/index.tsx
|
|
83
21
|
import { jsonSchemaTypeManager } from "@flowgram.ai/json-schema";
|
|
84
22
|
|
|
85
|
-
// src/
|
|
23
|
+
// src/plugins/json-schema-preset/type-definition/string.tsx
|
|
86
24
|
import React from "react";
|
|
87
25
|
import { Input } from "@douyinfe/semi-ui";
|
|
88
26
|
var stringRegistry = {
|
|
@@ -90,7 +28,7 @@ var stringRegistry = {
|
|
|
90
28
|
ConstantRenderer: (props) => /* @__PURE__ */ React.createElement(Input, { placeholder: "Please Input String", size: "small", disabled: props.readonly, ...props })
|
|
91
29
|
};
|
|
92
30
|
|
|
93
|
-
// src/
|
|
31
|
+
// src/plugins/json-schema-preset/type-definition/object.tsx
|
|
94
32
|
import React4 from "react";
|
|
95
33
|
|
|
96
34
|
// src/components/code-editor-mini/index.tsx
|
|
@@ -462,7 +400,7 @@ function CodeEditorMini(props) {
|
|
|
462
400
|
));
|
|
463
401
|
}
|
|
464
402
|
|
|
465
|
-
// src/
|
|
403
|
+
// src/plugins/json-schema-preset/type-definition/object.tsx
|
|
466
404
|
var objectRegistry = {
|
|
467
405
|
type: "object",
|
|
468
406
|
ConstantRenderer: (props) => /* @__PURE__ */ React4.createElement(
|
|
@@ -477,7 +415,7 @@ var objectRegistry = {
|
|
|
477
415
|
)
|
|
478
416
|
};
|
|
479
417
|
|
|
480
|
-
// src/
|
|
418
|
+
// src/plugins/json-schema-preset/type-definition/number.tsx
|
|
481
419
|
import React5 from "react";
|
|
482
420
|
import { InputNumber } from "@douyinfe/semi-ui";
|
|
483
421
|
var numberRegistry = {
|
|
@@ -494,7 +432,7 @@ var numberRegistry = {
|
|
|
494
432
|
)
|
|
495
433
|
};
|
|
496
434
|
|
|
497
|
-
// src/
|
|
435
|
+
// src/plugins/json-schema-preset/type-definition/integer.tsx
|
|
498
436
|
import React6 from "react";
|
|
499
437
|
import { InputNumber as InputNumber2 } from "@douyinfe/semi-ui";
|
|
500
438
|
var integerRegistry = {
|
|
@@ -511,7 +449,7 @@ var integerRegistry = {
|
|
|
511
449
|
)
|
|
512
450
|
};
|
|
513
451
|
|
|
514
|
-
// src/
|
|
452
|
+
// src/plugins/json-schema-preset/type-definition/boolean.tsx
|
|
515
453
|
import React7 from "react";
|
|
516
454
|
import { Select } from "@douyinfe/semi-ui";
|
|
517
455
|
var booleanRegistry = {
|
|
@@ -536,7 +474,7 @@ var booleanRegistry = {
|
|
|
536
474
|
}
|
|
537
475
|
};
|
|
538
476
|
|
|
539
|
-
// src/
|
|
477
|
+
// src/plugins/json-schema-preset/type-definition/array.tsx
|
|
540
478
|
import React8 from "react";
|
|
541
479
|
var arrayRegistry = {
|
|
542
480
|
type: "array",
|
|
@@ -552,7 +490,7 @@ var arrayRegistry = {
|
|
|
552
490
|
)
|
|
553
491
|
};
|
|
554
492
|
|
|
555
|
-
// src/
|
|
493
|
+
// src/plugins/json-schema-preset/type-definition/index.tsx
|
|
556
494
|
var jsonSchemaTypePreset = [
|
|
557
495
|
stringRegistry,
|
|
558
496
|
objectRegistry,
|
|
@@ -563,7 +501,7 @@ var jsonSchemaTypePreset = [
|
|
|
563
501
|
];
|
|
564
502
|
jsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));
|
|
565
503
|
|
|
566
|
-
// src/
|
|
504
|
+
// src/plugins/json-schema-preset/create-type-preset-plugin.tsx
|
|
567
505
|
import {
|
|
568
506
|
BaseTypeManager,
|
|
569
507
|
jsonSchemaContainerModule
|
|
@@ -573,18 +511,43 @@ var createTypePresetPlugin = definePluginCreator({
|
|
|
573
511
|
onInit(ctx, opts) {
|
|
574
512
|
const typeManager = ctx.get(BaseTypeManager);
|
|
575
513
|
jsonSchemaTypePreset.forEach((_type) => typeManager.register(_type));
|
|
576
|
-
opts.types
|
|
514
|
+
opts.types?.forEach((_type) => typeManager.register(_type));
|
|
515
|
+
opts.unregisterTypes?.forEach((_type) => typeManager.unregister(_type));
|
|
577
516
|
},
|
|
578
517
|
containerModules: [jsonSchemaContainerModule]
|
|
579
518
|
});
|
|
580
519
|
|
|
581
|
-
// src/
|
|
520
|
+
// src/plugins/json-schema-preset/index.tsx
|
|
582
521
|
var useTypeManager = () => useOriginTypeManager();
|
|
583
522
|
var JsonSchemaTypePresetProvider = ({
|
|
584
523
|
types = [],
|
|
585
524
|
children
|
|
586
525
|
}) => /* @__PURE__ */ React9.createElement(OriginTypePresetProvider, { types: [...jsonSchemaTypePreset, ...types] }, children);
|
|
587
526
|
|
|
527
|
+
// src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts
|
|
528
|
+
import {
|
|
529
|
+
ASTMatch,
|
|
530
|
+
definePluginCreator as definePluginCreator2,
|
|
531
|
+
VariableEngine
|
|
532
|
+
} from "@flowgram.ai/editor";
|
|
533
|
+
var createDisableDeclarationPlugin = definePluginCreator2({
|
|
534
|
+
onInit(ctx) {
|
|
535
|
+
const variableEngine = ctx.get(VariableEngine);
|
|
536
|
+
const handleEvent = (action) => {
|
|
537
|
+
if (ASTMatch.isVariableDeclaration(action.ast)) {
|
|
538
|
+
if (!action.ast.meta?.disabled) {
|
|
539
|
+
action.ast.updateMeta({
|
|
540
|
+
...action.ast.meta || {},
|
|
541
|
+
disabled: true
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
variableEngine.onGlobalEvent("NewAST", handleEvent);
|
|
547
|
+
variableEngine.onGlobalEvent("UpdateAST", handleEvent);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
|
|
588
551
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
589
552
|
function useVariableTree(params) {
|
|
590
553
|
const { includeSchema, excludeSchema, customSkip } = params;
|
|
@@ -606,7 +569,7 @@ function useVariableTree(params) {
|
|
|
606
569
|
return null;
|
|
607
570
|
}
|
|
608
571
|
let children;
|
|
609
|
-
if (
|
|
572
|
+
if (ASTMatch2.isObject(type)) {
|
|
610
573
|
children = (type.properties || []).map((_property) => renderVariable(_property, [...parentFields, variable])).filter(Boolean);
|
|
611
574
|
}
|
|
612
575
|
const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
|
|
@@ -772,7 +735,7 @@ var VariableSelector = ({
|
|
|
772
735
|
showClear: false,
|
|
773
736
|
arrowIcon: /* @__PURE__ */ React11.createElement(IconChevronDownStroked, { size: "small" }),
|
|
774
737
|
triggerRender,
|
|
775
|
-
placeholder: config?.placeholder ?? "Select Variable
|
|
738
|
+
placeholder: config?.placeholder ?? "Select Variable"
|
|
776
739
|
}
|
|
777
740
|
));
|
|
778
741
|
};
|
|
@@ -1766,7 +1729,11 @@ var rules = {
|
|
|
1766
1729
|
},
|
|
1767
1730
|
array: {
|
|
1768
1731
|
["is_empty" /* IS_EMPTY */]: null,
|
|
1769
|
-
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1732
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null,
|
|
1733
|
+
["contains" /* CONTAINS */]: "array",
|
|
1734
|
+
["not_contains" /* NOT_CONTAINS */]: "array",
|
|
1735
|
+
["eq" /* EQ */]: "array",
|
|
1736
|
+
["neq" /* NEQ */]: "array"
|
|
1770
1737
|
},
|
|
1771
1738
|
map: {
|
|
1772
1739
|
["is_empty" /* IS_EMPTY */]: null,
|
|
@@ -1936,7 +1903,7 @@ import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
|
|
|
1936
1903
|
// src/hooks/use-object-list/index.tsx
|
|
1937
1904
|
import { useEffect as useEffect4, useState as useState6 } from "react";
|
|
1938
1905
|
import { nanoid } from "nanoid";
|
|
1939
|
-
import { difference, get, isObject
|
|
1906
|
+
import { difference, get, isObject, set } from "lodash";
|
|
1940
1907
|
function genId2() {
|
|
1941
1908
|
return nanoid();
|
|
1942
1909
|
}
|
|
@@ -1986,7 +1953,7 @@ function useObjectList({
|
|
|
1986
1953
|
onChange(
|
|
1987
1954
|
Object.fromEntries(
|
|
1988
1955
|
nextList.filter((item) => item.key).map((item) => [item.key, item.value]).map((_res, idx) => {
|
|
1989
|
-
if (
|
|
1956
|
+
if (isObject(_res[1]) && sortIndexKey) {
|
|
1990
1957
|
set(_res[1], sortIndexKey, idx);
|
|
1991
1958
|
}
|
|
1992
1959
|
return _res;
|
|
@@ -2496,7 +2463,7 @@ import {
|
|
|
2496
2463
|
import React27, { useMemo as useMemo10 } from "react";
|
|
2497
2464
|
import { last as last2 } from "lodash";
|
|
2498
2465
|
import {
|
|
2499
|
-
ASTMatch as
|
|
2466
|
+
ASTMatch as ASTMatch3,
|
|
2500
2467
|
useScopeAvailable as useScopeAvailable3
|
|
2501
2468
|
} from "@flowgram.ai/editor";
|
|
2502
2469
|
import { Tree as Tree2 } from "@douyinfe/semi-ui";
|
|
@@ -2506,7 +2473,7 @@ function InputsPicker({
|
|
|
2506
2473
|
}) {
|
|
2507
2474
|
const available = useScopeAvailable3();
|
|
2508
2475
|
const getArrayDrilldown = (type, depth = 1) => {
|
|
2509
|
-
if (
|
|
2476
|
+
if (ASTMatch3.isArray(type.items)) {
|
|
2510
2477
|
return getArrayDrilldown(type.items, depth + 1);
|
|
2511
2478
|
}
|
|
2512
2479
|
return { type: type.items, depth };
|
|
@@ -2514,12 +2481,12 @@ function InputsPicker({
|
|
|
2514
2481
|
const renderVariable = (variable, keyPath) => {
|
|
2515
2482
|
let type = variable?.type;
|
|
2516
2483
|
let children;
|
|
2517
|
-
if (
|
|
2484
|
+
if (ASTMatch3.isObject(type)) {
|
|
2518
2485
|
children = (type.properties || []).map((_property) => renderVariable(_property, [...keyPath, _property.key])).filter(Boolean);
|
|
2519
2486
|
}
|
|
2520
|
-
if (
|
|
2487
|
+
if (ASTMatch3.isArray(type)) {
|
|
2521
2488
|
const drilldown = getArrayDrilldown(type);
|
|
2522
|
-
if (
|
|
2489
|
+
if (ASTMatch3.isObject(drilldown.type)) {
|
|
2523
2490
|
children = (drilldown.type.properties || []).map(
|
|
2524
2491
|
(_property) => renderVariable(_property, [
|
|
2525
2492
|
...keyPath,
|
|
@@ -3159,7 +3126,16 @@ function DisplayOutputs({ value, showIconInTree, displayFromScope }) {
|
|
|
3159
3126
|
return acm;
|
|
3160
3127
|
}, {}) : value?.properties || {};
|
|
3161
3128
|
const childEntries = Object.entries(properties || {});
|
|
3162
|
-
return /* @__PURE__ */ React37.createElement(DisplayOutputsWrapper, null, childEntries.map(([key, schema]) => /* @__PURE__ */ React37.createElement(
|
|
3129
|
+
return /* @__PURE__ */ React37.createElement(DisplayOutputsWrapper, null, childEntries.map(([key, schema]) => /* @__PURE__ */ React37.createElement(
|
|
3130
|
+
DisplaySchemaTag,
|
|
3131
|
+
{
|
|
3132
|
+
key,
|
|
3133
|
+
title: key,
|
|
3134
|
+
value: schema,
|
|
3135
|
+
showIconInTree,
|
|
3136
|
+
warning: !schema
|
|
3137
|
+
}
|
|
3138
|
+
)));
|
|
3163
3139
|
}
|
|
3164
3140
|
|
|
3165
3141
|
// src/components/display-flow-value/index.tsx
|
|
@@ -3220,6 +3196,127 @@ function DisplayInputsValues({ value, showIconInTree }) {
|
|
|
3220
3196
|
return /* @__PURE__ */ React39.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => /* @__PURE__ */ React39.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree })));
|
|
3221
3197
|
}
|
|
3222
3198
|
|
|
3199
|
+
// src/components/assign-rows/index.tsx
|
|
3200
|
+
import React42 from "react";
|
|
3201
|
+
import { FieldArray } from "@flowgram.ai/editor";
|
|
3202
|
+
import { Button as Button5 } from "@douyinfe/semi-ui";
|
|
3203
|
+
import { IconPlus as IconPlus4 } from "@douyinfe/semi-icons";
|
|
3204
|
+
|
|
3205
|
+
// src/components/assign-row/index.tsx
|
|
3206
|
+
import React41 from "react";
|
|
3207
|
+
import { IconButton as IconButton6 } from "@douyinfe/semi-ui";
|
|
3208
|
+
import { IconMinus as IconMinus2 } from "@douyinfe/semi-icons";
|
|
3209
|
+
|
|
3210
|
+
// src/components/assign-row/components/blur-input.tsx
|
|
3211
|
+
import React40, { useEffect as useEffect11, useState as useState11 } from "react";
|
|
3212
|
+
import Input7 from "@douyinfe/semi-ui/lib/es/input";
|
|
3213
|
+
function BlurInput3(props) {
|
|
3214
|
+
const [value, setValue] = useState11("");
|
|
3215
|
+
useEffect11(() => {
|
|
3216
|
+
setValue(props.value);
|
|
3217
|
+
}, [props.value]);
|
|
3218
|
+
return /* @__PURE__ */ React40.createElement(
|
|
3219
|
+
Input7,
|
|
3220
|
+
{
|
|
3221
|
+
...props,
|
|
3222
|
+
value,
|
|
3223
|
+
onChange: (value2) => {
|
|
3224
|
+
setValue(value2);
|
|
3225
|
+
},
|
|
3226
|
+
onBlur: (e) => props.onChange?.(value, e)
|
|
3227
|
+
}
|
|
3228
|
+
);
|
|
3229
|
+
}
|
|
3230
|
+
|
|
3231
|
+
// src/components/assign-row/index.tsx
|
|
3232
|
+
function AssignRow(props) {
|
|
3233
|
+
const {
|
|
3234
|
+
value = {
|
|
3235
|
+
operator: "assign"
|
|
3236
|
+
},
|
|
3237
|
+
onChange,
|
|
3238
|
+
onDelete,
|
|
3239
|
+
readonly
|
|
3240
|
+
} = props;
|
|
3241
|
+
return /* @__PURE__ */ React41.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5 } }, /* @__PURE__ */ React41.createElement("div", { style: { width: 150, minWidth: 150, maxWidth: 150 } }, value?.operator === "assign" ? /* @__PURE__ */ React41.createElement(
|
|
3242
|
+
VariableSelector,
|
|
3243
|
+
{
|
|
3244
|
+
style: { width: "100%", height: 26 },
|
|
3245
|
+
value: value?.left?.content,
|
|
3246
|
+
config: { placeholder: "Select Left" },
|
|
3247
|
+
onChange: (v) => onChange?.({
|
|
3248
|
+
...value,
|
|
3249
|
+
left: { type: "ref", content: v }
|
|
3250
|
+
})
|
|
3251
|
+
}
|
|
3252
|
+
) : /* @__PURE__ */ React41.createElement(
|
|
3253
|
+
BlurInput3,
|
|
3254
|
+
{
|
|
3255
|
+
style: { height: 26 },
|
|
3256
|
+
size: "small",
|
|
3257
|
+
placeholder: "Input Name",
|
|
3258
|
+
value: value?.left,
|
|
3259
|
+
onChange: (v) => onChange?.({
|
|
3260
|
+
...value,
|
|
3261
|
+
left: v
|
|
3262
|
+
})
|
|
3263
|
+
}
|
|
3264
|
+
)), /* @__PURE__ */ React41.createElement("div", { style: { flexGrow: 1 } }, /* @__PURE__ */ React41.createElement(
|
|
3265
|
+
DynamicValueInput,
|
|
3266
|
+
{
|
|
3267
|
+
readonly,
|
|
3268
|
+
value: value?.right,
|
|
3269
|
+
onChange: (v) => onChange?.({
|
|
3270
|
+
...value,
|
|
3271
|
+
right: v
|
|
3272
|
+
})
|
|
3273
|
+
}
|
|
3274
|
+
)), onDelete && /* @__PURE__ */ React41.createElement("div", null, /* @__PURE__ */ React41.createElement(
|
|
3275
|
+
IconButton6,
|
|
3276
|
+
{
|
|
3277
|
+
size: "small",
|
|
3278
|
+
theme: "borderless",
|
|
3279
|
+
icon: /* @__PURE__ */ React41.createElement(IconMinus2, null),
|
|
3280
|
+
onClick: () => onDelete?.()
|
|
3281
|
+
}
|
|
3282
|
+
)));
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// src/components/assign-rows/index.tsx
|
|
3286
|
+
function AssignRows(props) {
|
|
3287
|
+
const { name, readonly } = props;
|
|
3288
|
+
return /* @__PURE__ */ React42.createElement(FieldArray, { name }, ({ field }) => /* @__PURE__ */ React42.createElement(React42.Fragment, null, field.map((childField, index) => /* @__PURE__ */ React42.createElement(
|
|
3289
|
+
AssignRow,
|
|
3290
|
+
{
|
|
3291
|
+
key: childField.key,
|
|
3292
|
+
readonly,
|
|
3293
|
+
value: childField.value,
|
|
3294
|
+
onChange: (value) => {
|
|
3295
|
+
childField.onChange(value);
|
|
3296
|
+
},
|
|
3297
|
+
onDelete: () => field.remove(index)
|
|
3298
|
+
}
|
|
3299
|
+
)), /* @__PURE__ */ React42.createElement("div", { style: { display: "flex", gap: 5 } }, /* @__PURE__ */ React42.createElement(
|
|
3300
|
+
Button5,
|
|
3301
|
+
{
|
|
3302
|
+
size: "small",
|
|
3303
|
+
theme: "borderless",
|
|
3304
|
+
icon: /* @__PURE__ */ React42.createElement(IconPlus4, null),
|
|
3305
|
+
onClick: () => field.append({ operator: "assign" })
|
|
3306
|
+
},
|
|
3307
|
+
"Assign"
|
|
3308
|
+
), /* @__PURE__ */ React42.createElement(
|
|
3309
|
+
Button5,
|
|
3310
|
+
{
|
|
3311
|
+
size: "small",
|
|
3312
|
+
theme: "borderless",
|
|
3313
|
+
icon: /* @__PURE__ */ React42.createElement(IconPlus4, null),
|
|
3314
|
+
onClick: () => field.append({ operator: "declare" })
|
|
3315
|
+
},
|
|
3316
|
+
"Declaration"
|
|
3317
|
+
))));
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3223
3320
|
// src/effects/provide-batch-input/index.ts
|
|
3224
3321
|
import {
|
|
3225
3322
|
ASTFactory,
|
|
@@ -3256,7 +3353,7 @@ var provideBatchInputEffect = createEffectFromVariableProvider({
|
|
|
3256
3353
|
});
|
|
3257
3354
|
|
|
3258
3355
|
// src/effects/auto-rename-ref/index.ts
|
|
3259
|
-
import { isArray, isObject as
|
|
3356
|
+
import { isArray, isObject as isObject2, uniq } from "lodash";
|
|
3260
3357
|
import {
|
|
3261
3358
|
DataEvent,
|
|
3262
3359
|
VariableFieldKeyRenameService
|
|
@@ -3326,7 +3423,7 @@ function isTemplate(value) {
|
|
|
3326
3423
|
return value?.type === "template" && typeof value?.content === "string";
|
|
3327
3424
|
}
|
|
3328
3425
|
function traverseRef(name, value, cb) {
|
|
3329
|
-
if (
|
|
3426
|
+
if (isObject2(value)) {
|
|
3330
3427
|
if (isRef(value)) {
|
|
3331
3428
|
cb(name, value);
|
|
3332
3429
|
return;
|
|
@@ -3391,14 +3488,100 @@ var syncVariableTitle = [
|
|
|
3391
3488
|
}
|
|
3392
3489
|
];
|
|
3393
3490
|
|
|
3491
|
+
// src/effects/validate-when-variable-sync/index.ts
|
|
3492
|
+
import { isEmpty } from "lodash";
|
|
3493
|
+
import {
|
|
3494
|
+
DataEvent as DataEvent3,
|
|
3495
|
+
getNodeScope,
|
|
3496
|
+
getNodePrivateScope
|
|
3497
|
+
} from "@flowgram.ai/editor";
|
|
3498
|
+
var validateWhenVariableSync = ({
|
|
3499
|
+
scope
|
|
3500
|
+
} = {}) => [
|
|
3501
|
+
{
|
|
3502
|
+
event: DataEvent3.onValueInit,
|
|
3503
|
+
effect: ({ context, form }) => {
|
|
3504
|
+
const nodeScope = scope === "private" ? getNodePrivateScope(context.node) : getNodeScope(context.node);
|
|
3505
|
+
const disposable = nodeScope.available.onListOrAnyVarChange(() => {
|
|
3506
|
+
if (!isEmpty(form.state.errors)) {
|
|
3507
|
+
form.validate();
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
return () => disposable.dispose();
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
];
|
|
3514
|
+
|
|
3515
|
+
// src/shared/format-legacy-refs/index.ts
|
|
3516
|
+
import { isObject as isObject3 } from "lodash";
|
|
3517
|
+
function formatLegacyRefOnSubmit(value) {
|
|
3518
|
+
if (isObject3(value)) {
|
|
3519
|
+
if (isLegacyFlowRefValueSchema(value)) {
|
|
3520
|
+
return formatLegacyRefToNewRef(value);
|
|
3521
|
+
}
|
|
3522
|
+
return Object.fromEntries(
|
|
3523
|
+
Object.entries(value).map(([key, value2]) => [
|
|
3524
|
+
key,
|
|
3525
|
+
formatLegacyRefOnSubmit(value2)
|
|
3526
|
+
])
|
|
3527
|
+
);
|
|
3528
|
+
}
|
|
3529
|
+
if (Array.isArray(value)) {
|
|
3530
|
+
return value.map(formatLegacyRefOnSubmit);
|
|
3531
|
+
}
|
|
3532
|
+
return value;
|
|
3533
|
+
}
|
|
3534
|
+
function formatLegacyRefOnInit(value) {
|
|
3535
|
+
if (isObject3(value)) {
|
|
3536
|
+
if (isNewFlowRefValueSchema(value)) {
|
|
3537
|
+
return formatNewRefToLegacyRef(value);
|
|
3538
|
+
}
|
|
3539
|
+
return Object.fromEntries(
|
|
3540
|
+
Object.entries(value).map(([key, value2]) => [
|
|
3541
|
+
key,
|
|
3542
|
+
formatLegacyRefOnInit(value2)
|
|
3543
|
+
])
|
|
3544
|
+
);
|
|
3545
|
+
}
|
|
3546
|
+
if (Array.isArray(value)) {
|
|
3547
|
+
return value.map(formatLegacyRefOnInit);
|
|
3548
|
+
}
|
|
3549
|
+
return value;
|
|
3550
|
+
}
|
|
3551
|
+
function isLegacyFlowRefValueSchema(value) {
|
|
3552
|
+
return isObject3(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
|
|
3553
|
+
}
|
|
3554
|
+
function isNewFlowRefValueSchema(value) {
|
|
3555
|
+
return isObject3(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
|
|
3556
|
+
}
|
|
3557
|
+
function formatLegacyRefToNewRef(value) {
|
|
3558
|
+
const keyPath = value.content.split(".");
|
|
3559
|
+
if (keyPath[1] === "outputs") {
|
|
3560
|
+
return {
|
|
3561
|
+
type: "ref",
|
|
3562
|
+
content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
return {
|
|
3566
|
+
type: "ref",
|
|
3567
|
+
content: keyPath
|
|
3568
|
+
};
|
|
3569
|
+
}
|
|
3570
|
+
function formatNewRefToLegacyRef(value) {
|
|
3571
|
+
return {
|
|
3572
|
+
type: "ref",
|
|
3573
|
+
content: value.content.join(".")
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3394
3577
|
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
3395
3578
|
import {
|
|
3396
3579
|
ASTFactory as ASTFactory3,
|
|
3397
3580
|
createEffectFromVariableProvider as createEffectFromVariableProvider3,
|
|
3398
3581
|
defineFormPluginCreator,
|
|
3399
3582
|
getNodeForm as getNodeForm3,
|
|
3400
|
-
getNodePrivateScope,
|
|
3401
|
-
getNodeScope,
|
|
3583
|
+
getNodePrivateScope as getNodePrivateScope2,
|
|
3584
|
+
getNodeScope as getNodeScope2,
|
|
3402
3585
|
ScopeChainTransformService,
|
|
3403
3586
|
FlowNodeScopeType
|
|
3404
3587
|
} from "@flowgram.ai/editor";
|
|
@@ -3443,7 +3626,7 @@ var createBatchOutputsFormPlugin = defineFormPluginCreator({
|
|
|
3443
3626
|
transformCovers: (covers, ctx2) => {
|
|
3444
3627
|
const node = ctx2.scope.meta?.node;
|
|
3445
3628
|
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
3446
|
-
return [...covers,
|
|
3629
|
+
return [...covers, getNodeScope2(node.parent)];
|
|
3447
3630
|
}
|
|
3448
3631
|
return covers;
|
|
3449
3632
|
},
|
|
@@ -3456,8 +3639,8 @@ var createBatchOutputsFormPlugin = defineFormPluginCreator({
|
|
|
3456
3639
|
if (node?.flowNodeType === batchNodeType) {
|
|
3457
3640
|
const childBlocks = node.blocks;
|
|
3458
3641
|
return [
|
|
3459
|
-
|
|
3460
|
-
...childBlocks.map((_childBlock) =>
|
|
3642
|
+
getNodePrivateScope2(node),
|
|
3643
|
+
...childBlocks.map((_childBlock) => getNodeScope2(_childBlock))
|
|
3461
3644
|
];
|
|
3462
3645
|
}
|
|
3463
3646
|
return scopes;
|
|
@@ -3471,8 +3654,8 @@ import { get as get2, set as set2 } from "lodash";
|
|
|
3471
3654
|
import { JsonSchemaUtils as JsonSchemaUtils8 } from "@flowgram.ai/json-schema";
|
|
3472
3655
|
import {
|
|
3473
3656
|
defineFormPluginCreator as defineFormPluginCreator2,
|
|
3474
|
-
getNodePrivateScope as
|
|
3475
|
-
getNodeScope as
|
|
3657
|
+
getNodePrivateScope as getNodePrivateScope3,
|
|
3658
|
+
getNodeScope as getNodeScope3
|
|
3476
3659
|
} from "@flowgram.ai/editor";
|
|
3477
3660
|
var createInferInputsPlugin = defineFormPluginCreator2({
|
|
3478
3661
|
onSetupFormMeta({ addFormatOnSubmit }, { sourceKey, targetKey, scope }) {
|
|
@@ -3485,7 +3668,7 @@ var createInferInputsPlugin = defineFormPluginCreator2({
|
|
|
3485
3668
|
targetKey,
|
|
3486
3669
|
infer(
|
|
3487
3670
|
get2(formData, sourceKey),
|
|
3488
|
-
scope === "private" ?
|
|
3671
|
+
scope === "private" ? getNodePrivateScope3(ctx.node) : getNodeScope3(ctx.node)
|
|
3489
3672
|
)
|
|
3490
3673
|
);
|
|
3491
3674
|
return formData;
|
|
@@ -3545,7 +3728,110 @@ var infer = (values, scope) => {
|
|
|
3545
3728
|
};
|
|
3546
3729
|
}
|
|
3547
3730
|
};
|
|
3731
|
+
|
|
3732
|
+
// src/form-plugins/infer-assign-plugin/index.ts
|
|
3733
|
+
import { set as set3, uniqBy } from "lodash";
|
|
3734
|
+
import { JsonSchemaUtils as JsonSchemaUtils9 } from "@flowgram.ai/json-schema";
|
|
3735
|
+
import {
|
|
3736
|
+
ASTFactory as ASTFactory4,
|
|
3737
|
+
createEffectFromVariableProvider as createEffectFromVariableProvider4,
|
|
3738
|
+
defineFormPluginCreator as defineFormPluginCreator3,
|
|
3739
|
+
getNodeForm as getNodeForm4,
|
|
3740
|
+
getNodeScope as getNodeScope4
|
|
3741
|
+
} from "@flowgram.ai/editor";
|
|
3742
|
+
var createInferAssignPlugin = defineFormPluginCreator3({
|
|
3743
|
+
onSetupFormMeta({ addFormatOnSubmit, mergeEffect }, { assignKey, outputKey }) {
|
|
3744
|
+
if (!assignKey || !outputKey) {
|
|
3745
|
+
return;
|
|
3746
|
+
}
|
|
3747
|
+
mergeEffect({
|
|
3748
|
+
[assignKey]: createEffectFromVariableProvider4({
|
|
3749
|
+
parse: (value, ctx) => {
|
|
3750
|
+
const declareRows = uniqBy(
|
|
3751
|
+
value.filter((_v) => _v.operator === "declare" && _v.left && _v.right),
|
|
3752
|
+
"left"
|
|
3753
|
+
);
|
|
3754
|
+
return [
|
|
3755
|
+
ASTFactory4.createVariableDeclaration({
|
|
3756
|
+
key: `${ctx.node.id}`,
|
|
3757
|
+
meta: {
|
|
3758
|
+
title: getNodeForm4(ctx.node)?.getValueIn("title"),
|
|
3759
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
3760
|
+
},
|
|
3761
|
+
type: ASTFactory4.createObject({
|
|
3762
|
+
properties: declareRows.map(
|
|
3763
|
+
(_v) => ASTFactory4.createProperty({
|
|
3764
|
+
key: _v.left,
|
|
3765
|
+
type: _v.right?.type === "constant" ? JsonSchemaUtils9.schemaToAST(_v.right?.schema || {}) : void 0,
|
|
3766
|
+
initializer: _v.right?.type === "ref" ? ASTFactory4.createKeyPathExpression({
|
|
3767
|
+
keyPath: _v.right?.content || []
|
|
3768
|
+
}) : {}
|
|
3769
|
+
})
|
|
3770
|
+
)
|
|
3771
|
+
})
|
|
3772
|
+
})
|
|
3773
|
+
];
|
|
3774
|
+
}
|
|
3775
|
+
})
|
|
3776
|
+
});
|
|
3777
|
+
addFormatOnSubmit((formData, ctx) => {
|
|
3778
|
+
set3(
|
|
3779
|
+
formData,
|
|
3780
|
+
outputKey,
|
|
3781
|
+
JsonSchemaUtils9.astToSchema(getNodeScope4(ctx.node).output.variables?.[0]?.type)
|
|
3782
|
+
);
|
|
3783
|
+
return formData;
|
|
3784
|
+
});
|
|
3785
|
+
}
|
|
3786
|
+
});
|
|
3787
|
+
|
|
3788
|
+
// src/validate/validate-flow-value/index.tsx
|
|
3789
|
+
import { isNil, uniq as uniq2 } from "lodash";
|
|
3790
|
+
import { FeedbackLevel, getNodeScope as getNodeScope5 } from "@flowgram.ai/editor";
|
|
3791
|
+
function validateFlowValue(value, ctx) {
|
|
3792
|
+
const { node, required, errorMessages } = ctx;
|
|
3793
|
+
const {
|
|
3794
|
+
required: requiredMessage = "Field is required",
|
|
3795
|
+
unknownVariable: unknownVariableMessage = "Unknown Variable"
|
|
3796
|
+
} = errorMessages || {};
|
|
3797
|
+
if (required && (isNil(value) || isNil(value?.content) || value?.content === "")) {
|
|
3798
|
+
return {
|
|
3799
|
+
level: FeedbackLevel.Error,
|
|
3800
|
+
message: requiredMessage
|
|
3801
|
+
};
|
|
3802
|
+
}
|
|
3803
|
+
if (value?.type === "ref") {
|
|
3804
|
+
const variable = getNodeScope5(node).available.getByKeyPath(value?.content || []);
|
|
3805
|
+
if (!variable) {
|
|
3806
|
+
return {
|
|
3807
|
+
level: FeedbackLevel.Error,
|
|
3808
|
+
message: unknownVariableMessage
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
if (value?.type === "template") {
|
|
3813
|
+
const allRefs = getTemplateKeyPaths2(value);
|
|
3814
|
+
for (const ref of allRefs) {
|
|
3815
|
+
const variable = getNodeScope5(node).available.getByKeyPath(ref);
|
|
3816
|
+
if (!variable) {
|
|
3817
|
+
return {
|
|
3818
|
+
level: FeedbackLevel.Error,
|
|
3819
|
+
message: unknownVariableMessage
|
|
3820
|
+
};
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
return void 0;
|
|
3825
|
+
}
|
|
3826
|
+
function getTemplateKeyPaths2(value) {
|
|
3827
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
3828
|
+
return uniq2(value.content?.match(keyPathReg) || []).map(
|
|
3829
|
+
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
3830
|
+
);
|
|
3831
|
+
}
|
|
3548
3832
|
export {
|
|
3833
|
+
AssignRow,
|
|
3834
|
+
AssignRows,
|
|
3549
3835
|
BatchOutputs,
|
|
3550
3836
|
BatchVariableSelector,
|
|
3551
3837
|
CodeEditor,
|
|
@@ -3570,6 +3856,8 @@ export {
|
|
|
3570
3856
|
VariableSelector,
|
|
3571
3857
|
autoRenameRefEffect,
|
|
3572
3858
|
createBatchOutputsFormPlugin,
|
|
3859
|
+
createDisableDeclarationPlugin,
|
|
3860
|
+
createInferAssignPlugin,
|
|
3573
3861
|
createInferInputsPlugin,
|
|
3574
3862
|
createTypePresetPlugin,
|
|
3575
3863
|
formatLegacyRefOnInit,
|
|
@@ -3585,6 +3873,8 @@ export {
|
|
|
3585
3873
|
provideJsonSchemaOutputs,
|
|
3586
3874
|
syncVariableTitle,
|
|
3587
3875
|
useTypeManager,
|
|
3588
|
-
useVariableTree
|
|
3876
|
+
useVariableTree,
|
|
3877
|
+
validateFlowValue,
|
|
3878
|
+
validateWhenVariableSync
|
|
3589
3879
|
};
|
|
3590
3880
|
//# sourceMappingURL=index.js.map
|