@flowgram.ai/form-materials 0.1.0-alpha.19 → 0.1.0-alpha.21
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/cjs/components/assign-rows/index.js +8 -2
- package/dist/cjs/components/blur-input/index.js +4 -1
- package/dist/cjs/components/condition-context/hooks/use-condition.js +4 -0
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tag.js +13 -4
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tree.js +7 -3
- package/dist/cjs/components/display-outputs/index.js +3 -2
- package/dist/cjs/components/index.js +5 -1
- package/dist/cjs/components/json-schema-creator/index.js +36 -0
- package/dist/cjs/components/json-schema-creator/json-input-modal.js +96 -0
- package/dist/cjs/components/json-schema-creator/json-schema-creator.js +60 -0
- package/dist/cjs/components/json-schema-creator/utils/json-to-schema.js +67 -0
- package/dist/cjs/effects/validate-when-variable-sync/index.js +3 -3
- package/dist/cjs/index.js +3 -0
- package/dist/esm/components/assign-rows/index.mjs +9 -3
- package/dist/esm/components/blur-input/index.mjs +4 -1
- package/dist/esm/components/condition-context/hooks/use-condition.mjs +4 -0
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +13 -4
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +8 -4
- package/dist/esm/components/display-outputs/index.mjs +4 -3
- package/dist/esm/components/index.mjs +2 -1
- package/dist/esm/components/json-schema-creator/index.mjs +2 -0
- package/dist/esm/components/json-schema-creator/json-input-modal.mjs +62 -0
- package/dist/esm/components/json-schema-creator/json-schema-creator.mjs +26 -0
- package/dist/esm/components/json-schema-creator/utils/json-to-schema.mjs +33 -0
- package/dist/esm/effects/validate-when-variable-sync/index.mjs +3 -3
- package/dist/esm/index.mjs +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/assign-rows/index.d.ts +2 -0
- package/dist/types/components/display-outputs/index.d.ts +2 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/json-schema-creator/index.d.ts +6 -0
- package/dist/types/components/json-schema-creator/json-input-modal.d.ts +13 -0
- package/dist/types/components/json-schema-creator/json-schema-creator.d.ts +11 -0
- package/dist/types/components/json-schema-creator/utils/json-to-schema.d.ts +6 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +7 -3
- package/package.json +6 -6
- package/src/components/assign-rows/index.tsx +7 -6
- package/src/components/blur-input/index.tsx +4 -1
- package/src/components/condition-context/hooks/use-condition.tsx +4 -0
- package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +16 -8
- package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +14 -4
- package/src/components/display-outputs/index.tsx +5 -4
- package/src/components/index.ts +1 -0
- package/src/components/json-schema-creator/index.tsx +7 -0
- package/src/components/json-schema-creator/json-input-modal.tsx +61 -0
- package/src/components/json-schema-creator/json-schema-creator.tsx +37 -0
- package/src/components/json-schema-creator/utils/json-to-schema.ts +50 -0
- package/src/effects/validate-when-variable-sync/index.ts +7 -3
- package/src/index.ts +2 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +17 -12
- package/src/shared/inject-material/README.md +0 -170
- package/src/shared/inject-material/README.zh.md +0 -174
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { I18n } from "@flowgram.ai/editor";
|
|
4
|
+
import { Modal, Typography } from "@douyinfe/semi-ui";
|
|
5
|
+
import { jsonToSchema } from "./utils/json-to-schema.mjs";
|
|
6
|
+
import { JsonCodeEditor } from "../code-editor/index.mjs";
|
|
7
|
+
const { Text } = Typography;
|
|
8
|
+
function JsonInputModal({ visible, onClose, onConfirm }) {
|
|
9
|
+
const [jsonInput, setJsonInput] = useState('');
|
|
10
|
+
const [error, setError] = useState('');
|
|
11
|
+
const handleConfirm = ()=>{
|
|
12
|
+
try {
|
|
13
|
+
const schema = jsonToSchema(jsonInput);
|
|
14
|
+
onConfirm(schema);
|
|
15
|
+
setJsonInput('');
|
|
16
|
+
setError('');
|
|
17
|
+
} catch (err) {
|
|
18
|
+
setError(err.message);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return /*#__PURE__*/ jsxs(Modal, {
|
|
22
|
+
visible: visible,
|
|
23
|
+
onCancel: onClose,
|
|
24
|
+
onOk: handleConfirm,
|
|
25
|
+
title: I18n.t('JSON to JSONSchema'),
|
|
26
|
+
okText: I18n.t('Generate'),
|
|
27
|
+
cancelText: I18n.t('Cancel'),
|
|
28
|
+
width: 600,
|
|
29
|
+
children: [
|
|
30
|
+
/*#__PURE__*/ jsx("div", {
|
|
31
|
+
style: {
|
|
32
|
+
marginBottom: 8
|
|
33
|
+
},
|
|
34
|
+
children: /*#__PURE__*/ jsxs(Text, {
|
|
35
|
+
children: [
|
|
36
|
+
I18n.t('Paste JSON data'),
|
|
37
|
+
":"
|
|
38
|
+
]
|
|
39
|
+
})
|
|
40
|
+
}),
|
|
41
|
+
/*#__PURE__*/ jsx("div", {
|
|
42
|
+
style: {
|
|
43
|
+
minHeight: 300
|
|
44
|
+
},
|
|
45
|
+
children: /*#__PURE__*/ jsx(JsonCodeEditor, {
|
|
46
|
+
value: jsonInput,
|
|
47
|
+
onChange: (value)=>setJsonInput(value || '')
|
|
48
|
+
})
|
|
49
|
+
}),
|
|
50
|
+
error && /*#__PURE__*/ jsx("div", {
|
|
51
|
+
style: {
|
|
52
|
+
marginTop: 8
|
|
53
|
+
},
|
|
54
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
55
|
+
type: "danger",
|
|
56
|
+
children: error
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export { JsonInputModal };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { I18n } from "@flowgram.ai/editor";
|
|
4
|
+
import { Button } from "@douyinfe/semi-ui";
|
|
5
|
+
import { JsonInputModal } from "./json-input-modal.mjs";
|
|
6
|
+
function JsonSchemaCreator({ onSchemaCreate }) {
|
|
7
|
+
const [visible, setVisible] = useState(false);
|
|
8
|
+
const handleCreate = (schema)=>{
|
|
9
|
+
onSchemaCreate?.(schema);
|
|
10
|
+
setVisible(false);
|
|
11
|
+
};
|
|
12
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
13
|
+
children: [
|
|
14
|
+
/*#__PURE__*/ jsx(Button, {
|
|
15
|
+
onClick: ()=>setVisible(true),
|
|
16
|
+
children: I18n.t('JSON to JSONSchema')
|
|
17
|
+
}),
|
|
18
|
+
/*#__PURE__*/ jsx(JsonInputModal, {
|
|
19
|
+
visible: visible,
|
|
20
|
+
onClose: ()=>setVisible(false),
|
|
21
|
+
onConfirm: handleCreate
|
|
22
|
+
})
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { JsonSchemaCreator };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function jsonToSchema(jsonString) {
|
|
2
|
+
const data = JSON.parse(jsonString);
|
|
3
|
+
return generateSchema(data);
|
|
4
|
+
}
|
|
5
|
+
function generateSchema(value) {
|
|
6
|
+
if (null === value) return {
|
|
7
|
+
type: 'string'
|
|
8
|
+
};
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
const schema = {
|
|
11
|
+
type: 'array'
|
|
12
|
+
};
|
|
13
|
+
if (value.length > 0) schema.items = generateSchema(value[0]);
|
|
14
|
+
return schema;
|
|
15
|
+
}
|
|
16
|
+
if ('object' == typeof value) {
|
|
17
|
+
const schema = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {},
|
|
20
|
+
required: []
|
|
21
|
+
};
|
|
22
|
+
for (const [key, val] of Object.entries(value)){
|
|
23
|
+
schema.properties[key] = generateSchema(val);
|
|
24
|
+
schema.required.push(key);
|
|
25
|
+
}
|
|
26
|
+
return schema;
|
|
27
|
+
}
|
|
28
|
+
const type = typeof value;
|
|
29
|
+
return {
|
|
30
|
+
type: type
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { jsonToSchema };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { isEmpty } from "lodash-es";
|
|
2
1
|
import { DataEvent, getNodePrivateScope, getNodeScope } from "@flowgram.ai/editor";
|
|
3
2
|
const validateWhenVariableSync = ({ scope } = {})=>[
|
|
4
3
|
{
|
|
5
4
|
event: DataEvent.onValueInit,
|
|
6
|
-
effect: ({ context, form })=>{
|
|
5
|
+
effect: ({ context, form, name })=>{
|
|
7
6
|
const nodeScope = 'private' === scope ? getNodePrivateScope(context.node) : getNodeScope(context.node);
|
|
8
7
|
const disposable = nodeScope.available.onListOrAnyVarChange(()=>{
|
|
9
|
-
|
|
8
|
+
const errorKeys = Object.entries(form.state.errors || {}).filter(([_, errors])=>errors?.length > 0).filter(([key])=>key.startsWith(name) || name.startsWith(key)).map(([key])=>key);
|
|
9
|
+
if (errorKeys.length > 0) form.validate();
|
|
10
10
|
});
|
|
11
11
|
return ()=>disposable.dispose();
|
|
12
12
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaEditor, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, getTypeSelectValue, parseTypeSelectValue, useCondition, useConditionContext, useVariableTree } from "./components/index.mjs";
|
|
1
|
+
import { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaCreator, JsonSchemaEditor, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, getTypeSelectValue, parseTypeSelectValue, useCondition, useConditionContext, useVariableTree } from "./components/index.mjs";
|
|
2
2
|
import { autoRenameRefEffect, listenRefSchemaChange, listenRefValueChange, provideBatchInputEffect, provideJsonSchemaOutputs, syncVariableTitle, validateWhenVariableSync } from "./effects/index.mjs";
|
|
3
3
|
import { createBatchOutputsFormPlugin, createInferAssignPlugin, createInferInputsPlugin, provideBatchOutputsEffect } from "./form-plugins/index.mjs";
|
|
4
4
|
import { useObjectList } from "./hooks/index.mjs";
|
|
5
5
|
import { JsonSchemaTypePresetProvider, JsonSchemaUtils, createDisableDeclarationPlugin, createTypePresetPlugin, useTypeManager } from "./plugins/index.mjs";
|
|
6
6
|
import { FlowValueUtils, createInjectMaterial, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, polyfillCreateRoot, unstableSetCreateRoot, withSuspense } from "./shared/index.mjs";
|
|
7
7
|
import { validateFlowValue } from "./validate/index.mjs";
|
|
8
|
-
export { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, FlowValueUtils, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaEditor, JsonSchemaTypePresetProvider, JsonSchemaUtils, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, autoRenameRefEffect, createBatchOutputsFormPlugin, createDisableDeclarationPlugin, createInferAssignPlugin, createInferInputsPlugin, createInjectMaterial, createTypePresetPlugin, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, getTypeSelectValue, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, listenRefSchemaChange, listenRefValueChange, parseTypeSelectValue, polyfillCreateRoot, provideBatchInputEffect, provideBatchOutputsEffect, provideJsonSchemaOutputs, syncVariableTitle, unstableSetCreateRoot, useCondition, useConditionContext, useObjectList, useTypeManager, useVariableTree, validateFlowValue, validateWhenVariableSync, withSuspense };
|
|
8
|
+
export { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, FlowValueUtils, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaCreator, JsonSchemaEditor, JsonSchemaTypePresetProvider, JsonSchemaUtils, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, autoRenameRefEffect, createBatchOutputsFormPlugin, createDisableDeclarationPlugin, createInferAssignPlugin, createInferInputsPlugin, createInjectMaterial, createTypePresetPlugin, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, getTypeSelectValue, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, listenRefSchemaChange, listenRefValueChange, parseTypeSelectValue, polyfillCreateRoot, provideBatchInputEffect, provideBatchOutputsEffect, provideJsonSchemaOutputs, syncVariableTitle, unstableSetCreateRoot, useCondition, useConditionContext, useObjectList, useTypeManager, useVariableTree, validateFlowValue, validateWhenVariableSync, withSuspense };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/components/index.ts","../src/components/assign-row/index.tsx","../src/components/assign-row/types.ts","../src/components/assign-rows/index.tsx","../src/components/batch-outputs/index.tsx","../src/components/batch-outputs/types.ts","../src/components/batch-variable-selector/index.tsx","../src/components/blur-input/index.tsx","../src/components/code-editor/editor-all.tsx","../src/components/code-editor/editor-json.tsx","../src/components/code-editor/editor-python.tsx","../src/components/code-editor/editor-shell.tsx","../src/components/code-editor/editor-sql.tsx","../src/components/code-editor/editor-ts.tsx","../src/components/code-editor/editor.tsx","../src/components/code-editor/factory.tsx","../src/components/code-editor/index.tsx","../src/components/code-editor/utils.ts","../src/components/code-editor/theme/dark.ts","../src/components/code-editor/theme/index.ts","../src/components/code-editor/theme/light.ts","../src/components/code-editor-mini/index.tsx","../src/components/condition-context/context.tsx","../src/components/condition-context/index.tsx","../src/components/condition-context/op.ts","../src/components/condition-context/types.ts","../src/components/condition-context/hooks/use-condition.tsx","../src/components/condition-row/index.tsx","../src/components/condition-row/types.ts","../src/components/constant-input/index.tsx","../src/components/constant-input/types.ts","../src/components/coze-editor-extensions/index.tsx","../src/components/coze-editor-extensions/extensions/inputs-tree.tsx","../src/components/coze-editor-extensions/extensions/variable-tag.tsx","../src/components/coze-editor-extensions/extensions/variable-tree.tsx","../src/components/db-condition-row/index.tsx","../src/components/db-condition-row/types.ts","../src/components/display-flow-value/index.tsx","../src/components/display-inputs-values/index.tsx","../src/components/display-outputs/index.tsx","../src/components/display-schema-tag/index.tsx","../src/components/display-schema-tree/index.tsx","../src/components/dynamic-value-input/hooks.ts","../src/components/dynamic-value-input/index.tsx","../src/components/inputs-values/index.tsx","../src/components/inputs-values/types.ts","../src/components/inputs-values-tree/icon.tsx","../src/components/inputs-values-tree/index.tsx","../src/components/inputs-values-tree/row.tsx","../src/components/inputs-values-tree/types.ts","../src/components/inputs-values-tree/hooks/use-child-list.tsx","../src/components/json-editor-with-variables/editor.tsx","../src/components/json-editor-with-variables/index.tsx","../src/components/json-schema-editor/default-value.tsx","../src/components/json-schema-editor/hooks.tsx","../src/components/json-schema-editor/icon.tsx","../src/components/json-schema-editor/index.tsx","../src/components/json-schema-editor/types.ts","../src/components/prompt-editor/editor.tsx","../src/components/prompt-editor/index.tsx","../src/components/prompt-editor/types.tsx","../src/components/prompt-editor/extensions/jinja.tsx","../src/components/prompt-editor/extensions/language-support.tsx","../src/components/prompt-editor/extensions/markdown.tsx","../src/components/prompt-editor-with-inputs/index.tsx","../src/components/prompt-editor-with-variables/index.tsx","../src/components/sql-editor-with-variables/editor.tsx","../src/components/sql-editor-with-variables/index.tsx","../src/components/type-selector/index.tsx","../src/components/variable-selector/context.tsx","../src/components/variable-selector/index.tsx","../src/components/variable-selector/use-variable-tree.tsx","../src/effects/index.ts","../src/effects/auto-rename-ref/index.ts","../src/effects/listen-ref-schema-change/index.ts","../src/effects/listen-ref-value-change/index.ts","../src/effects/provide-batch-input/index.ts","../src/effects/provide-json-schema-outputs/index.ts","../src/effects/sync-variable-title/index.ts","../src/effects/validate-when-variable-sync/index.ts","../src/form-plugins/index.ts","../src/form-plugins/batch-outputs-plugin/index.ts","../src/form-plugins/infer-assign-plugin/index.ts","../src/form-plugins/infer-inputs-plugin/index.ts","../src/hooks/index.ts","../src/hooks/use-object-list/index.tsx","../src/plugins/index.ts","../src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts","../src/plugins/disable-declaration-plugin/index.tsx","../src/plugins/json-schema-preset/create-type-preset-plugin.tsx","../src/plugins/json-schema-preset/index.tsx","../src/plugins/json-schema-preset/react.tsx","../src/plugins/json-schema-preset/types.ts","../src/plugins/json-schema-preset/type-definition/array.tsx","../src/plugins/json-schema-preset/type-definition/boolean.tsx","../src/plugins/json-schema-preset/type-definition/date-time.tsx","../src/plugins/json-schema-preset/type-definition/index.tsx","../src/plugins/json-schema-preset/type-definition/integer.tsx","../src/plugins/json-schema-preset/type-definition/map.tsx","../src/plugins/json-schema-preset/type-definition/number.tsx","../src/plugins/json-schema-preset/type-definition/object.tsx","../src/plugins/json-schema-preset/type-definition/string.tsx","../src/shared/index.ts","../src/shared/flow-value/index.ts","../src/shared/flow-value/schema.ts","../src/shared/flow-value/types.ts","../src/shared/flow-value/utils.ts","../src/shared/format-legacy-refs/index.ts","../src/shared/inject-material/index.tsx","../src/shared/lazy-suspense/index.tsx","../src/shared/polyfill-create-root/index.tsx","../src/validate/index.ts","../src/validate/validate-flow-value/index.tsx"],"version":"5.9.2"}
|
|
1
|
+
{"root":["../src/index.ts","../src/components/index.ts","../src/components/assign-row/index.tsx","../src/components/assign-row/types.ts","../src/components/assign-rows/index.tsx","../src/components/batch-outputs/index.tsx","../src/components/batch-outputs/types.ts","../src/components/batch-variable-selector/index.tsx","../src/components/blur-input/index.tsx","../src/components/code-editor/editor-all.tsx","../src/components/code-editor/editor-json.tsx","../src/components/code-editor/editor-python.tsx","../src/components/code-editor/editor-shell.tsx","../src/components/code-editor/editor-sql.tsx","../src/components/code-editor/editor-ts.tsx","../src/components/code-editor/editor.tsx","../src/components/code-editor/factory.tsx","../src/components/code-editor/index.tsx","../src/components/code-editor/utils.ts","../src/components/code-editor/theme/dark.ts","../src/components/code-editor/theme/index.ts","../src/components/code-editor/theme/light.ts","../src/components/code-editor-mini/index.tsx","../src/components/condition-context/context.tsx","../src/components/condition-context/index.tsx","../src/components/condition-context/op.ts","../src/components/condition-context/types.ts","../src/components/condition-context/hooks/use-condition.tsx","../src/components/condition-row/index.tsx","../src/components/condition-row/types.ts","../src/components/constant-input/index.tsx","../src/components/constant-input/types.ts","../src/components/coze-editor-extensions/index.tsx","../src/components/coze-editor-extensions/extensions/inputs-tree.tsx","../src/components/coze-editor-extensions/extensions/variable-tag.tsx","../src/components/coze-editor-extensions/extensions/variable-tree.tsx","../src/components/db-condition-row/index.tsx","../src/components/db-condition-row/types.ts","../src/components/display-flow-value/index.tsx","../src/components/display-inputs-values/index.tsx","../src/components/display-outputs/index.tsx","../src/components/display-schema-tag/index.tsx","../src/components/display-schema-tree/index.tsx","../src/components/dynamic-value-input/hooks.ts","../src/components/dynamic-value-input/index.tsx","../src/components/inputs-values/index.tsx","../src/components/inputs-values/types.ts","../src/components/inputs-values-tree/icon.tsx","../src/components/inputs-values-tree/index.tsx","../src/components/inputs-values-tree/row.tsx","../src/components/inputs-values-tree/types.ts","../src/components/inputs-values-tree/hooks/use-child-list.tsx","../src/components/json-editor-with-variables/editor.tsx","../src/components/json-editor-with-variables/index.tsx","../src/components/json-schema-creator/index.tsx","../src/components/json-schema-creator/json-input-modal.tsx","../src/components/json-schema-creator/json-schema-creator.tsx","../src/components/json-schema-creator/utils/json-to-schema.ts","../src/components/json-schema-editor/default-value.tsx","../src/components/json-schema-editor/hooks.tsx","../src/components/json-schema-editor/icon.tsx","../src/components/json-schema-editor/index.tsx","../src/components/json-schema-editor/types.ts","../src/components/prompt-editor/editor.tsx","../src/components/prompt-editor/index.tsx","../src/components/prompt-editor/types.tsx","../src/components/prompt-editor/extensions/jinja.tsx","../src/components/prompt-editor/extensions/language-support.tsx","../src/components/prompt-editor/extensions/markdown.tsx","../src/components/prompt-editor-with-inputs/index.tsx","../src/components/prompt-editor-with-variables/index.tsx","../src/components/sql-editor-with-variables/editor.tsx","../src/components/sql-editor-with-variables/index.tsx","../src/components/type-selector/index.tsx","../src/components/variable-selector/context.tsx","../src/components/variable-selector/index.tsx","../src/components/variable-selector/use-variable-tree.tsx","../src/effects/index.ts","../src/effects/auto-rename-ref/index.ts","../src/effects/listen-ref-schema-change/index.ts","../src/effects/listen-ref-value-change/index.ts","../src/effects/provide-batch-input/index.ts","../src/effects/provide-json-schema-outputs/index.ts","../src/effects/sync-variable-title/index.ts","../src/effects/validate-when-variable-sync/index.ts","../src/form-plugins/index.ts","../src/form-plugins/batch-outputs-plugin/index.ts","../src/form-plugins/infer-assign-plugin/index.ts","../src/form-plugins/infer-inputs-plugin/index.ts","../src/hooks/index.ts","../src/hooks/use-object-list/index.tsx","../src/plugins/index.ts","../src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts","../src/plugins/disable-declaration-plugin/index.tsx","../src/plugins/json-schema-preset/create-type-preset-plugin.tsx","../src/plugins/json-schema-preset/index.tsx","../src/plugins/json-schema-preset/react.tsx","../src/plugins/json-schema-preset/types.ts","../src/plugins/json-schema-preset/type-definition/array.tsx","../src/plugins/json-schema-preset/type-definition/boolean.tsx","../src/plugins/json-schema-preset/type-definition/date-time.tsx","../src/plugins/json-schema-preset/type-definition/index.tsx","../src/plugins/json-schema-preset/type-definition/integer.tsx","../src/plugins/json-schema-preset/type-definition/map.tsx","../src/plugins/json-schema-preset/type-definition/number.tsx","../src/plugins/json-schema-preset/type-definition/object.tsx","../src/plugins/json-schema-preset/type-definition/string.tsx","../src/shared/index.ts","../src/shared/flow-value/index.ts","../src/shared/flow-value/schema.ts","../src/shared/flow-value/types.ts","../src/shared/flow-value/utils.ts","../src/shared/format-legacy-refs/index.ts","../src/shared/inject-material/index.tsx","../src/shared/lazy-suspense/index.tsx","../src/shared/polyfill-create-root/index.tsx","../src/validate/index.ts","../src/validate/validate-flow-value/index.tsx"],"version":"5.9.2"}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { AssignValueType } from '../assign-row';
|
|
6
7
|
interface AssignRowsProps {
|
|
7
8
|
name: string;
|
|
8
9
|
readonly?: boolean;
|
|
10
|
+
defaultValue?: AssignValueType[];
|
|
9
11
|
}
|
|
10
12
|
export declare function AssignRows(props: AssignRowsProps): React.JSX.Element;
|
|
11
13
|
export {};
|
|
@@ -10,6 +10,7 @@ interface PropsType {
|
|
|
10
10
|
showIconInTree?: boolean;
|
|
11
11
|
displayFromScope?: boolean;
|
|
12
12
|
typeManager?: JsonSchemaTypeManager;
|
|
13
|
+
style?: React.CSSProperties;
|
|
13
14
|
}
|
|
14
|
-
export declare function DisplayOutputs({ value, showIconInTree, displayFromScope }: PropsType): React.JSX.Element;
|
|
15
|
+
export declare function DisplayOutputs({ value, showIconInTree, displayFromScope, style }: PropsType): React.JSX.Element;
|
|
15
16
|
export {};
|
|
@@ -23,6 +23,7 @@ export { DynamicValueInput, InjectDynamicValueInput } from './dynamic-value-inpu
|
|
|
23
23
|
export { InputsValues } from './inputs-values';
|
|
24
24
|
export { InputsValuesTree } from './inputs-values-tree';
|
|
25
25
|
export { JsonEditorWithVariables, type JsonEditorWithVariablesProps, } from './json-editor-with-variables';
|
|
26
|
+
export { JsonSchemaCreator, type JsonSchemaCreatorProps } from './json-schema-creator';
|
|
26
27
|
export { JsonSchemaEditor } from './json-schema-editor';
|
|
27
28
|
export { PromptEditor, type PromptEditorPropsType } from './prompt-editor';
|
|
28
29
|
export { PromptEditorWithInputs, type PromptEditorWithInputsProps, } from './prompt-editor-with-inputs';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
interface JsonInputModalProps {
|
|
8
|
+
visible: boolean;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
onConfirm: (schema: IJsonSchema) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function JsonInputModal({ visible, onClose, onConfirm }: JsonInputModalProps): React.JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
export interface JsonSchemaCreatorProps {
|
|
8
|
+
/** 生成 schema 后的回调 */
|
|
9
|
+
onSchemaCreate?: (schema: IJsonSchema) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function JsonSchemaCreator({ onSchemaCreate }: JsonSchemaCreatorProps): React.JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
-
export { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaEditor, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, getTypeSelectValue, parseTypeSelectValue, type AssignValueType, type CodeEditorPropsType, type ConditionOpConfig, type ConditionOpConfigs, type ConditionRowValueType, type ConstantInputStrategy, type DBConditionOptionType, type DBConditionRowValueType, type IConditionRule, type IConditionRuleFactory, type JsonEditorWithVariablesProps, type PromptEditorPropsType, type PromptEditorWithInputsProps, type PromptEditorWithVariablesProps, type SQLEditorWithVariablesProps, type TypeSelectorProps, type VariableSelectorProps, useCondition, useConditionContext, useVariableTree, } from './components';
|
|
5
|
+
export { AssignRow, AssignRows, BaseCodeEditor, BatchOutputs, BatchVariableSelector, BlurInput, CodeEditor, CodeEditorMini, ConditionPresetOp, ConditionProvider, ConditionRow, ConstantInput, DBConditionRow, DisplayFlowValue, DisplayInputsValueAllInTag, DisplayInputsValues, DisplayOutputs, DisplaySchemaTag, DisplaySchemaTree, DynamicValueInput, EditorInputsTree, EditorVariableTagInject, EditorVariableTree, InjectDynamicValueInput, InjectTypeSelector, InjectVariableSelector, InputsValues, InputsValuesTree, JsonCodeEditor, JsonEditorWithVariables, JsonSchemaCreator, JsonSchemaEditor, PromptEditor, PromptEditorWithInputs, PromptEditorWithVariables, PythonCodeEditor, SQLCodeEditor, SQLEditorWithVariables, ShellCodeEditor, TypeScriptCodeEditor, TypeSelector, VariableSelector, VariableSelectorProvider, getTypeSelectValue, parseTypeSelectValue, type AssignValueType, type CodeEditorPropsType, type ConditionOpConfig, type ConditionOpConfigs, type ConditionRowValueType, type ConstantInputStrategy, type DBConditionOptionType, type DBConditionRowValueType, type IConditionRule, type IConditionRuleFactory, type JsonEditorWithVariablesProps, type JsonSchemaCreatorProps, type PromptEditorPropsType, type PromptEditorWithInputsProps, type PromptEditorWithVariablesProps, type SQLEditorWithVariablesProps, type TypeSelectorProps, type VariableSelectorProps, useCondition, useConditionContext, useVariableTree, } from './components';
|
|
6
6
|
export { autoRenameRefEffect, listenRefSchemaChange, listenRefValueChange, provideBatchInputEffect, provideJsonSchemaOutputs, syncVariableTitle, validateWhenVariableSync, } from './effects';
|
|
7
7
|
export { createBatchOutputsFormPlugin, createInferAssignPlugin, createInferInputsPlugin, provideBatchOutputsEffect, } from './form-plugins';
|
|
8
8
|
export { useObjectList } from './hooks';
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
+
import { type PluginCreator } from '@flowgram.ai/editor';
|
|
5
6
|
import { JsonSchemaTypeRegistry } from './types';
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
type TypePresetRegistry = Partial<JsonSchemaTypeRegistry> & Pick<JsonSchemaTypeRegistry, 'type'>;
|
|
8
|
+
interface TypePresetPluginOptions {
|
|
9
|
+
types?: TypePresetRegistry[];
|
|
8
10
|
unregisterTypes?: string[];
|
|
9
|
-
}
|
|
11
|
+
}
|
|
12
|
+
export declare const createTypePresetPlugin: PluginCreator<TypePresetPluginOptions>;
|
|
13
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"@codemirror/view": "~6.38.0",
|
|
68
68
|
"@codemirror/state": "~6.5.2",
|
|
69
69
|
"zod": "^3.24.4",
|
|
70
|
-
"@flowgram.ai/editor": "0.1.0-alpha.
|
|
71
|
-
"@flowgram.ai/
|
|
72
|
-
"@flowgram.ai/
|
|
70
|
+
"@flowgram.ai/editor": "0.1.0-alpha.21",
|
|
71
|
+
"@flowgram.ai/json-schema": "0.1.0-alpha.21",
|
|
72
|
+
"@flowgram.ai/coze-editor": "0.1.0-alpha.21"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"cross-env": "~7.0.3",
|
|
87
87
|
"@rsbuild/plugin-react": "^1.1.1",
|
|
88
88
|
"date-fns": "~4.1.0",
|
|
89
|
-
"@flowgram.ai/
|
|
90
|
-
"@flowgram.ai/
|
|
89
|
+
"@flowgram.ai/ts-config": "0.1.0-alpha.21",
|
|
90
|
+
"@flowgram.ai/eslint-config": "0.1.0-alpha.21"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"react": ">=16.8",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import { FieldArray
|
|
8
|
+
import { FieldArray } from '@flowgram.ai/editor';
|
|
9
9
|
import { Button } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconPlus } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
@@ -14,15 +14,16 @@ import { AssignRow, AssignValueType } from '@/components/assign-row';
|
|
|
14
14
|
interface AssignRowsProps {
|
|
15
15
|
name: string;
|
|
16
16
|
readonly?: boolean;
|
|
17
|
+
defaultValue?: AssignValueType[];
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export function AssignRows(props: AssignRowsProps) {
|
|
20
|
-
const { name, readonly } = props;
|
|
21
|
+
const { name, readonly, defaultValue } = props;
|
|
21
22
|
|
|
22
23
|
return (
|
|
23
|
-
<FieldArray name={name}>
|
|
24
|
-
{({ field }
|
|
25
|
-
|
|
24
|
+
<FieldArray<AssignValueType | undefined> name={name} defaultValue={defaultValue}>
|
|
25
|
+
{({ field }) => (
|
|
26
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 5 }}>
|
|
26
27
|
{field.map((childField, index) => (
|
|
27
28
|
<AssignRow
|
|
28
29
|
key={childField.key}
|
|
@@ -52,7 +53,7 @@ export function AssignRows(props: AssignRowsProps) {
|
|
|
52
53
|
Declaration
|
|
53
54
|
</Button>
|
|
54
55
|
</div>
|
|
55
|
-
|
|
56
|
+
</div>
|
|
56
57
|
)}
|
|
57
58
|
</FieldArray>
|
|
58
59
|
);
|
|
@@ -125,6 +125,10 @@ export function useCondition({
|
|
|
125
125
|
|
|
126
126
|
// When type of target schema updated, clear it
|
|
127
127
|
useEffect(() => {
|
|
128
|
+
if (!prevTargetSchemaRef.current) {
|
|
129
|
+
prevTargetSchemaRef.current = targetSchema;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
128
132
|
if (prevTargetSchemaRef.current?.type !== targetSchema?.type) {
|
|
129
133
|
onClearRight?.();
|
|
130
134
|
}
|
|
@@ -107,17 +107,25 @@ class VariableTagWidget extends WidgetType {
|
|
|
107
107
|
})
|
|
108
108
|
);
|
|
109
109
|
|
|
110
|
+
const refresh = () => {
|
|
111
|
+
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
112
|
+
};
|
|
113
|
+
|
|
110
114
|
this.toDispose.push(
|
|
111
|
-
this.scope.available.trackByKeyPath(
|
|
112
|
-
this.keyPath,
|
|
113
|
-
(v) => {
|
|
114
|
-
this.renderVariable(v);
|
|
115
|
-
},
|
|
116
|
-
{ triggerOnInit: false }
|
|
117
|
-
)
|
|
115
|
+
this.scope.available.trackByKeyPath(this.keyPath, refresh, { triggerOnInit: false })
|
|
118
116
|
);
|
|
119
117
|
|
|
120
|
-
|
|
118
|
+
if (this.keyPath?.[0]) {
|
|
119
|
+
this.toDispose.push(
|
|
120
|
+
// listen to root title changed
|
|
121
|
+
this.scope.available.trackByKeyPath<{ title?: string }>([this.keyPath[0]], refresh, {
|
|
122
|
+
selector: (curr) => ({ ...curr?.meta }),
|
|
123
|
+
triggerOnInit: false,
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
refresh();
|
|
121
129
|
|
|
122
130
|
return dom;
|
|
123
131
|
}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
+
import { debounce } from 'lodash-es';
|
|
8
9
|
import {
|
|
9
10
|
Mention,
|
|
10
11
|
MentionOpenChangeEvent,
|
|
@@ -69,6 +70,11 @@ export function VariableTree({
|
|
|
69
70
|
|
|
70
71
|
const treeData = useVariableTree({});
|
|
71
72
|
|
|
73
|
+
const debounceUpdatePosKey = useCallback(
|
|
74
|
+
debounce(() => setPosKey(String(Math.random())), 100),
|
|
75
|
+
[]
|
|
76
|
+
);
|
|
77
|
+
|
|
72
78
|
return (
|
|
73
79
|
<>
|
|
74
80
|
<Mention triggerCharacters={triggerCharacters} onOpenChange={handleOpenChange} />
|
|
@@ -82,8 +88,9 @@ export function VariableTree({
|
|
|
82
88
|
<div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
|
|
83
89
|
<Tree
|
|
84
90
|
treeData={treeData}
|
|
85
|
-
onExpand={(
|
|
86
|
-
|
|
91
|
+
onExpand={() => {
|
|
92
|
+
// When Expand, an animation is triggered, so we need to update the position by debounce
|
|
93
|
+
debounceUpdatePosKey();
|
|
87
94
|
}}
|
|
88
95
|
onSelect={(v) => {
|
|
89
96
|
insert(v);
|
|
@@ -96,7 +103,10 @@ export function VariableTree({
|
|
|
96
103
|
<PositionMirror
|
|
97
104
|
position={position}
|
|
98
105
|
// When Doc scroll, update position
|
|
99
|
-
onChange={() =>
|
|
106
|
+
onChange={() => {
|
|
107
|
+
// Update immediately to avoid the popover position lagging behind the cursor
|
|
108
|
+
setPosKey(String(Math.random()));
|
|
109
|
+
}}
|
|
100
110
|
/>
|
|
101
111
|
</Popover>
|
|
102
112
|
</>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React, {
|
|
6
|
+
import React, { useLayoutEffect } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema, JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useCurrentScope, useRefresh } from '@flowgram.ai/editor';
|
|
@@ -17,13 +17,14 @@ interface PropsType {
|
|
|
17
17
|
showIconInTree?: boolean;
|
|
18
18
|
displayFromScope?: boolean;
|
|
19
19
|
typeManager?: JsonSchemaTypeManager;
|
|
20
|
+
style?: React.CSSProperties;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export function DisplayOutputs({ value, showIconInTree, displayFromScope }: PropsType) {
|
|
23
|
+
export function DisplayOutputs({ value, showIconInTree, displayFromScope, style }: PropsType) {
|
|
23
24
|
const scope = useCurrentScope();
|
|
24
25
|
const refresh = useRefresh();
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
useLayoutEffect(() => {
|
|
27
28
|
if (!displayFromScope || !scope) {
|
|
28
29
|
return () => null;
|
|
29
30
|
}
|
|
@@ -50,7 +51,7 @@ export function DisplayOutputs({ value, showIconInTree, displayFromScope }: Prop
|
|
|
50
51
|
const childEntries = Object.entries(properties || {});
|
|
51
52
|
|
|
52
53
|
return (
|
|
53
|
-
<div className="gedit-m-display-outputs-wrapper">
|
|
54
|
+
<div className="gedit-m-display-outputs-wrapper" style={style}>
|
|
54
55
|
{childEntries.map(([key, schema]) => (
|
|
55
56
|
<DisplaySchemaTag
|
|
56
57
|
key={key}
|
package/src/components/index.ts
CHANGED
|
@@ -53,6 +53,7 @@ export {
|
|
|
53
53
|
JsonEditorWithVariables,
|
|
54
54
|
type JsonEditorWithVariablesProps,
|
|
55
55
|
} from './json-editor-with-variables';
|
|
56
|
+
export { JsonSchemaCreator, type JsonSchemaCreatorProps } from './json-schema-creator';
|
|
56
57
|
export { JsonSchemaEditor } from './json-schema-editor';
|
|
57
58
|
export { PromptEditor, type PromptEditorPropsType } from './prompt-editor';
|
|
58
59
|
export {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import type { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
10
|
+
import { Modal, Typography } from '@douyinfe/semi-ui';
|
|
11
|
+
|
|
12
|
+
import { jsonToSchema } from './utils/json-to-schema';
|
|
13
|
+
import { JsonCodeEditor } from '../code-editor';
|
|
14
|
+
|
|
15
|
+
const { Text } = Typography;
|
|
16
|
+
|
|
17
|
+
interface JsonInputModalProps {
|
|
18
|
+
visible: boolean;
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
onConfirm: (schema: IJsonSchema) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function JsonInputModal({ visible, onClose, onConfirm }: JsonInputModalProps) {
|
|
24
|
+
const [jsonInput, setJsonInput] = useState('');
|
|
25
|
+
const [error, setError] = useState('');
|
|
26
|
+
|
|
27
|
+
const handleConfirm = () => {
|
|
28
|
+
try {
|
|
29
|
+
const schema = jsonToSchema(jsonInput);
|
|
30
|
+
onConfirm(schema);
|
|
31
|
+
setJsonInput('');
|
|
32
|
+
setError('');
|
|
33
|
+
} catch (err) {
|
|
34
|
+
setError((err as Error).message);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Modal
|
|
40
|
+
visible={visible}
|
|
41
|
+
onCancel={onClose}
|
|
42
|
+
onOk={handleConfirm}
|
|
43
|
+
title={I18n.t('JSON to JSONSchema')}
|
|
44
|
+
okText={I18n.t('Generate')}
|
|
45
|
+
cancelText={I18n.t('Cancel')}
|
|
46
|
+
width={600}
|
|
47
|
+
>
|
|
48
|
+
<div style={{ marginBottom: 8 }}>
|
|
49
|
+
<Text>{I18n.t('Paste JSON data')}:</Text>
|
|
50
|
+
</div>
|
|
51
|
+
<div style={{ minHeight: 300 }}>
|
|
52
|
+
<JsonCodeEditor value={jsonInput} onChange={(value) => setJsonInput(value || '')} />
|
|
53
|
+
</div>
|
|
54
|
+
{error && (
|
|
55
|
+
<div style={{ marginTop: 8 }}>
|
|
56
|
+
<Text type="danger">{error}</Text>
|
|
57
|
+
</div>
|
|
58
|
+
)}
|
|
59
|
+
</Modal>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import type { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
10
|
+
import { Button } from '@douyinfe/semi-ui';
|
|
11
|
+
|
|
12
|
+
import { JsonInputModal } from './json-input-modal';
|
|
13
|
+
|
|
14
|
+
export interface JsonSchemaCreatorProps {
|
|
15
|
+
/** 生成 schema 后的回调 */
|
|
16
|
+
onSchemaCreate?: (schema: IJsonSchema) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function JsonSchemaCreator({ onSchemaCreate }: JsonSchemaCreatorProps) {
|
|
20
|
+
const [visible, setVisible] = useState(false);
|
|
21
|
+
|
|
22
|
+
const handleCreate = (schema: IJsonSchema) => {
|
|
23
|
+
onSchemaCreate?.(schema);
|
|
24
|
+
setVisible(false);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<Button onClick={() => setVisible(true)}>{I18n.t('JSON to JSONSchema')}</Button>
|
|
30
|
+
<JsonInputModal
|
|
31
|
+
visible={visible}
|
|
32
|
+
onClose={() => setVisible(false)}
|
|
33
|
+
onConfirm={handleCreate}
|
|
34
|
+
/>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|