@flowgram.ai/form-materials 0.3.3 → 0.3.4
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/esm/index.js +61 -30
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +14 -18
- package/dist/index.d.ts +14 -18
- package/dist/index.js +164 -133
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/condition-row/constants.ts +2 -2
- package/src/components/condition-row/hooks/useOp.tsx +13 -9
- package/src/components/condition-row/hooks/useRule.ts +6 -3
- package/src/components/condition-row/index.tsx +22 -6
- package/src/components/condition-row/types.ts +4 -6
- package/src/components/json-schema-editor/index.tsx +7 -4
- package/src/components/type-selector/index.tsx +2 -4
- package/src/components/variable-selector/index.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@codemirror/view": "~6.38.0",
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
|
-
"@flowgram.ai/editor": "0.3.
|
|
38
|
-
"@flowgram.ai/json-schema": "0.3.
|
|
37
|
+
"@flowgram.ai/editor": "0.3.4",
|
|
38
|
+
"@flowgram.ai/json-schema": "0.3.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/lodash": "^4.14.137",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"tsup": "^8.0.1",
|
|
52
52
|
"typescript": "^5.8.3",
|
|
53
53
|
"vitest": "^0.34.6",
|
|
54
|
-
"@flowgram.ai/eslint-config": "0.3.
|
|
55
|
-
"@flowgram.ai/ts-config": "0.3.
|
|
54
|
+
"@flowgram.ai/eslint-config": "0.3.4",
|
|
55
|
+
"@flowgram.ai/ts-config": "0.3.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": ">=16.8",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { IRules, Op, OpConfigs } from './types';
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const defaultRules: IRules = {
|
|
9
9
|
string: {
|
|
10
10
|
[Op.EQ]: 'string',
|
|
11
11
|
[Op.NEQ]: 'string',
|
|
@@ -62,7 +62,7 @@ export const rules: IRules = {
|
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export const
|
|
65
|
+
export const defaultOpConfigs: OpConfigs = {
|
|
66
66
|
[Op.EQ]: {
|
|
67
67
|
label: 'Equal',
|
|
68
68
|
abbreviation: '=',
|
|
@@ -5,30 +5,34 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
8
9
|
import { Button, Select } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
11
|
-
import { IRule,
|
|
12
|
-
import {
|
|
12
|
+
import { IRule, OpConfigs } from '../types';
|
|
13
|
+
import { defaultOpConfigs } from '../constants';
|
|
13
14
|
|
|
14
15
|
interface HookParams {
|
|
15
16
|
rule?: IRule;
|
|
16
|
-
op?:
|
|
17
|
-
onChange: (op:
|
|
17
|
+
op?: string;
|
|
18
|
+
onChange: (op: string) => void;
|
|
18
19
|
readonly?: boolean;
|
|
20
|
+
userOps?: OpConfigs;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export function useOp({ rule, op, onChange, readonly }: HookParams) {
|
|
23
|
+
export function useOp({ rule, op, onChange, readonly, userOps }: HookParams) {
|
|
22
24
|
const options = useMemo(
|
|
23
25
|
() =>
|
|
24
26
|
Object.keys(rule || {}).map((_op) => ({
|
|
25
|
-
...(
|
|
27
|
+
...(defaultOpConfigs[_op] || {}),
|
|
28
|
+
...(userOps?.[_op] || {}),
|
|
26
29
|
value: _op,
|
|
30
|
+
label: I18n.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label),
|
|
27
31
|
})),
|
|
28
|
-
[rule]
|
|
32
|
+
[rule, userOps]
|
|
29
33
|
);
|
|
30
34
|
|
|
31
|
-
const opConfig = useMemo(() =>
|
|
35
|
+
const opConfig = useMemo(() => defaultOpConfigs[op as string], [op]);
|
|
32
36
|
|
|
33
37
|
const renderOpSelect = () => (
|
|
34
38
|
<Select
|
|
@@ -38,7 +42,7 @@ export function useOp({ rule, op, onChange, readonly }: HookParams) {
|
|
|
38
42
|
value={op}
|
|
39
43
|
optionList={options}
|
|
40
44
|
onChange={(v) => {
|
|
41
|
-
onChange(v as
|
|
45
|
+
onChange(v as string);
|
|
42
46
|
}}
|
|
43
47
|
triggerRender={({ value }) => (
|
|
44
48
|
<Button size="small" disabled={!rule}>
|
|
@@ -8,12 +8,15 @@ import { useMemo } from 'react';
|
|
|
8
8
|
import { JsonSchemaUtils, JsonSchemaBasicType } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { IRules } from '../types';
|
|
12
|
+
import { defaultRules } from '../constants';
|
|
12
13
|
import { IFlowRefValue } from '../../../typings';
|
|
13
14
|
|
|
14
|
-
export function useRule(left?: IFlowRefValue) {
|
|
15
|
+
export function useRule(left?: IFlowRefValue, userRules?: IRules) {
|
|
15
16
|
const available = useScopeAvailable();
|
|
16
17
|
|
|
18
|
+
const rules = useMemo(() => ({ ...defaultRules, ...(userRules || {}) }), [userRules]);
|
|
19
|
+
|
|
17
20
|
const variable = useMemo(() => {
|
|
18
21
|
if (!left) return undefined;
|
|
19
22
|
return available.getByKeyPath(left.content);
|
|
@@ -25,7 +28,7 @@ export function useRule(left?: IFlowRefValue) {
|
|
|
25
28
|
const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
|
|
26
29
|
|
|
27
30
|
return rules[schema?.type as JsonSchemaBasicType];
|
|
28
|
-
}, [variable?.type]);
|
|
31
|
+
}, [variable?.type, rules]);
|
|
29
32
|
|
|
30
33
|
return { rule };
|
|
31
34
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
9
|
import { Input } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
|
-
import { ConditionRowValueType,
|
|
11
|
+
import { ConditionRowValueType, IRules, OpConfigs } from './types';
|
|
12
12
|
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
13
13
|
import { useRule } from './hooks/useRule';
|
|
14
14
|
import { useOp } from './hooks/useOp';
|
|
@@ -20,20 +20,36 @@ interface PropTypes {
|
|
|
20
20
|
onChange: (value?: ConditionRowValueType) => void;
|
|
21
21
|
style?: React.CSSProperties;
|
|
22
22
|
readonly?: boolean;
|
|
23
|
+
ruleConfig?: {
|
|
24
|
+
ops?: OpConfigs;
|
|
25
|
+
rules?: IRules;
|
|
26
|
+
};
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
const defaultRuleConfig = {
|
|
30
|
+
ops: {},
|
|
31
|
+
rules: {},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function ConditionRow({
|
|
35
|
+
style,
|
|
36
|
+
value,
|
|
37
|
+
onChange,
|
|
38
|
+
readonly,
|
|
39
|
+
ruleConfig = defaultRuleConfig,
|
|
40
|
+
}: PropTypes) {
|
|
26
41
|
const { left, operator, right } = value || {};
|
|
27
|
-
const { rule } = useRule(left);
|
|
42
|
+
const { rule } = useRule(left, ruleConfig.rules);
|
|
28
43
|
const { renderOpSelect, opConfig } = useOp({
|
|
29
44
|
rule,
|
|
30
45
|
op: operator,
|
|
31
46
|
onChange: (v) => onChange({ ...value, operator: v }),
|
|
32
47
|
readonly,
|
|
48
|
+
userOps: ruleConfig.ops,
|
|
33
49
|
});
|
|
34
50
|
|
|
35
51
|
const targetSchema = useMemo(() => {
|
|
36
|
-
const targetType:
|
|
52
|
+
const targetType: string | null = rule?.[operator || ''] || null;
|
|
37
53
|
return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
38
54
|
}, [rule, opConfig]);
|
|
39
55
|
|
|
@@ -70,7 +86,7 @@ export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
|
|
|
70
86
|
size="small"
|
|
71
87
|
disabled
|
|
72
88
|
style={{ pointerEvents: 'none' }}
|
|
73
|
-
value={opConfig?.rightDisplay || 'Empty'}
|
|
89
|
+
value={opConfig?.rightDisplay || I18n.t('Empty')}
|
|
74
90
|
/>
|
|
75
91
|
)}
|
|
76
92
|
</UIRight>
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { JsonSchemaBasicType } from '@flowgram.ai/json-schema';
|
|
7
|
-
|
|
8
6
|
import { IFlowConstantRefValue, IFlowRefValue } from '../../typings';
|
|
9
7
|
|
|
10
8
|
export enum Op {
|
|
@@ -31,14 +29,14 @@ export interface OpConfig {
|
|
|
31
29
|
rightDisplay?: string;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
export type OpConfigs = Record<
|
|
32
|
+
export type OpConfigs = Record<string, OpConfig>;
|
|
35
33
|
|
|
36
|
-
export type IRule = Partial<Record<
|
|
34
|
+
export type IRule = Partial<Record<string, string | null>>;
|
|
37
35
|
|
|
38
|
-
export type IRules = Record<
|
|
36
|
+
export type IRules = Record<string, IRule>;
|
|
39
37
|
|
|
40
38
|
export interface ConditionRowValueType {
|
|
41
39
|
left?: IFlowRefValue;
|
|
42
|
-
operator?:
|
|
40
|
+
operator?: string;
|
|
43
41
|
right?: IFlowConstantRefValue;
|
|
44
42
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
|
|
10
11
|
import {
|
|
11
12
|
IconExpand,
|
|
@@ -219,25 +220,27 @@ function PropertyEdit(props: {
|
|
|
219
220
|
</UIRow>
|
|
220
221
|
{expand && (
|
|
221
222
|
<UIExpandDetail>
|
|
222
|
-
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
223
|
+
<UILabel>{config?.descTitle ?? I18n.t('Description')}</UILabel>
|
|
223
224
|
<BlurInput
|
|
224
225
|
disabled={readonly}
|
|
225
226
|
size="small"
|
|
226
227
|
value={description}
|
|
227
228
|
onChange={(value) => onChange('description', value)}
|
|
228
|
-
placeholder={
|
|
229
|
+
placeholder={
|
|
230
|
+
config?.descPlaceholder ?? I18n.t('Help LLM to understand the property')
|
|
231
|
+
}
|
|
229
232
|
/>
|
|
230
233
|
{$level === 0 && type && type !== 'array' && (
|
|
231
234
|
<>
|
|
232
235
|
<UILabel style={{ marginTop: 10 }}>
|
|
233
|
-
{config?.defaultValueTitle ?? 'Default Value'}
|
|
236
|
+
{config?.defaultValueTitle ?? I18n.t('Default Value')}
|
|
234
237
|
</UILabel>
|
|
235
238
|
<DefaultValueWrapper>
|
|
236
239
|
<DefaultValue
|
|
237
240
|
value={defaultValue}
|
|
238
241
|
schema={value}
|
|
239
242
|
type={type}
|
|
240
|
-
placeholder={config?.defaultValuePlaceholder}
|
|
243
|
+
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
241
244
|
jsonFormatText={config?.jsonFormatText}
|
|
242
245
|
onChange={(value) => onChange('default', value)}
|
|
243
246
|
/>
|
|
@@ -23,8 +23,6 @@ interface PropTypes {
|
|
|
23
23
|
|
|
24
24
|
const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
|
|
25
25
|
|
|
26
|
-
const firstUppercase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
27
|
-
|
|
28
26
|
export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
|
|
29
27
|
if (value?.type === 'array' && value?.items) {
|
|
30
28
|
return [value.type, ...(getTypeSelectValue(value.items) || [])];
|
|
@@ -61,7 +59,7 @@ export function TypeSelector(props: PropTypes) {
|
|
|
61
59
|
label: (
|
|
62
60
|
<div style={labelStyle}>
|
|
63
61
|
<Icon size="small" svg={_type.icon} />
|
|
64
|
-
{
|
|
62
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
65
63
|
</div>
|
|
66
64
|
),
|
|
67
65
|
value: _type.type,
|
|
@@ -76,7 +74,7 @@ export function TypeSelector(props: PropTypes) {
|
|
|
76
74
|
items: { type: _type.type },
|
|
77
75
|
})}
|
|
78
76
|
/>
|
|
79
|
-
{
|
|
77
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
80
78
|
</div>
|
|
81
79
|
),
|
|
82
80
|
value: _type.type,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
10
11
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
11
12
|
import { Popover } from '@douyinfe/semi-ui';
|
|
@@ -130,7 +131,7 @@ export const VariableSelector = ({
|
|
|
130
131
|
showClear={false}
|
|
131
132
|
arrowIcon={<IconChevronDownStroked size="small" />}
|
|
132
133
|
triggerRender={triggerRender}
|
|
133
|
-
placeholder={config?.placeholder ?? 'Select Variable'}
|
|
134
|
+
placeholder={config?.placeholder ?? I18n.t('Select Variable')}
|
|
134
135
|
/>
|
|
135
136
|
</>
|
|
136
137
|
);
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
9
11
|
import { CodeEditorMini } from '@/components/code-editor-mini';
|
|
10
12
|
|
|
11
13
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -17,7 +19,7 @@ export const arrayRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
17
19
|
value={props.value}
|
|
18
20
|
languageId="json"
|
|
19
21
|
onChange={(v) => props.onChange?.(v)}
|
|
20
|
-
placeholder=
|
|
22
|
+
placeholder={I18n.t('Please Input Array')}
|
|
21
23
|
readonly={props.readonly}
|
|
22
24
|
/>
|
|
23
25
|
),
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { Select } from '@douyinfe/semi-ui';
|
|
10
11
|
|
|
11
12
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -16,12 +17,12 @@ export const booleanRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
16
17
|
const { value, onChange, ...rest } = props;
|
|
17
18
|
return (
|
|
18
19
|
<Select
|
|
19
|
-
placeholder=
|
|
20
|
+
placeholder={I18n.t('Please Select Boolean')}
|
|
20
21
|
size="small"
|
|
21
22
|
disabled={props.readonly}
|
|
22
23
|
optionList={[
|
|
23
|
-
{ label: 'True', value: 1 },
|
|
24
|
-
{ label: 'False', value: 0 },
|
|
24
|
+
{ label: I18n.t('True'), value: 1 },
|
|
25
|
+
{ label: I18n.t('False'), value: 0 },
|
|
25
26
|
]}
|
|
26
27
|
value={value ? 1 : 0}
|
|
27
28
|
onChange={(value) => onChange?.(!!value)}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { InputNumber } from '@douyinfe/semi-ui';
|
|
10
11
|
|
|
11
12
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -14,7 +15,7 @@ export const integerRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
14
15
|
type: 'integer',
|
|
15
16
|
ConstantRenderer: (props) => (
|
|
16
17
|
<InputNumber
|
|
17
|
-
placeholder=
|
|
18
|
+
placeholder={I18n.t('Please Input Integer')}
|
|
18
19
|
size="small"
|
|
19
20
|
disabled={props.readonly}
|
|
20
21
|
precision={0}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { InputNumber } from '@douyinfe/semi-ui';
|
|
10
11
|
|
|
11
12
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -14,7 +15,7 @@ export const numberRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
14
15
|
type: 'number',
|
|
15
16
|
ConstantRenderer: (props) => (
|
|
16
17
|
<InputNumber
|
|
17
|
-
placeholder=
|
|
18
|
+
placeholder={I18n.t('Please Input Number')}
|
|
18
19
|
size="small"
|
|
19
20
|
disabled={props.readonly}
|
|
20
21
|
hideButtons
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
9
11
|
import { CodeEditorMini } from '@/components/code-editor-mini';
|
|
10
12
|
|
|
11
13
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -17,7 +19,7 @@ export const objectRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
17
19
|
value={props.value}
|
|
18
20
|
onChange={(v) => props.onChange?.(v)}
|
|
19
21
|
languageId="json"
|
|
20
|
-
placeholder=
|
|
22
|
+
placeholder={I18n.t('Please Input Object')}
|
|
21
23
|
readonly={props.readonly}
|
|
22
24
|
/>
|
|
23
25
|
),
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React from 'react';
|
|
8
8
|
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { Input } from '@douyinfe/semi-ui';
|
|
10
11
|
|
|
11
12
|
import { type JsonSchemaTypeRegistry } from '../manager';
|
|
@@ -13,6 +14,11 @@ import { type JsonSchemaTypeRegistry } from '../manager';
|
|
|
13
14
|
export const stringRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
14
15
|
type: 'string',
|
|
15
16
|
ConstantRenderer: (props) => (
|
|
16
|
-
<Input
|
|
17
|
+
<Input
|
|
18
|
+
placeholder={I18n.t('Please Input String')}
|
|
19
|
+
size="small"
|
|
20
|
+
disabled={props.readonly}
|
|
21
|
+
{...props}
|
|
22
|
+
/>
|
|
17
23
|
),
|
|
18
24
|
};
|