@flowgram.ai/form-materials 0.4.1 → 0.4.3
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 +198 -87
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +249 -139
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/display-flow-value/index.tsx +2 -12
- package/src/components/display-inputs-values/index.tsx +44 -6
- package/src/components/dynamic-value-input/hooks.ts +23 -2
- package/src/components/dynamic-value-input/index.tsx +21 -12
- package/src/components/inputs-values/index.tsx +12 -1
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +8 -3
- package/src/components/inputs-values-tree/index.tsx +7 -1
- package/src/components/inputs-values-tree/row.tsx +23 -9
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +11 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +1 -2
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +1 -1
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +13 -1
- package/src/components/type-selector/index.tsx +12 -2
- package/src/index.ts +1 -0
- package/src/shared/flow-value/schema.ts +1 -1
- package/src/shared/flow-value/utils.ts +1 -1
- package/src/typings/flow-value/index.ts +1 -1
- package/src/validate/validate-flow-value/index.tsx +4 -16
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.
|
|
106
|
+
content: z.any().optional(),
|
|
107
107
|
schema: z.any().optional(),
|
|
108
108
|
extra: extraSchema
|
|
109
109
|
});
|
|
@@ -183,13 +183,13 @@ var FlowValueUtils;
|
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
FlowValueUtils2.traverse = traverse;
|
|
186
|
-
function
|
|
187
|
-
const keyPathReg =
|
|
186
|
+
function getTemplateKeyPaths(value) {
|
|
187
|
+
const keyPathReg = /\{\{([^\}\{]+)\}\}/g;
|
|
188
188
|
return uniq(value.content?.match(keyPathReg) || []).map(
|
|
189
189
|
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
190
190
|
);
|
|
191
191
|
}
|
|
192
|
-
FlowValueUtils2.getTemplateKeyPaths =
|
|
192
|
+
FlowValueUtils2.getTemplateKeyPaths = getTemplateKeyPaths;
|
|
193
193
|
function inferConstantJsonSchema(value) {
|
|
194
194
|
if (value?.schema) {
|
|
195
195
|
return value.schema;
|
|
@@ -1052,12 +1052,24 @@ function TypeSelector(props) {
|
|
|
1052
1052
|
}),
|
|
1053
1053
|
[]
|
|
1054
1054
|
);
|
|
1055
|
+
const isDisabled = readonly || disabled;
|
|
1055
1056
|
return /* @__PURE__ */ React13.createElement(
|
|
1056
1057
|
Cascader,
|
|
1057
1058
|
{
|
|
1058
|
-
disabled:
|
|
1059
|
+
disabled: isDisabled,
|
|
1059
1060
|
size: "small",
|
|
1060
|
-
triggerRender: () => /* @__PURE__ */ React13.createElement(
|
|
1061
|
+
triggerRender: () => /* @__PURE__ */ React13.createElement(
|
|
1062
|
+
IconButton,
|
|
1063
|
+
{
|
|
1064
|
+
size: "small",
|
|
1065
|
+
style: {
|
|
1066
|
+
...isDisabled ? { pointerEvents: "none" } : {},
|
|
1067
|
+
...style || {}
|
|
1068
|
+
},
|
|
1069
|
+
disabled: isDisabled,
|
|
1070
|
+
icon
|
|
1071
|
+
}
|
|
1072
|
+
),
|
|
1061
1073
|
treeData: options,
|
|
1062
1074
|
value: selectValue,
|
|
1063
1075
|
leafOnly: true,
|
|
@@ -1541,7 +1553,10 @@ function BatchVariableSelector(props) {
|
|
|
1541
1553
|
|
|
1542
1554
|
// src/components/dynamic-value-input/index.tsx
|
|
1543
1555
|
import React20 from "react";
|
|
1544
|
-
import {
|
|
1556
|
+
import {
|
|
1557
|
+
JsonSchemaUtils as JsonSchemaUtils4,
|
|
1558
|
+
useTypeManager as useTypeManager3
|
|
1559
|
+
} from "@flowgram.ai/json-schema";
|
|
1545
1560
|
import { IconButton as IconButton3 } from "@douyinfe/semi-ui";
|
|
1546
1561
|
import { IconSetting } from "@douyinfe/semi-icons";
|
|
1547
1562
|
|
|
@@ -1601,7 +1616,7 @@ var UITrigger = styled4.div`
|
|
|
1601
1616
|
`;
|
|
1602
1617
|
|
|
1603
1618
|
// src/components/dynamic-value-input/hooks.ts
|
|
1604
|
-
import { useMemo as useMemo5, useState as useState4 } from "react";
|
|
1619
|
+
import { useEffect as useEffect4, useMemo as useMemo5, useRef as useRef3, useState as useState4 } from "react";
|
|
1605
1620
|
import { useScopeAvailable } from "@flowgram.ai/editor";
|
|
1606
1621
|
function useRefVariable(value) {
|
|
1607
1622
|
const available = useScopeAvailable();
|
|
@@ -1617,8 +1632,25 @@ function useSelectSchema(schemaFromProps, constantProps, value) {
|
|
|
1617
1632
|
if (value?.type === "constant") {
|
|
1618
1633
|
defaultSelectSchema = value?.schema || defaultSelectSchema;
|
|
1619
1634
|
}
|
|
1635
|
+
const changeVersion = useRef3(0);
|
|
1636
|
+
const effectVersion = useRef3(0);
|
|
1620
1637
|
const [selectSchema, setSelectSchema] = useState4(defaultSelectSchema);
|
|
1621
|
-
|
|
1638
|
+
useEffect4(() => {
|
|
1639
|
+
effectVersion.current += 1;
|
|
1640
|
+
if (changeVersion.current === effectVersion.current) {
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
effectVersion.current = changeVersion.current;
|
|
1644
|
+
if (value?.type === "constant" && value?.schema) {
|
|
1645
|
+
setSelectSchema(value?.schema);
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
}, [value]);
|
|
1649
|
+
const setSelectSchemaWithVersionUpdate = (schema) => {
|
|
1650
|
+
setSelectSchema(schema);
|
|
1651
|
+
changeVersion.current += 1;
|
|
1652
|
+
};
|
|
1653
|
+
return [selectSchema, setSelectSchemaWithVersionUpdate];
|
|
1622
1654
|
}
|
|
1623
1655
|
function useIncludeSchema(schemaFromProps) {
|
|
1624
1656
|
const includeSchema = useMemo5(() => {
|
|
@@ -1634,6 +1666,11 @@ function useIncludeSchema(schemaFromProps) {
|
|
|
1634
1666
|
}
|
|
1635
1667
|
|
|
1636
1668
|
// src/components/dynamic-value-input/index.tsx
|
|
1669
|
+
var DEFAULT_VALUE = {
|
|
1670
|
+
type: "constant",
|
|
1671
|
+
content: "",
|
|
1672
|
+
schema: { type: "string" }
|
|
1673
|
+
};
|
|
1637
1674
|
function DynamicValueInput({
|
|
1638
1675
|
value,
|
|
1639
1676
|
onChange,
|
|
@@ -1645,6 +1682,7 @@ function DynamicValueInput({
|
|
|
1645
1682
|
const refVariable = useRefVariable(value);
|
|
1646
1683
|
const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
|
|
1647
1684
|
const includeSchema = useIncludeSchema(schemaFromProps);
|
|
1685
|
+
const typeManager = useTypeManager3();
|
|
1648
1686
|
const renderTypeSelector = () => {
|
|
1649
1687
|
if (schemaFromProps) {
|
|
1650
1688
|
return /* @__PURE__ */ React20.createElement(TypeSelector, { value: schemaFromProps, readonly: true });
|
|
@@ -1659,20 +1697,18 @@ function DynamicValueInput({
|
|
|
1659
1697
|
value: selectSchema,
|
|
1660
1698
|
onChange: (_v) => {
|
|
1661
1699
|
setSelectSchema(_v || { type: "string" });
|
|
1662
|
-
|
|
1700
|
+
const schema = _v || { type: "string" };
|
|
1701
|
+
let content = typeManager.getDefaultValue(schema);
|
|
1663
1702
|
if (_v?.type === "object") {
|
|
1664
1703
|
content = "{}";
|
|
1665
1704
|
}
|
|
1666
1705
|
if (_v?.type === "array") {
|
|
1667
1706
|
content = "[]";
|
|
1668
1707
|
}
|
|
1669
|
-
if (_v?.type === "boolean") {
|
|
1670
|
-
content = false;
|
|
1671
|
-
}
|
|
1672
1708
|
onChange({
|
|
1673
1709
|
type: "constant",
|
|
1674
1710
|
content,
|
|
1675
|
-
schema
|
|
1711
|
+
schema
|
|
1676
1712
|
});
|
|
1677
1713
|
},
|
|
1678
1714
|
readonly
|
|
@@ -1686,7 +1722,7 @@ function DynamicValueInput({
|
|
|
1686
1722
|
{
|
|
1687
1723
|
style: { width: "100%" },
|
|
1688
1724
|
value: value?.content,
|
|
1689
|
-
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } :
|
|
1725
|
+
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : DEFAULT_VALUE),
|
|
1690
1726
|
includeSchema,
|
|
1691
1727
|
readonly
|
|
1692
1728
|
}
|
|
@@ -1700,17 +1736,17 @@ function DynamicValueInput({
|
|
|
1700
1736
|
onChange: (_v) => onChange({ type: "constant", content: _v, schema: constantSchema2 }),
|
|
1701
1737
|
schema: constantSchema2 || { type: "string" },
|
|
1702
1738
|
readonly,
|
|
1703
|
-
strategies: [...constantProps?.strategies || []],
|
|
1704
1739
|
fallbackRenderer: () => /* @__PURE__ */ React20.createElement(
|
|
1705
1740
|
InjectVariableSelector,
|
|
1706
1741
|
{
|
|
1707
1742
|
style: { width: "100%" },
|
|
1708
|
-
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } :
|
|
1743
|
+
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : DEFAULT_VALUE),
|
|
1709
1744
|
includeSchema,
|
|
1710
1745
|
readonly
|
|
1711
1746
|
}
|
|
1712
1747
|
),
|
|
1713
|
-
...constantProps
|
|
1748
|
+
...constantProps,
|
|
1749
|
+
strategies: [...constantProps?.strategies || []]
|
|
1714
1750
|
}
|
|
1715
1751
|
);
|
|
1716
1752
|
};
|
|
@@ -1996,7 +2032,7 @@ import { Button as Button3, Input as Input5 } from "@douyinfe/semi-ui";
|
|
|
1996
2032
|
import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
|
|
1997
2033
|
|
|
1998
2034
|
// src/hooks/use-object-list/index.tsx
|
|
1999
|
-
import { useEffect as
|
|
2035
|
+
import { useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
|
|
2000
2036
|
import { nanoid } from "nanoid";
|
|
2001
2037
|
import { difference as difference2, get, isObject as isObject3, set } from "lodash";
|
|
2002
2038
|
function genId2() {
|
|
@@ -2008,15 +2044,15 @@ function useObjectList({
|
|
|
2008
2044
|
sortIndexKey
|
|
2009
2045
|
}) {
|
|
2010
2046
|
const [list, setList] = useState5([]);
|
|
2011
|
-
const effectVersion =
|
|
2012
|
-
const changeVersion =
|
|
2047
|
+
const effectVersion = useRef4(0);
|
|
2048
|
+
const changeVersion = useRef4(0);
|
|
2013
2049
|
const getSortIndex = (value2) => {
|
|
2014
2050
|
if (typeof sortIndexKey === "function") {
|
|
2015
2051
|
return get(value2, sortIndexKey(value2)) || 0;
|
|
2016
2052
|
}
|
|
2017
2053
|
return get(value2, sortIndexKey || "") || 0;
|
|
2018
2054
|
};
|
|
2019
|
-
|
|
2055
|
+
useEffect5(() => {
|
|
2020
2056
|
effectVersion.current = effectVersion.current + 1;
|
|
2021
2057
|
if (effectVersion.current === changeVersion.current) {
|
|
2022
2058
|
return;
|
|
@@ -2156,7 +2192,7 @@ function BatchOutputs(props) {
|
|
|
2156
2192
|
}
|
|
2157
2193
|
|
|
2158
2194
|
// src/components/prompt-editor/index.tsx
|
|
2159
|
-
import React24, { useEffect as
|
|
2195
|
+
import React24, { useEffect as useEffect6, useRef as useRef5 } from "react";
|
|
2160
2196
|
import { Renderer, EditorProvider as EditorProvider2, ActiveLinePlaceholder as ActiveLinePlaceholder2 } from "@coze-editor/editor/react";
|
|
2161
2197
|
import preset2 from "@coze-editor/editor/preset-prompt";
|
|
2162
2198
|
|
|
@@ -2301,8 +2337,8 @@ function PromptEditor(props) {
|
|
|
2301
2337
|
disableMarkdownHighlight,
|
|
2302
2338
|
options
|
|
2303
2339
|
} = props || {};
|
|
2304
|
-
const editorRef =
|
|
2305
|
-
|
|
2340
|
+
const editorRef = useRef5(null);
|
|
2341
|
+
useEffect6(() => {
|
|
2306
2342
|
if (editorRef.current?.getValue() !== value?.content) {
|
|
2307
2343
|
editorRef.current?.setValue(String(value?.content || ""));
|
|
2308
2344
|
}
|
|
@@ -2332,7 +2368,7 @@ function PromptEditor(props) {
|
|
|
2332
2368
|
import React27 from "react";
|
|
2333
2369
|
|
|
2334
2370
|
// src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
|
|
2335
|
-
import React25, { useEffect as
|
|
2371
|
+
import React25, { useEffect as useEffect7, useState as useState6 } from "react";
|
|
2336
2372
|
import { Popover as Popover2, Tree } from "@douyinfe/semi-ui";
|
|
2337
2373
|
import {
|
|
2338
2374
|
Mention,
|
|
@@ -2350,8 +2386,16 @@ function VariableTree() {
|
|
|
2350
2386
|
if (!range) {
|
|
2351
2387
|
return;
|
|
2352
2388
|
}
|
|
2389
|
+
let { from, to } = range;
|
|
2390
|
+
while (editor.$view.state.doc.sliceString(from - 1, from) === "{") {
|
|
2391
|
+
from--;
|
|
2392
|
+
}
|
|
2393
|
+
while (editor.$view.state.doc.sliceString(to, to + 1) === "}") {
|
|
2394
|
+
to++;
|
|
2395
|
+
}
|
|
2353
2396
|
editor.replaceText({
|
|
2354
|
-
|
|
2397
|
+
from,
|
|
2398
|
+
to,
|
|
2355
2399
|
text: "{{" + variablePath + "}}"
|
|
2356
2400
|
});
|
|
2357
2401
|
setVisible(false);
|
|
@@ -2360,7 +2404,7 @@ function VariableTree() {
|
|
|
2360
2404
|
setPosition(e.state.selection.main.head);
|
|
2361
2405
|
setVisible(e.value);
|
|
2362
2406
|
}
|
|
2363
|
-
|
|
2407
|
+
useEffect7(() => {
|
|
2364
2408
|
if (!editor) {
|
|
2365
2409
|
return;
|
|
2366
2410
|
}
|
|
@@ -2523,7 +2567,7 @@ function VariableTagInject() {
|
|
|
2523
2567
|
const scope = useCurrentScope();
|
|
2524
2568
|
useLayoutEffect4(() => {
|
|
2525
2569
|
const atMatcher = new MatchDecorator({
|
|
2526
|
-
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2570
|
+
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
2527
2571
|
decoration: (match) => Decoration.replace({
|
|
2528
2572
|
widget: new VariableTagWidget({
|
|
2529
2573
|
keyPath: match[1]?.split(".") ?? [],
|
|
@@ -2565,7 +2609,7 @@ function PromptEditorWithVariables(props) {
|
|
|
2565
2609
|
import React30 from "react";
|
|
2566
2610
|
|
|
2567
2611
|
// src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
|
|
2568
|
-
import React29, { useEffect as
|
|
2612
|
+
import React29, { useEffect as useEffect8, useState as useState7 } from "react";
|
|
2569
2613
|
import { Popover as Popover4 } from "@douyinfe/semi-ui";
|
|
2570
2614
|
import {
|
|
2571
2615
|
Mention as Mention2,
|
|
@@ -2576,7 +2620,7 @@ import {
|
|
|
2576
2620
|
|
|
2577
2621
|
// src/components/prompt-editor-with-inputs/inputs-picker.tsx
|
|
2578
2622
|
import React28, { useMemo as useMemo9 } from "react";
|
|
2579
|
-
import { last as last2 } from "lodash";
|
|
2623
|
+
import { isPlainObject as isPlainObject2, last as last2 } from "lodash";
|
|
2580
2624
|
import {
|
|
2581
2625
|
ASTMatch as ASTMatch3,
|
|
2582
2626
|
useScopeAvailable as useScopeAvailable3
|
|
@@ -2619,20 +2663,32 @@ function InputsPicker({
|
|
|
2619
2663
|
children
|
|
2620
2664
|
};
|
|
2621
2665
|
};
|
|
2622
|
-
const
|
|
2623
|
-
|
|
2624
|
-
|
|
2666
|
+
const getTreeData = (value, keyPath) => {
|
|
2667
|
+
const currKey = keyPath.join(".");
|
|
2668
|
+
if (FlowValueUtils.isFlowValue(value)) {
|
|
2669
|
+
if (FlowValueUtils.isRef(value)) {
|
|
2625
2670
|
const variable = available.getByKeyPath(value.content || []);
|
|
2626
2671
|
if (variable) {
|
|
2627
|
-
return renderVariable(variable,
|
|
2672
|
+
return renderVariable(variable, keyPath);
|
|
2628
2673
|
}
|
|
2629
2674
|
}
|
|
2630
2675
|
return {
|
|
2631
|
-
key,
|
|
2632
|
-
value:
|
|
2633
|
-
label:
|
|
2676
|
+
key: currKey,
|
|
2677
|
+
value: currKey,
|
|
2678
|
+
label: last2(keyPath)
|
|
2634
2679
|
};
|
|
2635
|
-
}
|
|
2680
|
+
}
|
|
2681
|
+
if (isPlainObject2(value)) {
|
|
2682
|
+
return {
|
|
2683
|
+
key: currKey,
|
|
2684
|
+
value: currKey,
|
|
2685
|
+
label: last2(keyPath),
|
|
2686
|
+
children: Object.entries(value).map(([key, value2]) => getTreeData(value2, [...keyPath, key])).filter(Boolean)
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
const treeData = useMemo9(
|
|
2691
|
+
() => Object.entries(inputsValues).map(([key, value]) => getTreeData(value, [key])).filter(Boolean),
|
|
2636
2692
|
[]
|
|
2637
2693
|
);
|
|
2638
2694
|
return /* @__PURE__ */ React28.createElement(Tree2, { treeData, onSelect: (v) => onSelect(v) });
|
|
@@ -2649,6 +2705,13 @@ function InputsTree({ inputsValues }) {
|
|
|
2649
2705
|
if (!range) {
|
|
2650
2706
|
return;
|
|
2651
2707
|
}
|
|
2708
|
+
let { from, to } = range;
|
|
2709
|
+
while (editor.$view.state.doc.sliceString(from - 1, from) === "{") {
|
|
2710
|
+
from--;
|
|
2711
|
+
}
|
|
2712
|
+
while (editor.$view.state.doc.sliceString(to, to + 1) === "}") {
|
|
2713
|
+
to++;
|
|
2714
|
+
}
|
|
2652
2715
|
editor.replaceText({
|
|
2653
2716
|
...range,
|
|
2654
2717
|
text: "{{" + variablePath + "}}"
|
|
@@ -2659,7 +2722,7 @@ function InputsTree({ inputsValues }) {
|
|
|
2659
2722
|
setPosition(e.state.selection.main.head);
|
|
2660
2723
|
setVisible(e.value);
|
|
2661
2724
|
}
|
|
2662
|
-
|
|
2725
|
+
useEffect8(() => {
|
|
2663
2726
|
if (!editor) {
|
|
2664
2727
|
return;
|
|
2665
2728
|
}
|
|
@@ -2701,7 +2764,7 @@ import React33 from "react";
|
|
|
2701
2764
|
import { transformerCreator } from "@coze-editor/editor/preset-code";
|
|
2702
2765
|
|
|
2703
2766
|
// src/components/json-editor-with-variables/extensions/variable-tree.tsx
|
|
2704
|
-
import React31, { useEffect as
|
|
2767
|
+
import React31, { useEffect as useEffect9, useState as useState8 } from "react";
|
|
2705
2768
|
import { Popover as Popover5, Tree as Tree3 } from "@douyinfe/semi-ui";
|
|
2706
2769
|
import {
|
|
2707
2770
|
Mention as Mention3,
|
|
@@ -2729,7 +2792,7 @@ function VariableTree2() {
|
|
|
2729
2792
|
setPosition(e.state.selection.main.head);
|
|
2730
2793
|
setVisible(e.value);
|
|
2731
2794
|
}
|
|
2732
|
-
|
|
2795
|
+
useEffect9(() => {
|
|
2733
2796
|
if (!editor) {
|
|
2734
2797
|
return;
|
|
2735
2798
|
}
|
|
@@ -2888,7 +2951,7 @@ function VariableTagInject2() {
|
|
|
2888
2951
|
const scope = useCurrentScope2();
|
|
2889
2952
|
useLayoutEffect5(() => {
|
|
2890
2953
|
const atMatcher = new MatchDecorator2({
|
|
2891
|
-
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2954
|
+
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
2892
2955
|
decoration: (match) => Decoration2.replace({
|
|
2893
2956
|
widget: new VariableTagWidget2({
|
|
2894
2957
|
keyPath: match[1]?.split(".") ?? [],
|
|
@@ -3035,7 +3098,20 @@ function InputsValues({
|
|
|
3035
3098
|
size: "small",
|
|
3036
3099
|
onClick: () => remove(item.id)
|
|
3037
3100
|
}
|
|
3038
|
-
)))), /* @__PURE__ */ React34.createElement(
|
|
3101
|
+
)))), /* @__PURE__ */ React34.createElement(
|
|
3102
|
+
Button4,
|
|
3103
|
+
{
|
|
3104
|
+
disabled: readonly,
|
|
3105
|
+
icon: /* @__PURE__ */ React34.createElement(IconPlus3, null),
|
|
3106
|
+
size: "small",
|
|
3107
|
+
onClick: () => add({
|
|
3108
|
+
type: "constant",
|
|
3109
|
+
content: "",
|
|
3110
|
+
schema: { type: "string" }
|
|
3111
|
+
})
|
|
3112
|
+
},
|
|
3113
|
+
I18n13.t("Add")
|
|
3114
|
+
));
|
|
3039
3115
|
}
|
|
3040
3116
|
|
|
3041
3117
|
// src/components/display-schema-tree/index.tsx
|
|
@@ -3145,7 +3221,7 @@ function SchemaTree(props) {
|
|
|
3145
3221
|
}
|
|
3146
3222
|
|
|
3147
3223
|
// src/components/display-outputs/index.tsx
|
|
3148
|
-
import React37, { useEffect as
|
|
3224
|
+
import React37, { useEffect as useEffect10 } from "react";
|
|
3149
3225
|
import { JsonSchemaUtils as JsonSchemaUtils6 } from "@flowgram.ai/json-schema";
|
|
3150
3226
|
import { useCurrentScope as useCurrentScope3, useRefresh } from "@flowgram.ai/editor";
|
|
3151
3227
|
|
|
@@ -3202,7 +3278,7 @@ var DisplayOutputsWrapper = styled13.div`
|
|
|
3202
3278
|
function DisplayOutputs({ value, showIconInTree, displayFromScope }) {
|
|
3203
3279
|
const scope = useCurrentScope3();
|
|
3204
3280
|
const refresh = useRefresh();
|
|
3205
|
-
|
|
3281
|
+
useEffect10(() => {
|
|
3206
3282
|
if (!displayFromScope) {
|
|
3207
3283
|
return () => null;
|
|
3208
3284
|
}
|
|
@@ -3248,18 +3324,7 @@ function DisplayFlowValue({ value, title, showIconInTree }) {
|
|
|
3248
3324
|
return { type: "string" };
|
|
3249
3325
|
}
|
|
3250
3326
|
if (value?.type === "constant") {
|
|
3251
|
-
|
|
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
|
-
}
|
|
3327
|
+
return FlowValueUtils.inferConstantJsonSchema(value);
|
|
3263
3328
|
}
|
|
3264
3329
|
return { type: "unknown" };
|
|
3265
3330
|
}, [value, variable?.hash]);
|
|
@@ -3275,7 +3340,9 @@ function DisplayFlowValue({ value, title, showIconInTree }) {
|
|
|
3275
3340
|
}
|
|
3276
3341
|
|
|
3277
3342
|
// src/components/display-inputs-values/index.tsx
|
|
3278
|
-
import React39 from "react";
|
|
3343
|
+
import React39, { useMemo as useMemo11 } from "react";
|
|
3344
|
+
import { isPlainObject as isPlainObject3 } from "lodash";
|
|
3345
|
+
import { useScopeAvailable as useScopeAvailable5 } from "@flowgram.ai/editor";
|
|
3279
3346
|
|
|
3280
3347
|
// src/components/display-inputs-values/styles.ts
|
|
3281
3348
|
import styled14 from "styled-components";
|
|
@@ -3288,7 +3355,35 @@ var DisplayInputsWrapper = styled14.div`
|
|
|
3288
3355
|
// src/components/display-inputs-values/index.tsx
|
|
3289
3356
|
function DisplayInputsValues({ value, showIconInTree }) {
|
|
3290
3357
|
const childEntries = Object.entries(value || {});
|
|
3291
|
-
return /* @__PURE__ */ React39.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) =>
|
|
3358
|
+
return /* @__PURE__ */ React39.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => {
|
|
3359
|
+
if (FlowValueUtils.isFlowValue(value2)) {
|
|
3360
|
+
return /* @__PURE__ */ React39.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree });
|
|
3361
|
+
}
|
|
3362
|
+
if (isPlainObject3(value2)) {
|
|
3363
|
+
return /* @__PURE__ */ React39.createElement(
|
|
3364
|
+
DisplayInputsValueAllInTag,
|
|
3365
|
+
{
|
|
3366
|
+
key,
|
|
3367
|
+
title: key,
|
|
3368
|
+
value: value2,
|
|
3369
|
+
showIconInTree
|
|
3370
|
+
}
|
|
3371
|
+
);
|
|
3372
|
+
}
|
|
3373
|
+
return null;
|
|
3374
|
+
}));
|
|
3375
|
+
}
|
|
3376
|
+
function DisplayInputsValueAllInTag({
|
|
3377
|
+
value,
|
|
3378
|
+
title,
|
|
3379
|
+
showIconInTree
|
|
3380
|
+
}) {
|
|
3381
|
+
const available = useScopeAvailable5();
|
|
3382
|
+
const schema = useMemo11(
|
|
3383
|
+
() => FlowValueUtils.inferJsonSchema(value, available.scope),
|
|
3384
|
+
[available.version, value]
|
|
3385
|
+
);
|
|
3386
|
+
return /* @__PURE__ */ React39.createElement(DisplaySchemaTag, { title, value: schema, showIconInTree });
|
|
3292
3387
|
}
|
|
3293
3388
|
|
|
3294
3389
|
// src/components/assign-rows/index.tsx
|
|
@@ -3303,11 +3398,11 @@ import { IconButton as IconButton5 } from "@douyinfe/semi-ui";
|
|
|
3303
3398
|
import { IconMinus as IconMinus2 } from "@douyinfe/semi-icons";
|
|
3304
3399
|
|
|
3305
3400
|
// src/components/assign-row/components/blur-input.tsx
|
|
3306
|
-
import React40, { useEffect as
|
|
3401
|
+
import React40, { useEffect as useEffect11, useState as useState9 } from "react";
|
|
3307
3402
|
import Input6 from "@douyinfe/semi-ui/lib/es/input";
|
|
3308
3403
|
function BlurInput2(props) {
|
|
3309
3404
|
const [value, setValue] = useState9("");
|
|
3310
|
-
|
|
3405
|
+
useEffect11(() => {
|
|
3311
3406
|
setValue(props.value);
|
|
3312
3407
|
}, [props.value]);
|
|
3313
3408
|
return /* @__PURE__ */ React40.createElement(
|
|
@@ -3523,17 +3618,17 @@ var iconAddChildrenSvg2 = /* @__PURE__ */ React43.createElement(
|
|
|
3523
3618
|
var IconAddChildren2 = () => /* @__PURE__ */ React43.createElement(Icon4, { size: "small", svg: iconAddChildrenSvg2 });
|
|
3524
3619
|
|
|
3525
3620
|
// src/components/inputs-values-tree/row.tsx
|
|
3526
|
-
import React44, { useState as useState10 } from "react";
|
|
3621
|
+
import React44, { useMemo as useMemo13, useState as useState10 } from "react";
|
|
3527
3622
|
import { I18n as I18n14 } from "@flowgram.ai/editor";
|
|
3528
3623
|
import { IconButton as IconButton6, Input as Input7 } from "@douyinfe/semi-ui";
|
|
3529
3624
|
import { IconChevronDown as IconChevronDown2, IconChevronRight as IconChevronRight2, IconDelete as IconDelete3 } from "@douyinfe/semi-icons";
|
|
3530
3625
|
|
|
3531
3626
|
// src/components/inputs-values-tree/hooks/use-child-list.tsx
|
|
3532
|
-
import { useMemo as
|
|
3533
|
-
import { isPlainObject as
|
|
3627
|
+
import { useMemo as useMemo12 } from "react";
|
|
3628
|
+
import { isPlainObject as isPlainObject4 } from "lodash";
|
|
3534
3629
|
function useChildList(value, onChange) {
|
|
3535
|
-
const canAddField =
|
|
3536
|
-
if (!
|
|
3630
|
+
const canAddField = useMemo12(() => {
|
|
3631
|
+
if (!isPlainObject4(value)) {
|
|
3537
3632
|
return false;
|
|
3538
3633
|
}
|
|
3539
3634
|
if (FlowValueUtils.isFlowValue(value)) {
|
|
@@ -3541,8 +3636,8 @@ function useChildList(value, onChange) {
|
|
|
3541
3636
|
}
|
|
3542
3637
|
return true;
|
|
3543
3638
|
}, [value]);
|
|
3544
|
-
const objectListValue =
|
|
3545
|
-
if (
|
|
3639
|
+
const objectListValue = useMemo12(() => {
|
|
3640
|
+
if (isPlainObject4(value)) {
|
|
3546
3641
|
if (FlowValueUtils.isFlowValue(value)) {
|
|
3547
3642
|
return void 0;
|
|
3548
3643
|
}
|
|
@@ -3550,7 +3645,6 @@ function useChildList(value, onChange) {
|
|
|
3550
3645
|
}
|
|
3551
3646
|
return void 0;
|
|
3552
3647
|
}, [value]);
|
|
3553
|
-
console.log("debugger objectListValue", objectListValue);
|
|
3554
3648
|
const { list, add, updateKey, updateValue, remove } = useObjectList({
|
|
3555
3649
|
value: objectListValue,
|
|
3556
3650
|
onChange: (value2) => {
|
|
@@ -3558,8 +3652,13 @@ function useChildList(value, onChange) {
|
|
|
3558
3652
|
},
|
|
3559
3653
|
sortIndexKey: (value2) => FlowValueUtils.isFlowValue(value2) ? "extra.index" : ""
|
|
3560
3654
|
});
|
|
3655
|
+
const hasChildren = useMemo12(
|
|
3656
|
+
() => canAddField && (list.length > 0 || Object.keys(objectListValue || {}).length > 0),
|
|
3657
|
+
[canAddField, list.length, Object.keys(objectListValue || {}).length]
|
|
3658
|
+
);
|
|
3561
3659
|
return {
|
|
3562
3660
|
canAddField,
|
|
3661
|
+
hasChildren,
|
|
3563
3662
|
list,
|
|
3564
3663
|
add,
|
|
3565
3664
|
updateKey,
|
|
@@ -3595,12 +3694,21 @@ function InputValueRow(props) {
|
|
|
3595
3694
|
readonly
|
|
3596
3695
|
} = props;
|
|
3597
3696
|
const [collapse, setCollapse] = useState10(false);
|
|
3598
|
-
const { canAddField, list, add, updateKey, updateValue, remove } = useChildList(
|
|
3697
|
+
const { canAddField, hasChildren, list, add, updateKey, updateValue, remove } = useChildList(
|
|
3599
3698
|
value,
|
|
3600
3699
|
onUpdateValue
|
|
3601
3700
|
);
|
|
3602
|
-
const
|
|
3603
|
-
|
|
3701
|
+
const strategies = useMemo13(
|
|
3702
|
+
() => [...hasChildren ? [AddObjectChildStrategy] : [], ...constantProps?.strategies || []],
|
|
3703
|
+
[hasChildren, constantProps?.strategies]
|
|
3704
|
+
);
|
|
3705
|
+
const flowDisplayValue = useMemo13(
|
|
3706
|
+
() => hasChildren ? {
|
|
3707
|
+
type: "constant",
|
|
3708
|
+
schema: { type: "object" }
|
|
3709
|
+
} : value,
|
|
3710
|
+
[hasChildren, value]
|
|
3711
|
+
);
|
|
3604
3712
|
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
3713
|
BlurInput,
|
|
3606
3714
|
{
|
|
@@ -3621,10 +3729,7 @@ function InputValueRow(props) {
|
|
|
3621
3729
|
hasError,
|
|
3622
3730
|
constantProps: {
|
|
3623
3731
|
...constantProps,
|
|
3624
|
-
strategies
|
|
3625
|
-
...hasChildren ? [AddObjectChildStrategy] : [],
|
|
3626
|
-
...constantProps?.strategies || []
|
|
3627
|
-
]
|
|
3732
|
+
strategies
|
|
3628
3733
|
}
|
|
3629
3734
|
}
|
|
3630
3735
|
), /* @__PURE__ */ React44.createElement(UIActions2, null, canAddField && /* @__PURE__ */ React44.createElement(
|
|
@@ -3635,7 +3740,11 @@ function InputValueRow(props) {
|
|
|
3635
3740
|
theme: "borderless",
|
|
3636
3741
|
icon: /* @__PURE__ */ React44.createElement(IconAddChildren2, null),
|
|
3637
3742
|
onClick: () => {
|
|
3638
|
-
add(
|
|
3743
|
+
add({
|
|
3744
|
+
type: "constant",
|
|
3745
|
+
content: "",
|
|
3746
|
+
schema: { type: "string" }
|
|
3747
|
+
});
|
|
3639
3748
|
setCollapse(true);
|
|
3640
3749
|
}
|
|
3641
3750
|
}
|
|
@@ -3700,7 +3809,13 @@ function InputsValuesTree(props) {
|
|
|
3700
3809
|
disabled: readonly,
|
|
3701
3810
|
icon: /* @__PURE__ */ React45.createElement(IconPlus5, null),
|
|
3702
3811
|
size: "small",
|
|
3703
|
-
onClick:
|
|
3812
|
+
onClick: () => {
|
|
3813
|
+
add({
|
|
3814
|
+
type: "constant",
|
|
3815
|
+
content: "",
|
|
3816
|
+
schema: { type: "string" }
|
|
3817
|
+
});
|
|
3818
|
+
}
|
|
3704
3819
|
},
|
|
3705
3820
|
I18n15.t("Add")
|
|
3706
3821
|
));
|
|
@@ -4083,7 +4198,7 @@ var createInferAssignPlugin = defineFormPluginCreator3({
|
|
|
4083
4198
|
});
|
|
4084
4199
|
|
|
4085
4200
|
// src/validate/validate-flow-value/index.tsx
|
|
4086
|
-
import { isNil
|
|
4201
|
+
import { isNil } from "lodash";
|
|
4087
4202
|
import { FeedbackLevel, getNodeScope as getNodeScope7 } from "@flowgram.ai/editor";
|
|
4088
4203
|
function validateFlowValue(value, ctx) {
|
|
4089
4204
|
const { node, required, errorMessages } = ctx;
|
|
@@ -4107,7 +4222,7 @@ function validateFlowValue(value, ctx) {
|
|
|
4107
4222
|
}
|
|
4108
4223
|
}
|
|
4109
4224
|
if (value?.type === "template") {
|
|
4110
|
-
const allRefs = getTemplateKeyPaths(value);
|
|
4225
|
+
const allRefs = FlowValueUtils.getTemplateKeyPaths(value);
|
|
4111
4226
|
for (const ref of allRefs) {
|
|
4112
4227
|
const variable = getNodeScope7(node).available.getByKeyPath(ref);
|
|
4113
4228
|
if (!variable) {
|
|
@@ -4120,12 +4235,6 @@ function validateFlowValue(value, ctx) {
|
|
|
4120
4235
|
}
|
|
4121
4236
|
return void 0;
|
|
4122
4237
|
}
|
|
4123
|
-
function getTemplateKeyPaths(value) {
|
|
4124
|
-
const keyPathReg = /{{(.*?)}}/g;
|
|
4125
|
-
return uniq2(value.content?.match(keyPathReg) || []).map(
|
|
4126
|
-
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
4127
|
-
);
|
|
4128
|
-
}
|
|
4129
4238
|
export {
|
|
4130
4239
|
AssignRow,
|
|
4131
4240
|
AssignRows,
|
|
@@ -4137,6 +4246,7 @@ export {
|
|
|
4137
4246
|
ConditionRow,
|
|
4138
4247
|
ConstantInput,
|
|
4139
4248
|
DisplayFlowValue,
|
|
4249
|
+
DisplayInputsValueAllInTag,
|
|
4140
4250
|
DisplayInputsValues,
|
|
4141
4251
|
DisplayOutputs,
|
|
4142
4252
|
DisplaySchemaTag,
|
|
@@ -4178,6 +4288,7 @@ export {
|
|
|
4178
4288
|
provideBatchOutputsEffect,
|
|
4179
4289
|
provideJsonSchemaOutputs,
|
|
4180
4290
|
syncVariableTitle,
|
|
4291
|
+
useObjectList,
|
|
4181
4292
|
useTypeManager,
|
|
4182
4293
|
useVariableTree,
|
|
4183
4294
|
validateFlowValue,
|