@flowgram.ai/form-materials 0.4.1 → 0.4.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
@@ -103,7 +103,7 @@ var extraSchema = z.object({
103
103
  }).optional();
104
104
  var constantSchema = z.object({
105
105
  type: z.literal("constant"),
106
- content: z.union([z.string(), z.number(), z.boolean()]).optional(),
106
+ content: z.any().optional(),
107
107
  schema: z.any().optional(),
108
108
  extra: extraSchema
109
109
  });
@@ -1601,7 +1601,7 @@ var UITrigger = styled4.div`
1601
1601
  `;
1602
1602
 
1603
1603
  // src/components/dynamic-value-input/hooks.ts
1604
- import { useMemo as useMemo5, useState as useState4 } from "react";
1604
+ import { useEffect as useEffect4, useMemo as useMemo5, useRef as useRef3, useState as useState4 } from "react";
1605
1605
  import { useScopeAvailable } from "@flowgram.ai/editor";
1606
1606
  function useRefVariable(value) {
1607
1607
  const available = useScopeAvailable();
@@ -1617,8 +1617,25 @@ function useSelectSchema(schemaFromProps, constantProps, value) {
1617
1617
  if (value?.type === "constant") {
1618
1618
  defaultSelectSchema = value?.schema || defaultSelectSchema;
1619
1619
  }
1620
+ const changeVersion = useRef3(0);
1621
+ const effectVersion = useRef3(0);
1620
1622
  const [selectSchema, setSelectSchema] = useState4(defaultSelectSchema);
1621
- return [selectSchema, setSelectSchema];
1623
+ useEffect4(() => {
1624
+ effectVersion.current += 1;
1625
+ if (changeVersion.current === effectVersion.current) {
1626
+ return;
1627
+ }
1628
+ effectVersion.current = changeVersion.current;
1629
+ if (value?.type === "constant" && value?.schema) {
1630
+ setSelectSchema(value?.schema);
1631
+ return;
1632
+ }
1633
+ }, [value]);
1634
+ const setSelectSchemaWithVersionUpdate = (schema) => {
1635
+ setSelectSchema(schema);
1636
+ changeVersion.current += 1;
1637
+ };
1638
+ return [selectSchema, setSelectSchemaWithVersionUpdate];
1622
1639
  }
1623
1640
  function useIncludeSchema(schemaFromProps) {
1624
1641
  const includeSchema = useMemo5(() => {
@@ -1700,7 +1717,6 @@ function DynamicValueInput({
1700
1717
  onChange: (_v) => onChange({ type: "constant", content: _v, schema: constantSchema2 }),
1701
1718
  schema: constantSchema2 || { type: "string" },
1702
1719
  readonly,
1703
- strategies: [...constantProps?.strategies || []],
1704
1720
  fallbackRenderer: () => /* @__PURE__ */ React20.createElement(
1705
1721
  InjectVariableSelector,
1706
1722
  {
@@ -1710,7 +1726,8 @@ function DynamicValueInput({
1710
1726
  readonly
1711
1727
  }
1712
1728
  ),
1713
- ...constantProps
1729
+ ...constantProps,
1730
+ strategies: [...constantProps?.strategies || []]
1714
1731
  }
1715
1732
  );
1716
1733
  };
@@ -1996,7 +2013,7 @@ import { Button as Button3, Input as Input5 } from "@douyinfe/semi-ui";
1996
2013
  import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
1997
2014
 
1998
2015
  // src/hooks/use-object-list/index.tsx
1999
- import { useEffect as useEffect4, useRef as useRef3, useState as useState5 } from "react";
2016
+ import { useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
2000
2017
  import { nanoid } from "nanoid";
2001
2018
  import { difference as difference2, get, isObject as isObject3, set } from "lodash";
2002
2019
  function genId2() {
@@ -2008,15 +2025,15 @@ function useObjectList({
2008
2025
  sortIndexKey
2009
2026
  }) {
2010
2027
  const [list, setList] = useState5([]);
2011
- const effectVersion = useRef3(0);
2012
- const changeVersion = useRef3(0);
2028
+ const effectVersion = useRef4(0);
2029
+ const changeVersion = useRef4(0);
2013
2030
  const getSortIndex = (value2) => {
2014
2031
  if (typeof sortIndexKey === "function") {
2015
2032
  return get(value2, sortIndexKey(value2)) || 0;
2016
2033
  }
2017
2034
  return get(value2, sortIndexKey || "") || 0;
2018
2035
  };
2019
- useEffect4(() => {
2036
+ useEffect5(() => {
2020
2037
  effectVersion.current = effectVersion.current + 1;
2021
2038
  if (effectVersion.current === changeVersion.current) {
2022
2039
  return;
@@ -2156,7 +2173,7 @@ function BatchOutputs(props) {
2156
2173
  }
2157
2174
 
2158
2175
  // src/components/prompt-editor/index.tsx
2159
- import React24, { useEffect as useEffect5, useRef as useRef4 } from "react";
2176
+ import React24, { useEffect as useEffect6, useRef as useRef5 } from "react";
2160
2177
  import { Renderer, EditorProvider as EditorProvider2, ActiveLinePlaceholder as ActiveLinePlaceholder2 } from "@coze-editor/editor/react";
2161
2178
  import preset2 from "@coze-editor/editor/preset-prompt";
2162
2179
 
@@ -2301,8 +2318,8 @@ function PromptEditor(props) {
2301
2318
  disableMarkdownHighlight,
2302
2319
  options
2303
2320
  } = props || {};
2304
- const editorRef = useRef4(null);
2305
- useEffect5(() => {
2321
+ const editorRef = useRef5(null);
2322
+ useEffect6(() => {
2306
2323
  if (editorRef.current?.getValue() !== value?.content) {
2307
2324
  editorRef.current?.setValue(String(value?.content || ""));
2308
2325
  }
@@ -2332,7 +2349,7 @@ function PromptEditor(props) {
2332
2349
  import React27 from "react";
2333
2350
 
2334
2351
  // src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
2335
- import React25, { useEffect as useEffect6, useState as useState6 } from "react";
2352
+ import React25, { useEffect as useEffect7, useState as useState6 } from "react";
2336
2353
  import { Popover as Popover2, Tree } from "@douyinfe/semi-ui";
2337
2354
  import {
2338
2355
  Mention,
@@ -2360,7 +2377,7 @@ function VariableTree() {
2360
2377
  setPosition(e.state.selection.main.head);
2361
2378
  setVisible(e.value);
2362
2379
  }
2363
- useEffect6(() => {
2380
+ useEffect7(() => {
2364
2381
  if (!editor) {
2365
2382
  return;
2366
2383
  }
@@ -2565,7 +2582,7 @@ function PromptEditorWithVariables(props) {
2565
2582
  import React30 from "react";
2566
2583
 
2567
2584
  // src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
2568
- import React29, { useEffect as useEffect7, useState as useState7 } from "react";
2585
+ import React29, { useEffect as useEffect8, useState as useState7 } from "react";
2569
2586
  import { Popover as Popover4 } from "@douyinfe/semi-ui";
2570
2587
  import {
2571
2588
  Mention as Mention2,
@@ -2659,7 +2676,7 @@ function InputsTree({ inputsValues }) {
2659
2676
  setPosition(e.state.selection.main.head);
2660
2677
  setVisible(e.value);
2661
2678
  }
2662
- useEffect7(() => {
2679
+ useEffect8(() => {
2663
2680
  if (!editor) {
2664
2681
  return;
2665
2682
  }
@@ -2701,7 +2718,7 @@ import React33 from "react";
2701
2718
  import { transformerCreator } from "@coze-editor/editor/preset-code";
2702
2719
 
2703
2720
  // src/components/json-editor-with-variables/extensions/variable-tree.tsx
2704
- import React31, { useEffect as useEffect8, useState as useState8 } from "react";
2721
+ import React31, { useEffect as useEffect9, useState as useState8 } from "react";
2705
2722
  import { Popover as Popover5, Tree as Tree3 } from "@douyinfe/semi-ui";
2706
2723
  import {
2707
2724
  Mention as Mention3,
@@ -2729,7 +2746,7 @@ function VariableTree2() {
2729
2746
  setPosition(e.state.selection.main.head);
2730
2747
  setVisible(e.value);
2731
2748
  }
2732
- useEffect8(() => {
2749
+ useEffect9(() => {
2733
2750
  if (!editor) {
2734
2751
  return;
2735
2752
  }
@@ -3145,7 +3162,7 @@ function SchemaTree(props) {
3145
3162
  }
3146
3163
 
3147
3164
  // src/components/display-outputs/index.tsx
3148
- import React37, { useEffect as useEffect9 } from "react";
3165
+ import React37, { useEffect as useEffect10 } from "react";
3149
3166
  import { JsonSchemaUtils as JsonSchemaUtils6 } from "@flowgram.ai/json-schema";
3150
3167
  import { useCurrentScope as useCurrentScope3, useRefresh } from "@flowgram.ai/editor";
3151
3168
 
@@ -3202,7 +3219,7 @@ var DisplayOutputsWrapper = styled13.div`
3202
3219
  function DisplayOutputs({ value, showIconInTree, displayFromScope }) {
3203
3220
  const scope = useCurrentScope3();
3204
3221
  const refresh = useRefresh();
3205
- useEffect9(() => {
3222
+ useEffect10(() => {
3206
3223
  if (!displayFromScope) {
3207
3224
  return () => null;
3208
3225
  }
@@ -3248,18 +3265,7 @@ function DisplayFlowValue({ value, title, showIconInTree }) {
3248
3265
  return { type: "string" };
3249
3266
  }
3250
3267
  if (value?.type === "constant") {
3251
- if (value?.schema) {
3252
- return value?.schema;
3253
- }
3254
- if (typeof value?.content === "string") {
3255
- return { type: "string" };
3256
- }
3257
- if (typeof value?.content === "number") {
3258
- return { type: "number" };
3259
- }
3260
- if (typeof value?.content === "boolean") {
3261
- return { type: "boolean" };
3262
- }
3268
+ return FlowValueUtils.inferConstantJsonSchema(value);
3263
3269
  }
3264
3270
  return { type: "unknown" };
3265
3271
  }, [value, variable?.hash]);
@@ -3275,7 +3281,9 @@ function DisplayFlowValue({ value, title, showIconInTree }) {
3275
3281
  }
3276
3282
 
3277
3283
  // src/components/display-inputs-values/index.tsx
3278
- import React39 from "react";
3284
+ import React39, { useMemo as useMemo11 } from "react";
3285
+ import { isPlainObject as isPlainObject2 } from "lodash";
3286
+ import { useScopeAvailable as useScopeAvailable5 } from "@flowgram.ai/editor";
3279
3287
 
3280
3288
  // src/components/display-inputs-values/styles.ts
3281
3289
  import styled14 from "styled-components";
@@ -3288,7 +3296,35 @@ var DisplayInputsWrapper = styled14.div`
3288
3296
  // src/components/display-inputs-values/index.tsx
3289
3297
  function DisplayInputsValues({ value, showIconInTree }) {
3290
3298
  const childEntries = Object.entries(value || {});
3291
- return /* @__PURE__ */ React39.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => /* @__PURE__ */ React39.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree })));
3299
+ return /* @__PURE__ */ React39.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => {
3300
+ if (FlowValueUtils.isFlowValue(value2)) {
3301
+ return /* @__PURE__ */ React39.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree });
3302
+ }
3303
+ if (isPlainObject2(value2)) {
3304
+ return /* @__PURE__ */ React39.createElement(
3305
+ DisplayInputsValueAllInTag,
3306
+ {
3307
+ key,
3308
+ title: key,
3309
+ value: value2,
3310
+ showIconInTree
3311
+ }
3312
+ );
3313
+ }
3314
+ return null;
3315
+ }));
3316
+ }
3317
+ function DisplayInputsValueAllInTag({
3318
+ value,
3319
+ title,
3320
+ showIconInTree
3321
+ }) {
3322
+ const available = useScopeAvailable5();
3323
+ const schema = useMemo11(
3324
+ () => FlowValueUtils.inferJsonSchema(value, available.scope),
3325
+ [available.version, value]
3326
+ );
3327
+ return /* @__PURE__ */ React39.createElement(DisplaySchemaTag, { title, value: schema, showIconInTree });
3292
3328
  }
3293
3329
 
3294
3330
  // src/components/assign-rows/index.tsx
@@ -3303,11 +3339,11 @@ import { IconButton as IconButton5 } from "@douyinfe/semi-ui";
3303
3339
  import { IconMinus as IconMinus2 } from "@douyinfe/semi-icons";
3304
3340
 
3305
3341
  // src/components/assign-row/components/blur-input.tsx
3306
- import React40, { useEffect as useEffect10, useState as useState9 } from "react";
3342
+ import React40, { useEffect as useEffect11, useState as useState9 } from "react";
3307
3343
  import Input6 from "@douyinfe/semi-ui/lib/es/input";
3308
3344
  function BlurInput2(props) {
3309
3345
  const [value, setValue] = useState9("");
3310
- useEffect10(() => {
3346
+ useEffect11(() => {
3311
3347
  setValue(props.value);
3312
3348
  }, [props.value]);
3313
3349
  return /* @__PURE__ */ React40.createElement(
@@ -3523,17 +3559,17 @@ var iconAddChildrenSvg2 = /* @__PURE__ */ React43.createElement(
3523
3559
  var IconAddChildren2 = () => /* @__PURE__ */ React43.createElement(Icon4, { size: "small", svg: iconAddChildrenSvg2 });
3524
3560
 
3525
3561
  // src/components/inputs-values-tree/row.tsx
3526
- import React44, { useState as useState10 } from "react";
3562
+ import React44, { useMemo as useMemo13, useState as useState10 } from "react";
3527
3563
  import { I18n as I18n14 } from "@flowgram.ai/editor";
3528
3564
  import { IconButton as IconButton6, Input as Input7 } from "@douyinfe/semi-ui";
3529
3565
  import { IconChevronDown as IconChevronDown2, IconChevronRight as IconChevronRight2, IconDelete as IconDelete3 } from "@douyinfe/semi-icons";
3530
3566
 
3531
3567
  // src/components/inputs-values-tree/hooks/use-child-list.tsx
3532
- import { useMemo as useMemo11 } from "react";
3533
- import { isPlainObject as isPlainObject2 } from "lodash";
3568
+ import { useMemo as useMemo12 } from "react";
3569
+ import { isPlainObject as isPlainObject3 } from "lodash";
3534
3570
  function useChildList(value, onChange) {
3535
- const canAddField = useMemo11(() => {
3536
- if (!isPlainObject2(value)) {
3571
+ const canAddField = useMemo12(() => {
3572
+ if (!isPlainObject3(value)) {
3537
3573
  return false;
3538
3574
  }
3539
3575
  if (FlowValueUtils.isFlowValue(value)) {
@@ -3541,8 +3577,8 @@ function useChildList(value, onChange) {
3541
3577
  }
3542
3578
  return true;
3543
3579
  }, [value]);
3544
- const objectListValue = useMemo11(() => {
3545
- if (isPlainObject2(value)) {
3580
+ const objectListValue = useMemo12(() => {
3581
+ if (isPlainObject3(value)) {
3546
3582
  if (FlowValueUtils.isFlowValue(value)) {
3547
3583
  return void 0;
3548
3584
  }
@@ -3550,7 +3586,6 @@ function useChildList(value, onChange) {
3550
3586
  }
3551
3587
  return void 0;
3552
3588
  }, [value]);
3553
- console.log("debugger objectListValue", objectListValue);
3554
3589
  const { list, add, updateKey, updateValue, remove } = useObjectList({
3555
3590
  value: objectListValue,
3556
3591
  onChange: (value2) => {
@@ -3558,8 +3593,13 @@ function useChildList(value, onChange) {
3558
3593
  },
3559
3594
  sortIndexKey: (value2) => FlowValueUtils.isFlowValue(value2) ? "extra.index" : ""
3560
3595
  });
3596
+ const hasChildren = useMemo12(
3597
+ () => canAddField && (list.length > 0 || Object.keys(objectListValue || {}).length > 0),
3598
+ [canAddField, list.length, Object.keys(objectListValue || {}).length]
3599
+ );
3561
3600
  return {
3562
3601
  canAddField,
3602
+ hasChildren,
3563
3603
  list,
3564
3604
  add,
3565
3605
  updateKey,
@@ -3595,12 +3635,21 @@ function InputValueRow(props) {
3595
3635
  readonly
3596
3636
  } = props;
3597
3637
  const [collapse, setCollapse] = useState10(false);
3598
- const { canAddField, list, add, updateKey, updateValue, remove } = useChildList(
3638
+ const { canAddField, hasChildren, list, add, updateKey, updateValue, remove } = useChildList(
3599
3639
  value,
3600
3640
  onUpdateValue
3601
3641
  );
3602
- const hasChildren = canAddField && list.length > 0;
3603
- const flowDisplayValue = hasChildren ? { type: "constant", schema: { type: " object" } } : value;
3642
+ const strategies = useMemo13(
3643
+ () => [...hasChildren ? [AddObjectChildStrategy] : [], ...constantProps?.strategies || []],
3644
+ [hasChildren, constantProps?.strategies]
3645
+ );
3646
+ const flowDisplayValue = useMemo13(
3647
+ () => hasChildren ? {
3648
+ type: "constant",
3649
+ schema: { type: "object" }
3650
+ } : value,
3651
+ [hasChildren, value]
3652
+ );
3604
3653
  return /* @__PURE__ */ React44.createElement(React44.Fragment, null, /* @__PURE__ */ React44.createElement(UITreeItemLeft2, { $isLast, $showLine: $level > 0, $showCollapse: hasChildren }, hasChildren && /* @__PURE__ */ React44.createElement(UICollapseTrigger2, { onClick: () => setCollapse((_collapse) => !_collapse) }, collapse ? /* @__PURE__ */ React44.createElement(IconChevronDown2, { size: "small" }) : /* @__PURE__ */ React44.createElement(IconChevronRight2, { size: "small" }))), /* @__PURE__ */ React44.createElement(UITreeItemRight2, null, /* @__PURE__ */ React44.createElement(UITreeItemMain2, null, /* @__PURE__ */ React44.createElement(UIRow4, null, /* @__PURE__ */ React44.createElement(
3605
3654
  BlurInput,
3606
3655
  {
@@ -3621,10 +3670,7 @@ function InputValueRow(props) {
3621
3670
  hasError,
3622
3671
  constantProps: {
3623
3672
  ...constantProps,
3624
- strategies: [
3625
- ...hasChildren ? [AddObjectChildStrategy] : [],
3626
- ...constantProps?.strategies || []
3627
- ]
3673
+ strategies
3628
3674
  }
3629
3675
  }
3630
3676
  ), /* @__PURE__ */ React44.createElement(UIActions2, null, canAddField && /* @__PURE__ */ React44.createElement(
@@ -4137,6 +4183,7 @@ export {
4137
4183
  ConditionRow,
4138
4184
  ConstantInput,
4139
4185
  DisplayFlowValue,
4186
+ DisplayInputsValueAllInTag,
4140
4187
  DisplayInputsValues,
4141
4188
  DisplayOutputs,
4142
4189
  DisplaySchemaTag,