@tmorrow/cre8-wc 2.0.3 → 2.0.5
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/a2ui/build-knowledge-graph.py +297 -0
- package/a2ui/catalog +240 -0
- package/a2ui/catalog-kg.json +6704 -0
- package/a2ui/catalog.json +6114 -0
- package/a2ui/catalog.svg +3295 -0
- package/a2ui/demo.html +243 -0
- package/a2ui/examples/card-gallery.json +786 -0
- package/a2ui/examples/dating-grid.json +456 -0
- package/a2ui/examples/llm-observability.json +1719 -0
- package/a2ui/examples/portfolio.json +341 -0
- package/a2ui/generate-catalog.mjs +246 -0
- package/a2ui/index.d.ts +4 -0
- package/a2ui/index.js +2 -0
- package/a2ui/index.ts +12 -0
- package/a2ui/registry.d.ts +3 -0
- package/a2ui/registry.js +166 -0
- package/a2ui/registry.ts +182 -0
- package/a2ui/renderer.d.ts +7 -0
- package/a2ui/renderer.js +108 -0
- package/a2ui/renderer.ts +156 -0
- package/a2ui/smoke-test.mjs +238 -0
- package/a2ui/types.d.ts +75 -0
- package/a2ui/types.js +1 -0
- package/a2ui/types.ts +80 -0
- package/cdn/cre8-wc.esm.js +3057 -2438
- package/cdn/cre8-wc.esm.js.map +1 -1
- package/cdn/cre8-wc.min.js +1801 -1204
- package/cdn/cre8-wc.min.js.map +1 -1
- package/lib/a2ui/index.d.ts +5 -0
- package/lib/a2ui/index.d.ts.map +1 -0
- package/lib/a2ui/index.js +3 -0
- package/lib/a2ui/index.js.map +1 -0
- package/lib/a2ui/registry.d.ts +4 -0
- package/lib/a2ui/registry.d.ts.map +1 -0
- package/lib/a2ui/registry.js +167 -0
- package/lib/a2ui/registry.js.map +1 -0
- package/lib/a2ui/renderer.d.ts +8 -0
- package/lib/a2ui/renderer.d.ts.map +1 -0
- package/lib/a2ui/renderer.js +109 -0
- package/lib/a2ui/renderer.js.map +1 -0
- package/lib/a2ui/types.d.ts +76 -0
- package/lib/a2ui/types.d.ts.map +1 -0
- package/lib/a2ui/types.js +2 -0
- package/lib/a2ui/types.js.map +1 -0
- package/lib/components/accordion/accordion.d.ts +1 -0
- package/lib/components/accordion/accordion.d.ts.map +1 -1
- package/lib/components/accordion/accordion.js +1 -0
- package/lib/components/accordion/accordion.js.map +1 -1
- package/lib/components/accordion-item/accordion-item.d.ts +1 -0
- package/lib/components/accordion-item/accordion-item.d.ts.map +1 -1
- package/lib/components/accordion-item/accordion-item.js +1 -0
- package/lib/components/accordion-item/accordion-item.js.map +1 -1
- package/lib/components/alert/alert.d.ts +6 -0
- package/lib/components/alert/alert.d.ts.map +1 -1
- package/lib/components/alert/alert.js +6 -0
- package/lib/components/alert/alert.js.map +1 -1
- package/lib/components/button/button.d.ts +2 -0
- package/lib/components/button/button.d.ts.map +1 -1
- package/lib/components/button/button.js +2 -0
- package/lib/components/button/button.js.map +1 -1
- package/lib/components/button/button.styles.d.ts.map +1 -1
- package/lib/components/button/button.styles.js +1120 -557
- package/lib/components/button/button.styles.js.map +1 -1
- package/lib/components/button-group/button-group.d.ts +9 -0
- package/lib/components/button-group/button-group.d.ts.map +1 -1
- package/lib/components/button-group/button-group.js +8 -0
- package/lib/components/button-group/button-group.js.map +1 -1
- package/lib/components/button-group/button-group.styles.d.ts.map +1 -1
- package/lib/components/button-group/button-group.styles.js +12 -0
- package/lib/components/button-group/button-group.styles.js.map +1 -1
- package/lib/components/card/card.d.ts +1 -1
- package/lib/components/card/card.d.ts.map +1 -1
- package/lib/components/card/card.js +1 -0
- package/lib/components/card/card.js.map +1 -1
- package/lib/components/card/card.styles.d.ts.map +1 -1
- package/lib/components/card/card.styles.js +8 -0
- package/lib/components/card/card.styles.js.map +1 -1
- package/lib/components/checkbox-field-item/checkbox-field-item.d.ts +6 -0
- package/lib/components/checkbox-field-item/checkbox-field-item.d.ts.map +1 -1
- package/lib/components/checkbox-field-item/checkbox-field-item.js +6 -0
- package/lib/components/checkbox-field-item/checkbox-field-item.js.map +1 -1
- package/lib/components/checkbox-field-item/checkbox-field-item.styles.js +1 -1
- package/lib/components/checkbox-field-item/checkbox-field-item.styles.js.map +1 -1
- package/lib/components/date-picker/date-picker.d.ts +5 -0
- package/lib/components/date-picker/date-picker.d.ts.map +1 -1
- package/lib/components/date-picker/date-picker.js +12 -10
- package/lib/components/date-picker/date-picker.js.map +1 -1
- package/lib/components/dropdown/dropdown.d.ts +2 -0
- package/lib/components/dropdown/dropdown.d.ts.map +1 -1
- package/lib/components/dropdown/dropdown.js +2 -0
- package/lib/components/dropdown/dropdown.js.map +1 -1
- package/lib/components/dropdown-item/dropdown-item.d.ts +8 -0
- package/lib/components/dropdown-item/dropdown-item.d.ts.map +1 -1
- package/lib/components/dropdown-item/dropdown-item.js +15 -2
- package/lib/components/dropdown-item/dropdown-item.js.map +1 -1
- package/lib/components/feature/feature.d.ts +4 -0
- package/lib/components/feature/feature.d.ts.map +1 -1
- package/lib/components/feature/feature.js +4 -1
- package/lib/components/feature/feature.js.map +1 -1
- package/lib/components/field/field.d.ts +2 -0
- package/lib/components/field/field.d.ts.map +1 -1
- package/lib/components/field/field.js +3 -0
- package/lib/components/field/field.js.map +1 -1
- package/lib/components/global-nav-item/global-nav-item.d.ts +2 -0
- package/lib/components/global-nav-item/global-nav-item.d.ts.map +1 -1
- package/lib/components/global-nav-item/global-nav-item.js +2 -0
- package/lib/components/global-nav-item/global-nav-item.js.map +1 -1
- package/lib/components/header/header.d.ts +2 -0
- package/lib/components/header/header.d.ts.map +1 -1
- package/lib/components/header/header.js +2 -0
- package/lib/components/header/header.js.map +1 -1
- package/lib/components/hero/hero.d.ts +4 -0
- package/lib/components/hero/hero.d.ts.map +1 -1
- package/lib/components/hero/hero.js +4 -0
- package/lib/components/hero/hero.js.map +1 -1
- package/lib/components/hero/hero.styles.d.ts.map +1 -1
- package/lib/components/hero/hero.styles.js +13 -0
- package/lib/components/hero/hero.styles.js.map +1 -1
- package/lib/components/icon/icon.d.ts +3 -0
- package/lib/components/icon/icon.d.ts.map +1 -1
- package/lib/components/icon/icon.js +7 -5
- package/lib/components/icon/icon.js.map +1 -1
- package/lib/components/link/link.d.ts +2 -0
- package/lib/components/link/link.d.ts.map +1 -1
- package/lib/components/link/link.js +2 -0
- package/lib/components/link/link.js.map +1 -1
- package/lib/components/link-list-item/link-list-item.d.ts +2 -0
- package/lib/components/link-list-item/link-list-item.d.ts.map +1 -1
- package/lib/components/link-list-item/link-list-item.js +2 -0
- package/lib/components/link-list-item/link-list-item.js.map +1 -1
- package/lib/components/modal/modal.d.ts +4 -0
- package/lib/components/modal/modal.d.ts.map +1 -1
- package/lib/components/modal/modal.js +4 -0
- package/lib/components/modal/modal.js.map +1 -1
- package/lib/components/multi-select/multi-select.d.ts +4 -0
- package/lib/components/multi-select/multi-select.d.ts.map +1 -1
- package/lib/components/multi-select/multi-select.js +5 -2
- package/lib/components/multi-select/multi-select.js.map +1 -1
- package/lib/components/page-header/page-header.d.ts +1 -0
- package/lib/components/page-header/page-header.d.ts.map +1 -1
- package/lib/components/page-header/page-header.js +3 -2
- package/lib/components/page-header/page-header.js.map +1 -1
- package/lib/components/pagination/pagination.d.ts +7 -0
- package/lib/components/pagination/pagination.d.ts.map +1 -1
- package/lib/components/pagination/pagination.js +7 -0
- package/lib/components/pagination/pagination.js.map +1 -1
- package/lib/components/percent-bar/percent-bar.d.ts.map +1 -1
- package/lib/components/percent-bar/percent-bar.js +1 -0
- package/lib/components/percent-bar/percent-bar.js.map +1 -1
- package/lib/components/popover/popover.d.ts +6 -0
- package/lib/components/popover/popover.d.ts.map +1 -1
- package/lib/components/popover/popover.js +7 -1
- package/lib/components/popover/popover.js.map +1 -1
- package/lib/components/primary-nav-item/primary-nav-item.d.ts +2 -0
- package/lib/components/primary-nav-item/primary-nav-item.d.ts.map +1 -1
- package/lib/components/primary-nav-item/primary-nav-item.js +2 -0
- package/lib/components/primary-nav-item/primary-nav-item.js.map +1 -1
- package/lib/components/remove-tag/remove-tag.d.ts +2 -0
- package/lib/components/remove-tag/remove-tag.d.ts.map +1 -1
- package/lib/components/remove-tag/remove-tag.js +3 -1
- package/lib/components/remove-tag/remove-tag.js.map +1 -1
- package/lib/components/section/section.d.ts +1 -0
- package/lib/components/section/section.d.ts.map +1 -1
- package/lib/components/section/section.js +1 -0
- package/lib/components/section/section.js.map +1 -1
- package/lib/components/select/select.d.ts +2 -0
- package/lib/components/select/select.d.ts.map +1 -1
- package/lib/components/select/select.js +5 -1
- package/lib/components/select/select.js.map +1 -1
- package/lib/components/split-button/split-button.d.ts +3 -0
- package/lib/components/split-button/split-button.d.ts.map +1 -1
- package/lib/components/split-button/split-button.js.map +1 -1
- package/lib/components/tab/tab.d.ts +2 -0
- package/lib/components/tab/tab.d.ts.map +1 -1
- package/lib/components/tab/tab.js +2 -0
- package/lib/components/tab/tab.js.map +1 -1
- package/lib/components/table-object/table-object.d.ts +2 -0
- package/lib/components/table-object/table-object.d.ts.map +1 -1
- package/lib/components/table-object/table-object.js +2 -0
- package/lib/components/table-object/table-object.js.map +1 -1
- package/lib/components/table-row/table-row.d.ts +1 -0
- package/lib/components/table-row/table-row.d.ts.map +1 -1
- package/lib/components/table-row/table-row.js +1 -0
- package/lib/components/table-row/table-row.js.map +1 -1
- package/lib/components/tag/tag.d.ts +5 -0
- package/lib/components/tag/tag.d.ts.map +1 -1
- package/lib/components/tag/tag.js +2 -0
- package/lib/components/tag/tag.js.map +1 -1
- package/lib/components/tag-list/tag-list.d.ts +2 -0
- package/lib/components/tag-list/tag-list.d.ts.map +1 -1
- package/lib/components/tag-list/tag-list.js +2 -0
- package/lib/components/tag-list/tag-list.js.map +1 -1
- package/lib/components/text-link/text-link.d.ts +1 -0
- package/lib/components/text-link/text-link.d.ts.map +1 -1
- package/lib/components/text-link/text-link.js +1 -0
- package/lib/components/text-link/text-link.js.map +1 -1
- package/lib/components/tooltip/tooltip.d.ts +6 -0
- package/lib/components/tooltip/tooltip.d.ts.map +1 -1
- package/lib/components/tooltip/tooltip.js +3 -0
- package/lib/components/tooltip/tooltip.js.map +1 -1
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_brand.css +85 -0
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_claude-terracotta.css +1 -0
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_claude-terracotta.module.d.ts +3 -0
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_claude-terracotta.module.d.ts.map +1 -0
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_claude-terracotta.module.js +90 -0
- package/lib/design-tokens/brands/claude-terracotta/css/tokens_claude-terracotta.module.js.map +1 -0
- package/lib/design-tokens/brands/cre8-a2ui/css/tokens_brand.css +1 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_brand.css +87 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_cre8-teal.css +1 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_cre8-teal.module.d.ts +3 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_cre8-teal.module.d.ts.map +1 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_cre8-teal.module.js +90 -0
- package/lib/design-tokens/brands/cre8-teal/css/tokens_cre8-teal.module.js.map +1 -0
- package/lib/scripts/generate-react-manifest.d.ts +20 -0
- package/lib/scripts/generate-react-manifest.d.ts.map +1 -0
- package/lib/scripts/generate-react-manifest.js +154 -0
- package/lib/scripts/generate-react-manifest.js.map +1 -0
- package/mcp-manifest.json +203 -38
- package/package.json +24 -4
- package/react-manifest.json +3594 -0
- package/dist/leaf.png +0 -0
- package/dist/leafDS.png +0 -0
- package/dist/leafLogo.svg +0 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { CatalogComponentDef, CatalogSchema, ComponentSpec, EmittedEvent, EventBinding, PropSchema, RegisteredCatalog, } from './types.js';
|
|
2
|
+
export { registerCatalog, validateSpec } from './registry.js';
|
|
3
|
+
export { render } from './renderer.js';
|
|
4
|
+
export type { RenderOptions } from './renderer.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../a2ui/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../a2ui/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export type {\n CatalogComponentDef,\n CatalogSchema,\n ComponentSpec,\n EmittedEvent,\n EventBinding,\n PropSchema,\n RegisteredCatalog,\n} from './types.js';\nexport { registerCatalog, validateSpec } from './registry.js';\nexport { render } from './renderer.js';\nexport type { RenderOptions } from './renderer.js';\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CatalogSchema, ComponentSpec, RegisteredCatalog } from './types.js';
|
|
2
|
+
export declare function registerCatalog(schema: CatalogSchema): RegisteredCatalog;
|
|
3
|
+
export declare function validateSpec(spec: unknown, catalog: RegisteredCatalog, path?: string): asserts spec is ComponentSpec;
|
|
4
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../a2ui/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAc,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE9F,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,iBAAiB,CAKxE;AA+FD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,IAAI,SAAM,GAAG,OAAO,CAAC,IAAI,IAAI,aAAa,CA+EjH"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export function registerCatalog(schema) {
|
|
2
|
+
const defs = schema.$defs?.components ?? {};
|
|
3
|
+
const components = new Map(Object.entries(defs));
|
|
4
|
+
const id = schema['x-a2ui']?.catalogId ?? schema.$id ?? 'unknown';
|
|
5
|
+
return { id, schema, components };
|
|
6
|
+
}
|
|
7
|
+
function validatePropValue(value, schema, path) {
|
|
8
|
+
if (value === undefined || value === null)
|
|
9
|
+
return;
|
|
10
|
+
if (!schema)
|
|
11
|
+
return;
|
|
12
|
+
if (schema.const !== undefined && value !== schema.const) {
|
|
13
|
+
throw new Error(`${path}: expected const ${JSON.stringify(schema.const)}, got ${JSON.stringify(value)}`);
|
|
14
|
+
}
|
|
15
|
+
if (schema.enum && !schema.enum.includes(value)) {
|
|
16
|
+
const allowed = schema.enum.map((v) => JSON.stringify(v)).join(', ');
|
|
17
|
+
throw new Error(`${path}: value ${JSON.stringify(value)} not in enum [${allowed}]`);
|
|
18
|
+
}
|
|
19
|
+
if (schema.oneOf && schema.oneOf.length) {
|
|
20
|
+
const errors = [];
|
|
21
|
+
for (const branch of schema.oneOf) {
|
|
22
|
+
try {
|
|
23
|
+
validatePropValue(value, branch, path);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
errors.push(e.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`${path}: value ${JSON.stringify(value)} matched none of oneOf branches: ${errors.join(' | ')}`);
|
|
31
|
+
}
|
|
32
|
+
const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
33
|
+
if (types.length && !types.some((t) => matchesType(t, value))) {
|
|
34
|
+
throw new Error(`${path}: expected type ${types.join('|')}, got ${describeType(value)}`);
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(value) && schema.items) {
|
|
37
|
+
value.forEach((item, i) => validatePropValue(item, schema.items, `${path}[${i}]`));
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'object' &&
|
|
40
|
+
value !== null &&
|
|
41
|
+
!Array.isArray(value) &&
|
|
42
|
+
schema.properties) {
|
|
43
|
+
const obj = value;
|
|
44
|
+
if (schema.required) {
|
|
45
|
+
for (const req of schema.required) {
|
|
46
|
+
if (!(req in obj)) {
|
|
47
|
+
throw new Error(`${path}.${req}: required property missing`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const [key, childVal] of Object.entries(obj)) {
|
|
52
|
+
const childSchema = schema.properties[key];
|
|
53
|
+
if (!childSchema) {
|
|
54
|
+
if (schema.additionalProperties === false) {
|
|
55
|
+
throw new Error(`${path}.${key}: unexpected property`);
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
validatePropValue(childVal, childSchema, `${path}.${key}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function matchesType(t, v) {
|
|
64
|
+
switch (t) {
|
|
65
|
+
case 'string':
|
|
66
|
+
return typeof v === 'string';
|
|
67
|
+
case 'number':
|
|
68
|
+
return typeof v === 'number' && Number.isFinite(v);
|
|
69
|
+
case 'integer':
|
|
70
|
+
return typeof v === 'number' && Number.isInteger(v);
|
|
71
|
+
case 'boolean':
|
|
72
|
+
return typeof v === 'boolean';
|
|
73
|
+
case 'array':
|
|
74
|
+
return Array.isArray(v);
|
|
75
|
+
case 'object':
|
|
76
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
77
|
+
case 'null':
|
|
78
|
+
return v === null;
|
|
79
|
+
default:
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function describeType(v) {
|
|
84
|
+
if (v === null)
|
|
85
|
+
return 'null';
|
|
86
|
+
if (Array.isArray(v))
|
|
87
|
+
return 'array';
|
|
88
|
+
return typeof v;
|
|
89
|
+
}
|
|
90
|
+
export function validateSpec(spec, catalog, path = '$') {
|
|
91
|
+
if (!spec || typeof spec !== 'object') {
|
|
92
|
+
throw new Error(`${path}: spec must be an object`);
|
|
93
|
+
}
|
|
94
|
+
const s = spec;
|
|
95
|
+
if (typeof s.component !== 'string') {
|
|
96
|
+
throw new Error(`${path}: spec.component must be a string`);
|
|
97
|
+
}
|
|
98
|
+
if (!catalog.components.has(s.component)) {
|
|
99
|
+
throw new Error(`${path}: component "${s.component}" is not registered in catalog "${catalog.id}"`);
|
|
100
|
+
}
|
|
101
|
+
const def = catalog.components.get(s.component);
|
|
102
|
+
const allowedProps = new Set(Object.keys(def.properties?.props?.properties ?? {}));
|
|
103
|
+
const hasChildren = def.properties?.children !== undefined;
|
|
104
|
+
const allowedSlots = def.properties?.slots
|
|
105
|
+
? new Set(Object.keys(def.properties.slots.properties ?? {}))
|
|
106
|
+
: null;
|
|
107
|
+
if (s.props) {
|
|
108
|
+
if (typeof s.props !== 'object')
|
|
109
|
+
throw new Error(`${path}.props: must be an object`);
|
|
110
|
+
const propDefs = def.properties?.props?.properties ?? {};
|
|
111
|
+
for (const [prop, value] of Object.entries(s.props)) {
|
|
112
|
+
if (!allowedProps.has(prop)) {
|
|
113
|
+
throw new Error(`${path}.props.${prop}: not a declared prop on ${s.component}`);
|
|
114
|
+
}
|
|
115
|
+
validatePropValue(value, propDefs[prop], `${path}.props.${prop}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (s.children !== undefined) {
|
|
119
|
+
if (!hasChildren) {
|
|
120
|
+
throw new Error(`${path}.children: ${s.component} does not accept default children`);
|
|
121
|
+
}
|
|
122
|
+
if (!Array.isArray(s.children))
|
|
123
|
+
throw new Error(`${path}.children: must be an array`);
|
|
124
|
+
s.children.forEach((c, i) => {
|
|
125
|
+
if (typeof c === 'string')
|
|
126
|
+
return;
|
|
127
|
+
validateSpec(c, catalog, `${path}.children[${i}]`);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (s.events !== undefined) {
|
|
131
|
+
if (!s.events || typeof s.events !== 'object' || Array.isArray(s.events)) {
|
|
132
|
+
throw new Error(`${path}.events: must be an object`);
|
|
133
|
+
}
|
|
134
|
+
for (const [evtName, binding] of Object.entries(s.events)) {
|
|
135
|
+
if (typeof binding === 'string')
|
|
136
|
+
continue;
|
|
137
|
+
if (!binding || typeof binding !== 'object') {
|
|
138
|
+
throw new Error(`${path}.events.${evtName}: must be a string or { handler } object`);
|
|
139
|
+
}
|
|
140
|
+
const b = binding;
|
|
141
|
+
if (typeof b.handler !== 'string' || b.handler.length === 0) {
|
|
142
|
+
throw new Error(`${path}.events.${evtName}.handler: must be a non-empty string`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (s.slots !== undefined) {
|
|
147
|
+
if (!allowedSlots) {
|
|
148
|
+
throw new Error(`${path}.slots: ${s.component} does not accept named slots`);
|
|
149
|
+
}
|
|
150
|
+
if (typeof s.slots !== 'object')
|
|
151
|
+
throw new Error(`${path}.slots: must be an object`);
|
|
152
|
+
for (const [slotName, arr] of Object.entries(s.slots)) {
|
|
153
|
+
if (!allowedSlots.has(slotName)) {
|
|
154
|
+
throw new Error(`${path}.slots.${slotName}: not a declared slot on ${s.component}`);
|
|
155
|
+
}
|
|
156
|
+
if (!Array.isArray(arr)) {
|
|
157
|
+
throw new Error(`${path}.slots.${slotName}: must be an array`);
|
|
158
|
+
}
|
|
159
|
+
arr.forEach((c, i) => {
|
|
160
|
+
if (typeof c === 'string')
|
|
161
|
+
return;
|
|
162
|
+
validateSpec(c, catalog, `${path}.slots.${slotName}[${i}]`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
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AC,GAAG,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { CatalogSchema, ComponentSpec, PropSchema, RegisteredCatalog } from './types.js';\n\nexport function registerCatalog(schema: CatalogSchema): RegisteredCatalog {\n const defs = schema.$defs?.components ?? {};\n const components = new Map(Object.entries(defs));\n const id = schema['x-a2ui']?.catalogId ?? schema.$id ?? 'unknown';\n return { id, schema, components };\n}\n\nfunction validatePropValue(value: unknown, schema: PropSchema | undefined, path: string): void {\n if (value === undefined || value === null) return;\n if (!schema) return;\n\n if (schema.const !== undefined && value !== schema.const) {\n throw new Error(\n `${path}: expected const ${JSON.stringify(schema.const)}, got ${JSON.stringify(value)}`\n );\n }\n\n if (schema.enum && !schema.enum.includes(value as string)) {\n const allowed = schema.enum.map((v) => JSON.stringify(v)).join(', ');\n throw new Error(`${path}: value ${JSON.stringify(value)} not in enum [${allowed}]`);\n }\n\n if (schema.oneOf && schema.oneOf.length) {\n const errors: string[] = [];\n for (const branch of schema.oneOf) {\n try {\n validatePropValue(value, branch, path);\n return;\n } catch (e) {\n errors.push((e as Error).message);\n }\n }\n throw new Error(\n `${path}: value ${JSON.stringify(value)} matched none of oneOf branches: ${errors.join(' | ')}`\n );\n }\n\n const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];\n if (types.length && !types.some((t) => matchesType(t, value))) {\n throw new Error(`${path}: expected type ${types.join('|')}, got ${describeType(value)}`);\n }\n\n if (Array.isArray(value) && schema.items) {\n value.forEach((item, i) => validatePropValue(item, schema.items, `${path}[${i}]`));\n }\n\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n schema.properties\n ) {\n const obj = value as Record<string, unknown>;\n if (schema.required) {\n for (const req of schema.required) {\n if (!(req in obj)) {\n throw new Error(`${path}.${req}: required property missing`);\n }\n }\n }\n for (const [key, childVal] of Object.entries(obj)) {\n const childSchema = schema.properties[key];\n if (!childSchema) {\n if (schema.additionalProperties === false) {\n throw new Error(`${path}.${key}: unexpected property`);\n }\n continue;\n }\n validatePropValue(childVal, childSchema, `${path}.${key}`);\n }\n }\n}\n\nfunction matchesType(t: string, v: unknown): boolean {\n switch (t) {\n case 'string':\n return typeof v === 'string';\n case 'number':\n return typeof v === 'number' && Number.isFinite(v);\n case 'integer':\n return typeof v === 'number' && Number.isInteger(v);\n case 'boolean':\n return typeof v === 'boolean';\n case 'array':\n return Array.isArray(v);\n case 'object':\n return typeof v === 'object' && v !== null && !Array.isArray(v);\n case 'null':\n return v === null;\n default:\n return true;\n }\n}\n\nfunction describeType(v: unknown): string {\n if (v === null) return 'null';\n if (Array.isArray(v)) return 'array';\n return typeof v;\n}\n\nexport function validateSpec(spec: unknown, catalog: RegisteredCatalog, path = '$'): asserts spec is ComponentSpec {\n if (!spec || typeof spec !== 'object') {\n throw new Error(`${path}: spec must be an object`);\n }\n const s = spec as Record<string, unknown>;\n if (typeof s.component !== 'string') {\n throw new Error(`${path}: spec.component must be a string`);\n }\n if (!catalog.components.has(s.component)) {\n throw new Error(\n `${path}: component \"${s.component}\" is not registered in catalog \"${catalog.id}\"`\n );\n }\n\n const def = catalog.components.get(s.component)!;\n const allowedProps = new Set(Object.keys(def.properties?.props?.properties ?? {}));\n const hasChildren = def.properties?.children !== undefined;\n const allowedSlots = def.properties?.slots\n ? new Set(Object.keys(def.properties.slots.properties ?? {}))\n : null;\n\n if (s.props) {\n if (typeof s.props !== 'object') throw new Error(`${path}.props: must be an object`);\n const propDefs = def.properties?.props?.properties ?? {};\n for (const [prop, value] of Object.entries(s.props as Record<string, unknown>)) {\n if (!allowedProps.has(prop)) {\n throw new Error(`${path}.props.${prop}: not a declared prop on ${s.component}`);\n }\n validatePropValue(value, propDefs[prop], `${path}.props.${prop}`);\n }\n }\n\n if (s.children !== undefined) {\n if (!hasChildren) {\n throw new Error(`${path}.children: ${s.component} does not accept default children`);\n }\n if (!Array.isArray(s.children)) throw new Error(`${path}.children: must be an array`);\n s.children.forEach((c, i) => {\n if (typeof c === 'string') return;\n validateSpec(c, catalog, `${path}.children[${i}]`);\n });\n }\n\n if (s.events !== undefined) {\n if (!s.events || typeof s.events !== 'object' || Array.isArray(s.events)) {\n throw new Error(`${path}.events: must be an object`);\n }\n for (const [evtName, binding] of Object.entries(s.events as Record<string, unknown>)) {\n if (typeof binding === 'string') continue;\n if (!binding || typeof binding !== 'object') {\n throw new Error(`${path}.events.${evtName}: must be a string or { handler } object`);\n }\n const b = binding as Record<string, unknown>;\n if (typeof b.handler !== 'string' || b.handler.length === 0) {\n throw new Error(`${path}.events.${evtName}.handler: must be a non-empty string`);\n }\n }\n }\n\n if (s.slots !== undefined) {\n if (!allowedSlots) {\n throw new Error(`${path}.slots: ${s.component} does not accept named slots`);\n }\n if (typeof s.slots !== 'object') throw new Error(`${path}.slots: must be an object`);\n for (const [slotName, arr] of Object.entries(s.slots as Record<string, unknown>)) {\n if (!allowedSlots.has(slotName)) {\n throw new Error(\n `${path}.slots.${slotName}: not a declared slot on ${s.component}`\n );\n }\n if (!Array.isArray(arr)) {\n throw new Error(`${path}.slots.${slotName}: must be an array`);\n }\n arr.forEach((c, i) => {\n if (typeof c === 'string') return;\n validateSpec(c, catalog, `${path}.slots.${slotName}[${i}]`);\n });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentSpec, EmittedEvent, RegisteredCatalog } from './types.js';
|
|
2
|
+
export interface RenderOptions {
|
|
3
|
+
root?: HTMLElement;
|
|
4
|
+
doc?: Document;
|
|
5
|
+
onEvent?: (evt: EmittedEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function render(spec: ComponentSpec, catalog: RegisteredCatalog, options?: RenderOptions): HTMLElement;
|
|
8
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../a2ui/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EAGZ,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;CACvC;AAED,wBAAgB,MAAM,CACpB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,aAAkB,GAC1B,WAAW,CAMb"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { validateSpec } from './registry.js';
|
|
2
|
+
export function render(spec, catalog, options = {}) {
|
|
3
|
+
validateSpec(spec, catalog);
|
|
4
|
+
const doc = options.doc ?? document;
|
|
5
|
+
const el = buildElement(spec, catalog, doc, '$', options.onEvent);
|
|
6
|
+
if (options.root)
|
|
7
|
+
options.root.replaceChildren(el);
|
|
8
|
+
return el;
|
|
9
|
+
}
|
|
10
|
+
function buildElement(spec, catalog, doc, path, onEvent) {
|
|
11
|
+
const def = catalog.components.get(spec.component);
|
|
12
|
+
const propDefs = def.properties?.props?.properties ?? {};
|
|
13
|
+
const el = doc.createElement(spec.component);
|
|
14
|
+
if (spec.props) {
|
|
15
|
+
for (const [key, value] of Object.entries(spec.props)) {
|
|
16
|
+
applyProp(el, key, value, propDefs[key]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (spec.events && onEvent) {
|
|
20
|
+
for (const [evtName, binding] of Object.entries(spec.events)) {
|
|
21
|
+
attachEvent(el, spec.component, path, evtName, binding, onEvent);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (spec.children) {
|
|
25
|
+
spec.children.forEach((child, i) => {
|
|
26
|
+
if (typeof child === 'string') {
|
|
27
|
+
el.appendChild(doc.createTextNode(child));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
el.appendChild(buildElement(child, catalog, doc, `${path}.children[${i}]`, onEvent));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (spec.slots) {
|
|
34
|
+
for (const [slotName, children] of Object.entries(spec.slots)) {
|
|
35
|
+
children.forEach((child, i) => {
|
|
36
|
+
if (typeof child === 'string') {
|
|
37
|
+
if (slotName === 'default') {
|
|
38
|
+
el.appendChild(doc.createTextNode(child));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const wrap = doc.createElement('span');
|
|
42
|
+
wrap.setAttribute('slot', slotName);
|
|
43
|
+
wrap.textContent = child;
|
|
44
|
+
el.appendChild(wrap);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const childEl = buildElement(child, catalog, doc, `${path}.slots.${slotName}[${i}]`, onEvent);
|
|
49
|
+
if (slotName !== 'default')
|
|
50
|
+
childEl.setAttribute('slot', slotName);
|
|
51
|
+
el.appendChild(childEl);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return el;
|
|
56
|
+
}
|
|
57
|
+
function attachEvent(el, component, path, eventName, binding, onEvent) {
|
|
58
|
+
const handler = typeof binding === 'string' ? binding : binding.handler;
|
|
59
|
+
const stop = typeof binding === 'object' && binding.stopPropagation === true;
|
|
60
|
+
const prevent = typeof binding === 'object' && binding.preventDefault === true;
|
|
61
|
+
el.addEventListener(eventName, (nativeEvent) => {
|
|
62
|
+
if (stop)
|
|
63
|
+
nativeEvent.stopPropagation();
|
|
64
|
+
if (prevent)
|
|
65
|
+
nativeEvent.preventDefault();
|
|
66
|
+
const detail = 'detail' in nativeEvent
|
|
67
|
+
? nativeEvent.detail
|
|
68
|
+
: undefined;
|
|
69
|
+
onEvent({
|
|
70
|
+
component,
|
|
71
|
+
path,
|
|
72
|
+
event: eventName,
|
|
73
|
+
handler,
|
|
74
|
+
detail,
|
|
75
|
+
nativeEvent,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function applyProp(el, key, value, schema) {
|
|
80
|
+
if (value === undefined || value === null)
|
|
81
|
+
return;
|
|
82
|
+
if (schema?.['x-kind'] === 'property') {
|
|
83
|
+
el[key] = value;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (typeof value === 'boolean') {
|
|
87
|
+
if (value)
|
|
88
|
+
el.setAttribute(key, '');
|
|
89
|
+
else
|
|
90
|
+
el.removeAttribute(key);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {
|
|
94
|
+
el[key] = value;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (schema && isComplexSchema(schema)) {
|
|
98
|
+
el[key] = value;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
el.setAttribute(key, String(value));
|
|
102
|
+
}
|
|
103
|
+
function isComplexSchema(schema) {
|
|
104
|
+
const t = schema.type;
|
|
105
|
+
if (Array.isArray(t))
|
|
106
|
+
return t.some((x) => x === 'object' || x === 'array');
|
|
107
|
+
return t === 'object' || t === 'array';
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../a2ui/renderer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAQ7C,MAAM,UAAU,MAAM,CACpB,IAAmB,EACnB,OAA0B,EAC1B,UAAyB,EAAE;IAE3B,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,QAAQ,CAAC;IACpC,MAAM,EAAE,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,IAAI,OAAO,CAAC,IAAI;QAAE,OAAO,CAAC,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AAE,CAAC,CAAC;;YAC/B,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;QACzE,EAAyC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxD,OAAO;IACT,CAAC;IAED,IAAI,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,EAAyC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxD,OAAO;IACT,CAAC;IAED,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,eAAe,CAAC,MAAkB;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;IACtB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC;IAC5E,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,OAAO,CAAC;AACzC,CAAC","sourcesContent":["import type {\n ComponentSpec,\n EmittedEvent,\n EventBinding,\n PropSchema,\n RegisteredCatalog,\n} from './types.js';\nimport { validateSpec } from './registry.js';\n\nexport interface RenderOptions {\n root?: HTMLElement;\n doc?: Document;\n onEvent?: (evt: EmittedEvent) => void;\n}\n\nexport function render(\n spec: ComponentSpec,\n catalog: RegisteredCatalog,\n options: RenderOptions = {}\n): HTMLElement {\n validateSpec(spec, catalog);\n const doc = options.doc ?? document;\n const el = buildElement(spec, catalog, doc, '$', options.onEvent);\n if (options.root) options.root.replaceChildren(el);\n return el;\n}\n\nfunction buildElement(\n spec: ComponentSpec,\n catalog: RegisteredCatalog,\n doc: Document,\n path: string,\n onEvent?: (evt: EmittedEvent) => void\n): HTMLElement {\n const def = catalog.components.get(spec.component)!;\n const propDefs = def.properties?.props?.properties ?? {};\n const el = doc.createElement(spec.component);\n\n if (spec.props) {\n for (const [key, value] of Object.entries(spec.props)) {\n applyProp(el, key, value, propDefs[key]);\n }\n }\n\n if (spec.events && onEvent) {\n for (const [evtName, binding] of Object.entries(spec.events)) {\n attachEvent(el, spec.component, path, evtName, binding, onEvent);\n }\n }\n\n if (spec.children) {\n spec.children.forEach((child, i) => {\n if (typeof child === 'string') {\n el.appendChild(doc.createTextNode(child));\n return;\n }\n el.appendChild(buildElement(child, catalog, doc, `${path}.children[${i}]`, onEvent));\n });\n }\n\n if (spec.slots) {\n for (const [slotName, children] of Object.entries(spec.slots)) {\n children.forEach((child, i) => {\n if (typeof child === 'string') {\n if (slotName === 'default') {\n el.appendChild(doc.createTextNode(child));\n } else {\n const wrap = doc.createElement('span');\n wrap.setAttribute('slot', slotName);\n wrap.textContent = child;\n el.appendChild(wrap);\n }\n return;\n }\n const childEl = buildElement(\n child,\n catalog,\n doc,\n `${path}.slots.${slotName}[${i}]`,\n onEvent\n );\n if (slotName !== 'default') childEl.setAttribute('slot', slotName);\n el.appendChild(childEl);\n });\n }\n }\n\n return el;\n}\n\nfunction attachEvent(\n el: HTMLElement,\n component: string,\n path: string,\n eventName: string,\n binding: EventBinding,\n onEvent: (evt: EmittedEvent) => void\n): void {\n const handler = typeof binding === 'string' ? binding : binding.handler;\n const stop = typeof binding === 'object' && binding.stopPropagation === true;\n const prevent = typeof binding === 'object' && binding.preventDefault === true;\n\n el.addEventListener(eventName, (nativeEvent) => {\n if (stop) nativeEvent.stopPropagation();\n if (prevent) nativeEvent.preventDefault();\n const detail = 'detail' in nativeEvent\n ? (nativeEvent as CustomEvent).detail\n : undefined;\n onEvent({\n component,\n path,\n event: eventName,\n handler,\n detail,\n nativeEvent,\n });\n });\n}\n\nfunction applyProp(\n el: HTMLElement,\n key: string,\n value: unknown,\n schema: PropSchema | undefined\n): void {\n if (value === undefined || value === null) return;\n\n if (schema?.['x-kind'] === 'property') {\n (el as unknown as Record<string, unknown>)[key] = value;\n return;\n }\n\n if (typeof value === 'boolean') {\n if (value) el.setAttribute(key, '');\n else el.removeAttribute(key);\n return;\n }\n\n if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {\n (el as unknown as Record<string, unknown>)[key] = value;\n return;\n }\n\n if (schema && isComplexSchema(schema)) {\n (el as unknown as Record<string, unknown>)[key] = value;\n return;\n }\n\n el.setAttribute(key, String(value));\n}\n\nfunction isComplexSchema(schema: PropSchema): boolean {\n const t = schema.type;\n if (Array.isArray(t)) return t.some((x) => x === 'object' || x === 'array');\n return t === 'object' || t === 'array';\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type SpecChild = ComponentSpec | string;
|
|
2
|
+
export interface ComponentSpec {
|
|
3
|
+
component: string;
|
|
4
|
+
props?: Record<string, unknown>;
|
|
5
|
+
children?: SpecChild[];
|
|
6
|
+
slots?: Record<string, SpecChild[]>;
|
|
7
|
+
events?: Record<string, EventBinding>;
|
|
8
|
+
}
|
|
9
|
+
export type EventBinding = string | {
|
|
10
|
+
handler: string;
|
|
11
|
+
stopPropagation?: boolean;
|
|
12
|
+
preventDefault?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export interface EmittedEvent {
|
|
15
|
+
component: string;
|
|
16
|
+
path: string;
|
|
17
|
+
event: string;
|
|
18
|
+
handler: string;
|
|
19
|
+
detail: unknown;
|
|
20
|
+
nativeEvent: Event;
|
|
21
|
+
}
|
|
22
|
+
export interface CatalogSchema {
|
|
23
|
+
$id?: string;
|
|
24
|
+
$defs?: {
|
|
25
|
+
components?: Record<string, CatalogComponentDef>;
|
|
26
|
+
};
|
|
27
|
+
'x-a2ui'?: {
|
|
28
|
+
catalogId?: string;
|
|
29
|
+
library?: string;
|
|
30
|
+
libraryVersion?: string;
|
|
31
|
+
tagPrefix?: string;
|
|
32
|
+
framework?: string;
|
|
33
|
+
};
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface CatalogComponentDef {
|
|
37
|
+
title?: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
'x-category'?: string;
|
|
40
|
+
'x-slot-descriptions'?: Record<string, string>;
|
|
41
|
+
'x-events'?: Record<string, {
|
|
42
|
+
detail?: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
properties?: {
|
|
45
|
+
component?: {
|
|
46
|
+
const?: string;
|
|
47
|
+
};
|
|
48
|
+
props?: {
|
|
49
|
+
properties?: Record<string, PropSchema>;
|
|
50
|
+
};
|
|
51
|
+
children?: unknown;
|
|
52
|
+
slots?: {
|
|
53
|
+
properties?: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface PropSchema {
|
|
58
|
+
type?: string | string[];
|
|
59
|
+
enum?: string[];
|
|
60
|
+
const?: unknown;
|
|
61
|
+
default?: unknown;
|
|
62
|
+
description?: string;
|
|
63
|
+
items?: PropSchema;
|
|
64
|
+
properties?: Record<string, PropSchema>;
|
|
65
|
+
required?: string[];
|
|
66
|
+
additionalProperties?: boolean;
|
|
67
|
+
oneOf?: PropSchema[];
|
|
68
|
+
'x-tsType'?: string;
|
|
69
|
+
'x-kind'?: 'attribute' | 'property';
|
|
70
|
+
}
|
|
71
|
+
export interface RegisteredCatalog {
|
|
72
|
+
id: string;
|
|
73
|
+
schema: CatalogSchema;
|
|
74
|
+
components: Map<string, CatalogComponentDef>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../a2ui/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,MAAM,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,C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sourceRoot":"","sources":["../../a2ui/types.ts"],"names":[],"mappings":"","sourcesContent":["export type SpecChild = ComponentSpec | string;\n\nexport interface ComponentSpec {\n component: string;\n props?: Record<string, unknown>;\n children?: SpecChild[];\n slots?: Record<string, SpecChild[]>;\n events?: Record<string, EventBinding>;\n}\n\nexport type EventBinding =\n | string\n | {\n handler: string;\n stopPropagation?: boolean;\n preventDefault?: boolean;\n };\n\nexport interface EmittedEvent {\n component: string;\n path: string;\n event: string;\n handler: string;\n detail: unknown;\n nativeEvent: Event;\n}\n\nexport interface CatalogSchema {\n $id?: string;\n $defs?: {\n components?: Record<string, CatalogComponentDef>;\n };\n 'x-a2ui'?: {\n catalogId?: string;\n library?: string;\n libraryVersion?: string;\n tagPrefix?: string;\n framework?: string;\n };\n [key: string]: unknown;\n}\n\nexport interface CatalogComponentDef {\n title?: string;\n description?: string;\n 'x-category'?: string;\n 'x-slot-descriptions'?: Record<string, string>;\n 'x-events'?: Record<string, { detail?: unknown }>;\n properties?: {\n component?: { const?: string };\n props?: {\n properties?: Record<string, PropSchema>;\n };\n children?: unknown;\n slots?: {\n properties?: Record<string, unknown>;\n };\n };\n}\n\nexport interface PropSchema {\n type?: string | string[];\n enum?: string[];\n const?: unknown;\n default?: unknown;\n description?: string;\n items?: PropSchema;\n properties?: Record<string, PropSchema>;\n required?: string[];\n additionalProperties?: boolean;\n oneOf?: PropSchema[];\n 'x-tsType'?: string;\n 'x-kind'?: 'attribute' | 'property';\n}\n\nexport interface RegisteredCatalog {\n id: string;\n schema: CatalogSchema;\n components: Map<string, CatalogComponentDef>;\n}\n"]}
|
|
@@ -8,6 +8,7 @@ import { Cre8Element } from '../cre8-element';
|
|
|
8
8
|
*
|
|
9
9
|
* Users can select different border types: default (no border), rectangle, rounded bottom, and rounded.
|
|
10
10
|
*
|
|
11
|
+
* @slot - The `cre8-accordion-item` children to group
|
|
11
12
|
*/
|
|
12
13
|
export declare class Cre8Accordion extends Cre8Element {
|
|
13
14
|
static styles: import("lit").CSSResult[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion.d.ts","sourceRoot":"","sources":["../../../components/accordion/accordion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C
|
|
1
|
+
{"version":3,"file":"accordion.d.ts","sourceRoot":"","sources":["../../../components/accordion/accordion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C;;;;;;;;;;GAUG;AAEH,qBAAa,aAAc,SAAQ,WAAW;IAC1C,MAAM,CAAC,MAAM,4BAAY;IAG3B;;;;;;OAMG;IAEC,UAAU,CAAC,EAAE,WAAW,GAAG,gBAAgB,GAAG,SAAS,GAAG,MAAM,CAAC;IAErE;;;;;;OAMG;IAEC,UAAU,CAAC,UAAS;IAExB,iBAAiB,IAAI,IAAI;IAIzB,MAAM;CAeP;AAKD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,aAAa,CAAC;KACjC;CACF;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -17,6 +17,7 @@ import styles from './accordion.styles.js';
|
|
|
17
17
|
*
|
|
18
18
|
* Users can select different border types: default (no border), rectangle, rounded bottom, and rounded.
|
|
19
19
|
*
|
|
20
|
+
* @slot - The `cre8-accordion-item` children to group
|
|
20
21
|
*/
|
|
21
22
|
export class Cre8Accordion extends Cre8Element {
|
|
22
23
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion.js","sourceRoot":"","sources":["../../../components/accordion/accordion.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,GAAI,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,MAAM,MAAM,uBAAuB,CAAC;A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,EAAE,aAAa,CAAC,CAAC;AAC3D,CAAC;AAOD,eAAe,aAAa,CAAC","sourcesContent":["import { html, } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { Cre8Element } from '../cre8-element';\nimport styles from './accordion.styles.js';\n\n/**\n * The component is a vertically stacked list of headers that reveal or hide sections of related content on a page.\n * The header title gives the user a high level overview of the content allowing the user to decide\n * which sections to expand for the information.\n *\n * Accordion contains Accordion Items as children. This component is the wrapper for grouping related accordion items.\n *\n * Users can select different border types: default (no border), rectangle, rounded bottom, and rounded.\n *\n * @slot - The `cre8-accordion-item` children to group\n */\n\nexport class Cre8Accordion extends Cre8Element {\n static styles = [styles];\n\n\n /**\n * borderType\n * @prop {'rectangle' | 'rounded-bottom' | 'rounded' | 'none'}\n *\n * Controls the border and border-radius of the parent container of the slotted accordions.\n *\n */\n @property()\n borderType?: 'rectangle' | 'rounded-bottom' | 'rounded' | 'none';\n\n /**\n *\n * When it is true, the inner dividers are displayed;\n * if it is false, the inner dividers are not displayed\n * @prop {boolean} hasDivider\n *\n */\n @property({ type: Boolean, reflect: true })\n hasDivider? = false;\n\n connectedCallback(): void {\n super.connectedCallback();\n }\n\n render() {\n const componentClassNames = this.componentClassNames('cre8-c-accordion', {\n 'cre8-c-inner-divider': this.hasDivider === true,\n 'cre8-c-accordion--border-none': this.borderType === undefined || this.borderType === 'none',\n 'cre8-c-accordion--border-rectangle': this.borderType === 'rectangle',\n 'cre8-c-accordion--border-rounded-bottom': this.borderType === 'rounded-bottom',\n 'cre8-c-accordion--border-rounded': this.borderType === 'rounded',\n });\n\n return html`\n <div class=\"${componentClassNames}\">\n <slot> </slot>\n </div>\n `;\n }\n}\n\nif (customElements.get('cre8-accordion') === undefined) {\n customElements.define('cre8-accordion', Cre8Accordion);\n}\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cre8-accordion': Cre8Accordion;\n }\n}\n\nexport default Cre8Accordion;\n"]}
|
|
@@ -24,6 +24,7 @@ import '../button/button';
|
|
|
24
24
|
*
|
|
25
25
|
* @slot The body of the accordion item will be any valid html
|
|
26
26
|
* inserted between the cre8-accordion-item opening and closing tags.
|
|
27
|
+
* @slot heading - Custom heading content, used when the `heading` property is not set.
|
|
27
28
|
*
|
|
28
29
|
*
|
|
29
30
|
* @csspart ::part('header') - The container around the interactive header.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AAG1B
|
|
1
|
+
{"version":3,"file":"accordion-item.d.ts","sourceRoot":"","sources":["../../../components/accordion-item/accordion-item.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,qBAAa,iBAAkB,SAAQ,WAAW;IAC9C,MAAM,CAAC,MAAM,4BAAY;IAE3B;;;;;OAKG;IAGC,QAAQ,CAAC,UAAS;IAGtB;;;;;;OAMG;IAEC,eAAe,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;OAOG;IAEC,UAAU,CAAC,EAAE,OAAO,CAAC;IAEzB;;;;;;;OAOG;IAEC,YAAY,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;;OAMG;IAEC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAQ;IAE7B;;;;;;;OAOG;IAGC,iBAAiB,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAEtE;;;;;;OAMG;IAEC,OAAO,EAAG,MAAM,CAAC;IAErB;;;;;;OAMG;IAEC,WAAW,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;;OAOG;IAEH,OAAO,CAAC,aAAa,CAAU;IAE/B;;;;;;OAMG;IAEH,OAAO,CAAC,OAAO,CAAU;IAEzB;;;;;;OAMG;IAGH,OAAO,CAAC,UAAU,CAAC,CAAU;;IASpB,iBAAiB;YASZ,iBAAiB;IAY/B,OAAO,CAAC,oBAAoB;IAmB5B,MAAM;CAsEP;AAKD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,iBAAiB,CAAC;KAC1C;CACF;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -36,6 +36,7 @@ import styles from './accordion-item.styles.js';
|
|
|
36
36
|
*
|
|
37
37
|
* @slot The body of the accordion item will be any valid html
|
|
38
38
|
* inserted between the cre8-accordion-item opening and closing tags.
|
|
39
|
+
* @slot heading - Custom heading content, used when the `heading` property is not set.
|
|
39
40
|
*
|
|
40
41
|
*
|
|
41
42
|
* @csspart ::part('header') - The container around the interactive header.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion-item.js","sourceRoot":"","sources":["../../../components/accordion-item/accordion-item.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAU,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAE,IAAI,GAAI,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,MAAM,MAAM,4BAA4B,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAwHhD;QACI,KAAK,EAAE,CAAC;QAtHZ;;;;;WA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H,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4DAC0C;AAUlE;IADH,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDACN;AAUjB;IADH,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;sDACF;AAWlB;IADP,QAAQ,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;wDACV;AAUvB;IADP,KAAK,EAAE;kDACiB;AAWjB;IADP,KAAK,EAAE;qDACqB;AAyH/B,IAAI,cAAc,CAAC,GAAG,CAAC,qBAAqB,CAAC,KAAK,SAAS,EAAE,CAAC;IAC1D,cAAc,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC;AACpE,CAAC;AAOD,eAAe,iBAAiB,CAAC","sourcesContent":["import svgCaretUp from '@tmorrow/cre8-wc/icons/Caret_Up.svg?raw';\nimport { html, } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { ifDefined } from 'lit-html/directives/if-defined.js';\nimport classnames from 'classnames';\nimport { Cre8Element } from '../cre8-element';\nimport '../icon/icon';\nimport '../button/button';\nimport styles from './accordion-item.styles.js';\n\n/**\n *\n * The accordion item component delivers large amounts of content in a small space\n * through progressive disclosure. That is, the user gets key details about the\n * underlying content and can choose to expand that content within the constraints\n * of the accordion item. Accordion Items work especially well on mobile interfaces or\n * whenever vertical space is at a premium.\n *\n * ## HOW TO USE\n * Avoid “nested” accordion items—that is, collapsible content within collapsible content.\n * This type of pattern goes against UX best practices.\n *\n * The Cre8 accordion item header allows for two sizes:\n * 'sm' [cre8-typography-title-default] or 'lg' [cre8-typography-title-large]\n *\n * A chevron is used to indicate the “expand/collapse” action, though the entire\n * header area is clickable for the same action.\n *\n * **NOTE**: The header of the accordion item uses h tags so be sure to choose the headingTagVariant that\n * fits into the hierarchy of your html page layout. THIS WILL NOT CHANGE THE APPEARANCE OF THE HEADER.\n *\n * @slot The body of the accordion item will be any valid html\n * inserted between the cre8-accordion-item opening and closing tags.\n *\n *\n * @csspart ::part('header') - The container around the interactive header.\n * @csspart ::part('button') - The button containing the header text and the animated icon.\n * @csspart ::part('icon') - The animated icon that revolves on click.\n * @csspart ::part('body') - The container around the expanding body section.\n * @csspart ::part('body-inner') - The container around the slot into which any user provided HTML is inserted.\n *\n */\n\nexport class Cre8AccordionItem extends Cre8Element {\n static styles = [styles];\n\n /**\n *\n * When true, the Accordion Item is opens, when false it closes;\n * @prop {boolean} isActive\n *\n */\n\n @property({ type: Boolean, reflect: true })\n isActive? = false;\n\n\n /**\n *\n * Optional custom id for the accordion item, if one is not set, a random id is generated for you.\n * @prop {string} accordionItemId\n *\n *\n */\n @property({ type: String, reflect: true })\n accordionItemId?: string;\n\n /**\n *\n * Controls the positioning of the dropdown icon in relation to the text, true puts the icon before the text\n * and false/undefined default the icon to the opposite side of the accordion item\n * @prop {boolean} iconBefore\n *\n *\n */\n @property({ type: Boolean, reflect: true })\n iconBefore?: boolean;\n\n /**\n *\n * Controls the appearance of dropdown icon as being an icon-only button. true renders the tertiary variant and\n * false/undefined renders the default secondary appearance.\n * @prop {boolean} tertiaryIcon\n *\n *\n */\n @property({ type: Boolean, reflect: true })\n tertiaryIcon?: boolean;\n\n /**\n *\n * Users can choose between two header sizes: 'sm' [title-default] or 'lg' [title-large].\n * @prop {'sm' | 'lg'} size\n *\n *\n */\n @property({ reflect: true })\n size: 'sm' | 'lg' = 'sm';\n\n /**\n *\n * Purely meant to help the user structure the HTML page hierarchy. Does not change the\n * header size. Defaults to 'h3'\n * @prop {'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'} headingTagVariant\n *\n *\n */\n\n @property({ reflect: true })\n headingTagVariant: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' = 'h3';\n\n /**\n *\n * Controls the text content of the Accordion Item heading.\n * @prop {string} heading\n *\n *\n */\n @property({ type: String })\n heading!: string;\n\n /**\n *\n * Controls whether the header takes on the theme's 'brand-strong' color\n * @prop {boolean} brandHeader\n *\n *\n */\n @property({ type: Boolean })\n brandHeader?: boolean;\n\n /**\n *\n * The aria attribute to which is assigned the id of the details section which is revealed via interaction\n * with the header.\n * @private _ariaControls\n *\n *\n */\n @property({ attribute: 'aria-controls' })\n private _ariaControls!: string;\n\n /**\n *\n * Private internal state which indicates the current _height of the accordion item panel.\n * @private _height\n *\n *\n */\n @state()\n private _height!: string;\n\n /**\n *\n * Private internal state which Indicates if the accordion item panel is completely open.\n * @private _fullyOpen\n *\n *\n */\n\n @state()\n private _fullyOpen?: boolean;\n\n constructor() {\n super();\n const randomId = Math.floor(Math.random() * 900000) + 100000;\n this._ariaControls = `cre8-accordion-item-details-${randomId}`;\n this.accordionItemId = this.accordionItemId ?? `cre8-accordion-item-${randomId}`;\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this._setContentHeight();\n if (this.isActive) {\n this._fullyOpen = true;\n this._setContentHeight();\n }\n }\n\n private async _setContentHeight() {\n await this.updateComplete;\n\n if ((this.isActive && !this._fullyOpen) || (!this.isActive && this._fullyOpen)) {\n this._height = `${this.shadowRoot?.querySelector('.cre8-c-accordion-item__body-inner')?.scrollHeight}px`;\n } else if (this.isActive && this._fullyOpen) {\n this._height = 'auto';\n } else if (!this.isActive && !this._fullyOpen) {\n this._height = '0';\n }\n }\n\n private _toggleAccordionItem() {\n this.isActive = !this.isActive;\n\n if (this.isActive) {\n this._setContentHeight();\n setTimeout(() => {\n this._fullyOpen = true;\n this._setContentHeight();\n }, 350);\n } else {\n this._setContentHeight();\n setTimeout(() => {\n this._fullyOpen = false;\n this._setContentHeight();\n }, 50);\n }\n }\n\n\n render() {\n const componentClassNames = this.componentClassNames('cre8-c-accordion-item', {\n 'cre8-is-active': this.isActive,\n 'cre8-c-accordion-item--icon-before': this.iconBefore,\n 'cre8-c-accordion-item--small': this.size === 'sm',\n 'cre8-c-accordion-item--large': this.size === 'lg',\n });\n\n const buttonClassNames = classnames('cre8-c-accordion-item__button', {\n 'cre8-is-active': this.isActive,\n 'cre8-u-justify-content-start': this.iconBefore,\n 'cre8-brand-color': this.brandHeader === true,\n });\n\n return html` <div id=${this.accordionItemId} class=\"${componentClassNames}\">\n <cre8-heading\n type=${this.size === 'lg' ? 'title-large' : 'title-default'}\n part=\"heading\"\n ?brandColor=${(this.brandHeader)}\n tagVariant=\"${this.headingTagVariant ?? 'h3'}\"\n class=\"cre8-c-accordion-item__header\"\n >\n <button\n class=\"${buttonClassNames}\"\n aria-expanded=\"${ifDefined(this.isActive)}\"\n aria-controls=\"${this._ariaControls}\"\n part=\"button\"\n role=\"button\"\n id=\"${this.id}\"\n @click=${this._toggleAccordionItem}\n >\n ${this.iconBefore\n ? html`\n <div class=\"cre8-c-accordion-item--icon-before-heading-text\">\n <div\n class=${this.tertiaryIcon\n ? 'cre8-c-accordion-item__tertiary-icon cre8-c-accordion-item__icon-before'\n : 'cre8-c-accordion-item__icon cre8-c-accordion-item__icon-before'}\n >\n <cre8-icon rotate=\"180\" svg=${svgCaretUp} aria-hidden=\"true\"></cre8-icon>\n </div>\n ${this.heading ?? html` <slot name=\"heading\"></slot>`}\n </div>\n `\n : html`\n <div class=\"cre8-c-accordion-item--icon-after-heading-text\">\n ${this.heading ?? html` <slot name=\"heading\"></slot>`}\n <div\n class=${this.tertiaryIcon\n ? 'cre8-c-accordion-item__tertiary-icon cre8-c-accordion-item__icon-after'\n : 'cre8-c-accordion-item__icon cre8-c-accordion-item__icon-after'}\n >\n <cre8-icon rotate=\"180\" svg='${svgCaretUp}' aria-hidden=\"true\"></cre8-icon>\n </div>\n </div>`}\n </button>\n </cre8-heading>\n <div\n class=\"cre8-c-accordion-item__body\"\n aria-hidden=\"${!this.isActive}\"\n id=\"${this._ariaControls}\"\n part=\"body\"\n style=${`height: ${this._height}`}\n >\n <div class=\"cre8-c-accordion-item__body-inner\" part=\"body-inner\">\n <slot></slot>\n </div>\n </div>\n </div>`;\n }\n}\n\nif (customElements.get('cre8-accordion-item') === undefined) {\n customElements.define('cre8-accordion-item', Cre8AccordionItem);\n}\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cre8-accordion-item': Cre8AccordionItem;\n }\n}\n\nexport default Cre8AccordionItem;\n"]}
|
|
1
|
+
{"version":3,"file":"accordion-item.js","sourceRoot":"","sources":["../../../components/accordion-item/accordion-item.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAU,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAE,IAAI,GAAI,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,cAAc,CAAC;AACtB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,MAAM,MAAM,4BAA4B,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAwHhD;QACI,KAAK,EAAE,CAAC;QAtHZ;;;;;WAKG;QAGC,aAAQ,GAAI,KAAK,CAAC;QAmCtB;;;;;;WAMG;QAEC,SAAI,GAAgB,IAAI,CAAC;QAE7B;;;;;;;WAOG;QAGC,sBAAiB,GAA4C,IAAI,CAAC;QAwDlE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAC7D,IAAI,CAAC,aAAa,GAAG,+BAA+B,QAAQ,EAAE,CAAC;QAC/D,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,uBAAuB,QAAQ,EAAE,CAAC;IACrF,CAAC;IAEQ,iBAAiB;QACtB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,iBAAiB,EAAE,CAAC;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CAAC","sourcesContent":["import svgCaretUp from '@tmorrow/cre8-wc/icons/Caret_Up.svg?raw';\nimport { html, } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { ifDefined } from 'lit-html/directives/if-defined.js';\nimport classnames from 'classnames';\nimport { Cre8Element } from '../cre8-element';\nimport '../icon/icon';\nimport '../button/button';\nimport styles from './accordion-item.styles.js';\n\n/**\n *\n * The accordion item component delivers large amounts of content in a small space\n * through progressive disclosure. That is, the user gets key details about the\n * underlying content and can choose to expand that content within the constraints\n * of the accordion item. Accordion Items work especially well on mobile interfaces or\n * whenever vertical space is at a premium.\n *\n * ## HOW TO USE\n * Avoid “nested” accordion items—that is, collapsible content within collapsible content.\n * This type of pattern goes against UX best practices.\n *\n * The Cre8 accordion item header allows for two sizes:\n * 'sm' [cre8-typography-title-default] or 'lg' [cre8-typography-title-large]\n *\n * A chevron is used to indicate the “expand/collapse” action, though the entire\n * header area is clickable for the same action.\n *\n * **NOTE**: The header of the accordion item uses h tags so be sure to choose the headingTagVariant that\n * fits into the hierarchy of your html page layout. THIS WILL NOT CHANGE THE APPEARANCE OF THE HEADER.\n *\n * @slot The body of the accordion item will be any valid html\n * inserted between the cre8-accordion-item opening and closing tags.\n * @slot heading - Custom heading content, used when the `heading` property is not set.\n *\n *\n * @csspart ::part('header') - The container around the interactive header.\n * @csspart ::part('button') - The button containing the header text and the animated icon.\n * @csspart ::part('icon') - The animated icon that revolves on click.\n * @csspart ::part('body') - The container around the expanding body section.\n * @csspart ::part('body-inner') - The container around the slot into which any user provided HTML is inserted.\n *\n */\n\nexport class Cre8AccordionItem extends Cre8Element {\n static styles = [styles];\n\n /**\n *\n * When true, the Accordion Item is opens, when false it closes;\n * @prop {boolean} isActive\n *\n */\n\n @property({ type: Boolean, reflect: true })\n isActive? = false;\n\n\n /**\n *\n * Optional custom id for the accordion item, if one is not set, a random id is generated for you.\n * @prop {string} accordionItemId\n *\n *\n */\n @property({ type: String, reflect: true })\n accordionItemId?: string;\n\n /**\n *\n * Controls the positioning of the dropdown icon in relation to the text, true puts the icon before the text\n * and false/undefined default the icon to the opposite side of the accordion item\n * @prop {boolean} iconBefore\n *\n *\n */\n @property({ type: Boolean, reflect: true })\n iconBefore?: boolean;\n\n /**\n *\n * Controls the appearance of dropdown icon as being an icon-only button. true renders the tertiary variant and\n * false/undefined renders the default secondary appearance.\n * @prop {boolean} tertiaryIcon\n *\n *\n */\n @property({ type: Boolean, reflect: true })\n tertiaryIcon?: boolean;\n\n /**\n *\n * Users can choose between two header sizes: 'sm' [title-default] or 'lg' [title-large].\n * @prop {'sm' | 'lg'} size\n *\n *\n */\n @property({ reflect: true })\n size: 'sm' | 'lg' = 'sm';\n\n /**\n *\n * Purely meant to help the user structure the HTML page hierarchy. Does not change the\n * header size. Defaults to 'h3'\n * @prop {'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'} headingTagVariant\n *\n *\n */\n\n @property({ reflect: true })\n headingTagVariant: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' = 'h3';\n\n /**\n *\n * Controls the text content of the Accordion Item heading.\n * @prop {string} heading\n *\n *\n */\n @property({ type: String })\n heading!: string;\n\n /**\n *\n * Controls whether the header takes on the theme's 'brand-strong' color\n * @prop {boolean} brandHeader\n *\n *\n */\n @property({ type: Boolean })\n brandHeader?: boolean;\n\n /**\n *\n * The aria attribute to which is assigned the id of the details section which is revealed via interaction\n * with the header.\n * @private _ariaControls\n *\n *\n */\n @property({ attribute: 'aria-controls' })\n private _ariaControls!: string;\n\n /**\n *\n * Private internal state which indicates the current _height of the accordion item panel.\n * @private _height\n *\n *\n */\n @state()\n private _height!: string;\n\n /**\n *\n * Private internal state which Indicates if the accordion item panel is completely open.\n * @private _fullyOpen\n *\n *\n */\n\n @state()\n private _fullyOpen?: boolean;\n\n constructor() {\n super();\n const randomId = Math.floor(Math.random() * 900000) + 100000;\n this._ariaControls = `cre8-accordion-item-details-${randomId}`;\n this.accordionItemId = this.accordionItemId ?? `cre8-accordion-item-${randomId}`;\n }\n\n override connectedCallback() {\n super.connectedCallback();\n this._setContentHeight();\n if (this.isActive) {\n this._fullyOpen = true;\n this._setContentHeight();\n }\n }\n\n private async _setContentHeight() {\n await this.updateComplete;\n\n if ((this.isActive && !this._fullyOpen) || (!this.isActive && this._fullyOpen)) {\n this._height = `${this.shadowRoot?.querySelector('.cre8-c-accordion-item__body-inner')?.scrollHeight}px`;\n } else if (this.isActive && this._fullyOpen) {\n this._height = 'auto';\n } else if (!this.isActive && !this._fullyOpen) {\n this._height = '0';\n }\n }\n\n private _toggleAccordionItem() {\n this.isActive = !this.isActive;\n\n if (this.isActive) {\n this._setContentHeight();\n setTimeout(() => {\n this._fullyOpen = true;\n this._setContentHeight();\n }, 350);\n } else {\n this._setContentHeight();\n setTimeout(() => {\n this._fullyOpen = false;\n this._setContentHeight();\n }, 50);\n }\n }\n\n\n render() {\n const componentClassNames = this.componentClassNames('cre8-c-accordion-item', {\n 'cre8-is-active': this.isActive,\n 'cre8-c-accordion-item--icon-before': this.iconBefore,\n 'cre8-c-accordion-item--small': this.size === 'sm',\n 'cre8-c-accordion-item--large': this.size === 'lg',\n });\n\n const buttonClassNames = classnames('cre8-c-accordion-item__button', {\n 'cre8-is-active': this.isActive,\n 'cre8-u-justify-content-start': this.iconBefore,\n 'cre8-brand-color': this.brandHeader === true,\n });\n\n return html` <div id=${this.accordionItemId} class=\"${componentClassNames}\">\n <cre8-heading\n type=${this.size === 'lg' ? 'title-large' : 'title-default'}\n part=\"heading\"\n ?brandColor=${(this.brandHeader)}\n tagVariant=\"${this.headingTagVariant ?? 'h3'}\"\n class=\"cre8-c-accordion-item__header\"\n >\n <button\n class=\"${buttonClassNames}\"\n aria-expanded=\"${ifDefined(this.isActive)}\"\n aria-controls=\"${this._ariaControls}\"\n part=\"button\"\n role=\"button\"\n id=\"${this.id}\"\n @click=${this._toggleAccordionItem}\n >\n ${this.iconBefore\n ? html`\n <div class=\"cre8-c-accordion-item--icon-before-heading-text\">\n <div\n class=${this.tertiaryIcon\n ? 'cre8-c-accordion-item__tertiary-icon cre8-c-accordion-item__icon-before'\n : 'cre8-c-accordion-item__icon cre8-c-accordion-item__icon-before'}\n >\n <cre8-icon rotate=\"180\" svg=${svgCaretUp} aria-hidden=\"true\"></cre8-icon>\n </div>\n ${this.heading ?? html` <slot name=\"heading\"></slot>`}\n </div>\n `\n : html`\n <div class=\"cre8-c-accordion-item--icon-after-heading-text\">\n ${this.heading ?? html` <slot name=\"heading\"></slot>`}\n <div\n class=${this.tertiaryIcon\n ? 'cre8-c-accordion-item__tertiary-icon cre8-c-accordion-item__icon-after'\n : 'cre8-c-accordion-item__icon cre8-c-accordion-item__icon-after'}\n >\n <cre8-icon rotate=\"180\" svg='${svgCaretUp}' aria-hidden=\"true\"></cre8-icon>\n </div>\n </div>`}\n </button>\n </cre8-heading>\n <div\n class=\"cre8-c-accordion-item__body\"\n aria-hidden=\"${!this.isActive}\"\n id=\"${this._ariaControls}\"\n part=\"body\"\n style=${`height: ${this._height}`}\n >\n <div class=\"cre8-c-accordion-item__body-inner\" part=\"body-inner\">\n <slot></slot>\n </div>\n </div>\n </div>`;\n }\n}\n\nif (customElements.get('cre8-accordion-item') === undefined) {\n customElements.define('cre8-accordion-item', Cre8AccordionItem);\n}\ndeclare global {\n interface HTMLElementTagNameMap {\n 'cre8-accordion-item': Cre8AccordionItem;\n }\n}\n\nexport default Cre8AccordionItem;\n"]}
|