@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.
Files changed (54) hide show
  1. package/bin/materials.ts +6 -1
  2. package/bin/project.ts +5 -0
  3. package/dist/esm/index.js +207 -8
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.mts +149 -6
  6. package/dist/index.d.ts +149 -6
  7. package/dist/index.js +202 -9
  8. package/dist/index.js.map +1 -1
  9. package/package.json +4 -4
  10. package/src/components/batch-outputs/config.json +12 -0
  11. package/src/components/batch-outputs/index.tsx +61 -0
  12. package/src/components/batch-outputs/styles.tsx +19 -0
  13. package/src/components/batch-outputs/types.ts +22 -0
  14. package/src/components/batch-outputs/use-list.ts +86 -0
  15. package/src/components/batch-variable-selector/index.tsx +5 -0
  16. package/src/components/condition-row/constants.ts +5 -0
  17. package/src/components/condition-row/hooks/useOp.tsx +5 -0
  18. package/src/components/condition-row/hooks/useRule.ts +5 -0
  19. package/src/components/condition-row/index.tsx +6 -1
  20. package/src/components/condition-row/styles.tsx +5 -0
  21. package/src/components/condition-row/types.ts +5 -0
  22. package/src/components/constant-input/index.tsx +5 -0
  23. package/src/components/constant-input/types.ts +5 -0
  24. package/src/components/dynamic-value-input/index.tsx +6 -0
  25. package/src/components/dynamic-value-input/styles.tsx +5 -0
  26. package/src/components/index.ts +6 -0
  27. package/src/components/json-schema-editor/components/blur-input.tsx +5 -0
  28. package/src/components/json-schema-editor/default-value.tsx +5 -0
  29. package/src/components/json-schema-editor/hooks.tsx +5 -0
  30. package/src/components/json-schema-editor/index.tsx +5 -0
  31. package/src/components/json-schema-editor/styles.tsx +5 -0
  32. package/src/components/json-schema-editor/types.ts +5 -0
  33. package/src/components/json-schema-editor/utils.ts +5 -0
  34. package/src/components/type-selector/constants.tsx +5 -0
  35. package/src/components/type-selector/index.tsx +5 -0
  36. package/src/components/variable-selector/index.tsx +7 -0
  37. package/src/components/variable-selector/styles.tsx +5 -0
  38. package/src/components/variable-selector/use-variable-tree.tsx +8 -3
  39. package/src/effects/auto-rename-ref/index.ts +5 -0
  40. package/src/effects/index.ts +5 -0
  41. package/src/effects/provide-batch-input/index.ts +5 -0
  42. package/src/effects/provide-batch-outputs/index.ts +5 -1
  43. package/src/effects/provide-json-schema-outputs/index.ts +5 -0
  44. package/src/effects/sync-variable-title/index.ts +5 -0
  45. package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
  46. package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
  47. package/src/form-plugins/index.ts +6 -0
  48. package/src/index.ts +6 -0
  49. package/src/typings/flow-value/index.ts +5 -0
  50. package/src/typings/index.ts +5 -0
  51. package/src/typings/json-schema/index.ts +5 -0
  52. package/src/utils/format-legacy-refs/index.ts +5 -0
  53. package/src/utils/index.ts +5 -0
  54. package/src/utils/json-schema/index.ts +6 -1
package/bin/materials.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
1
6
  import { fileURLToPath } from 'url';
2
7
  import path from 'path';
3
8
  import fs from 'fs';
@@ -17,7 +22,7 @@ export interface Material {
17
22
  [key: string]: any; // For other properties from config.json
18
23
  }
19
24
 
20
- const _types: string[] = ['components', 'effects', 'utils', 'typings'];
25
+ const _types: string[] = ['components', 'effects', 'utils', 'typings', 'form-plugins'];
21
26
 
