@react-fabric/form 1.0.0-beta.5 → 1.0.0-beta.52

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 (187) hide show
  1. package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
  2. package/css/_colorPicker.css +65 -0
  3. package/{src/internal/Field.module.css → css/_field.css} +64 -29
  4. package/{src/input/File.module.css → css/_file.css} +21 -6
  5. package/css/styles.css +27 -0
  6. package/dist/cjs/builder/FileField.js +37 -25
  7. package/dist/cjs/builder/FormField.js +50 -34
  8. package/dist/cjs/builder/SchemaEditor.js +72 -0
  9. package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +143 -0
  11. package/dist/cjs/builder/components/SchemaField.js +414 -0
  12. package/dist/cjs/form/Controller.js +46 -1
  13. package/dist/cjs/form/Form.js +43 -6
  14. package/dist/cjs/hooks/useFileUploader.js +16 -0
  15. package/dist/cjs/hooks/useFormBuilder.js +57 -15
  16. package/dist/cjs/i18n/ar.json.js +5 -4
  17. package/dist/cjs/i18n/en.json.js +5 -5
  18. package/dist/cjs/index.js +11 -2
  19. package/dist/cjs/input/ArrayInput.js +100 -33
  20. package/dist/cjs/input/AvatarInput.js +17 -8
  21. package/dist/cjs/input/Checkbox.js +15 -5
  22. package/dist/cjs/input/ColorInput.js +108 -56
  23. package/dist/cjs/input/ColorPicker.js +11 -35
  24. package/dist/cjs/input/DateInput.js +195 -0
  25. package/dist/cjs/input/Field.js +10 -4
  26. package/dist/cjs/input/File.js +14 -7
  27. package/dist/cjs/input/Hidden.js +11 -1
  28. package/dist/cjs/input/Input.js +19 -7
  29. package/dist/cjs/input/Number.js +17 -7
  30. package/dist/cjs/input/Password.js +16 -8
  31. package/dist/cjs/input/Radio.js +11 -2
  32. package/dist/cjs/input/RadioGroup.js +14 -3
  33. package/dist/cjs/input/{Range.js → RangeSlider.js} +14 -6
  34. package/dist/cjs/input/Search.js +25 -16
  35. package/dist/cjs/input/Slider.js +10 -4
  36. package/dist/cjs/input/Switch.js +39 -7
  37. package/dist/cjs/input/Textarea.js +23 -4
  38. package/dist/cjs/internal/ErrorIcon.js +1 -1
  39. package/dist/cjs/internal/FieldWrapper.js +11 -4
  40. package/dist/cjs/internal/InputWrapper.js +19 -16
  41. package/dist/cjs/select/AutoComplete.js +19 -8
  42. package/dist/cjs/select/DualList.js +15 -1
  43. package/dist/cjs/select/List.js +45 -20
  44. package/dist/cjs/select/Options.js +2 -2
  45. package/dist/cjs/select/Select.js +14 -4
  46. package/dist/cjs/select/useSelect.js +10 -6
  47. package/dist/cjs/types/schema.js +43 -0
  48. package/dist/cjs/utils/eventHandlers.js +11 -5
  49. package/dist/cjs/utils/getColor.js +6 -0
  50. package/dist/esm/builder/FileField.js +39 -27
  51. package/dist/esm/builder/FormField.js +50 -34
  52. package/dist/esm/builder/SchemaEditor.js +72 -0
  53. package/dist/esm/builder/components/AddSchemaFields.js +62 -0
  54. package/dist/esm/builder/components/SchemaArrayForm.js +143 -0
  55. package/dist/esm/builder/components/SchemaField.js +414 -0
  56. package/dist/esm/form/Controller.js +46 -1
  57. package/dist/esm/form/Form.js +43 -6
  58. package/dist/esm/hooks/useFileUploader.js +16 -0
  59. package/dist/esm/hooks/useFormBuilder.js +55 -13
  60. package/dist/esm/i18n/ar.json.js +5 -4
  61. package/dist/esm/i18n/en.json.js +5 -5
  62. package/dist/esm/index.js +5 -1
  63. package/dist/esm/input/ArrayInput.js +100 -33
  64. package/dist/esm/input/AvatarInput.js +17 -8
  65. package/dist/esm/input/Checkbox.js +15 -5
  66. package/dist/esm/input/ColorInput.js +110 -58
  67. package/dist/esm/input/ColorPicker.js +11 -35
  68. package/dist/esm/input/DateInput.js +195 -0
  69. package/dist/esm/input/Field.js +11 -5
  70. package/dist/esm/input/File.js +16 -9
  71. package/dist/esm/input/Hidden.js +11 -1
  72. package/dist/esm/input/Input.js +21 -9
  73. package/dist/esm/input/Number.js +19 -9
  74. package/dist/esm/input/Password.js +18 -10
  75. package/dist/esm/input/Radio.js +11 -2
  76. package/dist/esm/input/RadioGroup.js +15 -4
  77. package/dist/esm/input/{Range.js → RangeSlider.js} +14 -6
  78. package/dist/esm/input/Search.js +27 -18
  79. package/dist/esm/input/Slider.js +10 -4
  80. package/dist/esm/input/Switch.js +41 -9
  81. package/dist/esm/input/Textarea.js +24 -5
  82. package/dist/esm/internal/ErrorIcon.js +1 -1
  83. package/dist/esm/internal/FieldWrapper.js +11 -4
  84. package/dist/esm/internal/InputWrapper.js +19 -16
  85. package/dist/esm/select/AutoComplete.js +19 -8
  86. package/dist/esm/select/DualList.js +15 -1
  87. package/dist/esm/select/List.js +46 -21
  88. package/dist/esm/select/Options.js +2 -2
  89. package/dist/esm/select/Select.js +14 -4
  90. package/dist/esm/select/useSelect.js +11 -7
  91. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  92. package/dist/esm/utils/eventHandlers.js +11 -5
  93. package/dist/esm/utils/getColor.js +6 -1
  94. package/dist/types/builder/FileField.d.ts +4 -2
  95. package/dist/types/builder/FormField.d.ts +3 -1
  96. package/dist/types/builder/SchemaEditor.d.ts +9 -0
  97. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  98. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  99. package/dist/types/builder/components/SchemaField.d.ts +10 -0
  100. package/dist/types/form/Controller.d.ts +47 -2
  101. package/dist/types/form/Form.d.ts +37 -2
  102. package/dist/types/hooks/useFileUploader.d.ts +16 -0
  103. package/dist/types/hooks/useFormBuilder.d.ts +32 -1
  104. package/dist/types/index.d.ts +5 -2
  105. package/dist/types/input/ArrayInput.d.ts +78 -6
  106. package/dist/types/input/AvatarInput.d.ts +14 -3
  107. package/dist/types/input/Checkbox.d.ts +13 -4
  108. package/dist/types/input/ColorInput.d.ts +15 -2
  109. package/dist/types/input/ColorPicker.d.ts +11 -1
  110. package/dist/types/input/DateInput.d.ts +28 -0
  111. package/dist/types/input/Field.d.ts +5 -1
  112. package/dist/types/input/File.d.ts +9 -0
  113. package/dist/types/input/Hidden.d.ts +8 -0
  114. package/dist/types/input/Input.d.ts +9 -1
  115. package/dist/types/input/Number.d.ts +9 -1
  116. package/dist/types/input/Password.d.ts +7 -1
  117. package/dist/types/input/Radio.d.ts +9 -1
  118. package/dist/types/input/RadioGroup.d.ts +26 -3
  119. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +10 -2
  120. package/dist/types/input/Search.d.ts +14 -1
  121. package/dist/types/input/Slider.d.ts +7 -1
  122. package/dist/types/input/Switch.d.ts +16 -4
  123. package/dist/types/input/Textarea.d.ts +15 -1
  124. package/dist/types/internal/FieldWrapper.d.ts +1 -1
  125. package/dist/types/internal/InputWrapper.d.ts +1 -1
  126. package/dist/types/ranger/index.d.ts +2 -2
  127. package/dist/types/select/AutoComplete.d.ts +8 -1
  128. package/dist/types/select/DualList.d.ts +17 -2
  129. package/dist/types/select/List.d.ts +9 -1
  130. package/dist/types/select/Select.d.ts +9 -1
  131. package/dist/types/select/useSelect.d.ts +7 -6
  132. package/dist/types/types/index.d.ts +28 -7
  133. package/dist/types/types/schema.d.ts +78 -33
  134. package/dist/types/utils/eventHandlers.d.ts +1 -1
  135. package/package.json +15 -12
  136. package/src/builder/FileField.tsx +53 -27
  137. package/src/builder/FormField.tsx +52 -32
  138. package/src/builder/SchemaEditor.tsx +79 -0
  139. package/src/builder/components/AddSchemaFields.tsx +74 -0
  140. package/src/builder/components/SchemaArrayForm.tsx +158 -0
  141. package/src/builder/components/SchemaField.tsx +436 -0
  142. package/src/form/Controller.tsx +48 -3
  143. package/src/form/Form.tsx +45 -5
  144. package/src/hooks/useFileUploader.ts +16 -0
  145. package/src/hooks/useFormBuilder.tsx +58 -15
  146. package/src/i18n/ar.json +5 -4
  147. package/src/i18n/en.json +5 -5
  148. package/src/index.ts +11 -2
  149. package/src/input/ArrayInput.tsx +169 -54
  150. package/src/input/AvatarInput.tsx +20 -8
  151. package/src/input/Checkbox.tsx +15 -5
  152. package/src/input/ColorInput.tsx +126 -69
  153. package/src/input/ColorPicker.tsx +12 -36
  154. package/src/input/DateInput.tsx +259 -0
  155. package/src/input/Field.tsx +15 -11
  156. package/src/input/File.tsx +16 -14
  157. package/src/input/Hidden.tsx +12 -1
  158. package/src/input/Input.tsx +23 -10
  159. package/src/input/Number.tsx +18 -10
  160. package/src/input/Password.tsx +19 -12
  161. package/src/input/Radio.tsx +11 -2
  162. package/src/input/RadioGroup.tsx +35 -4
  163. package/src/input/{Range.tsx → RangeSlider.tsx} +13 -5
  164. package/src/input/Search.tsx +29 -19
  165. package/src/input/Slider.tsx +10 -4
  166. package/src/input/Switch.tsx +52 -7
  167. package/src/input/Textarea.tsx +29 -5
  168. package/src/internal/ErrorIcon.tsx +1 -1
  169. package/src/internal/FieldWrapper.tsx +8 -4
  170. package/src/internal/InputWrapper.tsx +36 -20
  171. package/src/select/AutoComplete.tsx +12 -1
  172. package/src/select/DualList.tsx +19 -0
  173. package/src/select/List.tsx +49 -8
  174. package/src/select/Options.tsx +1 -1
  175. package/src/select/Select.tsx +21 -3
  176. package/src/select/useSelect.tsx +13 -5
  177. package/src/types/index.ts +34 -8
  178. package/src/types/schema.ts +96 -41
  179. package/src/utils/eventHandlers.ts +9 -3
  180. package/dist/cjs/input/ArrayInput.module.css +0 -1
  181. package/dist/cjs/input/ColorPicker.module.css +0 -1
  182. package/dist/cjs/input/File.module.css +0 -1
  183. package/dist/cjs/internal/Field.module.css +0 -1
  184. package/dist/esm/input/ArrayInput.module.css +0 -1
  185. package/dist/esm/input/ColorPicker.module.css +0 -1
  186. package/dist/esm/input/File.module.css +0 -1
  187. package/dist/esm/internal/Field.module.css +0 -1
