@flowgram.ai/form-materials 0.1.0-alpha.18 → 0.1.0-alpha.20
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/batch-outputs/index.js +5 -3
- package/dist/cjs/components/batch-outputs/styles.css +13 -0
- package/dist/cjs/components/blur-input/index.js +5 -1
- package/dist/cjs/components/code-editor/editor.js +16 -12
- package/dist/cjs/components/code-editor/styles.css +4 -0
- package/dist/cjs/components/code-editor/theme/dark.js +1 -1
- package/dist/cjs/components/code-editor/theme/light.js +1 -1
- package/dist/cjs/components/code-editor-mini/index.js +2 -16
- package/dist/cjs/components/condition-context/hooks/use-condition.js +21 -1
- package/dist/cjs/components/condition-row/index.js +26 -12
- package/dist/cjs/components/condition-row/styles.css +19 -0
- package/dist/cjs/components/coze-editor-extensions/extensions/inputs-tree.js +2 -2
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tag.js +44 -15
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tree.js +7 -3
- package/dist/{esm/components/coze-editor-extensions/styles.mjs → cjs/components/coze-editor-extensions/styles.css} +19 -18
- package/dist/cjs/components/db-condition-row/index.js +29 -14
- package/dist/cjs/components/db-condition-row/styles.css +30 -0
- package/dist/cjs/components/display-inputs-values/index.js +3 -2
- package/dist/cjs/components/display-inputs-values/styles.css +6 -0
- package/dist/cjs/components/display-outputs/index.js +8 -6
- package/dist/cjs/components/display-outputs/styles.css +6 -0
- package/dist/cjs/components/display-schema-tag/index.js +7 -4
- package/dist/cjs/components/display-schema-tag/styles.css +21 -0
- package/dist/cjs/components/display-schema-tree/index.js +12 -7
- package/dist/cjs/components/display-schema-tree/styles.css +64 -0
- package/dist/cjs/components/dynamic-value-input/index.js +9 -5
- package/dist/{esm/components/dynamic-value-input/styles.mjs → cjs/components/dynamic-value-input/styles.css} +24 -30
- package/dist/cjs/components/index.js +5 -1
- package/dist/cjs/components/inputs-values/index.js +5 -3
- package/dist/cjs/components/inputs-values/styles.css +13 -0
- package/dist/cjs/components/inputs-values-tree/icon.js +70 -0
- package/dist/cjs/components/inputs-values-tree/index.js +4 -3
- package/dist/cjs/components/inputs-values-tree/row.js +19 -15
- package/dist/cjs/components/inputs-values-tree/styles.css +85 -0
- package/dist/cjs/components/{display-inputs-values/styles.js → json-schema-creator/index.js} +4 -19
- package/dist/cjs/components/json-schema-creator/json-input-modal.js +96 -0
- package/dist/cjs/components/{prompt-editor-with-variables/editor.js → json-schema-creator/json-schema-creator.js} +23 -11
- package/dist/cjs/components/{batch-outputs/styles.js → json-schema-creator/utils/json-to-schema.js} +35 -28
- package/dist/cjs/components/json-schema-editor/default-value.js +2 -2
- package/dist/cjs/components/json-schema-editor/hooks.js +55 -48
- package/dist/cjs/components/json-schema-editor/icon.js +70 -0
- package/dist/cjs/components/json-schema-editor/index.js +37 -25
- package/dist/cjs/components/json-schema-editor/styles.css +113 -0
- package/dist/cjs/components/prompt-editor/editor.js +16 -6
- package/dist/cjs/components/prompt-editor/styles.css +10 -0
- package/dist/cjs/components/prompt-editor-with-inputs/index.js +16 -26
- package/dist/cjs/components/prompt-editor-with-variables/index.js +17 -26
- package/dist/cjs/components/variable-selector/context.js +7 -3
- package/dist/cjs/components/variable-selector/index.js +16 -10
- package/dist/{esm/components/variable-selector/styles.mjs → cjs/components/variable-selector/styles.css} +37 -29
- package/dist/cjs/components/variable-selector/use-variable-tree.js +3 -1
- package/dist/cjs/effects/validate-when-variable-sync/index.js +3 -3
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/shared/inject-material/index.js +1 -1
- package/dist/esm/components/assign-rows/index.mjs +9 -3
- package/dist/esm/components/batch-outputs/index.mjs +5 -3
- package/dist/esm/components/batch-outputs/styles.css +13 -0
- package/dist/esm/components/blur-input/index.mjs +5 -1
- package/dist/esm/components/code-editor/editor.mjs +16 -11
- package/dist/esm/components/code-editor/styles.css +4 -0
- package/dist/esm/components/code-editor/theme/dark.mjs +1 -1
- package/dist/esm/components/code-editor/theme/light.mjs +1 -1
- package/dist/esm/components/code-editor-mini/index.mjs +2 -6
- package/dist/esm/components/condition-context/hooks/use-condition.mjs +22 -2
- package/dist/esm/components/condition-row/index.mjs +26 -12
- package/dist/esm/components/condition-row/styles.css +19 -0
- package/dist/esm/components/coze-editor-extensions/extensions/inputs-tree.mjs +3 -3
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +45 -16
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +8 -4
- package/dist/esm/components/coze-editor-extensions/styles.css +37 -0
- package/dist/esm/components/db-condition-row/index.mjs +29 -14
- package/dist/esm/components/db-condition-row/styles.css +30 -0
- package/dist/esm/components/display-inputs-values/index.mjs +3 -2
- package/dist/esm/components/display-inputs-values/styles.css +6 -0
- package/dist/esm/components/display-outputs/index.mjs +9 -7
- package/dist/esm/components/display-outputs/styles.css +6 -0
- package/dist/esm/components/display-schema-tag/index.mjs +8 -5
- package/dist/esm/components/display-schema-tag/styles.css +21 -0
- package/dist/esm/components/display-schema-tree/index.mjs +12 -7
- package/dist/esm/components/display-schema-tree/styles.css +64 -0
- package/dist/esm/components/dynamic-value-input/index.mjs +9 -5
- package/dist/esm/components/dynamic-value-input/styles.css +48 -0
- package/dist/esm/components/index.mjs +2 -1
- package/dist/esm/components/inputs-values/index.mjs +5 -3
- package/dist/esm/components/inputs-values/styles.css +13 -0
- package/dist/esm/components/inputs-values-tree/icon.mjs +26 -0
- package/dist/esm/components/inputs-values-tree/index.mjs +4 -3
- package/dist/esm/components/inputs-values-tree/row.mjs +18 -14
- package/dist/esm/components/inputs-values-tree/styles.css +85 -0
- 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/components/json-schema-editor/default-value.mjs +2 -2
- package/dist/esm/components/json-schema-editor/hooks.mjs +55 -48
- package/dist/esm/components/json-schema-editor/icon.mjs +26 -0
- package/dist/esm/components/json-schema-editor/index.mjs +36 -24
- package/dist/esm/components/json-schema-editor/styles.css +113 -0
- package/dist/esm/components/prompt-editor/editor.mjs +16 -6
- package/dist/esm/components/prompt-editor/styles.css +10 -0
- package/dist/esm/components/prompt-editor-with-inputs/index.mjs +12 -4
- package/dist/esm/components/prompt-editor-with-variables/index.mjs +13 -4
- package/dist/esm/components/variable-selector/context.mjs +7 -3
- package/dist/esm/components/variable-selector/index.mjs +17 -11
- package/{src/components/variable-selector/styles.tsx → dist/esm/components/variable-selector/styles.css} +35 -38
- package/dist/esm/components/variable-selector/use-variable-tree.mjs +3 -1
- package/dist/esm/effects/validate-when-variable-sync/index.mjs +3 -3
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/shared/inject-material/index.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/assign-rows/index.d.ts +2 -0
- package/dist/types/components/batch-outputs/index.d.ts +1 -0
- package/dist/types/components/blur-input/index.d.ts +1 -1
- package/dist/types/components/code-editor/editor.d.ts +1 -0
- package/dist/types/components/condition-context/hooks/use-condition.d.ts +16 -1
- package/dist/types/components/condition-row/index.d.ts +5 -1
- package/dist/types/components/coze-editor-extensions/extensions/inputs-tree.d.ts +3 -3
- package/dist/types/components/coze-editor-extensions/extensions/variable-tag.d.ts +1 -0
- package/dist/types/components/coze-editor-extensions/index.d.ts +1 -1
- package/dist/types/components/db-condition-row/index.d.ts +4 -0
- package/dist/types/components/db-condition-row/types.d.ts +0 -1
- package/dist/types/components/display-inputs-values/index.d.ts +3 -1
- package/dist/types/components/display-outputs/index.d.ts +3 -1
- package/dist/types/components/display-schema-tag/index.d.ts +1 -0
- package/dist/types/components/display-schema-tree/index.d.ts +1 -0
- package/dist/types/components/dynamic-value-input/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/inputs-values/index.d.ts +1 -0
- package/dist/types/components/inputs-values-tree/icon.d.ts +6 -0
- package/dist/types/components/inputs-values-tree/index.d.ts +1 -0
- package/dist/types/components/inputs-values-tree/row.d.ts +1 -0
- package/dist/types/components/inputs-values-tree/types.d.ts +3 -2
- 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/components/json-schema-editor/icon.d.ts +6 -0
- package/dist/types/components/json-schema-editor/index.d.ts +1 -0
- package/dist/types/components/prompt-editor/editor.d.ts +1 -0
- package/dist/types/components/prompt-editor-with-inputs/index.d.ts +7 -2
- package/dist/types/components/prompt-editor-with-variables/index.d.ts +5 -2
- package/dist/types/components/variable-selector/context.d.ts +16 -3
- package/dist/types/components/variable-selector/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +7 -3
- package/dist/types/shared/flow-value/index.d.ts +1 -1
- package/dist/types/shared/flow-value/types.d.ts +3 -0
- package/dist/types/shared/index.d.ts +1 -1
- package/package.json +7 -10
- package/src/components/assign-rows/index.tsx +7 -6
- package/src/components/batch-outputs/index.tsx +5 -5
- package/src/components/batch-outputs/{styles.tsx → styles.css} +4 -6
- package/src/components/blur-input/index.tsx +6 -2
- package/src/components/code-editor/editor.tsx +19 -14
- package/src/components/code-editor/styles.css +11 -0
- package/src/components/code-editor/theme/dark.ts +1 -1
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/code-editor-mini/index.tsx +2 -9
- package/src/components/condition-context/hooks/use-condition.tsx +55 -7
- package/src/components/condition-row/index.tsx +27 -22
- package/src/components/condition-row/{styles.tsx → styles.css} +11 -11
- package/src/components/coze-editor-extensions/extensions/inputs-tree.tsx +7 -6
- package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +35 -22
- package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +14 -4
- package/src/components/coze-editor-extensions/{styles.tsx → styles.css} +8 -11
- package/src/components/db-condition-row/index.tsx +29 -26
- package/src/components/db-condition-row/{styles.tsx → styles.css} +14 -16
- package/src/components/db-condition-row/types.ts +0 -1
- package/src/components/display-inputs-values/index.tsx +5 -4
- package/src/components/display-inputs-values/{styles.ts → styles.css} +2 -4
- package/src/components/display-outputs/index.tsx +9 -8
- package/src/components/display-outputs/{styles.ts → styles.css} +2 -4
- package/src/components/display-schema-tag/index.tsx +7 -7
- package/src/components/display-schema-tag/{styles.ts → styles.css} +7 -10
- package/src/components/display-schema-tree/index.tsx +10 -10
- package/src/components/display-schema-tree/{styles.tsx → styles.css} +18 -24
- package/src/components/dynamic-value-input/index.tsx +6 -6
- package/src/components/dynamic-value-input/{styles.tsx → styles.css} +9 -12
- package/src/components/index.ts +1 -0
- package/src/components/inputs-values/index.tsx +5 -5
- package/src/components/inputs-values/{styles.tsx → styles.css} +4 -6
- package/src/components/inputs-values-tree/icon.tsx +28 -0
- package/src/components/inputs-values-tree/index.tsx +8 -6
- package/src/components/inputs-values-tree/row.tsx +25 -27
- package/src/components/inputs-values-tree/styles.css +94 -0
- package/src/components/inputs-values-tree/types.ts +3 -2
- 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/components/json-schema-editor/default-value.tsx +2 -4
- package/src/components/json-schema-editor/hooks.tsx +60 -53
- package/src/components/json-schema-editor/icon.tsx +28 -0
- package/src/components/json-schema-editor/index.tsx +45 -50
- package/src/components/json-schema-editor/styles.css +135 -0
- package/src/components/prompt-editor/editor.tsx +18 -7
- package/src/components/prompt-editor/styles.css +14 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +18 -5
- package/src/components/prompt-editor-with-variables/index.tsx +13 -5
- package/src/components/variable-selector/context.tsx +22 -2
- package/src/components/variable-selector/index.tsx +24 -14
- package/src/components/variable-selector/styles.css +70 -0
- package/src/components/variable-selector/use-variable-tree.tsx +9 -1
- package/src/effects/validate-when-variable-sync/index.ts +7 -3
- package/src/index.ts +3 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +17 -12
- package/src/shared/flow-value/index.ts +1 -0
- package/src/shared/flow-value/types.ts +4 -0
- package/src/shared/index.ts +1 -0
- package/src/shared/inject-material/index.tsx +1 -1
- package/dist/cjs/components/condition-row/styles.js +0 -77
- package/dist/cjs/components/coze-editor-extensions/styles.js +0 -89
- package/dist/cjs/components/db-condition-row/styles.js +0 -94
- package/dist/cjs/components/display-outputs/styles.js +0 -51
- package/dist/cjs/components/display-schema-tag/styles.js +0 -71
- package/dist/cjs/components/display-schema-tree/styles.js +0 -135
- package/dist/cjs/components/dynamic-value-input/styles.js +0 -107
- package/dist/cjs/components/inputs-values/styles.js +0 -60
- package/dist/cjs/components/inputs-values-tree/styles.js +0 -177
- package/dist/cjs/components/json-schema-editor/styles.js +0 -231
- package/dist/cjs/components/prompt-editor/styles.js +0 -55
- package/dist/cjs/components/prompt-editor-with-inputs/editor.js +0 -47
- package/dist/cjs/components/variable-selector/styles.js +0 -114
- package/dist/esm/components/batch-outputs/styles.mjs +0 -13
- package/dist/esm/components/condition-row/styles.mjs +0 -21
- package/dist/esm/components/db-condition-row/styles.mjs +0 -32
- package/dist/esm/components/display-inputs-values/styles.mjs +0 -7
- package/dist/esm/components/display-outputs/styles.mjs +0 -7
- package/dist/esm/components/display-schema-tag/styles.mjs +0 -21
- package/dist/esm/components/display-schema-tree/styles.mjs +0 -79
- package/dist/esm/components/inputs-values/styles.mjs +0 -13
- package/dist/esm/components/inputs-values-tree/styles.mjs +0 -105
- package/dist/esm/components/json-schema-editor/styles.mjs +0 -138
- package/dist/esm/components/prompt-editor/styles.mjs +0 -11
- package/dist/esm/components/prompt-editor-with-inputs/editor.mjs +0 -13
- package/dist/esm/components/prompt-editor-with-variables/editor.mjs +0 -14
- package/dist/types/components/batch-outputs/styles.d.ts +0 -6
- package/dist/types/components/condition-row/styles.d.ts +0 -9
- package/dist/types/components/coze-editor-extensions/styles.d.ts +0 -9
- package/dist/types/components/db-condition-row/styles.d.ts +0 -12
- package/dist/types/components/display-inputs-values/styles.d.ts +0 -5
- package/dist/types/components/display-outputs/styles.d.ts +0 -5
- package/dist/types/components/display-schema-tag/styles.d.ts +0 -8
- package/dist/types/components/display-schema-tree/styles.d.ts +0 -11
- package/dist/types/components/dynamic-value-input/styles.d.ts +0 -8
- package/dist/types/components/inputs-values/styles.d.ts +0 -6
- package/dist/types/components/inputs-values-tree/styles.d.ts +0 -23
- package/dist/types/components/json-schema-editor/styles.d.ts +0 -30
- package/dist/types/components/prompt-editor/styles.d.ts +0 -7
- package/dist/types/components/prompt-editor-with-inputs/editor.d.ts +0 -10
- package/dist/types/components/prompt-editor-with-variables/editor.d.ts +0 -9
- package/dist/types/components/variable-selector/styles.d.ts +0 -14
- package/src/components/inputs-values-tree/styles.tsx +0 -128
- package/src/components/json-schema-editor/styles.tsx +0 -168
- package/src/components/prompt-editor/styles.tsx +0 -18
- package/src/components/prompt-editor-with-inputs/editor.tsx +0 -24
- package/src/components/prompt-editor-with-variables/editor.tsx +0 -20
- package/src/shared/inject-material/README.md +0 -170
- package/src/shared/inject-material/README.zh.md +0 -174
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
7
|
import { ConfigType } from './types';
|
|
8
|
+
import './styles.css';
|
|
8
9
|
export declare function JsonSchemaEditor(props: {
|
|
9
10
|
value?: IJsonSchema;
|
|
10
11
|
onChange?: (value: IJsonSchema) => void;
|
|
@@ -6,6 +6,7 @@ import React from 'react';
|
|
|
6
6
|
import { InferValues } from '@flowgram.ai/coze-editor/react';
|
|
7
7
|
import preset from '@flowgram.ai/coze-editor/preset-prompt';
|
|
8
8
|
import { PropsType } from './types';
|
|
9
|
+
import './styles.css';
|
|
9
10
|
type Preset = typeof preset;
|
|
10
11
|
type Options = Partial<InferValues<Preset[number]>>;
|
|
11
12
|
export interface PromptEditorPropsType extends PropsType {
|
|
@@ -2,5 +2,10 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { IInputsValues } from '../../shared/flow-value';
|
|
7
|
+
import { PromptEditorPropsType } from '../prompt-editor';
|
|
8
|
+
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
9
|
+
inputsValues: IInputsValues;
|
|
10
|
+
}
|
|
11
|
+
export declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PromptEditorWithInputsProps): React.JSX.Element;
|
|
@@ -2,5 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { PromptEditorPropsType } from '../prompt-editor';
|
|
7
|
+
export interface PromptEditorWithVariablesProps extends PromptEditorPropsType {
|
|
8
|
+
}
|
|
9
|
+
export declare function PromptEditorWithVariables(props: PromptEditorWithVariablesProps): React.JSX.Element;
|
|
@@ -3,14 +3,27 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
6
7
|
import { BaseVariableField } from '@flowgram.ai/editor';
|
|
8
|
+
type VariableField = BaseVariableField<{
|
|
9
|
+
icon?: string | JSX.Element;
|
|
10
|
+
title?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}>;
|
|
7
13
|
export declare const VariableSelectorContext: React.Context<{
|
|
8
|
-
|
|
14
|
+
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
15
|
+
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
16
|
+
skipVariable?: (variable: VariableField) => boolean;
|
|
9
17
|
}>;
|
|
10
18
|
export declare const useVariableSelectorContext: () => {
|
|
11
|
-
|
|
19
|
+
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
20
|
+
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
21
|
+
skipVariable?: (variable: VariableField) => boolean;
|
|
12
22
|
};
|
|
13
|
-
export declare const VariableSelectorProvider: ({ children, skipVariable, }: {
|
|
23
|
+
export declare const VariableSelectorProvider: ({ children, skipVariable, includeSchema, excludeSchema, }: {
|
|
14
24
|
skipVariable?: (variable?: BaseVariableField) => boolean;
|
|
25
|
+
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
26
|
+
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
15
27
|
children: React.ReactNode;
|
|
16
28
|
}) => React.JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -6,6 +6,7 @@ import React from 'react';
|
|
|
6
6
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
7
|
import { type TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
8
8
|
import { useVariableTree } from './use-variable-tree';
|
|
9
|
+
import './styles.css';
|
|
9
10
|
export interface VariableSelectorProps {
|
|
10
11
|
value?: string[];
|
|
11
12
|
config?: {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
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';
|
|
9
9
|
export { JsonSchemaTypePresetProvider, JsonSchemaUtils, createDisableDeclarationPlugin, createTypePresetPlugin, type ConstantRendererProps, type IJsonSchema, type JsonSchemaBasicType, type JsonSchemaTypeRegistry, useTypeManager, } from './plugins';
|
|
10
|
-
export { FlowValueUtils, createInjectMaterial, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, polyfillCreateRoot, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IPolyfillRoot, unstableSetCreateRoot, withSuspense, } from './shared';
|
|
10
|
+
export { FlowValueUtils, createInjectMaterial, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, polyfillCreateRoot, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IInputsValues, type IPolyfillRoot, unstableSetCreateRoot, withSuspense, } from './shared';
|
|
11
11
|
export { validateFlowValue } from './validate';
|
|
@@ -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 {};
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
export { FlowValueUtils } from './utils';
|
|
6
|
-
export { type IFlowValueExtra, type FlowValueType, type IFlowValue, type IFlowConstantValue, type IFlowRefValue, type IFlowExpressionValue, type IFlowTemplateValue, type IFlowConstantRefValue, } from './types';
|
|
6
|
+
export { type IFlowValueExtra, type FlowValueType, type IFlowValue, type IFlowConstantValue, type IFlowRefValue, type IFlowExpressionValue, type IFlowTemplateValue, type IFlowConstantRefValue, type IInputsValues, } from './types';
|
|
@@ -30,3 +30,6 @@ export interface IFlowTemplateValue {
|
|
|
30
30
|
}
|
|
31
31
|
export type IFlowValue = IFlowConstantValue | IFlowRefValue | IFlowExpressionValue | IFlowTemplateValue;
|
|
32
32
|
export type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
|
|
33
|
+
export interface IInputsValues {
|
|
34
|
+
[key: string]: IInputsValues | IFlowValue | undefined;
|
|
35
|
+
}
|
|
@@ -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 { FlowValueUtils, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, } from './flow-value';
|
|
5
|
+
export { FlowValueUtils, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IInputsValues, } from './flow-value';
|
|
6
6
|
export { formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, } from './format-legacy-refs';
|
|
7
7
|
export { createInjectMaterial } from './inject-material';
|
|
8
8
|
export { lazySuspense, withSuspense } from './lazy-suspense';
|
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.20",
|
|
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/
|
|
71
|
-
"@flowgram.ai/
|
|
72
|
-
"@flowgram.ai/
|
|
70
|
+
"@flowgram.ai/coze-editor": "0.1.0-alpha.20",
|
|
71
|
+
"@flowgram.ai/editor": "0.1.0-alpha.20",
|
|
72
|
+
"@flowgram.ai/json-schema": "0.1.0-alpha.20"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -77,24 +77,21 @@
|
|
|
77
77
|
"@types/react": "^18",
|
|
78
78
|
"@types/react-dom": "^18",
|
|
79
79
|
"@types/inquirer": "^9.0.9",
|
|
80
|
-
"@types/styled-components": "^5",
|
|
81
80
|
"eslint": "^8.54.0",
|
|
82
81
|
"react": "^18",
|
|
83
82
|
"react-dom": "^18",
|
|
84
|
-
"styled-components": "^5",
|
|
85
83
|
"typescript": "^5.8.3",
|
|
86
84
|
"vitest": "^3.2.4",
|
|
87
85
|
"@rslib/core": "~0.12.4",
|
|
88
86
|
"cross-env": "~7.0.3",
|
|
89
87
|
"@rsbuild/plugin-react": "^1.1.1",
|
|
90
88
|
"date-fns": "~4.1.0",
|
|
91
|
-
"@flowgram.ai/eslint-config": "0.1.0-alpha.
|
|
92
|
-
"@flowgram.ai/ts-config": "0.1.0-alpha.
|
|
89
|
+
"@flowgram.ai/eslint-config": "0.1.0-alpha.20",
|
|
90
|
+
"@flowgram.ai/ts-config": "0.1.0-alpha.20"
|
|
93
91
|
},
|
|
94
92
|
"peerDependencies": {
|
|
95
93
|
"react": ">=16.8",
|
|
96
|
-
"react-dom": ">=16.8"
|
|
97
|
-
"styled-components": ">=5"
|
|
94
|
+
"react-dom": ">=16.8"
|
|
98
95
|
},
|
|
99
96
|
"publishConfig": {
|
|
100
97
|
"access": "public",
|
|
@@ -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
|
);
|
|
@@ -13,7 +13,7 @@ import { useObjectList } from '@/hooks';
|
|
|
13
13
|
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
14
14
|
|
|
15
15
|
import { PropsType } from './types';
|
|
16
|
-
import
|
|
16
|
+
import './styles.css';
|
|
17
17
|
|
|
18
18
|
export function BatchOutputs(props: PropsType) {
|
|
19
19
|
const { readonly, style } = props;
|
|
@@ -22,9 +22,9 @@ export function BatchOutputs(props: PropsType) {
|
|
|
22
22
|
|
|
23
23
|
return (
|
|
24
24
|
<div>
|
|
25
|
-
<
|
|
25
|
+
<div className="gedit-m-batch-outputs-rows" style={style}>
|
|
26
26
|
{list.map((item) => (
|
|
27
|
-
<
|
|
27
|
+
<div className="gedit-m-batch-outputs-row" key={item.id}>
|
|
28
28
|
<Input
|
|
29
29
|
style={{ width: 100 }}
|
|
30
30
|
disabled={readonly}
|
|
@@ -44,9 +44,9 @@ export function BatchOutputs(props: PropsType) {
|
|
|
44
44
|
size="small"
|
|
45
45
|
onClick={() => remove(item.id)}
|
|
46
46
|
/>
|
|
47
|
-
</
|
|
47
|
+
</div>
|
|
48
48
|
))}
|
|
49
|
-
</
|
|
49
|
+
</div>
|
|
50
50
|
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={() => add()}>
|
|
51
51
|
{I18n.t('Add')}
|
|
52
52
|
</Button>
|
|
@@ -3,17 +3,15 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const UIRows = styled.div`
|
|
6
|
+
.gedit-m-batch-outputs-rows {
|
|
9
7
|
display: flex;
|
|
10
8
|
flex-direction: column;
|
|
11
9
|
gap: 10px;
|
|
12
10
|
margin-bottom: 10px;
|
|
13
|
-
|
|
11
|
+
}
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
.gedit-m-batch-outputs-row {
|
|
16
14
|
display: flex;
|
|
17
15
|
align-items: center;
|
|
18
16
|
gap: 5px;
|
|
19
|
-
|
|
17
|
+
}
|
|
@@ -13,7 +13,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
13
13
|
|
|
14
14
|
import { Input } from '@douyinfe/semi-ui';
|
|
15
15
|
|
|
16
|
-
type InputProps = React.
|
|
16
|
+
type InputProps = React.ComponentPropsWithRef<typeof Input>;
|
|
17
17
|
|
|
18
18
|
export function BlurInput(props: InputProps) {
|
|
19
19
|
const [value, setValue] = useState('');
|
|
@@ -24,12 +24,16 @@ export function BlurInput(props: InputProps) {
|
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<Input
|
|
27
|
+
ref={props.ref}
|
|
27
28
|
{...props}
|
|
28
29
|
value={value}
|
|
29
30
|
onChange={(value) => {
|
|
30
31
|
setValue(value);
|
|
31
32
|
}}
|
|
32
|
-
onBlur={(e) =>
|
|
33
|
+
onBlur={(e) => {
|
|
34
|
+
props.onChange?.(value, e);
|
|
35
|
+
props.onBlur?.(e);
|
|
36
|
+
}}
|
|
33
37
|
/>
|
|
34
38
|
);
|
|
35
39
|
}
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useEffect, useRef } from 'react';
|
|
7
7
|
|
|
8
|
-
import styled, { css } from 'styled-components';
|
|
9
8
|
import {
|
|
10
9
|
ActiveLinePlaceholder,
|
|
11
10
|
createRenderer,
|
|
@@ -17,6 +16,8 @@ import { EditorView } from '@codemirror/view';
|
|
|
17
16
|
|
|
18
17
|
import { getSuffixByLanguageId } from './utils';
|
|
19
18
|
|
|
19
|
+
import './styles.css';
|
|
20
|
+
|
|
20
21
|
const OriginCodeEditor = createRenderer(preset, [
|
|
21
22
|
EditorView.theme({
|
|
22
23
|
'&.cm-focused': {
|
|
@@ -25,13 +26,7 @@ const OriginCodeEditor = createRenderer(preset, [
|
|
|
25
26
|
}),
|
|
26
27
|
]);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
${({ $mini }) =>
|
|
30
|
-
$mini &&
|
|
31
|
-
css`
|
|
32
|
-
height: 24px;
|
|
33
|
-
`}
|
|
34
|
-
`;
|
|
29
|
+
// CSS styles are in styles.css
|
|
35
30
|
|
|
36
31
|
type Preset = typeof preset;
|
|
37
32
|
type Options = Partial<InferValues<Preset[number]>>;
|
|
@@ -62,18 +57,28 @@ export function BaseCodeEditor({
|
|
|
62
57
|
}: CodeEditorPropsType) {
|
|
63
58
|
const editorRef = useRef<EditorAPI | null>(null);
|
|
64
59
|
|
|
60
|
+
const editorValue = String(value || '');
|
|
61
|
+
|
|
65
62
|
useEffect(() => {
|
|
66
63
|
// listen to value change
|
|
67
|
-
if (editorRef.current?.getValue() !==
|
|
68
|
-
|
|
64
|
+
if (editorRef.current?.getValue() !== editorValue) {
|
|
65
|
+
// apply updates on readonly mode
|
|
66
|
+
const editorView = editorRef.current?.$view;
|
|
67
|
+
editorView?.dispatch({
|
|
68
|
+
changes: {
|
|
69
|
+
from: 0,
|
|
70
|
+
to: editorView?.state.doc.length,
|
|
71
|
+
insert: editorValue,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
69
74
|
}
|
|
70
|
-
}, [
|
|
75
|
+
}, [editorValue]);
|
|
71
76
|
|
|
72
77
|
return (
|
|
73
|
-
<
|
|
78
|
+
<div className={`gedit-m-code-editor-container ${mini ? 'mini' : ''}`}>
|
|
74
79
|
<EditorProvider>
|
|
75
80
|
<OriginCodeEditor
|
|
76
|
-
defaultValue={
|
|
81
|
+
defaultValue={editorValue}
|
|
77
82
|
options={{
|
|
78
83
|
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
79
84
|
languageId,
|
|
@@ -101,6 +106,6 @@ export function BaseCodeEditor({
|
|
|
101
106
|
{children}
|
|
102
107
|
</OriginCodeEditor>
|
|
103
108
|
</EditorProvider>
|
|
104
|
-
</
|
|
109
|
+
</div>
|
|
105
110
|
);
|
|
106
111
|
}
|
|
@@ -47,7 +47,7 @@ export const darkTheme: Extension = createTheme({
|
|
|
47
47
|
gutterForeground: colors.foreground,
|
|
48
48
|
gutterBorderColor: 'transparent',
|
|
49
49
|
gutterBorderWidth: 0,
|
|
50
|
-
lineHighlight: '
|
|
50
|
+
lineHighlight: 'transparent',
|
|
51
51
|
bracketColors: ['#FBBF24', '#A78BFA', '#7DD3FC'],
|
|
52
52
|
tooltip: {
|
|
53
53
|
backgroundColor: '#21262D',
|
|
@@ -42,7 +42,7 @@ export const lightTheme: Extension = createTheme({
|
|
|
42
42
|
gutterForeground: colors.foreground,
|
|
43
43
|
gutterBorderColor: 'transparent',
|
|
44
44
|
gutterBorderWidth: 0,
|
|
45
|
-
lineHighlight:
|
|
45
|
+
lineHighlight: 'transparent',
|
|
46
46
|
bracketColors: ['#F59E0B', '#8B5CF6', '#06B6D4'],
|
|
47
47
|
tooltip: {
|
|
48
48
|
backgroundColor: colors.dropdownBackground,
|
|
@@ -5,21 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import styled from 'styled-components';
|
|
9
|
-
|
|
10
8
|
import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
|
|
11
9
|
|
|
12
|
-
const UIMini = styled.div`
|
|
13
|
-
.ͼ1 .cm-content {
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
10
|
/**
|
|
18
11
|
* @deprecated use mini in CodeEditorPropsType instead
|
|
19
12
|
*/
|
|
20
13
|
export function CodeEditorMini(props: CodeEditorPropsType) {
|
|
21
14
|
return (
|
|
22
|
-
<
|
|
15
|
+
<div className="gedit-m-code-editor-mini">
|
|
23
16
|
<CodeEditor
|
|
24
17
|
{...props}
|
|
25
18
|
options={{
|
|
@@ -29,6 +22,6 @@ export function CodeEditorMini(props: CodeEditorPropsType) {
|
|
|
29
22
|
...(props.options || {}),
|
|
30
23
|
}}
|
|
31
24
|
/>
|
|
32
|
-
</
|
|
25
|
+
</div>
|
|
33
26
|
);
|
|
34
27
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useMemo } from 'react';
|
|
6
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { I18n } from '@flowgram.ai/editor';
|
|
@@ -14,10 +14,28 @@ import { IConditionRule, ConditionOpConfigs } from '../types';
|
|
|
14
14
|
import { useConditionContext } from '../context';
|
|
15
15
|
|
|
16
16
|
interface HooksParams {
|
|
17
|
+
/**
|
|
18
|
+
* Left schema of condition
|
|
19
|
+
*/
|
|
17
20
|
leftSchema?: IJsonSchema;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Operator of condition
|
|
24
|
+
*/
|
|
18
25
|
operator?: string;
|
|
19
26
|
|
|
20
27
|
/**
|
|
28
|
+
* If op is not in opOptionList, clear it
|
|
29
|
+
*/
|
|
30
|
+
onClearOp?: () => void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* If targetSchema updated, clear it
|
|
34
|
+
*/
|
|
35
|
+
onClearRight?: () => void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated use ConditionProvider instead
|
|
21
39
|
* custom rule config
|
|
22
40
|
*/
|
|
23
41
|
ruleConfig?: {
|
|
@@ -26,26 +44,32 @@ interface HooksParams {
|
|
|
26
44
|
};
|
|
27
45
|
}
|
|
28
46
|
|
|
29
|
-
export function useCondition({
|
|
47
|
+
export function useCondition({
|
|
48
|
+
leftSchema,
|
|
49
|
+
operator,
|
|
50
|
+
onClearOp,
|
|
51
|
+
onClearRight,
|
|
52
|
+
ruleConfig,
|
|
53
|
+
}: HooksParams) {
|
|
30
54
|
const typeManager = useTypeManager();
|
|
31
55
|
const { rules: contextRules, ops: contextOps } = useConditionContext();
|
|
32
56
|
|
|
33
|
-
//
|
|
57
|
+
// Merge user rules and context rules
|
|
34
58
|
const userRules = useMemo(
|
|
35
59
|
() => ruleConfig?.rules || contextRules || {},
|
|
36
60
|
[contextRules, ruleConfig?.rules]
|
|
37
61
|
);
|
|
38
62
|
|
|
39
|
-
//
|
|
63
|
+
// Merge user operators and context operators
|
|
40
64
|
const allOps = useMemo(() => ruleConfig?.ops || contextOps || {}, [contextOps, ruleConfig?.ops]);
|
|
41
65
|
|
|
42
|
-
//
|
|
66
|
+
// Get type configuration
|
|
43
67
|
const config = useMemo(
|
|
44
68
|
() => (leftSchema ? typeManager.getTypeBySchema(leftSchema) : undefined),
|
|
45
69
|
[leftSchema, typeManager]
|
|
46
70
|
);
|
|
47
71
|
|
|
48
|
-
//
|
|
72
|
+
// Calculate rule
|
|
49
73
|
const rule = useMemo(() => {
|
|
50
74
|
if (!config) {
|
|
51
75
|
return undefined;
|
|
@@ -59,7 +83,7 @@ export function useCondition({ leftSchema, operator, ruleConfig }: HooksParams)
|
|
|
59
83
|
return config.conditionRule;
|
|
60
84
|
}, [userRules, leftSchema, config]);
|
|
61
85
|
|
|
62
|
-
//
|
|
86
|
+
// Calculate operator option list
|
|
63
87
|
const opOptionList = useMemo(
|
|
64
88
|
() =>
|
|
65
89
|
Object.keys(rule || {})
|
|
@@ -72,6 +96,16 @@ export function useCondition({ leftSchema, operator, ruleConfig }: HooksParams)
|
|
|
72
96
|
[rule, allOps]
|
|
73
97
|
);
|
|
74
98
|
|
|
99
|
+
// When op not in list, clear it
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!operator || !rule) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!opOptionList.find((item) => item.value === operator)) {
|
|
105
|
+
onClearOp?.();
|
|
106
|
+
}
|
|
107
|
+
}, [operator, opOptionList, onClearOp]);
|
|
108
|
+
|
|
75
109
|
// get target schema
|
|
76
110
|
const targetSchema = useMemo(() => {
|
|
77
111
|
const targetType: string | IJsonSchema | null = rule?.[operator || ''] || null;
|
|
@@ -87,6 +121,20 @@ export function useCondition({ leftSchema, operator, ruleConfig }: HooksParams)
|
|
|
87
121
|
return targetType;
|
|
88
122
|
}, [rule, operator]);
|
|
89
123
|
|
|
124
|
+
const prevTargetSchemaRef = useRef<IJsonSchema | undefined>(undefined);
|
|
125
|
+
|
|
126
|
+
// When type of target schema updated, clear it
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (!prevTargetSchemaRef.current) {
|
|
129
|
+
prevTargetSchemaRef.current = targetSchema;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (prevTargetSchemaRef.current?.type !== targetSchema?.type) {
|
|
133
|
+
onClearRight?.();
|
|
134
|
+
}
|
|
135
|
+
prevTargetSchemaRef.current = targetSchema;
|
|
136
|
+
}, [targetSchema, onClearRight]);
|
|
137
|
+
|
|
90
138
|
// get current operator config
|
|
91
139
|
const opConfig = useMemo(() => allOps[operator || ''], [operator, allOps]);
|
|
92
140
|
|