juxscript 1.1.2 → 1.1.4
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/machinery/build3.js +7 -91
- package/machinery/compiler3.js +3 -209
- package/machinery/config.js +93 -6
- package/machinery/serve.js +255 -0
- package/machinery/watcher.js +49 -161
- package/package.json +19 -5
- package/lib/components/alert.ts +0 -200
- package/lib/components/app.ts +0 -247
- package/lib/components/badge.ts +0 -101
- package/lib/components/base/BaseComponent.ts +0 -421
- package/lib/components/base/FormInput.ts +0 -227
- package/lib/components/button.ts +0 -178
- package/lib/components/card.ts +0 -173
- package/lib/components/chart.ts +0 -231
- package/lib/components/checkbox.ts +0 -242
- package/lib/components/code.ts +0 -123
- package/lib/components/container.ts +0 -140
- package/lib/components/data.ts +0 -135
- package/lib/components/datepicker.ts +0 -234
- package/lib/components/dialog.ts +0 -172
- package/lib/components/divider.ts +0 -100
- package/lib/components/dropdown.ts +0 -186
- package/lib/components/element.ts +0 -267
- package/lib/components/fileupload.ts +0 -309
- package/lib/components/grid.ts +0 -291
- package/lib/components/guard.ts +0 -92
- package/lib/components/heading.ts +0 -96
- package/lib/components/helpers.ts +0 -41
- package/lib/components/hero.ts +0 -224
- package/lib/components/icon.ts +0 -178
- package/lib/components/icons.ts +0 -464
- package/lib/components/include.ts +0 -410
- package/lib/components/input.ts +0 -457
- package/lib/components/list.ts +0 -419
- package/lib/components/loading.ts +0 -100
- package/lib/components/menu.ts +0 -275
- package/lib/components/modal.ts +0 -284
- package/lib/components/nav.ts +0 -257
- package/lib/components/paragraph.ts +0 -97
- package/lib/components/progress.ts +0 -159
- package/lib/components/radio.ts +0 -278
- package/lib/components/req.ts +0 -303
- package/lib/components/script.ts +0 -41
- package/lib/components/select.ts +0 -252
- package/lib/components/sidebar.ts +0 -275
- package/lib/components/style.ts +0 -41
- package/lib/components/switch.ts +0 -246
- package/lib/components/table.ts +0 -1249
- package/lib/components/tabs.ts +0 -250
- package/lib/components/theme-toggle.ts +0 -293
- package/lib/components/tooltip.ts +0 -144
- package/lib/components/view.ts +0 -190
- package/lib/components/write.ts +0 -272
- package/lib/layouts/default.css +0 -260
- package/lib/layouts/figma.css +0 -334
- package/lib/reactivity/state.ts +0 -78
- package/lib/utils/fetch.ts +0 -553
- package/machinery/ast.js +0 -347
- package/machinery/build.js +0 -466
- package/machinery/bundleAssets.js +0 -0
- package/machinery/bundleJux.js +0 -0
- package/machinery/bundleVendors.js +0 -0
- package/machinery/doc-generator.js +0 -136
- package/machinery/imports.js +0 -155
- package/machinery/server.js +0 -166
- package/machinery/ts-shim.js +0 -46
- package/machinery/validators/file-validator.js +0 -123
package/lib/components/switch.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { FormInput, FormInputState } from './base/FormInput.js';
|
|
2
|
-
|
|
3
|
-
// Event definitions
|
|
4
|
-
const TRIGGER_EVENTS = [] as const;
|
|
5
|
-
const CALLBACK_EVENTS = ['change'] as const;
|
|
6
|
-
|
|
7
|
-
export interface SwitchOptions {
|
|
8
|
-
checked?: boolean;
|
|
9
|
-
label?: string;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
name?: string;
|
|
13
|
-
value?: string;
|
|
14
|
-
style?: string;
|
|
15
|
-
class?: string;
|
|
16
|
-
onValidate?: (checked: boolean) => boolean | string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface SwitchState extends FormInputState {
|
|
20
|
-
checked: boolean;
|
|
21
|
-
value: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class Switch extends FormInput<SwitchState> {
|
|
25
|
-
constructor(id: string, options: SwitchOptions = {}) {
|
|
26
|
-
super(id, {
|
|
27
|
-
checked: options.checked ?? false,
|
|
28
|
-
value: options.value ?? 'on',
|
|
29
|
-
label: options.label ?? '',
|
|
30
|
-
required: options.required ?? false,
|
|
31
|
-
disabled: options.disabled ?? false,
|
|
32
|
-
name: options.name ?? id,
|
|
33
|
-
style: options.style ?? '',
|
|
34
|
-
class: options.class ?? '',
|
|
35
|
-
errorMessage: undefined
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (options.onValidate) {
|
|
39
|
-
this._onValidate = options.onValidate;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
protected getTriggerEvents(): readonly string[] {
|
|
44
|
-
return TRIGGER_EVENTS;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected getCallbackEvents(): readonly string[] {
|
|
48
|
-
return CALLBACK_EVENTS;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
52
|
-
* FLUENT API
|
|
53
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
54
|
-
|
|
55
|
-
// ✅ Inherited from FormInput/BaseComponent:
|
|
56
|
-
// - label(), required(), name(), onValidate()
|
|
57
|
-
// - validate(), isValid()
|
|
58
|
-
// - style(), class()
|
|
59
|
-
// - bind(), sync(), renderTo()
|
|
60
|
-
// - disabled(), enable(), disable()
|
|
61
|
-
|
|
62
|
-
checked(value: boolean): this {
|
|
63
|
-
return this.setValue(value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
value(value: string): this {
|
|
67
|
-
this.state.value = value;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
toggle(): this {
|
|
72
|
-
return this.setValue(!this.state.checked);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
76
|
-
* FORM INPUT IMPLEMENTATION
|
|
77
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
78
|
-
|
|
79
|
-
getValue(): boolean {
|
|
80
|
-
return this.state.checked;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
setValue(value: boolean): this {
|
|
84
|
-
this.state.checked = value;
|
|
85
|
-
if (this._inputElement) {
|
|
86
|
-
(this._inputElement as HTMLInputElement).checked = value;
|
|
87
|
-
}
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
protected _validateValue(checked: boolean): boolean | string {
|
|
92
|
-
const { required } = this.state;
|
|
93
|
-
|
|
94
|
-
if (required && !checked) {
|
|
95
|
-
return 'This field must be enabled';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (this._onValidate) {
|
|
99
|
-
const result = this._onValidate(checked);
|
|
100
|
-
if (result !== true) {
|
|
101
|
-
return result || 'Invalid value';
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected _buildInputElement(): HTMLElement {
|
|
109
|
-
const { checked, value, required, disabled, name } = this.state;
|
|
110
|
-
|
|
111
|
-
const input = document.createElement('input');
|
|
112
|
-
input.type = 'checkbox';
|
|
113
|
-
input.className = 'jux-switch-input';
|
|
114
|
-
input.id = `${this._id}-input`;
|
|
115
|
-
input.name = name;
|
|
116
|
-
input.value = value;
|
|
117
|
-
input.checked = checked;
|
|
118
|
-
input.required = required;
|
|
119
|
-
input.disabled = disabled;
|
|
120
|
-
|
|
121
|
-
return input;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
125
|
-
* RENDER
|
|
126
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
127
|
-
|
|
128
|
-
render(targetId?: string): this {
|
|
129
|
-
const container = this._setupContainer(targetId);
|
|
130
|
-
|
|
131
|
-
const { style, class: className } = this.state;
|
|
132
|
-
|
|
133
|
-
// Build wrapper
|
|
134
|
-
const wrapper = document.createElement('div');
|
|
135
|
-
wrapper.className = 'jux-switch';
|
|
136
|
-
wrapper.id = this._id;
|
|
137
|
-
if (className) wrapper.className += ` ${className}`;
|
|
138
|
-
if (style) wrapper.setAttribute('style', style);
|
|
139
|
-
|
|
140
|
-
// Switch container
|
|
141
|
-
const switchContainer = document.createElement('label');
|
|
142
|
-
switchContainer.className = 'jux-switch-container';
|
|
143
|
-
switchContainer.htmlFor = `${this._id}-input`;
|
|
144
|
-
|
|
145
|
-
// Input element
|
|
146
|
-
const inputEl = this._buildInputElement() as HTMLInputElement;
|
|
147
|
-
this._inputElement = inputEl;
|
|
148
|
-
switchContainer.appendChild(inputEl);
|
|
149
|
-
|
|
150
|
-
// Toggle slider
|
|
151
|
-
const slider = document.createElement('span');
|
|
152
|
-
slider.className = 'jux-switch-slider';
|
|
153
|
-
switchContainer.appendChild(slider);
|
|
154
|
-
|
|
155
|
-
// Label text
|
|
156
|
-
if (this.state.label) {
|
|
157
|
-
const labelText = document.createElement('span');
|
|
158
|
-
labelText.className = 'jux-switch-label-text';
|
|
159
|
-
labelText.textContent = this.state.label;
|
|
160
|
-
if (this.state.required) {
|
|
161
|
-
const requiredSpan = document.createElement('span');
|
|
162
|
-
requiredSpan.className = 'jux-input-required';
|
|
163
|
-
requiredSpan.textContent = ' *';
|
|
164
|
-
labelText.appendChild(requiredSpan);
|
|
165
|
-
}
|
|
166
|
-
switchContainer.appendChild(labelText);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
wrapper.appendChild(switchContainer);
|
|
170
|
-
|
|
171
|
-
// Error element
|
|
172
|
-
wrapper.appendChild(this._renderError());
|
|
173
|
-
|
|
174
|
-
// Wire events
|
|
175
|
-
this._wireStandardEvents(wrapper);
|
|
176
|
-
|
|
177
|
-
// Wire switch-specific sync (maps 'checked' to 'value' property for consistency)
|
|
178
|
-
const valueSync = this._syncBindings.find(b => b.property === 'value' || b.property === 'checked');
|
|
179
|
-
|
|
180
|
-
if (valueSync) {
|
|
181
|
-
const { stateObj, toState, toComponent } = valueSync;
|
|
182
|
-
|
|
183
|
-
const transformToState = toState || ((v: boolean) => v);
|
|
184
|
-
const transformToComponent = toComponent || ((v: any) => Boolean(v));
|
|
185
|
-
|
|
186
|
-
let isUpdating = false;
|
|
187
|
-
|
|
188
|
-
// State → Component
|
|
189
|
-
stateObj.subscribe((val: any) => {
|
|
190
|
-
if (isUpdating) return;
|
|
191
|
-
const transformed = transformToComponent(val);
|
|
192
|
-
this.setValue(transformed);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// Component → State
|
|
196
|
-
inputEl.addEventListener('change', () => {
|
|
197
|
-
if (isUpdating) return;
|
|
198
|
-
isUpdating = true;
|
|
199
|
-
|
|
200
|
-
const checked = inputEl.checked;
|
|
201
|
-
this.state.checked = checked;
|
|
202
|
-
this._clearError();
|
|
203
|
-
|
|
204
|
-
const transformed = transformToState(checked);
|
|
205
|
-
stateObj.set(transformed);
|
|
206
|
-
|
|
207
|
-
// 🎯 Fire the change callback event
|
|
208
|
-
this._triggerCallback('change', checked);
|
|
209
|
-
|
|
210
|
-
setTimeout(() => { isUpdating = false; }, 0);
|
|
211
|
-
});
|
|
212
|
-
} else {
|
|
213
|
-
// Default behavior without sync
|
|
214
|
-
inputEl.addEventListener('change', () => {
|
|
215
|
-
this.state.checked = inputEl.checked;
|
|
216
|
-
this._clearError();
|
|
217
|
-
|
|
218
|
-
// 🎯 Fire the change callback event
|
|
219
|
-
this._triggerCallback('change', inputEl.checked);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Always add blur validation
|
|
224
|
-
inputEl.addEventListener('blur', () => {
|
|
225
|
-
this.validate();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Sync label changes
|
|
229
|
-
const labelSync = this._syncBindings.find(b => b.property === 'label');
|
|
230
|
-
if (labelSync) {
|
|
231
|
-
const transform = labelSync.toComponent || ((v: any) => String(v));
|
|
232
|
-
labelSync.stateObj.subscribe((val: any) => {
|
|
233
|
-
this.label(transform(val));
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
container.appendChild(wrapper);
|
|
238
|
-
|
|
239
|
-
return this;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function switchComponent(id: string, options: SwitchOptions = {}): Switch {
|
|
244
|
-
return new Switch(id, options);
|
|
245
|
-
}
|
|
246
|
-
|