@flowgram.ai/form-materials 0.1.30 → 0.2.0

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 (39) hide show
  1. package/bin/materials.js +21 -5
  2. package/dist/esm/index.js +463 -57
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/index.d.mts +171 -28
  5. package/dist/index.d.ts +171 -28
  6. package/dist/index.js +472 -60
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -4
  9. package/src/components/batch-variable-selector/config.json +5 -0
  10. package/src/components/batch-variable-selector/index.tsx +18 -0
  11. package/src/components/constant-input/config.json +6 -0
  12. package/src/components/constant-input/index.tsx +81 -0
  13. package/src/components/constant-input/types.ts +18 -0
  14. package/src/components/dynamic-value-input/config.json +5 -0
  15. package/src/components/dynamic-value-input/index.tsx +77 -0
  16. package/src/components/dynamic-value-input/styles.tsx +19 -0
  17. package/src/components/index.ts +6 -3
  18. package/src/components/json-schema-editor/hooks.tsx +33 -22
  19. package/src/components/json-schema-editor/index.tsx +11 -7
  20. package/src/components/json-schema-editor/types.ts +7 -0
  21. package/src/components/type-selector/index.tsx +5 -2
  22. package/src/components/type-selector/types.ts +4 -18
  23. package/src/components/variable-selector/config.json +1 -1
  24. package/src/components/variable-selector/index.tsx +80 -16
  25. package/src/components/variable-selector/styles.tsx +43 -0
  26. package/src/components/variable-selector/use-variable-tree.tsx +29 -7
  27. package/src/effects/index.ts +2 -0
  28. package/src/effects/provide-batch-input/config.json +5 -0
  29. package/src/effects/provide-batch-input/index.ts +38 -0
  30. package/src/effects/provide-batch-outputs/config.json +5 -0
  31. package/src/effects/provide-batch-outputs/index.ts +34 -0
  32. package/src/index.ts +3 -0
  33. package/src/typings/flow-value/config.json +5 -0
  34. package/src/typings/flow-value/index.ts +27 -0
  35. package/src/typings/index.ts +1 -0
  36. package/src/utils/format-legacy-refs/config.json +5 -0
  37. package/src/utils/format-legacy-refs/index.ts +153 -0
  38. package/src/utils/format-legacy-refs/readme.md +38 -0
  39. package/src/utils/index.ts +1 -0
