@flowgram.ai/form-materials 0.2.0 → 0.2.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/dist/esm/index.js +544 -107
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +130 -39
- package/dist/index.d.ts +130 -39
- package/dist/index.js +544 -107
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/batch-variable-selector/index.tsx +3 -2
- package/src/components/condition-row/config.json +5 -0
- package/src/components/condition-row/constants.ts +123 -0
- package/src/components/condition-row/hooks/useOp.tsx +45 -0
- package/src/components/condition-row/hooks/useRule.ts +26 -0
- package/src/components/condition-row/index.tsx +71 -0
- package/src/components/condition-row/styles.tsx +25 -0
- package/src/components/condition-row/types.ts +37 -0
- package/src/components/constant-input/config.json +1 -1
- package/src/components/constant-input/types.ts +3 -3
- package/src/components/dynamic-value-input/index.tsx +13 -5
- package/src/components/index.ts +1 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +22 -0
- package/src/components/json-schema-editor/config.json +1 -1
- package/src/components/json-schema-editor/hooks.tsx +2 -2
- package/src/components/json-schema-editor/index.tsx +7 -6
- package/src/components/json-schema-editor/types.ts +3 -3
- package/src/components/type-selector/config.json +1 -1
- package/src/components/type-selector/constants.tsx +2 -2
- package/src/components/type-selector/index.tsx +6 -6
- package/src/components/variable-selector/config.json +1 -1
- package/src/components/variable-selector/index.tsx +4 -4
- package/src/components/variable-selector/use-variable-tree.tsx +11 -5
- package/src/effects/auto-rename-ref/config.json +5 -0
- package/src/effects/auto-rename-ref/index.ts +104 -0
- package/src/effects/index.ts +1 -0
- package/src/typings/index.ts +1 -0
- package/src/typings/json-schema/config.json +5 -0
- package/src/typings/json-schema/index.ts +31 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/json-schema/config.json +5 -0
- package/src/utils/json-schema/index.ts +161 -0
- package/src/components/type-selector/types.ts +0 -5
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
|
|
|
4
4
|
|
|
5
5
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
6
6
|
import React2, { useCallback } from "react";
|
|
7
|
-
import { useScopeAvailable, ASTMatch } from "@flowgram.ai/editor";
|
|
7
|
+
import { useScopeAvailable, ASTMatch as ASTMatch2 } from "@flowgram.ai/editor";
|
|
8
8
|
import { Icon as Icon2 } from "@douyinfe/semi-ui";
|
|
9
9
|
|
|
10
10
|
// src/components/type-selector/constants.tsx
|
|
@@ -396,6 +396,119 @@ var options = [
|
|
|
396
396
|
}
|
|
397
397
|
];
|
|
398
398
|
|
|
399
|
+
// src/utils/json-schema/index.ts
|
|
400
|
+
import { get } from "lodash";
|
|
401
|
+
import { ASTFactory, ASTKind, ASTMatch } from "@flowgram.ai/editor";
|
|
402
|
+
var JsonSchemaUtils;
|
|
403
|
+
((JsonSchemaUtils2) => {
|
|
404
|
+
function schemaToAST(jsonSchema) {
|
|
405
|
+
const { type, extra } = jsonSchema || {};
|
|
406
|
+
const { weak = false } = extra || {};
|
|
407
|
+
if (!type) {
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
410
|
+
switch (type) {
|
|
411
|
+
case "object":
|
|
412
|
+
if (weak) {
|
|
413
|
+
return { kind: ASTKind.Object, weak: true };
|
|
414
|
+
}
|
|
415
|
+
return ASTFactory.createObject({
|
|
416
|
+
properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => (get(a?.[1], "extra.index") || 0) - (get(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
|
|
417
|
+
key,
|
|
418
|
+
type: schemaToAST(_property),
|
|
419
|
+
meta: { description: _property.description }
|
|
420
|
+
}))
|
|
421
|
+
});
|
|
422
|
+
case "array":
|
|
423
|
+
if (weak) {
|
|
424
|
+
return { kind: ASTKind.Array, weak: true };
|
|
425
|
+
}
|
|
426
|
+
return ASTFactory.createArray({
|
|
427
|
+
items: schemaToAST(jsonSchema.items)
|
|
428
|
+
});
|
|
429
|
+
case "map":
|
|
430
|
+
if (weak) {
|
|
431
|
+
return { kind: ASTKind.Map, weak: true };
|
|
432
|
+
}
|
|
433
|
+
return ASTFactory.createMap({
|
|
434
|
+
valueType: schemaToAST(jsonSchema.additionalProperties)
|
|
435
|
+
});
|
|
436
|
+
case "string":
|
|
437
|
+
return ASTFactory.createString();
|
|
438
|
+
case "number":
|
|
439
|
+
return ASTFactory.createNumber();
|
|
440
|
+
case "boolean":
|
|
441
|
+
return ASTFactory.createBoolean();
|
|
442
|
+
case "integer":
|
|
443
|
+
return ASTFactory.createInteger();
|
|
444
|
+
default:
|
|
445
|
+
return ASTFactory.createCustomType({ typeName: type });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
JsonSchemaUtils2.schemaToAST = schemaToAST;
|
|
449
|
+
function astToSchema(typeAST, options2) {
|
|
450
|
+
const { drilldown = true } = options2 || {};
|
|
451
|
+
if (ASTMatch.isString(typeAST)) {
|
|
452
|
+
return {
|
|
453
|
+
type: "string"
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (ASTMatch.isBoolean(typeAST)) {
|
|
457
|
+
return {
|
|
458
|
+
type: "boolean"
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
if (ASTMatch.isNumber(typeAST)) {
|
|
462
|
+
return {
|
|
463
|
+
type: "number"
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (ASTMatch.isInteger(typeAST)) {
|
|
467
|
+
return {
|
|
468
|
+
type: "integer"
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (ASTMatch.isObject(typeAST)) {
|
|
472
|
+
return {
|
|
473
|
+
type: "object",
|
|
474
|
+
properties: drilldown ? Object.fromEntries(
|
|
475
|
+
Object.entries(typeAST.properties).map(([key, value]) => [key, astToSchema(value)])
|
|
476
|
+
) : {}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (ASTMatch.isArray(typeAST)) {
|
|
480
|
+
return {
|
|
481
|
+
type: "array",
|
|
482
|
+
items: drilldown ? astToSchema(typeAST.items) : void 0
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
if (ASTMatch.isMap(typeAST)) {
|
|
486
|
+
return {
|
|
487
|
+
type: "map",
|
|
488
|
+
items: drilldown ? astToSchema(typeAST.valueType) : void 0
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
if (ASTMatch.isCustomType(typeAST)) {
|
|
492
|
+
return {
|
|
493
|
+
type: typeAST.typeName
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
JsonSchemaUtils2.astToSchema = astToSchema;
|
|
499
|
+
function isASTMatchSchema(typeAST, schema) {
|
|
500
|
+
if (Array.isArray(schema)) {
|
|
501
|
+
return typeAST.isTypeEqual(
|
|
502
|
+
ASTFactory.createUnion({
|
|
503
|
+
types: schema.map((_schema) => schemaToAST(_schema)).filter(Boolean)
|
|
504
|
+
})
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
return typeAST.isTypeEqual(schemaToAST(schema));
|
|
508
|
+
}
|
|
509
|
+
JsonSchemaUtils2.isASTMatchSchema = isASTMatchSchema;
|
|
510
|
+
})(JsonSchemaUtils || (JsonSchemaUtils = {}));
|
|
511
|
+
|
|
399
512
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
400
513
|
function useVariableTree(params) {
|
|
401
514
|
const { includeSchema, excludeSchema } = params;
|
|
@@ -408,7 +521,7 @@ function useVariableTree(params) {
|
|
|
408
521
|
return variable.meta.icon;
|
|
409
522
|
}
|
|
410
523
|
const _type = variable.type;
|
|
411
|
-
if (
|
|
524
|
+
if (ASTMatch2.isArray(_type)) {
|
|
412
525
|
return /* @__PURE__ */ React2.createElement(
|
|
413
526
|
Icon2,
|
|
414
527
|
{
|
|
@@ -417,7 +530,7 @@ function useVariableTree(params) {
|
|
|
417
530
|
}
|
|
418
531
|
);
|
|
419
532
|
}
|
|
420
|
-
if (
|
|
533
|
+
if (ASTMatch2.isCustomType(_type)) {
|
|
421
534
|
return /* @__PURE__ */ React2.createElement(Icon2, { size: "small", svg: VariableTypeIcons[_type.typeName.toLowerCase()] });
|
|
422
535
|
}
|
|
423
536
|
return /* @__PURE__ */ React2.createElement(Icon2, { size: "small", svg: VariableTypeIcons[variable.type?.kind.toLowerCase()] });
|
|
@@ -428,7 +541,7 @@ function useVariableTree(params) {
|
|
|
428
541
|
return null;
|
|
429
542
|
}
|
|
430
543
|
let children;
|
|
431
|
-
if (
|
|
544
|
+
if (ASTMatch2.isObject(type)) {
|
|
432
545
|
children = (type.properties || []).map((_property) => renderVariable(_property, [...parentFields, variable])).filter(Boolean);
|
|
433
546
|
if (!children?.length) {
|
|
434
547
|
return null;
|
|
@@ -436,8 +549,8 @@ function useVariableTree(params) {
|
|
|
436
549
|
}
|
|
437
550
|
const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
|
|
438
551
|
const key = keyPath.join(".");
|
|
439
|
-
const isSchemaInclude = includeSchema ?
|
|
440
|
-
const isSchemaExclude = excludeSchema ?
|
|
552
|
+
const isSchemaInclude = includeSchema ? JsonSchemaUtils.isASTMatchSchema(type, includeSchema) : true;
|
|
553
|
+
const isSchemaExclude = excludeSchema ? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema) : false;
|
|
441
554
|
const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
|
|
442
555
|
if (!isSchemaMatch && !children?.length) {
|
|
443
556
|
return null;
|
|
@@ -567,7 +680,7 @@ var VariableSelector = ({
|
|
|
567
680
|
);
|
|
568
681
|
},
|
|
569
682
|
showClear: false,
|
|
570
|
-
arrowIcon:
|
|
683
|
+
arrowIcon: /* @__PURE__ */ React3.createElement(IconChevronDownStroked, { size: "small" }),
|
|
571
684
|
triggerRender,
|
|
572
685
|
placeholder: config?.placeholder ?? "Select Variable..."
|
|
573
686
|
}
|
|
@@ -610,8 +723,8 @@ function TypeSelector(props) {
|
|
|
610
723
|
}
|
|
611
724
|
|
|
612
725
|
// src/components/json-schema-editor/index.tsx
|
|
613
|
-
import
|
|
614
|
-
import { Button as Button2, Checkbox, IconButton
|
|
726
|
+
import React7, { useMemo as useMemo4, useState as useState3 } from "react";
|
|
727
|
+
import { Button as Button2, Checkbox, IconButton } from "@douyinfe/semi-ui";
|
|
615
728
|
import {
|
|
616
729
|
IconExpand,
|
|
617
730
|
IconShrink,
|
|
@@ -863,6 +976,27 @@ function usePropertiesEdit(value, onChange) {
|
|
|
863
976
|
};
|
|
864
977
|
}
|
|
865
978
|
|
|
979
|
+
// src/components/json-schema-editor/components/blur-input.tsx
|
|
980
|
+
import React6, { useEffect as useEffect2, useState as useState2 } from "react";
|
|
981
|
+
import Input from "@douyinfe/semi-ui/lib/es/input";
|
|
982
|
+
function BlurInput(props) {
|
|
983
|
+
const [value, setValue] = useState2("");
|
|
984
|
+
useEffect2(() => {
|
|
985
|
+
setValue(props.value);
|
|
986
|
+
}, [props.value]);
|
|
987
|
+
return /* @__PURE__ */ React6.createElement(
|
|
988
|
+
Input,
|
|
989
|
+
{
|
|
990
|
+
...props,
|
|
991
|
+
value,
|
|
992
|
+
onChange: (value2) => {
|
|
993
|
+
setValue(value2);
|
|
994
|
+
},
|
|
995
|
+
onBlur: (e) => props.onChange?.(value, e)
|
|
996
|
+
}
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
|
|
866
1000
|
// src/components/json-schema-editor/index.tsx
|
|
867
1001
|
function JsonSchemaEditor(props) {
|
|
868
1002
|
const { value = { type: "object" }, config = {}, onChange: onChangeProps } = props;
|
|
@@ -870,7 +1004,7 @@ function JsonSchemaEditor(props) {
|
|
|
870
1004
|
value,
|
|
871
1005
|
onChangeProps
|
|
872
1006
|
);
|
|
873
|
-
return /* @__PURE__ */
|
|
1007
|
+
return /* @__PURE__ */ React7.createElement(UIContainer, null, /* @__PURE__ */ React7.createElement(UIProperties, null, propertyList.map((_property) => /* @__PURE__ */ React7.createElement(
|
|
874
1008
|
PropertyEdit,
|
|
875
1009
|
{
|
|
876
1010
|
key: _property.key,
|
|
@@ -883,12 +1017,12 @@ function JsonSchemaEditor(props) {
|
|
|
883
1017
|
onRemoveProperty(_property.key);
|
|
884
1018
|
}
|
|
885
1019
|
}
|
|
886
|
-
))), /* @__PURE__ */
|
|
1020
|
+
))), /* @__PURE__ */ React7.createElement(Button2, { size: "small", style: { marginTop: 10 }, icon: /* @__PURE__ */ React7.createElement(IconPlus, null), onClick: onAddProperty }, config?.addButtonText ?? "Add"));
|
|
887
1021
|
}
|
|
888
1022
|
function PropertyEdit(props) {
|
|
889
1023
|
const { value, config, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
|
|
890
|
-
const [expand, setExpand] =
|
|
891
|
-
const [collapse, setCollapse] =
|
|
1024
|
+
const [expand, setExpand] = useState3(false);
|
|
1025
|
+
const [collapse, setCollapse] = useState3(false);
|
|
892
1026
|
const { name, type, items, description, isPropertyRequired } = value || {};
|
|
893
1027
|
const typeSelectorValue = useMemo4(() => ({ type, items }), [type, items]);
|
|
894
1028
|
const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(value, onChangeProps);
|
|
@@ -899,15 +1033,15 @@ function PropertyEdit(props) {
|
|
|
899
1033
|
});
|
|
900
1034
|
};
|
|
901
1035
|
const showCollapse = isDrilldownObject && propertyList.length > 0;
|
|
902
|
-
return /* @__PURE__ */
|
|
903
|
-
|
|
1036
|
+
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(UIPropertyLeft, { $isLast, $showLine }, showCollapse && /* @__PURE__ */ React7.createElement(UICollapseTrigger, { onClick: () => setCollapse((_collapse) => !_collapse) }, collapse ? /* @__PURE__ */ React7.createElement(IconChevronDown, { size: "small" }) : /* @__PURE__ */ React7.createElement(IconChevronRight, { size: "small" }))), /* @__PURE__ */ React7.createElement(UIPropertyRight, null, /* @__PURE__ */ React7.createElement(UIPropertyMain, { $expand: expand }, /* @__PURE__ */ React7.createElement(UIRow, null, /* @__PURE__ */ React7.createElement(UIName, null, /* @__PURE__ */ React7.createElement(
|
|
1037
|
+
BlurInput,
|
|
904
1038
|
{
|
|
905
1039
|
placeholder: config?.placeholder ?? "Input Variable Name",
|
|
906
1040
|
size: "small",
|
|
907
1041
|
value: name,
|
|
908
1042
|
onChange: (value2) => onChange("name", value2)
|
|
909
1043
|
}
|
|
910
|
-
)), /* @__PURE__ */
|
|
1044
|
+
)), /* @__PURE__ */ React7.createElement(UIType, null, /* @__PURE__ */ React7.createElement(
|
|
911
1045
|
TypeSelector,
|
|
912
1046
|
{
|
|
913
1047
|
value: typeSelectorValue,
|
|
@@ -918,48 +1052,48 @@ function PropertyEdit(props) {
|
|
|
918
1052
|
});
|
|
919
1053
|
}
|
|
920
1054
|
}
|
|
921
|
-
)), /* @__PURE__ */
|
|
1055
|
+
)), /* @__PURE__ */ React7.createElement(UIRequired, null, /* @__PURE__ */ React7.createElement(
|
|
922
1056
|
Checkbox,
|
|
923
1057
|
{
|
|
924
1058
|
checked: isPropertyRequired,
|
|
925
1059
|
onChange: (e) => onChange("isPropertyRequired", e.target.checked)
|
|
926
1060
|
}
|
|
927
|
-
)), /* @__PURE__ */
|
|
1061
|
+
)), /* @__PURE__ */ React7.createElement(UIActions, null, /* @__PURE__ */ React7.createElement(
|
|
928
1062
|
IconButton,
|
|
929
1063
|
{
|
|
930
1064
|
size: "small",
|
|
931
1065
|
theme: "borderless",
|
|
932
|
-
icon: expand ? /* @__PURE__ */
|
|
1066
|
+
icon: expand ? /* @__PURE__ */ React7.createElement(IconShrink, { size: "small" }) : /* @__PURE__ */ React7.createElement(IconExpand, { size: "small" }),
|
|
933
1067
|
onClick: () => setExpand((_expand) => !_expand)
|
|
934
1068
|
}
|
|
935
|
-
), isDrilldownObject && /* @__PURE__ */
|
|
1069
|
+
), isDrilldownObject && /* @__PURE__ */ React7.createElement(
|
|
936
1070
|
IconButton,
|
|
937
1071
|
{
|
|
938
1072
|
size: "small",
|
|
939
1073
|
theme: "borderless",
|
|
940
|
-
icon: /* @__PURE__ */
|
|
1074
|
+
icon: /* @__PURE__ */ React7.createElement(IconAddChildren, null),
|
|
941
1075
|
onClick: () => {
|
|
942
1076
|
onAddProperty();
|
|
943
1077
|
setCollapse(true);
|
|
944
1078
|
}
|
|
945
1079
|
}
|
|
946
|
-
), /* @__PURE__ */
|
|
1080
|
+
), /* @__PURE__ */ React7.createElement(
|
|
947
1081
|
IconButton,
|
|
948
1082
|
{
|
|
949
1083
|
size: "small",
|
|
950
1084
|
theme: "borderless",
|
|
951
|
-
icon: /* @__PURE__ */
|
|
1085
|
+
icon: /* @__PURE__ */ React7.createElement(IconMinus, { size: "small" }),
|
|
952
1086
|
onClick: onRemove
|
|
953
1087
|
}
|
|
954
|
-
))), expand && /* @__PURE__ */
|
|
955
|
-
|
|
1088
|
+
))), expand && /* @__PURE__ */ React7.createElement(UIExpandDetail, null, /* @__PURE__ */ React7.createElement(UILabel, null, config?.descTitle ?? "Description"), /* @__PURE__ */ React7.createElement(
|
|
1089
|
+
BlurInput,
|
|
956
1090
|
{
|
|
957
1091
|
size: "small",
|
|
958
1092
|
value: description,
|
|
959
1093
|
onChange: (value2) => onChange("description", value2),
|
|
960
1094
|
placeholder: config?.descPlaceholder ?? "Help LLM to understand the property"
|
|
961
1095
|
}
|
|
962
|
-
))), showCollapse && /* @__PURE__ */
|
|
1096
|
+
))), showCollapse && /* @__PURE__ */ React7.createElement(UICollapsible, { $collapse: collapse }, /* @__PURE__ */ React7.createElement(UIProperties, { $shrink: true }, propertyList.map((_property, index) => /* @__PURE__ */ React7.createElement(
|
|
963
1097
|
PropertyEdit,
|
|
964
1098
|
{
|
|
965
1099
|
key: _property.key,
|
|
@@ -978,27 +1112,27 @@ function PropertyEdit(props) {
|
|
|
978
1112
|
}
|
|
979
1113
|
|
|
980
1114
|
// src/components/batch-variable-selector/index.tsx
|
|
981
|
-
import
|
|
1115
|
+
import React8 from "react";
|
|
982
1116
|
import { PrivateScopeProvider } from "@flowgram.ai/editor";
|
|
983
1117
|
var batchVariableSchema = {
|
|
984
1118
|
type: "array",
|
|
985
1119
|
extra: { weak: true }
|
|
986
1120
|
};
|
|
987
1121
|
function BatchVariableSelector(props) {
|
|
988
|
-
return /* @__PURE__ */
|
|
1122
|
+
return /* @__PURE__ */ React8.createElement(PrivateScopeProvider, null, /* @__PURE__ */ React8.createElement(VariableSelector, { ...props, includeSchema: batchVariableSchema }));
|
|
989
1123
|
}
|
|
990
1124
|
|
|
991
1125
|
// src/components/constant-input/index.tsx
|
|
992
|
-
import
|
|
1126
|
+
import React9, { useMemo as useMemo5 } from "react";
|
|
993
1127
|
import { Input as Input2, InputNumber, Select } from "@douyinfe/semi-ui";
|
|
994
1128
|
var defaultStrategies = [
|
|
995
1129
|
{
|
|
996
1130
|
hit: (schema) => schema?.type === "string",
|
|
997
|
-
Renderer: (props) => /* @__PURE__ */
|
|
1131
|
+
Renderer: (props) => /* @__PURE__ */ React9.createElement(Input2, { placeholder: "Please Input String", size: "small", disabled: props.readonly, ...props })
|
|
998
1132
|
},
|
|
999
1133
|
{
|
|
1000
1134
|
hit: (schema) => schema?.type === "number",
|
|
1001
|
-
Renderer: (props) => /* @__PURE__ */
|
|
1135
|
+
Renderer: (props) => /* @__PURE__ */ React9.createElement(
|
|
1002
1136
|
InputNumber,
|
|
1003
1137
|
{
|
|
1004
1138
|
placeholder: "Please Input Number",
|
|
@@ -1011,7 +1145,7 @@ var defaultStrategies = [
|
|
|
1011
1145
|
},
|
|
1012
1146
|
{
|
|
1013
1147
|
hit: (schema) => schema?.type === "integer",
|
|
1014
|
-
Renderer: (props) => /* @__PURE__ */
|
|
1148
|
+
Renderer: (props) => /* @__PURE__ */ React9.createElement(
|
|
1015
1149
|
InputNumber,
|
|
1016
1150
|
{
|
|
1017
1151
|
placeholder: "Please Input Integer",
|
|
@@ -1027,7 +1161,7 @@ var defaultStrategies = [
|
|
|
1027
1161
|
hit: (schema) => schema?.type === "boolean",
|
|
1028
1162
|
Renderer: (props) => {
|
|
1029
1163
|
const { value, onChange, ...rest } = props;
|
|
1030
|
-
return /* @__PURE__ */
|
|
1164
|
+
return /* @__PURE__ */ React9.createElement(
|
|
1031
1165
|
Select,
|
|
1032
1166
|
{
|
|
1033
1167
|
placeholder: "Please Select Boolean",
|
|
@@ -1056,13 +1190,13 @@ function ConstantInput(props) {
|
|
|
1056
1190
|
return strategy?.Renderer;
|
|
1057
1191
|
}, [strategies, schema]);
|
|
1058
1192
|
if (!Renderer) {
|
|
1059
|
-
return /* @__PURE__ */
|
|
1193
|
+
return /* @__PURE__ */ React9.createElement(Input2, { size: "small", disabled: true, placeholder: "Unsupported type" });
|
|
1060
1194
|
}
|
|
1061
|
-
return /* @__PURE__ */
|
|
1195
|
+
return /* @__PURE__ */ React9.createElement(Renderer, { value, onChange, readonly, ...rest });
|
|
1062
1196
|
}
|
|
1063
1197
|
|
|
1064
1198
|
// src/components/dynamic-value-input/index.tsx
|
|
1065
|
-
import
|
|
1199
|
+
import React10, { useMemo as useMemo6 } from "react";
|
|
1066
1200
|
import { IconButton as IconButton2 } from "@douyinfe/semi-ui";
|
|
1067
1201
|
import { IconSetting } from "@douyinfe/semi-icons";
|
|
1068
1202
|
|
|
@@ -1093,19 +1227,25 @@ function DynamicValueInput({
|
|
|
1093
1227
|
schema,
|
|
1094
1228
|
constantProps
|
|
1095
1229
|
}) {
|
|
1230
|
+
const includeSchema = useMemo6(() => {
|
|
1231
|
+
if (schema?.type === "number") {
|
|
1232
|
+
return [schema, { type: "integer" }];
|
|
1233
|
+
}
|
|
1234
|
+
return schema;
|
|
1235
|
+
}, [schema]);
|
|
1096
1236
|
const renderMain = () => {
|
|
1097
1237
|
if (value?.type === "ref") {
|
|
1098
|
-
return /* @__PURE__ */
|
|
1238
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1099
1239
|
VariableSelector,
|
|
1100
1240
|
{
|
|
1101
1241
|
value: value?.content,
|
|
1102
1242
|
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
|
|
1103
|
-
includeSchema
|
|
1243
|
+
includeSchema,
|
|
1104
1244
|
readonly
|
|
1105
1245
|
}
|
|
1106
1246
|
);
|
|
1107
1247
|
}
|
|
1108
|
-
return /* @__PURE__ */
|
|
1248
|
+
return /* @__PURE__ */ React10.createElement(
|
|
1109
1249
|
ConstantInput,
|
|
1110
1250
|
{
|
|
1111
1251
|
value: value?.content,
|
|
@@ -1116,85 +1256,171 @@ function DynamicValueInput({
|
|
|
1116
1256
|
}
|
|
1117
1257
|
);
|
|
1118
1258
|
};
|
|
1119
|
-
const renderTrigger = () => /* @__PURE__ */
|
|
1259
|
+
const renderTrigger = () => /* @__PURE__ */ React10.createElement(
|
|
1120
1260
|
VariableSelector,
|
|
1121
1261
|
{
|
|
1122
1262
|
style: { width: "100%" },
|
|
1123
1263
|
value: value?.type === "ref" ? value?.content : void 0,
|
|
1124
1264
|
onChange: (_v) => onChange({ type: "ref", content: _v }),
|
|
1125
|
-
includeSchema
|
|
1265
|
+
includeSchema,
|
|
1126
1266
|
readonly,
|
|
1127
|
-
triggerRender: () => /* @__PURE__ */
|
|
1267
|
+
triggerRender: () => /* @__PURE__ */ React10.createElement(IconButton2, { disabled: readonly, size: "small", icon: /* @__PURE__ */ React10.createElement(IconSetting, { size: "small" }) })
|
|
1128
1268
|
}
|
|
1129
1269
|
);
|
|
1130
|
-
return /* @__PURE__ */
|
|
1270
|
+
return /* @__PURE__ */ React10.createElement(UIContainer2, { style }, /* @__PURE__ */ React10.createElement(UIMain, null, renderMain()), /* @__PURE__ */ React10.createElement(UITrigger, null, renderTrigger()));
|
|
1131
1271
|
}
|
|
1132
1272
|
|
|
1133
|
-
// src/
|
|
1134
|
-
import {
|
|
1135
|
-
|
|
1136
|
-
createEffectFromVariableProvider,
|
|
1137
|
-
getNodeForm
|
|
1138
|
-
} from "@flowgram.ai/editor";
|
|
1139
|
-
var provideBatchInputEffect = createEffectFromVariableProvider({
|
|
1140
|
-
private: true,
|
|
1141
|
-
parse: (value, ctx) => [
|
|
1142
|
-
ASTFactory.createVariableDeclaration({
|
|
1143
|
-
key: `${ctx.node.id}_locals`,
|
|
1144
|
-
meta: {
|
|
1145
|
-
title: getNodeForm(ctx.node)?.getValueIn("title"),
|
|
1146
|
-
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1147
|
-
},
|
|
1148
|
-
type: ASTFactory.createObject({
|
|
1149
|
-
properties: [
|
|
1150
|
-
ASTFactory.createProperty({
|
|
1151
|
-
key: "item",
|
|
1152
|
-
initializer: ASTFactory.createEnumerateExpression({
|
|
1153
|
-
enumerateFor: ASTFactory.createKeyPathExpression({
|
|
1154
|
-
keyPath: value.content || []
|
|
1155
|
-
})
|
|
1156
|
-
})
|
|
1157
|
-
}),
|
|
1158
|
-
ASTFactory.createProperty({
|
|
1159
|
-
key: "index",
|
|
1160
|
-
type: ASTFactory.createNumber()
|
|
1161
|
-
})
|
|
1162
|
-
]
|
|
1163
|
-
})
|
|
1164
|
-
})
|
|
1165
|
-
]
|
|
1166
|
-
});
|
|
1273
|
+
// src/components/condition-row/index.tsx
|
|
1274
|
+
import React12, { useMemo as useMemo9 } from "react";
|
|
1275
|
+
import { Input as Input3 } from "@douyinfe/semi-ui";
|
|
1167
1276
|
|
|
1168
|
-
// src/
|
|
1169
|
-
import
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1277
|
+
// src/components/condition-row/styles.tsx
|
|
1278
|
+
import styled4 from "styled-components";
|
|
1279
|
+
var UIContainer3 = styled4.div`
|
|
1280
|
+
display: flex;
|
|
1281
|
+
align-items: center;
|
|
1282
|
+
gap: 4px;
|
|
1283
|
+
`;
|
|
1284
|
+
var UIOperator = styled4.div``;
|
|
1285
|
+
var UILeft = styled4.div`
|
|
1286
|
+
width: 100%;
|
|
1287
|
+
`;
|
|
1288
|
+
var UIRight = styled4.div`
|
|
1289
|
+
width: 100%;
|
|
1290
|
+
`;
|
|
1291
|
+
var UIValues = styled4.div`
|
|
1292
|
+
flex-grow: 1;
|
|
1293
|
+
display: flex;
|
|
1294
|
+
flex-direction: column;
|
|
1295
|
+
align-items: center;
|
|
1296
|
+
gap: 4px;
|
|
1297
|
+
`;
|
|
1298
|
+
|
|
1299
|
+
// src/components/condition-row/hooks/useRule.ts
|
|
1300
|
+
import { useMemo as useMemo7 } from "react";
|
|
1301
|
+
import { useScopeAvailable as useScopeAvailable2 } from "@flowgram.ai/editor";
|
|
1302
|
+
|
|
1303
|
+
// src/components/condition-row/constants.ts
|
|
1304
|
+
var rules = {
|
|
1305
|
+
string: {
|
|
1306
|
+
["eq" /* EQ */]: "string",
|
|
1307
|
+
["neq" /* NEQ */]: "string",
|
|
1308
|
+
["contains" /* CONTAINS */]: "string",
|
|
1309
|
+
["not_contains" /* NOT_CONTAINS */]: "string",
|
|
1310
|
+
["in" /* IN */]: "array",
|
|
1311
|
+
["nin" /* NIN */]: "array",
|
|
1312
|
+
["is_empty" /* IS_EMPTY */]: "string",
|
|
1313
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: "string"
|
|
1314
|
+
},
|
|
1315
|
+
number: {
|
|
1316
|
+
["eq" /* EQ */]: "number",
|
|
1317
|
+
["neq" /* NEQ */]: "number",
|
|
1318
|
+
["gt" /* GT */]: "number",
|
|
1319
|
+
["gte" /* GTE */]: "number",
|
|
1320
|
+
["lt" /* LT */]: "number",
|
|
1321
|
+
["lte" /* LTE */]: "number",
|
|
1322
|
+
["in" /* IN */]: "array",
|
|
1323
|
+
["nin" /* NIN */]: "array",
|
|
1324
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1325
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1326
|
+
},
|
|
1327
|
+
integer: {
|
|
1328
|
+
["eq" /* EQ */]: "number",
|
|
1329
|
+
["neq" /* NEQ */]: "number",
|
|
1330
|
+
["gt" /* GT */]: "number",
|
|
1331
|
+
["gte" /* GTE */]: "number",
|
|
1332
|
+
["lt" /* LT */]: "number",
|
|
1333
|
+
["lte" /* LTE */]: "number",
|
|
1334
|
+
["in" /* IN */]: "array",
|
|
1335
|
+
["nin" /* NIN */]: "array",
|
|
1336
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1337
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1338
|
+
},
|
|
1339
|
+
boolean: {
|
|
1340
|
+
["eq" /* EQ */]: "boolean",
|
|
1341
|
+
["neq" /* NEQ */]: "boolean",
|
|
1342
|
+
["is_true" /* IS_TRUE */]: null,
|
|
1343
|
+
["is_false" /* IS_FALSE */]: null,
|
|
1344
|
+
["in" /* IN */]: "array",
|
|
1345
|
+
["nin" /* NIN */]: "array",
|
|
1346
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1347
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1348
|
+
},
|
|
1349
|
+
object: {
|
|
1350
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1351
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1352
|
+
},
|
|
1353
|
+
array: {
|
|
1354
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1355
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1356
|
+
},
|
|
1357
|
+
map: {
|
|
1358
|
+
["is_empty" /* IS_EMPTY */]: null,
|
|
1359
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
var opConfigs = {
|
|
1363
|
+
["eq" /* EQ */]: {
|
|
1364
|
+
label: "Equal",
|
|
1365
|
+
abbreviation: "="
|
|
1366
|
+
},
|
|
1367
|
+
["neq" /* NEQ */]: {
|
|
1368
|
+
label: "Not Equal",
|
|
1369
|
+
abbreviation: "\u2260"
|
|
1370
|
+
},
|
|
1371
|
+
["gt" /* GT */]: {
|
|
1372
|
+
label: "Greater Than",
|
|
1373
|
+
abbreviation: ">"
|
|
1374
|
+
},
|
|
1375
|
+
["gte" /* GTE */]: {
|
|
1376
|
+
label: "Greater Than or Equal",
|
|
1377
|
+
abbreviation: ">="
|
|
1378
|
+
},
|
|
1379
|
+
["lt" /* LT */]: {
|
|
1380
|
+
label: "Less Than",
|
|
1381
|
+
abbreviation: "<"
|
|
1382
|
+
},
|
|
1383
|
+
["lte" /* LTE */]: {
|
|
1384
|
+
label: "Less Than or Equal",
|
|
1385
|
+
abbreviation: "<="
|
|
1386
|
+
},
|
|
1387
|
+
["in" /* IN */]: {
|
|
1388
|
+
label: "In",
|
|
1389
|
+
abbreviation: "\u2208"
|
|
1390
|
+
},
|
|
1391
|
+
["nin" /* NIN */]: {
|
|
1392
|
+
label: "Not In",
|
|
1393
|
+
abbreviation: "\u2209"
|
|
1394
|
+
},
|
|
1395
|
+
["contains" /* CONTAINS */]: {
|
|
1396
|
+
label: "Contains",
|
|
1397
|
+
abbreviation: "\u2287"
|
|
1398
|
+
},
|
|
1399
|
+
["not_contains" /* NOT_CONTAINS */]: {
|
|
1400
|
+
label: "Not Contains",
|
|
1401
|
+
abbreviation: "\u2289"
|
|
1402
|
+
},
|
|
1403
|
+
["is_empty" /* IS_EMPTY */]: {
|
|
1404
|
+
label: "Is Empty",
|
|
1405
|
+
abbreviation: "=",
|
|
1406
|
+
rightDisplay: "Empty"
|
|
1407
|
+
},
|
|
1408
|
+
["is_not_empty" /* IS_NOT_EMPTY */]: {
|
|
1409
|
+
label: "Is Not Empty",
|
|
1410
|
+
abbreviation: "\u2260",
|
|
1411
|
+
rightDisplay: "Empty"
|
|
1412
|
+
},
|
|
1413
|
+
["is_true" /* IS_TRUE */]: {
|
|
1414
|
+
label: "Is True",
|
|
1415
|
+
abbreviation: "=",
|
|
1416
|
+
rightDisplay: "True"
|
|
1417
|
+
},
|
|
1418
|
+
["is_false" /* IS_FALSE */]: {
|
|
1419
|
+
label: "Is False",
|
|
1420
|
+
abbreviation: "=",
|
|
1421
|
+
rightDisplay: "False"
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1198
1424
|
|
|
1199
1425
|
// src/utils/format-legacy-refs/index.ts
|
|
1200
1426
|
import { isObject } from "lodash";
|
|
@@ -1257,15 +1483,226 @@ function formatNewRefToLegacyRef(value) {
|
|
|
1257
1483
|
content: value.content.join(".")
|
|
1258
1484
|
};
|
|
1259
1485
|
}
|
|
1486
|
+
|
|
1487
|
+
// src/components/condition-row/hooks/useRule.ts
|
|
1488
|
+
function useRule(left) {
|
|
1489
|
+
const available = useScopeAvailable2();
|
|
1490
|
+
const variable = useMemo7(() => {
|
|
1491
|
+
if (!left) return void 0;
|
|
1492
|
+
return available.getByKeyPath(left.content);
|
|
1493
|
+
}, [available, left]);
|
|
1494
|
+
const rule = useMemo7(() => {
|
|
1495
|
+
if (!variable) return void 0;
|
|
1496
|
+
const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
|
|
1497
|
+
return rules[schema?.type];
|
|
1498
|
+
}, [variable?.type]);
|
|
1499
|
+
return { rule };
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
// src/components/condition-row/hooks/useOp.tsx
|
|
1503
|
+
import React11, { useMemo as useMemo8 } from "react";
|
|
1504
|
+
import { Button as Button3, Select as Select2 } from "@douyinfe/semi-ui";
|
|
1505
|
+
import { IconChevronDownStroked as IconChevronDownStroked2 } from "@douyinfe/semi-icons";
|
|
1506
|
+
function useOp({ rule, op, onChange }) {
|
|
1507
|
+
const options2 = useMemo8(
|
|
1508
|
+
() => Object.keys(rule || {}).map((_op) => ({
|
|
1509
|
+
...opConfigs[_op] || {},
|
|
1510
|
+
value: _op
|
|
1511
|
+
})),
|
|
1512
|
+
[rule]
|
|
1513
|
+
);
|
|
1514
|
+
const opConfig = useMemo8(() => opConfigs[op], [op]);
|
|
1515
|
+
const renderOpSelect = () => /* @__PURE__ */ React11.createElement(
|
|
1516
|
+
Select2,
|
|
1517
|
+
{
|
|
1518
|
+
style: { height: 22 },
|
|
1519
|
+
size: "small",
|
|
1520
|
+
value: op,
|
|
1521
|
+
optionList: options2,
|
|
1522
|
+
onChange: (v) => {
|
|
1523
|
+
onChange(v);
|
|
1524
|
+
},
|
|
1525
|
+
triggerRender: ({ value }) => /* @__PURE__ */ React11.createElement(Button3, { size: "small", disabled: !rule }, opConfig?.abbreviation || /* @__PURE__ */ React11.createElement(IconChevronDownStroked2, { size: "small" }))
|
|
1526
|
+
}
|
|
1527
|
+
);
|
|
1528
|
+
return { renderOpSelect, opConfig };
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// src/components/condition-row/index.tsx
|
|
1532
|
+
function ConditionRow({ style, value, onChange, readonly }) {
|
|
1533
|
+
const { left, operator, right } = value || {};
|
|
1534
|
+
const { rule } = useRule(left);
|
|
1535
|
+
const { renderOpSelect, opConfig } = useOp({
|
|
1536
|
+
rule,
|
|
1537
|
+
op: operator,
|
|
1538
|
+
onChange: (v) => onChange({ ...value, operator: v })
|
|
1539
|
+
});
|
|
1540
|
+
const targetSchema = useMemo9(() => {
|
|
1541
|
+
const targetType = rule?.[operator] || null;
|
|
1542
|
+
return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
1543
|
+
}, [rule, opConfig]);
|
|
1544
|
+
return /* @__PURE__ */ React12.createElement(UIContainer3, { style }, /* @__PURE__ */ React12.createElement(UIOperator, null, renderOpSelect()), /* @__PURE__ */ React12.createElement(UIValues, null, /* @__PURE__ */ React12.createElement(UILeft, null, /* @__PURE__ */ React12.createElement(
|
|
1545
|
+
VariableSelector,
|
|
1546
|
+
{
|
|
1547
|
+
readonly,
|
|
1548
|
+
style: { width: "100%" },
|
|
1549
|
+
value: left?.content,
|
|
1550
|
+
onChange: (v) => onChange({
|
|
1551
|
+
...value,
|
|
1552
|
+
left: {
|
|
1553
|
+
type: "ref",
|
|
1554
|
+
content: v
|
|
1555
|
+
}
|
|
1556
|
+
})
|
|
1557
|
+
}
|
|
1558
|
+
)), /* @__PURE__ */ React12.createElement(UIRight, null, targetSchema ? /* @__PURE__ */ React12.createElement(
|
|
1559
|
+
DynamicValueInput,
|
|
1560
|
+
{
|
|
1561
|
+
readonly: readonly || !rule,
|
|
1562
|
+
value: right,
|
|
1563
|
+
schema: targetSchema,
|
|
1564
|
+
onChange: (v) => onChange({ ...value, right: v })
|
|
1565
|
+
}
|
|
1566
|
+
) : /* @__PURE__ */ React12.createElement(Input3, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
// src/effects/provide-batch-input/index.ts
|
|
1570
|
+
import {
|
|
1571
|
+
ASTFactory as ASTFactory2,
|
|
1572
|
+
createEffectFromVariableProvider,
|
|
1573
|
+
getNodeForm
|
|
1574
|
+
} from "@flowgram.ai/editor";
|
|
1575
|
+
var provideBatchInputEffect = createEffectFromVariableProvider({
|
|
1576
|
+
private: true,
|
|
1577
|
+
parse: (value, ctx) => [
|
|
1578
|
+
ASTFactory2.createVariableDeclaration({
|
|
1579
|
+
key: `${ctx.node.id}_locals`,
|
|
1580
|
+
meta: {
|
|
1581
|
+
title: getNodeForm(ctx.node)?.getValueIn("title"),
|
|
1582
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1583
|
+
},
|
|
1584
|
+
type: ASTFactory2.createObject({
|
|
1585
|
+
properties: [
|
|
1586
|
+
ASTFactory2.createProperty({
|
|
1587
|
+
key: "item",
|
|
1588
|
+
initializer: ASTFactory2.createEnumerateExpression({
|
|
1589
|
+
enumerateFor: ASTFactory2.createKeyPathExpression({
|
|
1590
|
+
keyPath: value.content || []
|
|
1591
|
+
})
|
|
1592
|
+
})
|
|
1593
|
+
}),
|
|
1594
|
+
ASTFactory2.createProperty({
|
|
1595
|
+
key: "index",
|
|
1596
|
+
type: ASTFactory2.createNumber()
|
|
1597
|
+
})
|
|
1598
|
+
]
|
|
1599
|
+
})
|
|
1600
|
+
})
|
|
1601
|
+
]
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
// src/effects/provide-batch-outputs/index.ts
|
|
1605
|
+
import {
|
|
1606
|
+
ASTFactory as ASTFactory3,
|
|
1607
|
+
createEffectFromVariableProvider as createEffectFromVariableProvider2,
|
|
1608
|
+
getNodeForm as getNodeForm2
|
|
1609
|
+
} from "@flowgram.ai/editor";
|
|
1610
|
+
var provideBatchOutputsEffect = createEffectFromVariableProvider2({
|
|
1611
|
+
private: true,
|
|
1612
|
+
parse: (value, ctx) => [
|
|
1613
|
+
ASTFactory3.createVariableDeclaration({
|
|
1614
|
+
key: `${ctx.node.id}`,
|
|
1615
|
+
meta: {
|
|
1616
|
+
title: getNodeForm2(ctx.node)?.getValueIn("title"),
|
|
1617
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1618
|
+
},
|
|
1619
|
+
type: ASTFactory3.createObject({
|
|
1620
|
+
properties: Object.entries(value).map(
|
|
1621
|
+
([_key, value2]) => ASTFactory3.createProperty({
|
|
1622
|
+
key: _key,
|
|
1623
|
+
initializer: ASTFactory3.createWrapArrayExpression({
|
|
1624
|
+
wrapFor: ASTFactory3.createKeyPathExpression({
|
|
1625
|
+
keyPath: value2.content || []
|
|
1626
|
+
})
|
|
1627
|
+
})
|
|
1628
|
+
})
|
|
1629
|
+
)
|
|
1630
|
+
})
|
|
1631
|
+
})
|
|
1632
|
+
]
|
|
1633
|
+
});
|
|
1634
|
+
|
|
1635
|
+
// src/effects/auto-rename-ref/index.ts
|
|
1636
|
+
import { isArray, isObject as isObject2 } from "lodash";
|
|
1637
|
+
import {
|
|
1638
|
+
DataEvent,
|
|
1639
|
+
VariableFieldKeyRenameService
|
|
1640
|
+
} from "@flowgram.ai/editor";
|
|
1641
|
+
var autoRenameRefEffect = [
|
|
1642
|
+
{
|
|
1643
|
+
event: DataEvent.onValueInit,
|
|
1644
|
+
effect: (params) => {
|
|
1645
|
+
const { context, form, name } = params;
|
|
1646
|
+
const renameService = context.node.getService(VariableFieldKeyRenameService);
|
|
1647
|
+
const disposable = renameService.onRename(({ before, after }) => {
|
|
1648
|
+
const beforeKeyPath = [
|
|
1649
|
+
...before.parentFields.map((_field) => _field.key).reverse(),
|
|
1650
|
+
before.key
|
|
1651
|
+
];
|
|
1652
|
+
const afterKeyPath = [
|
|
1653
|
+
...after.parentFields.map((_field) => _field.key).reverse(),
|
|
1654
|
+
after.key
|
|
1655
|
+
];
|
|
1656
|
+
traverseRef(name, form.getValueIn(name), (_drilldownName, _v) => {
|
|
1657
|
+
if (isRefMatch(_v, beforeKeyPath)) {
|
|
1658
|
+
_v.content = [...afterKeyPath, ...(_v.content || [])?.slice(beforeKeyPath.length)];
|
|
1659
|
+
form.setValueIn(_drilldownName, _v);
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
return () => {
|
|
1664
|
+
disposable.dispose();
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
];
|
|
1669
|
+
function isRefMatch(value, targetKeyPath) {
|
|
1670
|
+
return targetKeyPath.every((_key, index) => _key === value.content?.[index]);
|
|
1671
|
+
}
|
|
1672
|
+
function isRef(value) {
|
|
1673
|
+
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
1674
|
+
}
|
|
1675
|
+
function traverseRef(name, value, cb) {
|
|
1676
|
+
if (isObject2(value)) {
|
|
1677
|
+
if (isRef(value)) {
|
|
1678
|
+
cb(name, value);
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
Object.entries(value).forEach(([_key, _value]) => {
|
|
1682
|
+
traverseRef(`${name}.${_key}`, _value, cb);
|
|
1683
|
+
});
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
if (isArray(value)) {
|
|
1687
|
+
value.forEach((_value, idx) => {
|
|
1688
|
+
traverseRef(`${name}[${idx}]`, _value, cb);
|
|
1689
|
+
});
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1260
1694
|
export {
|
|
1261
1695
|
ArrayIcons,
|
|
1262
1696
|
BatchVariableSelector,
|
|
1697
|
+
ConditionRow,
|
|
1263
1698
|
ConstantInput,
|
|
1264
1699
|
DynamicValueInput,
|
|
1265
1700
|
JsonSchemaEditor,
|
|
1701
|
+
JsonSchemaUtils,
|
|
1266
1702
|
TypeSelector,
|
|
1267
1703
|
VariableSelector,
|
|
1268
1704
|
VariableTypeIcons,
|
|
1705
|
+
autoRenameRefEffect,
|
|
1269
1706
|
formatLegacyRefOnInit,
|
|
1270
1707
|
formatLegacyRefOnSubmit,
|
|
1271
1708
|
formatLegacyRefToNewRef,
|