@flowgram.ai/form-materials 0.1.0-alpha.8

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 (60) hide show
  1. package/bin/index.ts +94 -0
  2. package/bin/materials.ts +137 -0
  3. package/bin/project.ts +86 -0
  4. package/dist/esm/index.js +1978 -0
  5. package/dist/esm/index.js.map +1 -0
  6. package/dist/index.d.mts +285 -0
  7. package/dist/index.d.ts +285 -0
  8. package/dist/index.js +2018 -0
  9. package/dist/index.js.map +1 -0
  10. package/package.json +72 -0
  11. package/src/components/batch-variable-selector/config.json +5 -0
  12. package/src/components/batch-variable-selector/index.tsx +19 -0
  13. package/src/components/condition-row/config.json +5 -0
  14. package/src/components/condition-row/constants.ts +123 -0
  15. package/src/components/condition-row/hooks/useOp.tsx +45 -0
  16. package/src/components/condition-row/hooks/useRule.ts +26 -0
  17. package/src/components/condition-row/index.tsx +71 -0
  18. package/src/components/condition-row/styles.tsx +25 -0
  19. package/src/components/condition-row/types.ts +37 -0
  20. package/src/components/constant-input/config.json +6 -0
  21. package/src/components/constant-input/index.tsx +81 -0
  22. package/src/components/constant-input/types.ts +18 -0
  23. package/src/components/dynamic-value-input/config.json +5 -0
  24. package/src/components/dynamic-value-input/index.tsx +85 -0
  25. package/src/components/dynamic-value-input/styles.tsx +19 -0
  26. package/src/components/index.ts +7 -0
  27. package/src/components/json-schema-editor/components/blur-input.tsx +22 -0
  28. package/src/components/json-schema-editor/config.json +5 -0
  29. package/src/components/json-schema-editor/default-value.tsx +130 -0
  30. package/src/components/json-schema-editor/hooks.tsx +161 -0
  31. package/src/components/json-schema-editor/index.tsx +256 -0
  32. package/src/components/json-schema-editor/styles.tsx +235 -0
  33. package/src/components/json-schema-editor/types.ts +21 -0
  34. package/src/components/json-schema-editor/utils.ts +24 -0
  35. package/src/components/type-selector/config.json +5 -0
  36. package/src/components/type-selector/constants.tsx +359 -0
  37. package/src/components/type-selector/index.tsx +57 -0
  38. package/src/components/variable-selector/config.json +5 -0
  39. package/src/components/variable-selector/index.tsx +109 -0
  40. package/src/components/variable-selector/styles.tsx +43 -0
  41. package/src/components/variable-selector/use-variable-tree.tsx +101 -0
  42. package/src/effects/auto-rename-ref/config.json +5 -0
  43. package/src/effects/auto-rename-ref/index.ts +104 -0
  44. package/src/effects/index.ts +3 -0
  45. package/src/effects/provide-batch-input/config.json +5 -0
  46. package/src/effects/provide-batch-input/index.ts +38 -0
  47. package/src/effects/provide-batch-outputs/config.json +5 -0
  48. package/src/effects/provide-batch-outputs/index.ts +34 -0
  49. package/src/index.ts +4 -0
  50. package/src/typings/flow-value/config.json +5 -0
  51. package/src/typings/flow-value/index.ts +27 -0
  52. package/src/typings/index.ts +2 -0
  53. package/src/typings/json-schema/config.json +5 -0
  54. package/src/typings/json-schema/index.ts +31 -0
  55. package/src/utils/format-legacy-refs/config.json +5 -0
  56. package/src/utils/format-legacy-refs/index.ts +153 -0
  57. package/src/utils/format-legacy-refs/readme.md +38 -0
  58. package/src/utils/index.ts +2 -0
  59. package/src/utils/json-schema/config.json +5 -0
  60. package/src/utils/json-schema/index.ts +161 -0