@@ -21,20 +21,20 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer var {
25
- .arrayInput {
24
+ @layer variants {
25
+ .fabric-arrayInput {
26
26
  & [data-ref="fieldWrapper"] {
27
27
  flex: 1 1 0%;
28
28
  }
29
29
 
30
- & .addButton :global(.buttonInner) {
31
- color: theme(colors.tint.600);
32
- outline: 1px dashed theme(colors.tint.600);
30
+ & .fabric-addButton .fabric-button {
31
+ color: var(--color-tint-600);
32
+ outline: 1px dashed var(--color-tint-600);
33
33
 
34
34
  &[data-invalid="true"] {
35
- color: theme(colors.danger.600);
36
- background-color: theme(colors.danger.100);
37
- outline: 1px dashed theme(colors.danger.600);
35
+ color: var(--color-danger-600);
36
+ background-color: var(--color-danger-100);
37
+ outline: 1px dashed var(--color-danger-600);
38
38
  }
39
39
  }
40
40
  }
@@ -0,0 +1,65 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ @layer components {
25
+ .fabric-colorPicker {
26
+ --color-shadow: var(--border-color-base);
27
+
28
+ & input {
29
+ padding: 0 4px !important;
30
+
31
+ line-height: 2;
32
+ color: var(--text-color-base);
33
+
34
+ background-color: var(--bg-color-base);
35
+ border: 1px solid var(--border-color-base);
36
+ border-radius: var(--rounded-sm);
37
+ box-shadow: none;
38
+
39
+ &:focus {
40
+ border-color: var(--border-primary-500);
41
+ }
42
+ }
43
+
44
+ & label {
45
+ color: var(--text-color-base);
46
+ }
47
+
48
+ & .flexbox-fix {
49
+ justify-content: center;
50
+ border-color: var(--border-color-muted);
51
+
52
+ & > div > div {
53
+ text-align: center;
54
+ }
55
+
56
+ & span > div {
57
+ box-shadow: 0 0 1px 1px var(--border-color-base) inset !important;
58
+ }
59
+ }
60
+
61
+ & .saturation-black ~ div {
62
+ pointer-events: none;
63
+ }
64
+ }
65
+ }
@@ -21,28 +21,28 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer comp {
25
- .fieldWrapper {
24
+ @layer components {
25
+ .fabric-fieldWrapper {
26
26
  /* later */
27
27
  }
28
28
  }
29
29
 
30
- @layer var {
31
- .inputWrapper {
30
+ @layer variants {
31
+ .fabric-inputWrapper {
32
32
  &::after {
33
33
  inset-inline: 50%;
34
34
  transition: all 300ms;
35
35
  transition-delay: 100ms;
36
36
  }
37
37
 
38
- & .decorate:has([data-ref="button"]) {
38
+ & .fabric-decorate:has([data-ref="button"]) {
39
39
  display: flex;
40
40
  align-self: stretch;
41
41
  }
42
42
 
43
43
  &:has(input[disabled], textarea[disabled]) {
44
44
  cursor: not-allowed;
45
- background-color: theme(colors.tint.50);
45
+ background-color: var(--color-tint-50);
46
46
 
47
47
  & input,
48
48
  & textarea {
@@ -54,14 +54,14 @@
54
54
  &:has([data-open="true"]) {
55
55
  z-index: 1;
56
56
  background-color: var(--fabric-input-focus);
57
- outline-color: var(--primary);
57
+ outline-color: var(--color-primary);
58
58
 
59
59
  &:not(:has([aria-readonly="true"]:not([hidden])))::after {
60
60
  inset-inline: 0;
61
61
  }
62
62
  }
63
63
 
64
- &:global(.fixed) {
64
+ &.fixed {
65
65
  box-shadow: 0 0 2rem 0.5rem var(--fabric-shadow);
66
66
  }
67
67
 
@@ -71,7 +71,7 @@
71
71
  }
72
72
 
73
73
  & > input[type="number"] + .inputClear {
74
- margin-inline: -3rem 2rem;
74
+ margin-inline: -3rem 0;
75
75
  }
76
76
 
77
77
  & input::-ms-clear,
@@ -90,49 +90,84 @@
90
90
  letter-spacing: 2px;
91
91
  }
92
92
 
93
+ & input[type="date"]::-webkit-calendar-picker-indicator,
94
+ & input[type="datetime-local"]::-webkit-calendar-picker-indicator {
95
+ display: none;
96
+ appearance: none;
97
+ }
98
+
99
+ & input[type="date"].empty::-webkit-datetime-edit,
100
+ & input[type="datetime-local"].empty::-webkit-datetime-edit {
101
+ color: var(--color-tint-400);
102
+ }
103
+
93
104
  & input:-webkit-autofill {
94
105
  box-shadow: 0 0 0 999em var(--fabric-input) inset;
95
106
 
96
- -webkit-text-fill-color: theme(colors.accent.700);
107
+ -webkit-text-fill-color: var(--color-accent-700);
97
108
  }
98
109
 
99
110
  & input:-webkit-autofill:focus {
100
111
  box-shadow: 0 0 0 999em var(--fabric-input-focus) inset;
101
112
 
102
- -webkit-text-fill-color: theme(colors.accent.700);
113
+ -webkit-text-fill-color: var(--color-accent-700);
103
114
  }
104
115
 
105
- &.invalidWrapper {
106
- outline-color: theme(colors.danger.500);
116
+ &.fabric-invalidWrapper {
117
+ outline-color: var(--color-danger-500);
107
118
 
108
119
  &::after {
109
- background-color: theme(colors.danger.500);
120
+ background-color: var(--color-danger-500);
110
121
  }
111
122
  }
112
123
  }
113
124
 
114
- .fieldGroup {
125
+ .fabric-fieldGroup {
115
126
  > * {
116
127
  line-height: 1;
117
128
  }
118
129
 
119
- > :not(:first-child) {
120
- &,
121
- & > div,
122
- & > [role="button"],
123
- & > [data-ref="button"] > [role="button"] {
124
- border-start-start-radius: 0;
125
- border-end-start-radius: 0;
130
+ &[data-vertical="false"] {
131
+ > :not(:first-child) {
132
+ &,
133
+ & > div,
134
+ & > [role="button"],
135
+ & > [data-ref="button"] > [role="button"] {
136
+ border-start-start-radius: 0;
137
+ border-end-start-radius: 0;
138
+ }
139
+ }
140
+
141
+ > :not(:last-child) {
142
+ &,
143
+ & > div,
144
+ & > [role="button"],
145
+ & > [data-ref="button"] > [role="button"] {
146
+ border-start-end-radius: 0;
147
+ border-end-end-radius: 0;
148
+ }
126
149
  }
127
150
  }
128
151
 
129
- > :not(:last-child) {
130
- &,
131
- & > div,
132
- & > [role="button"],
133
- & > [data-ref="button"] > [role="button"] {
134
- border-start-end-radius: 0;
135
- border-end-end-radius: 0;
152
+ &[data-vertical="true"] {
153
+ > :not(:first-child) {
154
+ &,
155
+ & > div,
156
+ & > [role="button"],
157
+ & > [data-ref="button"] > [role="button"] {
158
+ border-start-start-radius: 0;
159
+ border-start-end-radius: 0;
160
+ }
161
+ }
162
+
163
+ > :not(:last-child) {
164
+ &,
165
+ & > div,
166
+ & > [role="button"],
167
+ & > [data-ref="button"] > [role="button"] {
168
+ border-end-start-radius: 0;
169
+ border-end-end-radius: 0;
170
+ }
136
171
  }
137
172
  }
138
173
  }
@@ -21,22 +21,37 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- @layer comp {
25
- .fileInput {
24
+ @layer components {
25
+ .fabric-fileInput {
26
26
  &::-webkit-file-upload-button {
27
- @apply bg-primary-500 opacity-80 hover:opacity-90 text-white rounded border-none py-0 cursor-pointer;
27
+ cursor: pointer;
28
+
29
+ padding-block: 0;
30
+ padding-inline: 4px;
31
+
32
+ color: var(--color-white);
33
+
34
+ opacity: 0.8;
35
+ background-color: var(--color-primary-500);
36
+ border: 0;
37
+ border-radius: var(--rounded);
38
+
39
+ &:hover {
40
+ opacity: 0.9;
41
+ }
28
42
  }
29
43
 
30
44
  &[aria-invalid="true"]::-webkit-file-upload-button {
31
- @apply bg-danger-500;
45
+ background-color: var(--color-danger-500);
32
46
  }
33
47
 
34
48
  &:disabled::-webkit-file-upload-button {
35
- @apply bg-muted pointer-events-none;
49
+ pointer-events: none;
50
+ background-color: var(--bg-color-muted);
36
51
  }
37
52
 
38
53
  &[readOnly] {
39
- @apply pointer-events-none;
54
+ pointer-events: none;
40
55
  }
41
56
  }
42
57
  }
package/css/styles.css ADDED
@@ -0,0 +1,27 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ @import "./_arrayInput.css";
25
+ @import "./_colorPicker.css";
26
+ @import "./_field.css";
27
+ @import "./_file.css";
@@ -7,23 +7,29 @@ var _regeneratorRuntime = require('@babel/runtime/regenerator');
7
7
  var core = require('@react-fabric/core');
8
8
  var utilities = require('@react-fabric/utilities');
9
9
  var react = require('react');
10
+ var reactI18next = require('react-i18next');
10
11
  var useFileUploader = require('../hooks/useFileUploader.js');
11
12
  var Field = require('../input/Field.js');
12
13
  var Hidden = require('../input/Hidden.js');
13
14
  var jsxRuntime = require('react/jsx-runtime');
14
15
 
15
- var _excluded = ["uploadHandler", "inline", "label", "accept", "multiple", "value"];
16
+ var _excluded = ["uploadHandler", "inline", "label", "accept", "value", "fileUrl", "multiple", "invalid", "error"];
16
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
18
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
19
  var FileField = function FileField(_ref) {
20
+ var _error$values$label, _error$values, _error$values2;
19
21
  var uploadHandler = _ref.uploadHandler,
20
22
  inline = _ref.inline,
21
23
  label = _ref.label,
22
24
  accept = _ref.accept,
23
- _ref$multiple = _ref.multiple,
24
- multiple = _ref$multiple === void 0 ? false : _ref$multiple,
25
- value = _ref.value,
25
+ value = _ref.value;
26
+ _ref.fileUrl;
27
+ var multiple = _ref.multiple;
28
+ _ref.invalid;
29
+ var error = _ref.error,
26
30
  rest = _objectWithoutProperties(_ref, _excluded);
31
+ var _useTranslation = reactI18next.useTranslation(),
32
+ t = _useTranslation.t;
27
33
  var _useFileUploader = useFileUploader.useFileUploader( /*#__PURE__*/function () {
28
34
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
29
35
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -49,32 +55,38 @@ var FileField = function FileField(_ref) {
49
55
  upload = _useFileUploader.upload,
50
56
  remove = _useFileUploader.remove;
51
57
  return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
52
- children: [/*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
58
+ children: [/*#__PURE__*/jsxRuntime.jsx(Field.Field, {
53
59
  plain: true,
54
60
  inline: inline,
55
61
  label: label,
56
- className: "inline-block",
57
- children: [/*#__PURE__*/jsxRuntime.jsx(Hidden.HiddenInput, _objectSpread({
62
+ children: /*#__PURE__*/jsxRuntime.jsx(Hidden.HiddenInput, _objectSpread({
58
63
  hiddenValue: multiple ? list : list === null || list === void 0 ? void 0 : list[0]
59
- }, rest)), /*#__PURE__*/jsxRuntime.jsx("span", {
60
- children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
61
- badge: pending > 0 ? "".concat(pending) : undefined,
62
- "data-ref": "filebtn",
63
- children: /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
64
- children: [/*#__PURE__*/jsxRuntime.jsx("span", {
65
- children: "Add file"
66
- }), /*#__PURE__*/jsxRuntime.jsx("input", {
67
- type: "file",
68
- accept: accept,
69
- multiple: multiple,
70
- className: "absolute inset-0 opacity-0 z-5",
71
- onChange: function onChange(e) {
72
- return [upload(e.target.files), e.target.value = ""];
73
- }
74
- })]
75
- })
64
+ }, rest))
65
+ }), /*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
66
+ color: "danger-200",
67
+ content: utilities.isString(error) ? "".concat(error) : error && t(error === null || error === void 0 ? void 0 : error.key, error.values ? _objectSpread(_objectSpread({}, error === null || error === void 0 ? void 0 : error.values), {}, {
68
+ label: t((_error$values$label = (_error$values = error.values) === null || _error$values === void 0 ? void 0 : _error$values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", (_error$values2 = error.values) === null || _error$values2 === void 0 ? void 0 : _error$values2.path)
69
+ }) : {}),
70
+ disabled: !error,
71
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
72
+ badge: pending > 0 ? "".concat(pending) : undefined,
73
+ color: error ? "danger" : undefined,
74
+ variant: error ? "soft" : undefined,
75
+ "data-ref": "filebtn",
76
+ children: /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
77
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
78
+ children: "Add file"
79
+ }), /*#__PURE__*/jsxRuntime.jsx("input", {
80
+ type: "file",
81
+ accept: accept,
82
+ multiple: multiple,
83
+ className: "absolute inset-0 opacity-0 z-5",
84
+ onChange: function onChange(e) {
85
+ return [upload(e.target.files), e.target.value = ""];
86
+ }
87
+ })]
76
88
  })
77
- })]
89
+ })
78
90
  }), /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx("div", {
79
91
  className: "bg-alternate",
80
92
  children: files.map(function (file, idx) {
@@ -2,22 +2,25 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
+ var utilities = require('@react-fabric/utilities');
5
6
  var react = require('react');
6
7
  var reactI18next = require('react-i18next');
7
8
  var Controller = require('../form/Controller.js');
8
9
  var ArrayInput = require('../input/ArrayInput.js');
9
10
  var AvatarInput = require('../input/AvatarInput.js');
10
11
  var ColorInput = require('../input/ColorInput.js');
12
+ var DateInput = require('../input/DateInput.js');
11
13
  var Input = require('../input/Input.js');
12
14
  var Number = require('../input/Number.js');
13
- var Range = require('../input/Range.js');
15
+ var RangeSlider = require('../input/RangeSlider.js');
14
16
  var Switch = require('../input/Switch.js');
15
17
  var Textarea = require('../input/Textarea.js');
16
18
  var Select = require('../select/Select.js');
19
+ var schema = require('../types/schema.js');
17
20
  var FileField = require('./FileField.js');
18
21
  var jsxRuntime = require('react/jsx-runtime');
19
22
 
20
- var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "defaultValue", "fileUrl", "uploadHandler"];
23
+ var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "optionLists", "fileUrl", "uploadHandler"];
21
24
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
25
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
26
  var FormField = function FormField(_ref) {
@@ -26,9 +29,9 @@ var FormField = function FormField(_ref) {
26
29
  required = _ref.required,
27
30
  inline = _ref.inline,
28
31
  prefix = _ref.prefix,
29
- autoFocus = _ref.autoFocus;
30
- _ref.defaultValue;
31
- var fileUrl = _ref.fileUrl,
32
+ autoFocus = _ref.autoFocus,
33
+ optionLists = _ref.optionLists,
34
+ fileUrl = _ref.fileUrl,
32
35
  uploadHandler = _ref.uploadHandler,
33
36
  rest = _objectWithoutProperties(_ref, _excluded);
34
37
  var _useTranslation = reactI18next.useTranslation(),
@@ -36,48 +39,61 @@ var FormField = function FormField(_ref) {
36
39
  var fieldName = react.useMemo(function () {
37
40
  return [prefix, id].filter(Boolean).join(".");
38
41
  }, [id, prefix]);
42
+ var hasOptions = react.useMemo(function () {
43
+ var _rest$optionList;
44
+ return rest.datatype === schema.DATA_TYPES.STRING && (rest.optionList === "--CUSTOM--" && !utilities.isEmpty(rest.options) || !utilities.isEmpty(optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList = rest.optionList) !== null && _rest$optionList !== void 0 ? _rest$optionList : ""]));
45
+ }, [rest]);
39
46
  var E = react.useMemo(function () {
40
- if (rest.datatype === "number" || rest.datatype === "decimal") return Number.Number;
41
- if (rest.datatype === "range") return Range.Range;
42
- if (rest.datatype === "boolean") return Switch.Switch;
43
- if (rest.datatype === "text") return Textarea.Textarea;
44
- if (rest.datatype === "color") return ColorInput.ColorInput;
45
- if (rest.datatype === "string" && rest.options) return Select.Select;
47
+ if (rest.datatype === schema.DATA_TYPES.NUMBER) return Number.Number;
48
+ if (rest.datatype === schema.DATA_TYPES.RANGE) return RangeSlider.RangeSlider;
49
+ if (rest.datatype === schema.DATA_TYPES.BOOL) return Switch.Switch;
50
+ if (rest.datatype === schema.DATA_TYPES.TEXT) return Textarea.Textarea;
51
+ if (rest.datatype === schema.DATA_TYPES.DATE) return DateInput.DateInput;
52
+ if (rest.datatype === schema.DATA_TYPES.DATETIME) return DateInput.DateInput;
53
+ if (rest.datatype === schema.DATA_TYPES.COLOR) return ColorInput.ColorInput;
54
+ if (hasOptions) return Select.Select;
46
55
  return Input.Input;
47
- }, [rest.datatype]);
56
+ }, [rest.datatype, hasOptions]);
48
57
  var props = react.useMemo(function () {
49
- var _rest$step, _rest$step2, _rest$min, _rest$max, _rest$step3;
50
- if (rest.datatype === "number") return {
58
+ var _rest$step, _rest$min, _rest$max, _rest$step2, _optionLists, _rest$optionList2;
59
+ if (rest.datatype === schema.DATA_TYPES.NUMBER) return {
51
60
  min: rest.min,
52
61
  max: rest.max,
53
62
  step: (_rest$step = rest.step) !== null && _rest$step !== void 0 ? _rest$step : 1
54
63
  };
55
- if (rest.datatype === "decimal") return {
56
- min: rest.min,
57
- max: rest.max,
58
- step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 0.1
59
- };
60
- if (rest.datatype === "range") return {
64
+ if (rest.datatype === schema.DATA_TYPES.RANGE) return {
61
65
  min: (_rest$min = rest.min) !== null && _rest$min !== void 0 ? _rest$min : 1,
62
66
  max: (_rest$max = rest.max) !== null && _rest$max !== void 0 ? _rest$max : 99,
63
- step: (_rest$step3 = rest.step) !== null && _rest$step3 !== void 0 ? _rest$step3 : 1,
67
+ step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 1,
64
68
  showValue: true,
65
69
  showLabels: true
66
70
  };
67
- if (rest.datatype === "text") return {
71
+ if (rest.datatype === schema.DATA_TYPES.DATE) return {
72
+ min: rest.min,
73
+ max: rest.max,
74
+ type: "date"
75
+ };
76
+ if (rest.datatype === schema.DATA_TYPES.DATETIME) return {
77
+ min: rest.min,
78
+ max: rest.max,
79
+ type: "datetime"
80
+ };
81
+ if (rest.datatype === schema.DATA_TYPES.TEXT) return {
68
82
  rows: 3
69
83
  };
70
- if (rest.datatype === "color") return {
84
+ if (rest.datatype === schema.DATA_TYPES.COLOR) return {
71
85
  showPicker: true
72
86
  };
73
- if (rest.datatype === "string" && rest.options) return {
74
- options: rest.options,
87
+ if (rest.datatype === schema.DATA_TYPES.STRING && hasOptions) return _objectSpread({
75
88
  multiple: rest.multiple,
89
+ allowCreate: rest.allowCustom,
76
90
  searchable: true
77
- };
91
+ }, (_optionLists = optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList2 = rest.optionList) !== null && _rest$optionList2 !== void 0 ? _rest$optionList2 : ""]) !== null && _optionLists !== void 0 ? _optionLists : {
92
+ options: rest.options
93
+ });
78
94
  return {};
79
- }, [rest]);
80
- if (rest.datatype === "avatar") return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
95
+ }, [rest, hasOptions, optionLists]);
96
+ if (rest.datatype === schema.DATA_TYPES.AVATAR) return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
81
97
  name: fieldName,
82
98
  children: /*#__PURE__*/jsxRuntime.jsx(AvatarInput.AvatarInput, {
83
99
  uploadHandler: uploadHandler,
@@ -85,7 +101,7 @@ var FormField = function FormField(_ref) {
85
101
  name: fieldName
86
102
  })
87
103
  });
88
- if (rest.datatype === "file") return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
104
+ if (rest.datatype === schema.DATA_TYPES.FILE) return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
89
105
  name: fieldName,
90
106
  children: /*#__PURE__*/jsxRuntime.jsx(FileField.FileField, _objectSpread({
91
107
  uploadHandler: uploadHandler,
@@ -94,12 +110,12 @@ var FormField = function FormField(_ref) {
94
110
  id: id
95
111
  }, rest))
96
112
  });
97
- return rest.multiple && !("options" in rest) ? /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
113
+ return rest.multiple && !hasOptions ? /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
98
114
  name: fieldName,
99
- label: t(label, label),
115
+ label: t("fb.".concat(id), label || id),
100
116
  required: required,
101
117
  onAdd: function onAdd() {
102
- return "";
118
+ return String("");
103
119
  },
104
120
  children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
105
121
  children: /*#__PURE__*/jsxRuntime.jsx(E, _objectSpread({}, props))
@@ -108,8 +124,8 @@ var FormField = function FormField(_ref) {
108
124
  name: fieldName,
109
125
  children: /*#__PURE__*/jsxRuntime.jsx(E, _objectSpread(_objectSpread({}, props), {}, {
110
126
  autoFocus: autoFocus,
111
- label: t(label, label),
112
- placeholder: t(label, label),
127
+ label: t("fb.".concat(id), label || id),
128
+ placeholder: t("fb.".concat(id), label || id),
113
129
  required: required,
114
130
  inline: inline
115
131
  }))
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ var core = require('@react-fabric/core');
4
+ var utilities = require('@react-fabric/utilities');
5
+ var react = require('react');
6
+ var Form = require('../form/Form.js');
7
+ var schema = require('../types/schema.js');
8
+ var SchemaArrayForm = require('./components/SchemaArrayForm.js');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+
11
+ /*
12
+ * React Fabric
13
+ * @version: 1.0.0
14
+ *
15
+ *
16
+ * The MIT License (MIT)
17
+ * Copyright (c) 2025 Adarsh Pastakia
18
+ *
19
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
20
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
21
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
22
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
23
+ * subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
26
+ * portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
29
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+ */
33
+
34
+ var SchemaEditor = function SchemaEditor(_ref) {
35
+ var schemaDef = _ref.schemaDef,
36
+ dynamic = _ref.dynamic,
37
+ acceptableTypes = _ref.acceptableTypes,
38
+ _ref$optionLists = _ref.optionLists,
39
+ optionLists = _ref$optionLists === void 0 ? utilities.EMPTY_ARRAY : _ref$optionLists,
40
+ children = _ref.children,
41
+ onSubmit = _ref.onSubmit,
42
+ onChange = _ref.onChange;
43
+ var formRef = react.useRef(null);
44
+ var handleChange = react.useCallback(function (model) {
45
+ onChange === null || onChange === void 0 || onChange(model.schema);
46
+ }, []);
47
+ var handleSubmit = react.useCallback(function (model) {
48
+ onSubmit === null || onSubmit === void 0 || onSubmit(model.schema);
49
+ }, []);
50
+ react.useEffect(function () {
51
+ var _formRef$current;
52
+ (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
53
+ schema: schemaDef
54
+ });
55
+ }, [schemaDef]);
56
+ return /*#__PURE__*/jsxRuntime.jsxs(Form.Form, {
57
+ formRef: formRef,
58
+ onChange: handleChange,
59
+ onSubmit: handleSubmit,
60
+ children: [/*#__PURE__*/jsxRuntime.jsx(SchemaArrayForm.SchemaArrayForm, {
61
+ dynamic: dynamic,
62
+ optionLists: optionLists,
63
+ acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(schema.DATA_TYPES)
64
+ }), children && /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
65
+ flex: true,
66
+ className: "border-t bg-base px-6 py-2",
67
+ children: children
68
+ })]
69
+ });
70
+ };
71
+
72
+ exports.SchemaEditor = SchemaEditor;