@flowgram.ai/form-materials 0.3.1 → 0.3.3
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/materials.ts +1 -0
- package/dist/esm/index.js +331 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +125 -6
- package/dist/index.d.ts +125 -6
- package/dist/index.js +360 -51
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/config.json +11 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/config.json +11 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/constant-input/config.json +1 -1
- package/src/components/display-outputs/index.tsx +7 -1
- package/src/components/display-schema-tree/config.json +1 -1
- package/src/components/index.ts +2 -0
- package/src/components/variable-selector/index.tsx +1 -1
- package/src/effects/index.ts +3 -0
- package/src/effects/listen-ref-schema-change/config.json +10 -0
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/config.json +9 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/validate-when-variable-sync/config.json +5 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/index.ts +1 -0
- package/src/form-plugins/infer-assign-plugin/config.json +7 -0
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/index.ts +1 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +1 -1
- package/src/plugins/json-schema-preset/index.tsx +2 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +2 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/config.json +7 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isNil, uniq } from 'lodash';
|
|
7
|
+
import { FeedbackLevel, FlowNodeEntity, getNodeScope } from '@flowgram.ai/editor';
|
|
8
|
+
|
|
9
|
+
import { IFlowTemplateValue, IFlowValue } from '@/typings';
|
|
10
|
+
|
|
11
|
+
interface Context {
|
|
12
|
+
node: FlowNodeEntity;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
errorMessages?: {
|
|
15
|
+
required?: string;
|
|
16
|
+
unknownVariable?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function validateFlowValue(value: IFlowValue | undefined, ctx: Context) {
|
|
21
|
+
const { node, required, errorMessages } = ctx;
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
required: requiredMessage = 'Field is required',
|
|
25
|
+
unknownVariable: unknownVariableMessage = 'Unknown Variable',
|
|
26
|
+
} = errorMessages || {};
|
|
27
|
+
|
|
28
|
+
if (required && (isNil(value) || isNil(value?.content) || value?.content === '')) {
|
|
29
|
+
return {
|
|
30
|
+
level: FeedbackLevel.Error,
|
|
31
|
+
message: requiredMessage,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (value?.type === 'ref') {
|
|
36
|
+
const variable = getNodeScope(node).available.getByKeyPath(value?.content || []);
|
|
37
|
+
if (!variable) {
|
|
38
|
+
return {
|
|
39
|
+
level: FeedbackLevel.Error,
|
|
40
|
+
message: unknownVariableMessage,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value?.type === 'template') {
|
|
46
|
+
const allRefs = getTemplateKeyPaths(value);
|
|
47
|
+
|
|
48
|
+
for (const ref of allRefs) {
|
|
49
|
+
const variable = getNodeScope(node).available.getByKeyPath(ref);
|
|
50
|
+
if (!variable) {
|
|
51
|
+
return {
|
|
52
|
+
level: FeedbackLevel.Error,
|
|
53
|
+
message: unknownVariableMessage,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* get template key paths
|
|
64
|
+
* @param value
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
function getTemplateKeyPaths(value: IFlowTemplateValue) {
|
|
68
|
+
// find all keyPath wrapped in {{}}
|
|
69
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
70
|
+
return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>
|
|
71
|
+
_keyPath.slice(2, -2).split('.')
|
|
72
|
+
);
|
|
73
|
+
}
|