-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.zod.ts
More file actions
329 lines (292 loc) · 13.9 KB
/
page.zod.ts
File metadata and controls
329 lines (292 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { SnakeCaseIdentifierSchema } from '../shared/identifiers.zod';
import { SortItemSchema } from '../shared/enums.zod';
import { FilterConditionSchema } from '../data/filter.zod';
import { I18nLabelSchema, AriaPropsSchema } from './i18n.zod';
import { ResponsiveConfigSchema } from './responsive.zod';
import {
UserActionsConfigSchema,
AppearanceConfigSchema,
ViewTabSchema,
ViewFilterRuleSchema,
AddRecordConfigSchema,
} from './view.zod';
/**
* Page Region Schema
* A named region in the template where components are dropped.
*/
export const PageRegionSchema = z.object({
name: z.string().describe('Region name (e.g. "sidebar", "main", "header")'),
width: z.enum(['small', 'medium', 'large', 'full']).optional(),
components: z.array(z.lazy(() => PageComponentSchema)).describe('Components in this region')
});
/**
* Standard Page Component Types
*/
export const PageComponentType = z.enum([
// Structure
'page:header', 'page:footer', 'page:sidebar', 'page:tabs', 'page:accordion', 'page:card', 'page:section',
// Record Context
'record:details', 'record:highlights', 'record:related_list', 'record:activity', 'record:chatter', 'record:path',
// Navigation
'app:launcher', 'nav:menu', 'nav:breadcrumb',
// Utility
'global:search', 'global:notifications', 'user:profile',
// AI
'ai:chat_window', 'ai:suggestion',
// Content Elements (Airtable Interface parity)
'element:text', 'element:number', 'element:image', 'element:divider',
// Interactive Elements (Phase B — Element Library)
'element:button', 'element:filter', 'element:form', 'element:record_picker'
]);
/**
* Element Data Source Schema
* Per-element data binding for multi-object pages.
* Overrides page-level object context so each element can query a different object.
*/
export const ElementDataSourceSchema = z.object({
object: z.string().describe('Object to query'),
view: z.string().optional().describe('Named view to apply'),
filter: FilterConditionSchema.optional().describe('Additional filter criteria'),
sort: z.array(SortItemSchema).optional().describe('Sort order'),
limit: z.number().int().positive().optional().describe('Max records to display'),
});
/**
* Page Component Schema
* A configured instance of a UI component.
*/
export const PageComponentSchema = z.object({
/** Definition */
type: z.union([
PageComponentType,
z.string()
]).describe('Component Type (Standard enum or custom string)'),
id: z.string().optional().describe('Unique instance ID'),
/** Configuration */
label: I18nLabelSchema.optional(),
properties: z.record(z.string(), z.unknown()).describe('Component props passed to the widget. See component.zod.ts for schemas.'),
/**
* Event Handlers
* Map event names to Action expressions.
* "onClick": "set_variable('userId', $event.id)"
* "onRowSelect": "navigate_to('page_detail', { id: $event.id })"
*/
events: z.record(z.string(), z.string()).optional().describe('Event handlers map'),
/** Appearance */
style: z.record(z.string(), z.string()).optional().describe('Inline styles or utility classes'),
className: z.string().optional().describe('CSS class names'),
/** Visibility Rule */
visibility: z.string().optional().describe('Visibility filter/formula'),
/** Per-element data binding, overrides page-level object context */
dataSource: ElementDataSourceSchema.optional().describe('Per-element data binding for multi-object pages'),
/** Responsive layout overrides per breakpoint */
responsive: ResponsiveConfigSchema.optional().describe('Responsive layout configuration'),
/** ARIA accessibility attributes */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
/**
* Page Variable Schema
* Defines local state for the page.
* Variables can be bound to interactive elements (e.g. element:record_picker, element:filter).
*/
export const PageVariableSchema = z.object({
name: z.string().describe('Variable name'),
type: z.enum(['string', 'number', 'boolean', 'object', 'array', 'record_id']).default('string'),
defaultValue: z.unknown().optional(),
/** Source element binding (e.g. element:record_picker writes to this variable) */
source: z.string().optional().describe('Component ID that writes to this variable'),
});
/**
* Blank Page Layout Item Schema
* Positions a component on a free-form grid canvas.
*/
export const BlankPageLayoutItemSchema = z.object({
componentId: z.string().describe('Reference to a PageComponent.id in the page'),
x: z.number().int().min(0).describe('Grid column position (0-based)'),
y: z.number().int().min(0).describe('Grid row position (0-based)'),
width: z.number().int().min(1).describe('Width in grid columns'),
height: z.number().int().min(1).describe('Height in grid rows'),
});
/**
* Blank Page Layout Schema
* Free-form canvas composition with grid-based positioning.
* Used when page type is 'blank' to enable drag-and-drop element placement.
*/
export const BlankPageLayoutSchema = z.object({
columns: z.number().int().min(1).default(12).describe('Number of grid columns'),
rowHeight: z.number().int().min(1).default(40).describe('Height of each grid row in pixels'),
gap: z.number().int().min(0).default(8).describe('Gap between grid items in pixels'),
items: z.array(BlankPageLayoutItemSchema).describe('Positioned components on the canvas'),
});
/**
* Page Type Schema
* Unified page type enum covering both platform pages (Salesforce FlexiPage style)
* and Airtable-inspired interface page types.
*
* **Disambiguation of similar types:**
* - `record` vs `record_detail`: `record` is a component-based layout page (FlexiPage style with regions),
* `record_detail` is a field-display page showing all fields of a single record (Airtable style).
* Use `record` for custom record pages with regions/components, `record_detail` for auto-generated detail views.
* - `home` vs `overview`: `home` is the platform-level landing page (tab landing),
* `overview` is an interface-level navigation hub with links/instructions.
* Use `home` for app-level landing, `overview` for in-interface navigation hubs.
* - `app` vs `utility` vs `blank`: `app` is an app-level page with navigation context,
* `utility` is a floating utility panel (e.g. notes, phone), `blank` is a free-form canvas
* for custom composition. They serve distinct layout purposes.
*/
export const PageTypeSchema = z.enum([
// Platform page types (Salesforce FlexiPage style)
'record', // Component-based record layout page with regions
'home', // Platform-level home/landing page
'app', // App-level page with navigation context
'utility', // Floating utility panel (e.g. notes, phone dialer)
// Interface page types (Airtable Interface parity)
'dashboard', // KPI summary with charts/metrics
'grid', // Spreadsheet-like data table
'list', // Record list with quick actions
'gallery', // Card-based visual browsing
'kanban', // Status-based board
'calendar', // Date-based scheduling
'timeline', // Gantt-like project timeline
'form', // Data entry form
'record_detail', // Auto-generated single record field display
'record_review', // Sequential record review/approval
'overview', // Interface-level navigation/landing hub
'blank', // Free-form canvas for custom composition
]).describe('Page type — platform or interface page types');
/**
* Record Review Config Schema
* Configuration for a sequential record review/approval page.
* Users navigate through records one-by-one, taking actions (approve/reject/skip).
* Only applicable when page type is 'record_review'.
*/
export const RecordReviewConfigSchema = z.object({
object: z.string().describe('Target object for review'),
filter: FilterConditionSchema.optional().describe('Filter criteria for review queue'),
sort: z.array(SortItemSchema).optional().describe('Sort order for review queue'),
displayFields: z.array(z.string()).optional()
.describe('Fields to display on the review page'),
actions: z.array(z.object({
label: z.string().describe('Action button label'),
type: z.enum(['approve', 'reject', 'skip', 'custom'])
.describe('Action type'),
field: z.string().optional()
.describe('Field to update on action'),
value: z.union([z.string(), z.number(), z.boolean()]).optional()
.describe('Value to set on action'),
nextRecord: z.boolean().optional().default(true)
.describe('Auto-advance to next record after action'),
})).describe('Review actions'),
navigation: z.enum(['sequential', 'random', 'filtered'])
.optional().default('sequential')
.describe('Record navigation mode'),
showProgress: z.boolean().optional().default(true)
.describe('Show review progress indicator'),
});
/**
* Interface Page Configuration Schema (Airtable Interface parity)
* Page-level declarative configuration for Airtable-style interface pages.
* Covers title/data binding, levels, filter by, appearance, user actions,
* tabs, record count, add record, and advanced options (printing).
*
* @see Airtable Interface → right panel (Page / Data / Appearance / User filters / User actions / Advanced)
*/
export const InterfacePageConfigSchema = z.object({
/** Data binding */
source: z.string().optional().describe('Source object name for the page'),
levels: z.number().int().min(1).optional().describe('Number of hierarchy levels to display'),
filterBy: z.array(ViewFilterRuleSchema).optional().describe('Page-level filter criteria'),
/** Appearance */
appearance: AppearanceConfigSchema.optional().describe('Appearance and visualization configuration'),
/** User filters */
userFilters: z.object({
elements: z.array(z.enum(['grid', 'gallery', 'kanban'])).optional()
.describe('Visualization element types available in user filter bar'),
tabs: z.array(ViewTabSchema).optional().describe('User-configurable tabs'),
}).optional().describe('User filter configuration'),
/** User actions */
userActions: UserActionsConfigSchema.optional().describe('User action toggles'),
/** Add record */
addRecord: AddRecordConfigSchema.optional().describe('Add record entry point configuration'),
/** Record count */
showRecordCount: z.boolean().optional().describe('Show record count at page bottom'),
/** Advanced */
allowPrinting: z.boolean().optional().describe('Allow users to print the page'),
}).describe('Interface-level page configuration (Airtable parity)');
/**
* Page Schema
* Defines a composition of components for a specific context.
* Supports both platform pages (Salesforce FlexiPage style: record, home, app, utility)
* and interface pages (Airtable Interface style: dashboard, grid, kanban, record_review, etc.).
*
* **NAMING CONVENTION:**
* Page names are used in routing and must be lowercase snake_case.
* Prefix with 'page_' is recommended for clarity.
*
* @example Good page names
* - 'page_dashboard'
* - 'page_settings'
* - 'home_page'
* - 'record_detail'
*
* @example Bad page names (will be rejected)
* - 'PageDashboard' (PascalCase)
* - 'Settings Page' (spaces)
*/
export const PageSchema = z.object({
name: SnakeCaseIdentifierSchema.describe('Page unique name (lowercase snake_case)'),
label: I18nLabelSchema,
description: I18nLabelSchema.optional(),
/** Icon (used in interface navigation) */
icon: z.string().optional().describe('Page icon name'),
/** Page Type */
type: PageTypeSchema.default('record').describe('Page type'),
/** Page State Definitions */
variables: z.array(PageVariableSchema).optional().describe('Local page state variables'),
/** Context */
object: z.string().optional().describe('Bound object (for Record pages)'),
/** Record Review Configuration (only for record_review pages) */
recordReview: RecordReviewConfigSchema.optional()
.describe('Record review configuration (required when type is "record_review")'),
/** Blank Page Layout (only for blank pages) */
blankLayout: BlankPageLayoutSchema.optional()
.describe('Free-form grid layout for blank pages (used when type is "blank")'),
/** Layout Template */
template: z.string().default('default').describe('Layout template name (e.g. "header-sidebar-main")'),
/** Regions & Content */
regions: z.array(PageRegionSchema).describe('Defined regions with components'),
/** Activation */
isDefault: z.boolean().default(false),
assignedProfiles: z.array(z.string()).optional(),
/** Interface Page Configuration (Airtable Interface parity) */
interfaceConfig: InterfacePageConfigSchema.optional()
.describe('Interface-level page configuration (for Airtable-style interface pages)'),
/** ARIA accessibility attributes */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
}).superRefine((data, ctx) => {
if (data.type === 'record_review' && !data.recordReview) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['recordReview'],
message: 'recordReview is required when type is "record_review"',
});
}
if (data.type === 'blank' && !data.blankLayout) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['blankLayout'],
message: 'blankLayout is required when type is "blank"',
});
}
});
export type Page = z.infer<typeof PageSchema>;
export type PageType = z.infer<typeof PageTypeSchema>;
export type PageComponent = z.infer<typeof PageComponentSchema>;
export type PageRegion = z.infer<typeof PageRegionSchema>;
export type PageVariable = z.infer<typeof PageVariableSchema>;
export type ElementDataSource = z.infer<typeof ElementDataSourceSchema>;
export type RecordReviewConfig = z.infer<typeof RecordReviewConfigSchema>;
export type BlankPageLayoutItem = z.infer<typeof BlankPageLayoutItemSchema>;
export type BlankPageLayout = z.infer<typeof BlankPageLayoutSchema>;
export type InterfacePageConfig = z.infer<typeof InterfacePageConfigSchema>;