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,275 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
import { renderIcon } from './icons.js';
|
|
3
|
+
import { Menu, MenuOptions } from './menu.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// Event definitions
|
|
7
|
+
const TRIGGER_EVENTS = [] as const;
|
|
8
|
+
const CALLBACK_EVENTS = ['toggle'] as const;
|
|
9
|
+
|
|
10
|
+
export interface SidebarOptions {
|
|
11
|
+
position?: 'left' | 'right';
|
|
12
|
+
width?: string;
|
|
13
|
+
collapsible?: boolean;
|
|
14
|
+
showToggle?: boolean;
|
|
15
|
+
expandOnHover?: boolean;
|
|
16
|
+
collapsed?: boolean;
|
|
17
|
+
menu?: MenuOptions;
|
|
18
|
+
style?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type SidebarState = {
|
|
23
|
+
position: 'left' | 'right';
|
|
24
|
+
width: string;
|
|
25
|
+
collapsible: boolean;
|
|
26
|
+
showToggle: boolean;
|
|
27
|
+
expandOnHover: boolean;
|
|
28
|
+
collapsed: boolean;
|
|
29
|
+
menu: MenuOptions | null;
|
|
30
|
+
style: string;
|
|
31
|
+
class: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class Sidebar extends BaseComponent<SidebarState> {
|
|
35
|
+
private _sidebar: HTMLElement | null = null;
|
|
36
|
+
private _menu: Menu | null = null;
|
|
37
|
+
|
|
38
|
+
constructor(id: string, options: SidebarOptions = {}) {
|
|
39
|
+
// Restore collapsed state from localStorage if available
|
|
40
|
+
const storageKey = `jux-sidebar-${id}-collapsed`;
|
|
41
|
+
const savedCollapsed = localStorage.getItem(storageKey);
|
|
42
|
+
const initialCollapsed = savedCollapsed !== null ? savedCollapsed === 'true' : (options.collapsed ?? false);
|
|
43
|
+
|
|
44
|
+
super(id, {
|
|
45
|
+
position: options.position ?? 'left',
|
|
46
|
+
width: options.width ?? '',
|
|
47
|
+
collapsible: options.collapsible ?? true,
|
|
48
|
+
showToggle: options.showToggle ?? false,
|
|
49
|
+
expandOnHover: options.expandOnHover ?? false,
|
|
50
|
+
collapsed: initialCollapsed,
|
|
51
|
+
menu: options.menu ?? null,
|
|
52
|
+
style: options.style ?? '',
|
|
53
|
+
class: options.class ?? ''
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Listen for URL changes to update menu active states
|
|
57
|
+
if (typeof window !== 'undefined') {
|
|
58
|
+
window.addEventListener('popstate', () => this.refreshMenu());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected getTriggerEvents(): readonly string[] {
|
|
63
|
+
return TRIGGER_EVENTS;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected getCallbackEvents(): readonly string[] {
|
|
67
|
+
return CALLBACK_EVENTS;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
71
|
+
* FLUENT API
|
|
72
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
73
|
+
|
|
74
|
+
// ✅ Inherited from BaseComponent:
|
|
75
|
+
// - style(), class()
|
|
76
|
+
// - bind(), sync(), renderTo()
|
|
77
|
+
// - addClass(), removeClass(), toggleClass()
|
|
78
|
+
// - visible(), show(), hide()
|
|
79
|
+
// - attr(), attrs(), removeAttr()
|
|
80
|
+
// - disabled(), enable(), disable()
|
|
81
|
+
// - loading(), focus(), blur(), remove()
|
|
82
|
+
|
|
83
|
+
width(value: string): this {
|
|
84
|
+
this.state.width = value;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
position(value: 'left' | 'right'): this {
|
|
89
|
+
this.state.position = value;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
collapsible(value: boolean): this {
|
|
94
|
+
this.state.collapsible = value;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
showToggle(value: boolean): this {
|
|
99
|
+
this.state.showToggle = value;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
expandOnHover(value: boolean): this {
|
|
104
|
+
this.state.expandOnHover = value;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
collapsed(value: boolean): this {
|
|
109
|
+
this.state.collapsed = value;
|
|
110
|
+
this._updateCollapsedState();
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
menu(value: MenuOptions): this {
|
|
115
|
+
this.state.menu = value;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
toggle(): void {
|
|
120
|
+
this.state.collapsed = !this.state.collapsed;
|
|
121
|
+
this._updateCollapsedState();
|
|
122
|
+
|
|
123
|
+
// Save to localStorage
|
|
124
|
+
const storageKey = `jux-sidebar-${this._id}-collapsed`;
|
|
125
|
+
localStorage.setItem(storageKey, String(this.state.collapsed));
|
|
126
|
+
|
|
127
|
+
// 🎯 Fire the toggle callback event
|
|
128
|
+
this._triggerCallback('toggle', this.state.collapsed);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Refresh menu active states (called automatically on URL changes)
|
|
133
|
+
*/
|
|
134
|
+
refreshMenu(): this {
|
|
135
|
+
if (this._menu && this.state.menu) {
|
|
136
|
+
// Re-evaluate and update menu items with current active states
|
|
137
|
+
this._menu.items(this.state.menu.items || []);
|
|
138
|
+
}
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private _updateCollapsedState(): void {
|
|
143
|
+
if (this._sidebar) {
|
|
144
|
+
this._sidebar.classList.toggle('jux-sidebar-collapsed', this.state.collapsed);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
149
|
+
* RENDER
|
|
150
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
151
|
+
|
|
152
|
+
render(targetId?: string): this {
|
|
153
|
+
const container = this._setupContainer(targetId);
|
|
154
|
+
|
|
155
|
+
const { position, collapsed, expandOnHover, menu, style, class: className } = this.state;
|
|
156
|
+
|
|
157
|
+
// Build sidebar element
|
|
158
|
+
const sidebar = document.createElement('aside');
|
|
159
|
+
sidebar.id = this._id;
|
|
160
|
+
if (className) sidebar.className = className;
|
|
161
|
+
if (style) sidebar.setAttribute('style', style);
|
|
162
|
+
|
|
163
|
+
// Apply initial collapsed state
|
|
164
|
+
if (collapsed) {
|
|
165
|
+
sidebar.classList.add('jux-sidebar-collapsed');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Menu container (append first so toggle appears at bottom)
|
|
169
|
+
const menuContainer = document.createElement('div');
|
|
170
|
+
menuContainer.className = 'jux-sidebar-menu';
|
|
171
|
+
menuContainer.id = `${this._id}-menu`;
|
|
172
|
+
sidebar.appendChild(menuContainer);
|
|
173
|
+
|
|
174
|
+
// Toggle button (append last so it appears at bottom)
|
|
175
|
+
if (this.state.collapsible || this.state.showToggle) {
|
|
176
|
+
const toggleBtn = document.createElement('button');
|
|
177
|
+
toggleBtn.className = 'jux-sidebar-toggle';
|
|
178
|
+
toggleBtn.type = 'button';
|
|
179
|
+
|
|
180
|
+
const toggleIcon = document.createElement('span');
|
|
181
|
+
toggleIcon.className = 'jux-sidebar-toggle-icon';
|
|
182
|
+
const chevronIcon = renderIcon(position === 'left' ? '➡️' : '⬅️');
|
|
183
|
+
toggleIcon.appendChild(chevronIcon);
|
|
184
|
+
toggleBtn.appendChild(toggleIcon);
|
|
185
|
+
|
|
186
|
+
if (collapsed) {
|
|
187
|
+
toggleBtn.classList.add('jux-sidebar-toggle-collapsed');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
toggleBtn.addEventListener('click', () => {
|
|
191
|
+
this.toggle();
|
|
192
|
+
toggleBtn.classList.toggle('jux-sidebar-toggle-collapsed', this.state.collapsed);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
sidebar.appendChild(toggleBtn);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Handle expand on hover
|
|
199
|
+
if (expandOnHover) {
|
|
200
|
+
sidebar.addEventListener('mouseenter', () => {
|
|
201
|
+
if (this.state.collapsed) {
|
|
202
|
+
sidebar.classList.add('jux-sidebar-hover-expanded');
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
sidebar.addEventListener('mouseleave', () => {
|
|
207
|
+
if (this.state.collapsed) {
|
|
208
|
+
sidebar.classList.remove('jux-sidebar-hover-expanded');
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Wire events using inherited method
|
|
214
|
+
this._wireStandardEvents(sidebar);
|
|
215
|
+
|
|
216
|
+
// Wire sync bindings for 'collapsed' property
|
|
217
|
+
this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
|
|
218
|
+
if (property === 'collapsed') {
|
|
219
|
+
const transform = toComponent || ((v: any) => v);
|
|
220
|
+
|
|
221
|
+
stateObj.subscribe((val: any) => {
|
|
222
|
+
const transformed = transform(val);
|
|
223
|
+
const isCollapsed = Boolean(transformed);
|
|
224
|
+
this.state.collapsed = isCollapsed;
|
|
225
|
+
this._updateCollapsedState();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else if (property === 'menu') {
|
|
229
|
+
const transform = toComponent || ((v: any) => v);
|
|
230
|
+
|
|
231
|
+
stateObj.subscribe((val: any) => {
|
|
232
|
+
const transformed = transform(val);
|
|
233
|
+
this.state.menu = transformed;
|
|
234
|
+
|
|
235
|
+
// Update menu items if menu instance exists
|
|
236
|
+
if (this._menu) {
|
|
237
|
+
this._menu.items(transformed.items || []);
|
|
238
|
+
|
|
239
|
+
// Re-render the menu
|
|
240
|
+
const menuEl = menuContainer.querySelector(`#${this._id}-menu-instance`);
|
|
241
|
+
if (menuEl) {
|
|
242
|
+
menuEl.remove();
|
|
243
|
+
}
|
|
244
|
+
this._menu.render(`#${menuContainer.id}`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
container.appendChild(sidebar);
|
|
251
|
+
this._sidebar = sidebar;
|
|
252
|
+
|
|
253
|
+
// Create and render menu (after sidebar is in DOM)
|
|
254
|
+
if (menu) {
|
|
255
|
+
this._menu = new Menu(`${this._id}-menu-instance`, {
|
|
256
|
+
...menu,
|
|
257
|
+
orientation: 'vertical'
|
|
258
|
+
});
|
|
259
|
+
this._menu.render(`#${menuContainer.id}`);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Trigger Iconify icon rendering
|
|
263
|
+
requestAnimationFrame(() => {
|
|
264
|
+
if ((window as any).Iconify) {
|
|
265
|
+
(window as any).Iconify.scan();
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function sidebar(id: string, options: SidebarOptions = {}): Sidebar {
|
|
274
|
+
return new Sidebar(id, options);
|
|
275
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style - Inject inline CSS into the document
|
|
3
|
+
* For external stylesheets, use Import component instead
|
|
4
|
+
* Auto-renders when created or modified
|
|
5
|
+
*/
|
|
6
|
+
export declare class Style {
|
|
7
|
+
private _id;
|
|
8
|
+
private css;
|
|
9
|
+
constructor(css: string, id?: string);
|
|
10
|
+
render(): this;
|
|
11
|
+
remove(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function style(css: string, id?: string): Style;
|
|
14
|
+
//# sourceMappingURL=style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;IAMpC,MAAM,IAAI,IAAI;IAcd,MAAM,IAAI,IAAI;CAMf;AAGD,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,CAErD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style - Inject inline CSS into the document
|
|
3
|
+
* For external stylesheets, use Import component instead
|
|
4
|
+
* Auto-renders when created or modified
|
|
5
|
+
*/
|
|
6
|
+
export class Style {
|
|
7
|
+
constructor(css, id) {
|
|
8
|
+
// ID only for deduplication, auto-generate if not provided
|
|
9
|
+
this._id = id || `jux-style-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
10
|
+
this.css = css;
|
|
11
|
+
}
|
|
12
|
+
render() {
|
|
13
|
+
// Check if style with this ID already exists
|
|
14
|
+
if (document.getElementById(this._id)) {
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.id = this._id;
|
|
19
|
+
style.textContent = this.css;
|
|
20
|
+
document.head.appendChild(style);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
remove() {
|
|
24
|
+
const existing = document.getElementById(this._id);
|
|
25
|
+
if (existing) {
|
|
26
|
+
existing.remove();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// ✅ ID is optional
|
|
31
|
+
export function style(css, id) {
|
|
32
|
+
return new Style(css, id);
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style - Inject inline CSS into the document
|
|
3
|
+
* For external stylesheets, use Import component instead
|
|
4
|
+
* Auto-renders when created or modified
|
|
5
|
+
*/
|
|
6
|
+
export class Style {
|
|
7
|
+
private _id: string;
|
|
8
|
+
private css: string;
|
|
9
|
+
|
|
10
|
+
constructor(css: string, id?: string) {
|
|
11
|
+
// ID only for deduplication, auto-generate if not provided
|
|
12
|
+
this._id = id || `jux-style-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
13
|
+
this.css = css;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
render(): this {
|
|
17
|
+
// Check if style with this ID already exists
|
|
18
|
+
if (document.getElementById(this._id)) {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const style = document.createElement('style');
|
|
23
|
+
style.id = this._id;
|
|
24
|
+
style.textContent = this.css;
|
|
25
|
+
document.head.appendChild(style);
|
|
26
|
+
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
remove(): void {
|
|
31
|
+
const existing = document.getElementById(this._id);
|
|
32
|
+
if (existing) {
|
|
33
|
+
existing.remove();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ✅ ID is optional
|
|
39
|
+
export function style(css: string, id?: string): Style {
|
|
40
|
+
return new Style(css, id);
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FormInput, FormInputState } from './base/FormInput.js';
|
|
2
|
+
export interface SwitchOptions {
|
|
3
|
+
checked?: boolean;
|
|
4
|
+
label?: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
name?: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
style?: string;
|
|
10
|
+
class?: string;
|
|
11
|
+
onValidate?: (checked: boolean) => boolean | string;
|
|
12
|
+
}
|
|
13
|
+
interface SwitchState extends FormInputState {
|
|
14
|
+
checked: boolean;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class Switch extends FormInput<SwitchState> {
|
|
18
|
+
constructor(id: string, options?: SwitchOptions);
|
|
19
|
+
protected getTriggerEvents(): readonly string[];
|
|
20
|
+
protected getCallbackEvents(): readonly string[];
|
|
21
|
+
checked(value: boolean): this;
|
|
22
|
+
value(value: string): this;
|
|
23
|
+
toggle(): this;
|
|
24
|
+
getValue(): boolean;
|
|
25
|
+
setValue(value: boolean): this;
|
|
26
|
+
protected _validateValue(checked: boolean): boolean | string;
|
|
27
|
+
protected _buildInputElement(): HTMLElement;
|
|
28
|
+
render(targetId?: string): this;
|
|
29
|
+
}
|
|
30
|
+
export declare function switchComponent(id: string, options?: SwitchOptions): Switch;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMhE,MAAM,WAAW,aAAa;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,MAAM,CAAC;CACvD;AAED,UAAU,WAAY,SAAQ,cAAc;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,MAAO,SAAQ,SAAS,CAAC,WAAW,CAAC;gBAClC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB;IAkBnD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAehD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI7B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B,MAAM,IAAI,IAAI;IAQd,QAAQ,IAAI,OAAO;IAInB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAQ9B,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM;IAiB5D,SAAS,CAAC,kBAAkB,IAAI,WAAW;IAoB3C,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CAiHlC;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAE/E"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { FormInput } from './base/FormInput.js';
|
|
2
|
+
// Event definitions
|
|
3
|
+
const TRIGGER_EVENTS = [];
|
|
4
|
+
const CALLBACK_EVENTS = ['change'];
|
|
5
|
+
export class Switch extends FormInput {
|
|
6
|
+
constructor(id, options = {}) {
|
|
7
|
+
super(id, {
|
|
8
|
+
checked: options.checked ?? false,
|
|
9
|
+
value: options.value ?? 'on',
|
|
10
|
+
label: options.label ?? '',
|
|
11
|
+
required: options.required ?? false,
|
|
12
|
+
disabled: options.disabled ?? false,
|
|
13
|
+
name: options.name ?? id,
|
|
14
|
+
style: options.style ?? '',
|
|
15
|
+
class: options.class ?? '',
|
|
16
|
+
errorMessage: undefined
|
|
17
|
+
});
|
|
18
|
+
if (options.onValidate) {
|
|
19
|
+
this._onValidate = options.onValidate;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getTriggerEvents() {
|
|
23
|
+
return TRIGGER_EVENTS;
|
|
24
|
+
}
|
|
25
|
+
getCallbackEvents() {
|
|
26
|
+
return CALLBACK_EVENTS;
|
|
27
|
+
}
|
|
28
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
29
|
+
* FLUENT API
|
|
30
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
31
|
+
// ✅ Inherited from FormInput/BaseComponent:
|
|
32
|
+
// - label(), required(), name(), onValidate()
|
|
33
|
+
// - validate(), isValid()
|
|
34
|
+
// - style(), class()
|
|
35
|
+
// - bind(), sync(), renderTo()
|
|
36
|
+
// - disabled(), enable(), disable()
|
|
37
|
+
checked(value) {
|
|
38
|
+
return this.setValue(value);
|
|
39
|
+
}
|
|
40
|
+
value(value) {
|
|
41
|
+
this.state.value = value;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
toggle() {
|
|
45
|
+
return this.setValue(!this.state.checked);
|
|
46
|
+
}
|
|
47
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
48
|
+
* FORM INPUT IMPLEMENTATION
|
|
49
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
50
|
+
getValue() {
|
|
51
|
+
return this.state.checked;
|
|
52
|
+
}
|
|
53
|
+
setValue(value) {
|
|
54
|
+
this.state.checked = value;
|
|
55
|
+
if (this._inputElement) {
|
|
56
|
+
this._inputElement.checked = value;
|
|
57
|
+
}
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
_validateValue(checked) {
|
|
61
|
+
const { required } = this.state;
|
|
62
|
+
if (required && !checked) {
|
|
63
|
+
return 'This field must be enabled';
|
|
64
|
+
}
|
|
65
|
+
if (this._onValidate) {
|
|
66
|
+
const result = this._onValidate(checked);
|
|
67
|
+
if (result !== true) {
|
|
68
|
+
return result || 'Invalid value';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
_buildInputElement() {
|
|
74
|
+
const { checked, value, required, disabled, name } = this.state;
|
|
75
|
+
const input = document.createElement('input');
|
|
76
|
+
input.type = 'checkbox';
|
|
77
|
+
input.className = 'jux-switch-input';
|
|
78
|
+
input.id = `${this._id}-input`;
|
|
79
|
+
input.name = name;
|
|
80
|
+
input.value = value;
|
|
81
|
+
input.checked = checked;
|
|
82
|
+
input.required = required;
|
|
83
|
+
input.disabled = disabled;
|
|
84
|
+
return input;
|
|
85
|
+
}
|
|
86
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
87
|
+
* RENDER
|
|
88
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
89
|
+
render(targetId) {
|
|
90
|
+
const container = this._setupContainer(targetId);
|
|
91
|
+
const { style, class: className } = this.state;
|
|
92
|
+
// Build wrapper
|
|
93
|
+
const wrapper = document.createElement('div');
|
|
94
|
+
wrapper.className = 'jux-switch';
|
|
95
|
+
wrapper.id = this._id;
|
|
96
|
+
if (className)
|
|
97
|
+
wrapper.className += ` ${className}`;
|
|
98
|
+
if (style)
|
|
99
|
+
wrapper.setAttribute('style', style);
|
|
100
|
+
// Switch container
|
|
101
|
+
const switchContainer = document.createElement('label');
|
|
102
|
+
switchContainer.className = 'jux-switch-container';
|
|
103
|
+
switchContainer.htmlFor = `${this._id}-input`;
|
|
104
|
+
// Input element
|
|
105
|
+
const inputEl = this._buildInputElement();
|
|
106
|
+
this._inputElement = inputEl;
|
|
107
|
+
switchContainer.appendChild(inputEl);
|
|
108
|
+
// Toggle slider
|
|
109
|
+
const slider = document.createElement('span');
|
|
110
|
+
slider.className = 'jux-switch-slider';
|
|
111
|
+
switchContainer.appendChild(slider);
|
|
112
|
+
// Label text
|
|
113
|
+
if (this.state.label) {
|
|
114
|
+
const labelText = document.createElement('span');
|
|
115
|
+
labelText.className = 'jux-switch-label-text';
|
|
116
|
+
labelText.textContent = this.state.label;
|
|
117
|
+
if (this.state.required) {
|
|
118
|
+
const requiredSpan = document.createElement('span');
|
|
119
|
+
requiredSpan.className = 'jux-input-required';
|
|
120
|
+
requiredSpan.textContent = ' *';
|
|
121
|
+
labelText.appendChild(requiredSpan);
|
|
122
|
+
}
|
|
123
|
+
switchContainer.appendChild(labelText);
|
|
124
|
+
}
|
|
125
|
+
wrapper.appendChild(switchContainer);
|
|
126
|
+
// Error element
|
|
127
|
+
wrapper.appendChild(this._renderError());
|
|
128
|
+
// Wire events
|
|
129
|
+
this._wireStandardEvents(wrapper);
|
|
130
|
+
// Wire switch-specific sync (maps 'checked' to 'value' property for consistency)
|
|
131
|
+
const valueSync = this._syncBindings.find(b => b.property === 'value' || b.property === 'checked');
|
|
132
|
+
if (valueSync) {
|
|
133
|
+
const { stateObj, toState, toComponent } = valueSync;
|
|
134
|
+
const transformToState = toState || ((v) => v);
|
|
135
|
+
const transformToComponent = toComponent || ((v) => Boolean(v));
|
|
136
|
+
let isUpdating = false;
|
|
137
|
+
// State → Component
|
|
138
|
+
stateObj.subscribe((val) => {
|
|
139
|
+
if (isUpdating)
|
|
140
|
+
return;
|
|
141
|
+
const transformed = transformToComponent(val);
|
|
142
|
+
this.setValue(transformed);
|
|
143
|
+
});
|
|
144
|
+
// Component → State
|
|
145
|
+
inputEl.addEventListener('change', () => {
|
|
146
|
+
if (isUpdating)
|
|
147
|
+
return;
|
|
148
|
+
isUpdating = true;
|
|
149
|
+
const checked = inputEl.checked;
|
|
150
|
+
this.state.checked = checked;
|
|
151
|
+
this._clearError();
|
|
152
|
+
const transformed = transformToState(checked);
|
|
153
|
+
stateObj.set(transformed);
|
|
154
|
+
// 🎯 Fire the change callback event
|
|
155
|
+
this._triggerCallback('change', checked);
|
|
156
|
+
setTimeout(() => { isUpdating = false; }, 0);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Default behavior without sync
|
|
161
|
+
inputEl.addEventListener('change', () => {
|
|
162
|
+
this.state.checked = inputEl.checked;
|
|
163
|
+
this._clearError();
|
|
164
|
+
// 🎯 Fire the change callback event
|
|
165
|
+
this._triggerCallback('change', inputEl.checked);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// Always add blur validation
|
|
169
|
+
inputEl.addEventListener('blur', () => {
|
|
170
|
+
this.validate();
|
|
171
|
+
});
|
|
172
|
+
// Sync label changes
|
|
173
|
+
const labelSync = this._syncBindings.find(b => b.property === 'label');
|
|
174
|
+
if (labelSync) {
|
|
175
|
+
const transform = labelSync.toComponent || ((v) => String(v));
|
|
176
|
+
labelSync.stateObj.subscribe((val) => {
|
|
177
|
+
this.label(transform(val));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
container.appendChild(wrapper);
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export function switchComponent(id, options = {}) {
|
|
185
|
+
return new Switch(id, options);
|
|
186
|
+
}
|