juxscript 1.0.32 → 1.0.34
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/lib/components/list.ts +16 -6
- package/package.json +1 -1
- package/presets/default/layout.jux +2 -1
package/lib/components/list.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface ListItem {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface ListOptions {
|
|
22
|
-
items?: ListItem[];
|
|
22
|
+
items?: (ListItem | string)[]; // ✅ Allow string or ListItem
|
|
23
23
|
header?: string;
|
|
24
24
|
gap?: string;
|
|
25
25
|
direction?: 'vertical' | 'horizontal';
|
|
@@ -62,8 +62,13 @@ export class List extends BaseComponent<ListState> {
|
|
|
62
62
|
private _listElement: HTMLElement | null = null;
|
|
63
63
|
|
|
64
64
|
constructor(id: string, options: ListOptions = {}) {
|
|
65
|
+
// ✅ Normalize items - convert strings to ListItem objects
|
|
66
|
+
const normalizedItems = (options.items ?? []).map(item =>
|
|
67
|
+
typeof item === 'string' ? { title: item } : item
|
|
68
|
+
);
|
|
69
|
+
|
|
65
70
|
super(id, {
|
|
66
|
-
items:
|
|
71
|
+
items: normalizedItems,
|
|
67
72
|
header: options.header ?? '',
|
|
68
73
|
gap: options.gap ?? '0.5rem',
|
|
69
74
|
direction: options.direction ?? 'vertical',
|
|
@@ -98,14 +103,19 @@ export class List extends BaseComponent<ListState> {
|
|
|
98
103
|
|
|
99
104
|
// ✅ Inherited from BaseComponent
|
|
100
105
|
|
|
101
|
-
items(value: ListItem[]): this {
|
|
102
|
-
|
|
106
|
+
items(value: (ListItem | string)[]): this {
|
|
107
|
+
// ✅ Normalize items when setting via fluent API
|
|
108
|
+
this.state.items = value.map(item =>
|
|
109
|
+
typeof item === 'string' ? { title: item } : item
|
|
110
|
+
);
|
|
103
111
|
this._updateList();
|
|
104
112
|
return this;
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
addItem(value: ListItem): this {
|
|
108
|
-
|
|
115
|
+
addItem(value: ListItem | string): this {
|
|
116
|
+
// ✅ Normalize single item
|
|
117
|
+
const normalizedItem = typeof value === 'string' ? { title: value } : value;
|
|
118
|
+
this.state.items = [...this.state.items, normalizedItem];
|
|
109
119
|
this._updateList();
|
|
110
120
|
return this;
|
|
111
121
|
}
|
package/package.json
CHANGED