form-craft-package 1.0.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 (40) hide show
  1. package/.prettierrc +9 -0
  2. package/AJV_JSON_Schema_Guide.md +409 -0
  3. package/README.md +108 -0
  4. package/index.ts +8 -0
  5. package/package.json +40 -0
  6. package/src/ajv/form/form.schema.json +10 -0
  7. package/src/ajv/form/layout.schema.json +97 -0
  8. package/src/ajv/form/migration-rules.schema.json +59 -0
  9. package/src/ajv/master-portal-only/render-conditions/conditions.schema.json +24 -0
  10. package/src/ajv/master-portal-only/render-conditions/validate.ts +15 -0
  11. package/src/components/common/button.tsx +72 -0
  12. package/src/components/common/custom-hooks/use-find-dynamic-form.ts +33 -0
  13. package/src/components/common/custom-hooks/use-lazy-modal-opener.hook.ts +20 -0
  14. package/src/components/common/custom-hooks/use-notification.hook.tsx +157 -0
  15. package/src/components/common/disabled-field-indicator.tsx +20 -0
  16. package/src/components/common/warning-icon.tsx +10 -0
  17. package/src/components/form/layout-renderer/1-row/index.tsx +27 -0
  18. package/src/components/form/layout-renderer/2-col/index.tsx +32 -0
  19. package/src/components/form/layout-renderer/3-element/1-dynamic-button.tsx +277 -0
  20. package/src/components/form/layout-renderer/3-element/2-field-element.tsx +220 -0
  21. package/src/components/form/layout-renderer/3-element/index.tsx +73 -0
  22. package/src/components/index.tsx +2 -0
  23. package/src/components/modals/form-data-loading.modal.tsx +48 -0
  24. package/src/constants.ts +15 -0
  25. package/src/enums.ts +177 -0
  26. package/src/functions/axios-handler.ts +158 -0
  27. package/src/functions/data-list-functions.tsx +41 -0
  28. package/src/functions/form-schema-validator.ts +50 -0
  29. package/src/functions/get-element-props.ts +20 -0
  30. package/src/functions/index.ts +56 -0
  31. package/src/functions/json-handlers.ts +19 -0
  32. package/src/functions/validations.ts +120 -0
  33. package/src/types/form-data-list/index.ts +54 -0
  34. package/src/types/index.ts +124 -0
  35. package/src/types/layout-elements/element-data-render-logic.ts +56 -0
  36. package/src/types/layout-elements/field-option-source.ts +14 -0
  37. package/src/types/layout-elements/index.ts +224 -0
  38. package/src/types/layout-elements/style.ts +35 -0
  39. package/src/types/layout-elements/validation.ts +18 -0
  40. package/tsconfig.json +111 -0
