@simpleplatform/ui-kit 0.2.1 → 0.4.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/README.md +291 -44
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/views.d.ts +164 -0
- package/dist/contracts/views.d.ts.map +1 -0
- package/dist/contracts/views.js +670 -0
- package/dist/elements/status-badge.d.ts.map +1 -1
- package/dist/elements/status-badge.js +11 -15
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/record-bridge.d.ts +9 -0
- package/dist/react/record-bridge.d.ts.map +1 -1
- package/dist/react/record-bridge.js +8 -0
- package/dist/react/record-form.d.ts.map +1 -1
- package/dist/react/record-form.js +3 -0
- package/dist/react/record-view.d.ts +6 -0
- package/dist/react/record-view.d.ts.map +1 -0
- package/dist/react/record-view.js +186 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +7 -1
- package/package.json +2 -2
- package/theme.css +11 -27
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
export const RECORD_VIEW_ICON_IDS_V1 = [
|
|
2
|
+
'lucide:circle-alert',
|
|
3
|
+
'lucide:arrow-up-right',
|
|
4
|
+
'lucide:columns-3',
|
|
5
|
+
'lucide:box',
|
|
6
|
+
'lucide:calendar-days',
|
|
7
|
+
'lucide:check',
|
|
8
|
+
'lucide:clock-3',
|
|
9
|
+
'lucide:file',
|
|
10
|
+
'lucide:circle-question-mark',
|
|
11
|
+
'lucide:inbox',
|
|
12
|
+
'lucide:layout-grid',
|
|
13
|
+
'lucide:list',
|
|
14
|
+
'lucide:mail',
|
|
15
|
+
'lucide:settings',
|
|
16
|
+
'lucide:star',
|
|
17
|
+
'lucide:table',
|
|
18
|
+
'lucide:tag',
|
|
19
|
+
'lucide:user-round',
|
|
20
|
+
'lucide:video',
|
|
21
|
+
];
|
|
22
|
+
export const RECORD_TILE_PRESENTATIONS_V1 = [
|
|
23
|
+
'standard',
|
|
24
|
+
'media',
|
|
25
|
+
'message',
|
|
26
|
+
];
|
|
27
|
+
export const RECORD_VIEW_KINDS_V1 = ['board', 'inbox', 'list', 'table'];
|
|
28
|
+
export class RecordViewContractError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'RecordViewContractError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function isPlainObject(value) {
|
|
35
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
36
|
+
return false;
|
|
37
|
+
const proto = Object.getPrototypeOf(value);
|
|
38
|
+
return proto === Object.prototype || proto === null;
|
|
39
|
+
}
|
|
40
|
+
function isNonEmptyString(value) {
|
|
41
|
+
return typeof value === 'string' && value.trim().length > 0 && value.trim() === value;
|
|
42
|
+
}
|
|
43
|
+
function assertOnlyKeys(value, allowed, label) {
|
|
44
|
+
const allowedKeys = new Set(allowed);
|
|
45
|
+
const unexpected = Object.keys(value).find(key => !allowedKeys.has(key));
|
|
46
|
+
if (unexpected)
|
|
47
|
+
throw new RecordViewContractError(`${label} contains an unsupported property: ${unexpected}.`);
|
|
48
|
+
}
|
|
49
|
+
export function validateTableRecordSourceV1(value) {
|
|
50
|
+
if (!isPlainObject(value))
|
|
51
|
+
throw new RecordViewContractError('Record source must be an object.');
|
|
52
|
+
if (value.kind !== 'table')
|
|
53
|
+
throw new RecordViewContractError('Record source kind must be \'table\'.');
|
|
54
|
+
assertOnlyKeys(value, ['kind', 'appId', 'tableId'], 'Table source');
|
|
55
|
+
if (!isNonEmptyString(value.appId))
|
|
56
|
+
throw new RecordViewContractError('Table source appId must be a non-empty string without whitespace padding.');
|
|
57
|
+
if (!isNonEmptyString(value.tableId))
|
|
58
|
+
throw new RecordViewContractError('Table source tableId must be a non-empty string without whitespace padding.');
|
|
59
|
+
return { appId: value.appId, kind: 'table', tableId: value.tableId };
|
|
60
|
+
}
|
|
61
|
+
export function validateRecordSourceV1(value) {
|
|
62
|
+
return validateTableRecordSourceV1(value);
|
|
63
|
+
}
|
|
64
|
+
export function isRecordSourceV1(value) {
|
|
65
|
+
try {
|
|
66
|
+
validateRecordSourceV1(value);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function validateRecordReferenceV1(value) {
|
|
74
|
+
if (!isPlainObject(value)) {
|
|
75
|
+
throw new RecordViewContractError('Record reference must be an object.');
|
|
76
|
+
}
|
|
77
|
+
if (!isNonEmptyString(value.appId)) {
|
|
78
|
+
throw new RecordViewContractError('Record reference appId must be a non-empty string.');
|
|
79
|
+
}
|
|
80
|
+
if (!isNonEmptyString(value.tableName)) {
|
|
81
|
+
throw new RecordViewContractError('Record reference tableName must be a non-empty string.');
|
|
82
|
+
}
|
|
83
|
+
if (!isNonEmptyString(value.recordId)) {
|
|
84
|
+
throw new RecordViewContractError('Record reference recordId must be a non-empty string.');
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
appId: value.appId,
|
|
88
|
+
recordId: value.recordId,
|
|
89
|
+
tableName: value.tableName,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function isRecordReferenceV1(value) {
|
|
93
|
+
try {
|
|
94
|
+
validateRecordReferenceV1(value);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function validateViewItemReferenceV1(value) {
|
|
102
|
+
if (!isPlainObject(value)) {
|
|
103
|
+
throw new RecordViewContractError('View item reference must be an object.');
|
|
104
|
+
}
|
|
105
|
+
if (value.kind !== 'record')
|
|
106
|
+
throw new RecordViewContractError(`View item reference kind must be 'record', got '${String(value.kind)}'.`);
|
|
107
|
+
assertOnlyKeys(value, ['appId', 'kind', 'recordId', 'tableName'], 'Record view item reference');
|
|
108
|
+
return { ...validateRecordReferenceV1(value), kind: 'record' };
|
|
109
|
+
}
|
|
110
|
+
export function isViewItemReferenceV1(value) {
|
|
111
|
+
try {
|
|
112
|
+
validateViewItemReferenceV1(value);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const MAX_PRESETS = 20;
|
|
120
|
+
const MAX_VIEW_FIELDS = 40;
|
|
121
|
+
const MAX_SORT_FIELDS = 5;
|
|
122
|
+
const MAX_LANES = 20;
|
|
123
|
+
const MAX_LANE_PAGE_SIZE = 50;
|
|
124
|
+
const MAX_RECORD_WHERE_DEPTH = 8;
|
|
125
|
+
const MAX_RECORD_WHERE_NODES = 100;
|
|
126
|
+
const MAX_RECORD_WHERE_ENTRIES = 50;
|
|
127
|
+
const SAFE_TILE_ICON_IDS = new Set(RECORD_VIEW_ICON_IDS_V1);
|
|
128
|
+
const isSafeTileIconId = (value) => typeof value === 'string' && SAFE_TILE_ICON_IDS.has(value);
|
|
129
|
+
function assertRecordWhereShape(value, depth = 1, state = { count: 0 }) {
|
|
130
|
+
if (depth > MAX_RECORD_WHERE_DEPTH || ++state.count > MAX_RECORD_WHERE_NODES)
|
|
131
|
+
throw new RecordViewContractError('RecordWhere is nested too deeply or has too many conditions.');
|
|
132
|
+
if (!isPlainObject(value))
|
|
133
|
+
throw new RecordViewContractError('RecordWhere must be an object.');
|
|
134
|
+
const entries = Object.entries(value);
|
|
135
|
+
if (depth > 1 && entries.length === 0)
|
|
136
|
+
throw new RecordViewContractError('RecordWhere clauses cannot be empty.');
|
|
137
|
+
if (entries.length > MAX_RECORD_WHERE_ENTRIES)
|
|
138
|
+
throw new RecordViewContractError(`RecordWhere can contain at most ${MAX_RECORD_WHERE_ENTRIES} clauses.`);
|
|
139
|
+
for (const [key, condition] of entries) {
|
|
140
|
+
if (key.includes('.'))
|
|
141
|
+
throw new RecordViewContractError('Dotted relationship paths must use nested RecordWhere objects.');
|
|
142
|
+
if (key === '_and' || key === '_or') {
|
|
143
|
+
if (!Array.isArray(condition) || condition.length === 0 || condition.length > MAX_RECORD_WHERE_ENTRIES)
|
|
144
|
+
throw new RecordViewContractError(`${key} must contain 1 to ${MAX_RECORD_WHERE_ENTRIES} clauses.`);
|
|
145
|
+
for (const clause of condition)
|
|
146
|
+
assertRecordWhereShape(clause, depth + 1, state);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (key === '_not') {
|
|
150
|
+
assertRecordWhereShape(condition, depth + 1, state);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!isPlainObject(condition))
|
|
154
|
+
throw new RecordViewContractError('RecordWhere field conditions must use native operator objects.');
|
|
155
|
+
if (Object.keys(condition).length === 0)
|
|
156
|
+
throw new RecordViewContractError('RecordWhere field conditions cannot be empty.');
|
|
157
|
+
for (const [operator, operand] of Object.entries(condition)) {
|
|
158
|
+
if (operator.startsWith('_') && !['_and', '_or', '_not'].includes(operator))
|
|
159
|
+
continue;
|
|
160
|
+
assertRecordWhereShape({ [operator]: operand }, depth + 1, state);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export function validateRecordSortV1(value) {
|
|
165
|
+
if (!isPlainObject(value)) {
|
|
166
|
+
throw new RecordViewContractError('Record sort must be an object.');
|
|
167
|
+
}
|
|
168
|
+
if (!isNonEmptyString(value.fieldName)) {
|
|
169
|
+
throw new RecordViewContractError('Record sort fieldName must be a non-empty string.');
|
|
170
|
+
}
|
|
171
|
+
assertOnlyKeys(value, ['direction', 'fieldName'], 'Record sort');
|
|
172
|
+
if (value.fieldName.length > 200)
|
|
173
|
+
throw new RecordViewContractError('Record sort fieldName must be at most 200 characters.');
|
|
174
|
+
if (value.direction !== 'asc' && value.direction !== 'desc') {
|
|
175
|
+
throw new RecordViewContractError(`Record sort direction must be 'asc' or 'desc', got ${String(value.direction)}.`);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
direction: value.direction,
|
|
179
|
+
fieldName: value.fieldName,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function isRecordSortV1(value) {
|
|
183
|
+
try {
|
|
184
|
+
validateRecordSortV1(value);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export function validateRecordTileLayoutV1(value) {
|
|
192
|
+
if (!isPlainObject(value)) {
|
|
193
|
+
throw new RecordViewContractError('Record tile layout must be an object.');
|
|
194
|
+
}
|
|
195
|
+
if (value.version !== 1) {
|
|
196
|
+
throw new RecordViewContractError(`Record tile layout version must be 1, got ${String(value.version)}.`);
|
|
197
|
+
}
|
|
198
|
+
if (!RECORD_TILE_PRESENTATIONS_V1.includes(value.presentation)) {
|
|
199
|
+
throw new RecordViewContractError(`Invalid tile presentation: ${String(value.presentation)}.`);
|
|
200
|
+
}
|
|
201
|
+
if (!isNonEmptyString(value.titleFieldName)) {
|
|
202
|
+
throw new RecordViewContractError('Record tile layout titleFieldName must be a non-empty string.');
|
|
203
|
+
}
|
|
204
|
+
if (value.badgeStyle !== undefined && (value.presentation !== 'standard' || !['filled', 'outline'].includes(String(value.badgeStyle))))
|
|
205
|
+
throw new RecordViewContractError('Tile badgeStyle must be filled or outline on standard tiles.');
|
|
206
|
+
if (value.presentation === 'message') {
|
|
207
|
+
if (!isNonEmptyString(value.eyebrowFieldName)
|
|
208
|
+
|| !Array.isArray(value.subtitleFieldNames)
|
|
209
|
+
|| value.subtitleFieldNames.length === 0
|
|
210
|
+
|| value.subtitleFieldNames.length > MAX_VIEW_FIELDS
|
|
211
|
+
|| !value.subtitleFieldNames.every(name => isNonEmptyString(name) && name.length <= 200)
|
|
212
|
+
|| !isNonEmptyString(value.trailingFieldName)) {
|
|
213
|
+
throw new RecordViewContractError('Message tiles require sender, preview, and received-at fields.');
|
|
214
|
+
}
|
|
215
|
+
if (value.badgeFieldNames !== undefined || value.detailFieldNames !== undefined || value.visual !== undefined) {
|
|
216
|
+
throw new RecordViewContractError('Email tiles do not support badges, details, or visuals.');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
assertOnlyKeys(value, ['badgeFieldNames', 'badgeStyle', 'detailFieldNames', 'eyebrowFieldName', 'presentation', 'subtitleFieldNames', 'titleFieldName', 'trailingFieldName', 'version', 'visual'], 'Record tile layout');
|
|
220
|
+
for (const name of ['titleFieldName', 'eyebrowFieldName', 'trailingFieldName']) {
|
|
221
|
+
const fieldName = value[name];
|
|
222
|
+
if (fieldName !== undefined && (typeof fieldName !== 'string' || fieldName.length > 200))
|
|
223
|
+
throw new RecordViewContractError(`Record tile layout ${name} must be at most 200 characters.`);
|
|
224
|
+
}
|
|
225
|
+
let visual;
|
|
226
|
+
if (value.visual !== undefined) {
|
|
227
|
+
if (!isPlainObject(value.visual)) {
|
|
228
|
+
throw new RecordViewContractError('Tile visual must be an object.');
|
|
229
|
+
}
|
|
230
|
+
if (value.visual.kind === 'image') {
|
|
231
|
+
if (!isNonEmptyString(value.visual.fieldName)) {
|
|
232
|
+
throw new RecordViewContractError('Tile image visual requires fieldName.');
|
|
233
|
+
}
|
|
234
|
+
if (value.visual.altFieldName !== undefined && !isNonEmptyString(value.visual.altFieldName)) {
|
|
235
|
+
throw new RecordViewContractError('Tile image visual altFieldName must be a non-empty string.');
|
|
236
|
+
}
|
|
237
|
+
if (value.visual.fieldName.length > 200 || (typeof value.visual.altFieldName === 'string' && value.visual.altFieldName.length > 200))
|
|
238
|
+
throw new RecordViewContractError('Tile image visual field names must be at most 200 characters.');
|
|
239
|
+
if (value.visual.fit !== undefined && value.visual.fit !== 'cover' && value.visual.fit !== 'contain') {
|
|
240
|
+
throw new RecordViewContractError(`Tile image visual fit must be 'cover' or 'contain', got ${String(value.visual.fit)}.`);
|
|
241
|
+
}
|
|
242
|
+
assertOnlyKeys(value.visual, ['altFieldName', 'fieldName', 'fit', 'kind'], 'Tile image visual');
|
|
243
|
+
visual = {
|
|
244
|
+
...(value.visual.altFieldName ? { altFieldName: value.visual.altFieldName } : {}),
|
|
245
|
+
fieldName: value.visual.fieldName,
|
|
246
|
+
...(value.visual.fit ? { fit: value.visual.fit } : {}),
|
|
247
|
+
kind: 'image',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
else if (value.visual.kind === 'avatar') {
|
|
251
|
+
if (value.presentation !== 'standard')
|
|
252
|
+
throw new RecordViewContractError('Tile avatar visuals are only supported on standard tiles.');
|
|
253
|
+
if (!isNonEmptyString(value.visual.fieldName))
|
|
254
|
+
throw new RecordViewContractError('Tile avatar visual requires fieldName.');
|
|
255
|
+
if (value.visual.altFieldName !== undefined && !isNonEmptyString(value.visual.altFieldName))
|
|
256
|
+
throw new RecordViewContractError('Tile avatar visual altFieldName must be a non-empty string.');
|
|
257
|
+
if (value.visual.fieldName.length > 200 || (typeof value.visual.altFieldName === 'string' && value.visual.altFieldName.length > 200))
|
|
258
|
+
throw new RecordViewContractError('Tile avatar visual field names must be at most 200 characters.');
|
|
259
|
+
assertOnlyKeys(value.visual, ['altFieldName', 'fieldName', 'kind'], 'Tile avatar visual');
|
|
260
|
+
visual = {
|
|
261
|
+
...(value.visual.altFieldName ? { altFieldName: value.visual.altFieldName } : {}),
|
|
262
|
+
fieldName: value.visual.fieldName,
|
|
263
|
+
kind: 'avatar',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
else if (value.visual.kind === 'icon') {
|
|
267
|
+
if (!isNonEmptyString(value.visual.iconId)) {
|
|
268
|
+
throw new RecordViewContractError('Tile icon visual requires iconId.');
|
|
269
|
+
}
|
|
270
|
+
if (!isSafeTileIconId(value.visual.iconId))
|
|
271
|
+
throw new RecordViewContractError(`Tile icon is not in the platform icon catalogue: ${value.visual.iconId}.`);
|
|
272
|
+
assertOnlyKeys(value.visual, ['iconId', 'kind'], 'Tile icon visual');
|
|
273
|
+
visual = { iconId: value.visual.iconId, kind: 'icon' };
|
|
274
|
+
}
|
|
275
|
+
else if (value.visual.kind === 'enum-icon') {
|
|
276
|
+
if (!isNonEmptyString(value.visual.fieldName)) {
|
|
277
|
+
throw new RecordViewContractError('Tile enum-icon visual requires fieldName.');
|
|
278
|
+
}
|
|
279
|
+
if (!isNonEmptyString(value.visual.fallbackIconId)) {
|
|
280
|
+
throw new RecordViewContractError('Tile enum-icon visual requires fallbackIconId.');
|
|
281
|
+
}
|
|
282
|
+
if (value.visual.fieldName.length > 200) {
|
|
283
|
+
throw new RecordViewContractError('Tile enum-icon fieldName must be at most 200 characters.');
|
|
284
|
+
}
|
|
285
|
+
if (!isSafeTileIconId(value.visual.fallbackIconId)) {
|
|
286
|
+
throw new RecordViewContractError(`Tile icon is not in the platform icon catalogue: ${String(value.visual.fallbackIconId)}.`);
|
|
287
|
+
}
|
|
288
|
+
assertOnlyKeys(value.visual, ['fallbackIconId', 'fieldName', 'kind'], 'Tile enum icon visual');
|
|
289
|
+
visual = {
|
|
290
|
+
fallbackIconId: value.visual.fallbackIconId,
|
|
291
|
+
fieldName: value.visual.fieldName,
|
|
292
|
+
kind: 'enum-icon',
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
throw new RecordViewContractError(`Invalid tile visual kind: ${String(value.visual.kind)}.`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const checkOptionalStringArray = (arr, name) => {
|
|
300
|
+
if (arr === undefined)
|
|
301
|
+
return undefined;
|
|
302
|
+
if (!Array.isArray(arr) || arr.length > MAX_VIEW_FIELDS || !arr.every(item => isNonEmptyString(item) && item.length <= 200)) {
|
|
303
|
+
throw new RecordViewContractError(`Tile layout ${name} must be an array of non-empty strings.`);
|
|
304
|
+
}
|
|
305
|
+
if (new Set(arr).size !== arr.length)
|
|
306
|
+
throw new RecordViewContractError(`Tile layout ${name} cannot contain duplicate fields.`);
|
|
307
|
+
return arr;
|
|
308
|
+
};
|
|
309
|
+
if (value.eyebrowFieldName !== undefined && !isNonEmptyString(value.eyebrowFieldName)) {
|
|
310
|
+
throw new RecordViewContractError('Tile layout eyebrowFieldName must be a non-empty string.');
|
|
311
|
+
}
|
|
312
|
+
if (value.trailingFieldName !== undefined && !isNonEmptyString(value.trailingFieldName)) {
|
|
313
|
+
throw new RecordViewContractError('Tile layout trailingFieldName must be a non-empty string.');
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
...(value.badgeFieldNames !== undefined ? { badgeFieldNames: checkOptionalStringArray(value.badgeFieldNames, 'badgeFieldNames') } : {}),
|
|
317
|
+
...(value.badgeStyle !== undefined ? { badgeStyle: value.badgeStyle } : {}),
|
|
318
|
+
...(value.detailFieldNames !== undefined ? { detailFieldNames: checkOptionalStringArray(value.detailFieldNames, 'detailFieldNames') } : {}),
|
|
319
|
+
...(isNonEmptyString(value.eyebrowFieldName) ? { eyebrowFieldName: value.eyebrowFieldName } : {}),
|
|
320
|
+
presentation: value.presentation,
|
|
321
|
+
...(value.subtitleFieldNames !== undefined ? { subtitleFieldNames: checkOptionalStringArray(value.subtitleFieldNames, 'subtitleFieldNames') } : {}),
|
|
322
|
+
titleFieldName: value.titleFieldName,
|
|
323
|
+
...(isNonEmptyString(value.trailingFieldName) ? { trailingFieldName: value.trailingFieldName } : {}),
|
|
324
|
+
version: 1,
|
|
325
|
+
...(visual ? { visual } : {}),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
export function isRecordTileLayoutV1(value) {
|
|
329
|
+
try {
|
|
330
|
+
validateRecordTileLayoutV1(value);
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function validatePresetBase(value) {
|
|
338
|
+
if (!isPlainObject(value)) {
|
|
339
|
+
throw new RecordViewContractError('Preset must be an object.');
|
|
340
|
+
}
|
|
341
|
+
if (!isNonEmptyString(value.id)) {
|
|
342
|
+
throw new RecordViewContractError('Preset id must be a non-empty string.');
|
|
343
|
+
}
|
|
344
|
+
if (!isNonEmptyString(value.title)) {
|
|
345
|
+
throw new RecordViewContractError('Preset title must be a non-empty string.');
|
|
346
|
+
}
|
|
347
|
+
assertOnlyKeys(value, ['config', 'filter', 'id', 'kind', 'orderBy', 'title'], 'Preset');
|
|
348
|
+
if (value.id.length > 80 || value.title.length > 120)
|
|
349
|
+
throw new RecordViewContractError('Preset id must be at most 80 characters and title at most 120 characters.');
|
|
350
|
+
if (value.filter !== undefined)
|
|
351
|
+
assertRecordWhereShape(value.filter);
|
|
352
|
+
const filter = value.filter;
|
|
353
|
+
const orderBy = validateOrderBy(value.orderBy);
|
|
354
|
+
return {
|
|
355
|
+
...(value.filter !== undefined ? { filter } : {}),
|
|
356
|
+
id: value.id,
|
|
357
|
+
...(orderBy ? { orderBy } : {}),
|
|
358
|
+
title: value.title,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function validateOrderBy(orderBy) {
|
|
362
|
+
if (orderBy === undefined)
|
|
363
|
+
return undefined;
|
|
364
|
+
if (!Array.isArray(orderBy) || orderBy.length > MAX_SORT_FIELDS) {
|
|
365
|
+
throw new RecordViewContractError(`Preset orderBy must contain at most ${MAX_SORT_FIELDS} sort fields.`);
|
|
366
|
+
}
|
|
367
|
+
const sorts = orderBy.map(validateRecordSortV1);
|
|
368
|
+
if (new Set(sorts.map(sort => sort.fieldName)).size !== sorts.length)
|
|
369
|
+
throw new RecordViewContractError('Preset orderBy cannot contain duplicate fields.');
|
|
370
|
+
return sorts;
|
|
371
|
+
}
|
|
372
|
+
export function validateListPresetV1(value) {
|
|
373
|
+
const base = validatePresetBase(value);
|
|
374
|
+
const obj = value;
|
|
375
|
+
if (obj.kind !== 'list') {
|
|
376
|
+
throw new RecordViewContractError(`List preset kind must be 'list', got ${String(obj.kind)}.`);
|
|
377
|
+
}
|
|
378
|
+
if (!isPlainObject(obj.config)) {
|
|
379
|
+
throw new RecordViewContractError('List preset config must be an object.');
|
|
380
|
+
}
|
|
381
|
+
const tile = validateRecordTileLayoutV1(obj.config.tile);
|
|
382
|
+
assertOnlyKeys(obj.config, ['tile'], 'List preset config');
|
|
383
|
+
return {
|
|
384
|
+
...base,
|
|
385
|
+
config: {
|
|
386
|
+
tile,
|
|
387
|
+
},
|
|
388
|
+
kind: 'list',
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
export function isListPresetV1(value) {
|
|
392
|
+
try {
|
|
393
|
+
validateListPresetV1(value);
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
export function validateDataGridPresetV1(value) {
|
|
401
|
+
const base = validatePresetBase(value);
|
|
402
|
+
const obj = value;
|
|
403
|
+
if (obj.kind !== 'table') {
|
|
404
|
+
throw new RecordViewContractError(`DataGrid preset kind must be 'table', got ${String(obj.kind)}.`);
|
|
405
|
+
}
|
|
406
|
+
if (!isPlainObject(obj.config)) {
|
|
407
|
+
throw new RecordViewContractError('DataGrid preset config must be an object.');
|
|
408
|
+
}
|
|
409
|
+
assertOnlyKeys(obj.config, ['columns', 'tile'], 'DataGrid preset config');
|
|
410
|
+
if (!Array.isArray(obj.config.columns) || obj.config.columns.length === 0 || obj.config.columns.length > MAX_VIEW_FIELDS) {
|
|
411
|
+
throw new RecordViewContractError(`DataGrid preset columns must contain 1 to ${MAX_VIEW_FIELDS} columns.`);
|
|
412
|
+
}
|
|
413
|
+
const columns = obj.config.columns.map((col) => {
|
|
414
|
+
if (!isPlainObject(col) || !isNonEmptyString(col.fieldName)) {
|
|
415
|
+
throw new RecordViewContractError('Column definition must include non-empty fieldName.');
|
|
416
|
+
}
|
|
417
|
+
assertOnlyKeys(col, ['fieldName', 'width'], 'DataGrid column');
|
|
418
|
+
if (col.fieldName.length > 200) {
|
|
419
|
+
throw new RecordViewContractError('DataGrid fieldName must be at most 200 characters.');
|
|
420
|
+
}
|
|
421
|
+
if (col.width !== undefined && (typeof col.width !== 'number' || !Number.isFinite(col.width) || col.width < 80 || col.width > 800)) {
|
|
422
|
+
throw new RecordViewContractError('Column width must be between 80 and 800 pixels.');
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
fieldName: col.fieldName,
|
|
426
|
+
...(col.width !== undefined ? { width: col.width } : {}),
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
if (new Set(columns.map(column => column.fieldName)).size !== columns.length)
|
|
430
|
+
throw new RecordViewContractError('DataGrid columns cannot contain duplicate fields.');
|
|
431
|
+
const tile = obj.config.tile !== undefined ? validateRecordTileLayoutV1(obj.config.tile) : undefined;
|
|
432
|
+
return {
|
|
433
|
+
...base,
|
|
434
|
+
config: {
|
|
435
|
+
columns,
|
|
436
|
+
...(tile ? { tile } : {}),
|
|
437
|
+
},
|
|
438
|
+
kind: 'table',
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
export function isDataGridPresetV1(value) {
|
|
442
|
+
try {
|
|
443
|
+
validateDataGridPresetV1(value);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
export function validateBoardPresetV1(value) {
|
|
451
|
+
const base = validatePresetBase(value);
|
|
452
|
+
const obj = value;
|
|
453
|
+
if (obj.kind !== 'board') {
|
|
454
|
+
throw new RecordViewContractError(`Board preset kind must be 'board', got ${String(obj.kind)}.`);
|
|
455
|
+
}
|
|
456
|
+
if (!isPlainObject(obj.config)) {
|
|
457
|
+
throw new RecordViewContractError('Board preset config must be an object.');
|
|
458
|
+
}
|
|
459
|
+
if (!isNonEmptyString(obj.config.laneFieldName)) {
|
|
460
|
+
throw new RecordViewContractError('Board preset laneFieldName must be a non-empty string.');
|
|
461
|
+
}
|
|
462
|
+
if (obj.config.laneFieldName.length > 200)
|
|
463
|
+
throw new RecordViewContractError('Board preset laneFieldName must be at most 200 characters.');
|
|
464
|
+
assertOnlyKeys(obj.config, ['laneFieldName', 'laneOrder', 'lanePageSize', 'summaries', 'tile'], 'Board preset config');
|
|
465
|
+
const tile = validateRecordTileLayoutV1(obj.config.tile);
|
|
466
|
+
if (obj.config.laneOrder !== undefined && (!Array.isArray(obj.config.laneOrder) || obj.config.laneOrder.length === 0 || obj.config.laneOrder.length > MAX_LANES || !obj.config.laneOrder.every(isNonEmptyString))) {
|
|
467
|
+
throw new RecordViewContractError(`Board preset laneOrder must contain 1 to ${MAX_LANES} non-empty strings.`);
|
|
468
|
+
}
|
|
469
|
+
if (Array.isArray(obj.config.laneOrder) && new Set(obj.config.laneOrder).size !== obj.config.laneOrder.length) {
|
|
470
|
+
throw new RecordViewContractError('Board preset laneOrder cannot contain duplicate values.');
|
|
471
|
+
}
|
|
472
|
+
if (obj.config.lanePageSize !== undefined && (!Number.isInteger(obj.config.lanePageSize) || obj.config.lanePageSize < 1 || obj.config.lanePageSize > MAX_LANE_PAGE_SIZE))
|
|
473
|
+
throw new RecordViewContractError(`Board preset lanePageSize must be between 1 and ${MAX_LANE_PAGE_SIZE}.`);
|
|
474
|
+
const summaries = validateRecordViewSummariesV1(obj.config.summaries);
|
|
475
|
+
return {
|
|
476
|
+
...base,
|
|
477
|
+
config: {
|
|
478
|
+
laneFieldName: obj.config.laneFieldName,
|
|
479
|
+
...(obj.config.laneOrder ? { laneOrder: obj.config.laneOrder } : {}),
|
|
480
|
+
...(obj.config.lanePageSize !== undefined ? { lanePageSize: obj.config.lanePageSize } : {}),
|
|
481
|
+
...(summaries ? { summaries } : {}),
|
|
482
|
+
tile,
|
|
483
|
+
},
|
|
484
|
+
kind: 'board',
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function validateRecordViewSummariesV1(value) {
|
|
488
|
+
if (value === undefined)
|
|
489
|
+
return undefined;
|
|
490
|
+
if (!Array.isArray(value) || value.length > 3)
|
|
491
|
+
throw new RecordViewContractError('Board summaries must contain at most 3 numeric summaries.');
|
|
492
|
+
const summaries = value.map((entry) => {
|
|
493
|
+
if (!isPlainObject(entry))
|
|
494
|
+
throw new RecordViewContractError('Board summary must be an object.');
|
|
495
|
+
assertOnlyKeys(entry, ['fieldName', 'operation'], 'Board summary');
|
|
496
|
+
if (!isNonEmptyString(entry.fieldName) || entry.fieldName.length > 200)
|
|
497
|
+
throw new RecordViewContractError('Board summary fieldName must be a non-empty string of at most 200 characters.');
|
|
498
|
+
if (entry.operation !== 'average' && entry.operation !== 'max' && entry.operation !== 'min' && entry.operation !== 'sum')
|
|
499
|
+
throw new RecordViewContractError('Board summary operation must be average, max, min, or sum.');
|
|
500
|
+
return { fieldName: entry.fieldName, operation: entry.operation };
|
|
501
|
+
});
|
|
502
|
+
if (new Set(summaries.map(summary => `${summary.operation}:${summary.fieldName}`)).size !== summaries.length)
|
|
503
|
+
throw new RecordViewContractError('Board summaries cannot contain duplicates.');
|
|
504
|
+
return summaries;
|
|
505
|
+
}
|
|
506
|
+
export function isBoardPresetV1(value) {
|
|
507
|
+
if (!isPlainObject(value) || value.kind !== 'board')
|
|
508
|
+
return false;
|
|
509
|
+
try {
|
|
510
|
+
validateBoardPresetV1(value);
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
export function validateInboxPresetV1(value) {
|
|
518
|
+
const base = validatePresetBase(value);
|
|
519
|
+
const obj = value;
|
|
520
|
+
if (obj.kind !== 'inbox') {
|
|
521
|
+
throw new RecordViewContractError(`Inbox preset kind must be 'inbox', got ${String(obj.kind)}.`);
|
|
522
|
+
}
|
|
523
|
+
if (!isPlainObject(obj.config)) {
|
|
524
|
+
throw new RecordViewContractError('Inbox preset config must be an object.');
|
|
525
|
+
}
|
|
526
|
+
const listTile = validateRecordTileLayoutV1(obj.config.listTile);
|
|
527
|
+
if (obj.config.detail !== undefined && obj.config.detail !== 'fields' && obj.config.detail !== 'record')
|
|
528
|
+
throw new RecordViewContractError('Inbox detail must be fields or record.');
|
|
529
|
+
if (obj.config.detail === 'record' && obj.config.detailFieldNames !== undefined) {
|
|
530
|
+
throw new RecordViewContractError('Inbox detailFieldNames are only valid when detail is fields.');
|
|
531
|
+
}
|
|
532
|
+
const detailFieldNames = obj.config.detail === 'record' ? undefined : obj.config.detailFieldNames;
|
|
533
|
+
if (detailFieldNames !== undefined && (!Array.isArray(detailFieldNames) || detailFieldNames.length === 0 || detailFieldNames.length > MAX_VIEW_FIELDS || !detailFieldNames.every(name => isNonEmptyString(name) && name.length <= 200))) {
|
|
534
|
+
throw new RecordViewContractError(`Inbox preset detailFieldNames must contain 1 to ${MAX_VIEW_FIELDS} non-empty field names.`);
|
|
535
|
+
}
|
|
536
|
+
if (detailFieldNames === undefined && obj.config.detail !== 'record') {
|
|
537
|
+
throw new RecordViewContractError(`Inbox preset detailFieldNames must contain 1 to ${MAX_VIEW_FIELDS} non-empty field names.`);
|
|
538
|
+
}
|
|
539
|
+
if (Array.isArray(detailFieldNames) && new Set(detailFieldNames).size !== detailFieldNames.length)
|
|
540
|
+
throw new RecordViewContractError('Inbox preset detailFieldNames cannot contain duplicates.');
|
|
541
|
+
assertOnlyKeys(obj.config, ['detail', 'detailFieldNames', 'listTile'], 'Inbox preset config');
|
|
542
|
+
const detailConfig = obj.config.detail === 'record'
|
|
543
|
+
? { detail: 'record' }
|
|
544
|
+
: {
|
|
545
|
+
...(obj.config.detail === 'fields' ? { detail: 'fields' } : {}),
|
|
546
|
+
detailFieldNames: detailFieldNames,
|
|
547
|
+
};
|
|
548
|
+
return {
|
|
549
|
+
...base,
|
|
550
|
+
config: {
|
|
551
|
+
...detailConfig,
|
|
552
|
+
listTile,
|
|
553
|
+
},
|
|
554
|
+
kind: 'inbox',
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
export function isInboxPresetV1(value) {
|
|
558
|
+
try {
|
|
559
|
+
validateInboxPresetV1(value);
|
|
560
|
+
return true;
|
|
561
|
+
}
|
|
562
|
+
catch {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
export function validateRecordViewPresetV1(value) {
|
|
567
|
+
if (!isPlainObject(value)) {
|
|
568
|
+
throw new RecordViewContractError('Preset must be an object.');
|
|
569
|
+
}
|
|
570
|
+
switch (value.kind) {
|
|
571
|
+
case 'list':
|
|
572
|
+
return validateListPresetV1(value);
|
|
573
|
+
case 'table':
|
|
574
|
+
return validateDataGridPresetV1(value);
|
|
575
|
+
case 'board':
|
|
576
|
+
return validateBoardPresetV1(value);
|
|
577
|
+
case 'inbox':
|
|
578
|
+
return validateInboxPresetV1(value);
|
|
579
|
+
default:
|
|
580
|
+
throw new RecordViewContractError(`Unknown record view preset kind: ${String(value.kind)}.`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
export function isRecordViewPresetV1(value) {
|
|
584
|
+
try {
|
|
585
|
+
validateRecordViewPresetV1(value);
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export function validateViewPresetSetV1(value) {
|
|
593
|
+
if (!isPlainObject(value)) {
|
|
594
|
+
throw new RecordViewContractError('ViewPresetSet must be an object.');
|
|
595
|
+
}
|
|
596
|
+
assertOnlyKeys(value, ['defaultPresetId', 'presets', 'version'], 'ViewPresetSet');
|
|
597
|
+
if (value.version !== 1) {
|
|
598
|
+
throw new RecordViewContractError(`ViewPresetSet version must be 1, got ${String(value.version)}.`);
|
|
599
|
+
}
|
|
600
|
+
if (!isNonEmptyString(value.defaultPresetId)) {
|
|
601
|
+
throw new RecordViewContractError('ViewPresetSet defaultPresetId must be a non-empty string.');
|
|
602
|
+
}
|
|
603
|
+
if (value.defaultPresetId.length > 80)
|
|
604
|
+
throw new RecordViewContractError('ViewPresetSet defaultPresetId must be at most 80 characters.');
|
|
605
|
+
if (!Array.isArray(value.presets) || value.presets.length === 0 || value.presets.length > MAX_PRESETS) {
|
|
606
|
+
throw new RecordViewContractError(`ViewPresetSet presets must contain 1 to ${MAX_PRESETS} presets.`);
|
|
607
|
+
}
|
|
608
|
+
const presets = value.presets.map(validateRecordViewPresetV1);
|
|
609
|
+
const ids = new Set();
|
|
610
|
+
for (const preset of presets) {
|
|
611
|
+
if (ids.has(preset.id)) {
|
|
612
|
+
throw new RecordViewContractError(`Duplicate preset id found: ${preset.id}.`);
|
|
613
|
+
}
|
|
614
|
+
ids.add(preset.id);
|
|
615
|
+
}
|
|
616
|
+
if (!ids.has(value.defaultPresetId)) {
|
|
617
|
+
throw new RecordViewContractError(`defaultPresetId '${value.defaultPresetId}' not found in presets.`);
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
defaultPresetId: value.defaultPresetId,
|
|
621
|
+
presets,
|
|
622
|
+
version: 1,
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
export function isViewPresetSetV1(value) {
|
|
626
|
+
try {
|
|
627
|
+
validateViewPresetSetV1(value);
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
export function validateControlledFilterPropsV1(props) {
|
|
635
|
+
if (!isPlainObject(props)) {
|
|
636
|
+
throw new RecordViewContractError('Props must be an object.');
|
|
637
|
+
}
|
|
638
|
+
const hasFilter = 'filter' in props;
|
|
639
|
+
const hasOnFilterChange = 'onFilterChange' in props;
|
|
640
|
+
if (!hasFilter && !hasOnFilterChange) {
|
|
641
|
+
return {};
|
|
642
|
+
}
|
|
643
|
+
if (hasFilter && props.filter === undefined && !hasOnFilterChange) {
|
|
644
|
+
return {};
|
|
645
|
+
}
|
|
646
|
+
if (hasFilter && !hasOnFilterChange) {
|
|
647
|
+
throw new RecordViewContractError('Controlled filter requires onFilterChange callback.');
|
|
648
|
+
}
|
|
649
|
+
if (!hasFilter && hasOnFilterChange) {
|
|
650
|
+
throw new RecordViewContractError('Controlled onFilterChange requires a filter prop.');
|
|
651
|
+
}
|
|
652
|
+
if (typeof props.onFilterChange !== 'function') {
|
|
653
|
+
throw new RecordViewContractError('onFilterChange must be a function.');
|
|
654
|
+
}
|
|
655
|
+
if (props.filter !== undefined)
|
|
656
|
+
assertRecordWhereShape(props.filter);
|
|
657
|
+
return {
|
|
658
|
+
filter: props.filter,
|
|
659
|
+
onFilterChange: props.onFilterChange,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
export function isControlledFilterPropsV1(props) {
|
|
663
|
+
try {
|
|
664
|
+
validateControlledFilterPropsV1(props);
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-badge.d.ts","sourceRoot":"","sources":["../../src/elements/status-badge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"status-badge.d.ts","sourceRoot":"","sources":["../../src/elements/status-badge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AA4DzE,QAAA,MAAM,eAAe,EAAE,OAAO,WAAsE,CAAA;AAEpG,8DAA8D;AAC9D,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,MAAM,KAAK,kBAAkB,aAE5B;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,MAAM,EAE5B;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED,IAAI,IAAI,IAAI,qBAAqB,CAGhC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,qBAAqB,EAEpC;;IAOD,wBAAwB,IAAI,IAAI;IAIhC,iBAAiB,IAAI,IAAI;IAIzB,OAAO,CAAC,MAAM;CAqBf;AAED,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C"}
|