juxscript 1.1.3 → 1.1.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.
Files changed (63) hide show
  1. package/machinery/build3.js +7 -91
  2. package/machinery/compiler3.js +3 -131
  3. package/package.json +19 -5
  4. package/lib/components/alert.ts +0 -200
  5. package/lib/components/app.ts +0 -247
  6. package/lib/components/badge.ts +0 -101
  7. package/lib/components/base/BaseComponent.ts +0 -421
  8. package/lib/components/base/FormInput.ts +0 -227
  9. package/lib/components/button.ts +0 -178
  10. package/lib/components/card.ts +0 -173
  11. package/lib/components/chart.ts +0 -231
  12. package/lib/components/checkbox.ts +0 -242
  13. package/lib/components/code.ts +0 -123
  14. package/lib/components/container.ts +0 -140
  15. package/lib/components/data.ts +0 -135
  16. package/lib/components/datepicker.ts +0 -234
  17. package/lib/components/dialog.ts +0 -172
  18. package/lib/components/divider.ts +0 -100
  19. package/lib/components/dropdown.ts +0 -186
  20. package/lib/components/element.ts +0 -267
  21. package/lib/components/fileupload.ts +0 -309
  22. package/lib/components/grid.ts +0 -291
  23. package/lib/components/guard.ts +0 -92
  24. package/lib/components/heading.ts +0 -96
  25. package/lib/components/helpers.ts +0 -41
  26. package/lib/components/hero.ts +0 -224
  27. package/lib/components/icon.ts +0 -178
  28. package/lib/components/icons.ts +0 -464
  29. package/lib/components/include.ts +0 -410
  30. package/lib/components/input.ts +0 -457
  31. package/lib/components/list.ts +0 -419
  32. package/lib/components/loading.ts +0 -100
  33. package/lib/components/menu.ts +0 -275
  34. package/lib/components/modal.ts +0 -284
  35. package/lib/components/nav.ts +0 -257
  36. package/lib/components/paragraph.ts +0 -97
  37. package/lib/components/progress.ts +0 -159
  38. package/lib/components/radio.ts +0 -278
  39. package/lib/components/req.ts +0 -303
  40. package/lib/components/script.ts +0 -41
  41. package/lib/components/select.ts +0 -252
  42. package/lib/components/sidebar.ts +0 -275
  43. package/lib/components/style.ts +0 -41
  44. package/lib/components/switch.ts +0 -246
  45. package/lib/components/table.ts +0 -1249
  46. package/lib/components/tabs.ts +0 -250
  47. package/lib/components/theme-toggle.ts +0 -293
  48. package/lib/components/tooltip.ts +0 -144
  49. package/lib/components/view.ts +0 -190
  50. package/lib/components/write.ts +0 -272
  51. package/lib/layouts/default.css +0 -260
  52. package/lib/layouts/figma.css +0 -334
  53. package/lib/reactivity/state.ts +0 -78
  54. package/lib/utils/fetch.ts +0 -553
  55. package/machinery/ast.js +0 -347
  56. package/machinery/build.js +0 -466
  57. package/machinery/bundleAssets.js +0 -0
  58. package/machinery/bundleJux.js +0 -0
  59. package/machinery/bundleVendors.js +0 -0
  60. package/machinery/doc-generator.js +0 -136
  61. package/machinery/imports.js +0 -155
  62. package/machinery/ts-shim.js +0 -46
  63. package/machinery/validators/file-validator.js +0 -123
@@ -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
-