package/.prettierrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "useTabs": false,
4
+ "singleQuote": true,
5
+ "trailingComma": "all",
6
+ "endOfLine": "lf",
7
+ "printWidth": 120,
8
+ "semi": false
9
+ }
@@ -0,0 +1,409 @@
1
+ # AJV JSON Schema Documentation
2
+
3
+ ## 1. `$schema`
4
+
5
+ Defines the JSON Schema version.
6
+
7
+ ```json
8
+ {
9
+ "$schema": "http://json-schema.org/draft-07/schema#"
10
+ }
11
+ ```
12
+
13
+ ## 2. `type`
14
+
15
+ Specifies the data type: `object`, `array`, `string`, `number`, `integer`, or `boolean`.
16
+
17
+ ```json
18
+ {
19
+ "type": "string"
20
+ }
21
+ ```
22
+
23
+ ## 3. `properties`
24
+
25
+ Defines the properties of an object and their types.
26
+
27
+ ```json
28
+ {
29
+ "type": "object",
30
+ "properties": {
31
+ "name": { "type": "string" },
32
+ "age": { "type": "integer" }
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## 4. `required`
38
+
39
+ Lists mandatory fields in an object.
40
+
41
+ ```json
42
+ {
43
+ "type": "object",
44
+ "properties": {
45
+ "name": { "type": "string" },
46
+ "age": { "type": "integer" }
47
+ },
48
+ "required": ["name"]
49
+ }
50
+ ```
51
+
52
+ - **`name`** is required.
53
+ - **`age`** is optional.
54
+
55
+ ---
56
+
57
+ ## 5. `items`
58
+
59
+ If the `type` is `array`, the `items` property defines the schema for the array elements.
60
+
61
+ ### a. Single Type for All Items
62
+
63
+ ```json
64
+ {
65
+ "type": "array",
66
+ "items": { "type": "string" }
67
+ }
68
+ ```
69
+
70
+ - Valid: `["apple", "banana"]`
71
+ - Invalid: `[1, "apple"]`
72
+
73
+ ### b. Different Types for Items (Tuple Validation)
74
+
75
+ ```json
76
+ {
77
+ "type": "array",
78
+ "items": [{ "type": "string" }, { "type": "integer" }]
79
+ }
80
+ ```
81
+
82
+ - Valid: `["apple", 5]`
83
+ - Invalid: `["apple", "banana"]`
84
+
85
+ ### c. Additional Items
86
+
87
+ Control extra items beyond those specified.
88
+
89
+ ```json
90
+ {
91
+ "type": "array",
92
+ "items": [{ "type": "string" }, { "type": "integer" }],
93
+ "additionalItems": false
94
+ }
95
+ ```
96
+
97
+ - Valid: `["apple", 5]`
98
+ - Invalid: `["apple", 5, "extra"]`
99
+
100
+ ---
101
+
102
+ ## 6. `enum`
103
+
104
+ Restricts a field to specific values.
105
+
106
+ ```json
107
+ {
108
+ "type": "string",
109
+ "enum": ["red", "green", "blue"]
110
+ }
111
+ ```
112
+ - Allows only these three values.
113
+
114
+ ## 7. `minimum` and `maximum`
115
+
116
+ Sets the range for numbers.
117
+
118
+ ```json
119
+ {
120
+ "type": "number",
121
+ "minimum": 10,
122
+ "maximum": 100
123
+ }
124
+ ```
125
+
126
+ ## 8. `minLength` and `maxLength`
127
+
128
+ Sets the length constraints for strings.
129
+
130
+ ```json
131
+ {
132
+ "type": "string",
133
+ "minLength": 3,
134
+ "maxLength": 10
135
+ }
136
+ ```
137
+
138
+ ## 9. `pattern`
139
+
140
+ Validates strings against a regex pattern.
141
+
142
+ ```json
143
+ {
144
+ "type": "string",
145
+ "pattern": "^[A-Z][a-z]+$"
146
+ }
147
+ ```
148
+ - The string should start with an uppercase letter.
149
+
150
+ ## 10. `format`
151
+
152
+ AJV supports several predefined string formats:
153
+
154
+ | **Format** | **Description** |
155
+ | -------------- | ----------------------------------------------------- |
156
+ | `email` | Valid email address (e.g., `user@domain.com`) |
157
+ | `uri` | Uniform Resource Identifier (URI) |
158
+ | `url` | Web address (HTTP/HTTPS) |
159
+ | `date` | Date in `YYYY-MM-DD` format |
160
+ | `time` | Time in `HH:MM:SS` format |
161
+ | `date-time` | Combined date and time (e.g., `2023-10-12T10:15:30Z`) |
162
+ | `ipv4` | IPv4 address (e.g., `192.168.1.1`) |
163
+ | `ipv6` | IPv6 address (e.g., `::1`) |
164
+ | `uuid` | UUID (e.g., `550e8400-e29b-41d4-a716-446655440000`) |
165
+ | `hostname` | Valid DNS hostname |
166
+ | `regex` | Regular expression |
167
+ | `json-pointer` | JSON Pointer (e.g., `/path/to/data`) |
168
+
169
+ Custom formats can be defined using `ajv.addFormat`.
170
+
171
+ ```json
172
+ {
173
+ "type": "string",
174
+ "format": "email"
175
+ }
176
+ ```
177
+
178
+ ## 11. `default`
179
+
180
+ Provides a default value for a property.
181
+
182
+ ```json
183
+ {
184
+ "type": "object",
185
+ "properties": {
186
+ "isActive": { "type": "boolean", "default": true }
187
+ }
188
+ }
189
+ ```
190
+
191
+ ## 12. `oneOf`
192
+
193
+ Specifies multiple valid schemas (OR).
194
+
195
+ ```json
196
+ {
197
+ "oneOf": [{ "type": "string" }, { "type": "integer" }]
198
+ }
199
+ ```
200
+ - Allows either a string or an integer, but not both.
201
+
202
+ ## 13. `allOf`
203
+
204
+ Requires the data to match all schemas.
205
+
206
+ ```json
207
+ {
208
+ "allOf": [
209
+ { "type": "object", "properties": { "name": { "type": "string" } } },
210
+ { "type": "object", "properties": { "age": { "type": "integer" } } }
211
+ ]
212
+ }
213
+ ```
214
+ - Allows either a string or a boolean.
215
+
216
+ ## 14. `anyOf`
217
+
218
+ Requires the data to match at least one schema.
219
+
220
+ ```json
221
+ {
222
+ "anyOf": [{ "type": "string" }, { "type": "boolean" }]
223
+ }
224
+ ```
225
+
226
+ ## 15. `not`
227
+
228
+ Specifies that data must not match a schema.
229
+
230
+ ```json
231
+ {
232
+ "not": { "type": "null" }
233
+ }
234
+ ```
235
+ - Disallows null values.
236
+
237
+ ## 16. `additionalProperties`
238
+
239
+ Allows or disallows extra properties in an object.
240
+
241
+ ```json
242
+ {
243
+ "type": "object",
244
+ "properties": {
245
+ "name": { "type": "string" }
246
+ },
247
+ "additionalProperties": false
248
+ }
249
+ ```
250
+ - Disallows extra fields.
251
+
252
+ ## 17. `patternProperties`
253
+
254
+ Validates object keys using a regex.
255
+
256
+ ```json
257
+ {
258
+ "type": "object",
259
+ "patternProperties": {
260
+ "^user_": { "type": "string" }
261
+ }
262
+ }
263
+ ```
264
+
265
+ - All keys starting with `user_` (e.g., `user_1`, `user_123`) must have string values.
266
+
267
+ ## 18. `dependencies`
268
+
269
+ Dependencies specify logical relationships between properties.
270
+
271
+ ### Property Dependencies
272
+
273
+ This means the presence of one property requires another property.
274
+
275
+ #### Example
276
+
277
+ ```json
278
+ {
279
+ "type": "object",
280
+ "properties": {
281
+ "creditCard": { "type": "string" },
282
+ "billingAddress": { "type": "string" }
283
+ },
284
+ "dependencies": {
285
+ "creditCard": ["billingAddress"]
286
+ }
287
+ }
288
+ ```
289
+
290
+ - If `creditCard` is present, `billingAddress` **must** also be present.
291
+ - If `creditCard` is not present, `billingAddress` can be omitted.
292
+
293
+ ### Schema Dependencies
294
+
295
+ Schema dependencies apply different schemas based on the presence of a field.
296
+
297
+ #### Example
298
+
299
+ ```json
300
+ {
301
+ "type": "object",
302
+ "properties": {
303
+ "country": { "type": "string" },
304
+ "postalCode": { "type": "string" }
305
+ },
306
+ "dependencies": {
307
+ "country": {
308
+ "oneOf": [
309
+ {
310
+ "properties": { "country": { "const": "US" }, "postalCode": { "pattern": "^[0-9]{5}$" } },
311
+ "required": ["postalCode"]
312
+ },
313
+ {
314
+ "properties": {
315
+ "country": { "const": "CA" },
316
+ "postalCode": { "pattern": "^[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$" }
317
+ },
318
+ "required": ["postalCode"]
319
+ }
320
+ ]
321
+ }
322
+ }
323
+ }
324
+ ```
325
+
326
+ - If `country` is `"US"`, `postalCode` must match the US zip code format.
327
+ - If `country` is `"CA"`, `postalCode` must match the Canadian postal code format.
328
+
329
+ ---
330
+
331
+ ## 19. `const`
332
+
333
+ Requires a field to have a specific value.
334
+
335
+ ```json
336
+ {
337
+ "type": "object",
338
+ "properties": {
339
+ "status": { "const": "active" }
340
+ }
341
+ }
342
+ ```
343
+ - Ensures the field always equals "active".
344
+
345
+ ## 20. `if`, `then`, `else`
346
+
347
+ Conditional validation.
348
+
349
+ ```json
350
+ {
351
+ "if": { "properties": { "role": { "const": "admin" } } },
352
+ "then": { "required": ["adminCode"] },
353
+ "else": { "required": ["userCode"] }
354
+ }
355
+ ```
356
+
357
+ ## 21. `uniqueItems`
358
+
359
+ Ensures all items in an array are unique.
360
+
361
+ ```json
362
+ {
363
+ "type": "array",
364
+ "items": { "type": "integer" },
365
+ "uniqueItems": true
366
+ }
367
+ ```
368
+ - Ensures [1, 2, 3] is valid, but [1, 2, 2] is not.
369
+
370
+ ## 22. `minItems` and `maxItems`
371
+
372
+ Limits the number of items in an array.
373
+
374
+ ```json
375
+ {
376
+ "type": "array",
377
+ "items": { "type": "string" },
378
+ "minItems": 1,
379
+ "maxItems": 5
380
+ }
381
+ ```
382
+
383
+ ## 23. `contains`
384
+
385
+ Requires at least one item in an array to match a schema.
386
+
387
+ ```json
388
+ {
389
+ "type": "array",
390
+ "items": { "type": "integer" },
391
+ "contains": { "const": 10 }
392
+ }
393
+ ```
394
+
395
+ ## 24. `$ref`
396
+
397
+ References reusable schemas.
398
+
399
+ ```json
400
+ {
401
+ "$ref": "#/definitions/person",
402
+ "definitions": {
403
+ "person": {
404
+ "type": "object",
405
+ "properties": { "name": { "type": "string" } }
406
+ }
407
+ }
408
+ }
409
+ ```
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+
2
+ # Using Submodules in Your Project
3
+
4
+ This guide provides instructions for adding, updating, and managing a submodule in your project. Submodules allow you to include shared code, like helper functions, from another repository.
5
+
6
+ ---
7
+
8
+ ## 1. How to Add this Submodule to a Project
9
+
10
+ To add this submodule to your project, follow these steps:
11
+
12
+ 1. Navigate to your project directory:
13
+ ```bash
14
+ cd /path/to/your/project
15
+ ```
16
+
17
+ 2. Add the submodule in the `submodule-name` folder:
18
+ ```bash
19
+ git submodule add <submodule-repo-url> submodule-name
20
+ ```
21
+
22
+ 3. Commit the changes to your main repository (simply committing the changes):
23
+ ```bash
24
+ git add .gitmodules submodule-name
25
+ git commit -m "Added submodule: submodule-name"
26
+ ```
27
+
28
+ ### **Note: Submodule Configuration**
29
+ - The submodule (`submodule-name`) is configured to be updated **only in its own repository**. Changes cannot be made directly from the projects that use this submodule.
30
+
31
+ ---
32
+
33
+ ## 2. How to Update the Submodule in a Project
34
+
35
+ To pull the latest updates from the submodule repository:
36
+
37
+ 1. Navigate to the submodule directory:
38
+ ```bash
39
+ cd submodule-name
40
+ ```
41
+
42
+ 2. Pull the latest changes:
43
+ ```bash
44
+ git pull origin main
45
+ ```
46
+
47
+ 3. Navigate back to your main project directory:
48
+ ```bash
49
+ cd ../../
50
+ ```
51
+
52
+ 4. Stage and commit the updated submodule reference:
53
+ ```bash
54
+ git add submodule-name
55
+ git commit -m "Updated submodule: submodule-name to latest version"
56
+ ```
57
+
58
+ 5. Push your changes to the main repository:
59
+ ```bash
60
+ git push origin main
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 3. Add Submodules to `.gitignore`
66
+
67
+ Since the submodule is not editable directly, add its parent folder (`submodule-name/`) to your `.gitignore` file to prevent tracking unintended changes.
68
+
69
+ Add the following line to your `.gitignore`:
70
+ ```
71
+ submodule-name/
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 4. Prevent Accidental Editing in the IDE
77
+
78
+ To avoid accidental edits, make the submodule folder read-only in your IDE by adding the following to `.vscode/settings.json`:
79
+
80
+ ```json
81
+ {
82
+ "files.readonlyInclude": {
83
+ "submodule-name/**": true
84
+ },
85
+ "git.ignoreSubmodules": true
86
+ }
87
+ ```
88
+
89
+ This configuration ensures that the submodule files are treated as read-only by your IDE.
90
+
91
+ ---
92
+
93
+ ## 5. Ignore git changes of submodules
94
+
95
+ To stop seeing the git changes of the submodules when pulling the updates, add the following command to the .gitmodules file. By default, this file contains path and url.
96
+
97
+ ```
98
+ ignore = all
99
+ ```
100
+
101
+ ---
102
+ ---
103
+ ---
104
+
105
+ # Peer Dependencies
106
+
107
+ This submodule relies on certain **peer dependencies** to ensure compatibility and prevent version conflicts. These dependencies must be installed in the consuming project. Failing to install or using incompatible versions of these dependencies can lead to unexpected behavior.
108
+
package/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './src/enums'
2
+ export * from './src/types'
3
+ export * from './src/constants'
4
+ export * from './src/functions'
5
+ export * from './src/functions/json-handlers'
6
+ export * from './src/functions/form-schema-validator'
7
+ export * from './src/functions/get-element-props'
8
+ export * from './src/components'
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "form-craft-package",
3
+ "version": "1.0.0",
4
+ "main": "index.ts",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "build": "tsc"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "ajv": "^8.17.1"
15
+ },
16
+ "peerDependencies": {
17
+ "antd": ">=5.21.6",
18
+ "axios": ">=1.7.7",
19
+ "dayjs": ">=1.11.13",
20
+ "js-cookie": ">=3.0.5",
21
+ "quill": ">=2.0.3",
22
+ "react": ">=18.0.0 <19.0.0",
23
+ "react-dom": ">=18.0.0 <19.0.0",
24
+ "react-icons": ">=5.3.0",
25
+ "react-quill": ">=2.0.0",
26
+ "react-router-dom": ">=6.27.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/js-cookie": "^3.0.6",
30
+ "@types/react": "^18.3.18",
31
+ "@types/react-dom": "^18.3.5",
32
+ "react": "^18.3.1",
33
+ "react-dom": "^18.3.1",
34
+ "ts-node": "^10.9.2",
35
+ "vite": "^6.0.7"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "form.schema",
4
+ "type": "object",
5
+ "properties": {
6
+ "layout": { "$ref": "layout.schema" },
7
+ "migrationRules": { "$ref": "migration-rules.schema" }
8
+ },
9
+ "required": ["layout", "migrationRules"]
10
+ }
@@ -0,0 +1,97 @@
1
+ {
2
+ "$id": "layout.schema",
3
+ "type": "array",
4
+ "items": { "$ref": "#/definitions/IFormLayoutRow" },
5
+ "definitions": {
6
+ "IFormLayoutRow": {
7
+ "type": "object",
8
+ "required": ["nodeType", "id", "children"],
9
+ "properties": {
10
+ "nodeType": { "type": "string", "enum": ["Row"] },
11
+ "id": { "type": "string" },
12
+ "children": {
13
+ "type": "array",
14
+ "items": { "$ref": "#/definitions/IFormLayoutCol" }
15
+ },
16
+ "isTemplate": { "type": ["boolean", "null"] },
17
+ "path": { "type": ["string", "null"] }
18
+ }
19
+ },
20
+ "IFormLayoutCol": {
21
+ "type": "object",
22
+ "required": ["nodeType", "id", "children"],
23
+ "properties": {
24
+ "nodeType": { "type": "string", "enum": ["Col"] },
25
+ "id": { "type": "string" },
26
+ "children": {
27
+ "type": "array",
28
+ "items": {
29
+ "oneOf": [{ "$ref": "#/definitions/IFormLayoutRow" }, { "$ref": "#/definitions/IFormLayoutField" }]
30
+ }
31
+ }
32
+ }
33
+ },
34
+ "IFormLayoutField": {
35
+ "type": "object",
36
+ "required": ["nodeType", "id", "key", "fieldType", "props", "validations"],
37
+ "properties": {
38
+ "nodeType": {
39
+ "type": "string",
40
+ "enum": ["Field"]
41
+ },
42
+ "id": { "type": "string" },
43
+ "path": { "type": ["string", "null"] },
44
+ "key": { "type": "string", "minLength": 2 },
45
+ "fieldType": { "type": "string" },
46
+ "props": {
47
+ "type": "object",
48
+ "properties": {
49
+ "label": { "type": ["string", "null"] },
50
+ "placeholder": { "type": ["string", "null"] },
51
+ "description": { "type": ["string", "null"] },
52
+ "allowClear": { "type": ["boolean", "null"] },
53
+ "isMultiValue": { "type": ["boolean", "null"] },
54
+ "hasNoLabel": { "type": ["boolean", "null"] },
55
+ "options": {
56
+ "type": "array",
57
+ "minItems": 1,
58
+ "items": { "$ref": "#/definitions/IFormLayoutFieldOption" }
59
+ }
60
+ }
61
+ },
62
+ "validations": {
63
+ "type": "array",
64
+ "items": {
65
+ "type": "object",
66
+ "required": ["key", "message"],
67
+ "properties": {
68
+ "key": { "type": "string" },
69
+ "message": { "type": "string" },
70
+ "value": {}
71
+ }
72
+ }
73
+ },
74
+ "conditions": {
75
+ "type": "object",
76
+ "properties": {
77
+ "showIf": {
78
+ "type": "object",
79
+ "required": ["field", "value"],
80
+ "properties": {
81
+ "field": { "type": "string" },
82
+ "value": { "type": "string" }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ },
89
+ "IFormLayoutFieldOption": {
90
+ "type": "object",
91
+ "required": ["value"],
92
+ "properties": {
93
+ "value": { "type": "string" }
94
+ }
95
+ }
96
+ }
97
+ }