@gzl10/nexus-sdk 0.12.7 → 0.13.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.
@@ -0,0 +1,377 @@
1
+ // src/fields/color.ts
2
+ function useColorField(config) {
3
+ const { label, hint, defaultValue, placeholder, required, nullable, meta, ...overrides } = config;
4
+ return {
5
+ label,
6
+ input: "color",
7
+ hint,
8
+ required: required ?? false,
9
+ placeholder,
10
+ defaultValue,
11
+ db: {
12
+ type: "string",
13
+ size: 9,
14
+ // #RRGGBBAA
15
+ nullable: nullable ?? !required,
16
+ default: defaultValue
17
+ },
18
+ meta: {
19
+ ...meta
20
+ },
21
+ ...overrides
22
+ };
23
+ }
24
+
25
+ // src/fields/media.ts
26
+ function parseFileSize(size) {
27
+ if (typeof size === "number") return size;
28
+ const match = size.match(/^(\d+(?:\.\d+)?)(B|KB|MB|GB)$/i);
29
+ if (!match || !match[1] || !match[2]) {
30
+ throw new Error(`Invalid file size format: ${size}`);
31
+ }
32
+ const value = match[1];
33
+ const unit = match[2].toUpperCase();
34
+ const multipliers = {
35
+ B: 1,
36
+ KB: 1024,
37
+ MB: 1024 * 1024,
38
+ GB: 1024 * 1024 * 1024
39
+ };
40
+ return Math.round(parseFloat(value) * multipliers[unit]);
41
+ }
42
+ function useImageField(config) {
43
+ const {
44
+ label,
45
+ hint,
46
+ accept = "image/*",
47
+ maxSize = "1MB",
48
+ folder,
49
+ isPublic,
50
+ dedupe,
51
+ required,
52
+ nullable,
53
+ meta,
54
+ ...overrides
55
+ } = config;
56
+ return {
57
+ label,
58
+ input: "image",
59
+ hint,
60
+ required: required ?? false,
61
+ db: {
62
+ type: "string",
63
+ nullable: nullable ?? !required
64
+ },
65
+ storage: {
66
+ accept,
67
+ maxSize: parseFileSize(maxSize),
68
+ folder,
69
+ isPublic,
70
+ dedupe
71
+ },
72
+ meta: {
73
+ ...meta
74
+ },
75
+ ...overrides
76
+ };
77
+ }
78
+ function useFileField(config) {
79
+ const {
80
+ label,
81
+ hint,
82
+ accept = "*/*",
83
+ maxSize = "10MB",
84
+ folder,
85
+ isPublic,
86
+ dedupe,
87
+ required,
88
+ nullable,
89
+ meta,
90
+ ...overrides
91
+ } = config;
92
+ return {
93
+ label,
94
+ input: "file",
95
+ hint,
96
+ required: required ?? false,
97
+ db: {
98
+ type: "string",
99
+ nullable: nullable ?? !required
100
+ },
101
+ storage: {
102
+ accept,
103
+ maxSize: parseFileSize(maxSize),
104
+ folder,
105
+ isPublic,
106
+ dedupe
107
+ },
108
+ meta: {
109
+ ...meta
110
+ },
111
+ ...overrides
112
+ };
113
+ }
114
+ function useMultiImageField(config) {
115
+ const {
116
+ label,
117
+ hint,
118
+ accept = "image/*",
119
+ maxSize = "1MB",
120
+ maxFiles = 10,
121
+ folder,
122
+ isPublic,
123
+ dedupe,
124
+ thumbnails,
125
+ required,
126
+ nullable,
127
+ meta,
128
+ ...overrides
129
+ } = config;
130
+ return {
131
+ label,
132
+ input: "multiimage",
133
+ hint,
134
+ required: required ?? false,
135
+ db: {
136
+ type: "json",
137
+ nullable: nullable ?? !required
138
+ },
139
+ storage: {
140
+ accept,
141
+ maxSize: parseFileSize(maxSize),
142
+ maxFiles,
143
+ folder,
144
+ isPublic,
145
+ dedupe,
146
+ thumbnails
147
+ },
148
+ meta: {
149
+ ...meta
150
+ },
151
+ ...overrides
152
+ };
153
+ }
154
+ function useMultiFileField(config) {
155
+ const {
156
+ label,
157
+ hint,
158
+ accept = "*/*",
159
+ maxSize = "10MB",
160
+ maxFiles = 10,
161
+ folder,
162
+ isPublic,
163
+ dedupe,
164
+ required,
165
+ nullable,
166
+ meta,
167
+ ...overrides
168
+ } = config;
169
+ return {
170
+ label,
171
+ input: "multifile",
172
+ hint,
173
+ required: required ?? false,
174
+ db: {
175
+ type: "json",
176
+ nullable: nullable ?? !required
177
+ },
178
+ storage: {
179
+ accept,
180
+ maxSize: parseFileSize(maxSize),
181
+ maxFiles,
182
+ folder,
183
+ isPublic,
184
+ dedupe
185
+ },
186
+ meta: {
187
+ ...meta
188
+ },
189
+ ...overrides
190
+ };
191
+ }
192
+
193
+ // src/fields/textarea.ts
194
+ function useTextareaField(config) {
195
+ const { label, hint, required, nullable, defaultValue, placeholder, meta, ...overrides } = config;
196
+ return {
197
+ label,
198
+ input: "textarea",
199
+ hint,
200
+ required: required ?? false,
201
+ defaultValue,
202
+ placeholder,
203
+ db: {
204
+ type: "text",
205
+ nullable: nullable ?? !required
206
+ },
207
+ meta: {
208
+ searchable: true,
209
+ ...meta
210
+ },
211
+ ...overrides
212
+ };
213
+ }
214
+
215
+ // src/fields/json.ts
216
+ function useJsonField(config) {
217
+ const { label, hint, required, nullable, meta, ...overrides } = config;
218
+ return {
219
+ label,
220
+ input: "json",
221
+ hint,
222
+ required: required ?? false,
223
+ db: {
224
+ type: "json",
225
+ nullable: nullable ?? !required
226
+ },
227
+ meta: {
228
+ showInDisplay: false,
229
+ ...meta
230
+ },
231
+ ...overrides
232
+ };
233
+ }
234
+
235
+ // src/fields/datetime.ts
236
+ function useDatetimeField(config) {
237
+ const { label, hint, required, nullable, meta, ...overrides } = config;
238
+ return {
239
+ label,
240
+ input: "datetime",
241
+ hint,
242
+ required: required ?? false,
243
+ db: {
244
+ type: "datetime",
245
+ nullable: nullable ?? !required
246
+ },
247
+ meta: {
248
+ ...meta
249
+ },
250
+ ...overrides
251
+ };
252
+ }
253
+
254
+ // src/fields/switch.ts
255
+ function useSwitchField(config) {
256
+ const { label, hint, defaultValue = false, meta, ...overrides } = config;
257
+ return {
258
+ label,
259
+ input: "switch",
260
+ hint,
261
+ defaultValue,
262
+ db: {
263
+ type: "boolean",
264
+ nullable: false,
265
+ default: defaultValue
266
+ },
267
+ meta: {
268
+ ...meta
269
+ },
270
+ ...overrides
271
+ };
272
+ }
273
+
274
+ // src/fields/email.ts
275
+ function useEmailField(config) {
276
+ const { label, hint, required, nullable, unique, placeholder, meta, ...overrides } = config;
277
+ return {
278
+ label,
279
+ input: "email",
280
+ hint,
281
+ required: required ?? false,
282
+ placeholder,
283
+ db: {
284
+ type: "string",
285
+ size: 255,
286
+ nullable: nullable ?? !required,
287
+ unique: unique ?? false
288
+ },
289
+ validation: {
290
+ format: "email"
291
+ },
292
+ meta: {
293
+ searchable: true,
294
+ ...meta
295
+ },
296
+ ...overrides
297
+ };
298
+ }
299
+
300
+ // src/fields/checkbox.ts
301
+ function useCheckboxField(config) {
302
+ const { label, hint, defaultValue = false, meta, ...overrides } = config;
303
+ return {
304
+ label,
305
+ input: "checkbox",
306
+ hint,
307
+ defaultValue,
308
+ db: {
309
+ type: "boolean",
310
+ nullable: false,
311
+ default: defaultValue
312
+ },
313
+ meta,
314
+ ...overrides
315
+ };
316
+ }
317
+
318
+ // src/fields/password.ts
319
+ function usePasswordField(config) {
320
+ const { label, hint, required, nullable, size = 255, placeholder, validation, meta, ...overrides } = config;
321
+ return {
322
+ label,
323
+ input: "password",
324
+ hint,
325
+ required: required ?? false,
326
+ placeholder,
327
+ db: {
328
+ type: "string",
329
+ size,
330
+ nullable: nullable ?? !required
331
+ },
332
+ validation,
333
+ meta: {
334
+ searchable: false,
335
+ showInDisplay: false,
336
+ ...meta
337
+ },
338
+ ...overrides
339
+ };
340
+ }
341
+
342
+ // src/fields/tags.ts
343
+ function useTagsField(config) {
344
+ const { label, hint, required, nullable, placeholder, validation, options, meta, ...overrides } = config;
345
+ return {
346
+ label,
347
+ input: "tags",
348
+ hint,
349
+ required: required ?? false,
350
+ placeholder,
351
+ db: {
352
+ type: "json",
353
+ nullable: nullable ?? true
354
+ },
355
+ validation,
356
+ options,
357
+ meta,
358
+ ...overrides
359
+ };
360
+ }
361
+
362
+ export {
363
+ useColorField,
364
+ parseFileSize,
365
+ useImageField,
366
+ useFileField,
367
+ useMultiImageField,
368
+ useMultiFileField,
369
+ useTextareaField,
370
+ useJsonField,
371
+ useDatetimeField,
372
+ useSwitchField,
373
+ useEmailField,
374
+ useCheckboxField,
375
+ usePasswordField,
376
+ useTagsField
377
+ };