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.
Files changed (67) hide show
  1. package/machinery/build3.js +7 -91
  2. package/machinery/compiler3.js +3 -209
  3. package/machinery/config.js +93 -6
  4. package/machinery/serve.js +255 -0
  5. package/machinery/watcher.js +49 -161
  6. package/package.json +19 -5
  7. package/lib/components/alert.ts +0 -200
  8. package/lib/components/app.ts +0 -247
  9. package/lib/components/badge.ts +0 -101
  10. package/lib/components/base/BaseComponent.ts +0 -421
  11. package/lib/components/base/FormInput.ts +0 -227
  12. package/lib/components/button.ts +0 -178
  13. package/lib/components/card.ts +0 -173
  14. package/lib/components/chart.ts +0 -231
  15. package/lib/components/checkbox.ts +0 -242
  16. package/lib/components/code.ts +0 -123
  17. package/lib/components/container.ts +0 -140
  18. package/lib/components/data.ts +0 -135
  19. package/lib/components/datepicker.ts +0 -234
  20. package/lib/components/dialog.ts +0 -172
  21. package/lib/components/divider.ts +0 -100
  22. package/lib/components/dropdown.ts +0 -186
  23. package/lib/components/element.ts +0 -267
  24. package/lib/components/fileupload.ts +0 -309
  25. package/lib/components/grid.ts +0 -291
  26. package/lib/components/guard.ts +0 -92
  27. package/lib/components/heading.ts +0 -96
  28. package/lib/components/helpers.ts +0 -41
  29. package/lib/components/hero.ts +0 -224
  30. package/lib/components/icon.ts +0 -178
  31. package/lib/components/icons.ts +0 -464
  32. package/lib/components/include.ts +0 -410
  33. package/lib/components/input.ts +0 -457
  34. package/lib/components/list.ts +0 -419
  35. package/lib/components/loading.ts +0 -100
  36. package/lib/components/menu.ts +0 -275
  37. package/lib/components/modal.ts +0 -284
  38. package/lib/components/nav.ts +0 -257
  39. package/lib/components/paragraph.ts +0 -97
  40. package/lib/components/progress.ts +0 -159
  41. package/lib/components/radio.ts +0 -278
  42. package/lib/components/req.ts +0 -303
  43. package/lib/components/script.ts +0 -41
  44. package/lib/components/select.ts +0 -252
  45. package/lib/components/sidebar.ts +0 -275
  46. package/lib/components/style.ts +0 -41
  47. package/lib/components/switch.ts +0 -246
  48. package/lib/components/table.ts +0 -1249
  49. package/lib/components/tabs.ts +0 -250
  50. package/lib/components/theme-toggle.ts +0 -293
  51. package/lib/components/tooltip.ts +0 -144
  52. package/lib/components/view.ts +0 -190
  53. package/lib/components/write.ts +0 -272
  54. package/lib/layouts/default.css +0 -260
  55. package/lib/layouts/figma.css +0 -334
  56. package/lib/reactivity/state.ts +0 -78
  57. package/lib/utils/fetch.ts +0 -553
  58. package/machinery/ast.js +0 -347
  59. package/machinery/build.js +0 -466
  60. package/machinery/bundleAssets.js +0 -0
  61. package/machinery/bundleJux.js +0 -0
  62. package/machinery/bundleVendors.js +0 -0
  63. package/machinery/doc-generator.js +0 -136
  64. package/machinery/imports.js +0 -155
  65. package/machinery/server.js +0 -166
  66. package/machinery/ts-shim.js +0 -46
  67. package/machinery/validators/file-validator.js +0 -123