22
27
  export function listAllMaterials(): Material[] {
23
28
  const _materials: Material[] = [];
package/bin/project.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
1
6
  import path from 'path';
2
7
  import fs from 'fs';
3
8
  import { execSync } from 'child_process';
package/dist/esm/index.js CHANGED
@@ -4,7 +4,7 @@ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
4
4
 
5
5
  // src/components/variable-selector/use-variable-tree.tsx
6
6
  import React2, { useCallback } from "react";
7
- import { useScopeAvailable, ASTMatch as ASTMatch2 } from "@flowgram.ai/editor";
7
+ import { ASTMatch as ASTMatch2, useAvailableVariables } from "@flowgram.ai/editor";
8
8
  import { Icon as Icon2 } from "@douyinfe/semi-ui";
9
9
 
10
10
  // src/components/type-selector/constants.tsx
@@ -472,7 +472,7 @@ var JsonSchemaUtils;
472
472
  return {
473
473
  type: "object",
474
474
  properties: drilldown ? Object.fromEntries(
475
- Object.entries(typeAST.properties).map(([key, value]) => [key, astToSchema(value)])
475
+ typeAST.properties.map((property) => [property.key, astToSchema(property.type)])
476
476
  ) : {}
477
477
  };
478
478
  }
@@ -512,7 +512,7 @@ var JsonSchemaUtils;
512
512
  // src/components/variable-selector/use-variable-tree.tsx
