@flowgram.ai/form-materials 0.4.12 → 0.4.13

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.
@@ -65,7 +65,6 @@ const VariableSelector = ({ value, config = {}, onChange, style, readonly = fals
65
65
  });
66
66
  return icon;
67
67
  };
68
- console.log('debugger treeValue', treeValue);
69
68
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
70
69
  children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_styles_js_namespaceObject.UITreeSelect, {
71
70
  dropdownMatchSelectWidth: false,
@@ -27,6 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  createBatchOutputsFormPlugin: ()=>createBatchOutputsFormPlugin,
28
28
  provideBatchOutputsEffect: ()=>provideBatchOutputsEffect
29
29
  });
30
+ const external_lodash_es_namespaceObject = require("lodash-es");
31
+ const json_schema_namespaceObject = require("@flowgram.ai/json-schema");
30
32
  const editor_namespaceObject = require("@flowgram.ai/editor");
31
33
  const provideBatchOutputsEffect = (0, editor_namespaceObject.createEffectFromVariableProvider)({
32
34
  parse: (value, ctx)=>[
@@ -51,10 +53,15 @@ const provideBatchOutputsEffect = (0, editor_namespaceObject.createEffectFromVar
51
53
  });
52
54
  const createBatchOutputsFormPlugin = (0, editor_namespaceObject.defineFormPluginCreator)({
53
55
  name: 'batch-outputs-plugin',
54
- onSetupFormMeta ({ mergeEffect }, { outputKey }) {
56
+ onSetupFormMeta ({ mergeEffect, addFormatOnSubmit }, { outputKey, inferTargetKey }) {
55
57
  mergeEffect({
56
58
  [outputKey]: provideBatchOutputsEffect
57
59
  });
60
+ if (inferTargetKey) addFormatOnSubmit((formData, ctx)=>{
61
+ const outputVariable = (0, editor_namespaceObject.getNodeScope)(ctx.node).output.variables?.[0];
62
+ if (outputVariable?.type) (0, external_lodash_es_namespaceObject.set)(formData, inferTargetKey, json_schema_namespaceObject.JsonSchemaUtils.astToSchema(outputVariable?.type));
63
+ return formData;
64
+ });
58
65
  },
59
66
  onInit (ctx, { outputKey }) {
60
67
  const chainTransformService = ctx.node.getService(editor_namespaceObject.ScopeChainTransformService);
@@ -34,7 +34,6 @@ const VariableSelector = ({ value, config = {}, onChange, style, readonly = fals
34
34
  });
35
35
  return icon;
36
36
  };
37
- console.log('debugger treeValue', treeValue);
38
37
  return /*#__PURE__*/ jsx(Fragment, {
39
38
  children: /*#__PURE__*/ jsx(UITreeSelect, {
40
39
  dropdownMatchSelectWidth: false,
@@ -1,3 +1,5 @@
1
+ import { set } from "lodash-es";
2
+ import { JsonSchemaUtils } from "@flowgram.ai/json-schema";
1
3
  import { ASTFactory, FlowNodeScopeType, ScopeChainTransformService, createEffectFromVariableProvider, defineFormPluginCreator, getNodeForm, getNodePrivateScope, getNodeScope } from "@flowgram.ai/editor";
2
4
  const provideBatchOutputsEffect = createEffectFromVariableProvider({
3
5
  parse: (value, ctx)=>[
@@ -22,10 +24,15 @@ const provideBatchOutputsEffect = createEffectFromVariableProvider({
22
24
  });
23
25
  const createBatchOutputsFormPlugin = defineFormPluginCreator({
24
26
  name: 'batch-outputs-plugin',
25
- onSetupFormMeta ({ mergeEffect }, { outputKey }) {
27
+ onSetupFormMeta ({ mergeEffect, addFormatOnSubmit }, { outputKey, inferTargetKey }) {
26
28
  mergeEffect({
27
29
  [outputKey]: provideBatchOutputsEffect
28
30
  });
31
+ if (inferTargetKey) addFormatOnSubmit((formData, ctx)=>{
32
+ const outputVariable = getNodeScope(ctx.node).output.variables?.[0];
33
+ if (outputVariable?.type) set(formData, inferTargetKey, JsonSchemaUtils.astToSchema(outputVariable?.type));
34
+ return formData;
35
+ });
29
36
  },
30
37
  onInit (ctx, { outputKey }) {
31
38
  const chainTransformService = ctx.node.getService(ScopeChainTransformService);
@@ -9,4 +9,8 @@ export declare const provideBatchOutputsEffect: EffectOptions[];
9
9
  */
10
10
  export declare const createBatchOutputsFormPlugin: FormPluginCreator<{
11
11
  outputKey: string;
12
+ /**
13
+ * if set, infer json schema to inferTargetKey when submit
14
+ */
15
+ inferTargetKey?: string;
12
16
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowgram.ai/form-materials",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
4
4
  "homepage": "https://flowgram.ai/",
5
5
  "repository": "https://github.com/bytedance/flowgram.ai",
6
6
  "license": "MIT",
@@ -63,21 +63,21 @@
63
63
  "@douyinfe/semi-illustrations": "^2.80.0",
64
64
  "@douyinfe/semi-ui": "^2.80.0",
65
65
  "lodash-es": "^4.17.21",
66
- "nanoid": "^4.0.2",
66
+ "nanoid": "^5.0.9",
67
67
  "immer": "~10.1.1",
68
68
  "@codemirror/view": "~6.38.0",
69
69
  "@codemirror/state": "~6.5.2",
70
70
  "zod": "^3.24.4",
71
- "@flowgram.ai/editor": "0.4.12",
72
- "@flowgram.ai/json-schema": "0.4.12",
73
- "@flowgram.ai/coze-editor": "0.4.12"
71
+ "@flowgram.ai/editor": "0.4.13",
72
+ "@flowgram.ai/json-schema": "0.4.13",
73
+ "@flowgram.ai/coze-editor": "0.4.13"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/lodash-es": "^4.17.12",
77
77
  "@types/node": "^18",
78
78
  "@types/react": "^18",
79
79
  "@types/react-dom": "^18",
80
- "@types/inquirer": "9.0.7",
80
+ "@types/inquirer": "^9.0.9",
81
81
  "@types/styled-components": "^5",
82
82
  "eslint": "^8.54.0",
83
83
  "react": "^18",
@@ -88,8 +88,8 @@
88
88
  "@rslib/core": "~0.12.4",
89
89
  "cross-env": "~7.0.3",
90
90
  "@rsbuild/plugin-react": "^1.1.1",
91
- "@flowgram.ai/eslint-config": "0.4.12",
92
- "@flowgram.ai/ts-config": "0.4.12"
91
+ "@flowgram.ai/ts-config": "0.4.13",
92
+ "@flowgram.ai/eslint-config": "0.4.13"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "react": ">=16.8",
@@ -73,8 +73,6 @@ export const VariableSelector = ({
73
73
  return icon;
74
74
  };
75
75
 
76
- console.log('debugger treeValue', treeValue);
77
-
78
76
  return (
79
77
  <>
80
78
  <UITreeSelect
@@ -3,6 +3,8 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
+ import { set } from 'lodash-es';
7
+ import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
6
8
  import {
7
9
  ASTFactory,
8
10
  createEffectFromVariableProvider,
@@ -46,59 +48,76 @@ export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariab
46
48
  /**
47
49
  * Free Layout only right now
48
50
  */
49
- export const createBatchOutputsFormPlugin: FormPluginCreator<{ outputKey: string }> =
50
- defineFormPluginCreator({
51
- name: 'batch-outputs-plugin',
52
- onSetupFormMeta({ mergeEffect }, { outputKey }) {
53
- mergeEffect({
54
- [outputKey]: provideBatchOutputsEffect,
51
+ export const createBatchOutputsFormPlugin: FormPluginCreator<{
52
+ outputKey: string;
53
+ /**
54
+ * if set, infer json schema to inferTargetKey when submit
55
+ */
56
+ inferTargetKey?: string;
57
+ }> = defineFormPluginCreator({
58
+ name: 'batch-outputs-plugin',
59
+ onSetupFormMeta({ mergeEffect, addFormatOnSubmit }, { outputKey, inferTargetKey }) {
60
+ mergeEffect({
61
+ [outputKey]: provideBatchOutputsEffect,
62
+ });
63
+
64
+ if (inferTargetKey) {
65
+ addFormatOnSubmit((formData, ctx) => {
66
+ const outputVariable = getNodeScope(ctx.node).output.variables?.[0];
67
+
68
+ if (outputVariable?.type) {
69
+ set(formData, inferTargetKey, JsonSchemaUtils.astToSchema(outputVariable?.type));
70
+ }
71
+
72
+ return formData;
55
73
  });
56
- },
57
- onInit(ctx, { outputKey }) {
58
- const chainTransformService = ctx.node.getService(ScopeChainTransformService);
74
+ }
75
+ },
76
+ onInit(ctx, { outputKey }) {
77
+ const chainTransformService = ctx.node.getService(ScopeChainTransformService);
59
78
 
60
- const batchNodeType = ctx.node.flowNodeType;
79
+ const batchNodeType = ctx.node.flowNodeType;
61
80
 
62
- const transformerId = `${batchNodeType}-outputs`;
81
+ const transformerId = `${batchNodeType}-outputs`;
63
82
 
64
- if (chainTransformService.hasTransformer(transformerId)) {
65
- return;
66
- }
83
+ if (chainTransformService.hasTransformer(transformerId)) {
84
+ return;
85
+ }
67
86
 
68
- chainTransformService.registerTransformer(transformerId, {
69
- transformCovers: (covers, ctx) => {
70
- const node = ctx.scope.meta?.node;
87
+ chainTransformService.registerTransformer(transformerId, {
88
+ transformCovers: (covers, ctx) => {
89
+ const node = ctx.scope.meta?.node;
71
90
 
72
- // Child Node's variable can cover parent
73
- if (node?.parent?.flowNodeType === batchNodeType) {
74
- return [...covers, getNodeScope(node.parent)];
75
- }
91
+ // Child Node's variable can cover parent
92
+ if (node?.parent?.flowNodeType === batchNodeType) {
93
+ return [...covers, getNodeScope(node.parent)];
94
+ }
76
95
 
77
- return covers;
78
- },
79
- transformDeps(scopes, ctx) {
80
- const scopeMeta = ctx.scope.meta;
96
+ return covers;
97
+ },
98
+ transformDeps(scopes, ctx) {
99
+ const scopeMeta = ctx.scope.meta;
81
100
 
82
- if (scopeMeta?.type === FlowNodeScopeType.private) {
83
- return scopes;
84
- }
101
+ if (scopeMeta?.type === FlowNodeScopeType.private) {
102
+ return scopes;
103
+ }
85
104
 
86
- const node = scopeMeta?.node;
105
+ const node = scopeMeta?.node;
87
106
 
88
- // Public of Loop Node depends on child Node
89
- if (node?.flowNodeType === batchNodeType) {
90
- // Get all child blocks
91
- const childBlocks = node.blocks;
107
+ // Public of Loop Node depends on child Node
108
+ if (node?.flowNodeType === batchNodeType) {
109
+ // Get all child blocks
110
+ const childBlocks = node.blocks;
92
111
 
93
- // public scope of all child blocks
94
- return [
95
- getNodePrivateScope(node),
96
- ...childBlocks.map((_childBlock) => getNodeScope(_childBlock)),
97
- ];
98
- }
112
+ // public scope of all child blocks
113
+ return [
114
+ getNodePrivateScope(node),
115
+ ...childBlocks.map((_childBlock) => getNodeScope(_childBlock)),
116
+ ];
117
+ }
99
118
 
100
- return scopes;
101
- },
102
- });
103
- },
104
- });
119
+ return scopes;
120
+ },
121
+ });
122
+ },
123
+ });