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,348 @@
1
+ import { FormInput } from './base/FormInput.js';
2
+ import { renderIcon } from './icons.js';
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [];
5
+ const CALLBACK_EVENTS = ['change', 'input'];
6
+ export class Input extends FormInput {
7
+ constructor(id, options = {}) {
8
+ super(id, {
9
+ type: options.type ?? 'text',
10
+ value: options.value ?? '',
11
+ placeholder: options.placeholder ?? '',
12
+ label: options.label ?? '',
13
+ icon: options.icon ?? '',
14
+ required: options.required ?? false,
15
+ disabled: options.disabled ?? false,
16
+ name: options.name ?? id,
17
+ rows: options.rows ?? 3,
18
+ min: options.min,
19
+ max: options.max,
20
+ step: options.step,
21
+ minLength: options.minLength,
22
+ maxLength: options.maxLength,
23
+ pattern: options.pattern,
24
+ style: options.style ?? '',
25
+ class: options.class ?? '',
26
+ errorMessage: undefined
27
+ });
28
+ if (options.onValidate) {
29
+ this._onValidate = options.onValidate;
30
+ }
31
+ }
32
+ getTriggerEvents() {
33
+ return TRIGGER_EVENTS;
34
+ }
35
+ getCallbackEvents() {
36
+ return CALLBACK_EVENTS;
37
+ }
38
+ /* ═════════════════════════════════════════════════════════════════
39
+ * FLUENT API
40
+ * ═════════════════════════════════════════════════════════════════ */
41
+ // ✅ Inherited from FormInput/BaseComponent:
42
+ // - label(), required(), name(), onValidate()
43
+ // - validate(), isValid()
44
+ // - style(), class()
45
+ // - bind(), sync(), renderTo()
46
+ // - disabled(), enable(), disable()
47
+ type(value) {
48
+ this.state.type = value;
49
+ return this;
50
+ }
51
+ value(value) {
52
+ return this.setValue(String(value));
53
+ }
54
+ placeholder(value) {
55
+ this.state.placeholder = value;
56
+ return this;
57
+ }
58
+ icon(value) {
59
+ this.state.icon = value;
60
+ return this;
61
+ }
62
+ rows(value) {
63
+ this.state.rows = value;
64
+ return this;
65
+ }
66
+ min(value) {
67
+ this.state.min = value;
68
+ return this;
69
+ }
70
+ max(value) {
71
+ this.state.max = value;
72
+ return this;
73
+ }
74
+ step(value) {
75
+ this.state.step = value;
76
+ return this;
77
+ }
78
+ minLength(value) {
79
+ this.state.minLength = value;
80
+ return this;
81
+ }
82
+ maxLength(value) {
83
+ this.state.maxLength = value;
84
+ return this;
85
+ }
86
+ pattern(value) {
87
+ this.state.pattern = value;
88
+ return this;
89
+ }
90
+ /* ═════════════════════════════════════════════════════════════════
91
+ * FORM INPUT IMPLEMENTATION
92
+ * ═════════════════════════════════════════════════════════════════ */
93
+ getValue() {
94
+ return this.state.value;
95
+ }
96
+ setValue(value) {
97
+ this.state.value = value;
98
+ if (this._inputElement) {
99
+ this._inputElement.value = value;
100
+ }
101
+ return this;
102
+ }
103
+ getNumericValue() {
104
+ const num = Number(this.state.value);
105
+ return isNaN(num) ? null : num;
106
+ }
107
+ _validateValue(value) {
108
+ const { required, type, min, max, minLength, maxLength, pattern } = this.state;
109
+ if (required && !value.trim()) {
110
+ return 'This field is required';
111
+ }
112
+ if (type === 'number' && value) {
113
+ const numValue = Number(value);
114
+ if (isNaN(numValue)) {
115
+ return 'Must be a valid number';
116
+ }
117
+ if (min !== undefined && numValue < min) {
118
+ return `Must be at least ${min}`;
119
+ }
120
+ if (max !== undefined && numValue > max) {
121
+ return `Must be at most ${max}`;
122
+ }
123
+ }
124
+ if ((type === 'text' || type === 'textarea') && value) {
125
+ if (minLength !== undefined && value.length < minLength) {
126
+ return `Must be at least ${minLength} characters`;
127
+ }
128
+ if (maxLength !== undefined && value.length > maxLength) {
129
+ return `Must be at most ${maxLength} characters`;
130
+ }
131
+ }
132
+ if (pattern && value) {
133
+ const regex = new RegExp(pattern);
134
+ if (!regex.test(value)) {
135
+ return 'Invalid format';
136
+ }
137
+ }
138
+ if (this._onValidate) {
139
+ const result = this._onValidate(value);
140
+ if (result !== true) {
141
+ return result || 'Invalid value';
142
+ }
143
+ }
144
+ return true;
145
+ }
146
+ _buildInputElement() {
147
+ const { type, value, placeholder, required, disabled, name, rows, min, max, step, minLength, maxLength, pattern } = this.state;
148
+ let inputEl;
149
+ if (type === 'textarea') {
150
+ inputEl = document.createElement('textarea');
151
+ inputEl.rows = rows;
152
+ if (minLength !== undefined)
153
+ inputEl.minLength = minLength;
154
+ if (maxLength !== undefined)
155
+ inputEl.maxLength = maxLength;
156
+ }
157
+ else {
158
+ inputEl = document.createElement('input');
159
+ inputEl.type = type;
160
+ if (type === 'number') {
161
+ if (min !== undefined)
162
+ inputEl.min = String(min);
163
+ if (max !== undefined)
164
+ inputEl.max = String(max);
165
+ if (step !== undefined)
166
+ inputEl.step = String(step);
167
+ }
168
+ if (type === 'text' || type === 'email' || type === 'tel' || type === 'url') {
169
+ if (minLength !== undefined)
170
+ inputEl.minLength = minLength;
171
+ if (maxLength !== undefined)
172
+ inputEl.maxLength = maxLength;
173
+ if (pattern)
174
+ inputEl.pattern = pattern;
175
+ }
176
+ }
177
+ inputEl.className = 'jux-input-element';
178
+ inputEl.id = `${this._id}-input`;
179
+ inputEl.name = name;
180
+ inputEl.value = value;
181
+ inputEl.placeholder = placeholder;
182
+ inputEl.required = required;
183
+ inputEl.disabled = disabled;
184
+ return inputEl;
185
+ }
186
+ /* ═════════════════════════════════════════════════════════════════
187
+ * RENDER
188
+ * ═════════════════════════════════════════════════════════════════ */
189
+ render(targetId) {
190
+ const container = this._setupContainer(targetId);
191
+ const { icon, maxLength, type, style, class: className } = this.state;
192
+ // Build wrapper
193
+ const wrapper = document.createElement('div');
194
+ wrapper.className = 'jux-input';
195
+ wrapper.id = this._id;
196
+ if (className)
197
+ wrapper.className += ` ${className}`;
198
+ if (style)
199
+ wrapper.setAttribute('style', style);
200
+ // Label
201
+ if (this.state.label) {
202
+ wrapper.appendChild(this._renderLabel());
203
+ }
204
+ // Input container
205
+ const inputContainer = document.createElement('div');
206
+ inputContainer.className = 'jux-input-container';
207
+ if (icon)
208
+ inputContainer.classList.add('jux-input-with-icon');
209
+ // Icon
210
+ if (icon) {
211
+ const iconEl = document.createElement('span');
212
+ iconEl.className = 'jux-input-icon';
213
+ iconEl.appendChild(renderIcon(icon));
214
+ inputContainer.appendChild(iconEl);
215
+ }
216
+ // Input element
217
+ const inputEl = this._buildInputElement();
218
+ this._inputElement = inputEl;
219
+ inputContainer.appendChild(inputEl);
220
+ wrapper.appendChild(inputContainer);
221
+ // Error element
222
+ wrapper.appendChild(this._renderError());
223
+ // Character counter
224
+ if (maxLength && (type === 'text' || type === 'textarea')) {
225
+ const counterEl = document.createElement('div');
226
+ counterEl.className = 'jux-input-counter';
227
+ counterEl.id = `${this._id}-counter`;
228
+ counterEl.textContent = `${this.state.value.length}/${maxLength}`;
229
+ wrapper.appendChild(counterEl);
230
+ inputEl.addEventListener('input', () => {
231
+ const input = inputEl;
232
+ counterEl.textContent = `${input.value.length}/${maxLength}`;
233
+ this.state.value = input.value;
234
+ // 🎯 Fire the input callback event
235
+ this._triggerCallback('input', input.value);
236
+ });
237
+ }
238
+ else {
239
+ // Fire input event even without counter
240
+ inputEl.addEventListener('input', () => {
241
+ const input = inputEl;
242
+ this.state.value = input.value;
243
+ // 🎯 Fire the input callback event
244
+ this._triggerCallback('input', input.value);
245
+ });
246
+ }
247
+ // Fire change event on blur
248
+ inputEl.addEventListener('change', () => {
249
+ const input = inputEl;
250
+ // 🎯 Fire the change callback event
251
+ this._triggerCallback('change', input.value);
252
+ });
253
+ // Wire events
254
+ this._wireStandardEvents(wrapper);
255
+ this._wireFormSync(inputEl, 'input');
256
+ // Sync label changes
257
+ const labelSync = this._syncBindings.find(b => b.property === 'label');
258
+ if (labelSync) {
259
+ const transform = labelSync.toComponent || ((v) => String(v));
260
+ labelSync.stateObj.subscribe((val) => {
261
+ this.label(transform(val));
262
+ });
263
+ }
264
+ container.appendChild(wrapper);
265
+ requestAnimationFrame(() => {
266
+ if (window.lucide) {
267
+ window.lucide.createIcons();
268
+ }
269
+ });
270
+ return this;
271
+ }
272
+ }
273
+ export function input(id, options = {}) {
274
+ return new Input(id, options);
275
+ }
276
+ // Shorter, consistent naming
277
+ export function text(id, options) {
278
+ return new Input(id, { ...options, type: 'text' });
279
+ }
280
+ export function textRequired(id, options) {
281
+ return new Input(id, { ...options, type: 'text', required: true });
282
+ }
283
+ export function number(id, options) {
284
+ return new Input(id, { ...options, type: 'number' });
285
+ }
286
+ export function numberRequired(id, options) {
287
+ return new Input(id, { ...options, type: 'number', required: true });
288
+ }
289
+ export function email(id, options) {
290
+ return new Input(id, { ...options, type: 'email' });
291
+ }
292
+ export function emailRequired(id, options) {
293
+ return new Input(id, { ...options, type: 'email', required: true });
294
+ }
295
+ export function password(id, options) {
296
+ return new Input(id, { ...options, type: 'password' });
297
+ }
298
+ export function passwordRequired(id, options) {
299
+ return new Input(id, { ...options, type: 'password', required: true });
300
+ }
301
+ export function tel(id, options) {
302
+ return new Input(id, { ...options, type: 'tel' });
303
+ }
304
+ export function telRequired(id, options) {
305
+ return new Input(id, { ...options, type: 'tel', required: true });
306
+ }
307
+ export function phone(id, options) {
308
+ return new Input(id, { ...options, type: 'tel' });
309
+ }
310
+ export function phoneRequired(id, options) {
311
+ return new Input(id, { ...options, type: 'tel', required: true });
312
+ }
313
+ export function url(id, options) {
314
+ return new Input(id, { ...options, type: 'url' });
315
+ }
316
+ export function urlRequired(id, options) {
317
+ return new Input(id, { ...options, type: 'url', required: true });
318
+ }
319
+ export function textarea(id, options) {
320
+ return new Input(id, { ...options, type: 'textarea' });
321
+ }
322
+ export function textareaRequired(id, options) {
323
+ return new Input(id, { ...options, type: 'textarea', required: true });
324
+ }
325
+ export function range(id, options) {
326
+ return new Input(id, { ...options, type: 'range' });
327
+ }
328
+ export function rangeRequired(id, options) {
329
+ return new Input(id, { ...options, type: 'range', required: true });
330
+ }
331
+ export function date(id, options) {
332
+ return new Input(id, { ...options, type: 'date' });
333
+ }
334
+ export function dateRequired(id, options) {
335
+ return new Input(id, { ...options, type: 'date', required: true });
336
+ }
337
+ export function time(id, options) {
338
+ return new Input(id, { ...options, type: 'time' });
339
+ }
340
+ export function timeRequired(id, options) {
341
+ return new Input(id, { ...options, type: 'time', required: true });
342
+ }
343
+ export function color(id, options) {
344
+ return new Input(id, { ...options, type: 'color' });
345
+ }
346
+ export function colorRequired(id, options) {
347
+ return new Input(id, { ...options, type: 'color', required: true });
348
+ }