@flowgram.ai/form-materials 0.2.29 → 0.2.31

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
@@ -524,7 +524,7 @@ var JsonSchemaUtils;
524
524
 
525
525
  // src/components/variable-selector/use-variable-tree.tsx
526
526
  function useVariableTree(params) {
527
- const { includeSchema, excludeSchema } = params;
527
+ const { includeSchema, excludeSchema, customSkip } = params;
528
528
  const variables = useAvailableVariables();
529
529
  const getVariableTypeIcon = useCallback((variable) => {
530
530
  if (variable.meta?.icon) {
@@ -561,7 +561,8 @@ function useVariableTree(params) {
561
561
  const key = keyPath.join(".");
562
562
  const isSchemaInclude = includeSchema ? JsonSchemaUtils.isASTMatchSchema(type, includeSchema) : true;
563
563
  const isSchemaExclude = excludeSchema ? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema) : false;
564
- const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
564
+ const isCustomSkip = customSkip ? customSkip(variable) : false;
565
+ const isSchemaMatch = isSchemaInclude && !isSchemaExclude && !isCustomSkip;
565
566
  if (!isSchemaMatch && !children?.length) {
566
567
  return null;
567
568
  }
@@ -573,7 +574,8 @@ function useVariableTree(params) {
573
574
  icon: getVariableTypeIcon(variable),
574
575
  children,
575
576
  disabled: !isSchemaMatch,
576
- rootMeta: parentFields[0]?.meta
577
+ rootMeta: parentFields[0]?.meta || variable.meta,
578
+ isRoot: !parentFields?.length
577
579
  };
578
580
  };
579
581
  return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
@@ -696,7 +698,7 @@ var VariableSelector = ({
696
698
  );
697
699
  }
698
700
  const rootIcon = renderIcon(_option.rootMeta?.icon || _option?.icon);
699
- const rootTitle = /* @__PURE__ */ React3.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null);
701
+ const rootTitle = /* @__PURE__ */ React3.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} ${_option.isRoot ? "" : "-"} ` : null);
700
702
  return /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement(
701
703
  Popover,
702
704
  {
@@ -710,7 +712,7 @@ var VariableSelector = ({
710
712
  onClose: () => onChange(void 0)
711
713
  },
712
714
  rootTitle,
713
- /* @__PURE__ */ React3.createElement(UIVarName, { $inSelector: true }, _option.label)
715
+ !_option.isRoot && /* @__PURE__ */ React3.createElement(UIVarName, { $inSelector: true }, _option.label)
714
716
  )
715
717
  ));
716
718
  },
@@ -1744,8 +1746,8 @@ var rules = {
1744
1746
  ["not_contains" /* NOT_CONTAINS */]: "string",
1745
1747
  ["in" /* IN */]: "array",
1746
1748
  ["nin" /* NIN */]: "array",
1747
- ["is_empty" /* IS_EMPTY */]: "string",
1748
- ["is_not_empty" /* IS_NOT_EMPTY */]: "string"
1749
+ ["is_empty" /* IS_EMPTY */]: null,
1750
+ ["is_not_empty" /* IS_NOT_EMPTY */]: null
1749
1751
  },
1750
1752
  number: {
1751
1753
  ["eq" /* EQ */]: "number",
@@ -1755,9 +1757,7 @@ var rules = {
1755
1757
  ["lt" /* LT */]: "number",
1756
1758
  ["lte" /* LTE */]: "number",
1757
1759
  ["in" /* IN */]: "array",
1758
- ["nin" /* NIN */]: "array",
1759
- ["is_empty" /* IS_EMPTY */]: null,
1760
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1760
+ ["nin" /* NIN */]: "array"
1761
1761
  },
1762
1762
  integer: {
1763
1763
  ["eq" /* EQ */]: "number",
@@ -1767,9 +1767,7 @@ var rules = {
1767
1767
  ["lt" /* LT */]: "number",
1768
1768
  ["lte" /* LTE */]: "number",
1769
1769
  ["in" /* IN */]: "array",
1770
- ["nin" /* NIN */]: "array",
1771
- ["is_empty" /* IS_EMPTY */]: null,
1772
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1770
+ ["nin" /* NIN */]: "array"
1773
1771
  },
1774
1772
  boolean: {
1775
1773
  ["eq" /* EQ */]: "boolean",
@@ -1777,9 +1775,7 @@ var rules = {
1777
1775
  ["is_true" /* IS_TRUE */]: null,
1778
1776
  ["is_false" /* IS_FALSE */]: null,
1779
1777
  ["in" /* IN */]: "array",
1780
- ["nin" /* NIN */]: "array",
1781
- ["is_empty" /* IS_EMPTY */]: null,
1782
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1778
+ ["nin" /* NIN */]: "array"
1783
1779
  },
1784
1780
  object: {
1785
1781
  ["is_empty" /* IS_EMPTY */]: null,
@@ -1955,18 +1951,19 @@ import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
1955
1951
  // src/hooks/use-object-list/index.tsx
1956
1952
  import { useEffect as useEffect3, useState as useState6 } from "react";
1957
1953
  import { nanoid } from "nanoid";
1958
- import { difference } from "lodash";
1954
+ import { difference, get as get2, isObject as isObject2, set } from "lodash";
1959
1955
  function genId2() {
1960
1956
  return nanoid();
1961
1957
  }
1962
1958
  function useObjectList({
1963
1959
  value,
1964
- onChange
1960
+ onChange,
1961
+ sortIndexKey
1965
1962
  }) {
1966
1963
  const [list, setList] = useState6([]);
1967
1964
  useEffect3(() => {
1968
1965
  setList((_prevList) => {
1969
- const newKeys = Object.keys(value || {});
1966
+ const newKeys = Object.entries(value || {}).sort((a, b) => get2(a[1], sortIndexKey || 0) - get2(b[1], sortIndexKey || 0)).map(([key]) => key);
1970
1967
  const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
1971
1968
  const addKeys = difference(newKeys, oldKeys);
1972
1969
  return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
@@ -2003,7 +2000,12 @@ function useObjectList({
2003
2000
  });
2004
2001
  onChange(
2005
2002
  Object.fromEntries(
2006
- nextList.filter((item) => item.key).map((item) => [item.key, item.value])
2003
+ nextList.filter((item) => item.key).map((item) => [item.key, item.value]).map((_res, idx) => {
2004
+ if (isObject2(_res[1]) && sortIndexKey) {
2005
+ set(_res[1], sortIndexKey, idx);
2006
+ }
2007
+ return _res;
2008
+ })
2007
2009
  )
2008
2010
  );
2009
2011
  return nextList;
@@ -2405,8 +2407,9 @@ var VariableTagWidget = class extends WidgetType {
2405
2407
  );
2406
2408
  return;
2407
2409
  }
2408
- const rootField = last(v.parentFields);
2409
- const rootTitle = /* @__PURE__ */ React17.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2410
+ const rootField = last(v.parentFields) || v;
2411
+ const isRoot = v.parentFields.length === 0;
2412
+ const rootTitle = /* @__PURE__ */ React17.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? "" : "-"} ` : "");
2410
2413
  const rootIcon = this.renderIcon(rootField?.meta.icon);
