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,275 +0,0 @@
1
- import { BaseComponent } from './base/BaseComponent.js';
2
- import { renderIcon } from './icons.js';
3
- import { req } from './req.js';
4
-
5
- // Event definitions
6
- const TRIGGER_EVENTS = [] as const;
7
- const CALLBACK_EVENTS = ['itemClick'] as const; // ✅ Fire when menu item is clicked
8
-
9
- export interface MenuItem {
10
- label: string;
11
- href?: string;
12
- click?: () => void;
13
- icon?: string;
14
- items?: MenuItem[];
15
- active?: boolean;
16
- itemClass?: string;
17
- }
18
-
19
- export interface MenuOptions {
20
- items?: MenuItem[];
21
- orientation?: 'vertical' | 'horizontal';
22
- style?: string;
23
- class?: string;
24
- }
25
-
26
- type MenuState = {
27
- items: MenuItem[];
28
- orientation: string;
29
- style: string;
30
- class: string;
31
- };
32
-
33
- export class Menu extends BaseComponent<MenuState> {
34
- constructor(id: string, options: MenuOptions = {}) {
35
- super(id, {
36
- items: options.items ?? [],
37
- orientation: options.orientation ?? 'vertical',
38
- style: options.style ?? '',
39
- class: options.class ?? ''
40
- });
41
-
42
- this._setActiveStates();
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
- private _setActiveStates(): void {
54
- this.state.items = this.state.items.map(item => ({
55
- ...item,
56
- active: item.href ? req.isActiveNavItem(item.href) : false,
57
- items: item.items?.map(subItem => ({
58
- ...subItem,
59
- active: subItem.href ? req.isActiveNavItem(subItem.href) : false
60
- }))
61
- }));
62
- }
63
-
64
- /* ═════════════════════════════════════════════════════════════════
65
- * FLUENT API
66
- * ═════════════════════════════════════════════════════════════════ */
67
-
68
- // ✅ Inherited from BaseComponent
69
-
70
- items(value: MenuItem[]): this {
71
- this.state.items = value;
72
- this._setActiveStates();
73
- return this;
74
- }
75
-
76
- addItem(item: MenuItem): this {
77
- this.state.items = [...this.state.items, item];
78
- this._setActiveStates();
79
- return this;
80
- }
81
-
82
- itemClass(className: string): this {
83
- this.state.items = this.state.items.map(item => ({
84
- ...item,
85
- itemClass: className,
86
- items: item.items?.map(subItem => ({
87
- ...subItem,
88
- itemClass: className
89
- }))
90
- }));
91
- return this;
92
- }
93
-
94
- orientation(value: 'vertical' | 'horizontal'): this {
95
- this.state.orientation = value;
96
- return this;
97
- }
98
-
99
- /* ═════════════════════════════════════════════════════════════════
100
- * HELPERS
101
- * ═════════════════════════════════════════════════════════════════ */
102
-
103
- private _renderMenuItem(item: MenuItem): HTMLElement {
104
- const menuItem = document.createElement('div');
105
- menuItem.className = 'jux-menu-item';
106
-
107
- if (item.itemClass) {
108
- menuItem.className += ` ${item.itemClass}`;
109
- }
110
-
111
- if (item.active) {
112
- menuItem.classList.add('jux-menu-item-active');
113
- }
114
-
115
- if (item.href) {
116
- const link = document.createElement('a');
117
- link.className = 'jux-menu-link';
118
- link.href = item.href;
119
-
120
- if (item.active) {
121
- link.classList.add('jux-menu-link-active');
122
- }
123
-
124
- if (item.icon) {
125
- const icon = document.createElement('span');
126
- icon.className = 'jux-menu-icon';
127
- icon.appendChild(renderIcon(item.icon));
128
- link.appendChild(icon);
129
- }
130
-
131
- const label = document.createElement('span');
132
- label.className = 'jux-menu-label';
133
- label.textContent = item.label;
134
- link.appendChild(label);
135
-
136
- // ✅ Fire itemClick callback when link is clicked
137
- link.addEventListener('click', (e) => {
138
- this._triggerCallback('itemClick', { item, event: e });
139
- });
140
-
141
- menuItem.appendChild(link);
142
- } else {
143
- const button = document.createElement('button');
144
- button.className = 'jux-menu-button';
145
-
146
- if (item.icon) {
147
- const icon = document.createElement('span');
148
- icon.className = 'jux-menu-icon';
149
- icon.appendChild(renderIcon(item.icon));
150
- button.appendChild(icon);
151
- }
152
-
153
- const label = document.createElement('span');
154
- label.className = 'jux-menu-label';
155
- label.textContent = item.label;
156
- button.appendChild(label);
157
-
158
- menuItem.appendChild(button);
159
-
160
- // ✅ Fire both the item's click handler AND the callback event
161
- button.addEventListener('click', (e) => {
162
- if (item.click) {
163
- item.click();
164
- }
165
- this._triggerCallback('itemClick', { item, event: e });
166
- });
167
- }
168
-
169
- if (item.items && item.items.length > 0) {
170
- // Mark item as having submenu
171
- menuItem.classList.add('jux-menu-item-has-submenu');
172
-
173
- const submenu = document.createElement('div');
174
- submenu.className = 'jux-menu-submenu';
175
-
176
- item.items.forEach(subItem => {
177
- submenu.appendChild(this._renderMenuItem(subItem));
178
- });
179
-
180
- menuItem.appendChild(submenu);
181
-
182
- // Add click handler to toggle submenu expansion
183
- const clickTarget = menuItem.querySelector('a, button');
184
- if (clickTarget) {
185
- clickTarget.addEventListener('click', (e) => {
186
- // Prevent default link behavior if it has submenus
187
- if (!item.href) {
188
- e.preventDefault();
189
- }
190
- menuItem.classList.toggle('jux-menu-item-expanded');
191
- });
192
- }
193
- }
194
-
195
- return menuItem;
196
- }
197
-
198
- /* ═════════════════════════════════════════════════════════════════
199
- * RENDER
200
- * ═════════════════════════════════════════════════════════════════ */
201
-
202
- render(targetId?: string): this {
203
- const container = this._setupContainer(targetId);
204
-
205
- const { items, orientation, style, class: className } = this.state;
206
-
207
- const menu = document.createElement('nav');
208
- menu.className = `jux-menu jux-menu-${orientation}`;
209
- menu.id = this._id;
210
-
211
- if (className) {
212
- menu.className += ` ${className}`;
213
- }
214
-
215
- if (style) {
216
- menu.setAttribute('style', style);
217
- }
218
-
219
- items.forEach(item => {
220
- menu.appendChild(this._renderMenuItem(item));
221
- });
222
-
223
- this._wireStandardEvents(menu);
224
-
225
- // Wire sync bindings
226
- this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
227
- if (property === 'items') {
228
- const transform = toComponent || ((v: any) => v);
229
-
230
- stateObj.subscribe((val: any) => {
231
- const transformed = transform(val);
232
- this.state.items = transformed;
233
- this._setActiveStates();
234
-
235
- const existingItems = menu.querySelectorAll('.jux-menu-item');
236
- existingItems.forEach(item => item.remove());
237
-
238
- this.state.items.forEach(item => {
239
- menu.appendChild(this._renderMenuItem(item));
240
- });
241
-
242
- requestAnimationFrame(() => {
243
- if ((window as any).lucide) {
244
- (window as any).lucide.createIcons();
245
- }
246
- });
247
- });
248
- }
249
- else if (property === 'orientation') {
250
- const transform = toComponent || ((v: any) => String(v));
251
-
252
- stateObj.subscribe((val: any) => {
253
- const transformed = transform(val);
254
- menu.classList.remove(`jux-menu-${this.state.orientation}`);
255
- this.state.orientation = transformed;
256
- menu.classList.add(`jux-menu-${transformed}`);
257
- });
258
- }
259
- });
260
-
261
- container.appendChild(menu);
262
-
263
- requestAnimationFrame(() => {
264
- if ((window as any).lucide) {
265
- (window as any).lucide.createIcons();
266
- }
267
- });
268
-
269
- return this;
270
- }
271
- }
272
-
273
- export function menu(id: string, options: MenuOptions = {}): Menu {
274
- return new Menu(id, options);
275
- }
@@ -1,284 +0,0 @@
1
- import { BaseComponent } from './base/BaseComponent.js';
2
-
3
- // Event definitions
4
- const TRIGGER_EVENTS = [] as const;
5
- const CALLBACK_EVENTS = ['open', 'close'] as const;
6
-
7
- export interface ModalOptions {
8
- title?: string;
9
- content?: string;
10
- showCloseButton?: boolean;
11
- closeOnBackdropClick?: boolean;
12
- size?: 'small' | 'medium' | 'large';
13
- style?: string;
14
- class?: string;
15
- }
16
-
17
- type ModalState = {
18
- title: string;
19
- content: string;
20
- showCloseButton: boolean;
21
- closeOnBackdropClick: boolean;
22
- size: string;
23
- open: boolean;
24
- style: string;
25
- class: string;
26
- };
27
-
28
- export class Modal extends BaseComponent<ModalState> {
29
- private _overlay: HTMLElement | null = null;
30
-
31
- constructor(id: string, options: ModalOptions = {}) {
32
- super(id, {
33
- title: options.title ?? '',
34
- content: options.content ?? '',
35
- showCloseButton: options.showCloseButton ?? true,
36
- closeOnBackdropClick: options.closeOnBackdropClick ?? true,
37
- size: options.size ?? 'medium',
38
- open: false,
39
- style: options.style ?? '',
40
- class: options.class ?? ''
41
- });
42
- }
43
-
44
- protected getTriggerEvents(): readonly string[] {
45
- return TRIGGER_EVENTS;
46
- }
47
-
48
- protected getCallbackEvents(): readonly string[] {
49
- return CALLBACK_EVENTS;
50
- }
51
-
52
- /* ═════════════════════════════════════════════════════════════════
53
- * FLUENT API
54
- * ═════════════════════════════════════════════════════════════════ */
55
-
56
- // ✅ Inherited from BaseComponent:
57
- // - style(), class()
58
- // - bind(), sync(), renderTo()
59
- // - addClass(), removeClass(), toggleClass()
60
- // - visible(), show(), hide()
61
- // - attr(), attrs(), removeAttr()
62
-
63
- title(value: string): this {
64
- this.state.title = value;
65
- if (this._overlay) {
66
- const modal = this._overlay.querySelector('.jux-modal');
67
- const header = modal?.querySelector('.jux-modal-header');
68
- if (header) {
69
- header.textContent = value;
70
- }
71
- }
72
- return this;
73
- }
74
-
75
- content(value: string): this {
76
- this.state.content = value;
77
- if (this._overlay) {
78
- const body = this._overlay.querySelector('.jux-modal-body');
79
- if (body) {
80
- body.innerHTML = value;
81
- }
82
- }
83
- return this;
84
- }
85
-
86
- showCloseButton(value: boolean): this {
87
- this.state.showCloseButton = value;
88
- return this;
89
- }
90
-
91
- closeOnBackdropClick(value: boolean): this {
92
- this.state.closeOnBackdropClick = value;
93
- return this;
94
- }
95
-
96
- size(value: 'small' | 'medium' | 'large'): this {
97
- this.state.size = value;
98
- if (this._overlay) {
99
- const modal = this._overlay.querySelector('.jux-modal');
100
- if (modal) {
101
- modal.className = modal.className.replace(/jux-modal-(small|medium|large)/, `jux-modal-${value}`);
102
- }
103
- }
104
- return this;
105
- }
106
-
107
- open(): this {
108
- this.state.open = true;
109
- if (this._overlay) {
110
- this._overlay.style.display = 'flex';
111
- }
112
- // 🎯 Fire the open callback event
113
- this._triggerCallback('open');
114
- return this;
115
- }
116
-
117
- close(): this {
118
- this.state.open = false;
119
- if (this._overlay) {
120
- this._overlay.style.display = 'none';
121
- }
122
- // 🎯 Fire the close callback event
123
- this._triggerCallback('close');
124
- return this;
125
- }
126
-
127
- /**
128
- * Get the modal body element ID for rendering child components
129
- * @returns The ID of the modal body element (e.g., 'mymodal-body')
130
- *
131
- * Usage:
132
- * const modal = jux.modal('files-modal', { title: 'Files' }).render('body').open();
133
- * jux.table('files-table', {...}).render(modal.bodyId());
134
- */
135
- bodyId(): string {
136
- return `${this._id}-body`;
137
- }
138
-
139
- /**
140
- * Get the modal body element (only available after render)
141
- * @returns The modal body element or null if not rendered
142
- */
143
- getBodyElement(): HTMLElement | null {
144
- return document.getElementById(this.bodyId());
145
- }
146
-
147
- /* ═════════════════════════════════════════════════════════════════
148
- * RENDER
149
- * ═════════════════════════════════════════════════════════════════ */
150
-
151
- render(targetId?: string): this {
152
- const container = this._setupContainer(targetId);
153
-
154
- const { open, title, content, size, closeOnBackdropClick: closeOnBackdrop, showCloseButton: showClose, style, class: className } = this.state;
155
- const hasOpenSync = this._syncBindings.some(b => b.property === 'open');
156
-
157
- const overlay = document.createElement('div');
158
- overlay.className = 'jux-modal-overlay';
159
- overlay.id = this._id;
160
- overlay.style.display = open ? 'flex' : 'none';
161
- if (className) overlay.className += ` ${className}`;
162
- if (style) overlay.setAttribute('style', style);
163
- this._overlay = overlay;
164
-
165
- const modal = document.createElement('div');
166
- modal.className = `jux-modal jux-modal-${size}`;
167
-
168
- if (showClose) {
169
- const closeButton = document.createElement('button');
170
- closeButton.className = 'jux-modal-close';
171
- closeButton.innerHTML = '×';
172
- modal.appendChild(closeButton);
173
- }
174
-
175
- if (title) {
176
- const header = document.createElement('div');
177
- header.className = 'jux-modal-header';
178
- header.textContent = title;
179
- modal.appendChild(header);
180
- }
181
-
182
- const body = document.createElement('div');
183
- body.className = 'jux-modal-body';
184
- body.id = this.bodyId(); // Set predictable ID for child component rendering
185
- body.innerHTML = content;
186
- modal.appendChild(body);
187
-
188
- overlay.appendChild(modal);
189
-
190
- if (!hasOpenSync) {
191
- if (showClose) {
192
- const closeButton = modal.querySelector('.jux-modal-close');
193
- closeButton?.addEventListener('click', () => {
194
- this.state.open = false;
195
- overlay.style.display = 'none';
196
- });
197
- }
198
-
199
- if (closeOnBackdrop) {
200
- overlay.addEventListener('click', (e) => {
201
- if (e.target === overlay) {
202
- this.state.open = false;
203
- overlay.style.display = 'none';
204
- }
205
- });
206
- }
207
- }
208
-
209
- this._wireStandardEvents(overlay);
210
-
211
- this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
212
- if (property === 'open') {
213
- const transformToState = toState || ((v: any) => Boolean(v));
214
- const transformToComponent = toComponent || ((v: any) => Boolean(v));
215
-
216
- let isUpdating = false;
217
-
218
- stateObj.subscribe((val: any) => {
219
- if (isUpdating) return;
220
- const transformed = transformToComponent(val);
221
- this.state.open = transformed;
222
- overlay.style.display = transformed ? 'flex' : 'none';
223
- });
224
-
225
- if (showClose) {
226
- const closeButton = modal.querySelector('.jux-modal-close');
227
- closeButton?.addEventListener('click', () => {
228
- if (isUpdating) return;
229
- isUpdating = true;
230
-
231
- this.state.open = false;
232
- overlay.style.display = 'none';
233
- stateObj.set(transformToState(false));
234
-
235
- setTimeout(() => { isUpdating = false; }, 0);
236
- });
237
- }
238
-
239
- if (closeOnBackdrop) {
240
- overlay.addEventListener('click', (e) => {
241
- if (e.target === overlay) {
242
- if (isUpdating) return;
243
- isUpdating = true;
244
-
245
- this.state.open = false;
246
- overlay.style.display = 'none';
247
- stateObj.set(transformToState(false));
248
-
249
- setTimeout(() => { isUpdating = false; }, 0);
250
- }
251
- });
252
- }
253
- }
254
- else if (property === 'content') {
255
- const transform = toComponent || ((v: any) => String(v));
256
-
257
- stateObj.subscribe((val: any) => {
258
- const transformed = transform(val);
259
- body.innerHTML = transformed;
260
- this.state.content = transformed;
261
- });
262
- }
263
- else if (property === 'title') {
264
- const transform = toComponent || ((v: any) => String(v));
265
-
266
- stateObj.subscribe((val: any) => {
267
- const transformed = transform(val);
268
- const header = modal.querySelector('.jux-modal-header');
269
- if (header) {
270
- header.textContent = transformed;
271
- }
272
- this.state.title = transformed;
273
- });
274
- }
275
- });
276
-
277
- container.appendChild(overlay);
278
- return this;
279
- }
280
- }
281
-
282
- export function modal(id: string, options: ModalOptions = {}): Modal {
283
- return new Modal(id, options);
284
- }