-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponent.zod.ts
More file actions
219 lines (194 loc) · 9.11 KB
/
component.zod.ts
File metadata and controls
219 lines (194 loc) · 9.11 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
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { I18nLabelSchema, AriaPropsSchema } from './i18n.zod';
/**
* Empty Properties Schema
*/
const EmptyProps = z.object({});
/**
* ----------------------------------------------------------------------
* 1. Structure Components
* ----------------------------------------------------------------------
*/
export const PageHeaderProps = z.object({
title: I18nLabelSchema.describe('Page title'),
subtitle: I18nLabelSchema.optional().describe('Page subtitle'),
icon: z.string().optional().describe('Icon name'),
breadcrumb: z.boolean().default(true).describe('Show breadcrumb'),
actions: z.array(z.string()).optional().describe('Action IDs to show in header'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const PageTabsProps = z.object({
type: z.enum(['line', 'card', 'pill']).default('line'),
position: z.enum(['top', 'left']).default('top'),
items: z.array(z.object({
label: I18nLabelSchema,
icon: z.string().optional(),
children: z.array(z.unknown()).describe('Child components')
})),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const PageCardProps = z.object({
title: I18nLabelSchema.optional(),
bordered: z.boolean().default(true),
actions: z.array(z.string()).optional(),
/** Slot for nested content in the Card body */
body: z.array(z.unknown()).optional().describe('Card content components (slot)'),
/** Slot for footer content */
footer: z.array(z.unknown()).optional().describe('Card footer components (slot)'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
/**
* ----------------------------------------------------------------------
* 2. Record Context Components
* ----------------------------------------------------------------------
*/
export const RecordDetailsProps = z.object({
columns: z.enum(['1', '2', '3', '4']).default('2').describe('Number of columns for field layout (1-4)'),
layout: z.enum(['auto', 'custom']).default('auto').describe('Layout mode: auto uses object compactLayout, custom uses explicit sections'),
sections: z.array(z.string()).optional().describe('Section IDs to show (required when layout is "custom")'),
fields: z.array(z.string()).optional().describe('Explicit field list to display (optional, overrides compactLayout)'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const RecordRelatedListProps = z.object({
objectName: z.string().describe('Related object name (e.g., "task", "opportunity")'),
relationshipField: z.string().describe('Field on related object that points to this record (e.g., "account_id")'),
columns: z.array(z.string()).describe('Fields to display in the related list'),
sort: z.union([
z.string(),
z.array(z.object({
field: z.string(),
order: z.enum(['asc', 'desc'])
}))
]).optional().describe('Sort order for related records'),
limit: z.number().int().positive().default(5).describe('Number of records to display initially'),
filter: z.array(z.unknown()).optional().describe('Additional filter criteria for related records'),
title: I18nLabelSchema.optional().describe('Custom title for the related list'),
showViewAll: z.boolean().default(true).describe('Show "View All" link to see all related records'),
actions: z.array(z.string()).optional().describe('Action IDs available for related records'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const RecordHighlightsProps = z.object({
fields: z.array(z.string()).min(1).max(7).describe('Key fields to highlight (1-7 fields max, typically displayed as prominent cards)'),
layout: z.enum(['horizontal', 'vertical']).default('horizontal').describe('Layout orientation for highlight fields'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const RecordActivityProps = z.object({
types: z.array(z.enum(['task', 'event', 'email', 'call', 'note'])).optional().describe('Activity types to display'),
limit: z.number().int().positive().default(10).describe('Number of activities to show'),
showCompleted: z.boolean().default(false).describe('Include completed activities'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const RecordPathProps = z.object({
statusField: z.string().describe('Field name representing the current status/stage'),
stages: z.array(z.object({
value: z.string(),
label: I18nLabelSchema,
})).optional().describe('Explicit stage definitions (if not using field metadata)'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const PageAccordionProps = z.object({
items: z.array(z.object({
label: I18nLabelSchema,
icon: z.string().optional(),
collapsed: z.boolean().default(false),
children: z.array(z.unknown()).describe('Child components'),
})),
allowMultiple: z.boolean().default(false).describe('Allow multiple panels to be expanded simultaneously'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const AIChatWindowProps = z.object({
mode: z.enum(['float', 'sidebar', 'inline']).default('float').describe('Display mode for the chat window'),
agentId: z.string().optional().describe('Specific AI agent to use'),
context: z.record(z.string(), z.unknown()).optional().describe('Contextual data to pass to the AI'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
/**
* ----------------------------------------------------------------------
* 3. Content Element Components (Airtable Interface Parity)
* ----------------------------------------------------------------------
*/
export const ElementTextPropsSchema = z.object({
content: z.string().describe('Text or Markdown content'),
variant: z.enum(['heading', 'subheading', 'body', 'caption'])
.optional().default('body').describe('Text style variant'),
align: z.enum(['left', 'center', 'right'])
.optional().default('left').describe('Text alignment'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const ElementNumberPropsSchema = z.object({
object: z.string().describe('Source object'),
field: z.string().optional().describe('Field to aggregate'),
aggregate: z.enum(['count', 'sum', 'avg', 'min', 'max'])
.describe('Aggregation function'),
filter: z.any().optional().describe('Filter criteria'),
format: z.enum(['number', 'currency', 'percent']).optional().describe('Number display format'),
prefix: z.string().optional().describe('Prefix text (e.g. "$")'),
suffix: z.string().optional().describe('Suffix text (e.g. "%")'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
export const ElementImagePropsSchema = z.object({
src: z.string().describe('Image URL or attachment field'),
alt: z.string().optional().describe('Alt text for accessibility'),
fit: z.enum(['cover', 'contain', 'fill'])
.optional().default('cover').describe('Image object-fit mode'),
height: z.number().optional().describe('Fixed height in pixels'),
/** ARIA accessibility */
aria: AriaPropsSchema.optional().describe('ARIA accessibility attributes'),
});
/**
* ----------------------------------------------------------------------
* Component Props Map
* Maps Component Type to its Property Schema
* ----------------------------------------------------------------------
*/
export const ComponentPropsMap = {
// Structure
'page:header': PageHeaderProps,
'page:tabs': PageTabsProps,
'page:card': PageCardProps,
'page:footer': EmptyProps,
'page:sidebar': EmptyProps,
'page:accordion': PageAccordionProps,
'page:section': EmptyProps,
// Record
'record:details': RecordDetailsProps,
'record:related_list': RecordRelatedListProps,
'record:highlights': RecordHighlightsProps,
'record:activity': RecordActivityProps,
'record:chatter': EmptyProps,
'record:path': RecordPathProps,
// Navigation
'app:launcher': EmptyProps,
'nav:menu': EmptyProps,
'nav:breadcrumb': EmptyProps,
// Utility
'global:search': EmptyProps,
'global:notifications': EmptyProps,
'user:profile': EmptyProps,
// AI
'ai:chat_window': AIChatWindowProps,
'ai:suggestion': z.object({ context: z.string().optional() }),
// Content Elements
'element:text': ElementTextPropsSchema,
'element:number': ElementNumberPropsSchema,
'element:image': ElementImagePropsSchema,
'element:divider': EmptyProps,
} as const;
/**
* Type Helper to extract props from map
*/
export type ComponentProps<T extends keyof typeof ComponentPropsMap> = z.infer<typeof ComponentPropsMap[T]>;
export type ComponentPropsInput<T extends keyof typeof ComponentPropsMap> = z.input<typeof ComponentPropsMap[T]>;