@@ -0,0 +1,153 @@
1
+ import { isObject } from 'lodash';
2
+
3
+ interface LegacyFlowRefValueSchema {
4
+ type: 'ref';
5
+ content: string;
6
+ }
7
+
8
+ interface NewFlowRefValueSchema {
9
+ type: 'ref';
10
+ content: string[];
11
+ }
12
+
13
+ /**
14
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
15
+ * the FlowRefValueSchema type definition is updated:
16
+ *
17
+ * interface LegacyFlowRefValueSchema {
18
+ * type: 'ref';
19
+ * content: string;
20
+ * }
21
+ *
22
+ * interface NewFlowRefValueSchema {
23
+ * type: 'ref';
24
+ * content: string[];
25
+ * }
26
+ *
27
+ *
28
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
29
+ *
30
+ * How to use:
31
+ *
32
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
33
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
34
+ *
35
+ * Example:
36
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';
37
+ * formMeta: {
38
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
39
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
40
+ * }
41
+ */
42
+ export function formatLegacyRefOnSubmit(value: any): any {
43
+ if (isObject(value)) {
44
+ if (isLegacyFlowRefValueSchema(value)) {
45
+ return formatLegacyRefToNewRef(value);
46
+ }
47
+
48
+ return Object.fromEntries(
49
+ Object.entries(value).map(([key, value]: [string, any]) => [
50
+ key,
51
+ formatLegacyRefOnSubmit(value),
52
+ ])
53
+ );
54
+ }
55
+
56
+ if (Array.isArray(value)) {
57
+ return value.map(formatLegacyRefOnSubmit);
58
+ }
59
+
60
+ return value;
61
+ }
62
+
63
+ /**
64
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
65
+ * the FlowRefValueSchema type definition is updated:
66
+ *
67
+ * interface LegacyFlowRefValueSchema {
68
+ * type: 'ref';
69
+ * content: string;
70
+ * }
71
+ *
72
+ * interface NewFlowRefValueSchema {
73
+ * type: 'ref';
74
+ * content: string[];
75
+ * }
76
+ *
77
+ *
78
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
79
+ *
80
+ * How to use:
81
+ *
82
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
83
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
84
+ *
85
+ * Example:
86
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';
87
+ *
88
+ * formMeta: {
89
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
90
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
91
+ * }
92
+ */
93
+ export function formatLegacyRefOnInit(value: any): any {
94
+ if (isObject(value)) {
95
+ if (isNewFlowRefValueSchema(value)) {
96
+ return formatNewRefToLegacyRef(value);
97
+ }
98
+
99
+ return Object.fromEntries(
100
+ Object.entries(value).map(([key, value]: [string, any]) => [
101
+ key,
102
+ formatLegacyRefOnInit(value),
103
+ ])
104
+ );
105
+ }
106
+
107
+ if (Array.isArray(value)) {
108
+ return value.map(formatLegacyRefOnInit);
109
+ }
110
+
111
+ return value;
112
+ }
113
+
114
+ export function isLegacyFlowRefValueSchema(value: any): value is LegacyFlowRefValueSchema {
115
+ return (
116
+ isObject(value) &&
117
+ Object.keys(value).length === 2 &&
118
+ (value as any).type === 'ref' &&
119
+ typeof (value as any).content === 'string'
120
+ );
121
+ }
122
+
123
+ export function isNewFlowRefValueSchema(value: any): value is NewFlowRefValueSchema {
124
+ return (
125
+ isObject(value) &&
126
+ Object.keys(value).length === 2 &&
127
+ (value as any).type === 'ref' &&
128
+ Array.isArray((value as any).content)
129
+ );
130
+ }
131
+
132
+ export function formatLegacyRefToNewRef(value: LegacyFlowRefValueSchema) {
133
+ const keyPath = value.content.split('.');
134
+
135
+ if (keyPath[1] === 'outputs') {
136
+ return {
137
+ type: 'ref',
138
+ content: [`${keyPath[0]}.${keyPath[1]}`, ...(keyPath.length > 2 ? keyPath.slice(2) : [])],
139
+ };
140
+ }
141
+
142
+ return {
143
+ type: 'ref',
144
+ content: keyPath,
145
+ };
146
+ }
147
+
148
+ export function formatNewRefToLegacyRef(value: NewFlowRefValueSchema) {
149
+ return {
150
+ type: 'ref',
151
+ content: value.content.join('.'),
152
+ };
153
+ }
@@ -0,0 +1,38 @@
1
+ # Notice
2
+
3
+ In `@flowgram.ai/form-materials@0.2.0`, for introducing loop-related materials,
4
+
5
+ The FlowRefValueSchema type definition is updated:
6
+
7
+ ```typescript
8
+ interface LegacyFlowRefValueSchema {
9
+ type: 'ref';
10
+ content: string;
11
+ }
12
+
13
+ interface NewFlowRefValueSchema {
14
+ type: 'ref';
15
+ content: string[];
16
+ }
17
+ ```
18
+
19
+
20
+
21
+ For making sure backend json will not be changed in your application, we provide `format-legacy-ref` utils for upgrading
22
+
23
+
24
+ How to use:
25
+
26
+ 1. Call formatLegacyRefOnSubmit on the formData before submitting
27
+ 2. Call formatLegacyRefOnInit on the formData after submitting
28
+
29
+ Example:
30
+
31
+ ```typescript
32
+ import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';
33
+
34
+ formMeta: {
35
+ formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
36
+ formatOnInit: (data) => formatLegacyRefOnInit(data),
37
+ }
38
+ ```
@@ -0,0 +1 @@
1
+ export * from './format-legacy-refs';