juxscript 1.1.4 → 1.1.6
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/index.d.ts +10 -10
- package/index.d.ts.map +1 -0
- package/lib/components/alert.d.ts +32 -0
- package/lib/components/alert.d.ts.map +1 -0
- package/lib/components/alert.js +153 -0
- package/lib/components/alert.ts +200 -0
- package/lib/components/app.d.ts +89 -0
- package/lib/components/app.d.ts.map +1 -0
- package/lib/components/app.js +175 -0
- package/lib/components/app.ts +247 -0
- package/lib/components/badge.d.ts +27 -0
- package/lib/components/badge.d.ts.map +1 -0
- package/lib/components/badge.js +70 -0
- package/lib/components/badge.ts +101 -0
- package/lib/components/base/BaseComponent.d.ts +142 -0
- package/lib/components/base/BaseComponent.d.ts.map +1 -0
- package/lib/components/base/BaseComponent.js +363 -0
- package/lib/components/base/BaseComponent.ts +421 -0
- package/lib/components/base/FormInput.d.ts +73 -0
- package/lib/components/base/FormInput.d.ts.map +1 -0
- package/lib/components/base/FormInput.js +163 -0
- package/lib/components/base/FormInput.ts +227 -0
- package/lib/components/button.d.ts +48 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +121 -0
- package/lib/components/button.ts +178 -0
- package/lib/components/card.d.ts +34 -0
- package/lib/components/card.d.ts.map +1 -0
- package/lib/components/card.js +127 -0
- package/lib/components/card.ts +173 -0
- package/lib/components/chart.d.ts +45 -0
- package/lib/components/chart.d.ts.map +1 -0
- package/lib/components/chart.js +186 -0
- package/lib/components/chart.ts +231 -0
- package/lib/components/checkbox.d.ts +31 -0
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +185 -0
- package/lib/components/checkbox.ts +242 -0
- package/lib/components/code.d.ts +24 -0
- package/lib/components/code.d.ts.map +1 -0
- package/lib/components/code.js +88 -0
- package/lib/components/code.ts +123 -0
- package/lib/components/container.d.ts +42 -0
- package/lib/components/container.d.ts.map +1 -0
- package/lib/components/container.js +93 -0
- package/lib/components/container.ts +140 -0
- package/lib/components/data.d.ts +36 -0
- package/lib/components/data.d.ts.map +1 -0
- package/lib/components/data.js +110 -0
- package/lib/components/data.ts +135 -0
- package/lib/components/datepicker.d.ts +38 -0
- package/lib/components/datepicker.d.ts.map +1 -0
- package/lib/components/datepicker.js +177 -0
- package/lib/components/datepicker.ts +234 -0
- package/lib/components/dialog.d.ts +38 -0
- package/lib/components/dialog.d.ts.map +1 -0
- package/lib/components/dialog.js +126 -0
- package/lib/components/dialog.ts +172 -0
- package/lib/components/divider.d.ts +30 -0
- package/lib/components/divider.d.ts.map +1 -0
- package/lib/components/divider.js +69 -0
- package/lib/components/divider.ts +100 -0
- package/lib/components/dropdown.d.ts +39 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +133 -0
- package/lib/components/dropdown.ts +186 -0
- package/lib/components/element.d.ts +50 -0
- package/lib/components/element.d.ts.map +1 -0
- package/lib/components/element.js +206 -0
- package/lib/components/element.ts +267 -0
- package/lib/components/fileupload.d.ts +40 -0
- package/lib/components/fileupload.d.ts.map +1 -0
- package/lib/components/fileupload.js +241 -0
- package/lib/components/fileupload.ts +309 -0
- package/lib/components/grid.d.ts +87 -0
- package/lib/components/grid.d.ts.map +1 -0
- package/lib/components/grid.js +205 -0
- package/lib/components/grid.ts +291 -0
- package/lib/components/guard.d.ts +41 -0
- package/lib/components/guard.d.ts.map +1 -0
- package/lib/components/guard.js +56 -0
- package/lib/components/guard.ts +92 -0
- package/lib/components/heading.d.ts +24 -0
- package/lib/components/heading.d.ts.map +1 -0
- package/lib/components/heading.js +67 -0
- package/lib/components/heading.ts +96 -0
- package/lib/components/helpers.d.ts +9 -0
- package/lib/components/helpers.d.ts.map +1 -0
- package/lib/components/helpers.js +30 -0
- package/lib/components/helpers.ts +41 -0
- package/lib/components/hero.d.ts +45 -0
- package/lib/components/hero.d.ts.map +1 -0
- package/lib/components/hero.js +165 -0
- package/lib/components/hero.ts +224 -0
- package/lib/components/icon.d.ts +35 -0
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +132 -0
- package/lib/components/icon.ts +178 -0
- package/lib/components/icons.d.ts +25 -0
- package/lib/components/icons.d.ts.map +1 -0
- package/lib/components/icons.js +440 -0
- package/lib/components/icons.ts +464 -0
- package/lib/components/include.d.ts +120 -0
- package/lib/components/include.d.ts.map +1 -0
- package/lib/components/include.js +350 -0
- package/lib/components/include.ts +410 -0
- package/lib/components/input.d.ts +83 -0
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +348 -0
- package/lib/components/input.ts +457 -0
- package/lib/components/list.d.ts +82 -0
- package/lib/components/list.d.ts.map +1 -0
- package/lib/components/list.js +311 -0
- package/lib/components/list.ts +419 -0
- package/lib/components/loading.d.ts +24 -0
- package/lib/components/loading.d.ts.map +1 -0
- package/lib/components/loading.js +73 -0
- package/lib/components/loading.ts +100 -0
- package/lib/components/menu.d.ts +37 -0
- package/lib/components/menu.d.ts.map +1 -0
- package/lib/components/menu.js +202 -0
- package/lib/components/menu.ts +275 -0
- package/lib/components/modal.d.ts +51 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +227 -0
- package/lib/components/modal.ts +284 -0
- package/lib/components/nav.d.ts +45 -0
- package/lib/components/nav.d.ts.map +1 -0
- package/lib/components/nav.js +190 -0
- package/lib/components/nav.ts +257 -0
- package/lib/components/paragraph.d.ts +21 -0
- package/lib/components/paragraph.d.ts.map +1 -0
- package/lib/components/paragraph.js +70 -0
- package/lib/components/paragraph.ts +97 -0
- package/lib/components/progress.d.ts +39 -0
- package/lib/components/progress.d.ts.map +1 -0
- package/lib/components/progress.js +113 -0
- package/lib/components/progress.ts +159 -0
- package/lib/components/radio.d.ts +41 -0
- package/lib/components/radio.d.ts.map +1 -0
- package/lib/components/radio.js +203 -0
- package/lib/components/radio.ts +278 -0
- package/lib/components/req.d.ts +155 -0
- package/lib/components/req.d.ts.map +1 -0
- package/lib/components/req.js +253 -0
- package/lib/components/req.ts +303 -0
- package/lib/components/script.d.ts +14 -0
- package/lib/components/script.d.ts.map +1 -0
- package/lib/components/script.js +33 -0
- package/lib/components/script.ts +41 -0
- package/lib/components/select.d.ts +40 -0
- package/lib/components/select.d.ts.map +1 -0
- package/lib/components/select.js +183 -0
- package/lib/components/select.ts +252 -0
- package/lib/components/sidebar.d.ts +48 -0
- package/lib/components/sidebar.d.ts.map +1 -0
- package/lib/components/sidebar.js +207 -0
- package/lib/components/sidebar.ts +275 -0
- package/lib/components/style.d.ts +14 -0
- package/lib/components/style.d.ts.map +1 -0
- package/lib/components/style.js +33 -0
- package/lib/components/style.ts +41 -0
- package/lib/components/switch.d.ts +32 -0
- package/lib/components/switch.d.ts.map +1 -0
- package/lib/components/switch.js +186 -0
- package/lib/components/switch.ts +246 -0
- package/lib/components/table.d.ts +137 -0
- package/lib/components/table.d.ts.map +1 -0
- package/lib/components/table.js +1045 -0
- package/lib/components/table.ts +1249 -0
- package/lib/components/tabs.d.ts +36 -0
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +198 -0
- package/lib/components/tabs.ts +250 -0
- package/lib/components/theme-toggle.d.ts +44 -0
- package/lib/components/theme-toggle.d.ts.map +1 -0
- package/lib/components/theme-toggle.js +215 -0
- package/lib/components/theme-toggle.ts +293 -0
- package/lib/components/tooltip.d.ts +30 -0
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +109 -0
- package/lib/components/tooltip.ts +144 -0
- package/lib/components/view.d.ts +48 -0
- package/lib/components/view.d.ts.map +1 -0
- package/lib/components/view.js +149 -0
- package/lib/components/view.ts +190 -0
- package/lib/components/write.d.ts +107 -0
- package/lib/components/write.d.ts.map +1 -0
- package/lib/components/write.js +222 -0
- package/lib/components/write.ts +272 -0
- package/lib/layouts/default.css +260 -0
- package/lib/layouts/figma.css +334 -0
- package/lib/reactivity/state.d.ts +36 -0
- package/lib/reactivity/state.d.ts.map +1 -0
- package/lib/reactivity/state.js +67 -0
- package/lib/reactivity/state.ts +78 -0
- package/lib/utils/fetch.d.ts +176 -0
- package/lib/utils/fetch.d.ts.map +1 -0
- package/lib/utils/fetch.js +427 -0
- package/lib/utils/fetch.ts +553 -0
- package/machinery/compiler3.js +78 -0
- package/machinery/doc-generator.js +136 -0
- package/machinery/imports.js +155 -0
- package/machinery/ts-shim.js +46 -0
- package/package.json +9 -15
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
|
|
3
|
+
// Event definitions
|
|
4
|
+
const TRIGGER_EVENTS = [] as const;
|
|
5
|
+
const CALLBACK_EVENTS = ['select'] as const;
|
|
6
|
+
|
|
7
|
+
export interface DropdownItem {
|
|
8
|
+
label?: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
divider?: boolean;
|
|
11
|
+
click?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface DropdownOptions {
|
|
15
|
+
triggerLabel?: string;
|
|
16
|
+
items?: DropdownItem[];
|
|
17
|
+
position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
|
|
18
|
+
style?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type DropdownState = {
|
|
23
|
+
triggerLabel: string;
|
|
24
|
+
items: DropdownItem[];
|
|
25
|
+
position: string;
|
|
26
|
+
open: boolean;
|
|
27
|
+
style: string;
|
|
28
|
+
class: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export class Dropdown extends BaseComponent<DropdownState> {
|
|
32
|
+
private _dropdown: HTMLElement | null = null;
|
|
33
|
+
private _menu: HTMLElement | null = null;
|
|
34
|
+
|
|
35
|
+
constructor(id: string, options: DropdownOptions = {}) {
|
|
36
|
+
super(id, {
|
|
37
|
+
triggerLabel: options.triggerLabel ?? 'Menu',
|
|
38
|
+
items: options.items ?? [],
|
|
39
|
+
position: options.position ?? 'bottom-left',
|
|
40
|
+
open: false,
|
|
41
|
+
style: options.style ?? '',
|
|
42
|
+
class: options.class ?? ''
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected getTriggerEvents(): readonly string[] {
|
|
47
|
+
return TRIGGER_EVENTS;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected getCallbackEvents(): readonly string[] {
|
|
51
|
+
return CALLBACK_EVENTS;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
55
|
+
* FLUENT API
|
|
56
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
57
|
+
|
|
58
|
+
triggerLabel(value: string): this {
|
|
59
|
+
this.state.triggerLabel = value;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
items(value: DropdownItem[]): this {
|
|
64
|
+
this.state.items = value;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
position(value: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'): this {
|
|
69
|
+
this.state.position = value;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
open(): this {
|
|
74
|
+
this.state.open = true;
|
|
75
|
+
if (this._menu) {
|
|
76
|
+
this._menu.style.display = 'block';
|
|
77
|
+
}
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
close(): this {
|
|
82
|
+
this.state.open = false;
|
|
83
|
+
if (this._menu) {
|
|
84
|
+
this._menu.style.display = 'none';
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
toggle(): this {
|
|
90
|
+
return this.state.open ? this.close() : this.open();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
94
|
+
* RENDER
|
|
95
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
96
|
+
|
|
97
|
+
render(targetId?: string): this {
|
|
98
|
+
const container = this._setupContainer(targetId);
|
|
99
|
+
|
|
100
|
+
const { triggerLabel, items, position, style, class: className } = this.state;
|
|
101
|
+
|
|
102
|
+
const wrapper = document.createElement('div');
|
|
103
|
+
wrapper.className = 'jux-dropdown';
|
|
104
|
+
wrapper.id = this._id;
|
|
105
|
+
if (className) wrapper.className += ` ${className}`;
|
|
106
|
+
if (style) wrapper.setAttribute('style', style);
|
|
107
|
+
|
|
108
|
+
// Trigger button
|
|
109
|
+
const triggerBtn = document.createElement('button');
|
|
110
|
+
triggerBtn.className = 'jux-dropdown-trigger';
|
|
111
|
+
triggerBtn.textContent = triggerLabel;
|
|
112
|
+
triggerBtn.type = 'button';
|
|
113
|
+
|
|
114
|
+
// Dropdown menu
|
|
115
|
+
const menu = document.createElement('div');
|
|
116
|
+
menu.className = `jux-dropdown-menu jux-dropdown-${position}`;
|
|
117
|
+
menu.style.display = 'none';
|
|
118
|
+
this._menu = menu;
|
|
119
|
+
|
|
120
|
+
items.forEach(item => {
|
|
121
|
+
if (item.divider) {
|
|
122
|
+
const divider = document.createElement('div');
|
|
123
|
+
divider.className = 'jux-dropdown-divider';
|
|
124
|
+
menu.appendChild(divider);
|
|
125
|
+
} else {
|
|
126
|
+
const menuItem = document.createElement('button');
|
|
127
|
+
menuItem.className = 'jux-dropdown-item';
|
|
128
|
+
menuItem.type = 'button';
|
|
129
|
+
|
|
130
|
+
if (item.icon) {
|
|
131
|
+
const icon = document.createElement('span');
|
|
132
|
+
icon.className = 'jux-dropdown-icon';
|
|
133
|
+
icon.textContent = item.icon;
|
|
134
|
+
menuItem.appendChild(icon);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (item.label) {
|
|
138
|
+
const label = document.createElement('span');
|
|
139
|
+
label.textContent = item.label;
|
|
140
|
+
menuItem.appendChild(label);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
menuItem.addEventListener('click', () => {
|
|
144
|
+
// 🎯 Fire the select callback event
|
|
145
|
+
this._triggerCallback('select', item);
|
|
146
|
+
|
|
147
|
+
// Then fire item-specific click handler
|
|
148
|
+
if (item.click) {
|
|
149
|
+
item.click();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.close();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
menu.appendChild(menuItem);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Toggle on trigger click
|
|
160
|
+
triggerBtn.addEventListener('click', (e) => {
|
|
161
|
+
e.stopPropagation();
|
|
162
|
+
this.toggle();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Close on outside click
|
|
166
|
+
document.addEventListener('click', (e) => {
|
|
167
|
+
if (this._dropdown && !this._dropdown.contains(e.target as Node)) {
|
|
168
|
+
this.close();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
wrapper.appendChild(triggerBtn);
|
|
173
|
+
wrapper.appendChild(menu);
|
|
174
|
+
|
|
175
|
+
this._wireStandardEvents(wrapper);
|
|
176
|
+
|
|
177
|
+
container.appendChild(wrapper);
|
|
178
|
+
this._dropdown = wrapper;
|
|
179
|
+
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function dropdown(id: string, options: DropdownOptions = {}): Dropdown {
|
|
185
|
+
return new Dropdown(id, options);
|
|
186
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
export interface ElementOptions {
|
|
3
|
+
tagType?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
innerHTML?: string;
|
|
7
|
+
attributes?: Record<string, string>;
|
|
8
|
+
styles?: Record<string, string>;
|
|
9
|
+
style?: string;
|
|
10
|
+
class?: string;
|
|
11
|
+
}
|
|
12
|
+
type ElementState = {
|
|
13
|
+
tagType: string;
|
|
14
|
+
className: string;
|
|
15
|
+
text: string;
|
|
16
|
+
innerHTML: string;
|
|
17
|
+
attributes: Record<string, string>;
|
|
18
|
+
styles: Record<string, string>;
|
|
19
|
+
style: string;
|
|
20
|
+
class: string;
|
|
21
|
+
};
|
|
22
|
+
export declare class Element extends BaseComponent<ElementState> {
|
|
23
|
+
private _element;
|
|
24
|
+
constructor(id: string, options?: ElementOptions);
|
|
25
|
+
protected getTriggerEvents(): readonly string[];
|
|
26
|
+
protected getCallbackEvents(): readonly string[];
|
|
27
|
+
tagType(value: string): Element;
|
|
28
|
+
className(value: string): Element;
|
|
29
|
+
text(value: string): Element;
|
|
30
|
+
innerHTML(value: string): Element;
|
|
31
|
+
write(content: string, asHTML?: boolean, newLine?: boolean): Element;
|
|
32
|
+
prepend(content: string, asHTML?: boolean, newLine?: boolean): Element;
|
|
33
|
+
clear(): Element;
|
|
34
|
+
/**
|
|
35
|
+
* Append child component or HTML element
|
|
36
|
+
*/
|
|
37
|
+
append(child: any): Element;
|
|
38
|
+
render(targetId?: string): this;
|
|
39
|
+
}
|
|
40
|
+
export declare function element(id: string, options?: ElementOptions): Element;
|
|
41
|
+
export declare function header(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
42
|
+
export declare function footer(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
43
|
+
export declare function main(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
44
|
+
export declare function aside(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
45
|
+
export declare function section(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
46
|
+
export declare function article(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
47
|
+
export declare function div(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
48
|
+
export declare function span(id: string, options?: Omit<ElementOptions, 'tagType'>): Element;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.ts"],"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EtF;AAED,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAM,GAAG,OAAO,CAEvF"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
// Event definitions
|
|
3
|
+
const TRIGGER_EVENTS = []; // Element has no trigger events
|
|
4
|
+
const CALLBACK_EVENTS = []; // Element has no callback events
|
|
5
|
+
export class Element extends BaseComponent {
|
|
6
|
+
constructor(id, options = {}) {
|
|
7
|
+
super(id, {
|
|
8
|
+
tagType: options.tagType ?? 'div',
|
|
9
|
+
className: options.className ?? '',
|
|
10
|
+
text: options.text ?? '',
|
|
11
|
+
innerHTML: options.innerHTML ?? '',
|
|
12
|
+
attributes: options.attributes ?? {},
|
|
13
|
+
styles: options.styles ?? {},
|
|
14
|
+
style: options.style ?? '',
|
|
15
|
+
class: options.class ?? ''
|
|
16
|
+
});
|
|
17
|
+
this._element = null;
|
|
18
|
+
}
|
|
19
|
+
getTriggerEvents() {
|
|
20
|
+
return TRIGGER_EVENTS;
|
|
21
|
+
}
|
|
22
|
+
getCallbackEvents() {
|
|
23
|
+
return CALLBACK_EVENTS;
|
|
24
|
+
}
|
|
25
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
26
|
+
* FLUENT API
|
|
27
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
28
|
+
// ✅ Inherited from BaseComponent:
|
|
29
|
+
// - style(), class()
|
|
30
|
+
// - addClass(), removeClass(), toggleClass()
|
|
31
|
+
// - visible(), show(), hide(), toggleVisibility()
|
|
32
|
+
// - attr(), attrs(), removeAttr()
|
|
33
|
+
// - disabled(), enable(), disable()
|
|
34
|
+
// - loading()
|
|
35
|
+
// - focus(), blur()
|
|
36
|
+
// - remove()
|
|
37
|
+
// - bind(), sync(), renderTo()
|
|
38
|
+
tagType(value) {
|
|
39
|
+
this.state.tagType = value;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
className(value) {
|
|
43
|
+
this.state.className = value;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
text(value) {
|
|
47
|
+
this.state.text = value;
|
|
48
|
+
this.state.innerHTML = '';
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
innerHTML(value) {
|
|
52
|
+
this.state.innerHTML = value;
|
|
53
|
+
this.state.text = '';
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
write(content, asHTML = false, newLine = false) {
|
|
57
|
+
if (!this._element) {
|
|
58
|
+
console.warn(`Element.write: Element "${this._id}" not yet rendered`);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
const contentWithBreak = newLine ? (asHTML ? content + '<br>' : content + '\n') : content;
|
|
62
|
+
if (asHTML) {
|
|
63
|
+
this._element.insertAdjacentHTML('beforeend', contentWithBreak);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const textNode = document.createTextNode(contentWithBreak);
|
|
67
|
+
this._element.appendChild(textNode);
|
|
68
|
+
}
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
prepend(content, asHTML = false, newLine = false) {
|
|
72
|
+
if (!this._element) {
|
|
73
|
+
console.warn(`Element.prepend: Element "${this._id}" not yet rendered`);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
const contentWithBreak = newLine ? (asHTML ? content + '<br>' : content + '\n') : content;
|
|
77
|
+
if (asHTML) {
|
|
78
|
+
this._element.insertAdjacentHTML('afterbegin', contentWithBreak);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const textNode = document.createTextNode(contentWithBreak);
|
|
82
|
+
this._element.insertBefore(textNode, this._element.firstChild);
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
clear() {
|
|
87
|
+
if (!this._element) {
|
|
88
|
+
console.warn(`Element.clear: Element "${this._id}" not yet rendered`);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
this._element.innerHTML = '';
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Append child component or HTML element
|
|
96
|
+
*/
|
|
97
|
+
append(child) {
|
|
98
|
+
if (!this._element) {
|
|
99
|
+
console.warn(`Element.append: Element "${this._id}" not yet rendered`);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
if (child instanceof HTMLElement) {
|
|
103
|
+
this._element.appendChild(child);
|
|
104
|
+
}
|
|
105
|
+
else if (child?._element) {
|
|
106
|
+
// Another Jux component
|
|
107
|
+
this._element.appendChild(child._element);
|
|
108
|
+
}
|
|
109
|
+
else if (typeof child === 'string') {
|
|
110
|
+
const div = document.createElement('div');
|
|
111
|
+
div.innerHTML = child;
|
|
112
|
+
this._element.appendChild(div.firstChild || div);
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
render(targetId) {
|
|
117
|
+
const container = this._setupContainer(targetId);
|
|
118
|
+
const { tagType, className, text, innerHTML, attributes, styles, style, class: classValue } = this.state;
|
|
119
|
+
// Build element
|
|
120
|
+
const element = document.createElement(tagType);
|
|
121
|
+
element.id = this._id;
|
|
122
|
+
if (className)
|
|
123
|
+
element.className = className;
|
|
124
|
+
if (classValue)
|
|
125
|
+
element.className = `${element.className} ${classValue}`.trim();
|
|
126
|
+
if (text) {
|
|
127
|
+
element.textContent = text;
|
|
128
|
+
}
|
|
129
|
+
else if (innerHTML) {
|
|
130
|
+
element.innerHTML = innerHTML;
|
|
131
|
+
}
|
|
132
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
133
|
+
element.setAttribute(key, value);
|
|
134
|
+
});
|
|
135
|
+
const styleString = Object.entries(styles)
|
|
136
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
137
|
+
.join('; ');
|
|
138
|
+
if (styleString || style) {
|
|
139
|
+
element.setAttribute('style', `${styleString}; ${style}`.trim());
|
|
140
|
+
}
|
|
141
|
+
// Wire events using inherited method
|
|
142
|
+
this._wireStandardEvents(element);
|
|
143
|
+
// Wire sync bindings
|
|
144
|
+
this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
|
|
145
|
+
const transform = toComponent || ((v) => v);
|
|
146
|
+
stateObj.subscribe((val) => {
|
|
147
|
+
const transformed = transform(val);
|
|
148
|
+
if (property === 'text') {
|
|
149
|
+
element.textContent = String(transformed);
|
|
150
|
+
this.state.text = String(transformed);
|
|
151
|
+
}
|
|
152
|
+
else if (property === 'innerHTML') {
|
|
153
|
+
element.innerHTML = String(transformed);
|
|
154
|
+
this.state.innerHTML = String(transformed);
|
|
155
|
+
}
|
|
156
|
+
else if (property === 'class') {
|
|
157
|
+
element.className = String(transformed);
|
|
158
|
+
this.state.class = String(transformed);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
container.appendChild(element);
|
|
163
|
+
this._element = element;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export function element(id, options = {}) {
|
|
168
|
+
return new Element(id, options);
|
|
169
|
+
}
|
|
170
|
+
// Semantic HTML element factories with default classes
|
|
171
|
+
export function header(id, options = {}) {
|
|
172
|
+
const defaultClass = 'jux-header';
|
|
173
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
174
|
+
return new Element(id, { ...options, tagType: 'header', class: mergedClass });
|
|
175
|
+
}
|
|
176
|
+
export function footer(id, options = {}) {
|
|
177
|
+
const defaultClass = 'jux-footer';
|
|
178
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
179
|
+
return new Element(id, { ...options, tagType: 'footer', class: mergedClass });
|
|
180
|
+
}
|
|
181
|
+
export function main(id, options = {}) {
|
|
182
|
+
const defaultClass = 'jux-main';
|
|
183
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
184
|
+
return new Element(id, { ...options, tagType: 'main', class: mergedClass });
|
|
185
|
+
}
|
|
186
|
+
export function aside(id, options = {}) {
|
|
187
|
+
const defaultClass = 'jux-aside';
|
|
188
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
189
|
+
return new Element(id, { ...options, tagType: 'aside', class: mergedClass });
|
|
190
|
+
}
|
|
191
|
+
export function section(id, options = {}) {
|
|
192
|
+
const defaultClass = 'jux-section';
|
|
193
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
194
|
+
return new Element(id, { ...options, tagType: 'section', class: mergedClass });
|
|
195
|
+
}
|
|
196
|
+
export function article(id, options = {}) {
|
|
197
|
+
const defaultClass = 'jux-article';
|
|
198
|
+
const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
|
|
199
|
+
return new Element(id, { ...options, tagType: 'article', class: mergedClass });
|
|
200
|
+
}
|
|
201
|
+
export function div(id, options = {}) {
|
|
202
|
+
return new Element(id, { ...options, tagType: 'div' });
|
|
203
|
+
}
|
|
204
|
+
export function span(id, options = {}) {
|
|
205
|
+
return new Element(id, { ...options, tagType: 'span' });
|
|
206
|
+
}
|