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