dalila 1.8.2 → 1.8.4
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/dist/cli/routes-generator.js +1 -2
- package/dist/components/ui/dialog/index.d.ts +0 -8
- package/dist/components/ui/dialog/index.js +2 -41
- package/dist/components/ui/dialog/internal.d.ts +5 -0
- package/dist/{componentes/ui/dialog/index.js → components/ui/dialog/internal.js} +1 -23
- package/dist/components/ui/drawer/index.js +2 -2
- package/dist/components/ui/index.d.ts +1 -1
- package/dist/components/ui/index.js +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/query.js +9 -7
- package/dist/core/resource.d.ts +23 -171
- package/dist/core/resource.js +178 -15
- package/dist/form/index.d.ts +1 -1
- package/dist/form/index.js +1 -1
- package/dist/router/index.d.ts +1 -1
- package/dist/router/index.js +1 -1
- package/dist/runtime/bind.d.ts +10 -0
- package/dist/runtime/bind.js +382 -53
- package/package.json +1 -1
- package/dist/componentes/ui/accordion/index.d.ts +0 -2
- package/dist/componentes/ui/accordion/index.js +0 -114
- package/dist/componentes/ui/calendar/index.d.ts +0 -2
- package/dist/componentes/ui/calendar/index.js +0 -132
- package/dist/componentes/ui/combobox/index.d.ts +0 -2
- package/dist/componentes/ui/combobox/index.js +0 -161
- package/dist/componentes/ui/dialog/index.d.ts +0 -10
- package/dist/componentes/ui/drawer/index.d.ts +0 -2
- package/dist/componentes/ui/drawer/index.js +0 -41
- package/dist/componentes/ui/dropdown/index.d.ts +0 -2
- package/dist/componentes/ui/dropdown/index.js +0 -48
- package/dist/componentes/ui/dropzone/index.d.ts +0 -2
- package/dist/componentes/ui/dropzone/index.js +0 -92
- package/dist/componentes/ui/env.d.ts +0 -1
- package/dist/componentes/ui/env.js +0 -2
- package/dist/componentes/ui/index.d.ts +0 -13
- package/dist/componentes/ui/index.js +0 -12
- package/dist/componentes/ui/popover/index.d.ts +0 -2
- package/dist/componentes/ui/popover/index.js +0 -156
- package/dist/componentes/ui/runtime.d.ts +0 -20
- package/dist/componentes/ui/runtime.js +0 -421
- package/dist/componentes/ui/tabs/index.d.ts +0 -3
- package/dist/componentes/ui/tabs/index.js +0 -101
- package/dist/componentes/ui/toast/index.d.ts +0 -3
- package/dist/componentes/ui/toast/index.js +0 -115
- package/dist/componentes/ui/ui-types.d.ts +0 -175
- package/dist/componentes/ui/ui-types.js +0 -1
- package/dist/componentes/ui/validate.d.ts +0 -7
- package/dist/componentes/ui/validate.js +0 -71
- package/dist/core/store.d.ts +0 -130
- package/dist/core/store.js +0 -234
- package/dist/core/virtual.d.ts +0 -26
- package/dist/core/virtual.js +0 -277
- package/dist/core/watch-testing.d.ts +0 -13
- package/dist/core/watch-testing.js +0 -16
- package/dist/router/route.d.ts +0 -23
- package/dist/router/route.js +0 -48
- package/dist/simple.d.ts +0 -11
- package/dist/simple.js +0 -11
- package/dist/ui/accordion.d.ts +0 -2
- package/dist/ui/accordion.js +0 -114
- package/dist/ui/calendar.d.ts +0 -2
- package/dist/ui/calendar.js +0 -132
- package/dist/ui/combobox.d.ts +0 -2
- package/dist/ui/combobox.js +0 -161
- package/dist/ui/dialog.d.ts +0 -10
- package/dist/ui/dialog.js +0 -54
- package/dist/ui/drawer.d.ts +0 -2
- package/dist/ui/drawer.js +0 -41
- package/dist/ui/dropdown.d.ts +0 -2
- package/dist/ui/dropdown.js +0 -48
- package/dist/ui/dropzone.d.ts +0 -2
- package/dist/ui/dropzone.js +0 -92
- package/dist/ui/env.d.ts +0 -1
- package/dist/ui/env.js +0 -2
- package/dist/ui/index.d.ts +0 -13
- package/dist/ui/index.js +0 -12
- package/dist/ui/popover.d.ts +0 -2
- package/dist/ui/popover.js +0 -156
- package/dist/ui/runtime.d.ts +0 -20
- package/dist/ui/runtime.js +0 -421
- package/dist/ui/tabs.d.ts +0 -3
- package/dist/ui/tabs.js +0 -101
- package/dist/ui/toast.d.ts +0 -3
- package/dist/ui/toast.js +0 -115
- package/dist/ui/ui-types.d.ts +0 -175
- package/dist/ui/ui-types.js +0 -1
- package/dist/ui/validate.d.ts +0 -7
- package/dist/ui/validate.js +0 -71
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { signal, computed } from "../../../core/signal.js";
|
|
2
|
-
import { batch } from "../../../core/scheduler.js";
|
|
3
|
-
import { validateCalendarOptions } from "../validate.js";
|
|
4
|
-
const DEFAULT_DAY_LABELS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
5
|
-
const DEFAULT_MONTH_LABELS = [
|
|
6
|
-
"January", "February", "March", "April", "May", "June",
|
|
7
|
-
"July", "August", "September", "October", "November", "December",
|
|
8
|
-
];
|
|
9
|
-
function isSameDay(a, b) {
|
|
10
|
-
return (a.getFullYear() === b.getFullYear() &&
|
|
11
|
-
a.getMonth() === b.getMonth() &&
|
|
12
|
-
a.getDate() === b.getDate());
|
|
13
|
-
}
|
|
14
|
-
export function createCalendar(options = {}) {
|
|
15
|
-
validateCalendarOptions(options);
|
|
16
|
-
const { initial, min, max, dayLabels: customDayLabels, monthLabels: customMonthLabels, } = options;
|
|
17
|
-
const now = initial ?? new Date();
|
|
18
|
-
const monthLabels = customMonthLabels ?? DEFAULT_MONTH_LABELS;
|
|
19
|
-
const calDayLabels = customDayLabels ?? DEFAULT_DAY_LABELS;
|
|
20
|
-
const year = signal(now.getFullYear());
|
|
21
|
-
const month = signal(now.getMonth());
|
|
22
|
-
const selected = signal(initial ?? null);
|
|
23
|
-
const title = computed(() => `${monthLabels[month()]} ${year()}`);
|
|
24
|
-
const days = computed(() => {
|
|
25
|
-
const y = year();
|
|
26
|
-
const m = month();
|
|
27
|
-
const sel = selected();
|
|
28
|
-
const today = new Date();
|
|
29
|
-
const firstDow = new Date(y, m, 1).getDay();
|
|
30
|
-
const daysInMonth = new Date(y, m + 1, 0).getDate();
|
|
31
|
-
const prevMonthDays = new Date(y, m, 0).getDate();
|
|
32
|
-
const grid = [];
|
|
33
|
-
const GRID_SIZE = 42;
|
|
34
|
-
// Previous month days
|
|
35
|
-
for (let i = firstDow - 1; i >= 0; i--) {
|
|
36
|
-
const date = prevMonthDays - i;
|
|
37
|
-
const fullDate = new Date(y, m - 1, date);
|
|
38
|
-
grid.push({
|
|
39
|
-
date,
|
|
40
|
-
month: "prev",
|
|
41
|
-
fullDate,
|
|
42
|
-
isToday: isSameDay(fullDate, today),
|
|
43
|
-
isSelected: sel !== null && isSameDay(fullDate, sel),
|
|
44
|
-
disabled: isOutOfBounds(fullDate),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
// Current month days
|
|
48
|
-
for (let d = 1; d <= daysInMonth; d++) {
|
|
49
|
-
const fullDate = new Date(y, m, d);
|
|
50
|
-
grid.push({
|
|
51
|
-
date: d,
|
|
52
|
-
month: "current",
|
|
53
|
-
fullDate,
|
|
54
|
-
isToday: isSameDay(fullDate, today),
|
|
55
|
-
isSelected: sel !== null && isSameDay(fullDate, sel),
|
|
56
|
-
disabled: isOutOfBounds(fullDate),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
// Next month days
|
|
60
|
-
const remaining = GRID_SIZE - grid.length;
|
|
61
|
-
for (let d = 1; d <= remaining; d++) {
|
|
62
|
-
const fullDate = new Date(y, m + 1, d);
|
|
63
|
-
grid.push({
|
|
64
|
-
date: d,
|
|
65
|
-
month: "next",
|
|
66
|
-
fullDate,
|
|
67
|
-
isToday: isSameDay(fullDate, today),
|
|
68
|
-
isSelected: sel !== null && isSameDay(fullDate, sel),
|
|
69
|
-
disabled: isOutOfBounds(fullDate),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return grid;
|
|
73
|
-
});
|
|
74
|
-
function isOutOfBounds(date) {
|
|
75
|
-
if (min && date < min)
|
|
76
|
-
return true;
|
|
77
|
-
if (max && date > max)
|
|
78
|
-
return true;
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const prev = () => {
|
|
82
|
-
batch(() => {
|
|
83
|
-
if (month() === 0) {
|
|
84
|
-
month.set(11);
|
|
85
|
-
year.update((y) => y - 1);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
month.update((m) => m - 1);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
const next = () => {
|
|
93
|
-
batch(() => {
|
|
94
|
-
if (month() === 11) {
|
|
95
|
-
month.set(0);
|
|
96
|
-
year.update((y) => y + 1);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
month.update((m) => m + 1);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
const select = (date) => {
|
|
104
|
-
if (isOutOfBounds(date))
|
|
105
|
-
return;
|
|
106
|
-
selected.set(date);
|
|
107
|
-
};
|
|
108
|
-
const handleDayClick = (ev) => {
|
|
109
|
-
const target = ev.target.closest("[data-date]");
|
|
110
|
-
if (!target)
|
|
111
|
-
return;
|
|
112
|
-
const dateStr = target.dataset.date;
|
|
113
|
-
if (!dateStr)
|
|
114
|
-
return;
|
|
115
|
-
const date = new Date(dateStr);
|
|
116
|
-
if (isNaN(date.getTime()))
|
|
117
|
-
return;
|
|
118
|
-
select(date);
|
|
119
|
-
};
|
|
120
|
-
return {
|
|
121
|
-
year,
|
|
122
|
-
month,
|
|
123
|
-
selected,
|
|
124
|
-
title,
|
|
125
|
-
days,
|
|
126
|
-
dayLabels: calDayLabels,
|
|
127
|
-
prev,
|
|
128
|
-
next,
|
|
129
|
-
select,
|
|
130
|
-
handleDayClick,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { signal, computed } from "../../../core/signal.js";
|
|
2
|
-
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
-
import { validateComboboxOptions } from "../validate.js";
|
|
4
|
-
import { isBrowser } from "../env.js";
|
|
5
|
-
let comboboxUid = 0;
|
|
6
|
-
export function createCombobox(options) {
|
|
7
|
-
validateComboboxOptions(options);
|
|
8
|
-
const { options: items, placeholder = "", name: fieldName } = options;
|
|
9
|
-
const open = signal(false);
|
|
10
|
-
const query = signal("");
|
|
11
|
-
const value = signal("");
|
|
12
|
-
const label = signal("");
|
|
13
|
-
const highlightedIndex = signal(-1);
|
|
14
|
-
const filtered = computed(() => {
|
|
15
|
-
const q = query().toLowerCase();
|
|
16
|
-
if (!q)
|
|
17
|
-
return items;
|
|
18
|
-
return items.filter((opt) => opt.label.toLowerCase().includes(q));
|
|
19
|
-
});
|
|
20
|
-
const show = () => open.set(true);
|
|
21
|
-
const close = () => {
|
|
22
|
-
open.set(false);
|
|
23
|
-
highlightedIndex.set(-1);
|
|
24
|
-
};
|
|
25
|
-
const toggle = () => open.update((v) => !v);
|
|
26
|
-
const handleInput = (ev) => {
|
|
27
|
-
const input = ev.target;
|
|
28
|
-
query.set(input.value);
|
|
29
|
-
open.set(true);
|
|
30
|
-
highlightedIndex.set(-1);
|
|
31
|
-
};
|
|
32
|
-
const handleSelect = (ev) => {
|
|
33
|
-
const target = ev.target.closest("[data-value]");
|
|
34
|
-
if (!target)
|
|
35
|
-
return;
|
|
36
|
-
const val = target.dataset.value ?? "";
|
|
37
|
-
const lbl = target.textContent?.trim() ?? val;
|
|
38
|
-
value.set(val);
|
|
39
|
-
label.set(lbl);
|
|
40
|
-
query.set(lbl);
|
|
41
|
-
close();
|
|
42
|
-
};
|
|
43
|
-
const handleKeydown = (ev) => {
|
|
44
|
-
const list = filtered();
|
|
45
|
-
switch (ev.key) {
|
|
46
|
-
case "ArrowDown":
|
|
47
|
-
ev.preventDefault();
|
|
48
|
-
if (!open()) {
|
|
49
|
-
show();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
highlightedIndex.update((i) => i < list.length - 1 ? i + 1 : 0);
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
case "ArrowUp":
|
|
56
|
-
ev.preventDefault();
|
|
57
|
-
if (open()) {
|
|
58
|
-
highlightedIndex.update((i) => i > 0 ? i - 1 : list.length - 1);
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case "Enter":
|
|
62
|
-
ev.preventDefault();
|
|
63
|
-
if (open() && highlightedIndex() >= 0) {
|
|
64
|
-
const opt = list[highlightedIndex()];
|
|
65
|
-
if (opt) {
|
|
66
|
-
value.set(opt.value);
|
|
67
|
-
label.set(opt.label);
|
|
68
|
-
query.set(opt.label);
|
|
69
|
-
close();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
case "Escape":
|
|
74
|
-
close();
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const _attachTo = (el) => {
|
|
79
|
-
const scope = getCurrentScope();
|
|
80
|
-
const uid = ++comboboxUid;
|
|
81
|
-
// ARIA setup
|
|
82
|
-
const input = el.querySelector("input");
|
|
83
|
-
const list = el.querySelector("ul, [data-d-tag='d-combobox-list'], .d-combobox-list");
|
|
84
|
-
if (input) {
|
|
85
|
-
if (placeholder)
|
|
86
|
-
input.setAttribute("placeholder", placeholder);
|
|
87
|
-
input.setAttribute("role", "combobox");
|
|
88
|
-
input.setAttribute("aria-autocomplete", "list");
|
|
89
|
-
input.setAttribute("aria-expanded", "false");
|
|
90
|
-
}
|
|
91
|
-
if (list) {
|
|
92
|
-
const listId = list.id || `d-combobox-list-${uid}`;
|
|
93
|
-
if (!list.id)
|
|
94
|
-
list.id = listId;
|
|
95
|
-
list.setAttribute("role", "listbox");
|
|
96
|
-
if (input)
|
|
97
|
-
input.setAttribute("aria-controls", listId);
|
|
98
|
-
}
|
|
99
|
-
const unsubExpanded = open.on((isOpen) => {
|
|
100
|
-
input?.setAttribute("aria-expanded", String(isOpen));
|
|
101
|
-
});
|
|
102
|
-
const unsubHighlight = highlightedIndex.on((idx) => {
|
|
103
|
-
if (idx >= 0 && list) {
|
|
104
|
-
const opts = list.querySelectorAll("[data-value]");
|
|
105
|
-
const active = opts[idx];
|
|
106
|
-
if (active) {
|
|
107
|
-
const activeId = active.id || `d-combobox-opt-${uid}-${idx}`;
|
|
108
|
-
if (!active.id)
|
|
109
|
-
active.id = activeId;
|
|
110
|
-
active.setAttribute("role", "option");
|
|
111
|
-
input?.setAttribute("aria-activedescendant", activeId);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
input?.removeAttribute("aria-activedescendant");
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
// Hidden input for form submission
|
|
119
|
-
let hidden = el.querySelector('input[type="hidden"]');
|
|
120
|
-
if (!hidden) {
|
|
121
|
-
hidden = el.ownerDocument.createElement("input");
|
|
122
|
-
hidden.type = "hidden";
|
|
123
|
-
hidden.name = fieldName || input?.getAttribute("name") || "";
|
|
124
|
-
el.appendChild(hidden);
|
|
125
|
-
}
|
|
126
|
-
const unsubValue = value.on((v) => {
|
|
127
|
-
if (hidden)
|
|
128
|
-
hidden.value = v;
|
|
129
|
-
});
|
|
130
|
-
const onDocClick = (e) => {
|
|
131
|
-
if (!el.contains(e.target))
|
|
132
|
-
close();
|
|
133
|
-
};
|
|
134
|
-
if (isBrowser)
|
|
135
|
-
document.addEventListener("click", onDocClick);
|
|
136
|
-
if (scope) {
|
|
137
|
-
scope.onCleanup(() => {
|
|
138
|
-
unsubExpanded();
|
|
139
|
-
unsubHighlight();
|
|
140
|
-
unsubValue();
|
|
141
|
-
if (isBrowser)
|
|
142
|
-
document.removeEventListener("click", onDocClick);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
return {
|
|
147
|
-
open,
|
|
148
|
-
query,
|
|
149
|
-
value,
|
|
150
|
-
label,
|
|
151
|
-
filtered,
|
|
152
|
-
highlightedIndex,
|
|
153
|
-
show,
|
|
154
|
-
close,
|
|
155
|
-
toggle,
|
|
156
|
-
handleInput,
|
|
157
|
-
handleSelect,
|
|
158
|
-
handleKeydown,
|
|
159
|
-
_attachTo,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Signal } from "../../../core/signal.js";
|
|
2
|
-
import type { Dialog, DialogOptions } from "../ui-types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Shared dialog behavior — used by both createDialog and createDrawer.
|
|
5
|
-
*/
|
|
6
|
-
export declare function _attachDialogBehavior(el: HTMLDialogElement, open: Signal<boolean>, closeFn: () => void, opts: {
|
|
7
|
-
closeOnBackdrop: boolean;
|
|
8
|
-
closeOnEscape: boolean;
|
|
9
|
-
}): void;
|
|
10
|
-
export declare function createDialog(options?: DialogOptions): Dialog;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { signal } from "../../../core/signal.js";
|
|
2
|
-
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
-
import { _attachDialogBehavior } from "../dialog/index.js";
|
|
4
|
-
import { validateDrawerOptions } from "../validate.js";
|
|
5
|
-
const SIDE_CLASSES = {
|
|
6
|
-
right: "",
|
|
7
|
-
left: "d-drawer-left",
|
|
8
|
-
bottom: "d-sheet",
|
|
9
|
-
};
|
|
10
|
-
export function createDrawer(options = {}) {
|
|
11
|
-
validateDrawerOptions(options);
|
|
12
|
-
const { closeOnBackdrop = true, closeOnEscape = true, side: initialSide = "right", } = options;
|
|
13
|
-
const open = signal(false);
|
|
14
|
-
const side = signal(initialSide);
|
|
15
|
-
const show = () => open.set(true);
|
|
16
|
-
const close = () => open.set(false);
|
|
17
|
-
const toggle = () => open.update((v) => !v);
|
|
18
|
-
const _attachTo = (el) => {
|
|
19
|
-
const scope = getCurrentScope();
|
|
20
|
-
// Shared dialog behavior (open sync, backdrop, escape, ARIA)
|
|
21
|
-
_attachDialogBehavior(el, open, close, { closeOnBackdrop, closeOnEscape });
|
|
22
|
-
// Apply initial side class
|
|
23
|
-
const initial = SIDE_CLASSES[side()];
|
|
24
|
-
if (initial)
|
|
25
|
-
el.classList.add(initial);
|
|
26
|
-
// React to side changes
|
|
27
|
-
const unsub = side.on((s) => {
|
|
28
|
-
for (const cls of Object.values(SIDE_CLASSES)) {
|
|
29
|
-
if (cls)
|
|
30
|
-
el.classList.remove(cls);
|
|
31
|
-
}
|
|
32
|
-
const cls = SIDE_CLASSES[s];
|
|
33
|
-
if (cls)
|
|
34
|
-
el.classList.add(cls);
|
|
35
|
-
});
|
|
36
|
-
if (scope) {
|
|
37
|
-
scope.onCleanup(() => unsub());
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return { open, side, show, close, toggle, _attachTo };
|
|
41
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { signal } from "../../../core/signal.js";
|
|
2
|
-
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
-
import { isBrowser } from "../env.js";
|
|
4
|
-
export function createDropdown(options = {}) {
|
|
5
|
-
const { closeOnSelect = true } = options;
|
|
6
|
-
const open = signal(false);
|
|
7
|
-
const toggle = (ev) => {
|
|
8
|
-
if (ev)
|
|
9
|
-
ev.stopPropagation();
|
|
10
|
-
open.update((v) => !v);
|
|
11
|
-
};
|
|
12
|
-
const close = () => open.set(false);
|
|
13
|
-
const select = (ev) => {
|
|
14
|
-
if (ev)
|
|
15
|
-
ev.stopPropagation();
|
|
16
|
-
if (closeOnSelect)
|
|
17
|
-
close();
|
|
18
|
-
};
|
|
19
|
-
const _attachTo = (el) => {
|
|
20
|
-
const scope = getCurrentScope();
|
|
21
|
-
// ARIA
|
|
22
|
-
const trigger = el.querySelector("button, [role='button'], [data-d-tag='d-button']");
|
|
23
|
-
const menu = el.querySelector("[data-d-tag='d-menu'], .d-menu");
|
|
24
|
-
if (menu)
|
|
25
|
-
menu.setAttribute("role", "menu");
|
|
26
|
-
if (trigger) {
|
|
27
|
-
trigger.setAttribute("aria-haspopup", "true");
|
|
28
|
-
trigger.setAttribute("aria-expanded", "false");
|
|
29
|
-
}
|
|
30
|
-
const unsubAria = open.on((isOpen) => {
|
|
31
|
-
trigger?.setAttribute("aria-expanded", String(isOpen));
|
|
32
|
-
});
|
|
33
|
-
const onDocClick = (e) => {
|
|
34
|
-
if (!el.contains(e.target))
|
|
35
|
-
close();
|
|
36
|
-
};
|
|
37
|
-
if (isBrowser)
|
|
38
|
-
document.addEventListener("click", onDocClick);
|
|
39
|
-
if (scope) {
|
|
40
|
-
scope.onCleanup(() => {
|
|
41
|
-
unsubAria();
|
|
42
|
-
if (isBrowser)
|
|
43
|
-
document.removeEventListener("click", onDocClick);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
return { open, toggle, close, select, _attachTo };
|
|
48
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { signal } from "../../../core/signal.js";
|
|
2
|
-
import { getCurrentScope } from "../../../core/scope.js";
|
|
3
|
-
import { validateDropzoneOptions } from "../validate.js";
|
|
4
|
-
export function createDropzone(options = {}) {
|
|
5
|
-
validateDropzoneOptions(options);
|
|
6
|
-
const { accept, multiple = true, maxFiles, maxSize } = options;
|
|
7
|
-
const dragging = signal(false);
|
|
8
|
-
const files = signal([]);
|
|
9
|
-
let inputEl = null;
|
|
10
|
-
const filterFiles = (fileList) => {
|
|
11
|
-
let result = fileList;
|
|
12
|
-
if (accept) {
|
|
13
|
-
const types = accept.split(",").map((t) => t.trim().toLowerCase());
|
|
14
|
-
result = result.filter((f) => {
|
|
15
|
-
const ext = "." + f.name.split(".").pop()?.toLowerCase();
|
|
16
|
-
const mime = f.type.toLowerCase();
|
|
17
|
-
return types.some((t) => t === ext || t === mime || (t.endsWith("/*") && mime.startsWith(t.slice(0, -1))));
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
if (maxSize) {
|
|
21
|
-
result = result.filter((f) => f.size <= maxSize);
|
|
22
|
-
}
|
|
23
|
-
if (maxFiles) {
|
|
24
|
-
result = result.slice(0, maxFiles);
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
const addFiles = (newFiles) => {
|
|
29
|
-
const filtered = filterFiles(newFiles);
|
|
30
|
-
if (multiple) {
|
|
31
|
-
files.update((current) => {
|
|
32
|
-
const combined = [...current, ...filtered];
|
|
33
|
-
return maxFiles ? combined.slice(0, maxFiles) : combined;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
files.set(filtered.slice(0, 1));
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const browse = () => {
|
|
41
|
-
inputEl?.click();
|
|
42
|
-
};
|
|
43
|
-
const handleClick = () => browse();
|
|
44
|
-
const handleDragover = (ev) => {
|
|
45
|
-
ev.preventDefault();
|
|
46
|
-
dragging.set(true);
|
|
47
|
-
};
|
|
48
|
-
const handleDragleave = () => {
|
|
49
|
-
dragging.set(false);
|
|
50
|
-
};
|
|
51
|
-
const handleDrop = (ev) => {
|
|
52
|
-
ev.preventDefault();
|
|
53
|
-
dragging.set(false);
|
|
54
|
-
if (ev.dataTransfer?.files) {
|
|
55
|
-
addFiles(Array.from(ev.dataTransfer.files));
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const _attachTo = (el) => {
|
|
59
|
-
const scope = getCurrentScope();
|
|
60
|
-
// ARIA
|
|
61
|
-
el.setAttribute("role", "button");
|
|
62
|
-
el.setAttribute("tabindex", "0");
|
|
63
|
-
inputEl = el.querySelector('input[type="file"]');
|
|
64
|
-
if (inputEl) {
|
|
65
|
-
if (accept)
|
|
66
|
-
inputEl.accept = accept;
|
|
67
|
-
inputEl.multiple = multiple;
|
|
68
|
-
const onInputChange = () => {
|
|
69
|
-
if (inputEl?.files) {
|
|
70
|
-
addFiles(Array.from(inputEl.files));
|
|
71
|
-
inputEl.value = "";
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
inputEl.addEventListener("change", onInputChange);
|
|
75
|
-
if (scope) {
|
|
76
|
-
scope.onCleanup(() => {
|
|
77
|
-
inputEl?.removeEventListener("change", onInputChange);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return {
|
|
83
|
-
dragging,
|
|
84
|
-
files,
|
|
85
|
-
browse,
|
|
86
|
-
handleClick,
|
|
87
|
-
handleDragover,
|
|
88
|
-
handleDragleave,
|
|
89
|
-
handleDrop,
|
|
90
|
-
_attachTo,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isBrowser: boolean;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./ui-types.js";
|
|
2
|
-
export { createDialog, _attachDialogBehavior } from "./dialog/index.js";
|
|
3
|
-
export { createDrawer } from "./drawer/index.js";
|
|
4
|
-
export { createToast, toastIcon } from "./toast/index.js";
|
|
5
|
-
export { createTabs, tabBindings } from "./tabs/index.js";
|
|
6
|
-
export { createDropdown } from "./dropdown/index.js";
|
|
7
|
-
export { createCombobox } from "./combobox/index.js";
|
|
8
|
-
export { createAccordion } from "./accordion/index.js";
|
|
9
|
-
export { createCalendar } from "./calendar/index.js";
|
|
10
|
-
export { createDropzone } from "./dropzone/index.js";
|
|
11
|
-
export { createPopover } from "./popover/index.js";
|
|
12
|
-
export { mountUI } from "./runtime.js";
|
|
13
|
-
export type { MountUIOptions } from "./runtime.js";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./ui-types.js";
|
|
2
|
-
export { createDialog, _attachDialogBehavior } from "./dialog/index.js";
|
|
3
|
-
export { createDrawer } from "./drawer/index.js";
|
|
4
|
-
export { createToast, toastIcon } from "./toast/index.js";
|
|
5
|
-
export { createTabs, tabBindings } from "./tabs/index.js";
|
|
6
|
-
export { createDropdown } from "./dropdown/index.js";
|
|
7
|
-
export { createCombobox } from "./combobox/index.js";
|
|
8
|
-
export { createAccordion } from "./accordion/index.js";
|
|
9
|
-
export { createCalendar } from "./calendar/index.js";
|
|
10
|
-
export { createDropzone } from "./dropzone/index.js";
|
|
11
|
-
export { createPopover } from "./popover/index.js";
|
|
12
|
-
export { mountUI } from "./runtime.js";
|