513
513
  function useVariableTree(params) {
514
514
  const { includeSchema, excludeSchema } = params;
515
- const available = useScopeAvailable();
515
+ const variables = useAvailableVariables();
516
516
  const getVariableTypeIcon = useCallback((variable) => {
517
517
  if (variable.meta?.icon) {
518
518
  if (typeof variable.meta.icon === "string") {
@@ -563,7 +563,7 @@ function useVariableTree(params) {
563
563
  rootMeta: parentFields[0]?.meta
564
564
  };
565
565
  };
566
- return [...available.variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
566
+ return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
567
567
  }
568
568
 
569
569
  // src/components/variable-selector/styles.tsx
@@ -1527,7 +1527,7 @@ var UIValues = styled4.div`
1527
1527
 
1528
1528
  // src/components/condition-row/hooks/useRule.ts
1529
1529
  import { useMemo as useMemo7 } from "react";
1530
- import { useScopeAvailable as useScopeAvailable2 } from "@flowgram.ai/editor";
1530
+ import { useScopeAvailable } from "@flowgram.ai/editor";
1531
1531
 
1532
1532
  // src/components/condition-row/constants.ts
1533
1533
  var rules = {
@@ -1715,7 +1715,7 @@ function formatNewRefToLegacyRef(value) {
1715
1715
 
1716
1716
  // src/components/condition-row/hooks/useRule.ts
1717
1717
  function useRule(left) {
1718
- const available = useScopeAvailable2();
1718
+ const available = useScopeAvailable();
1719
1719
  const variable = useMemo7(() => {
1720
1720
  if (!left) return void 0;
1721
1721
  return available.getByKeyPath(left.content);
@@ -1795,6 +1795,128 @@ function ConditionRow({ style, value, onChange, readonly }) {
1795
1795
  ) : /* @__PURE__ */ React13.createElement(Input3, { size: "small", disabled: true, value: opConfig?.rightDisplay || "Empty" }))));
1796
1796
  }
1797
1797
 
1798
+ // src/components/batch-outputs/index.tsx
1799
+ import React14 from "react";
1800
+ import { Button as Button4, Input as Input4 } from "@douyinfe/semi-ui";
1801
+ import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
1802
+
1803
+ // src/components/batch-outputs/use-list.ts
1804
+ import { useEffect as useEffect3, useState as useState5 } from "react";
1805
+ import { difference } from "lodash";
1806
+ var _id2 = 0;
1807
+ function genId2() {
1808
+ return _id2++;
1809
+ }
1810
+ function useList({ value, onChange }) {
1811
+ const [list, setList] = useState5([]);
1812
+ useEffect3(() => {
1813
+ setList((_prevList) => {
1814
+ const newKeys = Object.keys(value || {});
1815
+ const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
1816
+ const addKeys = difference(newKeys, oldKeys);
1817
+ return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
1818
+ id: item.id,
1819
+ key: item.key,
1820
+ value: item.key ? value?.[item.key] : void 0
1821
+ })).concat(
1822
+ addKeys.map((_key) => ({
1823
+ id: genId2(),
1824
+ key: _key,
1825
+ value: value?.[_key]
1826
+ }))
1827
+ );
1828
+ });
1829
+ }, [value]);
1830
+ const add = () => {
1831
+ setList((prevList) => [
1832
+ ...prevList,
1833
+ {
1834
+ id: genId2()
1835
+ }
1836
+ ]);
1837
+ };
1838
+ const update = (item) => {
1839
+ setList((prevList) => {
1840
+ const nextList = prevList.map((_item) => {
1841
+ if (_item.id === item.id) {
1842
+ return item;
1843
+ }
1844
+ return _item;
1845
+ });
1846
+ onChange(
1847
+ Object.fromEntries(
1848
+ nextList.filter((item2) => item2.key).map((item2) => [item2.key, item2.value])
1849
+ )
1850
+ );
1851
+ return nextList;
1852
+ });
1853
+ };
1854
+ const remove = (itemId) => {
1855
+ setList((prevList) => {
1856
+ const nextList = prevList.filter((_item) => _item.id !== itemId);
1857
+ onChange(
1858
+ Object.fromEntries(
1859
+ nextList.filter((item) => item.key).map((item) => [item.key, item.value])
1860
+ )
1861
+ );
1862
+ return nextList;
1863
+ });
1864
+ };
1865
+ return { list, add, update, remove };
1866
+ }
1867
+
1868
+ // src/components/batch-outputs/styles.tsx
1869
+ import styled5 from "styled-components";
1870
+ var UIRows = styled5.div`
1871
+ display: flex;
1872
+ flex-direction: column;
1873
+ gap: 10px;
1874
+ margin-bottom: 10px;
1875
+ `;
1876
+ var UIRow2 = styled5.div`
1877
+ display: flex;
1878
+ align-items: center;
1879
+ gap: 5px;
1880
+ `;
1881
+
1882
+ // src/components/batch-outputs/index.tsx
1883
+ function BatchOutputs(props) {
1884
+ const { readonly, style } = props;
1885
+ const { list, add, update, remove } = useList(props);
1886
+ return /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement(UIRows, { style }, list.map((item) => /* @__PURE__ */ React14.createElement(UIRow2, { key: item.id }, /* @__PURE__ */ React14.createElement(
1887
+ Input4,
1888
+ {
1889
+ style: { width: 100 },
1890
+ disabled: readonly,
1891
+ size: "small",
1892
+ value: item.key,
1893
+ onChange: (v) => update({ ...item, key: v })
1894
+ }
1895
+ ), /* @__PURE__ */ React14.createElement(
1896
+ VariableSelector,
1897
+ {
1898
+ style: { flexGrow: 1 },
1899
+ readonly,
1900
+ value: item.value?.content,
1901
+ onChange: (v) => update({
1902
+ ...item,
1903
+ value: {
1904
+ type: "ref",
1905
+ content: v
1906
+ }
1907
+ })
1908
+ }
1909
+ ), /* @__PURE__ */ React14.createElement(
1910
+ Button4,
1911
+ {
1912
+ disabled: readonly,
1913
+ icon: /* @__PURE__ */ React14.createElement(IconDelete, null),
1914
+ size: "small",
1915
+ onClick: () => remove(item.id)
1916
+ }
1917
+ )))), /* @__PURE__ */ React14.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React14.createElement(IconPlus2, null), size: "small", onClick: add }, "Add"));
1918
+ }
1919
+
1798
1920
  // src/effects/provide-batch-input/index.ts
1799
1921
  import {
1800
1922
  ASTFactory as ASTFactory2,
@@ -1837,7 +1959,6 @@ import {
1837
1959
  getNodeForm as getNodeForm2
1838
1960
  } from "@flowgram.ai/editor";
1839
1961
  var provideBatchOutputsEffect = createEffectFromVariableProvider2({
1840
- private: true,
1841
1962
  parse: (value, ctx) => [
1842
1963
  ASTFactory3.createVariableDeclaration({
1843
1964
  key: `${ctx.node.id}`,
@@ -1960,8 +2081,84 @@ var syncVariableTitle = [
1960
2081
  }
1961
2082
  }
1962
2083
  ];
2084
+
2085
+ // src/form-plugins/batch-outputs-plugin/index.ts
2086
+ import {
2087
+ ASTFactory as ASTFactory5,
2088
+ createEffectFromVariableProvider as createEffectFromVariableProvider4,
2089
+ defineFormPluginCreator,
2090
+ getNodeForm as getNodeForm4,
2091
+ getNodePrivateScope,
2092
+ getNodeScope,
2093
+ ScopeChainTransformService,
2094
+ FlowNodeScopeType
2095
+ } from "@flowgram.ai/editor";
2096
+ var provideBatchOutputsEffect2 = createEffectFromVariableProvider4({
2097
+ parse: (value, ctx) => [
2098
+ ASTFactory5.createVariableDeclaration({
2099
+ key: `${ctx.node.id}`,
2100
+ meta: {
2101
+ title: getNodeForm4(ctx.node)?.getValueIn("title"),
2102
+ icon: ctx.node.getNodeRegistry().info?.icon
2103
+ },
2104
+ type: ASTFactory5.createObject({
2105
+ properties: Object.entries(value).map(
2106
+ ([_key, value2]) => ASTFactory5.createProperty({
2107
+ key: _key,
2108
+ initializer: ASTFactory5.createWrapArrayExpression({
2109
+ wrapFor: ASTFactory5.createKeyPathExpression({
2110
+ keyPath: value2?.content || []
2111
+ })
2112
+ })
2113
+ })
2114
+ )
2115
+ })
2116
+ })
2117
+ ]
2118
+ });
2119
+ var createBatchOutputsFormPlugin = defineFormPluginCreator({
2120
+ name: "batch-outputs-plugin",
2121
+ onSetupFormMeta({ mergeEffect }, { outputKey }) {
2122
+ mergeEffect({
2123
+ [outputKey]: provideBatchOutputsEffect2
2124
+ });
2125
+ },
2126
+ onInit(ctx, { outputKey }) {
2127
+ const chainTransformService = ctx.node.getService(ScopeChainTransformService);
2128
+ const batchNodeType = ctx.node.flowNodeType;
2129
+ const transformerId = `${batchNodeType}-outputs`;
2130
+ if (chainTransformService.hasTransformer(transformerId)) {
2131
+ return;
2132
+ }
2133
+ chainTransformService.registerTransformer(transformerId, {
2134
+ transformCovers: (covers, ctx2) => {
2135
+ const node = ctx2.scope.meta?.node;
2136
+ if (node?.parent?.flowNodeType === batchNodeType) {
2137
+ return [...covers, getNodeScope(node.parent)];
2138
+ }
2139
+ return covers;
2140
+ },
2141
+ transformDeps(scopes, ctx2) {
2142
+ const scopeMeta = ctx2.scope.meta;
2143
+ if (scopeMeta?.type === FlowNodeScopeType.private) {
2144
+ return scopes;
2145
+ }
2146
+ const node = scopeMeta?.node;
2147
+ if (node?.flowNodeType === batchNodeType) {
2148
+ const childBlocks = node.blocks;
2149
+ return [
2150
+ getNodePrivateScope(node),
2151
+ ...childBlocks.map((_childBlock) => getNodeScope(_childBlock))
2152
+ ];
2153
+ }
2154
+ return scopes;
2155
+ }
2156
+ });
2157
+ }
2158
+ });
1963
2159
  export {
1964
2160
  ArrayIcons,
2161
+ BatchOutputs,
1965
2162
  BatchVariableSelector,
1966
2163
  ConditionRow,
1967
2164
  ConstantInput,
@@ -1972,6 +2169,7 @@ export {
1972
2169
  VariableSelector,
1973
2170
  VariableTypeIcons,
1974
2171
  autoRenameRefEffect,
2172
+ createBatchOutputsFormPlugin,
1975
2173
  formatLegacyRefOnInit,
1976
2174
  formatLegacyRefOnSubmit,
1977
2175
  formatLegacyRefToNewRef,
@@ -1984,6 +2182,7 @@ export {
1984
2182
  provideBatchInputEffect,
1985
2183
  provideBatchOutputsEffect,
1986
2184
  provideJsonSchemaOutputs,
1987
- syncVariableTitle
2185
+ syncVariableTitle,
2186
+ useVariableTree
1988
2187
  };
1989
2188
  //# sourceMappingURL=index.js.map