2411
2414
  this.renderReact(
2412
2415
  /* @__PURE__ */ React17.createElement(
@@ -2414,7 +2417,7 @@ var VariableTagWidget = class extends WidgetType {
2414
2417
  {
2415
2418
  content: /* @__PURE__ */ React17.createElement(UIPopoverContent2, null, rootIcon, rootTitle, /* @__PURE__ */ React17.createElement(UIVarName2, null, v?.keyPath.slice(1).join(".")))
2416
2419
  },
2417
- /* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ React17.createElement(UIVarName2, null, v?.key))
2420
+ /* @__PURE__ */ React17.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, !isRoot && /* @__PURE__ */ React17.createElement(UIVarName2, null, v?.key))
2418
2421
  )
2419
2422
  );
2420
2423
  }
@@ -2653,6 +2656,42 @@ function getSuffixByLanguageId(languageId) {
2653
2656
  return "";
2654
2657
  }
2655
2658
 
2659
+ // src/components/code-editor/language-features.ts
2660
+ import { languages } from "@coze-editor/editor/preset-code";
2661
+ import { typescript } from "@coze-editor/editor/language-typescript";
2662
+ import { shell } from "@coze-editor/editor/language-shell";
2663
+ import { python } from "@coze-editor/editor/language-python";
2664
+ import { json } from "@coze-editor/editor/language-json";
2665
+ import { mixLanguages } from "@coze-editor/editor";
2666
+ languages.register("python", python);
2667
+ languages.register("shell", shell);
2668
+ languages.register("typescript", typescript);
2669
+ languages.register("json", {
2670
+ // mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
2671
+ language: mixLanguages({
2672
+ outerLanguage: json.language
2673
+ }),
2674
+ languageService: json.languageService
2675
+ });
2676
+ var tsWorkerInit = false;
2677
+ var initTsWorker = () => {
2678
+ if (tsWorkerInit) {
2679
+ return;
2680
+ }
2681
+ tsWorkerInit = true;
2682
+ const tsWorker = new Worker(
2683
+ new URL(`@coze-editor/editor/language-typescript/worker`, import.meta.url),
2684
+ { type: "module" }
2685
+ );
2686
+ typescript.languageService.initialize(tsWorker, {
2687
+ compilerOptions: {
2688
+ // eliminate Promise error
2689
+ lib: ["es2015", "dom"],
2690
+ noImplicitAny: false
2691
+ }
2692
+ });
2693
+ };
2694
+
2656
2695
  // src/components/code-editor/theme/index.ts
