@object-ui/types 0.3.1 → 0.5.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.
- package/dist/app.d.ts +10 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/blocks.d.ts +332 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +8 -0
- package/dist/crud.d.ts +174 -3
- package/dist/crud.d.ts.map +1 -1
- package/dist/data-protocol.d.ts +1268 -0
- package/dist/data-protocol.d.ts.map +1 -0
- package/dist/data-protocol.js +8 -0
- package/dist/data.d.ts +6 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/field-types.d.ts +353 -11
- package/dist/field-types.d.ts.map +1 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/objectql.d.ts +8 -1
- package/dist/objectql.d.ts.map +1 -1
- package/dist/plugin-scope.d.ts +194 -0
- package/dist/plugin-scope.d.ts.map +1 -0
- package/dist/plugin-scope.js +8 -0
- package/dist/reports.d.ts +336 -0
- package/dist/reports.d.ts.map +1 -0
- package/dist/reports.js +8 -0
- package/dist/theme.d.ts +289 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +8 -0
- package/dist/ui-action.d.ts +175 -0
- package/dist/ui-action.d.ts.map +1 -0
- package/dist/ui-action.js +8 -0
- package/dist/views.d.ts +417 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +8 -0
- package/dist/zod/app.zod.d.ts +120 -0
- package/dist/zod/app.zod.d.ts.map +1 -0
- package/dist/zod/app.zod.js +60 -0
- package/dist/zod/blocks.zod.d.ts +834 -0
- package/dist/zod/blocks.zod.d.ts.map +1 -0
- package/dist/zod/blocks.zod.js +145 -0
- package/dist/zod/complex.zod.js +1 -1
- package/dist/zod/crud.zod.d.ts +598 -0
- package/dist/zod/crud.zod.d.ts.map +1 -0
- package/dist/zod/crud.zod.js +230 -0
- package/dist/zod/data-display.zod.js +1 -1
- package/dist/zod/disclosure.zod.js +1 -1
- package/dist/zod/feedback.zod.js +1 -1
- package/dist/zod/form.zod.js +1 -1
- package/dist/zod/index.zod.d.ts +1829 -18
- package/dist/zod/index.zod.d.ts.map +1 -1
- package/dist/zod/index.zod.js +96 -19
- package/dist/zod/layout.zod.d.ts +2 -2
- package/dist/zod/layout.zod.js +1 -1
- package/dist/zod/navigation.zod.js +1 -1
- package/dist/zod/objectql.zod.d.ts +10 -10
- package/dist/zod/objectql.zod.js +1 -1
- package/dist/zod/overlay.zod.js +1 -1
- package/dist/zod/reports.zod.d.ts +1628 -0
- package/dist/zod/reports.zod.d.ts.map +1 -0
- package/dist/zod/reports.zod.js +152 -0
- package/dist/zod/theme.zod.d.ts +611 -0
- package/dist/zod/theme.zod.d.ts.map +1 -0
- package/dist/zod/theme.zod.js +130 -0
- package/dist/zod/views.zod.d.ts +675 -0
- package/dist/zod/views.zod.d.ts.map +1 -0
- package/dist/zod/views.zod.js +159 -0
- package/package.json +2 -2
- package/src/__tests__/namespace-exports.test.ts +80 -0
- package/src/__tests__/phase2-schemas.test.ts +639 -0
- package/src/app.ts +12 -0
- package/src/blocks.ts +405 -0
- package/src/crud.ts +177 -3
- package/src/data-protocol.ts +1679 -0
- package/src/data.ts +3 -1
- package/src/field-types.ts +392 -11
- package/src/index.ts +214 -0
- package/src/objectql.ts +9 -1
- package/src/plugin-scope.ts +210 -0
- package/src/reports.ts +408 -0
- package/src/theme.ts +351 -0
- package/src/ui-action.ts +276 -0
- package/src/views.ts +429 -0
- package/src/zod/app.zod.ts +72 -0
- package/src/zod/blocks.zod.ts +170 -0
- package/src/zod/complex.zod.ts +1 -1
- package/src/zod/crud.zod.ts +259 -0
- package/src/zod/data-display.zod.ts +1 -1
- package/src/zod/disclosure.zod.ts +1 -1
- package/src/zod/feedback.zod.ts +1 -1
- package/src/zod/form.zod.ts +1 -1
- package/src/zod/index.zod.ts +167 -19
- package/src/zod/layout.zod.ts +1 -1
- package/src/zod/navigation.zod.ts +1 -1
- package/src/zod/objectql.zod.ts +1 -1
- package/src/zod/overlay.zod.ts +1 -1
- package/src/zod/reports.zod.ts +183 -0
- package/src/zod/theme.zod.ts +155 -0
- package/src/zod/views.zod.ts +182 -0
package/src/views.ts
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @object-ui/types - View Component Schemas
|
|
11
|
+
*
|
|
12
|
+
* Type definitions for various view components (List, Detail, Grid, Kanban, Calendar).
|
|
13
|
+
* These schemas enable building different data visualization interfaces.
|
|
14
|
+
*
|
|
15
|
+
* @module views
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { BaseSchema, SchemaNode } from './base';
|
|
20
|
+
import type { ActionSchema } from './crud';
|
|
21
|
+
import type { TableColumn } from './data-display';
|
|
22
|
+
import type { FormField } from './form';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* View Type
|
|
26
|
+
*/
|
|
27
|
+
export type ViewType = 'list' | 'detail' | 'grid' | 'kanban' | 'calendar' | 'timeline' | 'map';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Detail View Field Configuration
|
|
31
|
+
*/
|
|
32
|
+
export interface DetailViewField {
|
|
33
|
+
/**
|
|
34
|
+
* Field name/path
|
|
35
|
+
*/
|
|
36
|
+
name: string;
|
|
37
|
+
/**
|
|
38
|
+
* Display label
|
|
39
|
+
*/
|
|
40
|
+
label?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Field type for rendering
|
|
43
|
+
*/
|
|
44
|
+
type?: 'text' | 'image' | 'link' | 'badge' | 'date' | 'datetime' | 'json' | 'html' | 'markdown' | 'custom';
|
|
45
|
+
/**
|
|
46
|
+
* Format string (e.g., date format)
|
|
47
|
+
*/
|
|
48
|
+
format?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Custom renderer
|
|
51
|
+
*/
|
|
52
|
+
render?: SchemaNode;
|
|
53
|
+
/**
|
|
54
|
+
* Field value
|
|
55
|
+
*/
|
|
56
|
+
value?: any;
|
|
57
|
+
/**
|
|
58
|
+
* Whether field is read-only
|
|
59
|
+
*/
|
|
60
|
+
readonly?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Field visibility condition
|
|
63
|
+
*/
|
|
64
|
+
visible?: boolean | string;
|
|
65
|
+
/**
|
|
66
|
+
* Span across columns (for grid layout)
|
|
67
|
+
*/
|
|
68
|
+
span?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Detail View Section/Group
|
|
73
|
+
*/
|
|
74
|
+
export interface DetailViewSection {
|
|
75
|
+
/**
|
|
76
|
+
* Section title
|
|
77
|
+
*/
|
|
78
|
+
title?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Section description
|
|
81
|
+
*/
|
|
82
|
+
description?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Section icon
|
|
85
|
+
*/
|
|
86
|
+
icon?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Fields in this section
|
|
89
|
+
*/
|
|
90
|
+
fields: DetailViewField[];
|
|
91
|
+
/**
|
|
92
|
+
* Collapsible section
|
|
93
|
+
*/
|
|
94
|
+
collapsible?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Default collapsed state
|
|
97
|
+
*/
|
|
98
|
+
defaultCollapsed?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Grid columns for field layout
|
|
101
|
+
*/
|
|
102
|
+
columns?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Section visibility condition
|
|
105
|
+
*/
|
|
106
|
+
visible?: boolean | string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Detail View Tab
|
|
111
|
+
*/
|
|
112
|
+
export interface DetailViewTab {
|
|
113
|
+
/**
|
|
114
|
+
* Tab key/identifier
|
|
115
|
+
*/
|
|
116
|
+
key: string;
|
|
117
|
+
/**
|
|
118
|
+
* Tab label
|
|
119
|
+
*/
|
|
120
|
+
label: string;
|
|
121
|
+
/**
|
|
122
|
+
* Tab icon
|
|
123
|
+
*/
|
|
124
|
+
icon?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Tab content
|
|
127
|
+
*/
|
|
128
|
+
content: SchemaNode | SchemaNode[];
|
|
129
|
+
/**
|
|
130
|
+
* Tab visibility condition
|
|
131
|
+
*/
|
|
132
|
+
visible?: boolean | string;
|
|
133
|
+
/**
|
|
134
|
+
* Badge count
|
|
135
|
+
*/
|
|
136
|
+
badge?: string | number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Detail View Schema - Display detailed information about a single record
|
|
141
|
+
* Enhanced in Phase 2 with better organization and features
|
|
142
|
+
*/
|
|
143
|
+
export interface DetailViewSchema extends BaseSchema {
|
|
144
|
+
type: 'detail-view';
|
|
145
|
+
/**
|
|
146
|
+
* Detail title
|
|
147
|
+
*/
|
|
148
|
+
title?: string;
|
|
149
|
+
/**
|
|
150
|
+
* API endpoint to fetch detail data
|
|
151
|
+
*/
|
|
152
|
+
api?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Resource ID to display
|
|
155
|
+
*/
|
|
156
|
+
resourceId?: string | number;
|
|
157
|
+
/**
|
|
158
|
+
* Object name (for ObjectQL integration)
|
|
159
|
+
*/
|
|
160
|
+
objectName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Data to display (if not fetching from API)
|
|
163
|
+
*/
|
|
164
|
+
data?: any;
|
|
165
|
+
/**
|
|
166
|
+
* Layout mode
|
|
167
|
+
*/
|
|
168
|
+
layout?: 'vertical' | 'horizontal' | 'grid';
|
|
169
|
+
/**
|
|
170
|
+
* Grid columns (for grid layout)
|
|
171
|
+
*/
|
|
172
|
+
columns?: number;
|
|
173
|
+
/**
|
|
174
|
+
* Field sections for organized display
|
|
175
|
+
*/
|
|
176
|
+
sections?: DetailViewSection[];
|
|
177
|
+
/**
|
|
178
|
+
* Direct fields (without sections)
|
|
179
|
+
*/
|
|
180
|
+
fields?: DetailViewField[];
|
|
181
|
+
/**
|
|
182
|
+
* Actions available in detail view
|
|
183
|
+
*/
|
|
184
|
+
actions?: ActionSchema[];
|
|
185
|
+
/**
|
|
186
|
+
* Tabs for additional content
|
|
187
|
+
*/
|
|
188
|
+
tabs?: DetailViewTab[];
|
|
189
|
+
/**
|
|
190
|
+
* Show back button
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
showBack?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Back button URL
|
|
196
|
+
*/
|
|
197
|
+
backUrl?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Custom back action
|
|
200
|
+
*/
|
|
201
|
+
onBack?: string;
|
|
202
|
+
/**
|
|
203
|
+
* Show edit button
|
|
204
|
+
*/
|
|
205
|
+
showEdit?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Edit button URL
|
|
208
|
+
*/
|
|
209
|
+
editUrl?: string;
|
|
210
|
+
/**
|
|
211
|
+
* Show delete button
|
|
212
|
+
*/
|
|
213
|
+
showDelete?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Delete confirmation message
|
|
216
|
+
*/
|
|
217
|
+
deleteConfirmation?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Whether to show loading state
|
|
220
|
+
* @default true
|
|
221
|
+
*/
|
|
222
|
+
loading?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Custom header content
|
|
225
|
+
*/
|
|
226
|
+
header?: SchemaNode;
|
|
227
|
+
/**
|
|
228
|
+
* Custom footer content
|
|
229
|
+
*/
|
|
230
|
+
footer?: SchemaNode;
|
|
231
|
+
/**
|
|
232
|
+
* Related records section
|
|
233
|
+
*/
|
|
234
|
+
related?: Array<{
|
|
235
|
+
/**
|
|
236
|
+
* Relation title
|
|
237
|
+
*/
|
|
238
|
+
title: string;
|
|
239
|
+
/**
|
|
240
|
+
* Relation type
|
|
241
|
+
*/
|
|
242
|
+
type: 'list' | 'grid' | 'table';
|
|
243
|
+
/**
|
|
244
|
+
* API endpoint for related data
|
|
245
|
+
*/
|
|
246
|
+
api?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Static data
|
|
249
|
+
*/
|
|
250
|
+
data?: any[];
|
|
251
|
+
/**
|
|
252
|
+
* Columns for table view
|
|
253
|
+
*/
|
|
254
|
+
columns?: TableColumn[];
|
|
255
|
+
/**
|
|
256
|
+
* Fields for list view
|
|
257
|
+
*/
|
|
258
|
+
fields?: string[];
|
|
259
|
+
}>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* View Switcher Schema - Toggle between different view modes
|
|
264
|
+
* New in Phase 2
|
|
265
|
+
*/
|
|
266
|
+
export interface ViewSwitcherSchema extends BaseSchema {
|
|
267
|
+
type: 'view-switcher';
|
|
268
|
+
/**
|
|
269
|
+
* Available view types
|
|
270
|
+
*/
|
|
271
|
+
views: Array<{
|
|
272
|
+
/**
|
|
273
|
+
* View type
|
|
274
|
+
*/
|
|
275
|
+
type: ViewType;
|
|
276
|
+
/**
|
|
277
|
+
* View label
|
|
278
|
+
*/
|
|
279
|
+
label?: string;
|
|
280
|
+
/**
|
|
281
|
+
* View icon
|
|
282
|
+
*/
|
|
283
|
+
icon?: string;
|
|
284
|
+
/**
|
|
285
|
+
* View schema
|
|
286
|
+
*/
|
|
287
|
+
schema?: SchemaNode;
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* Default/active view
|
|
291
|
+
*/
|
|
292
|
+
defaultView?: ViewType;
|
|
293
|
+
/**
|
|
294
|
+
* Current active view
|
|
295
|
+
*/
|
|
296
|
+
activeView?: ViewType;
|
|
297
|
+
/**
|
|
298
|
+
* Switcher variant
|
|
299
|
+
*/
|
|
300
|
+
variant?: 'tabs' | 'buttons' | 'dropdown';
|
|
301
|
+
/**
|
|
302
|
+
* Switcher position
|
|
303
|
+
*/
|
|
304
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
305
|
+
/**
|
|
306
|
+
* View change callback
|
|
307
|
+
*/
|
|
308
|
+
onViewChange?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Persist view preference
|
|
311
|
+
*/
|
|
312
|
+
persistPreference?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Storage key for persisting view
|
|
315
|
+
*/
|
|
316
|
+
storageKey?: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Filter UI Schema - Enhanced filter interface
|
|
321
|
+
* New in Phase 2
|
|
322
|
+
*/
|
|
323
|
+
export interface FilterUISchema extends BaseSchema {
|
|
324
|
+
type: 'filter-ui';
|
|
325
|
+
/**
|
|
326
|
+
* Available filters
|
|
327
|
+
*/
|
|
328
|
+
filters: Array<{
|
|
329
|
+
/**
|
|
330
|
+
* Filter field
|
|
331
|
+
*/
|
|
332
|
+
field: string;
|
|
333
|
+
/**
|
|
334
|
+
* Filter label
|
|
335
|
+
*/
|
|
336
|
+
label?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Filter type
|
|
339
|
+
*/
|
|
340
|
+
type: 'text' | 'number' | 'select' | 'date' | 'date-range' | 'boolean';
|
|
341
|
+
/**
|
|
342
|
+
* Filter operator
|
|
343
|
+
*/
|
|
344
|
+
operator?: 'equals' | 'contains' | 'startsWith' | 'gt' | 'lt' | 'between' | 'in';
|
|
345
|
+
/**
|
|
346
|
+
* Options for select filter
|
|
347
|
+
*/
|
|
348
|
+
options?: Array<{ label: string; value: any }>;
|
|
349
|
+
/**
|
|
350
|
+
* Placeholder
|
|
351
|
+
*/
|
|
352
|
+
placeholder?: string;
|
|
353
|
+
}>;
|
|
354
|
+
/**
|
|
355
|
+
* Current filter values
|
|
356
|
+
*/
|
|
357
|
+
values?: Record<string, any>;
|
|
358
|
+
/**
|
|
359
|
+
* Filter change callback
|
|
360
|
+
*/
|
|
361
|
+
onChange?: string;
|
|
362
|
+
/**
|
|
363
|
+
* Show clear button
|
|
364
|
+
*/
|
|
365
|
+
showClear?: boolean;
|
|
366
|
+
/**
|
|
367
|
+
* Show apply button
|
|
368
|
+
*/
|
|
369
|
+
showApply?: boolean;
|
|
370
|
+
/**
|
|
371
|
+
* Filter layout
|
|
372
|
+
*/
|
|
373
|
+
layout?: 'inline' | 'popover' | 'drawer';
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Sort UI Schema - Enhanced sort interface
|
|
378
|
+
* New in Phase 2
|
|
379
|
+
*/
|
|
380
|
+
export interface SortUISchema extends BaseSchema {
|
|
381
|
+
type: 'sort-ui';
|
|
382
|
+
/**
|
|
383
|
+
* Sortable fields
|
|
384
|
+
*/
|
|
385
|
+
fields: Array<{
|
|
386
|
+
/**
|
|
387
|
+
* Field name
|
|
388
|
+
*/
|
|
389
|
+
field: string;
|
|
390
|
+
/**
|
|
391
|
+
* Field label
|
|
392
|
+
*/
|
|
393
|
+
label?: string;
|
|
394
|
+
}>;
|
|
395
|
+
/**
|
|
396
|
+
* Current sort configuration
|
|
397
|
+
*/
|
|
398
|
+
sort?: Array<{
|
|
399
|
+
/**
|
|
400
|
+
* Field to sort by
|
|
401
|
+
*/
|
|
402
|
+
field: string;
|
|
403
|
+
/**
|
|
404
|
+
* Sort direction
|
|
405
|
+
*/
|
|
406
|
+
direction: 'asc' | 'desc';
|
|
407
|
+
}>;
|
|
408
|
+
/**
|
|
409
|
+
* Sort change callback
|
|
410
|
+
*/
|
|
411
|
+
onChange?: string;
|
|
412
|
+
/**
|
|
413
|
+
* Allow multiple sort fields
|
|
414
|
+
*/
|
|
415
|
+
multiple?: boolean;
|
|
416
|
+
/**
|
|
417
|
+
* UI variant
|
|
418
|
+
*/
|
|
419
|
+
variant?: 'dropdown' | 'buttons';
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Union type of all view schemas
|
|
424
|
+
*/
|
|
425
|
+
export type ViewComponentSchema =
|
|
426
|
+
| DetailViewSchema
|
|
427
|
+
| ViewSwitcherSchema
|
|
428
|
+
| FilterUISchema
|
|
429
|
+
| SortUISchema;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @object-ui/types/zod - Application Schema Zod Validators
|
|
11
|
+
*
|
|
12
|
+
* Zod validation schemas for top-level application configuration.
|
|
13
|
+
* Following @objectstack/spec UI specification format.
|
|
14
|
+
*
|
|
15
|
+
* @module zod/app
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
import { BaseSchema } from './base.zod.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Menu Item Schema - Navigation menu item
|
|
24
|
+
*/
|
|
25
|
+
export const MenuItemSchema: z.ZodType<any> = z.lazy(() => z.object({
|
|
26
|
+
type: z.enum(['item', 'group', 'separator']).optional().describe('Item type'),
|
|
27
|
+
label: z.string().optional().describe('Display label'),
|
|
28
|
+
icon: z.string().optional().describe('Icon name (Lucide)'),
|
|
29
|
+
path: z.string().optional().describe('Target path (route)'),
|
|
30
|
+
href: z.string().optional().describe('External link'),
|
|
31
|
+
children: z.array(MenuItemSchema).optional().describe('Child items (submenu)'),
|
|
32
|
+
badge: z.union([z.string(), z.number()]).optional().describe('Badge or count'),
|
|
33
|
+
hidden: z.union([z.boolean(), z.string()]).optional().describe('Visibility condition'),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* App Action Schema - Application header/toolbar action
|
|
38
|
+
*/
|
|
39
|
+
export const AppActionSchema = z.object({
|
|
40
|
+
type: z.enum(['button', 'dropdown', 'user']).describe('Action type'),
|
|
41
|
+
label: z.string().optional().describe('Action label'),
|
|
42
|
+
icon: z.string().optional().describe('Icon name'),
|
|
43
|
+
onClick: z.string().optional().describe('Click handler expression'),
|
|
44
|
+
avatar: z.string().optional().describe('User avatar URL (for type="user")'),
|
|
45
|
+
description: z.string().optional().describe('Additional description (e.g., email for user)'),
|
|
46
|
+
items: z.array(MenuItemSchema).optional().describe('Dropdown menu items (for type="dropdown" or "user")'),
|
|
47
|
+
shortcut: z.string().optional().describe('Keyboard shortcut'),
|
|
48
|
+
variant: z.enum(['default', 'destructive', 'outline', 'secondary', 'ghost', 'link']).optional().describe('Button variant'),
|
|
49
|
+
size: z.enum(['default', 'sm', 'lg', 'icon']).optional().describe('Button size'),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* App Schema - Top-level application configuration
|
|
54
|
+
*/
|
|
55
|
+
export const AppSchema = BaseSchema.extend({
|
|
56
|
+
type: z.literal('app'),
|
|
57
|
+
name: z.string().optional().describe('Application name (system ID)'),
|
|
58
|
+
title: z.string().optional().describe('Display title'),
|
|
59
|
+
description: z.string().optional().describe('Application description'),
|
|
60
|
+
logo: z.string().optional().describe('Logo URL or icon name'),
|
|
61
|
+
favicon: z.string().optional().describe('Favicon URL'),
|
|
62
|
+
layout: z.enum(['sidebar', 'header', 'empty']).optional().default('sidebar').describe('Global layout strategy'),
|
|
63
|
+
menu: z.array(MenuItemSchema).optional().describe('Global navigation menu'),
|
|
64
|
+
actions: z.array(AppActionSchema).optional().describe('Global actions (user profile, settings, etc.)'),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Export type inference helpers
|
|
69
|
+
*/
|
|
70
|
+
export type MenuItemSchemaType = z.infer<typeof MenuItemSchema>;
|
|
71
|
+
export type AppActionSchemaType = z.infer<typeof AppActionSchema>;
|
|
72
|
+
export type AppSchemaType = z.infer<typeof AppSchema>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @object-ui/types/zod - Block Schema Zod Validators
|
|
11
|
+
*
|
|
12
|
+
* Zod validation schemas for reusable component blocks.
|
|
13
|
+
* Following @objectstack/spec UI specification format.
|
|
14
|
+
*
|
|
15
|
+
* @module zod/blocks
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
import { BaseSchema, SchemaNodeSchema } from './base.zod.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Block Variable Schema
|
|
24
|
+
*/
|
|
25
|
+
export const BlockVariableSchema = z.object({
|
|
26
|
+
name: z.string().describe('Variable name'),
|
|
27
|
+
label: z.string().optional().describe('Display label'),
|
|
28
|
+
type: z.enum(['string', 'number', 'boolean', 'object', 'array', 'component']).optional().describe('Variable type'),
|
|
29
|
+
defaultValue: z.any().optional().describe('Default value'),
|
|
30
|
+
description: z.string().optional().describe('Description/help text'),
|
|
31
|
+
required: z.boolean().optional().describe('Whether this variable is required'),
|
|
32
|
+
validation: z.any().optional().describe('Validation rules'),
|
|
33
|
+
enum: z.array(z.any()).optional().describe('Enum options (for string/number types)'),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Block Slot Schema
|
|
38
|
+
*/
|
|
39
|
+
export const BlockSlotSchema = z.object({
|
|
40
|
+
name: z.string().describe('Slot name'),
|
|
41
|
+
label: z.string().optional().describe('Display label'),
|
|
42
|
+
description: z.string().optional().describe('Description'),
|
|
43
|
+
defaultContent: z.union([SchemaNodeSchema, z.array(SchemaNodeSchema)]).optional().describe('Default content'),
|
|
44
|
+
allowedTypes: z.array(z.string()).optional().describe('Allowed component types'),
|
|
45
|
+
maxChildren: z.number().optional().describe('Maximum number of children'),
|
|
46
|
+
required: z.boolean().optional().describe('Whether this slot is required'),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Block Metadata Schema
|
|
51
|
+
*/
|
|
52
|
+
export const BlockMetadataSchema = z.object({
|
|
53
|
+
name: z.string().describe('Block name/identifier'),
|
|
54
|
+
label: z.string().optional().describe('Display label'),
|
|
55
|
+
description: z.string().optional().describe('Block description'),
|
|
56
|
+
category: z.string().optional().describe('Block category'),
|
|
57
|
+
icon: z.string().optional().describe('Block icon'),
|
|
58
|
+
tags: z.array(z.string()).optional().describe('Block tags for search'),
|
|
59
|
+
author: z.string().optional().describe('Author/creator'),
|
|
60
|
+
version: z.string().optional().describe('Version'),
|
|
61
|
+
license: z.string().optional().describe('License'),
|
|
62
|
+
repository: z.string().optional().describe('Repository URL'),
|
|
63
|
+
preview: z.string().optional().describe('Preview image URL'),
|
|
64
|
+
premium: z.boolean().optional().describe('Is this a premium/paid block'),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Block Schema
|
|
69
|
+
*/
|
|
70
|
+
export const BlockSchema = BaseSchema.extend({
|
|
71
|
+
type: z.literal('block'),
|
|
72
|
+
meta: BlockMetadataSchema.optional().describe('Block metadata'),
|
|
73
|
+
variables: z.array(BlockVariableSchema).optional().describe('Block variables/props'),
|
|
74
|
+
slots: z.array(BlockSlotSchema).optional().describe('Block slots for content injection'),
|
|
75
|
+
template: z.union([SchemaNodeSchema, z.array(SchemaNodeSchema)]).optional().describe('Block template (component tree)'),
|
|
76
|
+
values: z.record(z.string(), z.any()).optional().describe('Variable values (when using a block)'),
|
|
77
|
+
slotContent: z.record(z.string(), z.union([SchemaNodeSchema, z.array(SchemaNodeSchema)])).optional().describe('Slot content (when using a block)'),
|
|
78
|
+
blockRef: z.string().optional().describe('Block reference (for reusing saved blocks)'),
|
|
79
|
+
editable: z.boolean().optional().describe('Enable edit mode'),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Block Library Item Schema
|
|
84
|
+
*/
|
|
85
|
+
export const BlockLibraryItemSchema = z.object({
|
|
86
|
+
id: z.string().describe('Unique identifier'),
|
|
87
|
+
meta: BlockMetadataSchema.describe('Block metadata'),
|
|
88
|
+
schema: BlockSchema.describe('Block schema'),
|
|
89
|
+
installs: z.number().optional().describe('Installation count'),
|
|
90
|
+
rating: z.number().optional().describe('Rating (1-5)'),
|
|
91
|
+
ratingCount: z.number().optional().describe('Number of ratings'),
|
|
92
|
+
updatedAt: z.string().optional().describe('Last updated timestamp'),
|
|
93
|
+
createdAt: z.string().optional().describe('Created timestamp'),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Block Library Schema
|
|
98
|
+
*/
|
|
99
|
+
export const BlockLibrarySchema = BaseSchema.extend({
|
|
100
|
+
type: z.literal('block-library'),
|
|
101
|
+
apiEndpoint: z.string().optional().describe('Library API endpoint'),
|
|
102
|
+
category: z.string().optional().describe('Filter by category'),
|
|
103
|
+
searchQuery: z.string().optional().describe('Search query'),
|
|
104
|
+
tags: z.array(z.string()).optional().describe('Filter by tags'),
|
|
105
|
+
showPremium: z.boolean().optional().describe('Show premium blocks'),
|
|
106
|
+
blocks: z.array(BlockLibraryItemSchema).optional().describe('Blocks to display'),
|
|
107
|
+
loading: z.boolean().optional().describe('Loading state'),
|
|
108
|
+
onInstall: z.string().optional().describe('Install callback'),
|
|
109
|
+
onPreview: z.string().optional().describe('Preview callback'),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Block Editor Schema
|
|
114
|
+
*/
|
|
115
|
+
export const BlockEditorSchema = BaseSchema.extend({
|
|
116
|
+
type: z.literal('block-editor'),
|
|
117
|
+
block: BlockSchema.optional().describe('Block being edited'),
|
|
118
|
+
showVariables: z.boolean().optional().describe('Show variable editor'),
|
|
119
|
+
showSlots: z.boolean().optional().describe('Show slot editor'),
|
|
120
|
+
showTemplate: z.boolean().optional().describe('Show template editor'),
|
|
121
|
+
showPreview: z.boolean().optional().describe('Show preview'),
|
|
122
|
+
onSave: z.string().optional().describe('Save callback'),
|
|
123
|
+
onCancel: z.string().optional().describe('Cancel callback'),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Block Instance Schema
|
|
128
|
+
*/
|
|
129
|
+
export const BlockInstanceSchema = BaseSchema.extend({
|
|
130
|
+
type: z.literal('block-instance'),
|
|
131
|
+
blockId: z.string().describe('Block reference ID'),
|
|
132
|
+
blockName: z.string().optional().describe('Block name (for local blocks)'),
|
|
133
|
+
values: z.record(z.string(), z.any()).optional().describe('Variable values'),
|
|
134
|
+
slotContent: z.record(z.string(), z.union([SchemaNodeSchema, z.array(SchemaNodeSchema)])).optional().describe('Slot content'),
|
|
135
|
+
overrideStyles: z.boolean().optional().describe('Override styles'),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Component Schema
|
|
140
|
+
*/
|
|
141
|
+
export const ComponentSchema = BaseSchema.extend({
|
|
142
|
+
type: z.literal('component'),
|
|
143
|
+
componentName: z.string().optional().describe('Component name/identifier'),
|
|
144
|
+
props: z.record(z.string(), z.any()).optional().describe('Component props'),
|
|
145
|
+
children: z.union([SchemaNodeSchema, z.array(SchemaNodeSchema)]).optional().describe('Component children'),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Union of all block schemas
|
|
150
|
+
*/
|
|
151
|
+
export const BlockComponentSchema = z.union([
|
|
152
|
+
BlockSchema,
|
|
153
|
+
BlockLibrarySchema,
|
|
154
|
+
BlockEditorSchema,
|
|
155
|
+
BlockInstanceSchema,
|
|
156
|
+
ComponentSchema,
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Export type inference helpers
|
|
161
|
+
*/
|
|
162
|
+
export type BlockVariableSchemaType = z.infer<typeof BlockVariableSchema>;
|
|
163
|
+
export type BlockSlotSchemaType = z.infer<typeof BlockSlotSchema>;
|
|
164
|
+
export type BlockMetadataSchemaType = z.infer<typeof BlockMetadataSchema>;
|
|
165
|
+
export type BlockSchemaType = z.infer<typeof BlockSchema>;
|
|
166
|
+
export type BlockLibraryItemSchemaType = z.infer<typeof BlockLibraryItemSchema>;
|
|
167
|
+
export type BlockLibrarySchemaType = z.infer<typeof BlockLibrarySchema>;
|
|
168
|
+
export type BlockEditorSchemaType = z.infer<typeof BlockEditorSchema>;
|
|
169
|
+
export type BlockInstanceSchemaType = z.infer<typeof BlockInstanceSchema>;
|
|
170
|
+
export type ComponentSchemaType = z.infer<typeof ComponentSchema>;
|