@@ -0,0 +1,285 @@
1
+ import React$1 from 'react';
2
+ import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
3
+ import { EffectOptions, ASTNodeJSON, ASTNode, BaseType } from '@flowgram.ai/editor';
4
+
5
+ type JsonSchemaBasicType = 'boolean' | 'string' | 'integer' | 'number' | 'object' | 'array' | 'map';
6
+ interface IJsonSchema<T = string> {
7
+ type?: T;
8
+ default?: any;
9
+ title?: string;
10
+ description?: string;
11
+ enum?: (string | number)[];
12
+ properties?: Record<string, IJsonSchema<T>>;
13
+ additionalProperties?: IJsonSchema<T>;
14
+ items?: IJsonSchema<T>;
15
+ required?: string[];
16
+ $ref?: string;
17
+ extra?: {
18
+ index?: number;
19
+ weak?: boolean;
20
+ formComponent?: string;
21
+ [key: string]: any;
22
+ };
23
+ }
24
+ type IBasicJsonSchema = IJsonSchema<JsonSchemaBasicType>;
25
+
26
+ interface PropTypes$2 {
27
+ value?: string[];
28
+ config?: {
29
+ placeholder?: string;
30
+ notFoundContent?: string;
31
+ };
32
+ onChange: (value?: string[]) => void;
33
+ includeSchema?: IJsonSchema | IJsonSchema[];
34
+ excludeSchema?: IJsonSchema | IJsonSchema[];
35
+ readonly?: boolean;
36
+ hasError?: boolean;
37
+ style?: React$1.CSSProperties;
38
+ triggerRender?: (props: TriggerRenderProps) => React$1.ReactNode;
39
+ }
40
+ type VariableSelectorProps = PropTypes$2;
41
+ declare const VariableSelector: ({ value, config, onChange, style, readonly, includeSchema, excludeSchema, hasError, triggerRender, }: PropTypes$2) => React$1.JSX.Element;
42
+
43
+ interface IFlowConstantValue {
44
+ type: 'constant';
45
+ content?: string | number | boolean;
46
+ }
47
+ interface IFlowRefValue {
48
+ type: 'ref';
49
+ content?: string[];
50
+ }
51
+ interface IFlowExpressionValue {
52
+ type: 'expression';
53
+ content?: string;
54
+ }
55
+ interface IFlowTemplateValue {
56
+ type: 'template';
57
+ content?: string;
58
+ }
59
+ type IFlowValue = IFlowConstantValue | IFlowRefValue | IFlowExpressionValue | IFlowTemplateValue;
60
+ type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
61
+
62
+ declare const VariableTypeIcons: {
63
+ [key: string]: React$1.ReactNode;
64
+ };
65
+ declare const ArrayIcons: {
66
+ [key: string]: React$1.ReactNode;
67
+ };
68
+ declare const getSchemaIcon: (value?: Partial<IJsonSchema>) => React$1.ReactNode;
69
+
70
+ interface PropTypes$1 {
71
+ value?: Partial<IJsonSchema>;
72
+ onChange: (value?: Partial<IJsonSchema>) => void;
73
+ disabled?: boolean;
74
+ style?: React$1.CSSProperties;
75
+ }
76
+ declare const getTypeSelectValue: (value?: Partial<IJsonSchema>) => string[] | undefined;
77
+ declare const parseTypeSelectValue: (value?: string[]) => Partial<IJsonSchema> | undefined;
78
+ declare function TypeSelector(props: PropTypes$1): React$1.JSX.Element;
79
+
80
+ interface ConfigType {
81
+ placeholder?: string;
82
+ descTitle?: string;
83
+ descPlaceholder?: string;
84
+ defaultValueTitle?: string;
85
+ defaultValuePlaceholder?: string;
86
+ addButtonText?: string;
87
+ jsonFormatText?: string;
88
+ }
89
+
90
+ declare function JsonSchemaEditor(props: {
91
+ value?: IJsonSchema;
92
+ onChange?: (value: IJsonSchema) => void;
93
+ config?: ConfigType;
94
+ }): React$1.JSX.Element;
95
+
96
+ declare function BatchVariableSelector(props: VariableSelectorProps): React$1.JSX.Element;
97
+
98
+ interface Strategy<Value = any> {
99
+ hit: (schema: IJsonSchema) => boolean;
100
+ Renderer: React.FC<RendererProps<Value>>;
101
+ }
102
+ interface RendererProps<Value = any> {
103
+ value?: Value;
104
+ onChange?: (value: Value) => void;
105
+ readonly?: boolean;
106
+ }
107
+ interface PropsType$1 extends RendererProps {
108
+ schema: IJsonSchema;
109
+ strategies?: Strategy[];
110
+ [key: string]: any;
111
+ }
112
+
113
+ declare function ConstantInput(props: PropsType$1): React$1.JSX.Element;
114
+
115
+ interface PropsType {
116
+ value?: IFlowConstantRefValue;
117
+ onChange: (value?: IFlowConstantRefValue) => void;
118
+ readonly?: boolean;
119
+ hasError?: boolean;
120
+ style?: React$1.CSSProperties;
121
+ schema?: IJsonSchema;
122
+ constantProps?: {
123
+ strategies?: Strategy[];
124
+ [key: string]: any;
125
+ };
126
+ }
127
+ declare function DynamicValueInput({ value, onChange, readonly, style, schema, constantProps, }: PropsType): React$1.JSX.Element;
128
+
129
+ declare enum Op {
130
+ EQ = "eq",
131
+ NEQ = "neq",
132
+ GT = "gt",
133
+ GTE = "gte",
134
+ LT = "lt",
135
+ LTE = "lte",
136
+ IN = "in",
137
+ NIN = "nin",
138
+ CONTAINS = "contains",
139
+ NOT_CONTAINS = "not_contains",
140
+ IS_EMPTY = "is_empty",
141
+ IS_NOT_EMPTY = "is_not_empty",
142
+ IS_TRUE = "is_true",
143
+ IS_FALSE = "is_false"
144
+ }
145
+ interface ConditionRowValueType {
146
+ left?: IFlowRefValue;
147
+ operator?: Op;
148
+ right?: IFlowConstantRefValue;
149
+ }
150
+
151
+ interface PropTypes {
152
+ value?: ConditionRowValueType;
153
+ onChange: (value?: ConditionRowValueType) => void;
154
+ style?: React$1.CSSProperties;
155
+ readonly?: boolean;
156
+ }
157
+ declare function ConditionRow({ style, value, onChange, readonly }: PropTypes): React$1.JSX.Element;
158
+
159
+ declare const provideBatchInputEffect: EffectOptions[];
160
+
161
+ declare const provideBatchOutputsEffect: EffectOptions[];
162
+
163
+ /**
164
+ * Auto rename ref when form item's key is renamed
165
+ *
166
+ * Example:
167
+ *
168
+ * formMeta: {
169
+ * effects: {
170
+ * "inputsValues": autoRenameRefEffect,
171
+ * }
172
+ * }
173
+ */
174
+ declare const autoRenameRefEffect: EffectOptions[];
175
+
176
+ interface LegacyFlowRefValueSchema {
177
+ type: 'ref';
178
+ content: string;
179
+ }
180
+ interface NewFlowRefValueSchema {
181
+ type: 'ref';
182
+ content: string[];
183
+ }
184
+ /**
185
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
186
+ * the FlowRefValueSchema type definition is updated:
187
+ *
188
+ * interface LegacyFlowRefValueSchema {
189
+ * type: 'ref';
190
+ * content: string;
191
+ * }
192
+ *
193
+ * interface NewFlowRefValueSchema {
194
+ * type: 'ref';
195
+ * content: string[];
196
+ * }
197
+ *
198
+ *
199
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
200
+ *
201
+ * How to use:
202
+ *
203
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
204
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
205
+ *
206
+ * Example:
207
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';
208
+ * formMeta: {
209
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
210
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
211
+ * }
212
+ */
213
+ declare function formatLegacyRefOnSubmit(value: any): any;
214
+ /**
215
+ * In flowgram 0.2.0, for introducing Loop variable functionality,
216
+ * the FlowRefValueSchema type definition is updated:
217
+ *
218
+ * interface LegacyFlowRefValueSchema {
219
+ * type: 'ref';
220
+ * content: string;
221
+ * }
222
+ *
223
+ * interface NewFlowRefValueSchema {
224
+ * type: 'ref';
225
+ * content: string[];
226
+ * }
227
+ *
228
+ *
229
+ * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData
230
+ *
231
+ * How to use:
232
+ *
233
+ * 1. Call formatLegacyRefOnSubmit on the formData before submitting
234
+ * 2. Call formatLegacyRefOnInit on the formData after submitting
235
+ *
236
+ * Example:
237
+ * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';
238
+ *
239
+ * formMeta: {
240
+ * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),
241
+ * formatOnInit: (data) => formatLegacyRefOnInit(data),
242
+ * }
243
+ */
244
+ declare function formatLegacyRefOnInit(value: any): any;
245
+ declare function isLegacyFlowRefValueSchema(value: any): value is LegacyFlowRefValueSchema;
246
+ declare function isNewFlowRefValueSchema(value: any): value is NewFlowRefValueSchema;
247
+ declare function formatLegacyRefToNewRef(value: LegacyFlowRefValueSchema): {
248
+ type: string;
249
+ content: string[];
250
+ };
251
+ declare function formatNewRefToLegacyRef(value: NewFlowRefValueSchema): {
252
+ type: string;
253
+ content: string;
254
+ };
255
+
256
+ declare namespace JsonSchemaUtils {
257
+ /**
258
+ * Converts a JSON schema to an Abstract Syntax Tree (AST) representation.
259
+ * This function recursively processes the JSON schema and creates corresponding AST nodes.
260
+ *
261
+ * For more information on JSON Schema, refer to the official documentation:
262
+ * https://json-schema.org/
263
+ *
264
+ * @param jsonSchema - The JSON schema to convert.
265
+ * @returns An AST node representing the JSON schema, or undefined if the schema type is not recognized.
266
+ */
267
+ function schemaToAST(jsonSchema: IJsonSchema): ASTNodeJSON | undefined;
268
+ /**
269
+ * Convert AST To JSON Schema
270
+ * @param typeAST
271
+ * @returns
272
+ */
273
+ function astToSchema(typeAST: ASTNode, options?: {
274
+ drilldown?: boolean;
275
+ }): IJsonSchema | undefined;
276
+ /**
277
+ * Check if the AST type is match the JSON Schema
278
+ * @param typeAST
279
+ * @param schema
280
+ * @returns
281
+ */
282
+ function isASTMatchSchema(typeAST: BaseType, schema: IJsonSchema | IJsonSchema[]): boolean;
283
+ }
284
+
285
+ export { ArrayIcons, BatchVariableSelector, ConditionRow, type ConditionRowValueType, ConstantInput, DynamicValueInput, type IBasicJsonSchema, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IJsonSchema, type JsonSchemaBasicType, JsonSchemaEditor, JsonSchemaUtils, TypeSelector, VariableSelector, type VariableSelectorProps, VariableTypeIcons, autoRenameRefEffect, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, getSchemaIcon, getTypeSelectValue, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, parseTypeSelectValue, provideBatchInputEffect, provideBatchOutputsEffect };