juxscript 1.1.4 → 1.1.6

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 (205) hide show
  1. package/index.d.ts +10 -10
  2. package/index.d.ts.map +1 -0
  3. package/lib/components/alert.d.ts +32 -0
  4. package/lib/components/alert.d.ts.map +1 -0
  5. package/lib/components/alert.js +153 -0
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.d.ts +89 -0
  8. package/lib/components/app.d.ts.map +1 -0
  9. package/lib/components/app.js +175 -0
  10. package/lib/components/app.ts +247 -0
  11. package/lib/components/badge.d.ts +27 -0
  12. package/lib/components/badge.d.ts.map +1 -0
  13. package/lib/components/badge.js +70 -0
  14. package/lib/components/badge.ts +101 -0
  15. package/lib/components/base/BaseComponent.d.ts +142 -0
  16. package/lib/components/base/BaseComponent.d.ts.map +1 -0
  17. package/lib/components/base/BaseComponent.js +363 -0
  18. package/lib/components/base/BaseComponent.ts +421 -0
  19. package/lib/components/base/FormInput.d.ts +73 -0
  20. package/lib/components/base/FormInput.d.ts.map +1 -0
  21. package/lib/components/base/FormInput.js +163 -0
  22. package/lib/components/base/FormInput.ts +227 -0
  23. package/lib/components/button.d.ts +48 -0
  24. package/lib/components/button.d.ts.map +1 -0
  25. package/lib/components/button.js +121 -0
  26. package/lib/components/button.ts +178 -0
  27. package/lib/components/card.d.ts +34 -0
  28. package/lib/components/card.d.ts.map +1 -0
  29. package/lib/components/card.js +127 -0
  30. package/lib/components/card.ts +173 -0
  31. package/lib/components/chart.d.ts +45 -0
  32. package/lib/components/chart.d.ts.map +1 -0
  33. package/lib/components/chart.js +186 -0
  34. package/lib/components/chart.ts +231 -0
  35. package/lib/components/checkbox.d.ts +31 -0
  36. package/lib/components/checkbox.d.ts.map +1 -0
  37. package/lib/components/checkbox.js +185 -0
  38. package/lib/components/checkbox.ts +242 -0
  39. package/lib/components/code.d.ts +24 -0
  40. package/lib/components/code.d.ts.map +1 -0
  41. package/lib/components/code.js +88 -0
  42. package/lib/components/code.ts +123 -0
  43. package/lib/components/container.d.ts +42 -0
  44. package/lib/components/container.d.ts.map +1 -0
  45. package/lib/components/container.js +93 -0
  46. package/lib/components/container.ts +140 -0
  47. package/lib/components/data.d.ts +36 -0
  48. package/lib/components/data.d.ts.map +1 -0
  49. package/lib/components/data.js +110 -0
  50. package/lib/components/data.ts +135 -0
  51. package/lib/components/datepicker.d.ts +38 -0
  52. package/lib/components/datepicker.d.ts.map +1 -0
  53. package/lib/components/datepicker.js +177 -0
  54. package/lib/components/datepicker.ts +234 -0
  55. package/lib/components/dialog.d.ts +38 -0
  56. package/lib/components/dialog.d.ts.map +1 -0
  57. package/lib/components/dialog.js +126 -0
  58. package/lib/components/dialog.ts +172 -0
  59. package/lib/components/divider.d.ts +30 -0
  60. package/lib/components/divider.d.ts.map +1 -0
  61. package/lib/components/divider.js +69 -0
  62. package/lib/components/divider.ts +100 -0
  63. package/lib/components/dropdown.d.ts +39 -0
  64. package/lib/components/dropdown.d.ts.map +1 -0
  65. package/lib/components/dropdown.js +133 -0
  66. package/lib/components/dropdown.ts +186 -0
  67. package/lib/components/element.d.ts +50 -0
  68. package/lib/components/element.d.ts.map +1 -0
  69. package/lib/components/element.js +206 -0
  70. package/lib/components/element.ts +267 -0
  71. package/lib/components/fileupload.d.ts +40 -0
  72. package/lib/components/fileupload.d.ts.map +1 -0
  73. package/lib/components/fileupload.js +241 -0
  74. package/lib/components/fileupload.ts +309 -0
  75. package/lib/components/grid.d.ts +87 -0
  76. package/lib/components/grid.d.ts.map +1 -0
  77. package/lib/components/grid.js +205 -0
  78. package/lib/components/grid.ts +291 -0
  79. package/lib/components/guard.d.ts +41 -0
  80. package/lib/components/guard.d.ts.map +1 -0
  81. package/lib/components/guard.js +56 -0
  82. package/lib/components/guard.ts +92 -0
  83. package/lib/components/heading.d.ts +24 -0
  84. package/lib/components/heading.d.ts.map +1 -0
  85. package/lib/components/heading.js +67 -0
  86. package/lib/components/heading.ts +96 -0
  87. package/lib/components/helpers.d.ts +9 -0
  88. package/lib/components/helpers.d.ts.map +1 -0
  89. package/lib/components/helpers.js +30 -0
  90. package/lib/components/helpers.ts +41 -0
  91. package/lib/components/hero.d.ts +45 -0
  92. package/lib/components/hero.d.ts.map +1 -0
  93. package/lib/components/hero.js +165 -0
  94. package/lib/components/hero.ts +224 -0
  95. package/lib/components/icon.d.ts +35 -0
  96. package/lib/components/icon.d.ts.map +1 -0
  97. package/lib/components/icon.js +132 -0
  98. package/lib/components/icon.ts +178 -0
  99. package/lib/components/icons.d.ts +25 -0
  100. package/lib/components/icons.d.ts.map +1 -0
  101. package/lib/components/icons.js +440 -0
  102. package/lib/components/icons.ts +464 -0
  103. package/lib/components/include.d.ts +120 -0
  104. package/lib/components/include.d.ts.map +1 -0
  105. package/lib/components/include.js +350 -0
  106. package/lib/components/include.ts +410 -0
  107. package/lib/components/input.d.ts +83 -0
  108. package/lib/components/input.d.ts.map +1 -0
  109. package/lib/components/input.js +348 -0
  110. package/lib/components/input.ts +457 -0
  111. package/lib/components/list.d.ts +82 -0
  112. package/lib/components/list.d.ts.map +1 -0
  113. package/lib/components/list.js +311 -0
  114. package/lib/components/list.ts +419 -0
  115. package/lib/components/loading.d.ts +24 -0
  116. package/lib/components/loading.d.ts.map +1 -0
  117. package/lib/components/loading.js +73 -0
  118. package/lib/components/loading.ts +100 -0
  119. package/lib/components/menu.d.ts +37 -0
  120. package/lib/components/menu.d.ts.map +1 -0
  121. package/lib/components/menu.js +202 -0
  122. package/lib/components/menu.ts +275 -0
  123. package/lib/components/modal.d.ts +51 -0
  124. package/lib/components/modal.d.ts.map +1 -0
  125. package/lib/components/modal.js +227 -0
  126. package/lib/components/modal.ts +284 -0
  127. package/lib/components/nav.d.ts +45 -0
  128. package/lib/components/nav.d.ts.map +1 -0
  129. package/lib/components/nav.js +190 -0
  130. package/lib/components/nav.ts +257 -0
  131. package/lib/components/paragraph.d.ts +21 -0
  132. package/lib/components/paragraph.d.ts.map +1 -0
  133. package/lib/components/paragraph.js +70 -0
  134. package/lib/components/paragraph.ts +97 -0
  135. package/lib/components/progress.d.ts +39 -0
  136. package/lib/components/progress.d.ts.map +1 -0
  137. package/lib/components/progress.js +113 -0
  138. package/lib/components/progress.ts +159 -0
  139. package/lib/components/radio.d.ts +41 -0
  140. package/lib/components/radio.d.ts.map +1 -0
  141. package/lib/components/radio.js +203 -0
  142. package/lib/components/radio.ts +278 -0
  143. package/lib/components/req.d.ts +155 -0
  144. package/lib/components/req.d.ts.map +1 -0
  145. package/lib/components/req.js +253 -0
  146. package/lib/components/req.ts +303 -0
  147. package/lib/components/script.d.ts +14 -0
  148. package/lib/components/script.d.ts.map +1 -0
  149. package/lib/components/script.js +33 -0
  150. package/lib/components/script.ts +41 -0
  151. package/lib/components/select.d.ts +40 -0
  152. package/lib/components/select.d.ts.map +1 -0
  153. package/lib/components/select.js +183 -0
  154. package/lib/components/select.ts +252 -0
  155. package/lib/components/sidebar.d.ts +48 -0
  156. package/lib/components/sidebar.d.ts.map +1 -0
  157. package/lib/components/sidebar.js +207 -0
  158. package/lib/components/sidebar.ts +275 -0
  159. package/lib/components/style.d.ts +14 -0
  160. package/lib/components/style.d.ts.map +1 -0
  161. package/lib/components/style.js +33 -0
  162. package/lib/components/style.ts +41 -0
  163. package/lib/components/switch.d.ts +32 -0
  164. package/lib/components/switch.d.ts.map +1 -0
  165. package/lib/components/switch.js +186 -0
  166. package/lib/components/switch.ts +246 -0
  167. package/lib/components/table.d.ts +137 -0
  168. package/lib/components/table.d.ts.map +1 -0
  169. package/lib/components/table.js +1045 -0
  170. package/lib/components/table.ts +1249 -0
  171. package/lib/components/tabs.d.ts +36 -0
  172. package/lib/components/tabs.d.ts.map +1 -0
  173. package/lib/components/tabs.js +198 -0
  174. package/lib/components/tabs.ts +250 -0
  175. package/lib/components/theme-toggle.d.ts +44 -0
  176. package/lib/components/theme-toggle.d.ts.map +1 -0
  177. package/lib/components/theme-toggle.js +215 -0
  178. package/lib/components/theme-toggle.ts +293 -0
  179. package/lib/components/tooltip.d.ts +30 -0
  180. package/lib/components/tooltip.d.ts.map +1 -0
  181. package/lib/components/tooltip.js +109 -0
  182. package/lib/components/tooltip.ts +144 -0
  183. package/lib/components/view.d.ts +48 -0
  184. package/lib/components/view.d.ts.map +1 -0
  185. package/lib/components/view.js +149 -0
  186. package/lib/components/view.ts +190 -0
  187. package/lib/components/write.d.ts +107 -0
  188. package/lib/components/write.d.ts.map +1 -0
  189. package/lib/components/write.js +222 -0
  190. package/lib/components/write.ts +272 -0
  191. package/lib/layouts/default.css +260 -0
  192. package/lib/layouts/figma.css +334 -0
  193. package/lib/reactivity/state.d.ts +36 -0
  194. package/lib/reactivity/state.d.ts.map +1 -0
  195. package/lib/reactivity/state.js +67 -0
  196. package/lib/reactivity/state.ts +78 -0
  197. package/lib/utils/fetch.d.ts +176 -0
  198. package/lib/utils/fetch.d.ts.map +1 -0
  199. package/lib/utils/fetch.js +427 -0
  200. package/lib/utils/fetch.ts +553 -0
  201. package/machinery/compiler3.js +78 -0
  202. package/machinery/doc-generator.js +136 -0
  203. package/machinery/imports.js +155 -0
  204. package/machinery/ts-shim.js +46 -0
  205. package/package.json +9 -15
