@flowgram.ai/form-materials 0.3.3 → 0.3.4
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 +61 -30
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +14 -18
- package/dist/index.d.ts +14 -18
- package/dist/index.js +164 -133
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/condition-row/constants.ts +2 -2
- package/src/components/condition-row/hooks/useOp.tsx +13 -9
- package/src/components/condition-row/hooks/useRule.ts +6 -3
- package/src/components/condition-row/index.tsx +22 -6
- package/src/components/condition-row/types.ts +4 -6
- package/src/components/json-schema-editor/index.tsx +7 -4
- package/src/components/type-selector/index.tsx +2 -4
- package/src/components/variable-selector/index.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +7 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/components/variable-selector/index.tsx
|
|
2
2
|
import React11, { useMemo } from "react";
|
|
3
|
+
import { I18n as I18n7 } from "@flowgram.ai/editor";
|
|
3
4
|
import { Popover } from "@douyinfe/semi-ui";
|
|
4
5
|
import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
|
|
5
6
|
|
|
@@ -22,14 +23,24 @@ import { jsonSchemaTypeManager } from "@flowgram.ai/json-schema";
|
|
|
22
23
|
|
|
23
24
|
// src/plugins/json-schema-preset/type-definition/string.tsx
|
|
24
25
|
import React from "react";
|
|
26
|
+
import { I18n } from "@flowgram.ai/editor";
|
|
25
27
|
import { Input } from "@douyinfe/semi-ui";
|
|
26
28
|
var stringRegistry = {
|
|
27
29
|
type: "string",
|
|
28
|
-
ConstantRenderer: (props) => /* @__PURE__ */ React.createElement(
|
|
30
|
+
ConstantRenderer: (props) => /* @__PURE__ */ React.createElement(
|
|
31
|
+
Input,
|
|
32
|
+
{
|
|
33
|
+
placeholder: I18n.t("Please Input String"),
|
|
34
|
+
size: "small",
|
|
35
|
+
disabled: props.readonly,
|
|
36
|
+
...props
|
|
37
|
+
}
|
|
38
|
+
)
|
|
29
39
|
};
|
|
30
40
|
|
|
31
41
|
// src/plugins/json-schema-preset/type-definition/object.tsx
|
|
32
42
|
import React4 from "react";
|
|
43
|
+
import { I18n as I18n2 } from "@flowgram.ai/editor";
|
|
33
44
|
|
|
34
45
|
// src/components/code-editor-mini/index.tsx
|
|
35
46
|
import React3 from "react";
|
|
@@ -409,7 +420,7 @@ var objectRegistry = {
|
|
|
409
420
|
value: props.value,
|
|
410
421
|
onChange: (v) => props.onChange?.(v),
|
|
411
422
|
languageId: "json",
|
|
412
|
-
placeholder: "Please Input Object",
|
|
423
|
+
placeholder: I18n2.t("Please Input Object"),
|
|
413
424
|
readonly: props.readonly
|
|
414
425
|
}
|
|
415
426
|
)
|
|
@@ -417,13 +428,14 @@ var objectRegistry = {
|
|
|
417
428
|
|
|
418
429
|
// src/plugins/json-schema-preset/type-definition/number.tsx
|
|
419
430
|
import React5 from "react";
|
|
431
|
+
import { I18n as I18n3 } from "@flowgram.ai/editor";
|
|
420
432
|
import { InputNumber } from "@douyinfe/semi-ui";
|
|
421
433
|
var numberRegistry = {
|
|
422
434
|
type: "number",
|
|
423
435
|
ConstantRenderer: (props) => /* @__PURE__ */ React5.createElement(
|
|
424
436
|
InputNumber,
|
|
425
437
|
{
|
|
426
|
-
placeholder: "Please Input Number",
|
|
438
|
+
placeholder: I18n3.t("Please Input Number"),
|
|
427
439
|
size: "small",
|
|
428
440
|
disabled: props.readonly,
|
|
429
441
|
hideButtons: true,
|
|
@@ -434,13 +446,14 @@ var numberRegistry = {
|
|
|
434
446
|
|
|
435
447
|
// src/plugins/json-schema-preset/type-definition/integer.tsx
|
|
436
448
|
import React6 from "react";
|
|
449
|
+
import { I18n as I18n4 } from "@flowgram.ai/editor";
|
|
437
450
|
import { InputNumber as InputNumber2 } from "@douyinfe/semi-ui";
|
|
438
451
|
var integerRegistry = {
|
|
439
452
|
type: "integer",
|
|
440
453
|
ConstantRenderer: (props) => /* @__PURE__ */ React6.createElement(
|
|
441
454
|
InputNumber2,
|
|
442
455
|
{
|
|
443
|
-
placeholder: "Please Input Integer",
|
|
456
|
+
placeholder: I18n4.t("Please Input Integer"),
|
|
444
457
|
size: "small",
|
|
445
458
|
disabled: props.readonly,
|
|
446
459
|
precision: 0,
|
|
@@ -451,6 +464,7 @@ var integerRegistry = {
|
|
|
451
464
|
|
|
452
465
|
// src/plugins/json-schema-preset/type-definition/boolean.tsx
|
|
453
466
|
import React7 from "react";
|
|
467
|
+
import { I18n as I18n5 } from "@flowgram.ai/editor";
|
|
454
468
|
import { Select } from "@douyinfe/semi-ui";
|
|
455
469
|
var booleanRegistry = {
|
|
456
470
|
type: "boolean",
|
|
@@ -459,12 +473,12 @@ var booleanRegistry = {
|
|
|
459
473
|
return /* @__PURE__ */ React7.createElement(
|
|
460
474
|
Select,
|
|
461
475
|
{
|
|
462
|
-
placeholder: "Please Select Boolean",
|
|
476
|
+
placeholder: I18n5.t("Please Select Boolean"),
|
|
463
477
|
size: "small",
|
|
464
478
|
disabled: props.readonly,
|
|
465
479
|
optionList: [
|
|
466
|
-
{ label: "True", value: 1 },
|
|
467
|
-
{ label: "False", value: 0 }
|
|
480
|
+
{ label: I18n5.t("True"), value: 1 },
|
|
481
|
+
{ label: I18n5.t("False"), value: 0 }
|
|
468
482
|
],
|
|
469
483
|
value: value ? 1 : 0,
|
|
470
484
|
onChange: (value2) => onChange?.(!!value2),
|
|
@@ -476,6 +490,7 @@ var booleanRegistry = {
|
|
|
476
490
|
|
|
477
491
|
// src/plugins/json-schema-preset/type-definition/array.tsx
|
|
478
492
|
import React8 from "react";
|
|
493
|
+
import { I18n as I18n6 } from "@flowgram.ai/editor";
|
|
479
494
|
var arrayRegistry = {
|
|
480
495
|
type: "array",
|
|
481
496
|
ConstantRenderer: (props) => /* @__PURE__ */ React8.createElement(
|
|
@@ -484,7 +499,7 @@ var arrayRegistry = {
|
|
|
484
499
|
value: props.value,
|
|
485
500
|
languageId: "json",
|
|
486
501
|
onChange: (v) => props.onChange?.(v),
|
|
487
|
-
placeholder: "Please Input Array",
|
|
502
|
+
placeholder: I18n6.t("Please Input Array"),
|
|
488
503
|
readonly: props.readonly
|
|
489
504
|
}
|
|
490
505
|
)
|
|
@@ -735,7 +750,7 @@ var VariableSelector = ({
|
|
|
735
750
|
showClear: false,
|
|
736
751
|
arrowIcon: /* @__PURE__ */ React11.createElement(IconChevronDownStroked, { size: "small" }),
|
|
737
752
|
triggerRender,
|
|
738
|
-
placeholder: config?.placeholder ?? "Select Variable"
|
|
753
|
+
placeholder: config?.placeholder ?? I18n7.t("Select Variable")
|
|
739
754
|
}
|
|
740
755
|
));
|
|
741
756
|
};
|
|
@@ -744,7 +759,6 @@ var VariableSelector = ({
|
|
|
744
759
|
import React12, { useMemo as useMemo2 } from "react";
|
|
745
760
|
import { Cascader, Icon as Icon2, IconButton } from "@douyinfe/semi-ui";
|
|
746
761
|
var labelStyle = { display: "flex", alignItems: "center", gap: 5 };
|
|
747
|
-
var firstUppercase = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
748
762
|
var getTypeSelectValue = (value) => {
|
|
749
763
|
if (value?.type === "array" && value?.items) {
|
|
750
764
|
return [value.type, ...getTypeSelectValue(value.items) || []];
|
|
@@ -767,7 +781,7 @@ function TypeSelector(props) {
|
|
|
767
781
|
() => typeManager.getTypeRegistriesWithParentType().map((_type) => {
|
|
768
782
|
const isArray2 = _type.type === "array";
|
|
769
783
|
return {
|
|
770
|
-
label: /* @__PURE__ */ React12.createElement("div", { style: labelStyle }, /* @__PURE__ */ React12.createElement(Icon2, { size: "small", svg: _type.icon }),
|
|
784
|
+
label: /* @__PURE__ */ React12.createElement("div", { style: labelStyle }, /* @__PURE__ */ React12.createElement(Icon2, { size: "small", svg: _type.icon }), typeManager.getTypeBySchema(_type)?.label || _type.type),
|
|
771
785
|
value: _type.type,
|
|
772
786
|
children: isArray2 ? typeManager.getTypeRegistriesWithParentType("array").map((_type2) => ({
|
|
773
787
|
label: /* @__PURE__ */ React12.createElement("div", { style: labelStyle }, /* @__PURE__ */ React12.createElement(
|
|
@@ -779,7 +793,7 @@ function TypeSelector(props) {
|
|
|
779
793
|
items: { type: _type2.type }
|
|
780
794
|
})
|
|
781
795
|
}
|
|
782
|
-
),
|
|
796
|
+
), typeManager.getTypeBySchema(_type2)?.label || _type2.type),
|
|
783
797
|
value: _type2.type
|
|
784
798
|
})) : []
|
|
785
799
|
};
|
|
@@ -804,6 +818,7 @@ function TypeSelector(props) {
|
|
|
804
818
|
|
|
805
819
|
// src/components/json-schema-editor/index.tsx
|
|
806
820
|
import React17, { useMemo as useMemo5, useState as useState4 } from "react";
|
|
821
|
+
import { I18n as I18n8 } from "@flowgram.ai/editor";
|
|
807
822
|
import { Button, Checkbox, IconButton as IconButton3 } from "@douyinfe/semi-ui";
|
|
808
823
|
import {
|
|
809
824
|
IconExpand,
|
|
@@ -1418,22 +1433,22 @@ function PropertyEdit(props) {
|
|
|
1418
1433
|
onClick: onRemove
|
|
1419
1434
|
}
|
|
1420
1435
|
))),
|
|
1421
|
-
expand && /* @__PURE__ */ React17.createElement(UIExpandDetail, null, /* @__PURE__ */ React17.createElement(UILabel, null, config?.descTitle ?? "Description"), /* @__PURE__ */ React17.createElement(
|
|
1436
|
+
expand && /* @__PURE__ */ React17.createElement(UIExpandDetail, null, /* @__PURE__ */ React17.createElement(UILabel, null, config?.descTitle ?? I18n8.t("Description")), /* @__PURE__ */ React17.createElement(
|
|
1422
1437
|
BlurInput,
|
|
1423
1438
|
{
|
|
1424
1439
|
disabled: readonly,
|
|
1425
1440
|
size: "small",
|
|
1426
1441
|
value: description,
|
|
1427
1442
|
onChange: (value2) => onChange("description", value2),
|
|
1428
|
-
placeholder: config?.descPlaceholder ?? "Help LLM to understand the property"
|
|
1443
|
+
placeholder: config?.descPlaceholder ?? I18n8.t("Help LLM to understand the property")
|
|
1429
1444
|
}
|
|
1430
|
-
), $level === 0 && type && type !== "array" && /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(UILabel, { style: { marginTop: 10 } }, config?.defaultValueTitle ?? "Default Value"), /* @__PURE__ */ React17.createElement(DefaultValueWrapper, null, /* @__PURE__ */ React17.createElement(
|
|
1445
|
+
), $level === 0 && type && type !== "array" && /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(UILabel, { style: { marginTop: 10 } }, config?.defaultValueTitle ?? I18n8.t("Default Value")), /* @__PURE__ */ React17.createElement(DefaultValueWrapper, null, /* @__PURE__ */ React17.createElement(
|
|
1431
1446
|
DefaultValue,
|
|
1432
1447
|
{
|
|
1433
1448
|
value: defaultValue,
|
|
1434
1449
|
schema: value,
|
|
1435
1450
|
type,
|
|
1436
|
-
placeholder: config?.defaultValuePlaceholder,
|
|
1451
|
+
placeholder: config?.defaultValuePlaceholder ?? I18n8.t("Default Value"),
|
|
1437
1452
|
jsonFormatText: config?.jsonFormatText,
|
|
1438
1453
|
onChange: (value2) => onChange("default", value2)
|
|
1439
1454
|
}
|
|
@@ -1654,6 +1669,7 @@ function DynamicValueInput({
|
|
|
1654
1669
|
|
|
1655
1670
|
// src/components/condition-row/index.tsx
|
|
1656
1671
|
import React21, { useMemo as useMemo9 } from "react";
|
|
1672
|
+
import { I18n as I18n10 } from "@flowgram.ai/editor";
|
|
1657
1673
|
import { Input as Input4 } from "@douyinfe/semi-ui";
|
|
1658
1674
|
|
|
1659
1675
|
// src/components/condition-row/styles.tsx
|
|
@@ -1684,7 +1700,7 @@ import { JsonSchemaUtils as JsonSchemaUtils4 } from "@flowgram.ai/json-schema";
|
|
|
1684
1700
|
import { useScopeAvailable as useScopeAvailable2 } from "@flowgram.ai/editor";
|
|
1685
1701
|
|
|
1686
1702
|
// src/components/condition-row/constants.ts
|
|
1687
|
-
var
|
|
1703
|
+
var defaultRules = {
|
|
1688
1704
|
string: {
|
|
1689
1705
|
["eq" /* EQ */]: "string",
|
|
1690
1706
|
["neq" /* NEQ */]: "string",
|
|
@@ -1740,7 +1756,7 @@ var rules = {
|
|
|
1740
1756
|
["is_not_empty" /* IS_NOT_EMPTY */]: null
|
|
1741
1757
|
}
|
|
1742
1758
|
};
|
|
1743
|
-
var
|
|
1759
|
+
var defaultOpConfigs = {
|
|
1744
1760
|
["eq" /* EQ */]: {
|
|
1745
1761
|
label: "Equal",
|
|
1746
1762
|
abbreviation: "="
|
|
@@ -1804,8 +1820,9 @@ var opConfigs = {
|
|
|
1804
1820
|
};
|
|
1805
1821
|
|
|
1806
1822
|
// src/components/condition-row/hooks/useRule.ts
|
|
1807
|
-
function useRule(left) {
|
|
1823
|
+
function useRule(left, userRules) {
|
|
1808
1824
|
const available = useScopeAvailable2();
|
|
1825
|
+
const rules = useMemo7(() => ({ ...defaultRules, ...userRules || {} }), [userRules]);
|
|
1809
1826
|
const variable = useMemo7(() => {
|
|
1810
1827
|
if (!left) return void 0;
|
|
1811
1828
|
return available.getByKeyPath(left.content);
|
|
@@ -1814,23 +1831,26 @@ function useRule(left) {
|
|
|
1814
1831
|
if (!variable) return void 0;
|
|
1815
1832
|
const schema = JsonSchemaUtils4.astToSchema(variable.type, { drilldown: false });
|
|
1816
1833
|
return rules[schema?.type];
|
|
1817
|
-
}, [variable?.type]);
|
|
1834
|
+
}, [variable?.type, rules]);
|
|
1818
1835
|
return { rule };
|
|
1819
1836
|
}
|
|
1820
1837
|
|
|
1821
1838
|
// src/components/condition-row/hooks/useOp.tsx
|
|
1822
1839
|
import React20, { useMemo as useMemo8 } from "react";
|
|
1840
|
+
import { I18n as I18n9 } from "@flowgram.ai/editor";
|
|
1823
1841
|
import { Button as Button2, Select as Select2 } from "@douyinfe/semi-ui";
|
|
1824
1842
|
import { IconChevronDownStroked as IconChevronDownStroked2 } from "@douyinfe/semi-icons";
|
|
1825
|
-
function useOp({ rule, op, onChange, readonly }) {
|
|
1843
|
+
function useOp({ rule, op, onChange, readonly, userOps }) {
|
|
1826
1844
|
const options = useMemo8(
|
|
1827
1845
|
() => Object.keys(rule || {}).map((_op) => ({
|
|
1828
|
-
...
|
|
1829
|
-
|
|
1846
|
+
...defaultOpConfigs[_op] || {},
|
|
1847
|
+
...userOps?.[_op] || {},
|
|
1848
|
+
value: _op,
|
|
1849
|
+
label: I18n9.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label)
|
|
1830
1850
|
})),
|
|
1831
|
-
[rule]
|
|
1851
|
+
[rule, userOps]
|
|
1832
1852
|
);
|
|
1833
|
-
const opConfig = useMemo8(() =>
|
|
1853
|
+
const opConfig = useMemo8(() => defaultOpConfigs[op], [op]);
|
|
1834
1854
|
const renderOpSelect = () => /* @__PURE__ */ React20.createElement(
|
|
1835
1855
|
Select2,
|
|
1836
1856
|
{
|
|
@@ -1849,17 +1869,28 @@ function useOp({ rule, op, onChange, readonly }) {
|
|
|
1849
1869
|
}
|
|
1850
1870
|
|
|
1851
1871
|
// src/components/condition-row/index.tsx
|
|
1852
|
-
|
|
1872
|
+
var defaultRuleConfig = {
|
|
1873
|
+
ops: {},
|
|
1874
|
+
rules: {}
|
|
1875
|
+
};
|
|
1876
|
+
function ConditionRow({
|
|
1877
|
+
style,
|
|
1878
|
+
value,
|
|
1879
|
+
onChange,
|
|
1880
|
+
readonly,
|
|
1881
|
+
ruleConfig = defaultRuleConfig
|
|
1882
|
+
}) {
|
|
1853
1883
|
const { left, operator, right } = value || {};
|
|
1854
|
-
const { rule } = useRule(left);
|
|
1884
|
+
const { rule } = useRule(left, ruleConfig.rules);
|
|
1855
1885
|
const { renderOpSelect, opConfig } = useOp({
|
|
1856
1886
|
rule,
|
|
1857
1887
|
op: operator,
|
|
1858
1888
|
onChange: (v) => onChange({ ...value, operator: v }),
|
|
1859
|
-
readonly
|
|
1889
|
+
readonly,
|
|
1890
|
+
userOps: ruleConfig.ops
|
|
1860
1891
|
});
|
|
1861
1892
|
const targetSchema = useMemo9(() => {
|
|
1862
|
-
const targetType = rule?.[operator] || null;
|
|
1893
|
+
const targetType = rule?.[operator || ""] || null;
|
|
1863
1894
|
return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
1864
1895
|
}, [rule, opConfig]);
|
|
1865
1896
|
return /* @__PURE__ */ React21.createElement(UIContainer3, { style }, /* @__PURE__ */ React21.createElement(UIOperator, null, renderOpSelect()), /* @__PURE__ */ React21.createElement(UIValues, null, /* @__PURE__ */ React21.createElement(UILeft, null, /* @__PURE__ */ React21.createElement(
|
|
@@ -1890,7 +1921,7 @@ function ConditionRow({ style, value, onChange, readonly }) {
|
|
|
1890
1921
|
size: "small",
|
|
1891
1922
|
disabled: true,
|
|
1892
1923
|
style: { pointerEvents: "none" },
|
|
1893
|
-
value: opConfig?.rightDisplay || "Empty"
|
|
1924
|
+
value: opConfig?.rightDisplay || I18n10.t("Empty")
|
|
1894
1925
|
}
|
|
1895
1926
|
))));
|
|
1896
1927
|
}
|