juxscript 1.0.132 → 1.1.2

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 (133) hide show
  1. package/README.md +1 -32
  2. package/bin/cli.js +4 -2
  3. package/index.d.ts +200 -0
  4. package/index.js +96 -22
  5. package/juxconfig.example.js +58 -63
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.ts +247 -0
  8. package/lib/components/badge.ts +101 -0
  9. package/lib/components/base/BaseComponent.ts +421 -0
  10. package/lib/components/base/FormInput.ts +227 -0
  11. package/lib/components/button.ts +178 -0
  12. package/lib/components/card.ts +173 -0
  13. package/lib/components/chart.ts +231 -0
  14. package/lib/components/checkbox.ts +242 -0
  15. package/lib/components/code.ts +123 -0
  16. package/lib/components/container.ts +140 -0
  17. package/lib/components/data.ts +135 -0
  18. package/lib/components/datepicker.ts +234 -0
  19. package/lib/components/dialog.ts +172 -0
  20. package/lib/components/divider.ts +100 -0
  21. package/lib/components/dropdown.ts +186 -0
  22. package/lib/components/element.ts +267 -0
  23. package/lib/components/fileupload.ts +309 -0
  24. package/lib/components/grid.ts +291 -0
  25. package/lib/components/guard.ts +92 -0
  26. package/lib/components/heading.ts +96 -0
  27. package/lib/components/helpers.ts +41 -0
  28. package/lib/components/hero.ts +224 -0
  29. package/lib/components/icon.ts +178 -0
  30. package/lib/components/icons.ts +464 -0
  31. package/lib/components/include.ts +410 -0
  32. package/lib/components/input.ts +457 -0
  33. package/lib/components/list.ts +419 -0
  34. package/lib/components/loading.ts +100 -0
  35. package/lib/components/menu.ts +275 -0
  36. package/lib/components/modal.ts +284 -0
  37. package/lib/components/nav.ts +257 -0
  38. package/lib/components/paragraph.ts +97 -0
  39. package/lib/components/progress.ts +159 -0
  40. package/lib/components/radio.ts +278 -0
  41. package/lib/components/req.ts +303 -0
  42. package/lib/components/script.ts +41 -0
  43. package/lib/components/select.ts +252 -0
  44. package/lib/components/sidebar.ts +275 -0
  45. package/lib/components/style.ts +41 -0
  46. package/lib/components/switch.ts +246 -0
  47. package/lib/components/table.ts +1249 -0
  48. package/lib/components/tabs.ts +250 -0
  49. package/lib/components/theme-toggle.ts +293 -0
  50. package/lib/components/tooltip.ts +144 -0
  51. package/lib/components/view.ts +190 -0
  52. package/lib/components/write.ts +272 -0
  53. package/lib/globals.d.ts +19 -5
  54. package/lib/layouts/default.css +260 -0
  55. package/lib/layouts/figma.css +334 -0
  56. package/lib/reactivity/state.ts +78 -0
  57. package/lib/utils/{fetch.js → fetch.ts} +206 -81
  58. package/machinery/ast.js +347 -0
  59. package/machinery/build.js +466 -0
  60. package/machinery/compiler3.js +6 -66
  61. package/machinery/config.js +6 -93
  62. package/machinery/doc-generator.js +136 -0
  63. package/machinery/imports.js +155 -0
  64. package/machinery/server.js +166 -0
  65. package/machinery/ts-shim.js +46 -0
  66. package/machinery/watcher.js +162 -50
  67. package/package.json +9 -30
  68. package/create/index.jux +0 -77
  69. package/create/layout.jux +0 -18
  70. package/create/style.css +0 -57
  71. package/create/themes/assets/jux.svg +0 -34
  72. package/create/themes/base.css +0 -197
  73. package/create/themes/base2.css +0 -54
  74. package/create/themes/layouts/base.jux +0 -16
  75. package/create/themes/layouts/base_marketing.jux +0 -0
  76. package/create/themes/layouts/base_saas.jux +0 -0
  77. package/lib/componentsv2/base/BaseEngine.d.ts +0 -112
  78. package/lib/componentsv2/base/BaseEngine.js +0 -279
  79. package/lib/componentsv2/base/BaseSkin.d.ts +0 -74
  80. package/lib/componentsv2/base/BaseSkin.js +0 -130
  81. package/lib/componentsv2/base/Neighborhood.d.ts +0 -22
  82. package/lib/componentsv2/base/Neighborhood.js +0 -56
  83. package/lib/componentsv2/base/OptionsContract.d.ts +0 -20
  84. package/lib/componentsv2/base/OptionsContract.js +0 -107
  85. package/lib/componentsv2/base/State.d.ts +0 -18
  86. package/lib/componentsv2/base/State.js +0 -68
  87. package/lib/componentsv2/element/Element.d.ts +0 -30
  88. package/lib/componentsv2/element/Element.js +0 -50
  89. package/lib/componentsv2/element/ElementEngine.d.ts +0 -59
  90. package/lib/componentsv2/element/ElementEngine.js +0 -118
  91. package/lib/componentsv2/element/ElementSkin.d.ts +0 -10
  92. package/lib/componentsv2/element/ElementSkin.js +0 -56
  93. package/lib/componentsv2/element/structure.css +0 -261
  94. package/lib/componentsv2/grid/Grid.d.ts +0 -13
  95. package/lib/componentsv2/grid/Grid.js +0 -27
  96. package/lib/componentsv2/grid/GridEngine.d.ts +0 -77
  97. package/lib/componentsv2/grid/GridEngine.js +0 -153
  98. package/lib/componentsv2/grid/GridSkin.d.ts +0 -11
  99. package/lib/componentsv2/grid/GridSkin.js +0 -84
  100. package/lib/componentsv2/grid/structure.css +0 -27
  101. package/lib/componentsv2/input/Input.d.ts +0 -6
  102. package/lib/componentsv2/input/Input.js +0 -21
  103. package/lib/componentsv2/input/InputEngine.d.ts +0 -70
  104. package/lib/componentsv2/input/InputEngine.js +0 -143
  105. package/lib/componentsv2/input/InputSkin.d.ts +0 -11
  106. package/lib/componentsv2/input/InputSkin.js +0 -89
  107. package/lib/componentsv2/input/structure.css +0 -47
  108. package/lib/componentsv2/list/List.d.ts +0 -49
  109. package/lib/componentsv2/list/List.js +0 -105
  110. package/lib/componentsv2/list/ListEngine.d.ts +0 -121
  111. package/lib/componentsv2/list/ListEngine.js +0 -322
  112. package/lib/componentsv2/list/ListSkin.d.ts +0 -20
  113. package/lib/componentsv2/list/ListSkin.js +0 -345
  114. package/lib/componentsv2/list/structure.css +0 -359
  115. package/lib/componentsv2/plugins/ClientSQLitePlugin.d.ts +0 -21
  116. package/lib/componentsv2/plugins/ClientSQLitePlugin.js +0 -130
  117. package/lib/componentsv2/plugins/IndexedDBPlugin.d.ts +0 -18
  118. package/lib/componentsv2/plugins/IndexedDBPlugin.js +0 -75
  119. package/lib/componentsv2/plugins/LocalStoragePlugin.d.ts +0 -20
  120. package/lib/componentsv2/plugins/LocalStoragePlugin.js +0 -65
  121. package/lib/componentsv2/plugins/ServerSQLitePlugin.d.ts +0 -25
  122. package/lib/componentsv2/plugins/ServerSQLitePlugin.js +0 -70
  123. package/lib/componentsv2/stubs/ComponentComposition.ts.stub +0 -32
  124. package/lib/componentsv2/stubs/ComponentEngine.ts.stub +0 -36
  125. package/lib/componentsv2/stubs/ComponentSkin.ts.stub +0 -35
  126. package/lib/componentsv2/stubs/ComponentStructure.css.d.ts.stub +0 -2
  127. package/lib/componentsv2/stubs/ComponentStructure.css.stub +0 -13
  128. package/lib/utils/fetch.d.ts +0 -176
  129. package/machinery/serve.js +0 -255
  130. package/types/css.d.ts +0 -10
  131. /package/{create/themes/layouts/base_blog.jux → machinery/bundleAssets.js} +0 -0
  132. /package/{create/themes/layouts/base_docs.jux → machinery/bundleJux.js} +0 -0
  133. /package/{create/themes/layouts/base_login.jux → machinery/bundleVendors.js} +0 -0
