@zhama/a2ui-core 0.1.0 → 0.2.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 +95 -22
- package/dist/builders/index.cjs +3 -496
- package/dist/builders/index.d.cts +8 -13
- package/dist/builders/index.d.ts +8 -13
- package/dist/builders/index.js +3 -445
- package/dist/index.cjs +3 -869
- package/dist/index.d.cts +3 -41
- package/dist/index.d.ts +3 -41
- package/dist/index.js +3 -802
- package/dist/primitives-nmkVz-tB.d.cts +80 -0
- package/dist/primitives-nmkVz-tB.d.ts +80 -0
- package/dist/types/index.cjs +2 -22
- package/dist/types/index.d.cts +3 -79
- package/dist/types/index.d.ts +3 -79
- package/dist/types/index.js +2 -15
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.cts +40 -0
- package/dist/utils/index.d.ts +40 -0
- package/dist/utils/index.js +1 -0
- package/dist/validators/index.cjs +1 -313
- package/dist/validators/index.d.cts +1 -0
- package/dist/validators/index.d.ts +1 -0
- package/dist/validators/index.js +1 -308
- package/package.json +80 -53
- package/dist/builders/index.cjs.map +0 -1
- package/dist/builders/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/validators/index.cjs.map +0 -1
- package/dist/validators/index.js.map +0 -1
package/dist/builders/index.cjs
CHANGED
|
@@ -1,496 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var componentIdCounter = 0;
|
|
5
|
-
function generateId(prefix = "comp") {
|
|
6
|
-
return `${prefix}_${Date.now()}_${componentIdCounter++}`;
|
|
7
|
-
}
|
|
8
|
-
function resetIdCounter() {
|
|
9
|
-
componentIdCounter = 0;
|
|
10
|
-
}
|
|
11
|
-
function getIdCounter() {
|
|
12
|
-
return componentIdCounter;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/builders/component-builder.ts
|
|
16
|
-
function text(content, options = {}) {
|
|
17
|
-
const { id = generateId("text"), weight, usageHint } = options;
|
|
18
|
-
return {
|
|
19
|
-
id,
|
|
20
|
-
component: "Text",
|
|
21
|
-
text: content,
|
|
22
|
-
...weight !== void 0 && { weight },
|
|
23
|
-
...usageHint && { usageHint }
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function image(url, options = {}) {
|
|
27
|
-
const { id = generateId("image"), weight, fit, usageHint } = options;
|
|
28
|
-
return {
|
|
29
|
-
id,
|
|
30
|
-
component: "Image",
|
|
31
|
-
url,
|
|
32
|
-
...weight !== void 0 && { weight },
|
|
33
|
-
...fit && { fit },
|
|
34
|
-
...usageHint && { usageHint }
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function icon(name, options = {}) {
|
|
38
|
-
const { id = generateId("icon"), weight } = options;
|
|
39
|
-
return {
|
|
40
|
-
id,
|
|
41
|
-
component: "Icon",
|
|
42
|
-
name,
|
|
43
|
-
...weight !== void 0 && { weight }
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function video(url, options = {}) {
|
|
47
|
-
const { id = generateId("video"), weight } = options;
|
|
48
|
-
return {
|
|
49
|
-
id,
|
|
50
|
-
component: "Video",
|
|
51
|
-
url,
|
|
52
|
-
...weight !== void 0 && { weight }
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function audioPlayer(url, options = {}) {
|
|
56
|
-
const { id = generateId("audio"), weight, description } = options;
|
|
57
|
-
return {
|
|
58
|
-
id,
|
|
59
|
-
component: "AudioPlayer",
|
|
60
|
-
url,
|
|
61
|
-
...weight !== void 0 && { weight },
|
|
62
|
-
...description && { description }
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function row(children, options = {}) {
|
|
66
|
-
const { id = generateId("row"), weight, alignment, distribution } = options;
|
|
67
|
-
return {
|
|
68
|
-
id,
|
|
69
|
-
component: "Row",
|
|
70
|
-
children,
|
|
71
|
-
...weight !== void 0 && { weight },
|
|
72
|
-
...alignment && { alignment },
|
|
73
|
-
...distribution && { distribution }
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function column(children, options = {}) {
|
|
77
|
-
const { id = generateId("column"), weight, alignment, distribution } = options;
|
|
78
|
-
return {
|
|
79
|
-
id,
|
|
80
|
-
component: "Column",
|
|
81
|
-
children,
|
|
82
|
-
...weight !== void 0 && { weight },
|
|
83
|
-
...alignment && { alignment },
|
|
84
|
-
...distribution && { distribution }
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function list(children, options = {}) {
|
|
88
|
-
const { id = generateId("list"), weight, direction, alignment } = options;
|
|
89
|
-
return {
|
|
90
|
-
id,
|
|
91
|
-
component: "List",
|
|
92
|
-
children,
|
|
93
|
-
...weight !== void 0 && { weight },
|
|
94
|
-
...direction && { direction },
|
|
95
|
-
...alignment && { alignment }
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function card(childId, options = {}) {
|
|
99
|
-
const { id = generateId("card"), weight } = options;
|
|
100
|
-
return {
|
|
101
|
-
id,
|
|
102
|
-
component: "Card",
|
|
103
|
-
child: childId,
|
|
104
|
-
...weight !== void 0 && { weight }
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function tabs(items, options = {}) {
|
|
108
|
-
const { id = generateId("tabs"), weight } = options;
|
|
109
|
-
return {
|
|
110
|
-
id,
|
|
111
|
-
component: "Tabs",
|
|
112
|
-
tabItems: items.map((item) => ({
|
|
113
|
-
title: item.title,
|
|
114
|
-
child: item.childId
|
|
115
|
-
})),
|
|
116
|
-
...weight !== void 0 && { weight }
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function divider(options = {}) {
|
|
120
|
-
const { id = generateId("divider"), weight, axis } = options;
|
|
121
|
-
return {
|
|
122
|
-
id,
|
|
123
|
-
component: "Divider",
|
|
124
|
-
...weight !== void 0 && { weight },
|
|
125
|
-
...axis && { axis }
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function modal(entryPointChildId, contentChildId, options = {}) {
|
|
129
|
-
const { id = generateId("modal"), weight } = options;
|
|
130
|
-
return {
|
|
131
|
-
id,
|
|
132
|
-
component: "Modal",
|
|
133
|
-
entryPointChild: entryPointChildId,
|
|
134
|
-
contentChild: contentChildId,
|
|
135
|
-
...weight !== void 0 && { weight }
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function button(childId, action, options = {}) {
|
|
139
|
-
const { id = generateId("button"), weight, primary } = options;
|
|
140
|
-
return {
|
|
141
|
-
id,
|
|
142
|
-
component: "Button",
|
|
143
|
-
child: childId,
|
|
144
|
-
action,
|
|
145
|
-
...weight !== void 0 && { weight },
|
|
146
|
-
...primary !== void 0 && { primary }
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function checkbox(label, value, options = {}) {
|
|
150
|
-
const { id = generateId("checkbox"), weight } = options;
|
|
151
|
-
return {
|
|
152
|
-
id,
|
|
153
|
-
component: "CheckBox",
|
|
154
|
-
label,
|
|
155
|
-
value,
|
|
156
|
-
...weight !== void 0 && { weight }
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function textField(label, textValue, options = {}) {
|
|
160
|
-
const { id = generateId("textfield"), weight, usageHint, validationRegexp } = options;
|
|
161
|
-
return {
|
|
162
|
-
id,
|
|
163
|
-
component: "TextField",
|
|
164
|
-
label,
|
|
165
|
-
...textValue !== void 0 && { text: textValue },
|
|
166
|
-
...weight !== void 0 && { weight },
|
|
167
|
-
...usageHint && { usageHint },
|
|
168
|
-
...validationRegexp && { validationRegexp }
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function dateTimeInput(value, options = {}) {
|
|
172
|
-
const { id = generateId("datetime"), weight, enableDate, enableTime, outputFormat, label } = options;
|
|
173
|
-
return {
|
|
174
|
-
id,
|
|
175
|
-
component: "DateTimeInput",
|
|
176
|
-
value,
|
|
177
|
-
...weight !== void 0 && { weight },
|
|
178
|
-
...enableDate !== void 0 && { enableDate },
|
|
179
|
-
...enableTime !== void 0 && { enableTime },
|
|
180
|
-
...outputFormat && { outputFormat },
|
|
181
|
-
...label && { label }
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function choicePicker(optionsList, value, usageHint, options = {}) {
|
|
185
|
-
const { id = generateId("choice"), weight, label } = options;
|
|
186
|
-
return {
|
|
187
|
-
id,
|
|
188
|
-
component: "ChoicePicker",
|
|
189
|
-
options: optionsList,
|
|
190
|
-
value,
|
|
191
|
-
usageHint,
|
|
192
|
-
...weight !== void 0 && { weight },
|
|
193
|
-
...label && { label }
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function slider(value, options = {}) {
|
|
197
|
-
const { id = generateId("slider"), weight, label, min, max } = options;
|
|
198
|
-
return {
|
|
199
|
-
id,
|
|
200
|
-
component: "Slider",
|
|
201
|
-
value,
|
|
202
|
-
...weight !== void 0 && { weight },
|
|
203
|
-
...label && { label },
|
|
204
|
-
...min !== void 0 && { min },
|
|
205
|
-
...max !== void 0 && { max }
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function textButton(buttonText, action, options = {}) {
|
|
209
|
-
const textId = options.textId ?? generateId("btn_text");
|
|
210
|
-
const textComp = text(buttonText, { id: textId });
|
|
211
|
-
const buttonComp = button(textId, action, options);
|
|
212
|
-
return [textComp, buttonComp];
|
|
213
|
-
}
|
|
214
|
-
function h1(content, options = {}) {
|
|
215
|
-
return text(content, { ...options, usageHint: "h1" });
|
|
216
|
-
}
|
|
217
|
-
function h2(content, options = {}) {
|
|
218
|
-
return text(content, { ...options, usageHint: "h2" });
|
|
219
|
-
}
|
|
220
|
-
function h3(content, options = {}) {
|
|
221
|
-
return text(content, { ...options, usageHint: "h3" });
|
|
222
|
-
}
|
|
223
|
-
function h4(content, options = {}) {
|
|
224
|
-
return text(content, { ...options, usageHint: "h4" });
|
|
225
|
-
}
|
|
226
|
-
function h5(content, options = {}) {
|
|
227
|
-
return text(content, { ...options, usageHint: "h5" });
|
|
228
|
-
}
|
|
229
|
-
function caption(content, options = {}) {
|
|
230
|
-
return text(content, { ...options, usageHint: "caption" });
|
|
231
|
-
}
|
|
232
|
-
function body(content, options = {}) {
|
|
233
|
-
return text(content, { ...options, usageHint: "body" });
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/types/messages.ts
|
|
237
|
-
var STANDARD_CATALOG_ID = "https://a2ui.dev/specification/0.9/standard_catalog_definition.json";
|
|
238
|
-
|
|
239
|
-
// src/builders/data-model-builder.ts
|
|
240
|
-
var DEFAULT_PATH_MAPPINGS = {};
|
|
241
|
-
function objectToValueMap(obj, prefix = "") {
|
|
242
|
-
const entries = [];
|
|
243
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
244
|
-
const fullKey = prefix ? `${prefix}/${key}` : `/${key}`;
|
|
245
|
-
entries.push(valueToValueMap(fullKey, value));
|
|
246
|
-
}
|
|
247
|
-
return entries;
|
|
248
|
-
}
|
|
249
|
-
function valueToValueMap(key, value) {
|
|
250
|
-
if (value === null || value === void 0) {
|
|
251
|
-
return { key, valueString: "" };
|
|
252
|
-
}
|
|
253
|
-
if (typeof value === "string") {
|
|
254
|
-
return { key, valueString: value };
|
|
255
|
-
}
|
|
256
|
-
if (typeof value === "number") {
|
|
257
|
-
return { key, valueNumber: value };
|
|
258
|
-
}
|
|
259
|
-
if (typeof value === "boolean") {
|
|
260
|
-
return { key, valueBoolean: value };
|
|
261
|
-
}
|
|
262
|
-
if (Array.isArray(value)) {
|
|
263
|
-
return {
|
|
264
|
-
key,
|
|
265
|
-
valueMap: value.map((item, index) => valueToValueMap(String(index), item))
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
if (typeof value === "object") {
|
|
269
|
-
const nestedMaps = [];
|
|
270
|
-
for (const [k, v] of Object.entries(value)) {
|
|
271
|
-
nestedMaps.push(valueToValueMap(k, v));
|
|
272
|
-
}
|
|
273
|
-
return { key, valueMap: nestedMaps };
|
|
274
|
-
}
|
|
275
|
-
return { key, valueString: String(value) };
|
|
276
|
-
}
|
|
277
|
-
function normalizePath(path, pathMappings = {}) {
|
|
278
|
-
let normalizedPath = path.replace(/\./g, "/");
|
|
279
|
-
if (!normalizedPath.startsWith("/")) {
|
|
280
|
-
normalizedPath = `/${normalizedPath}`;
|
|
281
|
-
}
|
|
282
|
-
for (const [from, to] of Object.entries(pathMappings)) {
|
|
283
|
-
const fromPattern = new RegExp(`^/${from}(/|$)`);
|
|
284
|
-
if (fromPattern.test(normalizedPath)) {
|
|
285
|
-
normalizedPath = normalizedPath.replace(fromPattern, `/${to}$1`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return normalizedPath;
|
|
289
|
-
}
|
|
290
|
-
function updatesToValueMap(updates, basePath = "", pathMappings = DEFAULT_PATH_MAPPINGS) {
|
|
291
|
-
const entries = [];
|
|
292
|
-
for (const update of updates) {
|
|
293
|
-
const rawPath = update.path.startsWith("/") ? update.path : `${basePath}/${update.path}`;
|
|
294
|
-
const normalizedPath = normalizePath(rawPath, pathMappings);
|
|
295
|
-
if (update.value !== null && typeof update.value === "object" && !Array.isArray(update.value)) {
|
|
296
|
-
const flattenedEntries = flattenObjectToValueMap(
|
|
297
|
-
update.value,
|
|
298
|
-
normalizedPath
|
|
299
|
-
);
|
|
300
|
-
entries.push(...flattenedEntries);
|
|
301
|
-
} else {
|
|
302
|
-
entries.push(valueToValueMap(normalizedPath, update.value));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return entries;
|
|
306
|
-
}
|
|
307
|
-
function flattenObjectToValueMap(obj, basePath) {
|
|
308
|
-
const entries = [];
|
|
309
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
310
|
-
const fullPath = `${basePath}/${key}`;
|
|
311
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
312
|
-
const nestedEntries = flattenObjectToValueMap(value, fullPath);
|
|
313
|
-
entries.push(...nestedEntries);
|
|
314
|
-
} else {
|
|
315
|
-
entries.push(valueToValueMap(fullPath, value));
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return entries;
|
|
319
|
-
}
|
|
320
|
-
function valueMapToObject(valueMaps) {
|
|
321
|
-
const result = {};
|
|
322
|
-
for (const valueMap of valueMaps) {
|
|
323
|
-
const key = valueMap.key.startsWith("/") ? valueMap.key.slice(1) : valueMap.key;
|
|
324
|
-
if (valueMap.valueString !== void 0) {
|
|
325
|
-
result[key] = valueMap.valueString;
|
|
326
|
-
} else if (valueMap.valueNumber !== void 0) {
|
|
327
|
-
result[key] = valueMap.valueNumber;
|
|
328
|
-
} else if (valueMap.valueBoolean !== void 0) {
|
|
329
|
-
result[key] = valueMap.valueBoolean;
|
|
330
|
-
} else if (valueMap.valueMap !== void 0) {
|
|
331
|
-
result[key] = valueMapToObject(valueMap.valueMap);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return result;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// src/builders/message-builder.ts
|
|
338
|
-
function createSurface(surfaceId, catalogId = STANDARD_CATALOG_ID) {
|
|
339
|
-
return {
|
|
340
|
-
createSurface: {
|
|
341
|
-
surfaceId,
|
|
342
|
-
catalogId
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function updateComponents(surfaceId, components) {
|
|
347
|
-
return {
|
|
348
|
-
updateComponents: {
|
|
349
|
-
surfaceId,
|
|
350
|
-
components
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
function updateDataModel(surfaceId, value, path, op = "replace") {
|
|
355
|
-
return {
|
|
356
|
-
updateDataModel: {
|
|
357
|
-
surfaceId,
|
|
358
|
-
...path && { path },
|
|
359
|
-
op,
|
|
360
|
-
...op !== "remove" && { value }
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function deleteSurface(surfaceId) {
|
|
365
|
-
return {
|
|
366
|
-
deleteSurface: {
|
|
367
|
-
surfaceId
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
function createV09Messages(options) {
|
|
372
|
-
const { surfaceId, catalogId = STANDARD_CATALOG_ID, components, dataModel } = options;
|
|
373
|
-
const messages = [
|
|
374
|
-
createSurface(surfaceId, catalogId),
|
|
375
|
-
updateComponents(surfaceId, components)
|
|
376
|
-
];
|
|
377
|
-
if (dataModel) {
|
|
378
|
-
messages.push(updateDataModel(surfaceId, dataModel));
|
|
379
|
-
}
|
|
380
|
-
return messages;
|
|
381
|
-
}
|
|
382
|
-
function beginRendering(rootId, surfaceId = "@default", styles) {
|
|
383
|
-
return {
|
|
384
|
-
beginRendering: {
|
|
385
|
-
surfaceId,
|
|
386
|
-
root: rootId,
|
|
387
|
-
...styles && { styles }
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
function surfaceUpdate(components, surfaceId = "@default") {
|
|
392
|
-
return {
|
|
393
|
-
surfaceUpdate: {
|
|
394
|
-
surfaceId,
|
|
395
|
-
components
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
function dataModelUpdate(contents, surfaceId = "@default", path) {
|
|
400
|
-
return {
|
|
401
|
-
dataModelUpdate: {
|
|
402
|
-
surfaceId,
|
|
403
|
-
contents,
|
|
404
|
-
...path && { path }
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function dataModelInit(data, surfaceId = "@default") {
|
|
409
|
-
return dataModelUpdate(objectToValueMap(data), surfaceId);
|
|
410
|
-
}
|
|
411
|
-
function pathUpdate(path, value, surfaceId = "@default") {
|
|
412
|
-
return {
|
|
413
|
-
dataModelUpdate: {
|
|
414
|
-
surfaceId,
|
|
415
|
-
path,
|
|
416
|
-
contents: [valueToValueMap("", value)]
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
function deleteSurfaceV08(surfaceId) {
|
|
421
|
-
return {
|
|
422
|
-
deleteSurface: {
|
|
423
|
-
surfaceId
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
function createV08Messages(options) {
|
|
428
|
-
const { rootId, components, dataModel, surfaceId = "@default", styles } = options;
|
|
429
|
-
const messages = [
|
|
430
|
-
surfaceUpdate(components, surfaceId)
|
|
431
|
-
];
|
|
432
|
-
if (dataModel) {
|
|
433
|
-
messages.push(dataModelInit(dataModel, surfaceId));
|
|
434
|
-
}
|
|
435
|
-
messages.push(beginRendering(rootId, surfaceId, styles));
|
|
436
|
-
return messages;
|
|
437
|
-
}
|
|
438
|
-
function messagesToJsonl(messages) {
|
|
439
|
-
return messages.map((msg) => JSON.stringify(msg)).join("\n");
|
|
440
|
-
}
|
|
441
|
-
function jsonlToMessages(jsonl) {
|
|
442
|
-
return jsonl.split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line));
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
exports.DEFAULT_PATH_MAPPINGS = DEFAULT_PATH_MAPPINGS;
|
|
446
|
-
exports.audioPlayer = audioPlayer;
|
|
447
|
-
exports.beginRendering = beginRendering;
|
|
448
|
-
exports.body = body;
|
|
449
|
-
exports.button = button;
|
|
450
|
-
exports.caption = caption;
|
|
451
|
-
exports.card = card;
|
|
452
|
-
exports.checkbox = checkbox;
|
|
453
|
-
exports.choicePicker = choicePicker;
|
|
454
|
-
exports.column = column;
|
|
455
|
-
exports.createSurface = createSurface;
|
|
456
|
-
exports.createV08Messages = createV08Messages;
|
|
457
|
-
exports.createV09Messages = createV09Messages;
|
|
458
|
-
exports.dataModelInit = dataModelInit;
|
|
459
|
-
exports.dataModelUpdate = dataModelUpdate;
|
|
460
|
-
exports.dateTimeInput = dateTimeInput;
|
|
461
|
-
exports.deleteSurface = deleteSurface;
|
|
462
|
-
exports.deleteSurfaceV08 = deleteSurfaceV08;
|
|
463
|
-
exports.divider = divider;
|
|
464
|
-
exports.flattenObjectToValueMap = flattenObjectToValueMap;
|
|
465
|
-
exports.generateId = generateId;
|
|
466
|
-
exports.getIdCounter = getIdCounter;
|
|
467
|
-
exports.h1 = h1;
|
|
468
|
-
exports.h2 = h2;
|
|
469
|
-
exports.h3 = h3;
|
|
470
|
-
exports.h4 = h4;
|
|
471
|
-
exports.h5 = h5;
|
|
472
|
-
exports.icon = icon;
|
|
473
|
-
exports.image = image;
|
|
474
|
-
exports.jsonlToMessages = jsonlToMessages;
|
|
475
|
-
exports.list = list;
|
|
476
|
-
exports.messagesToJsonl = messagesToJsonl;
|
|
477
|
-
exports.modal = modal;
|
|
478
|
-
exports.normalizePath = normalizePath;
|
|
479
|
-
exports.objectToValueMap = objectToValueMap;
|
|
480
|
-
exports.pathUpdate = pathUpdate;
|
|
481
|
-
exports.resetIdCounter = resetIdCounter;
|
|
482
|
-
exports.row = row;
|
|
483
|
-
exports.slider = slider;
|
|
484
|
-
exports.surfaceUpdate = surfaceUpdate;
|
|
485
|
-
exports.tabs = tabs;
|
|
486
|
-
exports.text = text;
|
|
487
|
-
exports.textButton = textButton;
|
|
488
|
-
exports.textField = textField;
|
|
489
|
-
exports.updateComponents = updateComponents;
|
|
490
|
-
exports.updateDataModel = updateDataModel;
|
|
491
|
-
exports.updatesToValueMap = updatesToValueMap;
|
|
492
|
-
exports.valueMapToObject = valueMapToObject;
|
|
493
|
-
exports.valueToValueMap = valueToValueMap;
|
|
494
|
-
exports.video = video;
|
|
495
|
-
//# sourceMappingURL=index.cjs.map
|
|
496
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var g=0;function i(t="comp"){return `${t}_${Date.now()}_${g++}`}function V(){g=0;}function D(){return g}function p(t,e={}){let{id:n=i("text"),weight:o,usageHint:a}=e;return {id:n,component:"Text",text:t,...o!==void 0&&{weight:o},...a&&{usageHint:a}}}function v(t,e={}){let{id:n=i("image"),weight:o,fit:a,usageHint:r}=e;return {id:n,component:"Image",url:t,...o!==void 0&&{weight:o},...a&&{fit:a},...r&&{usageHint:r}}}function P(t,e={}){let{id:n=i("icon"),weight:o}=e;return {id:n,component:"Icon",name:t,...o!==void 0&&{weight:o}}}function A(t,e={}){let{id:n=i("video"),weight:o}=e;return {id:n,component:"Video",url:t,...o!==void 0&&{weight:o}}}function U(t,e={}){let{id:n=i("audio"),weight:o,description:a}=e;return {id:n,component:"AudioPlayer",url:t,...o!==void 0&&{weight:o},...a&&{description:a}}}function w(t,e={}){let{id:n=i("row"),weight:o,alignment:a,distribution:r}=e;return {id:n,component:"Row",children:t,...o!==void 0&&{weight:o},...a&&{alignment:a},...r&&{distribution:r}}}function j(t,e={}){let{id:n=i("column"),weight:o,alignment:a,distribution:r}=e;return {id:n,component:"Column",children:t,...o!==void 0&&{weight:o},...a&&{alignment:a},...r&&{distribution:r}}}function R(t,e={}){let{id:n=i("list"),weight:o,direction:a,alignment:r}=e;return {id:n,component:"List",children:t,...o!==void 0&&{weight:o},...a&&{direction:a},...r&&{alignment:r}}}function _(t,e={}){let{id:n=i("card"),weight:o}=e;return {id:n,component:"Card",child:t,...o!==void 0&&{weight:o}}}function k(t,e={}){let{id:n=i("tabs"),weight:o}=e;return {id:n,component:"Tabs",tabItems:t.map(a=>({title:a.title,child:a.childId})),...o!==void 0&&{weight:o}}}function B(t={}){let{id:e=i("divider"),weight:n,axis:o}=t;return {id:e,component:"Divider",...n!==void 0&&{weight:n},...o&&{axis:o}}}function H(t,e,n={}){let{id:o=i("modal"),weight:a}=n;return {id:o,component:"Modal",entryPointChild:t,contentChild:e,...a!==void 0&&{weight:a}}}function f(t,e,n={}){let{id:o=i("button"),weight:a,primary:r}=n;return {id:o,component:"Button",child:t,action:e,...a!==void 0&&{weight:a},...r!==void 0&&{primary:r}}}function N(t,e,n={}){let{id:o=i("checkbox"),weight:a}=n;return {id:o,component:"CheckBox",label:t,value:e,...a!==void 0&&{weight:a}}}function E(t,e,n={}){let{id:o=i("textfield"),weight:a,usageHint:r,validationRegexp:s}=n;return {id:o,component:"TextField",label:t,...e!==void 0&&{text:e},...a!==void 0&&{weight:a},...r&&{usageHint:r},...s&&{validationRegexp:s}}}function L(t,e={}){let{id:n=i("datetime"),weight:o,enableDate:a,enableTime:r,outputFormat:s,label:c}=e;return {id:n,component:"DateTimeInput",value:t,...o!==void 0&&{weight:o},...a!==void 0&&{enableDate:a},...r!==void 0&&{enableTime:r},...s&&{outputFormat:s},...c&&{label:c}}}function $(t,e,n,o={}){let{id:a=i("choice"),weight:r,label:s}=o;return {id:a,component:"ChoicePicker",options:t,value:e,usageHint:n,...r!==void 0&&{weight:r},...s&&{label:s}}}function F(t,e={}){let{id:n=i("slider"),weight:o,label:a,min:r,max:s}=e;return {id:n,component:"Slider",value:t,...o!==void 0&&{weight:o},...a&&{label:a},...r!==void 0&&{min:r},...s!==void 0&&{max:s}}}function G(t,e,n={}){let o=n.textId??i("btn_text"),a=p(t,{id:o}),r=f(o,e,n);return [a,r]}function z(t,e={}){return p(t,{...e,usageHint:"h1"})}function J(t,e={}){return p(t,{...e,usageHint:"h2"})}function X(t,e={}){return p(t,{...e,usageHint:"h3"})}function W(t,e={}){return p(t,{...e,usageHint:"h4"})}function Y(t,e={}){return p(t,{...e,usageHint:"h5"})}function K(t,e={}){return p(t,{...e,usageHint:"caption"})}function q(t,e={}){return p(t,{...e,usageHint:"body"})}var d="https://a2ui.dev/specification/0.9/standard_catalog_definition.json";var C={};function l(t,e=""){let n=[];for(let[o,a]of Object.entries(t)){let r=e?`${e}/${o}`:`/${o}`;n.push(u(r,a));}return n}function u(t,e){if(e==null)return {key:t,valueString:""};if(typeof e=="string")return {key:t,valueString:e};if(typeof e=="number")return {key:t,valueNumber:e};if(typeof e=="boolean")return {key:t,valueBoolean:e};if(Array.isArray(e))return {key:t,valueMap:e.map((n,o)=>u(String(o),n))};if(typeof e=="object"){let n=[];for(let[o,a]of Object.entries(e))n.push(u(o,a));return {key:t,valueMap:n}}return {key:t,valueString:String(e)}}function x(t,e={}){let n=t.replace(/\./g,"/");n.startsWith("/")||(n=`/${n}`);for(let[o,a]of Object.entries(e)){let r=new RegExp(`^/${o}(/|$)`);r.test(n)&&(n=n.replace(r,`/${a}$1`));}return n}function Q(t,e="",n=C){let o=[];for(let a of t){let r=a.path.startsWith("/")?a.path:`${e}/${a.path}`,s=x(r,n);if(a.value!==null&&typeof a.value=="object"&&!Array.isArray(a.value)){let c=m(a.value,s);o.push(...c);}else o.push(u(s,a.value));}return o}function m(t,e){let n=[];for(let[o,a]of Object.entries(t)){let r=`${e}/${o}`;if(a!==null&&typeof a=="object"&&!Array.isArray(a)){let s=m(a,r);n.push(...s);}else n.push(u(r,a));}return n}function M(t){let e={};for(let n of t){let o=n.key.startsWith("/")?n.key.slice(1):n.key;n.valueString!==void 0?e[o]=n.valueString:n.valueNumber!==void 0?e[o]=n.valueNumber:n.valueBoolean!==void 0?e[o]=n.valueBoolean:n.valueMap!==void 0&&(e[o]=M(n.valueMap));}return e}function O(t,e=d){return {createSurface:{surfaceId:t,catalogId:e}}}function h(t,e){return {updateComponents:{surfaceId:t,components:e}}}function I(t,e,n,o="replace"){return {updateDataModel:{surfaceId:t,...n&&{path:n},op:o,...o!=="remove"&&{value:e}}}}function Z(t){return {deleteSurface:{surfaceId:t}}}function ee(t){let{surfaceId:e,catalogId:n=d,components:o,dataModel:a}=t,r=[O(e,n),h(e,o)];return a&&r.push(I(e,a)),r}function S(t,e="@default",n){return {beginRendering:{surfaceId:e,root:t,...n&&{styles:n}}}}function T(t,e="@default"){return {surfaceUpdate:{surfaceId:e,components:t}}}function y(t,e="@default",n){return {dataModelUpdate:{surfaceId:e,contents:t,...n&&{path:n}}}}function b(t,e="@default"){return y(l(t),e)}function te(t,e,n="@default"){return {dataModelUpdate:{surfaceId:n,path:t,contents:[u("",e)]}}}function ne(t){return {deleteSurface:{surfaceId:t}}}function oe(t){let{rootId:e,components:n,dataModel:o,surfaceId:a="@default",styles:r}=t,s=[T(n,a)];return o&&s.push(b(o,a)),s.push(S(e,a,r)),s}function ae(t){return t.map(e=>JSON.stringify(e)).join(`
|
|
2
|
+
`)}function re(t){return t.split(`
|
|
3
|
+
`).filter(e=>e.trim()).map(e=>JSON.parse(e))}exports.DEFAULT_PATH_MAPPINGS=C;exports.audioPlayer=U;exports.beginRendering=S;exports.body=q;exports.button=f;exports.caption=K;exports.card=_;exports.checkbox=N;exports.choicePicker=$;exports.column=j;exports.createSurface=O;exports.createV08Messages=oe;exports.createV09Messages=ee;exports.dataModelInit=b;exports.dataModelUpdate=y;exports.dateTimeInput=L;exports.deleteSurface=Z;exports.deleteSurfaceV08=ne;exports.divider=B;exports.flattenObjectToValueMap=m;exports.generateId=i;exports.getIdCounter=D;exports.h1=z;exports.h2=J;exports.h3=X;exports.h4=W;exports.h5=Y;exports.icon=P;exports.image=v;exports.jsonlToMessages=re;exports.list=R;exports.messagesToJsonl=ae;exports.modal=H;exports.normalizePath=x;exports.objectToValueMap=l;exports.pathUpdate=te;exports.resetIdCounter=V;exports.row=w;exports.slider=F;exports.surfaceUpdate=T;exports.tabs=k;exports.text=p;exports.textButton=G;exports.textField=E;exports.updateComponents=h;exports.updateDataModel=I;exports.updatesToValueMap=Q;exports.valueMapToObject=M;exports.valueToValueMap=u;exports.video=A;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-nmkVz-tB.cjs';
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, BeginRenderingMessage, ComponentInstanceV08, SurfaceUpdateMessage, ValueMap, DataModelUpdateMessage, DataValue, ServerToClientMessageV08 } from '../types/index.cjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* ID Generator
|
|
@@ -58,13 +59,11 @@ interface ImageOptions extends ComponentOptions {
|
|
|
58
59
|
/**
|
|
59
60
|
* Icon 组件选项
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
-
}
|
|
62
|
+
type IconOptions = ComponentOptions;
|
|
63
63
|
/**
|
|
64
64
|
* Video 组件选项
|
|
65
65
|
*/
|
|
66
|
-
|
|
67
|
-
}
|
|
66
|
+
type VideoOptions = ComponentOptions;
|
|
68
67
|
/**
|
|
69
68
|
* AudioPlayer 组件选项
|
|
70
69
|
*/
|
|
@@ -88,13 +87,11 @@ interface ListOptions extends ComponentOptions {
|
|
|
88
87
|
/**
|
|
89
88
|
* Card 组件选项
|
|
90
89
|
*/
|
|
91
|
-
|
|
92
|
-
}
|
|
90
|
+
type CardOptions = ComponentOptions;
|
|
93
91
|
/**
|
|
94
92
|
* Tabs 组件选项
|
|
95
93
|
*/
|
|
96
|
-
|
|
97
|
-
}
|
|
94
|
+
type TabsOptions = ComponentOptions;
|
|
98
95
|
/**
|
|
99
96
|
* Tab 项目
|
|
100
97
|
*/
|
|
@@ -111,8 +108,7 @@ interface DividerOptions extends ComponentOptions {
|
|
|
111
108
|
/**
|
|
112
109
|
* Modal 组件选项
|
|
113
110
|
*/
|
|
114
|
-
|
|
115
|
-
}
|
|
111
|
+
type ModalOptions = ComponentOptions;
|
|
116
112
|
/**
|
|
117
113
|
* Button 组件选项
|
|
118
114
|
*/
|
|
@@ -122,8 +118,7 @@ interface ButtonOptions extends ComponentOptions {
|
|
|
122
118
|
/**
|
|
123
119
|
* CheckBox 组件选项
|
|
124
120
|
*/
|
|
125
|
-
|
|
126
|
-
}
|
|
121
|
+
type CheckBoxOptions = ComponentOptions;
|
|
127
122
|
/**
|
|
128
123
|
* TextField 组件选项
|
|
129
124
|
*/
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as StringOrPath, B as BooleanOrPath, a as StringArrayOrPath, N as NumberOrPath } from '../primitives-nmkVz-tB.js';
|
|
2
|
+
import { TextComponent, ImageComponent, RowComponent, ListComponent, DividerComponent, TextFieldComponent, ComponentInstance, ChildrenProperty, Action, ChoicePickerComponent, CreateSurfaceMessage, UpdateComponentsMessage, UpdateDataModelMessage, DeleteSurfaceMessage, DataObject, ServerToClientMessageV09, BeginRenderingMessage, ComponentInstanceV08, SurfaceUpdateMessage, ValueMap, DataModelUpdateMessage, DataValue, ServerToClientMessageV08 } from '../types/index.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* ID Generator
|
|
@@ -58,13 +59,11 @@ interface ImageOptions extends ComponentOptions {
|
|
|
58
59
|
/**
|
|
59
60
|
* Icon 组件选项
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
-
}
|
|
62
|
+
type IconOptions = ComponentOptions;
|
|
63
63
|
/**
|
|
64
64
|
* Video 组件选项
|
|
65
65
|
*/
|
|
66
|
-
|
|
67
|
-
}
|
|
66
|
+
type VideoOptions = ComponentOptions;
|
|
68
67
|
/**
|
|
69
68
|
* AudioPlayer 组件选项
|
|
70
69
|
*/
|
|
@@ -88,13 +87,11 @@ interface ListOptions extends ComponentOptions {
|
|
|
88
87
|
/**
|
|
89
88
|
* Card 组件选项
|
|
90
89
|
*/
|
|
91
|
-
|
|
92
|
-
}
|
|
90
|
+
type CardOptions = ComponentOptions;
|
|
93
91
|
/**
|
|
94
92
|
* Tabs 组件选项
|
|
95
93
|
*/
|
|
96
|
-
|
|
97
|
-
}
|
|
94
|
+
type TabsOptions = ComponentOptions;
|
|
98
95
|
/**
|
|
99
96
|
* Tab 项目
|
|
100
97
|
*/
|
|
@@ -111,8 +108,7 @@ interface DividerOptions extends ComponentOptions {
|
|
|
111
108
|
/**
|
|
112
109
|
* Modal 组件选项
|
|
113
110
|
*/
|
|
114
|
-
|
|
115
|
-
}
|
|
111
|
+
type ModalOptions = ComponentOptions;
|
|
116
112
|
/**
|
|
117
113
|
* Button 组件选项
|
|
118
114
|
*/
|
|
@@ -122,8 +118,7 @@ interface ButtonOptions extends ComponentOptions {
|
|
|
122
118
|
/**
|
|
123
119
|
* CheckBox 组件选项
|
|
124
120
|
*/
|
|
125
|
-
|
|
126
|
-
}
|
|
121
|
+
type CheckBoxOptions = ComponentOptions;
|
|
127
122
|
/**
|
|
128
123
|
* TextField 组件选项
|
|
129
124
|
*/
|