@flowgram.ai/form-materials 0.3.0 → 0.3.2

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.
Files changed (53) hide show
  1. package/bin/materials.ts +10 -1
  2. package/dist/esm/index.js +388 -98
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/index.d.mts +173 -90
  5. package/dist/index.d.ts +173 -90
  6. package/dist/index.js +453 -171
  7. package/dist/index.js.map +1 -1
  8. package/package.json +5 -5
  9. package/src/components/assign-row/components/blur-input.tsx +27 -0
  10. package/src/components/assign-row/config.json +11 -0
  11. package/src/components/assign-row/index.tsx +84 -0
  12. package/src/components/assign-row/types.ts +25 -0
  13. package/src/components/assign-rows/config.json +11 -0
  14. package/src/components/assign-rows/index.tsx +59 -0
  15. package/src/components/condition-row/constants.ts +4 -0
  16. package/src/components/constant-input/config.json +1 -1
  17. package/src/components/constant-input/index.tsx +1 -1
  18. package/src/components/constant-input/types.ts +1 -1
  19. package/src/components/display-outputs/index.tsx +7 -1
  20. package/src/components/display-schema-tag/index.tsx +1 -1
  21. package/src/components/display-schema-tree/config.json +1 -1
  22. package/src/components/display-schema-tree/index.tsx +1 -1
  23. package/src/components/index.ts +2 -0
  24. package/src/components/json-schema-editor/config.json +1 -1
  25. package/src/components/type-selector/index.tsx +1 -1
  26. package/src/components/variable-selector/index.tsx +1 -1
  27. package/src/components/variable-selector/use-variable-tree.tsx +1 -1
  28. package/src/effects/index.ts +1 -0
  29. package/src/effects/validate-when-variable-sync/config.json +5 -0
  30. package/src/effects/validate-when-variable-sync/index.ts +35 -0
  31. package/src/form-plugins/index.ts +1 -0
  32. package/src/form-plugins/infer-assign-plugin/config.json +7 -0
  33. package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
  34. package/src/index.ts +2 -0
  35. package/src/plugins/disable-declaration-plugin/config.json +5 -0
  36. package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
  37. package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
  38. package/src/plugins/index.ts +7 -0
  39. package/src/{shared → plugins}/json-schema-preset/create-type-preset-plugin.tsx +4 -2
  40. package/src/{shared → plugins}/json-schema-preset/type-definition/array.tsx +2 -1
  41. package/src/{shared → plugins}/json-schema-preset/type-definition/object.tsx +2 -1
  42. package/src/shared/index.ts +0 -1
  43. package/src/validate/index.tsx +6 -0
  44. package/src/validate/validate-flow-value/config.json +7 -0
  45. package/src/validate/validate-flow-value/index.tsx +73 -0
  46. /package/src/{shared → plugins}/json-schema-preset/config.json +0 -0
  47. /package/src/{shared → plugins}/json-schema-preset/index.tsx +0 -0
  48. /package/src/{shared → plugins}/json-schema-preset/manager.ts +0 -0
  49. /package/src/{shared → plugins}/json-schema-preset/type-definition/boolean.tsx +0 -0
  50. /package/src/{shared → plugins}/json-schema-preset/type-definition/index.tsx +0 -0
  51. /package/src/{shared → plugins}/json-schema-preset/type-definition/integer.tsx +0 -0
  52. /package/src/{shared → plugins}/json-schema-preset/type-definition/number.tsx +0 -0
  53. /package/src/{shared → plugins}/json-schema-preset/type-definition/string.tsx +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "validate-flow-value",
3
+ "depMaterials": [
4
+ "flow-value"
5
+ ],
6
+ "depPackages": []
7
+ }
@@ -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
+ }