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,234 @@
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'] as const;
7
+
8
+ export interface DatePickerOptions {
9
+ value?: string;
10
+ label?: string;
11
+ placeholder?: string;
12
+ required?: boolean;
13
+ disabled?: boolean;
14
+ name?: string;
15
+ min?: string;
16
+ max?: string;
17
+ style?: string;
18
+ class?: string;
19
+ onValidate?: (value: string) => boolean | string;
20
+ }
21
+
22
+ interface DatePickerState extends FormInputState {
23
+ value: string;
24
+ placeholder: string;
25
+ min?: string;
26
+ max?: string;
27
+ }
28
+
29
+ export class DatePicker extends FormInput<DatePickerState> {
30
+ constructor(id: string, options: DatePickerOptions = {}) {
31
+ super(id, {
32
+ value: options.value ?? '',
33
+ placeholder: options.placeholder ?? 'Select a date',
34
+ label: options.label ?? '',
35
+ required: options.required ?? false,
36
+ disabled: options.disabled ?? false,
37
+ name: options.name ?? id,
38
+ min: options.min,
39
+ max: options.max,
40
+ style: options.style ?? '',
41
+ class: options.class ?? '',
42
+ errorMessage: undefined
43
+ });
44
+
45
+ if (options.onValidate) {
46
+ this._onValidate = options.onValidate;
47
+ }
48
+ }
49
+
50
+ protected getTriggerEvents(): readonly string[] {
51
+ return TRIGGER_EVENTS;
52
+ }
53
+
54
+ protected getCallbackEvents(): readonly string[] {
55
+ return CALLBACK_EVENTS;
56
+ }
57
+
58
+ /* ═════════════════════════════════════════════════════════════════
59
+ * FLUENT API
60
+ * ═════════════════════════════════════════════════════════════════ */
61
+
62
+ // ✅ Inherited from FormInput/BaseComponent:
63
+ // - label(), required(), name(), onValidate()
64
+ // - validate(), isValid()
65
+ // - style(), class()
66
+ // - bind(), sync(), renderTo()
67
+ // - disabled(), enable(), disable()
68
+
69
+ value(value: string): this {
70
+ return this.setValue(value);
71
+ }
72
+
73
+ placeholder(value: string): this {
74
+ this.state.placeholder = value;
75
+ return this;
76
+ }
77
+
78
+ min(value: string): this {
79
+ this.state.min = value;
80
+ return this;
81
+ }
82
+
83
+ max(value: string): this {
84
+ this.state.max = value;
85
+ return this;
86
+ }
87
+
88
+ /* ═════════════════════════════════════════════════════════════════
89
+ * FORM INPUT IMPLEMENTATION
90
+ * ═════════════════════════════════════════════════════════════════ */
91
+
92
+ getValue(): string {
93
+ return this.state.value;
94
+ }
95
+
96
+ setValue(value: string): this {
97
+ this.state.value = value;
98
+ if (this._inputElement) {
99
+ (this._inputElement as HTMLInputElement).value = value;
100
+ }
101
+ return this;
102
+ }
103
+
104
+ getDate(): Date | null {
105
+ if (!this.state.value) return null;
106
+ const date = new Date(this.state.value);
107
+ return isNaN(date.getTime()) ? null : date;
108
+ }
109
+
110
+ protected _validateValue(value: string): boolean | string {
111
+ const { required, min, max } = this.state;
112
+
113
+ if (required && !value) {
114
+ return 'Please select a date';
115
+ }
116
+
117
+ if (value) {
118
+ const date = new Date(value);
119
+
120
+ if (isNaN(date.getTime())) {
121
+ return 'Invalid date';
122
+ }
123
+
124
+ if (min) {
125
+ const minDate = new Date(min);
126
+ if (date < minDate) {
127
+ return `Date must be on or after ${min}`;
128
+ }
129
+ }
130
+
131
+ if (max) {
132
+ const maxDate = new Date(max);
133
+ if (date > maxDate) {
134
+ return `Date must be on or before ${max}`;
135
+ }
136
+ }
137
+ }
138
+
139
+ if (this._onValidate) {
140
+ const result = this._onValidate(value);
141
+ if (result !== true) {
142
+ return result || 'Invalid date';
143
+ }
144
+ }
145
+
146
+ return true;
147
+ }
148
+
149
+ protected _buildInputElement(): HTMLElement {
150
+ const { value, placeholder, required, disabled, name, min, max } = this.state;
151
+
152
+ const input = document.createElement('input');
153
+ input.type = 'date';
154
+ input.className = 'jux-input-element jux-datepicker-input';
155
+ input.id = `${this._id}-input`;
156
+ input.name = name;
157
+ input.value = value;
158
+ input.placeholder = placeholder;
159
+ input.required = required;
160
+ input.disabled = disabled;
161
+
162
+ if (min) input.min = min;
163
+ if (max) input.max = max;
164
+
165
+ return input;
166
+ }
167
+
168
+ /* ═════════════════════════════════════════════════════════════════
169
+ * RENDER
170
+ * ═════════════════════════════════════════════════════════════════ */
171
+
172
+ render(targetId?: string): this {
173
+ const container = this._setupContainer(targetId);
174
+
175
+ const { style, class: className } = this.state;
176
+
177
+ // Build wrapper
178
+ const wrapper = document.createElement('div');
179
+ wrapper.className = 'jux-input jux-datepicker';
180
+ wrapper.id = this._id;
181
+ if (className) wrapper.className += ` ${className}`;
182
+ if (style) wrapper.setAttribute('style', style);
183
+
184
+ // Label
185
+ if (this.state.label) {
186
+ wrapper.appendChild(this._renderLabel());
187
+ }
188
+
189
+ // Input container
190
+ const inputContainer = document.createElement('div');
191
+ inputContainer.className = 'jux-input-container jux-datepicker-container';
192
+
193
+ // Calendar icon
194
+ const iconEl = document.createElement('span');
195
+ iconEl.className = 'jux-input-icon';
196
+ iconEl.appendChild(renderIcon('calendar'));
197
+ inputContainer.appendChild(iconEl);
198
+
199
+ // Date input
200
+ const inputEl = this._buildInputElement();
201
+ this._inputElement = inputEl;
202
+ inputContainer.appendChild(inputEl);
203
+ wrapper.appendChild(inputContainer);
204
+
205
+ // Error element
206
+ wrapper.appendChild(this._renderError());
207
+
208
+ // Wire events
209
+ this._wireStandardEvents(wrapper);
210
+ this._wireFormSync(inputEl, 'change');
211
+
212
+ // 🎯 Fire change event when date changes
213
+ inputEl.addEventListener('change', () => {
214
+ const input = inputEl as HTMLInputElement;
215
+ this._triggerCallback('change', input.value);
216
+ });
217
+
218
+ // Sync label changes
219
+ const labelSync = this._syncBindings.find(b => b.property === 'label');
220
+ if (labelSync) {
221
+ const transform = labelSync.toComponent || ((v: any) => String(v));
222
+ labelSync.stateObj.subscribe((val: any) => {
223
+ this.label(transform(val));
224
+ });
225
+ }
226
+
227
+ container.appendChild(wrapper);
228
+ return this;
229
+ }
230
+ }
231
+
232
+ export function datepicker(id: string, options: DatePickerOptions = {}): DatePicker {
233
+ return new DatePicker(id, options);
234
+ }
@@ -0,0 +1,172 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = ['confirm', 'cancel'] as const;
6
+
7
+ export interface DialogOptions {
8
+ title?: string;
9
+ message?: string;
10
+ confirmText?: string;
11
+ cancelText?: string;
12
+ variant?: 'default' | 'danger' | 'warning';
13
+ style?: string;
14
+ class?: string;
15
+ }
16
+
17
+ type DialogState = {
18
+ title: string;
19
+ message: string;
20
+ confirmText: string;
21
+ cancelText: string;
22
+ variant: string;
23
+ open: boolean;
24
+ style: string;
25
+ class: string;
26
+ };
27
+
28
+ export class Dialog extends BaseComponent<DialogState> {
29
+ private _dialog: HTMLElement | null = null;
30
+ private _overlay: HTMLElement | null = null;
31
+
32
+ constructor(id: string, options: DialogOptions = {}) {
33
+ super(id, {
34
+ title: options.title ?? 'Confirm',
35
+ message: options.message ?? 'Are you sure?',
36
+ confirmText: options.confirmText ?? 'Confirm',
37
+ cancelText: options.cancelText ?? 'Cancel',
38
+ variant: options.variant ?? 'default',
39
+ open: false,
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
+ title(value: string): this {
58
+ this.state.title = value;
59
+ return this;
60
+ }
61
+
62
+ message(value: string): this {
63
+ this.state.message = value;
64
+ return this;
65
+ }
66
+
67
+ confirmText(value: string): this {
68
+ this.state.confirmText = value;
69
+ return this;
70
+ }
71
+
72
+ cancelText(value: string): this {
73
+ this.state.cancelText = value;
74
+ return this;
75
+ }
76
+
77
+ variant(value: 'default' | 'danger' | 'warning'): this {
78
+ this.state.variant = value;
79
+ return this;
80
+ }
81
+
82
+ open(): this {
83
+ this.state.open = true;
84
+ if (this._overlay) {
85
+ this._overlay.style.display = 'flex';
86
+ }
87
+ return this;
88
+ }
89
+
90
+ close(): this {
91
+ this.state.open = false;
92
+ if (this._overlay) {
93
+ this._overlay.style.display = 'none';
94
+ }
95
+ return this;
96
+ }
97
+
98
+ /* ═════════════════════════════════════════════════════════════════
99
+ * RENDER
100
+ * ═════════════════════════════════════════════════════════════════ */
101
+
102
+ render(targetId?: string): this {
103
+ const { title, message, confirmText, cancelText, variant, style, class: className } = this.state;
104
+
105
+ // Overlay
106
+ const overlay = document.createElement('div');
107
+ overlay.className = 'jux-dialog-overlay';
108
+ overlay.style.display = 'none';
109
+ this._overlay = overlay;
110
+
111
+ // Dialog
112
+ const dialog = document.createElement('div');
113
+ dialog.className = `jux-dialog jux-dialog-${variant}`;
114
+ dialog.id = this._id;
115
+ if (className) dialog.className += ` ${className}`;
116
+ if (style) dialog.setAttribute('style', style);
117
+ this._dialog = dialog;
118
+
119
+ // Title
120
+ const titleEl = document.createElement('div');
121
+ titleEl.className = 'jux-dialog-title';
122
+ titleEl.textContent = title;
123
+ dialog.appendChild(titleEl);
124
+
125
+ // Message
126
+ const messageEl = document.createElement('div');
127
+ messageEl.className = 'jux-dialog-message';
128
+ messageEl.textContent = message;
129
+ dialog.appendChild(messageEl);
130
+
131
+ // Actions
132
+ const actions = document.createElement('div');
133
+ actions.className = 'jux-dialog-actions';
134
+
135
+ const cancelBtn = document.createElement('button');
136
+ cancelBtn.className = 'jux-dialog-button jux-dialog-button-cancel';
137
+ cancelBtn.textContent = cancelText;
138
+ cancelBtn.addEventListener('click', () => {
139
+ this._triggerCallback('cancel');
140
+ this.close();
141
+ });
142
+
143
+ const confirmBtn = document.createElement('button');
144
+ confirmBtn.className = `jux-dialog-button jux-dialog-button-confirm jux-dialog-button-${variant}`;
145
+ confirmBtn.textContent = confirmText;
146
+ confirmBtn.addEventListener('click', () => {
147
+ this._triggerCallback('confirm');
148
+ this.close();
149
+ });
150
+
151
+ actions.appendChild(cancelBtn);
152
+ actions.appendChild(confirmBtn);
153
+ dialog.appendChild(actions);
154
+
155
+ // Close on overlay click
156
+ overlay.addEventListener('click', (e) => {
157
+ if (e.target === overlay) {
158
+ this._triggerCallback('cancel');
159
+ this.close();
160
+ }
161
+ });
162
+
163
+ overlay.appendChild(dialog);
164
+ document.body.appendChild(overlay);
165
+
166
+ return this;
167
+ }
168
+ }
169
+
170
+ export function dialog(id: string, options: DialogOptions = {}): Dialog {
171
+ return new Dialog(id, options);
172
+ }
@@ -0,0 +1,100 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = [] as const;
6
+
7
+ export interface DividerOptions {
8
+ text?: string;
9
+ variant?: 'default' | 'dashed' | 'dotted';
10
+ margin?: string;
11
+ style?: string;
12
+ class?: string;
13
+ }
14
+
15
+ type DividerState = {
16
+ text: string;
17
+ variant: string;
18
+ margin: string;
19
+ style: string;
20
+ class: string;
21
+ orientation: string;
22
+ };
23
+
24
+ export class Divider extends BaseComponent<DividerState> {
25
+ constructor(id: string = `divider-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, options: DividerOptions = {}) {
26
+ super(id, {
27
+ text: options.text ?? '',
28
+ variant: options.variant ?? 'default',
29
+ margin: options.margin ?? '1rem 0',
30
+ style: options.style ?? '',
31
+ class: options.class ?? '',
32
+ orientation: 'horizontal'
33
+ });
34
+ }
35
+
36
+ protected getTriggerEvents(): readonly string[] {
37
+ return TRIGGER_EVENTS;
38
+ }
39
+
40
+ protected getCallbackEvents(): readonly string[] {
41
+ return CALLBACK_EVENTS;
42
+ }
43
+
44
+ text(value: string): this {
45
+ this.state.text = value;
46
+ return this;
47
+ }
48
+
49
+ orientation(value: 'horizontal' | 'vertical'): this {
50
+ this.state.orientation = value;
51
+ return this;
52
+ }
53
+
54
+ style(value: string): this {
55
+ this.state.style = value;
56
+ return this;
57
+ }
58
+
59
+ class(value: string): this {
60
+ this.state.class = value;
61
+ return this;
62
+ }
63
+
64
+ render(targetId?: string): this {
65
+ const container = this._setupContainer(targetId);
66
+
67
+ const { text, variant, margin, style, class: className } = this.state;
68
+
69
+ const divider = document.createElement('div');
70
+ divider.className = `jux-divider jux-divider-${variant}`;
71
+ divider.id = this._id;
72
+ divider.style.margin = margin;
73
+ if (className) divider.className += ` ${className}`;
74
+ if (style) divider.setAttribute('style', `${divider.getAttribute('style')}; ${style}`);
75
+
76
+ if (text) {
77
+ const textEl = document.createElement('span');
78
+ textEl.className = 'jux-divider-text';
79
+ textEl.textContent = text;
80
+ divider.appendChild(textEl);
81
+ }
82
+
83
+ this._wireStandardEvents(divider);
84
+ container.appendChild(divider);
85
+
86
+ return this;
87
+ }
88
+
89
+ renderTo(juxComponent: any): this {
90
+ if (!juxComponent?._id) {
91
+ throw new Error('Divider.renderTo: Invalid component');
92
+ }
93
+ return this.render(`#${juxComponent._id}`);
94
+ }
95
+ }
96
+
97
+ // ✅ ID is now optional - auto-generated if not provided
98
+ export function divider(options: DividerOptions = {}): Divider {
99
+ return new Divider(undefined, options);
100
+ }
@@ -0,0 +1,186 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = ['select'] as const;
6
+
7
+ export interface DropdownItem {
8
+ label?: string;
9
+ icon?: string;
10
+ divider?: boolean;
11
+ click?: () => void;
12
+ }
13
+
14
+ export interface DropdownOptions {
15
+ triggerLabel?: string;
16
+ items?: DropdownItem[];
17
+ position?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
18
+ style?: string;
19
+ class?: string;
20
+ }
21
+
22
+ type DropdownState = {
23
+ triggerLabel: string;
24
+ items: DropdownItem[];
25
+ position: string;
26
+ open: boolean;
27
+ style: string;
28
+ class: string;
29
+ };
30
+
31
+ export class Dropdown extends BaseComponent<DropdownState> {
32
+ private _dropdown: HTMLElement | null = null;
33
+ private _menu: HTMLElement | null = null;
34
+
35
+ constructor(id: string, options: DropdownOptions = {}) {
36
+ super(id, {
37
+ triggerLabel: options.triggerLabel ?? 'Menu',
38
+ items: options.items ?? [],
39
+ position: options.position ?? 'bottom-left',
40
+ open: false,
41
+ style: options.style ?? '',
42
+ class: options.class ?? ''
43
+ });
44
+ }
45
+
46
+ protected getTriggerEvents(): readonly string[] {
47
+ return TRIGGER_EVENTS;
48
+ }
49
+
50
+ protected getCallbackEvents(): readonly string[] {
51
+ return CALLBACK_EVENTS;
52
+ }
53
+
54
+ /* ═════════════════════════════════════════════════════════════════
55
+ * FLUENT API
56
+ * ═════════════════════════════════════════════════════════════════ */
57
+
58
+ triggerLabel(value: string): this {
59
+ this.state.triggerLabel = value;
60
+ return this;
61
+ }
62
+
63
+ items(value: DropdownItem[]): this {
64
+ this.state.items = value;
65
+ return this;
66
+ }
67
+
68
+ position(value: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'): this {
69
+ this.state.position = value;
70
+ return this;
71
+ }
72
+
73
+ open(): this {
74
+ this.state.open = true;
75
+ if (this._menu) {
76
+ this._menu.style.display = 'block';
77
+ }
78
+ return this;
79
+ }
80
+
81
+ close(): this {
82
+ this.state.open = false;
83
+ if (this._menu) {
84
+ this._menu.style.display = 'none';
85
+ }
86
+ return this;
87
+ }
88
+
89
+ toggle(): this {
90
+ return this.state.open ? this.close() : this.open();
91
+ }
92
+
93
+ /* ═════════════════════════════════════════════════════════════════
94
+ * RENDER
95
+ * ═════════════════════════════════════════════════════════════════ */
96
+
97
+ render(targetId?: string): this {
98
+ const container = this._setupContainer(targetId);
99
+
100
+ const { triggerLabel, items, position, style, class: className } = this.state;
101
+
102
+ const wrapper = document.createElement('div');
103
+ wrapper.className = 'jux-dropdown';
104
+ wrapper.id = this._id;
105
+ if (className) wrapper.className += ` ${className}`;
106
+ if (style) wrapper.setAttribute('style', style);
107
+
108
+ // Trigger button
109
+ const triggerBtn = document.createElement('button');
110
+ triggerBtn.className = 'jux-dropdown-trigger';
111
+ triggerBtn.textContent = triggerLabel;
112
+ triggerBtn.type = 'button';
113
+
114
+ // Dropdown menu
115
+ const menu = document.createElement('div');
116
+ menu.className = `jux-dropdown-menu jux-dropdown-${position}`;
117
+ menu.style.display = 'none';
118
+ this._menu = menu;
119
+
120
+ items.forEach(item => {
121
+ if (item.divider) {
122
+ const divider = document.createElement('div');
123
+ divider.className = 'jux-dropdown-divider';
124
+ menu.appendChild(divider);
125
+ } else {
126
+ const menuItem = document.createElement('button');
127
+ menuItem.className = 'jux-dropdown-item';
128
+ menuItem.type = 'button';
129
+
130
+ if (item.icon) {
131
+ const icon = document.createElement('span');
132
+ icon.className = 'jux-dropdown-icon';
133
+ icon.textContent = item.icon;
134
+ menuItem.appendChild(icon);
135
+ }
136
+
137
+ if (item.label) {
138
+ const label = document.createElement('span');
139
+ label.textContent = item.label;
140
+ menuItem.appendChild(label);
141
+ }
142
+
143
+ menuItem.addEventListener('click', () => {
144
+ // 🎯 Fire the select callback event
145
+ this._triggerCallback('select', item);
146
+
147
+ // Then fire item-specific click handler
148
+ if (item.click) {
149
+ item.click();
150
+ }
151
+
152
+ this.close();
153
+ });
154
+
155
+ menu.appendChild(menuItem);
156
+ }
157
+ });
158
+
159
+ // Toggle on trigger click
160
+ triggerBtn.addEventListener('click', (e) => {
161
+ e.stopPropagation();
162
+ this.toggle();
163
+ });
164
+
165
+ // Close on outside click
166
+ document.addEventListener('click', (e) => {
167
+ if (this._dropdown && !this._dropdown.contains(e.target as Node)) {
168
+ this.close();
169
+ }
170
+ });
171
+
172
+ wrapper.appendChild(triggerBtn);
173
+ wrapper.appendChild(menu);
174
+
175
+ this._wireStandardEvents(wrapper);
176
+
177
+ container.appendChild(wrapper);
178
+ this._dropdown = wrapper;
179
+
180
+ return this;
181
+ }
182
+ }
183
+
184
+ export function dropdown(id: string, options: DropdownOptions = {}): Dropdown {
185
+ return new Dropdown(id, options);
186
+ }