@@ -0,0 +1,252 @@
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 SelectOption {
8
+ label: string;
9
+ value: string;
10
+ disabled?: boolean;
11
+ }
12
+
13
+ export interface SelectOptions {
14
+ options?: SelectOption[];
15
+ value?: string;
16
+ label?: string;
17
+ placeholder?: string;
18
+ required?: boolean;
19
+ disabled?: boolean;
20
+ name?: string;
21
+ style?: string;
22
+ class?: string;
23
+ onValidate?: (value: string) => boolean | string;
24
+ }
25
+
26
+ interface SelectState extends FormInputState {
27
+ options: SelectOption[];
28
+ value: string;
29
+ placeholder: string;
30
+ }
31
+
32
+ export class Select extends FormInput<SelectState> {
33
+ constructor(id: string, options: SelectOptions = {}) {
34
+ super(id, {
35
+ options: options.options ?? [],
36
+ value: options.value ?? '',
37
+ placeholder: options.placeholder ?? 'Select an option',
38
+ label: options.label ?? '',
39
+ required: options.required ?? false,
40
+ disabled: options.disabled ?? false,
41
+ name: options.name ?? id,
42
+ style: options.style ?? '',
43
+ class: options.class ?? '',
44
+ errorMessage: undefined
45
+ });
46
+
47
+ if (options.onValidate) {
48
+ this._onValidate = options.onValidate;
49
+ }
50
+ }
51
+
52
+ protected getTriggerEvents(): readonly string[] {
53
+ return TRIGGER_EVENTS;
54
+ }
55
+
56
+ protected getCallbackEvents(): readonly string[] {
57
+ return CALLBACK_EVENTS;
58
+ }
59
+
60
+ /* ═════════════════════════════════════════════════════════════════
61
+ * FLUENT API
62
+ * ═════════════════════════════════════════════════════════════════ */
63
+
64
+ // ✅ Inherited from FormInput/BaseComponent:
65
+ // - label(), required(), name(), onValidate()
66
+ // - validate(), isValid()
67
+ // - style(), class()
68
+ // - bind(), sync(), renderTo()
69
+ // - disabled(), enable(), disable()
70
+
71
+ options(value: SelectOption[]): this {
72
+ this.state.options = value;
73
+ return this;
74
+ }
75
+
76
+ value(value: string): this {
77
+ return this.setValue(value);
78
+ }
79
+
80
+ placeholder(value: string): this {
81
+ this.state.placeholder = value;
82
+ return this;
83
+ }
84
+
85
+ addOption(option: SelectOption): this {
86
+ this.state.options = [...this.state.options, option];
87
+ return this;
88
+ }
89
+
90
+ /* ═════════════════════════════════════════════════════════════════
91
+ * FORM INPUT IMPLEMENTATION
92
+ * ═════════════════════════════════════════════════════════════════ */
93
+
94
+ getValue(): string {
95
+ return this.state.value;
96
+ }
97
+
98
+ setValue(value: string): this {
99
+ this.state.value = value;
100
+
101
+ if (this._inputElement) {
102
+ (this._inputElement as HTMLSelectElement).value = value;
103
+ }
104
+
105
+ return this;
106
+ }
107
+
108
+ protected _validateValue(value: string): boolean | string {
109
+ const { required, options } = this.state;
110
+
111
+ if (required && !value) {
112
+ return 'Please select an option';
113
+ }
114
+
115
+ // Validate that value is one of the options
116
+ if (value && !options.some(opt => opt.value === value)) {
117
+ return 'Invalid option selected';
118
+ }
119
+
120
+ if (this._onValidate) {
121
+ const result = this._onValidate(value);
122
+ if (result !== true) {
123
+ return result || 'Invalid value';
124
+ }
125
+ }
126
+
127
+ return true;
128
+ }
129
+
130
+ protected _buildInputElement(): HTMLElement {
131
+ const { options, value, placeholder, required, disabled, name } = this.state;
132
+
133
+ const select = document.createElement('select');
134
+ select.className = 'jux-input-element jux-select-element';
135
+ select.id = `${this._id}-input`;
136
+ select.name = name;
137
+ select.required = required;
138
+ select.disabled = disabled;
139
+
140
+ // Placeholder option
141
+ if (placeholder) {
142
+ const placeholderOption = document.createElement('option');
143
+ placeholderOption.value = '';
144
+ placeholderOption.textContent = placeholder;
145
+ placeholderOption.disabled = true;
146
+ placeholderOption.selected = !value;
147
+ select.appendChild(placeholderOption);
148
+ }
149
+
150
+ // Options
151
+ options.forEach(option => {
152
+ const optionEl = document.createElement('option');
153
+ optionEl.value = option.value;
154
+ optionEl.textContent = option.label;
155
+ optionEl.disabled = option.disabled || false;
156
+ optionEl.selected = option.value === value;
157
+ select.appendChild(optionEl);
158
+ });
159
+
160
+ return select;
161
+ }
162
+
163
+ /* ═════════════════════════════════════════════════════════════════
164
+ * RENDER
165
+ * ═════════════════════════════════════════════════════════════════ */
166
+
167
+ render(targetId?: string): this {
168
+ const container = this._setupContainer(targetId);
169
+
170
+ const { style, class: className } = this.state;
171
+
172
+ // Build wrapper
173
+ const wrapper = document.createElement('div');
174
+ wrapper.className = 'jux-input jux-select';
175
+ wrapper.id = this._id;
176
+ if (className) wrapper.className += ` ${className}`;
177
+ if (style) wrapper.setAttribute('style', style);
178
+
179
+ // Label
180
+ if (this.state.label) {
181
+ wrapper.appendChild(this._renderLabel());
182
+ }
183
+
184
+ // Select container
185
+ const selectContainer = document.createElement('div');
186
+ selectContainer.className = 'jux-input-container jux-select-container';
187
+
188
+ // Select element
189
+ const selectEl = this._buildInputElement() as HTMLSelectElement;
190
+ this._inputElement = selectEl;
191
+ selectContainer.appendChild(selectEl);
192
+ wrapper.appendChild(selectContainer);
193
+
194
+ // Error element
195
+ wrapper.appendChild(this._renderError());
196
+
197
+ // Wire events
198
+ this._wireStandardEvents(wrapper);
199
+ this._wireFormSync(selectEl, 'change');
200
+
201
+ // Sync label changes
202
+ const labelSync = this._syncBindings.find(b => b.property === 'label');
203
+ if (labelSync) {
204
+ const transform = labelSync.toComponent || ((v: any) => String(v));
205
+ labelSync.stateObj.subscribe((val: any) => {
206
+ this.label(transform(val));
207
+ });
208
+ }
209
+
210
+ // Sync options changes
211
+ const optionsSync = this._syncBindings.find(b => b.property === 'options');
212
+ if (optionsSync) {
213
+ const transform = optionsSync.toComponent || ((v: any) => v);
214
+ optionsSync.stateObj.subscribe((val: any) => {
215
+ const transformed = transform(val);
216
+ this.state.options = transformed;
217
+
218
+ // Rebuild select options
219
+ selectEl.innerHTML = '';
220
+
221
+ if (this.state.placeholder) {
222
+ const placeholderOption = document.createElement('option');
223
+ placeholderOption.value = '';
224
+ placeholderOption.textContent = this.state.placeholder;
225
+ placeholderOption.disabled = true;
226
+ placeholderOption.selected = !this.state.value;
227
+ selectEl.appendChild(placeholderOption);
228
+ }
229
+
230
+ transformed.forEach((option: SelectOption) => {
231
+ const optionEl = document.createElement('option');
232
+ optionEl.value = option.value;
233
+ optionEl.textContent = option.label;
234
+ optionEl.disabled = option.disabled || false;
235
+ optionEl.selected = option.value === this.state.value;
236
+ selectEl.appendChild(optionEl);
237
+ });
238
+ });
239
+ }
240
+
241
+ container.appendChild(wrapper);
242
+
243
+
244
+ return this;
245
+ }
246
+
247
+
248
+ }
249
+
250
+ export function select(id: string, options: SelectOptions = {}): Select {
251
+ return new Select(id, options);
252
+ }
@@ -0,0 +1,48 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ import { MenuOptions } from './menu.js';
3
+ export interface SidebarOptions {
4
+ position?: 'left' | 'right';
5
+ width?: string;
6
+ collapsible?: boolean;
7
+ showToggle?: boolean;
8
+ expandOnHover?: boolean;
9
+ collapsed?: boolean;
10
+ menu?: MenuOptions;
11
+ style?: string;
12
+ class?: string;
13
+ }
14
+ type SidebarState = {
15
+ position: 'left' | 'right';
16
+ width: string;
17
+ collapsible: boolean;
18
+ showToggle: boolean;
19
+ expandOnHover: boolean;
20
+ collapsed: boolean;
21
+ menu: MenuOptions | null;
22
+ style: string;
23
+ class: string;
24
+ };
25
+ export declare class Sidebar extends BaseComponent<SidebarState> {
26
+ private _sidebar;
27
+ private _menu;
28
+ constructor(id: string, options?: SidebarOptions);
29
+ protected getTriggerEvents(): readonly string[];
30
+ protected getCallbackEvents(): readonly string[];
31
+ width(value: string): this;
32
+ position(value: 'left' | 'right'): this;
33
+ collapsible(value: boolean): this;
34
+ showToggle(value: boolean): this;
35
+ expandOnHover(value: boolean): this;
36
+ collapsed(value: boolean): this;
37
+ menu(value: MenuOptions): this;
38
+ toggle(): void;
39
+ /**
40
+ * Refresh menu active states (called automatically on URL changes)
41
+ */
42
+ refreshMenu(): this;
43
+ private _updateCollapsedState;
44
+ render(targetId?: string): this;
45
+ }
46
+ export declare function sidebar(id: string, options?: SidebarOptions): Sidebar;
47
+ export {};
48
+ //# sourceMappingURL=sidebar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sidebar.d.ts","sourceRoot":"","sources":["sidebar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAQ,WAAW,EAAE,MAAM,WAAW,CAAC;AAO9C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,YAAY,GAAG;IAClB,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,OAAQ,SAAQ,aAAa,CAAC,YAAY,CAAC;IACtD,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,KAAK,CAAqB;gBAEtB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAwBpD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAiBhD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAKvC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAKjC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAKhC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAKnC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAM/B,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAK9B,MAAM,IAAI,IAAI;IAYd;;OAEG;IACH,WAAW,IAAI,IAAI;IAQnB,OAAO,CAAC,qBAAqB;IAU7B,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CAuHhC;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAEzE"}
@@ -0,0 +1,207 @@
1
+ import { BaseComponent } from './base/BaseComponent.js';
2
+ import { renderIcon } from './icons.js';
3
+ import { Menu } from './menu.js';
4
+ // Event definitions
5
+ const TRIGGER_EVENTS = [];
6
+ const CALLBACK_EVENTS = ['toggle'];
7
+ export class Sidebar extends BaseComponent {
8
+ constructor(id, options = {}) {
9
+ // Restore collapsed state from localStorage if available
10
+ const storageKey = `jux-sidebar-${id}-collapsed`;
11
+ const savedCollapsed = localStorage.getItem(storageKey);
12
+ const initialCollapsed = savedCollapsed !== null ? savedCollapsed === 'true' : (options.collapsed ?? false);
13
+ super(id, {
14
+ position: options.position ?? 'left',
15
+ width: options.width ?? '',
16
+ collapsible: options.collapsible ?? true,
17
+ showToggle: options.showToggle ?? false,
18
+ expandOnHover: options.expandOnHover ?? false,
19
+ collapsed: initialCollapsed,
20
+ menu: options.menu ?? null,
21
+ style: options.style ?? '',
22
+ class: options.class ?? ''
23
+ });
24
+ this._sidebar = null;
25
+ this._menu = null;
26
+ // Listen for URL changes to update menu active states
27
+ if (typeof window !== 'undefined') {
28
+ window.addEventListener('popstate', () => this.refreshMenu());
29
+ }
30
+ }
31
+ getTriggerEvents() {
32
+ return TRIGGER_EVENTS;
33
+ }
34
+ getCallbackEvents() {
35
+ return CALLBACK_EVENTS;
36
+ }
37
+ /* ═════════════════════════════════════════════════════════════════
38
+ * FLUENT API
39
+ * ═════════════════════════════════════════════════════════════════ */
40
+ // ✅ Inherited from BaseComponent:
41
+ // - style(), class()
42
+ // - bind(), sync(), renderTo()
43
+ // - addClass(), removeClass(), toggleClass()
44
+ // - visible(), show(), hide()
45
+ // - attr(), attrs(), removeAttr()
46
+ // - disabled(), enable(), disable()
47
+ // - loading(), focus(), blur(), remove()
48
+ width(value) {
49
+ this.state.width = value;
50
+ return this;
51
+ }
52
+ position(value) {
53
+ this.state.position = value;
54
+ return this;
55
+ }
56
+ collapsible(value) {
57
+ this.state.collapsible = value;
58
+ return this;
59
+ }
60
+ showToggle(value) {
61
+ this.state.showToggle = value;
62
+ return this;
63
+ }
64
+ expandOnHover(value) {
65
+ this.state.expandOnHover = value;
66
+ return this;
67
+ }
68
+ collapsed(value) {
69
+ this.state.collapsed = value;
70
+ this._updateCollapsedState();
71
+ return this;
72
+ }
73
+ menu(value) {
74
+ this.state.menu = value;
75
+ return this;
76
+ }
77
+ toggle() {
78
+ this.state.collapsed = !this.state.collapsed;
79
+ this._updateCollapsedState();
80
+ // Save to localStorage
81
+ const storageKey = `jux-sidebar-${this._id}-collapsed`;
82
+ localStorage.setItem(storageKey, String(this.state.collapsed));
83
+ // 🎯 Fire the toggle callback event
84
+ this._triggerCallback('toggle', this.state.collapsed);
85
+ }
86
+ /**
87
+ * Refresh menu active states (called automatically on URL changes)
88
+ */
89
+ refreshMenu() {
90
+ if (this._menu && this.state.menu) {
91
+ // Re-evaluate and update menu items with current active states
92
+ this._menu.items(this.state.menu.items || []);
93
+ }
94
+ return this;
95
+ }
96
+ _updateCollapsedState() {
97
+ if (this._sidebar) {
98
+ this._sidebar.classList.toggle('jux-sidebar-collapsed', this.state.collapsed);
99
+ }
100
+ }
101
+ /* ═════════════════════════════════════════════════════════════════
102
+ * RENDER
103
+ * ═════════════════════════════════════════════════════════════════ */
104
+ render(targetId) {
105
+ const container = this._setupContainer(targetId);
106
+ const { position, collapsed, expandOnHover, menu, style, class: className } = this.state;
107
+ // Build sidebar element
108
+ const sidebar = document.createElement('aside');
109
+ sidebar.id = this._id;
110
+ if (className)
111
+ sidebar.className = className;
112
+ if (style)
113
+ sidebar.setAttribute('style', style);
114
+ // Apply initial collapsed state
115
+ if (collapsed) {
116
+ sidebar.classList.add('jux-sidebar-collapsed');
117
+ }
118
+ // Menu container (append first so toggle appears at bottom)
119
+ const menuContainer = document.createElement('div');
120
+ menuContainer.className = 'jux-sidebar-menu';
121
+ menuContainer.id = `${this._id}-menu`;
122
+ sidebar.appendChild(menuContainer);
123
+ // Toggle button (append last so it appears at bottom)
124
+ if (this.state.collapsible || this.state.showToggle) {
125
+ const toggleBtn = document.createElement('button');
126
+ toggleBtn.className = 'jux-sidebar-toggle';
127
+ toggleBtn.type = 'button';
128
+ const toggleIcon = document.createElement('span');
129
+ toggleIcon.className = 'jux-sidebar-toggle-icon';
130
+ const chevronIcon = renderIcon(position === 'left' ? '➡️' : '⬅️');
131
+ toggleIcon.appendChild(chevronIcon);
132
+ toggleBtn.appendChild(toggleIcon);
133
+ if (collapsed) {
134
+ toggleBtn.classList.add('jux-sidebar-toggle-collapsed');
135
+ }
136
+ toggleBtn.addEventListener('click', () => {
137
+ this.toggle();
138
+ toggleBtn.classList.toggle('jux-sidebar-toggle-collapsed', this.state.collapsed);
139
+ });
140
+ sidebar.appendChild(toggleBtn);
141
+ }
142
+ // Handle expand on hover
143
+ if (expandOnHover) {
144
+ sidebar.addEventListener('mouseenter', () => {
145
+ if (this.state.collapsed) {
146
+ sidebar.classList.add('jux-sidebar-hover-expanded');
147
+ }
148
+ });
149
+ sidebar.addEventListener('mouseleave', () => {
150
+ if (this.state.collapsed) {
151
+ sidebar.classList.remove('jux-sidebar-hover-expanded');
152
+ }
153
+ });
154
+ }
155
+ // Wire events using inherited method
156
+ this._wireStandardEvents(sidebar);
157
+ // Wire sync bindings for 'collapsed' property
158
+ this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
159
+ if (property === 'collapsed') {
160
+ const transform = toComponent || ((v) => v);
161
+ stateObj.subscribe((val) => {
162
+ const transformed = transform(val);
163
+ const isCollapsed = Boolean(transformed);
164
+ this.state.collapsed = isCollapsed;
165
+ this._updateCollapsedState();
166
+ });
167
+ }
168
+ else if (property === 'menu') {
169
+ const transform = toComponent || ((v) => v);
170
+ stateObj.subscribe((val) => {
171
+ const transformed = transform(val);
172
+ this.state.menu = transformed;
173
+ // Update menu items if menu instance exists
174
+ if (this._menu) {
175
+ this._menu.items(transformed.items || []);
176
+ // Re-render the menu
177
+ const menuEl = menuContainer.querySelector(`#${this._id}-menu-instance`);
178
+ if (menuEl) {
179
+ menuEl.remove();
180
+ }
181
+ this._menu.render(`#${menuContainer.id}`);
182
+ }
183
+ });
184
+ }
185
+ });
186
+ container.appendChild(sidebar);
187
+ this._sidebar = sidebar;
188
+ // Create and render menu (after sidebar is in DOM)
189
+ if (menu) {
190
+ this._menu = new Menu(`${this._id}-menu-instance`, {
191
+ ...menu,
192
+ orientation: 'vertical'
193
+ });
194
+ this._menu.render(`#${menuContainer.id}`);
195
+ }
196
+ // Trigger Iconify icon rendering
197
+ requestAnimationFrame(() => {
198
+ if (window.Iconify) {
199
+ window.Iconify.scan();
200
+ }
201
+ });
202
+ return this;
203
+ }
204
+ }
205
+ export function sidebar(id, options = {}) {
206
+ return new Sidebar(id, options);
207
+ }