@flowgram.ai/form-materials 0.2.1 → 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 CHANGED
@@ -446,7 +446,8 @@ var JsonSchemaUtils;
446
446
  }
447
447
  }
448
448
  JsonSchemaUtils2.schemaToAST = schemaToAST;
449
- function astToSchema(typeAST) {
449
+ function astToSchema(typeAST, options2) {
450
+ const { drilldown = true } = options2 || {};
450
451
  if (ASTMatch.isString(typeAST)) {
451
452
  return {
452
453
  type: "string"
@@ -470,21 +471,21 @@ var JsonSchemaUtils;
470
471
  if (ASTMatch.isObject(typeAST)) {
471
472
  return {
472
473
  type: "object",
473
- properties: Object.fromEntries(
474
+ properties: drilldown ? Object.fromEntries(
474
475
  Object.entries(typeAST.properties).map(([key, value]) => [key, astToSchema(value)])
475
- )
476
+ ) : {}
476
477
  };
477
478
  }
478
479
  if (ASTMatch.isArray(typeAST)) {
479
480
  return {
480
481
  type: "array",
481
- items: astToSchema(typeAST.items)
482
+ items: drilldown ? astToSchema(typeAST.items) : void 0
482
483
  };
483
484
  }
484
485
  if (ASTMatch.isMap(typeAST)) {
485
486
  return {
486
487
  type: "map",
487
- items: astToSchema(typeAST.valueType)
488
+ items: drilldown ? astToSchema(typeAST.valueType) : void 0
488
489
  };
489
490
  }
490
491
  if (ASTMatch.isCustomType(typeAST)) {
@@ -679,7 +680,7 @@ var VariableSelector = ({
679
680
  );
680
681
  },
681
682
  showClear: false,
682
- arrowIcon: value ? null : /* @__PURE__ */ React3.createElement(IconChevronDownStroked, { size: "small" }),
683
+ arrowIcon: /* @__PURE__ */ React3.createElement(IconChevronDownStroked, { size: "small" }),
683
684
  triggerRender,
684
685
  placeholder: config?.placeholder ?? "Select Variable..."
685
686
  }
@@ -722,8 +723,8 @@ function TypeSelector(props) {
722
723
  }
723
724
 
724
725
  // src/components/json-schema-editor/index.tsx
725
- import React6, { useMemo as useMemo4, useState as useState2 } from "react";
726
- import { Button as Button2, Checkbox, IconButton, Input } from "@douyinfe/semi-ui";
726
+ import React7, { useMemo as useMemo4, useState as useState3 } from "react";
727
+ import { Button as Button2, Checkbox, IconButton } from "@douyinfe/semi-ui";
727
728
  import {
728
729
  IconExpand,
729
730
  IconShrink,
@@ -975,6 +976,27 @@ function usePropertiesEdit(value, onChange) {
975
976
  };
976
977
  }
977
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
+
978
1000
  // src/components/json-schema-editor/index.tsx
979
1001
  function JsonSchemaEditor(props) {
980
1002
  const { value = { type: "object" }, config = {}, onChange: onChangeProps } = props;
@@ -982,7 +1004,7 @@ function JsonSchemaEditor(props) {
982
1004
  value,
983
1005
  onChangeProps
984
1006
  );
985
- return /* @__PURE__ */ React6.createElement(UIContainer, null, /* @__PURE__ */ React6.createElement(UIProperties, null, propertyList.map((_property) => /* @__PURE__ */ React6.createElement(
1007
+ return /* @__PURE__ */ React7.createElement(UIContainer, null, /* @__PURE__ */ React7.createElement(UIProperties, null, propertyList.map((_property) => /* @__PURE__ */ React7.createElement(
986
1008
  PropertyEdit,
987
1009
  {
988
1010
  key: _property.key,
@@ -995,12 +1017,12 @@ function JsonSchemaEditor(props) {
995
1017
  onRemoveProperty(_property.key);
996
1018
  }
997
1019
  }
998
- ))), /* @__PURE__ */ React6.createElement(Button2, { size: "small", style: { marginTop: 10 }, icon: /* @__PURE__ */ React6.createElement(IconPlus, null), onClick: onAddProperty }, config?.addButtonText ?? "Add"));
1020
+ ))), /* @__PURE__ */ React7.createElement(Button2, { size: "small", style: { marginTop: 10 }, icon: /* @__PURE__ */ React7.createElement(IconPlus, null), onClick: onAddProperty }, config?.addButtonText ?? "Add"));
999
1021
  }
1000
1022
  function PropertyEdit(props) {
1001
1023
  const { value, config, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
1002
- const [expand, setExpand] = useState2(false);
1003
- const [collapse, setCollapse] = useState2(false);
1024
+ const [expand, setExpand] = useState3(false);
1025
+ const [collapse, setCollapse] = useState3(false);
1004
1026
  const { name, type, items, description, isPropertyRequired } = value || {};
1005
1027
  const typeSelectorValue = useMemo4(() => ({ type, items }), [type, items]);
1006
1028
  const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(value, onChangeProps);
@@ -1011,15 +1033,15 @@ function PropertyEdit(props) {
1011
1033
  });
1012
1034
  };
1013
1035
  const showCollapse = isDrilldownObject && propertyList.length > 0;
1014
- return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(UIPropertyLeft, { $isLast, $showLine }, showCollapse && /* @__PURE__ */ React6.createElement(UICollapseTrigger, { onClick: () => setCollapse((_collapse) => !_collapse) }, collapse ? /* @__PURE__ */ React6.createElement(IconChevronDown, { size: "small" }) : /* @__PURE__ */ React6.createElement(IconChevronRight, { size: "small" }))), /* @__PURE__ */ React6.createElement(UIPropertyRight, null, /* @__PURE__ */ React6.createElement(UIPropertyMain, { $expand: expand }, /* @__PURE__ */ React6.createElement(UIRow, null, /* @__PURE__ */ React6.createElement(UIName, null, /* @__PURE__ */ React6.createElement(
1015
- Input,
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,
1016
1038
  {
1017
1039
  placeholder: config?.placeholder ?? "Input Variable Name",
1018
1040
  size: "small",
1019
1041
  value: name,
1020
1042
  onChange: (value2) => onChange("name", value2)
1021
1043
  }
1022
- )), /* @__PURE__ */ React6.createElement(UIType, null, /* @__PURE__ */ React6.createElement(
1044
+ )), /* @__PURE__ */ React7.createElement(UIType, null, /* @__PURE__ */ React7.createElement(
1023
1045
  TypeSelector,
1024
1046
  {
1025
1047
  value: typeSelectorValue,
@@ -1030,48 +1052,48 @@ function PropertyEdit(props) {
1030
1052
  });
1031
1053
  }
1032
1054
  }
1033
- )), /* @__PURE__ */ React6.createElement(UIRequired, null, /* @__PURE__ */ React6.createElement(
1055
+ )), /* @__PURE__ */ React7.createElement(UIRequired, null, /* @__PURE__ */ React7.createElement(
1034
1056
  Checkbox,
1035
1057
  {
1036
1058
  checked: isPropertyRequired,
1037
1059
  onChange: (e) => onChange("isPropertyRequired", e.target.checked)
1038
1060
  }
1039
- )), /* @__PURE__ */ React6.createElement(UIActions, null, /* @__PURE__ */ React6.createElement(
1061
+ )), /* @__PURE__ */ React7.createElement(UIActions, null, /* @__PURE__ */ React7.createElement(
1040
1062
  IconButton,
1041
1063
  {
1042
1064
  size: "small",
1043
1065
  theme: "borderless",
1044
- icon: expand ? /* @__PURE__ */ React6.createElement(IconShrink, { size: "small" }) : /* @__PURE__ */ React6.createElement(IconExpand, { size: "small" }),
1066
+ icon: expand ? /* @__PURE__ */ React7.createElement(IconShrink, { size: "small" }) : /* @__PURE__ */ React7.createElement(IconExpand, { size: "small" }),
1045
1067
  onClick: () => setExpand((_expand) => !_expand)
1046
1068
  }
1047
- ), isDrilldownObject && /* @__PURE__ */ React6.createElement(
1069
+ ), isDrilldownObject && /* @__PURE__ */ React7.createElement(
1048
1070
  IconButton,
1049
1071
  {
1050
1072
  size: "small",
1051
1073
  theme: "borderless",
1052
- icon: /* @__PURE__ */ React6.createElement(IconAddChildren, null),
1074
+ icon: /* @__PURE__ */ React7.createElement(IconAddChildren, null),
1053
1075
  onClick: () => {
1054
1076
  onAddProperty();
1055
1077
  setCollapse(true);
1056
1078
  }
1057
1079
  }
1058
- ), /* @__PURE__ */ React6.createElement(
1080
+ ), /* @__PURE__ */ React7.createElement(
1059
1081
  IconButton,
1060
1082
  {
1061
1083
  size: "small",
1062
1084
  theme: "borderless",
1063
- icon: /* @__PURE__ */ React6.createElement(IconMinus, { size: "small" }),
1085
+ icon: /* @__PURE__ */ React7.createElement(IconMinus, { size: "small" }),
1064
1086
  onClick: onRemove
1065
1087
  }
1066
- ))), expand && /* @__PURE__ */ React6.createElement(UIExpandDetail, null, /* @__PURE__ */ React6.createElement(UILabel, null, config?.descTitle ?? "Description"), /* @__PURE__ */ React6.createElement(
1067
- Input,
1088
+ ))), expand && /* @__PURE__ */ React7.createElement(UIExpandDetail, null, /* @__PURE__ */ React7.createElement(UILabel, null, config?.descTitle ?? "Description"), /* @__PURE__ */ React7.createElement(
1089
+ BlurInput,
1068
1090
  {
1069
1091
  size: "small",
1070
1092
  value: description,
1071
1093
  onChange: (value2) => onChange("description", value2),
1072
1094
  placeholder: config?.descPlaceholder ?? "Help LLM to understand the property"
1073
1095
  }
1074
- ))), showCollapse && /* @__PURE__ */ React6.createElement(UICollapsible, { $collapse: collapse }, /* @__PURE__ */ React6.createElement(UIProperties, { $shrink: true }, propertyList.map((_property, index) => /* @__PURE__ */ React6.createElement(
1096
+ ))), showCollapse && /* @__PURE__ */ React7.createElement(UICollapsible, { $collapse: collapse }, /* @__PURE__ */ React7.createElement(UIProperties, { $shrink: true }, propertyList.map((_property, index) => /* @__PURE__ */ React7.createElement(
1075
1097
  PropertyEdit,
1076
1098
  {
1077
1099
  key: _property.key,
@@ -1090,27 +1112,27 @@ function PropertyEdit(props) {
1090
1112
  }
1091
1113
 
1092
1114
  // src/components/batch-variable-selector/index.tsx
1093
- import React7 from "react";
1115
+ import React8 from "react";
1094
1116
  import { PrivateScopeProvider } from "@flowgram.ai/editor";
1095
1117
  var batchVariableSchema = {
1096
1118
  type: "array",
1097
1119
  extra: { weak: true }
1098
1120
  };
1099
1121
  function BatchVariableSelector(props) {
1100
- return /* @__PURE__ */ React7.createElement(PrivateScopeProvider, null, /* @__PURE__ */ React7.createElement(VariableSelector, { ...props, includeSchema: batchVariableSchema }));
1122
+ return /* @__PURE__ */ React8.createElement(PrivateScopeProvider, null, /* @__PURE__ */ React8.createElement(VariableSelector, { ...props, includeSchema: batchVariableSchema }));
1101
1123
  }
1102
1124
 
1103
1125
  // src/components/constant-input/index.tsx
1104
- import React8, { useMemo as useMemo5 } from "react";
1126
+ import React9, { useMemo as useMemo5 } from "react";
1105
1127
  import { Input as Input2, InputNumber, Select } from "@douyinfe/semi-ui";
1106
1128
  var defaultStrategies = [
1107
1129
  {
1108
1130
  hit: (schema) => schema?.type === "string",
1109
- Renderer: (props) => /* @__PURE__ */ React8.createElement(Input2, { placeholder: "Please Input String", size: "small", disabled: props.readonly, ...props })
1131
+ Renderer: (props) => /* @__PURE__ */ React9.createElement(Input2, { placeholder: "Please Input String", size: "small", disabled: props.readonly, ...props })
1110
1132
  },
1111
1133
  {
1112
1134
  hit: (schema) => schema?.type === "number",
1113
- Renderer: (props) => /* @__PURE__ */ React8.createElement(
1135
+ Renderer: (props) => /* @__PURE__ */ React9.createElement(
1114
1136
  InputNumber,
1115
1137
  {
1116
1138
  placeholder: "Please Input Number",
@@ -1123,7 +1145,7 @@ var defaultStrategies = [
1123
1145
  },
1124
1146
  {
1125
1147
  hit: (schema) => schema?.type === "integer",
1126
- Renderer: (props) => /* @__PURE__ */ React8.createElement(
1148
+ Renderer: (props) => /* @__PURE__ */ React9.createElement(
1127
1149
  InputNumber,
1128
1150
  {
1129
1151
  placeholder: "Please Input Integer",
@@ -1139,7 +1161,7 @@ var defaultStrategies = [
1139
1161
  hit: (schema) => schema?.type === "boolean",
1140
1162
  Renderer: (props) => {
1141
1163
  const { value, onChange, ...rest } = props;
1142
- return /* @__PURE__ */ React8.createElement(
1164
+ return /* @__PURE__ */ React9.createElement(
1143
1165
  Select,
1144
1166
  {
1145
1167
  placeholder: "Please Select Boolean",
@@ -1168,13 +1190,13 @@ function ConstantInput(props) {
1168
1190
  return strategy?.Renderer;
1169
1191
  }, [strategies, schema]);
1170
1192
  if (!Renderer) {
1171
- return /* @__PURE__ */ React8.createElement(Input2, { size: "small", disabled: true, placeholder: "Unsupported type" });
1193
+ return /* @__PURE__ */ React9.createElement(Input2, { size: "small", disabled: true, placeholder: "Unsupported type" });
1172
1194
  }
1173
- return /* @__PURE__ */ React8.createElement(Renderer, { value, onChange, readonly, ...rest });
1195
+ return /* @__PURE__ */ React9.createElement(Renderer, { value, onChange, readonly, ...rest });
1174
1196
  }
1175
1197
 
1176
1198
  // src/components/dynamic-value-input/index.tsx
1177
- import React9 from "react";
1199
+ import React10, { useMemo as useMemo6 } from "react";
1178
1200
  import { IconButton as IconButton2 } from "@douyinfe/semi-ui";
1179
1201
  import { IconSetting } from "@douyinfe/semi-icons";
1180
1202
 
@@ -1205,19 +1227,25 @@ function DynamicValueInput({
1205
1227
  schema,
1206
1228
  constantProps
1207
1229
  }) {
1230
+ const includeSchema = useMemo6(() => {
1231
+ if (schema?.type === "number") {
1232
+ return [schema, { type: "integer" }];
1233
+ }
1234
+ return schema;
1235
+ }, [schema]);
1208
1236
  const renderMain = () => {
1209
1237
  if (value?.type === "ref") {
1210
- return /* @__PURE__ */ React9.createElement(
1238
+ return /* @__PURE__ */ React10.createElement(
1211
1239
  VariableSelector,
1212
1240
  {
1213
1241
  value: value?.content,
1214
1242
  onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
1215
- includeSchema: schema,
1243
+ includeSchema,
1216
1244
  readonly
1217
1245
  }
1218
1246
  );
1219
1247
  }
1220
- return /* @__PURE__ */ React9.createElement(
1248
+ return /* @__PURE__ */ React10.createElement(
1221
1249
  ConstantInput,
1222
1250
  {
1223
1251
  value: value?.content,
@@ -1228,18 +1256,314 @@ function DynamicValueInput({
1228
1256
  }
1229
1257
  );
1230
1258
  };
1231
- const renderTrigger = () => /* @__PURE__ */ React9.createElement(
1259
+ const renderTrigger = () => /* @__PURE__ */ React10.createElement(
1232
1260
  VariableSelector,
1233
1261
  {
1234
1262
  style: { width: "100%" },
1235
1263
  value: value?.type === "ref" ? value?.content : void 0,
1236
1264
  onChange: (_v) => onChange({ type: "ref", content: _v }),
1237
- includeSchema: schema,
1265
+ includeSchema,
1238
1266
  readonly,
1239
- triggerRender: () => /* @__PURE__ */ React9.createElement(IconButton2, { disabled: readonly, size: "small", icon: /* @__PURE__ */ React9.createElement(IconSetting, { size: "small" }) })
1267
+ triggerRender: () => /* @__PURE__ */ React10.createElement(IconButton2, { disabled: readonly, size: "small", icon: /* @__PURE__ */ React10.createElement(IconSetting, { size: "small" }) })
1240
1268
  }
1241
1269
  );
1242
- return /* @__PURE__ */ React9.createElement(UIContainer2, { style }, /* @__PURE__ */ React9.createElement(UIMain, null, renderMain()), /* @__PURE__ */ React9.createElement(UITrigger, null, renderTrigger()));
1270
+ return /* @__PURE__ */ React10.createElement(UIContainer2, { style }, /* @__PURE__ */ React10.createElement(UIMain, null, renderMain()), /* @__PURE__ */ React10.createElement(UITrigger, null, renderTrigger()));
1271
+ }
1272
+
1273
+ // src/components/condition-row/index.tsx
1274
+ import React12, { useMemo as useMemo9 } from "react";
1275
+ import { Input as Input3 } from "@douyinfe/semi-ui";
1276
+
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
+ };
1424
+
1425
+ // src/utils/format-legacy-refs/index.ts
1426
+ import { isObject } from "lodash";
1427
+ function formatLegacyRefOnSubmit(value) {
1428
+ if (isObject(value)) {
1429
+ if (isLegacyFlowRefValueSchema(value)) {
1430
+ return formatLegacyRefToNewRef(value);
1431
+ }
1432
+ return Object.fromEntries(
1433
+ Object.entries(value).map(([key, value2]) => [
1434
+ key,
1435
+ formatLegacyRefOnSubmit(value2)
1436
+ ])
1437
+ );
1438
+ }
1439
+ if (Array.isArray(value)) {
1440
+ return value.map(formatLegacyRefOnSubmit);
1441
+ }
1442
+ return value;
1443
+ }
1444
+ function formatLegacyRefOnInit(value) {
1445
+ if (isObject(value)) {
1446
+ if (isNewFlowRefValueSchema(value)) {
1447
+ return formatNewRefToLegacyRef(value);
1448
+ }
1449
+ return Object.fromEntries(
1450
+ Object.entries(value).map(([key, value2]) => [
1451
+ key,
1452
+ formatLegacyRefOnInit(value2)
1453
+ ])
1454
+ );
1455
+ }
1456
+ if (Array.isArray(value)) {
1457
+ return value.map(formatLegacyRefOnInit);
1458
+ }
1459
+ return value;
1460
+ }
1461
+ function isLegacyFlowRefValueSchema(value) {
1462
+ return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
1463
+ }
1464
+ function isNewFlowRefValueSchema(value) {
1465
+ return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
1466
+ }
1467
+ function formatLegacyRefToNewRef(value) {
1468
+ const keyPath = value.content.split(".");
1469
+ if (keyPath[1] === "outputs") {
1470
+ return {
1471
+ type: "ref",
1472
+ content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
1473
+ };
1474
+ }
1475
+ return {
1476
+ type: "ref",
1477
+ content: keyPath
1478
+ };
1479
+ }
1480
+ function formatNewRefToLegacyRef(value) {
1481
+ return {
1482
+ type: "ref",
1483
+ content: value.content.join(".")
1484
+ };
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" }))));
1243
1567
  }
1244
1568
 
1245
1569
  // src/effects/provide-batch-input/index.ts
@@ -1308,70 +1632,69 @@ var provideBatchOutputsEffect = createEffectFromVariableProvider2({
1308
1632
  ]
1309
1633
  });
1310
1634
 
1311
- // src/utils/format-legacy-refs/index.ts
1312
- import { isObject } from "lodash";
1313
- function formatLegacyRefOnSubmit(value) {
1314
- if (isObject(value)) {
1315
- if (isLegacyFlowRefValueSchema(value)) {
1316
- return formatLegacyRefToNewRef(value);
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
+ };
1317
1666
  }
1318
- return Object.fromEntries(
1319
- Object.entries(value).map(([key, value2]) => [
1320
- key,
1321
- formatLegacyRefOnSubmit(value2)
1322
- ])
1323
- );
1324
- }
1325
- if (Array.isArray(value)) {
1326
- return value.map(formatLegacyRefOnSubmit);
1327
1667
  }
1328
- return value;
1668
+ ];
1669
+ function isRefMatch(value, targetKeyPath) {
1670
+ return targetKeyPath.every((_key, index) => _key === value.content?.[index]);
1329
1671
  }
1330
- function formatLegacyRefOnInit(value) {
1331
- if (isObject(value)) {
1332
- if (isNewFlowRefValueSchema(value)) {
1333
- return formatNewRefToLegacyRef(value);
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;
1334
1680
  }
1335
- return Object.fromEntries(
1336
- Object.entries(value).map(([key, value2]) => [
1337
- key,
1338
- formatLegacyRefOnInit(value2)
1339
- ])
1340
- );
1341
- }
1342
- if (Array.isArray(value)) {
1343
- return value.map(formatLegacyRefOnInit);
1681
+ Object.entries(value).forEach(([_key, _value]) => {
1682
+ traverseRef(`${name}.${_key}`, _value, cb);
1683
+ });
1684
+ return;
1344
1685
  }
1345
- return value;
1346
- }
1347
- function isLegacyFlowRefValueSchema(value) {
1348
- return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
1349
- }
1350
- function isNewFlowRefValueSchema(value) {
1351
- return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
1352
- }
1353
- function formatLegacyRefToNewRef(value) {
1354
- const keyPath = value.content.split(".");
1355
- if (keyPath[1] === "outputs") {
1356
- return {
1357
- type: "ref",
1358
- content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
1359
- };
1686
+ if (isArray(value)) {
1687
+ value.forEach((_value, idx) => {
1688
+ traverseRef(`${name}[${idx}]`, _value, cb);
1689
+ });
1690
+ return;
1360
1691
  }
1361
- return {
1362
- type: "ref",
1363
- content: keyPath
1364
- };
1365
- }
1366
- function formatNewRefToLegacyRef(value) {
1367
- return {
1368
- type: "ref",
1369
- content: value.content.join(".")
1370
- };
1692
+ return;
1371
1693
  }
1372
1694
  export {
1373
1695
  ArrayIcons,
1374
1696
  BatchVariableSelector,
1697
+ ConditionRow,
1375
1698
  ConstantInput,
1376
1699
  DynamicValueInput,
1377
1700
  JsonSchemaEditor,
@@ -1379,6 +1702,7 @@ export {
1379
1702
  TypeSelector,
1380
1703
  VariableSelector,
1381
1704
  VariableTypeIcons,
1705
+ autoRenameRefEffect,
1382
1706
  formatLegacyRefOnInit,
1383
1707
  formatLegacyRefOnSubmit,
1384
1708
  formatLegacyRefToNewRef,