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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data component - SQL query execution
|
|
3
|
+
* Note: No id needed - this is a data-only component
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const posts = jux.data('SELECT * FROM posts WHERE id = ?', [1]);
|
|
7
|
+
* await posts.execute();
|
|
8
|
+
* console.log(posts.data);
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface DataOptions {
|
|
12
|
+
sql: string;
|
|
13
|
+
params?: any[];
|
|
14
|
+
apiUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Data {
|
|
18
|
+
private _data: any[] = [];
|
|
19
|
+
private _executed: boolean = false;
|
|
20
|
+
private _loading: boolean = false;
|
|
21
|
+
private _sql: string;
|
|
22
|
+
private _params: any[];
|
|
23
|
+
private _apiUrl: string;
|
|
24
|
+
|
|
25
|
+
constructor(sql: string, params: any[] = [], apiUrl: string = '/api/query') {
|
|
26
|
+
this._sql = sql;
|
|
27
|
+
this._params = params;
|
|
28
|
+
this._apiUrl = apiUrl;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* -------------------------
|
|
32
|
+
* Getters
|
|
33
|
+
* ------------------------- */
|
|
34
|
+
|
|
35
|
+
get data(): any[] {
|
|
36
|
+
return this._data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get executed(): boolean {
|
|
40
|
+
return this._executed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get loading(): boolean {
|
|
44
|
+
return this._loading;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get sql(): string {
|
|
48
|
+
return this._sql;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set sql(value: string) {
|
|
52
|
+
this._sql = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* -------------------------
|
|
56
|
+
* Methods
|
|
57
|
+
* ------------------------- */
|
|
58
|
+
|
|
59
|
+
async execute(): Promise<void> {
|
|
60
|
+
if (this._executed) return;
|
|
61
|
+
this._loading = true;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(this._apiUrl, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: {
|
|
67
|
+
'Content-Type': 'application/json'
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
sql: this._sql,
|
|
71
|
+
params: this._params
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const result = await response.json();
|
|
80
|
+
this._data = result.data || [];
|
|
81
|
+
this._executed = true;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Data execution error:', error);
|
|
84
|
+
this._data = [];
|
|
85
|
+
throw error;
|
|
86
|
+
} finally {
|
|
87
|
+
this._loading = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
reset(): void {
|
|
92
|
+
this._executed = false;
|
|
93
|
+
this._data = [];
|
|
94
|
+
this._loading = false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Remove id requirement, make it optional for caching
|
|
98
|
+
static async fetch<T = any>(url: string, options?: RequestInit): Promise<T> {
|
|
99
|
+
const response = await fetch(url, options);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
102
|
+
}
|
|
103
|
+
return response.json();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ✅ Static methods - no ID needed
|
|
107
|
+
static async post<T = any>(url: string, body: any, options?: RequestInit): Promise<T> {
|
|
108
|
+
const response = await fetch(url, options);
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
111
|
+
}
|
|
112
|
+
return response.json();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static async put<T = any>(url: string, body: any, options?: RequestInit): Promise<T> {
|
|
116
|
+
const response = await fetch(url, options);
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
119
|
+
}
|
|
120
|
+
return response.json();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static async delete<T = any>(url: string, options?: RequestInit): Promise<T> {
|
|
124
|
+
const response = await fetch(url, options);
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
127
|
+
}
|
|
128
|
+
return response.json();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ✅ No ID needed - pure data fetching
|
|
133
|
+
export function data<T = any>(url: string, options?: RequestInit): Promise<T> {
|
|
134
|
+
return Data.fetch<T>(url, options);
|
|
135
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FormInput, FormInputState } from './base/FormInput.js';
|
|
2
|
+
export interface DatePickerOptions {
|
|
3
|
+
value?: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
name?: string;
|
|
9
|
+
min?: string;
|
|
10
|
+
max?: string;
|
|
11
|
+
style?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
onValidate?: (value: string) => boolean | string;
|
|
14
|
+
}
|
|
15
|
+
interface DatePickerState extends FormInputState {
|
|
16
|
+
value: string;
|
|
17
|
+
placeholder: string;
|
|
18
|
+
min?: string;
|
|
19
|
+
max?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class DatePicker extends FormInput<DatePickerState> {
|
|
22
|
+
constructor(id: string, options?: DatePickerOptions);
|
|
23
|
+
protected getTriggerEvents(): readonly string[];
|
|
24
|
+
protected getCallbackEvents(): readonly string[];
|
|
25
|
+
value(value: string): this;
|
|
26
|
+
placeholder(value: string): this;
|
|
27
|
+
min(value: string): this;
|
|
28
|
+
max(value: string): this;
|
|
29
|
+
getValue(): string;
|
|
30
|
+
setValue(value: string): this;
|
|
31
|
+
getDate(): Date | null;
|
|
32
|
+
protected _validateValue(value: string): boolean | string;
|
|
33
|
+
protected _buildInputElement(): HTMLElement;
|
|
34
|
+
render(targetId?: string): this;
|
|
35
|
+
}
|
|
36
|
+
export declare function datepicker(id: string, options?: DatePickerOptions): DatePicker;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=datepicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datepicker.d.ts","sourceRoot":"","sources":["datepicker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOhE,MAAM,WAAW,iBAAiB;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAC;CACpD;AAED,UAAU,eAAgB,SAAQ,cAAc;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,UAAW,SAAQ,SAAS,CAAC,eAAe,CAAC;gBAC1C,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAoBvD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAehD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI1B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKhC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKxB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASxB,QAAQ,IAAI,MAAM;IAIlB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ7B,OAAO,IAAI,IAAI,GAAG,IAAI;IAMtB,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM;IAuCzD,SAAS,CAAC,kBAAkB,IAAI,WAAW;IAuB3C,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CA0DlC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAElF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
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'];
|
|
6
|
+
export class DatePicker extends FormInput {
|
|
7
|
+
constructor(id, options = {}) {
|
|
8
|
+
super(id, {
|
|
9
|
+
value: options.value ?? '',
|
|
10
|
+
placeholder: options.placeholder ?? 'Select a date',
|
|
11
|
+
label: options.label ?? '',
|
|
12
|
+
required: options.required ?? false,
|
|
13
|
+
disabled: options.disabled ?? false,
|
|
14
|
+
name: options.name ?? id,
|
|
15
|
+
min: options.min,
|
|
16
|
+
max: options.max,
|
|
17
|
+
style: options.style ?? '',
|
|
18
|
+
class: options.class ?? '',
|
|
19
|
+
errorMessage: undefined
|
|
20
|
+
});
|
|
21
|
+
if (options.onValidate) {
|
|
22
|
+
this._onValidate = options.onValidate;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
getTriggerEvents() {
|
|
26
|
+
return TRIGGER_EVENTS;
|
|
27
|
+
}
|
|
28
|
+
getCallbackEvents() {
|
|
29
|
+
return CALLBACK_EVENTS;
|
|
30
|
+
}
|
|
31
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
32
|
+
* FLUENT API
|
|
33
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
34
|
+
// ✅ Inherited from FormInput/BaseComponent:
|
|
35
|
+
// - label(), required(), name(), onValidate()
|
|
36
|
+
// - validate(), isValid()
|
|
37
|
+
// - style(), class()
|
|
38
|
+
// - bind(), sync(), renderTo()
|
|
39
|
+
// - disabled(), enable(), disable()
|
|
40
|
+
value(value) {
|
|
41
|
+
return this.setValue(value);
|
|
42
|
+
}
|
|
43
|
+
placeholder(value) {
|
|
44
|
+
this.state.placeholder = value;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
min(value) {
|
|
48
|
+
this.state.min = value;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
max(value) {
|
|
52
|
+
this.state.max = value;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
56
|
+
* FORM INPUT IMPLEMENTATION
|
|
57
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
58
|
+
getValue() {
|
|
59
|
+
return this.state.value;
|
|
60
|
+
}
|
|
61
|
+
setValue(value) {
|
|
62
|
+
this.state.value = value;
|
|
63
|
+
if (this._inputElement) {
|
|
64
|
+
this._inputElement.value = value;
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
getDate() {
|
|
69
|
+
if (!this.state.value)
|
|
70
|
+
return null;
|
|
71
|
+
const date = new Date(this.state.value);
|
|
72
|
+
return isNaN(date.getTime()) ? null : date;
|
|
73
|
+
}
|
|
74
|
+
_validateValue(value) {
|
|
75
|
+
const { required, min, max } = this.state;
|
|
76
|
+
if (required && !value) {
|
|
77
|
+
return 'Please select a date';
|
|
78
|
+
}
|
|
79
|
+
if (value) {
|
|
80
|
+
const date = new Date(value);
|
|
81
|
+
if (isNaN(date.getTime())) {
|
|
82
|
+
return 'Invalid date';
|
|
83
|
+
}
|
|
84
|
+
if (min) {
|
|
85
|
+
const minDate = new Date(min);
|
|
86
|
+
if (date < minDate) {
|
|
87
|
+
return `Date must be on or after ${min}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (max) {
|
|
91
|
+
const maxDate = new Date(max);
|
|
92
|
+
if (date > maxDate) {
|
|
93
|
+
return `Date must be on or before ${max}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (this._onValidate) {
|
|
98
|
+
const result = this._onValidate(value);
|
|
99
|
+
if (result !== true) {
|
|
100
|
+
return result || 'Invalid date';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
_buildInputElement() {
|
|
106
|
+
const { value, placeholder, required, disabled, name, min, max } = this.state;
|
|
107
|
+
const input = document.createElement('input');
|
|
108
|
+
input.type = 'date';
|
|
109
|
+
input.className = 'jux-input-element jux-datepicker-input';
|
|
110
|
+
input.id = `${this._id}-input`;
|
|
111
|
+
input.name = name;
|
|
112
|
+
input.value = value;
|
|
113
|
+
input.placeholder = placeholder;
|
|
114
|
+
input.required = required;
|
|
115
|
+
input.disabled = disabled;
|
|
116
|
+
if (min)
|
|
117
|
+
input.min = min;
|
|
118
|
+
if (max)
|
|
119
|
+
input.max = max;
|
|
120
|
+
return input;
|
|
121
|
+
}
|
|
122
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
123
|
+
* RENDER
|
|
124
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
125
|
+
render(targetId) {
|
|
126
|
+
const container = this._setupContainer(targetId);
|
|
127
|
+
const { style, class: className } = this.state;
|
|
128
|
+
// Build wrapper
|
|
129
|
+
const wrapper = document.createElement('div');
|
|
130
|
+
wrapper.className = 'jux-input jux-datepicker';
|
|
131
|
+
wrapper.id = this._id;
|
|
132
|
+
if (className)
|
|
133
|
+
wrapper.className += ` ${className}`;
|
|
134
|
+
if (style)
|
|
135
|
+
wrapper.setAttribute('style', style);
|
|
136
|
+
// Label
|
|
137
|
+
if (this.state.label) {
|
|
138
|
+
wrapper.appendChild(this._renderLabel());
|
|
139
|
+
}
|
|
140
|
+
// Input container
|
|
141
|
+
const inputContainer = document.createElement('div');
|
|
142
|
+
inputContainer.className = 'jux-input-container jux-datepicker-container';
|
|
143
|
+
// Calendar icon
|
|
144
|
+
const iconEl = document.createElement('span');
|
|
145
|
+
iconEl.className = 'jux-input-icon';
|
|
146
|
+
iconEl.appendChild(renderIcon('calendar'));
|
|
147
|
+
inputContainer.appendChild(iconEl);
|
|
148
|
+
// Date input
|
|
149
|
+
const inputEl = this._buildInputElement();
|
|
150
|
+
this._inputElement = inputEl;
|
|
151
|
+
inputContainer.appendChild(inputEl);
|
|
152
|
+
wrapper.appendChild(inputContainer);
|
|
153
|
+
// Error element
|
|
154
|
+
wrapper.appendChild(this._renderError());
|
|
155
|
+
// Wire events
|
|
156
|
+
this._wireStandardEvents(wrapper);
|
|
157
|
+
this._wireFormSync(inputEl, 'change');
|
|
158
|
+
// 🎯 Fire change event when date changes
|
|
159
|
+
inputEl.addEventListener('change', () => {
|
|
160
|
+
const input = inputEl;
|
|
161
|
+
this._triggerCallback('change', input.value);
|
|
162
|
+
});
|
|
163
|
+
// Sync label changes
|
|
164
|
+
const labelSync = this._syncBindings.find(b => b.property === 'label');
|
|
165
|
+
if (labelSync) {
|
|
166
|
+
const transform = labelSync.toComponent || ((v) => String(v));
|
|
167
|
+
labelSync.stateObj.subscribe((val) => {
|
|
168
|
+
this.label(transform(val));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
container.appendChild(wrapper);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export function datepicker(id, options = {}) {
|
|
176
|
+
return new DatePicker(id, options);
|
|
177
|
+
}
|
|
@@ -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,38 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
export interface DialogOptions {
|
|
3
|
+
title?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
confirmText?: string;
|
|
6
|
+
cancelText?: string;
|
|
7
|
+
variant?: 'default' | 'danger' | 'warning';
|
|
8
|
+
style?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
}
|
|
11
|
+
type DialogState = {
|
|
12
|
+
title: string;
|
|
13
|
+
message: string;
|
|
14
|
+
confirmText: string;
|
|
15
|
+
cancelText: string;
|
|
16
|
+
variant: string;
|
|
17
|
+
open: boolean;
|
|
18
|
+
style: string;
|
|
19
|
+
class: string;
|
|
20
|
+
};
|
|
21
|
+
export declare class Dialog extends BaseComponent<DialogState> {
|
|
22
|
+
private _dialog;
|
|
23
|
+
private _overlay;
|
|
24
|
+
constructor(id: string, options?: DialogOptions);
|
|
25
|
+
protected getTriggerEvents(): readonly string[];
|
|
26
|
+
protected getCallbackEvents(): readonly string[];
|
|
27
|
+
title(value: string): this;
|
|
28
|
+
message(value: string): this;
|
|
29
|
+
confirmText(value: string): this;
|
|
30
|
+
cancelText(value: string): this;
|
|
31
|
+
variant(value: 'default' | 'danger' | 'warning'): this;
|
|
32
|
+
open(): this;
|
|
33
|
+
close(): this;
|
|
34
|
+
render(targetId?: string): this;
|
|
35
|
+
}
|
|
36
|
+
export declare function dialog(id: string, options?: DialogOptions): Dialog;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,MAAM,WAAW,aAAa;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,WAAW,GAAG;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,MAAO,SAAQ,aAAa,CAAC,WAAW,CAAC;IAClD,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAA4B;gBAEhC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB;IAanD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAQhD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK5B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKhC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK/B,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI;IAKtD,IAAI,IAAI,IAAI;IAQZ,KAAK,IAAI,IAAI;IAYb,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CAkElC;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAEtE"}
|