2657
2696
  import { themes } from "@coze-editor/editor/preset-code";
2658
2697
 
@@ -2882,24 +2921,6 @@ var darkTheme = createTheme2({
2882
2921
  themes.register("dark", darkTheme);
2883
2922
  themes.register("light", lightTheme);
2884
2923
 
2885
- // src/components/code-editor/language-features.ts
2886
- import { languages } from "@coze-editor/editor/preset-code";
2887
- import { typescript } from "@coze-editor/editor/language-typescript";
2888
- import { shell } from "@coze-editor/editor/language-shell";
2889
- import { python } from "@coze-editor/editor/language-python";
2890
- import { json } from "@coze-editor/editor/language-json";
2891
- import { mixLanguages } from "@coze-editor/editor";
2892
- languages.register("python", python);
2893
- languages.register("typescript", typescript);
2894
- languages.register("shell", shell);
2895
- languages.register("json", {
2896
- // mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
2897
- language: mixLanguages({
2898
- outerLanguage: json.language
2899
- }),
2900
- languageService: json.languageService
2901
- });
2902
-
2903
2924
  // src/components/code-editor/index.tsx
2904
2925
  var OriginCodeEditor = createRenderer(preset2, [
2905
2926
  EditorView4.theme({
@@ -2920,6 +2941,11 @@ function CodeEditor({
2920
2941
  readonly
2921
2942
  }) {
2922
2943
  const editorRef = useRef4(null);
2944
+ useEffect7(() => {
2945
+ if (languageId === "typescript") {
2946
+ initTsWorker();
2947
+ }
2948
+ }, [languageId]);
2923
2949
  useEffect7(() => {
2924
2950
  if (editorRef.current?.getValue() !== value) {
2925
2951
  editorRef.current?.setValue(String(value || ""));
@@ -3220,8 +3246,8 @@ function JsonEditorWithVariables(props) {
3220
3246
  }
3221
3247
 
3222
3248
  // src/components/inputs-values/index.tsx
3223
- import React26 from "react";
3224
- import { Button as Button4, IconButton as IconButton5, Input as Input5 } from "@douyinfe/semi-ui";
3249
+ import React27 from "react";
3250
+ import { Button as Button4, IconButton as IconButton5 } from "@douyinfe/semi-ui";
3225
3251
  import { IconDelete as IconDelete2, IconPlus as IconPlus3 } from "@douyinfe/semi-icons";
3226
3252
 
3227
3253
  // src/components/inputs-values/styles.tsx
@@ -3238,43 +3264,76 @@ var UIRow3 = styled9.div`
3238
3264
  gap: 5px;
3239
3265
  `;
3240
3266
 
3267
+ // src/components/inputs-values/components/blur-input.tsx
3268
+ import React26, { useEffect as useEffect9, useState as useState10 } from "react";
3269
+ import Input5 from "@douyinfe/semi-ui/lib/es/input";
3270
+ function BlurInput2(props) {
3271
+ const [value, setValue] = useState10("");
3272
+ useEffect9(() => {
3273
+ setValue(props.value);
3274
+ }, [props.value]);
3275
+ return /* @__PURE__ */ React26.createElement(
3276
+ Input5,
3277
+ {
3278
+ ...props,
3279
+ value,
3280
+ onChange: (value2) => {
3281
+ setValue(value2);
3282
+ },
3283
+ onBlur: (e) => props.onChange?.(value, e)
3284
+ }
3285
+ );
3286
+ }
3287
+
3241
3288
  // src/components/inputs-values/index.tsx
3242
- function InputsValues({ value, onChange, style, readonly, constantProps }) {
3289
+ function InputsValues({
3290
+ value,
3291
+ onChange,
3292
+ style,
3293
+ readonly,
3294
+ constantProps,
3295
+ schema,
3296
+ hasError
3297
+ }) {
3243
3298
  const { list, updateKey, updateValue, remove, add } = useObjectList({
3244
3299
  value,
3245
- onChange
3300
+ onChange,
3301
+ sortIndexKey: "extra.index"
3246
3302
  });
3247
- return /* @__PURE__ */ React26.createElement("div", null, /* @__PURE__ */ React26.createElement(UIRows2, { style }, list.map((item) => /* @__PURE__ */ React26.createElement(UIRow3, { key: item.id }, /* @__PURE__ */ React26.createElement(
3248
- Input5,
3303
+ return /* @__PURE__ */ React27.createElement("div", null, /* @__PURE__ */ React27.createElement(UIRows2, { style }, list.map((item) => /* @__PURE__ */ React27.createElement(UIRow3, { key: item.id }, /* @__PURE__ */ React27.createElement(
3304
+ BlurInput2,
3249
3305
  {
3250
3306
  style: { width: 100, minWidth: 100, maxWidth: 100 },
3251
3307
  disabled: readonly,
3252
3308
  size: "small",
3253
3309
  value: item.key,
3254
- onChange: (v) => updateKey(item.id, v)
3310
+ onChange: (v) => updateKey(item.id, v),
3311
+ placeholder: "Input Key"
3255
3312
  }
3256
- ), /* @__PURE__ */ React26.createElement(
3313
+ ), /* @__PURE__ */ React27.createElement(
3257
3314
  DynamicValueInput,
3258
3315
  {
3259
3316
  style: { flexGrow: 1 },
3260
3317
  readonly,
3261
3318
  value: item.value,
3262
3319
  onChange: (v) => updateValue(item.id, v),
3320
+ schema,
3321
+ hasError,
3263
3322
  constantProps: {
3264
3323
  ...constantProps,
3265
3324
  strategies: [...constantProps?.strategies || []]
3266
3325
  }
3267
3326
  }
3268
- ), /* @__PURE__ */ React26.createElement(
3327
+ ), /* @__PURE__ */ React27.createElement(
3269
3328
  IconButton5,
3270
3329
  {
3271
3330
  disabled: readonly,
3272
3331
  theme: "borderless",
3273
- icon: /* @__PURE__ */ React26.createElement(IconDelete2, { size: "small" }),
3332
+ icon: /* @__PURE__ */ React27.createElement(IconDelete2, { size: "small" }),
3274
3333
  size: "small",
3275
3334
  onClick: () => remove(item.id)
3276
3335
  }
3277
- )))), /* @__PURE__ */ React26.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React26.createElement(IconPlus3, null), size: "small", onClick: add }, "Add"));
3336
+ )))), /* @__PURE__ */ React27.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React27.createElement(IconPlus3, null), size: "small", onClick: add }, "Add"));
3278
3337
  }
3279
3338
 
3280
3339
  // src/effects/provide-batch-input/index.ts
@@ -3313,7 +3372,7 @@ var provideBatchInputEffect = createEffectFromVariableProvider({
3313
3372
  });
3314
3373
 
3315
3374
  // src/effects/auto-rename-ref/index.ts
3316
- import { isArray, isObject as isObject2, uniq } from "lodash";
3375
+ import { isArray, isObject as isObject3, uniq } from "lodash";
3317
3376
  import {
3318
3377
  DataEvent,
3319
3378
  VariableFieldKeyRenameService
@@ -3383,7 +3442,7 @@ function isTemplate(value) {
3383
3442
  return value?.type === "template" && typeof value?.content === "string";
3384
3443
  }
3385
3444
  function traverseRef(name, value, cb) {
3386
- if (isObject2(value)) {
3445
+ if (isObject3(value)) {
3387
3446
  if (isRef(value)) {
3388
3447
  cb(name, value);
3389
3448
  return;
@@ -3522,7 +3581,7 @@ var createBatchOutputsFormPlugin = defineFormPluginCreator({
3522
3581
  });
3523
3582
 
3524
3583
  // src/form-plugins/infer-inputs-plugin/index.ts
3525
- import { get as get2, set } from "lodash";
3584
+ import { get as get3, set as set2 } from "lodash";
3526
3585
  import {
3527
3586
  defineFormPluginCreator as defineFormPluginCreator2,
3528
3587
  getNodePrivateScope as getNodePrivateScope2,
@@ -3534,11 +3593,11 @@ var createInferInputsPlugin = defineFormPluginCreator2({
3534
3593
  return;
3535
3594
  }
3536
3595
  addFormatOnSubmit((formData, ctx) => {
3537
- set(
3596
+ set2(
3538
3597
  formData,
3539
3598
  targetKey,
3540
3599
  infer(
3541
- get2(formData, sourceKey),
3600
+ get3(formData, sourceKey),
3542
3601
  scope === "private" ? getNodePrivateScope2(ctx.node) : getNodeScope2(ctx.node)
3543
3602
  )
3544
3603
  );