@@ -0,0 +1,267 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const; // Element has no trigger events
5
+ const CALLBACK_EVENTS = [] as const; // Element has no callback events
6
+
7
+ export interface ElementOptions {
8
+ tagType?: string;
9
+ className?: string;
10
+ text?: string;
11
+ innerHTML?: string;
12
+ attributes?: Record<string, string>;
13
+ styles?: Record<string, string>;
14
+ style?: string;
15
+ class?: string;
16
+ }
17
+
18
+ type ElementState = {
19
+ tagType: string;
20
+ className: string;
21
+ text: string;
22
+ innerHTML: string;
23
+ attributes: Record<string, string>;
24
+ styles: Record<string, string>;
25
+ style: string;
26
+ class: string;
27
+ };
28
+
29
+ export class Element extends BaseComponent<ElementState> {
30
+ private _element: HTMLElement | null = null;
31
+
32
+ constructor(id: string, options: ElementOptions = {}) {
33
+ super(id, {
34
+ tagType: options.tagType ?? 'div',
35
+ className: options.className ?? '',
36
+ text: options.text ?? '',
37
+ innerHTML: options.innerHTML ?? '',
38
+ attributes: options.attributes ?? {},
39
+ styles: options.styles ?? {},
40
+ style: options.style ?? '',
41
+ class: options.class ?? ''
42
+ });
43
+ }
44
+
45
+ protected getTriggerEvents(): readonly string[] {
46
+ return TRIGGER_EVENTS;
47
+ }
48
+
49
+ protected getCallbackEvents(): readonly string[] {
50
+ return CALLBACK_EVENTS;
51
+ }
52
+
53
+ /* ═════════════════════════════════════════════════════════════════
54
+ * FLUENT API
55
+ * ═════════════════════════════════════════════════════════════════ */
56
+
57
+ // ✅ Inherited from BaseComponent:
58
+ // - style(), class()
59
+ // - addClass(), removeClass(), toggleClass()
60
+ // - visible(), show(), hide(), toggleVisibility()
61
+ // - attr(), attrs(), removeAttr()
62
+ // - disabled(), enable(), disable()
63
+ // - loading()
64
+ // - focus(), blur()
65
+ // - remove()
66
+ // - bind(), sync(), renderTo()
67
+
68
+ tagType(value: string): Element {
69
+ this.state.tagType = value;
70
+ return this;
71
+ }
72
+
73
+ className(value: string): Element {
74
+ this.state.className = value;
75
+ return this;
76
+ }
77
+
78
+ text(value: string): Element {
79
+ this.state.text = value;
80
+ this.state.innerHTML = '';
81
+ return this;
82
+ }
83
+
84
+ innerHTML(value: string): Element {
85
+ this.state.innerHTML = value;
86
+ this.state.text = '';
87
+ return this;
88
+ }
89
+
90
+ write(content: string, asHTML: boolean = false, newLine: boolean = false): Element {
91
+ if (!this._element) {
92
+ console.warn(`Element.write: Element "${this._id}" not yet rendered`);
93
+ return this;
94
+ }
95
+
96
+ const contentWithBreak = newLine ? (asHTML ? content + '<br>' : content + '\n') : content;
97
+
98
+ if (asHTML) {
99
+ this._element.insertAdjacentHTML('beforeend', contentWithBreak);
100
+ } else {
101
+ const textNode = document.createTextNode(contentWithBreak);
102
+ this._element.appendChild(textNode);
103
+ }
104
+
105
+ return this;
106
+ }
107
+
108
+ prepend(content: string, asHTML: boolean = false, newLine: boolean = false): Element {
109
+ if (!this._element) {
110
+ console.warn(`Element.prepend: Element "${this._id}" not yet rendered`);
111
+ return this;
112
+ }
113
+
114
+ const contentWithBreak = newLine ? (asHTML ? content + '<br>' : content + '\n') : content;
115
+
116
+ if (asHTML) {
117
+ this._element.insertAdjacentHTML('afterbegin', contentWithBreak);
118
+ } else {
119
+ const textNode = document.createTextNode(contentWithBreak);
120
+ this._element.insertBefore(textNode, this._element.firstChild);
121
+ }
122
+
123
+ return this;
124
+ }
125
+
126
+ clear(): Element {
127
+ if (!this._element) {
128
+ console.warn(`Element.clear: Element "${this._id}" not yet rendered`);
129
+ return this;
130
+ }
131
+
132
+ this._element.innerHTML = '';
133
+ return this;
134
+ }
135
+
136
+ /**
137
+ * Append child component or HTML element
138
+ */
139
+ append(child: any): Element {
140
+ if (!this._element) {
141
+ console.warn(`Element.append: Element "${this._id}" not yet rendered`);
142
+ return this;
143
+ }
144
+
145
+ if (child instanceof HTMLElement) {
146
+ this._element.appendChild(child);
147
+ } else if (child?._element) {
148
+ // Another Jux component
149
+ this._element.appendChild(child._element);
150
+ } else if (typeof child === 'string') {
151
+ const div = document.createElement('div');
152
+ div.innerHTML = child;
153
+ this._element.appendChild(div.firstChild || div);
154
+ }
155
+
156
+ return this;
157
+ }
158
+
159
+ render(targetId?: string): this {
160
+ const container = this._setupContainer(targetId);
161
+
162
+ const { tagType, className, text, innerHTML, attributes, styles, style, class: classValue } = this.state;
163
+
164
+ // Build element
165
+ const element = document.createElement(tagType);
166
+ element.id = this._id;
167
+
168
+ if (className) element.className = className;
169
+ if (classValue) element.className = `${element.className} ${classValue}`.trim();
170
+
171
+ if (text) {
172
+ element.textContent = text;
173
+ } else if (innerHTML) {
174
+ element.innerHTML = innerHTML;
175
+ }
176
+
177
+ Object.entries(attributes).forEach(([key, value]) => {
178
+ element.setAttribute(key, value);
179
+ });
180
+
181
+ const styleString = Object.entries(styles)
182
+ .map(([key, value]) => `${key}: ${value}`)
183
+ .join('; ');
184
+
185
+ if (styleString || style) {
186
+ element.setAttribute('style', `${styleString}; ${style}`.trim());
187
+ }
188
+
189
+ // Wire events using inherited method
190
+ this._wireStandardEvents(element);
191
+
192
+ // Wire sync bindings
193
+ this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
194
+ const transform = toComponent || ((v: any) => v);
195
+
196
+ stateObj.subscribe((val: any) => {
197
+ const transformed = transform(val);
198
+
199
+ if (property === 'text') {
200
+ element.textContent = String(transformed);
201
+ this.state.text = String(transformed);
202
+ } else if (property === 'innerHTML') {
203
+ element.innerHTML = String(transformed);
204
+ this.state.innerHTML = String(transformed);
205
+ } else if (property === 'class') {
206
+ element.className = String(transformed);
207
+ this.state.class = String(transformed);
208
+ }
209
+ });
210
+ });
211
+
212
+ container.appendChild(element);
213
+ this._element = element;
214
+
215
+ return this;
216
+ }
217
+ }
218
+
219
+ export function element(id: string, options: ElementOptions = {}): Element {
220
+ return new Element(id, options);
221
+ }
222
+
223
+ // Semantic HTML element factories with default classes
224
+ export function header(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
225
+ const defaultClass = 'jux-header';
226
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
227
+ return new Element(id, { ...options, tagType: 'header', class: mergedClass });
228
+ }
229
+
230
+ export function footer(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
231
+ const defaultClass = 'jux-footer';
232
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
233
+ return new Element(id, { ...options, tagType: 'footer', class: mergedClass });
234
+ }
235
+
236
+ export function main(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
237
+ const defaultClass = 'jux-main';
238
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
239
+ return new Element(id, { ...options, tagType: 'main', class: mergedClass });
240
+ }
241
+
242
+ export function aside(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
243
+ const defaultClass = 'jux-aside';
244
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
245
+ return new Element(id, { ...options, tagType: 'aside', class: mergedClass });
246
+ }
247
+
248
+ export function section(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
249
+ const defaultClass = 'jux-section';
250
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
251
+ return new Element(id, { ...options, tagType: 'section', class: mergedClass });
252
+ }
253
+
254
+ export function article(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
255
+ const defaultClass = 'jux-article';
256
+ const mergedClass = options.class ? `${defaultClass} ${options.class}` : defaultClass;
257
+ return new Element(id, { ...options, tagType: 'article', class: mergedClass });
258
+ }
259
+
260
+ export function div(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
261
+ return new Element(id, { ...options, tagType: 'div' });
262
+ }
263
+
264
+ export function span(id: string, options: Omit<ElementOptions, 'tagType'> = {}): Element {
265
+ return new Element(id, { ...options, tagType: 'span' });
266
+ }
267
+
@@ -0,0 +1,309 @@
1
+ import { FormInput, FormInputState } from './base/FormInput.js';
2
+ import { renderIcon } from './icons.js';
3
+
4
+ // Event definitions
5
+ const TRIGGER_EVENTS = [] as const;
6
+ const CALLBACK_EVENTS = ['change', 'filesSelected', 'clear'] as const;
7
+
8
+ export interface FileUploadOptions {
9
+ label?: string;
10
+ accept?: string;
11
+ multiple?: boolean;
12
+ disabled?: boolean;
13
+ name?: string;
14
+ icon?: string;
15
+ required?: boolean;
16
+ style?: string;
17
+ class?: string;
18
+ onValidate?: (files: File[]) => boolean | string;
19
+ }
20
+
21
+ interface FileUploadState extends FormInputState {
22
+ files: File[];
23
+ accept: string;
24
+ multiple: boolean;
25
+ icon: string;
26
+ }
27
+
28
+ export class FileUpload extends FormInput<FileUploadState> {
29
+ private _fileListElement: HTMLElement | null = null;
30
+
31
+ constructor(id: string, options: FileUploadOptions = {}) {
32
+ super(id, {
33
+ files: [],
34
+ accept: options.accept ?? '',
35
+ multiple: options.multiple ?? false,
36
+ icon: options.icon ?? 'upload',
37
+ label: options.label ?? '',
38
+ required: options.required ?? false,
39
+ disabled: options.disabled ?? false,
40
+ name: options.name ?? id,
41
+ style: options.style ?? '',
42
+ class: options.class ?? '',
43
+ errorMessage: undefined
44
+ });
45
+
46
+ if (options.onValidate) {
47
+ this._onValidate = options.onValidate;
48
+ }
49
+ }
50
+
51
+ protected getTriggerEvents(): readonly string[] {
52
+ return TRIGGER_EVENTS;
53
+ }
54
+
55
+ protected getCallbackEvents(): readonly string[] {
56
+ return CALLBACK_EVENTS;
57
+ }
58
+
59
+ /* ═════════════════════════════════════════════════════════════════
60
+ * FLUENT API
61
+ * ═════════════════════════════════════════════════════════════════ */
62
+
63
+ // ✅ Inherited from FormInput/BaseComponent:
64
+ // - label(), required(), name(), onValidate()
65
+ // - validate(), isValid()
66
+ // - style(), class()
67
+ // - bind(), sync(), renderTo()
68
+ // - disabled(), enable(), disable()
69
+
70
+ accept(value: string): this {
71
+ this.state.accept = value;
72
+ return this;
73
+ }
74
+
75
+ multiple(value: boolean): this {
76
+ this.state.multiple = value;
77
+ return this;
78
+ }
79
+
80
+ icon(value: string): this {
81
+ this.state.icon = value;
82
+ return this;
83
+ }
84
+
85
+ clear(): this {
86
+ this.state.files = [];
87
+ if (this._inputElement) {
88
+ (this._inputElement as HTMLInputElement).value = '';
89
+ }
90
+ if (this._fileListElement) {
91
+ this._updateFileList([]);
92
+ }
93
+ // 🎯 Fire the clear callback event
94
+ this._triggerCallback('clear');
95
+ return this;
96
+ }
97
+
98
+ /* ═════════════════════════════════════════════════════════════════
99
+ * FORM INPUT IMPLEMENTATION
100
+ * ═════════════════════════════════════════════════════════════════ */
101
+
102
+ getValue(): File[] {
103
+ return this.state.files;
104
+ }
105
+
106
+ setValue(files: File[]): this {
107
+ this.state.files = files;
108
+ if (this._fileListElement) {
109
+ this._updateFileList(files);
110
+ }
111
+ return this;
112
+ }
113
+
114
+ getFiles(): File[] {
115
+ return this.getValue();
116
+ }
117
+
118
+ protected _validateValue(files: File[]): boolean | string {
119
+ const { required } = this.state;
120
+
121
+ if (required && files.length === 0) {
122
+ return 'Please select at least one file';
123
+ }
124
+
125
+ if (this._onValidate) {
126
+ const result = this._onValidate(files);
127
+ if (result !== true) {
128
+ return result || 'Invalid files';
129
+ }
130
+ }
131
+
132
+ return true;
133
+ }
134
+
135
+ protected _buildInputElement(): HTMLElement {
136
+ const { accept, multiple, required, disabled, name } = this.state;
137
+
138
+ const input = document.createElement('input');
139
+ input.type = 'file';
140
+ input.className = 'jux-fileupload-input';
141
+ input.id = `${this._id}-input`;
142
+ input.name = name;
143
+ input.required = required;
144
+ input.disabled = disabled;
145
+
146
+ if (accept) input.accept = accept;
147
+ if (multiple) input.multiple = multiple;
148
+
149
+ return input;
150
+ }
151
+
152
+ /* ═════════════════════════════════════════════════════════════════
153
+ * RENDER
154
+ * ═════════════════════════════════════════════════════════════════ */
155
+
156
+ render(targetId?: string): this {
157
+ const container = this._setupContainer(targetId);
158
+
159
+ const { icon, style, class: className } = this.state;
160
+
161
+ // Build wrapper
162
+ const wrapper = document.createElement('div');
163
+ wrapper.className = 'jux-input jux-fileupload';
164
+ wrapper.id = this._id;
165
+ if (className) wrapper.className += ` ${className}`;
166
+ if (style) wrapper.setAttribute('style', style);
167
+
168
+ // Label
169
+ if (this.state.label) {
170
+ wrapper.appendChild(this._renderLabel());
171
+ }
172
+
173
+ // Hidden file input
174
+ const inputEl = this._buildInputElement() as HTMLInputElement;
175
+ this._inputElement = inputEl;
176
+ wrapper.appendChild(inputEl);
177
+
178
+ // Button container
179
+ const buttonContainer = document.createElement('div');
180
+ buttonContainer.className = 'jux-fileupload-button-container';
181
+
182
+ if (icon) {
183
+ const iconEl = document.createElement('span');
184
+ iconEl.className = 'jux-fileupload-icon';
185
+ iconEl.appendChild(renderIcon(icon));
186
+ buttonContainer.appendChild(iconEl);
187
+ }
188
+
189
+ const button = document.createElement('button');
190
+ button.type = 'button';
191
+ button.className = 'jux-fileupload-button';
192
+ button.textContent = 'Choose File(s)';
193
+ button.disabled = this.state.disabled;
194
+
195
+ buttonContainer.appendChild(button);
196
+ wrapper.appendChild(buttonContainer);
197
+
198
+ // File list
199
+ const fileList = document.createElement('div');
200
+ fileList.className = 'jux-fileupload-list';
201
+ this._fileListElement = fileList;
202
+ wrapper.appendChild(fileList);
203
+
204
+ // Error element
205
+ wrapper.appendChild(this._renderError());
206
+
207
+ // Button click triggers file input
208
+ button.addEventListener('click', () => inputEl.click());
209
+
210
+ // Wire events
211
+ this._wireStandardEvents(wrapper);
212
+
213
+ // Wire file-specific sync
214
+ const filesSync = this._syncBindings.find(b => b.property === 'files' || b.property === 'value');
215
+
216
+ if (filesSync) {
217
+ const { stateObj, toState, toComponent } = filesSync;
218
+
219
+ const transformToState = toState || ((v: File[]) => v);
220
+ const transformToComponent = toComponent || ((v: any) => v);
221
+
222
+ let isUpdating = false;
223
+
224
+ // State → Component
225
+ stateObj.subscribe((val: any) => {
226
+ if (isUpdating) return;
227
+ const transformed = transformToComponent(val);
228
+ this.setValue(transformed);
229
+ });
230
+
231
+ // Component → State
232
+ inputEl.addEventListener('change', () => {
233
+ if (isUpdating) return;
234
+ isUpdating = true;
235
+
236
+ const files = Array.from(inputEl.files || []);
237
+ this.state.files = files;
238
+ this._updateFileList(files);
239
+ this._clearError();
240
+
241
+ const transformed = transformToState(files);
242
+ stateObj.set(transformed);
243
+
244
+ // 🎯 Fire the callback events
245
+ this._triggerCallback('change', files);
246
+ this._triggerCallback('filesSelected', files);
247
+
248
+ setTimeout(() => { isUpdating = false; }, 0);
249
+ });
250
+ } else {
251
+ // Default behavior without sync
252
+ inputEl.addEventListener('change', () => {
253
+ const files = Array.from(inputEl.files || []);
254
+ this.state.files = files;
255
+ this._updateFileList(files);
256
+ this._clearError();
257
+
258
+ // 🎯 Fire the callback events
259
+ this._triggerCallback('change', files);
260
+ this._triggerCallback('filesSelected', files);
261
+ });
262
+ }
263
+
264
+ // Always add blur validation
265
+ inputEl.addEventListener('blur', () => {
266
+ this.validate();
267
+ });
268
+
269
+ // Sync label changes
270
+ const labelSync = this._syncBindings.find(b => b.property === 'label');
271
+ if (labelSync) {
272
+ const transform = labelSync.toComponent || ((v: any) => String(v));
273
+ labelSync.stateObj.subscribe((val: any) => {
274
+ this.label(transform(val));
275
+ });
276
+ }
277
+
278
+ container.appendChild(wrapper);
279
+ return this;
280
+ }
281
+
282
+ private _updateFileList(files: File[]): void {
283
+ if (!this._fileListElement) return;
284
+
285
+ this._fileListElement.innerHTML = '';
286
+
287
+ if (files.length === 0) {
288
+ this._fileListElement.textContent = 'No files selected';
289
+ return;
290
+ }
291
+
292
+ files.forEach(file => {
293
+ const fileItem = document.createElement('div');
294
+ fileItem.className = 'jux-fileupload-item';
295
+ fileItem.textContent = `${file.name} (${this._formatFileSize(file.size)})`;
296
+ this._fileListElement!.appendChild(fileItem);
297
+ });
298
+ }
299
+
300
+ private _formatFileSize(bytes: number): string {
301
+ if (bytes < 1024) return `${bytes} B`;
302
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
303
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
304
+ }
305
+ }
306
+
307
+ export function fileupload(id: string, options: FileUploadOptions = {}): FileUpload {
308
+ return new FileUpload(id, options);
309
+ }