@flowgram.ai/form-materials 0.2.15 → 0.2.17
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/bin/materials.ts +6 -1
- package/bin/project.ts +5 -0
- package/dist/esm/index.js +207 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +149 -6
- package/dist/index.d.ts +149 -6
- package/dist/index.js +202 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/batch-outputs/config.json +12 -0
- package/src/components/batch-outputs/index.tsx +61 -0
- package/src/components/batch-outputs/styles.tsx +19 -0
- package/src/components/batch-outputs/types.ts +22 -0
- package/src/components/batch-outputs/use-list.ts +86 -0
- package/src/components/batch-variable-selector/index.tsx +5 -0
- package/src/components/condition-row/constants.ts +5 -0
- package/src/components/condition-row/hooks/useOp.tsx +5 -0
- package/src/components/condition-row/hooks/useRule.ts +5 -0
- package/src/components/condition-row/index.tsx +6 -1
- package/src/components/condition-row/styles.tsx +5 -0
- package/src/components/condition-row/types.ts +5 -0
- package/src/components/constant-input/index.tsx +5 -0
- package/src/components/constant-input/types.ts +5 -0
- package/src/components/dynamic-value-input/index.tsx +6 -0
- package/src/components/dynamic-value-input/styles.tsx +5 -0
- package/src/components/index.ts +6 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +5 -0
- package/src/components/json-schema-editor/default-value.tsx +5 -0
- package/src/components/json-schema-editor/hooks.tsx +5 -0
- package/src/components/json-schema-editor/index.tsx +5 -0
- package/src/components/json-schema-editor/styles.tsx +5 -0
- package/src/components/json-schema-editor/types.ts +5 -0
- package/src/components/json-schema-editor/utils.ts +5 -0
- package/src/components/type-selector/constants.tsx +5 -0
- package/src/components/type-selector/index.tsx +5 -0
- package/src/components/variable-selector/index.tsx +7 -0
- package/src/components/variable-selector/styles.tsx +5 -0
- package/src/components/variable-selector/use-variable-tree.tsx +8 -3
- package/src/effects/auto-rename-ref/index.ts +5 -0
- package/src/effects/index.ts +5 -0
- package/src/effects/provide-batch-input/index.ts +5 -0
- package/src/effects/provide-batch-outputs/index.ts +5 -1
- package/src/effects/provide-json-schema-outputs/index.ts +5 -0
- package/src/effects/sync-variable-title/index.ts +5 -0
- package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
- package/src/form-plugins/index.ts +6 -0
- package/src/index.ts +6 -0
- package/src/typings/flow-value/index.ts +5 -0
- package/src/typings/index.ts +5 -0
- package/src/typings/json-schema/index.ts +5 -0
- package/src/utils/format-legacy-refs/index.ts +5 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/json-schema/index.ts +6 -1
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
ArrayIcons: () => ArrayIcons,
|
|
34
|
+
BatchOutputs: () => BatchOutputs,
|
|
34
35
|
BatchVariableSelector: () => BatchVariableSelector,
|
|
35
36
|
ConditionRow: () => ConditionRow,
|
|
36
37
|
ConstantInput: () => ConstantInput,
|
|
@@ -41,6 +42,7 @@ __export(src_exports, {
|
|
|
41
42
|
VariableSelector: () => VariableSelector,
|
|
42
43
|
VariableTypeIcons: () => VariableTypeIcons,
|
|
43
44
|
autoRenameRefEffect: () => autoRenameRefEffect,
|
|
45
|
+
createBatchOutputsFormPlugin: () => createBatchOutputsFormPlugin,
|
|
44
46
|
formatLegacyRefOnInit: () => formatLegacyRefOnInit,
|
|
45
47
|
formatLegacyRefOnSubmit: () => formatLegacyRefOnSubmit,
|
|
46
48
|
formatLegacyRefToNewRef: () => formatLegacyRefToNewRef,
|
|
@@ -53,7 +55,8 @@ __export(src_exports, {
|
|
|
53
55
|
provideBatchInputEffect: () => provideBatchInputEffect,
|
|
54
56
|
provideBatchOutputsEffect: () => provideBatchOutputsEffect,
|
|
55
57
|
provideJsonSchemaOutputs: () => provideJsonSchemaOutputs,
|
|
56
|
-
syncVariableTitle: () => syncVariableTitle
|
|
58
|
+
syncVariableTitle: () => syncVariableTitle,
|
|
59
|
+
useVariableTree: () => useVariableTree
|
|
57
60
|
});
|
|
58
61
|
module.exports = __toCommonJS(src_exports);
|
|
59
62
|
|
|
@@ -531,7 +534,7 @@ var JsonSchemaUtils;
|
|
|
531
534
|
return {
|
|
532
535
|
type: "object",
|
|
533
536
|
properties: drilldown ? Object.fromEntries(
|
|
534
|
-
|
|
537
|
+
typeAST.properties.map((property) => [property.key, astToSchema(property.type)])
|
|
535
538
|
) : {}
|
|
536
539
|
};
|
|
537
540
|
}
|
|
@@ -571,7 +574,7 @@ var JsonSchemaUtils;
|
|
|
571
574
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
572
575
|
function useVariableTree(params) {
|
|
573
576
|
const { includeSchema, excludeSchema } = params;
|
|
574
|
-
const
|
|
577
|
+
const variables = (0, import_editor2.useAvailableVariables)();
|
|
575
578
|
const getVariableTypeIcon = (0, import_react2.useCallback)((variable) => {
|
|
576
579
|
if (variable.meta?.icon) {
|
|
577
580
|
if (typeof variable.meta.icon === "string") {
|
|
@@ -622,7 +625,7 @@ function useVariableTree(params) {
|
|
|
622
625
|
rootMeta: parentFields[0]?.meta
|
|
623
626
|
};
|
|
624
627
|
};
|
|
625
|
-
return [...
|
|
628
|
+
return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
|
|
626
629
|
}
|
|
627
630
|
|
|
628
631
|
// src/components/variable-selector/styles.tsx
|
|
@@ -1847,6 +1850,128 @@ function ConditionRow({ style, value, onChange, readonly }) {
|
|
|
1847
1850
|
) : /* @__PURE__ */ import_react15.default.createElement(import_semi_ui9.Input, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
|
|
1848
1851
|
}
|
|
1849
1852
|
|
|
1853
|
+
// src/components/batch-outputs/index.tsx
|
|
1854
|
+
var import_react17 = __toESM(require("react"));
|
|
1855
|
+
var import_semi_ui10 = require("@douyinfe/semi-ui");
|
|
1856
|
+
var import_semi_icons8 = require("@douyinfe/semi-icons");
|
|
1857
|
+
|
|
1858
|
+
// src/components/batch-outputs/use-list.ts
|
|
1859
|
+
var import_react16 = require("react");
|
|
1860
|
+
var import_lodash3 = require("lodash");
|
|
1861
|
+
var _id2 = 0;
|
|
1862
|
+
function genId2() {
|
|
1863
|
+
return _id2++;
|
|
1864
|
+
}
|
|
1865
|
+
function useList({ value, onChange }) {
|
|
1866
|
+
const [list, setList] = (0, import_react16.useState)([]);
|
|
1867
|
+
(0, import_react16.useEffect)(() => {
|
|
1868
|
+
setList((_prevList) => {
|
|
1869
|
+
const newKeys = Object.keys(value || {});
|
|
1870
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
|
|
1871
|
+
const addKeys = (0, import_lodash3.difference)(newKeys, oldKeys);
|
|
1872
|
+
return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
|
|
1873
|
+
id: item.id,
|
|
1874
|
+
key: item.key,
|
|
1875
|
+
value: item.key ? value?.[item.key] : void 0
|
|
1876
|
+
})).concat(
|
|
1877
|
+
addKeys.map((_key) => ({
|
|
1878
|
+
id: genId2(),
|
|
1879
|
+
key: _key,
|
|
1880
|
+
value: value?.[_key]
|
|
1881
|
+
}))
|
|
1882
|
+
);
|
|
1883
|
+
});
|
|
1884
|
+
}, [value]);
|
|
1885
|
+
const add = () => {
|
|
1886
|
+
setList((prevList) => [
|
|
1887
|
+
...prevList,
|
|
1888
|
+
{
|
|
1889
|
+
id: genId2()
|
|
1890
|
+
}
|
|
1891
|
+
]);
|
|
1892
|
+
};
|
|
1893
|
+
const update = (item) => {
|
|
1894
|
+
setList((prevList) => {
|
|
1895
|
+
const nextList = prevList.map((_item) => {
|
|
1896
|
+
if (_item.id === item.id) {
|
|
1897
|
+
return item;
|
|
1898
|
+
}
|
|
1899
|
+
return _item;
|
|
1900
|
+
});
|
|
1901
|
+
onChange(
|
|
1902
|
+
Object.fromEntries(
|
|
1903
|
+
nextList.filter((item2) => item2.key).map((item2) => [item2.key, item2.value])
|
|
1904
|
+
)
|
|
1905
|
+
);
|
|
1906
|
+
return nextList;
|
|
1907
|
+
});
|
|
1908
|
+
};
|
|
1909
|
+
const remove = (itemId) => {
|
|
1910
|
+
setList((prevList) => {
|
|
1911
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
1912
|
+
onChange(
|
|
1913
|
+
Object.fromEntries(
|
|
1914
|
+
nextList.filter((item) => item.key).map((item) => [item.key, item.value])
|
|
1915
|
+
)
|
|
1916
|
+
);
|
|
1917
|
+
return nextList;
|
|
1918
|
+
});
|
|
1919
|
+
};
|
|
1920
|
+
return { list, add, update, remove };
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
// src/components/batch-outputs/styles.tsx
|
|
1924
|
+
var import_styled_components5 = __toESM(require("styled-components"));
|
|
1925
|
+
var UIRows = import_styled_components5.default.div`
|
|
1926
|
+
display: flex;
|
|
1927
|
+
flex-direction: column;
|
|
1928
|
+
gap: 10px;
|
|
1929
|
+
margin-bottom: 10px;
|
|
1930
|
+
`;
|
|
1931
|
+
var UIRow2 = import_styled_components5.default.div`
|
|
1932
|
+
display: flex;
|
|
1933
|
+
align-items: center;
|
|
1934
|
+
gap: 5px;
|
|
1935
|
+
`;
|
|
1936
|
+
|
|
1937
|
+
// src/components/batch-outputs/index.tsx
|
|
1938
|
+
function BatchOutputs(props) {
|
|
1939
|
+
const { readonly, style } = props;
|
|
1940
|
+
const { list, add, update, remove } = useList(props);
|
|
1941
|
+
return /* @__PURE__ */ import_react17.default.createElement("div", null, /* @__PURE__ */ import_react17.default.createElement(UIRows, { style }, list.map((item) => /* @__PURE__ */ import_react17.default.createElement(UIRow2, { key: item.id }, /* @__PURE__ */ import_react17.default.createElement(
|
|
1942
|
+
import_semi_ui10.Input,
|
|
1943
|
+
{
|
|
1944
|
+
style: { width: 100 },
|
|
1945
|
+
disabled: readonly,
|
|
1946
|
+
size: "small",
|
|
1947
|
+
value: item.key,
|
|
1948
|
+
onChange: (v) => update({ ...item, key: v })
|
|
1949
|
+
}
|
|
1950
|
+
), /* @__PURE__ */ import_react17.default.createElement(
|
|
1951
|
+
VariableSelector,
|
|
1952
|
+
{
|
|
1953
|
+
style: { flexGrow: 1 },
|
|
1954
|
+
readonly,
|
|
1955
|
+
value: item.value?.content,
|
|
1956
|
+
onChange: (v) => update({
|
|
1957
|
+
...item,
|
|
1958
|
+
value: {
|
|
1959
|
+
type: "ref",
|
|
1960
|
+
content: v
|
|
1961
|
+
}
|
|
1962
|
+
})
|
|
1963
|
+
}
|
|
1964
|
+
), /* @__PURE__ */ import_react17.default.createElement(
|
|
1965
|
+
import_semi_ui10.Button,
|
|
1966
|
+
{
|
|
1967
|
+
disabled: readonly,
|
|
1968
|
+
icon: /* @__PURE__ */ import_react17.default.createElement(import_semi_icons8.IconDelete, null),
|
|
1969
|
+
size: "small",
|
|
1970
|
+
onClick: () => remove(item.id)
|
|
1971
|
+
}
|
|
1972
|
+
)))), /* @__PURE__ */ import_react17.default.createElement(import_semi_ui10.Button, { disabled: readonly, icon: /* @__PURE__ */ import_react17.default.createElement(import_semi_icons8.IconPlus, null), size: "small", onClick: add }, "Add"));
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1850
1975
|
// src/effects/provide-batch-input/index.ts
|
|
1851
1976
|
var import_editor5 = require("@flowgram.ai/editor");
|
|
1852
1977
|
var provideBatchInputEffect = (0, import_editor5.createEffectFromVariableProvider)({
|
|
@@ -1881,7 +2006,6 @@ var provideBatchInputEffect = (0, import_editor5.createEffectFromVariableProvide
|
|
|
1881
2006
|
// src/effects/provide-batch-outputs/index.ts
|
|
1882
2007
|
var import_editor6 = require("@flowgram.ai/editor");
|
|
1883
2008
|
var provideBatchOutputsEffect = (0, import_editor6.createEffectFromVariableProvider)({
|
|
1884
|
-
private: true,
|
|
1885
2009
|
parse: (value, ctx) => [
|
|
1886
2010
|
import_editor6.ASTFactory.createVariableDeclaration({
|
|
1887
2011
|
key: `${ctx.node.id}`,
|
|
@@ -1906,7 +2030,7 @@ var provideBatchOutputsEffect = (0, import_editor6.createEffectFromVariableProvi
|
|
|
1906
2030
|
});
|
|
1907
2031
|
|
|
1908
2032
|
// src/effects/auto-rename-ref/index.ts
|
|
1909
|
-
var
|
|
2033
|
+
var import_lodash4 = require("lodash");
|
|
1910
2034
|
var import_editor7 = require("@flowgram.ai/editor");
|
|
1911
2035
|
var autoRenameRefEffect = [
|
|
1912
2036
|
{
|
|
@@ -1943,7 +2067,7 @@ function isRef(value) {
|
|
|
1943
2067
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
1944
2068
|
}
|
|
1945
2069
|
function traverseRef(name, value, cb) {
|
|
1946
|
-
if ((0,
|
|
2070
|
+
if ((0, import_lodash4.isObject)(value)) {
|
|
1947
2071
|
if (isRef(value)) {
|
|
1948
2072
|
cb(name, value);
|
|
1949
2073
|
return;
|
|
@@ -1953,7 +2077,7 @@ function traverseRef(name, value, cb) {
|
|
|
1953
2077
|
});
|
|
1954
2078
|
return;
|
|
1955
2079
|
}
|
|
1956
|
-
if ((0,
|
|
2080
|
+
if ((0, import_lodash4.isArray)(value)) {
|
|
1957
2081
|
value.forEach((_value, idx) => {
|
|
1958
2082
|
traverseRef(`${name}[${idx}]`, _value, cb);
|
|
1959
2083
|
});
|
|
@@ -1994,9 +2118,76 @@ var syncVariableTitle = [
|
|
|
1994
2118
|
}
|
|
1995
2119
|
}
|
|
1996
2120
|
];
|
|
2121
|
+
|
|
2122
|
+
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
2123
|
+
var import_editor10 = require("@flowgram.ai/editor");
|
|
2124
|
+
var provideBatchOutputsEffect2 = (0, import_editor10.createEffectFromVariableProvider)({
|
|
2125
|
+
parse: (value, ctx) => [
|
|
2126
|
+
import_editor10.ASTFactory.createVariableDeclaration({
|
|
2127
|
+
key: `${ctx.node.id}`,
|
|
2128
|
+
meta: {
|
|
2129
|
+
title: (0, import_editor10.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
2130
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
2131
|
+
},
|
|
2132
|
+
type: import_editor10.ASTFactory.createObject({
|
|
2133
|
+
properties: Object.entries(value).map(
|
|
2134
|
+
([_key, value2]) => import_editor10.ASTFactory.createProperty({
|
|
2135
|
+
key: _key,
|
|
2136
|
+
initializer: import_editor10.ASTFactory.createWrapArrayExpression({
|
|
2137
|
+
wrapFor: import_editor10.ASTFactory.createKeyPathExpression({
|
|
2138
|
+
keyPath: value2?.content || []
|
|
2139
|
+
})
|
|
2140
|
+
})
|
|
2141
|
+
})
|
|
2142
|
+
)
|
|
2143
|
+
})
|
|
2144
|
+
})
|
|
2145
|
+
]
|
|
2146
|
+
});
|
|
2147
|
+
var createBatchOutputsFormPlugin = (0, import_editor10.defineFormPluginCreator)({
|
|
2148
|
+
name: "batch-outputs-plugin",
|
|
2149
|
+
onSetupFormMeta({ mergeEffect }, { outputKey }) {
|
|
2150
|
+
mergeEffect({
|
|
2151
|
+
[outputKey]: provideBatchOutputsEffect2
|
|
2152
|
+
});
|
|
2153
|
+
},
|
|
2154
|
+
onInit(ctx, { outputKey }) {
|
|
2155
|
+
const chainTransformService = ctx.node.getService(import_editor10.ScopeChainTransformService);
|
|
2156
|
+
const batchNodeType = ctx.node.flowNodeType;
|
|
2157
|
+
const transformerId = `${batchNodeType}-outputs`;
|
|
2158
|
+
if (chainTransformService.hasTransformer(transformerId)) {
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
chainTransformService.registerTransformer(transformerId, {
|
|
2162
|
+
transformCovers: (covers, ctx2) => {
|
|
2163
|
+
const node = ctx2.scope.meta?.node;
|
|
2164
|
+
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
2165
|
+
return [...covers, (0, import_editor10.getNodeScope)(node.parent)];
|
|
2166
|
+
}
|
|
2167
|
+
return covers;
|
|
2168
|
+
},
|
|
2169
|
+
transformDeps(scopes, ctx2) {
|
|
2170
|
+
const scopeMeta = ctx2.scope.meta;
|
|
2171
|
+
if (scopeMeta?.type === import_editor10.FlowNodeScopeType.private) {
|
|
2172
|
+
return scopes;
|
|
2173
|
+
}
|
|
2174
|
+
const node = scopeMeta?.node;
|
|
2175
|
+
if (node?.flowNodeType === batchNodeType) {
|
|
2176
|
+
const childBlocks = node.blocks;
|
|
2177
|
+
return [
|
|
2178
|
+
(0, import_editor10.getNodePrivateScope)(node),
|
|
2179
|
+
...childBlocks.map((_childBlock) => (0, import_editor10.getNodeScope)(_childBlock))
|
|
2180
|
+
];
|
|
2181
|
+
}
|
|
2182
|
+
return scopes;
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
1997
2187
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1998
2188
|
0 && (module.exports = {
|
|
1999
2189
|
ArrayIcons,
|
|
2190
|
+
BatchOutputs,
|
|
2000
2191
|
BatchVariableSelector,
|
|
2001
2192
|
ConditionRow,
|
|
2002
2193
|
ConstantInput,
|
|
@@ -2007,6 +2198,7 @@ var syncVariableTitle = [
|
|
|
2007
2198
|
VariableSelector,
|
|
2008
2199
|
VariableTypeIcons,
|
|
2009
2200
|
autoRenameRefEffect,
|
|
2201
|
+
createBatchOutputsFormPlugin,
|
|
2010
2202
|
formatLegacyRefOnInit,
|
|
2011
2203
|
formatLegacyRefOnSubmit,
|
|
2012
2204
|
formatLegacyRefToNewRef,
|
|
@@ -2019,6 +2211,7 @@ var syncVariableTitle = [
|
|
|
2019
2211
|
provideBatchInputEffect,
|
|
2020
2212
|
provideBatchOutputsEffect,
|
|
2021
2213
|
provideJsonSchemaOutputs,
|
|
2022
|
-
syncVariableTitle
|
|
2214
|
+
syncVariableTitle,
|
|
2215
|
+
useVariableTree
|
|
2023
2216
|
});
|
|
2024
2217
|
//# sourceMappingURL=index.js.map
|