@flowgram.ai/form-materials 0.4.2 → 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 +105 -41
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +95 -33
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/dynamic-value-input/index.tsx +20 -11
- package/src/components/inputs-values/index.tsx +12 -1
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +1 -1
- package/src/components/inputs-values-tree/index.tsx +7 -1
- package/src/components/inputs-values-tree/row.tsx +5 -1
- 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/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
|
@@ -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
|
|
|
@@ -1651,6 +1666,11 @@ function useIncludeSchema(schemaFromProps) {
|
|
|
1651
1666
|
}
|
|
1652
1667
|
|
|
1653
1668
|
// src/components/dynamic-value-input/index.tsx
|
|
1669
|
+
var DEFAULT_VALUE = {
|
|
1670
|
+
type: "constant",
|
|
1671
|
+
content: "",
|
|
1672
|
+
schema: { type: "string" }
|
|
1673
|
+
};
|
|
1654
1674
|
function DynamicValueInput({
|
|
1655
1675
|
value,
|
|
1656
1676
|
onChange,
|
|
@@ -1662,6 +1682,7 @@ function DynamicValueInput({
|
|
|
1662
1682
|
const refVariable = useRefVariable(value);
|
|
1663
1683
|
const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
|
|
1664
1684
|
const includeSchema = useIncludeSchema(schemaFromProps);
|
|
1685
|
+
const typeManager = useTypeManager3();
|
|
1665
1686
|
const renderTypeSelector = () => {
|
|
1666
1687
|
if (schemaFromProps) {
|
|
1667
1688
|
return /* @__PURE__ */ React20.createElement(TypeSelector, { value: schemaFromProps, readonly: true });
|
|
@@ -1676,20 +1697,18 @@ function DynamicValueInput({
|
|
|
1676
1697
|
value: selectSchema,
|
|
1677
1698
|
onChange: (_v) => {
|
|
1678
1699
|
setSelectSchema(_v || { type: "string" });
|
|
1679
|
-
|
|
1700
|
+
const schema = _v || { type: "string" };
|
|
1701
|
+
let content = typeManager.getDefaultValue(schema);
|
|
1680
1702
|
if (_v?.type === "object") {
|
|
1681
1703
|
content = "{}";
|
|
1682
1704
|
}
|
|
1683
1705
|
if (_v?.type === "array") {
|
|
1684
1706
|
content = "[]";
|
|
1685
1707
|
}
|
|
1686
|
-
if (_v?.type === "boolean") {
|
|
1687
|
-
content = false;
|
|
1688
|
-
}
|
|
1689
1708
|
onChange({
|
|
1690
1709
|
type: "constant",
|
|
1691
1710
|
content,
|
|
1692
|
-
schema
|
|
1711
|
+
schema
|
|
1693
1712
|
});
|
|
1694
1713
|
},
|
|
1695
1714
|
readonly
|
|
@@ -1703,7 +1722,7 @@ function DynamicValueInput({
|
|
|
1703
1722
|
{
|
|
1704
1723
|
style: { width: "100%" },
|
|
1705
1724
|
value: value?.content,
|
|
1706
|
-
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } :
|
|
1725
|
+
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : DEFAULT_VALUE),
|
|
1707
1726
|
includeSchema,
|
|
1708
1727
|
readonly
|
|
1709
1728
|
}
|
|
@@ -1721,7 +1740,7 @@ function DynamicValueInput({
|
|
|
1721
1740
|
InjectVariableSelector,
|
|
1722
1741
|
{
|
|
1723
1742
|
style: { width: "100%" },
|
|
1724
|
-
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } :
|
|
1743
|
+
onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : DEFAULT_VALUE),
|
|
1725
1744
|
includeSchema,
|
|
1726
1745
|
readonly
|
|
1727
1746
|
}
|
|
@@ -2367,8 +2386,16 @@ function VariableTree() {
|
|
|
2367
2386
|
if (!range) {
|
|
2368
2387
|
return;
|
|
2369
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
|
+
}
|
|
2370
2396
|
editor.replaceText({
|
|
2371
|
-
|
|
2397
|
+
from,
|
|
2398
|
+
to,
|
|
2372
2399
|
text: "{{" + variablePath + "}}"
|
|
2373
2400
|
});
|
|
2374
2401
|
setVisible(false);
|
|
@@ -2540,7 +2567,7 @@ function VariableTagInject() {
|
|
|
2540
2567
|
const scope = useCurrentScope();
|
|
2541
2568
|
useLayoutEffect4(() => {
|
|
2542
2569
|
const atMatcher = new MatchDecorator({
|
|
2543
|
-
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2570
|
+
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
2544
2571
|
decoration: (match) => Decoration.replace({
|
|
2545
2572
|
widget: new VariableTagWidget({
|
|
2546
2573
|
keyPath: match[1]?.split(".") ?? [],
|
|
@@ -2593,7 +2620,7 @@ import {
|
|
|
2593
2620
|
|
|
2594
2621
|
// src/components/prompt-editor-with-inputs/inputs-picker.tsx
|
|
2595
2622
|
import React28, { useMemo as useMemo9 } from "react";
|
|
2596
|
-
import { last as last2 } from "lodash";
|
|
2623
|
+
import { isPlainObject as isPlainObject2, last as last2 } from "lodash";
|
|
2597
2624
|
import {
|
|
2598
2625
|
ASTMatch as ASTMatch3,
|
|
2599
2626
|
useScopeAvailable as useScopeAvailable3
|
|
@@ -2636,20 +2663,32 @@ function InputsPicker({
|
|
|
2636
2663
|
children
|
|
2637
2664
|
};
|
|
2638
2665
|
};
|
|
2639
|
-
const
|
|
2640
|
-
|
|
2641
|
-
|
|
2666
|
+
const getTreeData = (value, keyPath) => {
|
|
2667
|
+
const currKey = keyPath.join(".");
|
|
2668
|
+
if (FlowValueUtils.isFlowValue(value)) {
|
|
2669
|
+
if (FlowValueUtils.isRef(value)) {
|
|
2642
2670
|
const variable = available.getByKeyPath(value.content || []);
|
|
2643
2671
|
if (variable) {
|
|
2644
|
-
return renderVariable(variable,
|
|
2672
|
+
return renderVariable(variable, keyPath);
|
|
2645
2673
|
}
|
|
2646
2674
|
}
|
|
2647
2675
|
return {
|
|
2648
|
-
key,
|
|
2649
|
-
value:
|
|
2650
|
-
label:
|
|
2676
|
+
key: currKey,
|
|
2677
|
+
value: currKey,
|
|
2678
|
+
label: last2(keyPath)
|
|
2651
2679
|
};
|
|
2652
|
-
}
|
|
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),
|
|
2653
2692
|
[]
|
|
2654
2693
|
);
|
|
2655
2694
|
return /* @__PURE__ */ React28.createElement(Tree2, { treeData, onSelect: (v) => onSelect(v) });
|
|
@@ -2666,6 +2705,13 @@ function InputsTree({ inputsValues }) {
|
|
|
2666
2705
|
if (!range) {
|
|
2667
2706
|
return;
|
|
2668
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
|
+
}
|
|
2669
2715
|
editor.replaceText({
|
|
2670
2716
|
...range,
|
|
2671
2717
|
text: "{{" + variablePath + "}}"
|
|
@@ -2905,7 +2951,7 @@ function VariableTagInject2() {
|
|
|
2905
2951
|
const scope = useCurrentScope2();
|
|
2906
2952
|
useLayoutEffect5(() => {
|
|
2907
2953
|
const atMatcher = new MatchDecorator2({
|
|
2908
|
-
regexp: /\{\{([^\}]+)\}\}/g,
|
|
2954
|
+
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
2909
2955
|
decoration: (match) => Decoration2.replace({
|
|
2910
2956
|
widget: new VariableTagWidget2({
|
|
2911
2957
|
keyPath: match[1]?.split(".") ?? [],
|
|
@@ -3052,7 +3098,20 @@ function InputsValues({
|
|
|
3052
3098
|
size: "small",
|
|
3053
3099
|
onClick: () => remove(item.id)
|
|
3054
3100
|
}
|
|
3055
|
-
)))), /* @__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
|
+
));
|
|
3056
3115
|
}
|
|
3057
3116
|
|
|
3058
3117
|
// src/components/display-schema-tree/index.tsx
|
|
@@ -3282,7 +3341,7 @@ function DisplayFlowValue({ value, title, showIconInTree }) {
|
|
|
3282
3341
|
|
|
3283
3342
|
// src/components/display-inputs-values/index.tsx
|
|
3284
3343
|
import React39, { useMemo as useMemo11 } from "react";
|
|
3285
|
-
import { isPlainObject as
|
|
3344
|
+
import { isPlainObject as isPlainObject3 } from "lodash";
|
|
3286
3345
|
import { useScopeAvailable as useScopeAvailable5 } from "@flowgram.ai/editor";
|
|
3287
3346
|
|
|
3288
3347
|
// src/components/display-inputs-values/styles.ts
|
|
@@ -3300,7 +3359,7 @@ function DisplayInputsValues({ value, showIconInTree }) {
|
|
|
3300
3359
|
if (FlowValueUtils.isFlowValue(value2)) {
|
|
3301
3360
|
return /* @__PURE__ */ React39.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree });
|
|
3302
3361
|
}
|
|
3303
|
-
if (
|
|
3362
|
+
if (isPlainObject3(value2)) {
|
|
3304
3363
|
return /* @__PURE__ */ React39.createElement(
|
|
3305
3364
|
DisplayInputsValueAllInTag,
|
|
3306
3365
|
{
|
|
@@ -3566,10 +3625,10 @@ import { IconChevronDown as IconChevronDown2, IconChevronRight as IconChevronRig
|
|
|
3566
3625
|
|
|
3567
3626
|
// src/components/inputs-values-tree/hooks/use-child-list.tsx
|
|
3568
3627
|
import { useMemo as useMemo12 } from "react";
|
|
3569
|
-
import { isPlainObject as
|
|
3628
|
+
import { isPlainObject as isPlainObject4 } from "lodash";
|
|
3570
3629
|
function useChildList(value, onChange) {
|
|
3571
3630
|
const canAddField = useMemo12(() => {
|
|
3572
|
-
if (!
|
|
3631
|
+
if (!isPlainObject4(value)) {
|
|
3573
3632
|
return false;
|
|
3574
3633
|
}
|
|
3575
3634
|
if (FlowValueUtils.isFlowValue(value)) {
|
|
@@ -3578,7 +3637,7 @@ function useChildList(value, onChange) {
|
|
|
3578
3637
|
return true;
|
|
3579
3638
|
}, [value]);
|
|
3580
3639
|
const objectListValue = useMemo12(() => {
|
|
3581
|
-
if (
|
|
3640
|
+
if (isPlainObject4(value)) {
|
|
3582
3641
|
if (FlowValueUtils.isFlowValue(value)) {
|
|
3583
3642
|
return void 0;
|
|
3584
3643
|
}
|
|
@@ -3681,7 +3740,11 @@ function InputValueRow(props) {
|
|
|
3681
3740
|
theme: "borderless",
|
|
3682
3741
|
icon: /* @__PURE__ */ React44.createElement(IconAddChildren2, null),
|
|
3683
3742
|
onClick: () => {
|
|
3684
|
-
add(
|
|
3743
|
+
add({
|
|
3744
|
+
type: "constant",
|
|
3745
|
+
content: "",
|
|
3746
|
+
schema: { type: "string" }
|
|
3747
|
+
});
|
|
3685
3748
|
setCollapse(true);
|
|
3686
3749
|
}
|
|
3687
3750
|
}
|
|
@@ -3746,7 +3809,13 @@ function InputsValuesTree(props) {
|
|
|
3746
3809
|
disabled: readonly,
|
|
3747
3810
|
icon: /* @__PURE__ */ React45.createElement(IconPlus5, null),
|
|
3748
3811
|
size: "small",
|
|
3749
|
-
onClick:
|
|
3812
|
+
onClick: () => {
|
|
3813
|
+
add({
|
|
3814
|
+
type: "constant",
|
|
3815
|
+
content: "",
|
|
3816
|
+
schema: { type: "string" }
|
|
3817
|
+
});
|
|
3818
|
+
}
|
|
3750
3819
|
},
|
|
3751
3820
|
I18n15.t("Add")
|
|
3752
3821
|
));
|
|
@@ -4129,7 +4198,7 @@ var createInferAssignPlugin = defineFormPluginCreator3({
|
|
|
4129
4198
|
});
|
|
4130
4199
|
|
|
4131
4200
|
// src/validate/validate-flow-value/index.tsx
|
|
4132
|
-
import { isNil
|
|
4201
|
+
import { isNil } from "lodash";
|
|
4133
4202
|
import { FeedbackLevel, getNodeScope as getNodeScope7 } from "@flowgram.ai/editor";
|
|
4134
4203
|
function validateFlowValue(value, ctx) {
|
|
4135
4204
|
const { node, required, errorMessages } = ctx;
|
|
@@ -4153,7 +4222,7 @@ function validateFlowValue(value, ctx) {
|
|
|
4153
4222
|
}
|
|
4154
4223
|
}
|
|
4155
4224
|
if (value?.type === "template") {
|
|
4156
|
-
const allRefs = getTemplateKeyPaths(value);
|
|
4225
|
+
const allRefs = FlowValueUtils.getTemplateKeyPaths(value);
|
|
4157
4226
|
for (const ref of allRefs) {
|
|
4158
4227
|
const variable = getNodeScope7(node).available.getByKeyPath(ref);
|
|
4159
4228
|
if (!variable) {
|
|
@@ -4166,12 +4235,6 @@ function validateFlowValue(value, ctx) {
|
|
|
4166
4235
|
}
|
|
4167
4236
|
return void 0;
|
|
4168
4237
|
}
|
|
4169
|
-
function getTemplateKeyPaths(value) {
|
|
4170
|
-
const keyPathReg = /{{(.*?)}}/g;
|
|
4171
|
-
return uniq2(value.content?.match(keyPathReg) || []).map(
|
|
4172
|
-
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
4173
|
-
);
|
|
4174
|
-
}
|
|
4175
4238
|
export {
|
|
4176
4239
|
AssignRow,
|
|
4177
4240
|
AssignRows,
|
|
@@ -4225,6 +4288,7 @@ export {
|
|
|
4225
4288
|
provideBatchOutputsEffect,
|
|
4226
4289
|
provideJsonSchemaOutputs,
|
|
4227
4290
|
syncVariableTitle,
|
|
4291
|
+
useObjectList,
|
|
4228
4292
|
useTypeManager,
|
|
4229
4293
|
useVariableTree,
|
|
4230
4294
|
validateFlowValue,
|