@@ -1,457 +0,0 @@
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', 'input'] as const;
7
-
8
- export interface InputOptions {
9
- type?: string;
10
- value?: string;
11
- placeholder?: string;
12
- label?: string;
13
- icon?: string;
14
- required?: boolean;
15
- disabled?: boolean;
16
- name?: string;
17
- rows?: number;
18
- min?: number;
19
- max?: number;
20
- step?: number;
21
- minLength?: number;
22
- maxLength?: number;
23
- pattern?: string;
24
- onValidate?: (value: string) => boolean | string;
25
- style?: string;
26
- class?: string;
27
- }
28
-
29
- interface InputState extends FormInputState {
30
- type: string;
31
- value: string;
32
- placeholder: string;
33
- icon: string;
34
- rows: number;
35
- min?: number;
36
- max?: number;
37
- step?: number;
38
- minLength?: number;
39
- maxLength?: number;
40
- pattern?: string;
41
- }
42
-
43
- export class Input extends FormInput<InputState> {
44
- constructor(id: string, options: InputOptions = {}) {
45
- super(id, {
46
- type: options.type ?? 'text',
47
- value: options.value ?? '',
48
- placeholder: options.placeholder ?? '',
49
- label: options.label ?? '',
50
- icon: options.icon ?? '',
51
- required: options.required ?? false,
52
- disabled: options.disabled ?? false,
53
- name: options.name ?? id,
54
- rows: options.rows ?? 3,
55
- min: options.min,
56
- max: options.max,
57
- step: options.step,
58
- minLength: options.minLength,
59
- maxLength: options.maxLength,
60
- pattern: options.pattern,
61
- style: options.style ?? '',
62
- class: options.class ?? '',
63
- errorMessage: undefined
64
- });
65
-
66
- if (options.onValidate) {
67
- this._onValidate = options.onValidate;
68
- }
69
- }
70
-
71
- protected getTriggerEvents(): readonly string[] {
72
- return TRIGGER_EVENTS;
73
- }
74
-
75
- protected getCallbackEvents(): readonly string[] {
76
- return CALLBACK_EVENTS;
77
- }
78
-
79
- /* ═════════════════════════════════════════════════════════════════
80
- * FLUENT API
81
- * ═════════════════════════════════════════════════════════════════ */
82
-
83
- // ✅ Inherited from FormInput/BaseComponent:
84
- // - label(), required(), name(), onValidate()
85
- // - validate(), isValid()
86
- // - style(), class()
87
- // - bind(), sync(), renderTo()
88
- // - disabled(), enable(), disable()
89
-
90
- type(value: string): this {
91
- this.state.type = value;
92
- return this;
93
- }
94
-
95
- value(value: string | number): this {
96
- return this.setValue(String(value));
97
- }
98
-
99
- placeholder(value: string): this {
100
- this.state.placeholder = value;
101
- return this;
102
- }
103
-
104
- icon(value: string): this {
105
- this.state.icon = value;
106
- return this;
107
- }
108
-
109
- rows(value: number): this {
110
- this.state.rows = value;
111
- return this;
112
- }
113
-
114
- min(value: number): this {
115
- this.state.min = value;
116
- return this;
117
- }
118
-
119
- max(value: number): this {
120
- this.state.max = value;
121
- return this;
122
- }
123
-
124
- step(value: number): this {
125
- this.state.step = value;
126
- return this;
127
- }
128
-
129
- minLength(value: number): this {
130
- this.state.minLength = value;
131
- return this;
132
- }
133
-
134
- maxLength(value: number): this {
135
- this.state.maxLength = value;
136
- return this;
137
- }
138
-
139
- pattern(value: string): this {
140
- this.state.pattern = value;
141
- return this;
142
- }
143
-
144
- /* ═════════════════════════════════════════════════════════════════
145
- * FORM INPUT IMPLEMENTATION
146
- * ═════════════════════════════════════════════════════════════════ */
147
-
148
- getValue(): string {
149
- return this.state.value;
150
- }
151
-
152
- setValue(value: string): this {
153
- this.state.value = value;
154
- if (this._inputElement) {
155
- (this._inputElement as HTMLInputElement | HTMLTextAreaElement).value = value;
156
- }
157
- return this;
158
- }
159
-
160
- getNumericValue(): number | null {
161
- const num = Number(this.state.value);
162
- return isNaN(num) ? null : num;
163
- }
164
-
165
- protected _validateValue(value: string): boolean | string {
166
- const { required, type, min, max, minLength, maxLength, pattern } = this.state;
167
-
168
- if (required && !value.trim()) {
169
- return 'This field is required';
170
- }
171
-
172
- if (type === 'number' && value) {
173
- const numValue = Number(value);
174
-
175
- if (isNaN(numValue)) {
176
- return 'Must be a valid number';
177
- }
178
-
179
- if (min !== undefined && numValue < min) {
180
- return `Must be at least ${min}`;
181
- }
182
-
183
- if (max !== undefined && numValue > max) {
184
- return `Must be at most ${max}`;
185
- }
186
- }
187
-
188
- if ((type === 'text' || type === 'textarea') && value) {
189
- if (minLength !== undefined && value.length < minLength) {
190
- return `Must be at least ${minLength} characters`;
191
- }
192
-
193
- if (maxLength !== undefined && value.length > maxLength) {
194
- return `Must be at most ${maxLength} characters`;
195
- }
196
- }
197
-
198
- if (pattern && value) {
199
- const regex = new RegExp(pattern);
200
- if (!regex.test(value)) {
201
- return 'Invalid format';
202
- }
203
- }
204
-
205
- if (this._onValidate) {
206
- const result = this._onValidate(value);
207
- if (result !== true) {
208
- return result || 'Invalid value';
209
- }
210
- }
211
-
212
- return true;
213
- }
214
-
215
- protected _buildInputElement(): HTMLElement {
216
- const { type, value, placeholder, required, disabled, name, rows, min, max, step, minLength, maxLength, pattern } = this.state;
217
-
218
- let inputEl: HTMLInputElement | HTMLTextAreaElement;
219
-
220
- if (type === 'textarea') {
221
- inputEl = document.createElement('textarea');
222
- inputEl.rows = rows;
223
- if (minLength !== undefined) inputEl.minLength = minLength;
224
- if (maxLength !== undefined) inputEl.maxLength = maxLength;
225
- } else {
226
- inputEl = document.createElement('input');
227
- inputEl.type = type;
228
-
229
- if (type === 'number') {
230
- if (min !== undefined) inputEl.min = String(min);
231
- if (max !== undefined) inputEl.max = String(max);
232
- if (step !== undefined) inputEl.step = String(step);
233
- }
234
-
235
- if (type === 'text' || type === 'email' || type === 'tel' || type === 'url') {
236
- if (minLength !== undefined) inputEl.minLength = minLength;
237
- if (maxLength !== undefined) inputEl.maxLength = maxLength;
238
- if (pattern) inputEl.pattern = pattern;
239
- }
240
- }
241
-
242
- inputEl.className = 'jux-input-element';
243
- inputEl.id = `${this._id}-input`;
244
- inputEl.name = name;
245
- inputEl.value = value;
246
- inputEl.placeholder = placeholder;
247
- inputEl.required = required;
248
- inputEl.disabled = disabled;
249
-
250
- return inputEl;
251
- }
252
-
253
- /* ═════════════════════════════════════════════════════════════════
254
- * RENDER
255
- * ═════════════════════════════════════════════════════════════════ */
256
-
257
- render(targetId?: string): this {
258
- const container = this._setupContainer(targetId);
259
-
260
- const { icon, maxLength, type, style, class: className } = this.state;
261
-
262
- // Build wrapper
263
- const wrapper = document.createElement('div');
264
- wrapper.className = 'jux-input';
265
- wrapper.id = this._id;
266
- if (className) wrapper.className += ` ${className}`;
267
- if (style) wrapper.setAttribute('style', style);
268
-
269
- // Label
270
- if (this.state.label) {
271
- wrapper.appendChild(this._renderLabel());
272
- }
273
-
274
- // Input container
275
- const inputContainer = document.createElement('div');
276
- inputContainer.className = 'jux-input-container';
277
- if (icon) inputContainer.classList.add('jux-input-with-icon');
278
-
279
- // Icon
280
- if (icon) {
281
- const iconEl = document.createElement('span');
282
- iconEl.className = 'jux-input-icon';
283
- iconEl.appendChild(renderIcon(icon));
284
- inputContainer.appendChild(iconEl);
285
- }
286
-
287
- // Input element
288
- const inputEl = this._buildInputElement();
289
- this._inputElement = inputEl;
290
- inputContainer.appendChild(inputEl);
291
- wrapper.appendChild(inputContainer);
292
-
293
- // Error element
294
- wrapper.appendChild(this._renderError());
295
-
296
- // Character counter
297
- if (maxLength && (type === 'text' || type === 'textarea')) {
298
- const counterEl = document.createElement('div');
299
- counterEl.className = 'jux-input-counter';
300
- counterEl.id = `${this._id}-counter`;
301
- counterEl.textContent = `${this.state.value.length}/${maxLength}`;
302
- wrapper.appendChild(counterEl);
303
-
304
- inputEl.addEventListener('input', () => {
305
- const input = inputEl as HTMLInputElement | HTMLTextAreaElement;
306
- counterEl.textContent = `${input.value.length}/${maxLength}`;
307
- this.state.value = input.value;
308
-
309
- // 🎯 Fire the input callback event
310
- this._triggerCallback('input', input.value);
311
- });
312
- } else {
313
- // Fire input event even without counter
314
- inputEl.addEventListener('input', () => {
315
- const input = inputEl as HTMLInputElement | HTMLTextAreaElement;
316
- this.state.value = input.value;
317
-
318
- // 🎯 Fire the input callback event
319
- this._triggerCallback('input', input.value);
320
- });
321
- }
322
-
323
- // Fire change event on blur
324
- inputEl.addEventListener('change', () => {
325
- const input = inputEl as HTMLInputElement | HTMLTextAreaElement;
326
- // 🎯 Fire the change callback event
327
- this._triggerCallback('change', input.value);
328
- });
329
-
330
- // Wire events
331
- this._wireStandardEvents(wrapper);
332
- this._wireFormSync(inputEl, 'input');
333
-
334
- // Sync label changes
335
- const labelSync = this._syncBindings.find(b => b.property === 'label');
336
- if (labelSync) {
337
- const transform = labelSync.toComponent || ((v: any) => String(v));
338
- labelSync.stateObj.subscribe((val: any) => {
339
- this.label(transform(val));
340
- });
341
- }
342
-
343
- container.appendChild(wrapper);
344
-
345
-
346
- requestAnimationFrame(() => {
347
- if ((window as any).lucide) {
348
- (window as any).lucide.createIcons();
349
- }
350
- });
351
-
352
- return this;
353
- }
354
- }
355
-
356
- export function input(id: string, options: InputOptions = {}): Input {
357
- return new Input(id, options);
358
- }
359
-
360
- // Shorter, consistent naming
361
- export function text(id: string, options?: Omit<InputOptions, 'type'>): Input {
362
- return new Input(id, { ...options, type: 'text' });
363
- }
364
-
365
- export function textRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
366
- return new Input(id, { ...options, type: 'text', required: true });
367
- }
368
-
369
-
370
- export function number(id: string, options?: Omit<InputOptions, 'type'>): Input {
371
- return new Input(id, { ...options, type: 'number' });
372
- }
373
-
374
-
375
- export function numberRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
376
- return new Input(id, { ...options, type: 'number', required: true });
377
- }
378
-
379
-
380
- export function email(id: string, options?: Omit<InputOptions, 'type'>): Input {
381
- return new Input(id, { ...options, type: 'email' });
382
- }
383
-
384
- export function emailRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
385
- return new Input(id, { ...options, type: 'email', required: true });
386
- }
387
-
388
- export function password(id: string, options?: Omit<InputOptions, 'type'>): Input {
389
- return new Input(id, { ...options, type: 'password' });
390
- }
391
-
392
- export function passwordRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
393
- return new Input(id, { ...options, type: 'password', required: true });
394
- }
395
-
396
- export function tel(id: string, options?: Omit<InputOptions, 'type'>): Input {
397
- return new Input(id, { ...options, type: 'tel' });
398
- }
399
-
400
- export function telRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
401
- return new Input(id, { ...options, type: 'tel', required: true });
402
- }
403
-
404
- export function phone(id: string, options?: Omit<InputOptions, 'type'>): Input {
405
- return new Input(id, { ...options, type: 'tel' });
406
- }
407
- export function phoneRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
408
- return new Input(id, { ...options, type: 'tel', required: true });
409
- }
410
-
411
- export function url(id: string, options?: Omit<InputOptions, 'type'>): Input {
412
- return new Input(id, { ...options, type: 'url' });
413
- }
414
-
415
- export function urlRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
416
- return new Input(id, { ...options, type: 'url', required: true });
417
- }
418
- export function textarea(id: string, options?: Omit<InputOptions, 'type'>): Input {
419
- return new Input(id, { ...options, type: 'textarea' });
420
- }
421
- export function textareaRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
422
- return new Input(id, { ...options, type: 'textarea', required: true });
423
- }
424
-
425
- export function range(id: string, options?: Omit<InputOptions, 'type'>): Input {
426
- return new Input(id, { ...options, type: 'range' });
427
- }
428
-
429
- export function rangeRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
430
- return new Input(id, { ...options, type: 'range', required: true });
431
- }
432
-
433
-
434
- export function date(id: string, options?: Omit<InputOptions, 'type'>): Input {
435
- return new Input(id, { ...options, type: 'date' });
436
- }
437
-
438
-
439
- export function dateRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
440
- return new Input(id, { ...options, type: 'date', required: true });
441
- }
442
-
443
- export function time(id: string, options?: Omit<InputOptions, 'type'>): Input {
444
- return new Input(id, { ...options, type: 'time' });
445
- }
446
-
447
- export function timeRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
448
- return new Input(id, { ...options, type: 'time', required: true });
449
- }
450
-
451
- export function color(id: string, options?: Omit<InputOptions, 'type'>): Input {
452
- return new Input(id, { ...options, type: 'color' });
453
- }
454
-
455
- export function colorRequired(id: string, options?: Omit<InputOptions, 'type'>): Input {
456
- return new Input(id, { ...options, type: 'color', required: true });
457
- }