@flowgram.ai/form-materials 0.1.0-alpha.11 → 0.1.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.ts +14 -22
- package/bin/materials.ts +41 -90
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/index.js +2073 -1601
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +392 -131
- package/dist/index.d.ts +392 -131
- package/dist/index.js +2175 -1710
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/batch-outputs/index.tsx +7 -14
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +2 -2
- package/src/components/code-editor/index.tsx +7 -0
- package/src/components/code-editor/language-features.ts +22 -1
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/constants.ts +8 -10
- package/src/components/condition-row/hooks/useOp.tsx +15 -9
- package/src/components/condition-row/hooks/useRule.ts +9 -5
- package/src/components/condition-row/index.tsx +28 -10
- package/src/components/condition-row/types.ts +5 -5
- package/src/components/constant-input/index.tsx +20 -61
- package/src/components/constant-input/types.ts +6 -9
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/index.tsx +28 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/index.tsx +65 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/index.tsx +45 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/index.tsx +75 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +74 -19
- package/src/components/dynamic-value-input/styles.tsx +28 -2
- package/src/components/index.ts +9 -0
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/index.tsx +75 -0
- package/src/components/inputs-values/styles.tsx +19 -0
- package/src/components/inputs-values/types.ts +22 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +2 -1
- package/src/components/json-schema-editor/default-value.tsx +12 -106
- package/src/components/json-schema-editor/hooks.tsx +53 -94
- package/src/components/json-schema-editor/index.tsx +32 -13
- package/src/components/json-schema-editor/styles.tsx +0 -29
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +2 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +3 -2
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +2 -2
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/prompt-editor-with-variables/index.tsx +2 -1
- package/src/components/type-selector/index.tsx +58 -13
- package/src/components/variable-selector/index.tsx +42 -17
- package/src/components/variable-selector/styles.tsx +18 -8
- package/src/components/variable-selector/use-variable-tree.tsx +19 -22
- package/src/effects/auto-rename-ref/index.ts +1 -1
- package/src/effects/index.ts +3 -1
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/provide-batch-input/index.ts +1 -1
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/index.ts +3 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
- package/src/hooks/index.tsx +6 -0
- package/src/hooks/use-object-list/index.tsx +136 -0
- package/src/index.ts +3 -1
- package/src/{utils/format-legacy-refs → plugins/disable-declaration-plugin}/config.json +1 -1
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/json-schema-preset/config.json +9 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
- package/src/plugins/json-schema-preset/index.tsx +41 -0
- package/src/plugins/json-schema-preset/manager.ts +18 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +33 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/object.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +24 -0
- package/src/{utils → shared}/index.ts +1 -1
- package/src/shared/inject-material/README.md +170 -0
- package/src/shared/inject-material/README.zh.md +174 -0
- package/src/shared/inject-material/index.tsx +87 -0
- package/src/typings/flow-value/index.ts +11 -0
- package/src/typings/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- package/src/components/batch-outputs/config.json +0 -12
- package/src/components/batch-outputs/use-list.ts +0 -86
- package/src/components/batch-variable-selector/config.json +0 -5
- package/src/components/code-editor/config.json +0 -10
- package/src/components/condition-row/config.json +0 -5
- package/src/components/constant-input/config.json +0 -6
- package/src/components/dynamic-value-input/config.json +0 -5
- package/src/components/json-editor-with-variables/config.json +0 -13
- package/src/components/json-schema-editor/config.json +0 -13
- package/src/components/json-schema-editor/utils.ts +0 -29
- package/src/components/prompt-editor/config.json +0 -9
- package/src/components/prompt-editor-with-inputs/config.json +0 -13
- package/src/components/prompt-editor-with-variables/config.json +0 -13
- package/src/components/type-selector/config.json +0 -5
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/components/variable-selector/config.json +0 -5
- package/src/effects/auto-rename-ref/config.json +0 -5
- package/src/effects/provide-batch-input/config.json +0 -5
- package/src/effects/provide-batch-outputs/config.json +0 -5
- package/src/effects/provide-batch-outputs/index.ts +0 -38
- package/src/effects/provide-json-schema-outputs/config.json +0 -8
- package/src/effects/sync-variable-title/config.json +0 -5
- package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
- package/src/typings/flow-value/config.json +0 -5
- package/src/typings/json-schema/config.json +0 -5
- package/src/typings/json-schema/index.ts +0 -36
- package/src/utils/json-schema/config.json +0 -5
- package/src/utils/json-schema/index.ts +0 -180
- /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { get } from 'lodash';
|
|
7
|
-
import { ASTFactory, ASTKind, ASTMatch, ASTNode, ASTNodeJSON, BaseType } from '@flowgram.ai/editor';
|
|
8
|
-
|
|
9
|
-
import { IJsonSchema } from '../../typings/json-schema';
|
|
10
|
-
|
|
11
|
-
export namespace JsonSchemaUtils {
|
|
12
|
-
/**
|
|
13
|
-
* Converts a JSON schema to an Abstract Syntax Tree (AST) representation.
|
|
14
|
-
* This function recursively processes the JSON schema and creates corresponding AST nodes.
|
|
15
|
-
*
|
|
16
|
-
* For more information on JSON Schema, refer to the official documentation:
|
|
17
|
-
* https://json-schema.org/
|
|
18
|
-
*
|
|
19
|
-
* @param jsonSchema - The JSON schema to convert.
|
|
20
|
-
* @returns An AST node representing the JSON schema, or undefined if the schema type is not recognized.
|
|
21
|
-
*/
|
|
22
|
-
export function schemaToAST(jsonSchema: IJsonSchema): ASTNodeJSON | undefined {
|
|
23
|
-
const { type, extra } = jsonSchema || {};
|
|
24
|
-
const { weak = false } = extra || {};
|
|
25
|
-
|
|
26
|
-
if (!type) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
switch (type) {
|
|
31
|
-
case 'object':
|
|
32
|
-
if (weak) {
|
|
33
|
-
return { kind: ASTKind.Object, weak: true };
|
|
34
|
-
}
|
|
35
|
-
return ASTFactory.createObject({
|
|
36
|
-
properties: Object.entries(jsonSchema.properties || {})
|
|
37
|
-
/**
|
|
38
|
-
* Sorts the properties of a JSON schema based on the 'extra.index' field.
|
|
39
|
-
* If the 'extra.index' field is not present, the property will be treated as having an index of 0.
|
|
40
|
-
*/
|
|
41
|
-
.sort((a, b) => (get(a?.[1], 'extra.index') || 0) - (get(b?.[1], 'extra.index') || 0))
|
|
42
|
-
.map(([key, _property]) => ({
|
|
43
|
-
key,
|
|
44
|
-
type: schemaToAST(_property),
|
|
45
|
-
meta: {
|
|
46
|
-
title: _property.title,
|
|
47
|
-
description: _property.description,
|
|
48
|
-
},
|
|
49
|
-
})),
|
|
50
|
-
});
|
|
51
|
-
case 'array':
|
|
52
|
-
if (weak) {
|
|
53
|
-
return { kind: ASTKind.Array, weak: true };
|
|
54
|
-
}
|
|
55
|
-
return ASTFactory.createArray({
|
|
56
|
-
items: schemaToAST(jsonSchema.items!),
|
|
57
|
-
});
|
|
58
|
-
case 'map':
|
|
59
|
-
if (weak) {
|
|
60
|
-
return { kind: ASTKind.Map, weak: true };
|
|
61
|
-
}
|
|
62
|
-
return ASTFactory.createMap({
|
|
63
|
-
valueType: schemaToAST(jsonSchema.additionalProperties!),
|
|
64
|
-
});
|
|
65
|
-
case 'string':
|
|
66
|
-
return ASTFactory.createString();
|
|
67
|
-
case 'number':
|
|
68
|
-
return ASTFactory.createNumber();
|
|
69
|
-
case 'boolean':
|
|
70
|
-
return ASTFactory.createBoolean();
|
|
71
|
-
case 'integer':
|
|
72
|
-
return ASTFactory.createInteger();
|
|
73
|
-
|
|
74
|
-
default:
|
|
75
|
-
// If the type is not recognized, return CustomType
|
|
76
|
-
return ASTFactory.createCustomType({ typeName: type });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Convert AST To JSON Schema
|
|
82
|
-
* @param typeAST
|
|
83
|
-
* @returns
|
|
84
|
-
*/
|
|
85
|
-
export function astToSchema(
|
|
86
|
-
typeAST: ASTNode,
|
|
87
|
-
options?: { drilldown?: boolean }
|
|
88
|
-
): IJsonSchema | undefined {
|
|
89
|
-
const { drilldown = true } = options || {};
|
|
90
|
-
|
|
91
|
-
if (ASTMatch.isString(typeAST)) {
|
|
92
|
-
return {
|
|
93
|
-
type: 'string',
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (ASTMatch.isBoolean(typeAST)) {
|
|
98
|
-
return {
|
|
99
|
-
type: 'boolean',
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (ASTMatch.isNumber(typeAST)) {
|
|
104
|
-
return {
|
|
105
|
-
type: 'number',
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (ASTMatch.isInteger(typeAST)) {
|
|
110
|
-
return {
|
|
111
|
-
type: 'integer',
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (ASTMatch.isObject(typeAST)) {
|
|
116
|
-
return {
|
|
117
|
-
type: 'object',
|
|
118
|
-
properties: drilldown
|
|
119
|
-
? Object.fromEntries(
|
|
120
|
-
typeAST.properties.map((property) => {
|
|
121
|
-
const schema = astToSchema(property.type);
|
|
122
|
-
|
|
123
|
-
if (property.meta?.title && schema) {
|
|
124
|
-
schema.title = property.meta.title;
|
|
125
|
-
}
|
|
126
|
-
if (property.meta?.description && schema) {
|
|
127
|
-
schema.description = property.meta.description;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return [property.key, schema!];
|
|
131
|
-
})
|
|
132
|
-
)
|
|
133
|
-
: {},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (ASTMatch.isArray(typeAST)) {
|
|
138
|
-
return {
|
|
139
|
-
type: 'array',
|
|
140
|
-
items: drilldown ? astToSchema(typeAST.items) : undefined,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (ASTMatch.isMap(typeAST)) {
|
|
145
|
-
return {
|
|
146
|
-
type: 'map',
|
|
147
|
-
items: drilldown ? astToSchema(typeAST.valueType) : undefined,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (ASTMatch.isCustomType(typeAST)) {
|
|
152
|
-
return {
|
|
153
|
-
type: typeAST.typeName,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Check if the AST type is match the JSON Schema
|
|
162
|
-
* @param typeAST
|
|
163
|
-
* @param schema
|
|
164
|
-
* @returns
|
|
165
|
-
*/
|
|
166
|
-
export function isASTMatchSchema(
|
|
167
|
-
typeAST: BaseType,
|
|
168
|
-
schema: IJsonSchema | IJsonSchema[]
|
|
169
|
-
): boolean {
|
|
170
|
-
if (Array.isArray(schema)) {
|
|
171
|
-
return typeAST.isTypeEqual(
|
|
172
|
-
ASTFactory.createUnion({
|
|
173
|
-
types: schema.map((_schema) => schemaToAST(_schema)!).filter(Boolean),
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return typeAST.isTypeEqual(schemaToAST(schema));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
File without changes
|
|
File without changes
|