@dorsk/tsumikit 0.2.11 → 0.2.13
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.
|
@@ -128,7 +128,11 @@
|
|
|
128
128
|
}
|
|
129
129
|
.textarea {
|
|
130
130
|
width: 100%;
|
|
131
|
-
padding
|
|
131
|
+
/* Horizontal padding matches Input/Button; vertical padding is tighter
|
|
132
|
+
(--sp-2) so a single line-box + border actually fits the 2.5rem floor —
|
|
133
|
+
--sp-3 top+bottom would overshoot it and a `rows={1}` textarea would
|
|
134
|
+
render taller than the buttons it sits beside. */
|
|
135
|
+
padding: var(--sp-2) var(--sp-3);
|
|
132
136
|
background: var(--bg);
|
|
133
137
|
border: 1px solid var(--border-strong);
|
|
134
138
|
border-radius: var(--r-md);
|
|
@@ -139,6 +143,7 @@
|
|
|
139
143
|
/* Match the single-row height of Button/Input so a `rows={1}` textarea
|
|
140
144
|
lines up with them; the native `rows` attribute grows it from here. */
|
|
141
145
|
min-height: 2.5rem;
|
|
146
|
+
line-height: var(--lh-tight);
|
|
142
147
|
font-family: inherit;
|
|
143
148
|
}
|
|
144
149
|
.textarea:focus {
|
|
@@ -146,7 +151,7 @@
|
|
|
146
151
|
border-color: var(--accent);
|
|
147
152
|
}
|
|
148
153
|
.textarea-sm {
|
|
149
|
-
padding: var(--sp-2);
|
|
154
|
+
padding: var(--sp-1) var(--sp-2);
|
|
150
155
|
font-size: var(--fs-sm);
|
|
151
156
|
min-height: 2rem;
|
|
152
157
|
}
|
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
// Drag-and-drop file area with a click/keyboard fallback to the file dialog.
|
|
3
3
|
// Emits chosen/dropped files via `onfiles`. Filters by `accept` (extensions
|
|
4
|
-
// or mime patterns). Dependency-free
|
|
5
|
-
//
|
|
4
|
+
// or mime patterns). Dependency-free.
|
|
5
|
+
//
|
|
6
|
+
// Two modes:
|
|
7
|
+
// - Default (box): the whole zone is a labelled button so it's
|
|
8
|
+
// keyboard-operable, backed by a visually-hidden <input type=file>.
|
|
9
|
+
// Children, if passed, render inside the dashed box.
|
|
10
|
+
// - Overlay (`overlay`): wraps interactive content. Children render in
|
|
11
|
+
// normal flow (no box model, no click hijack); the dashed border + label
|
|
12
|
+
// paint as an absolutely-positioned layer only while a file is dragged
|
|
13
|
+
// over. Drop-only — the browse affordance stays on the host (e.g. a
|
|
14
|
+
// FileButton). Use this to make a whole surface/drawer/window a drop
|
|
15
|
+
// target.
|
|
6
16
|
import type { Snippet } from 'svelte';
|
|
7
17
|
import Icon from '../atoms/Icon.svelte';
|
|
8
18
|
|
|
9
19
|
let {
|
|
10
20
|
onfiles,
|
|
21
|
+
onactive,
|
|
11
22
|
accept,
|
|
12
23
|
multiple = true,
|
|
13
24
|
disabled = false,
|
|
25
|
+
overlay = false,
|
|
14
26
|
label = 'Drop files here',
|
|
15
27
|
hint = 'or click to browse',
|
|
16
28
|
children
|
|
17
29
|
}: {
|
|
18
30
|
onfiles: (files: File[]) => void;
|
|
31
|
+
/** Fired when the drag-over (active) state changes — host can dim/highlight. */
|
|
32
|
+
onactive?: (active: boolean) => void;
|
|
19
33
|
accept?: string;
|
|
20
34
|
multiple?: boolean;
|
|
21
35
|
disabled?: boolean;
|
|
36
|
+
/** Wrap interactive content; show the drop UI as an overlay only while dragging. */
|
|
37
|
+
overlay?: boolean;
|
|
22
38
|
label?: string;
|
|
23
39
|
hint?: string;
|
|
24
40
|
children?: Snippet;
|
|
@@ -27,6 +43,19 @@
|
|
|
27
43
|
let over = $state(false);
|
|
28
44
|
let input = $state<HTMLInputElement | null>(null);
|
|
29
45
|
|
|
46
|
+
// Depth counter for robust enter/leave detection — dragenter/dragleave fire
|
|
47
|
+
// for every child element the cursor crosses, so a naive boolean flickers.
|
|
48
|
+
let depth = 0;
|
|
49
|
+
|
|
50
|
+
function setOver(next: boolean) {
|
|
51
|
+
if (over === next) return;
|
|
52
|
+
over = next;
|
|
53
|
+
onactive?.(next);
|
|
54
|
+
}
|
|
55
|
+
function hasFiles(e: DragEvent): boolean {
|
|
56
|
+
return Array.from(e.dataTransfer?.types ?? []).includes('Files');
|
|
57
|
+
}
|
|
58
|
+
|
|
30
59
|
function accepted(files: File[]): File[] {
|
|
31
60
|
if (!accept) return files;
|
|
32
61
|
const pats = accept.split(',').map((s) => s.trim().toLowerCase());
|
|
@@ -46,54 +75,91 @@
|
|
|
46
75
|
if (!multiple) files = files.slice(0, 1);
|
|
47
76
|
if (files.length) onfiles(files);
|
|
48
77
|
}
|
|
78
|
+
|
|
79
|
+
function onDragEnter(e: DragEvent) {
|
|
80
|
+
if (disabled || !hasFiles(e)) return;
|
|
81
|
+
depth++;
|
|
82
|
+
if (depth === 1) setOver(true);
|
|
83
|
+
}
|
|
84
|
+
function onDragLeave(e: DragEvent) {
|
|
85
|
+
if (disabled || !hasFiles(e)) return;
|
|
86
|
+
depth = Math.max(0, depth - 1);
|
|
87
|
+
if (depth === 0) setOver(false);
|
|
88
|
+
}
|
|
89
|
+
function onDragOver(e: DragEvent) {
|
|
90
|
+
if (disabled) return;
|
|
91
|
+
// preventDefault is required or `drop` never fires.
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy';
|
|
94
|
+
}
|
|
49
95
|
function onDrop(e: DragEvent) {
|
|
50
96
|
e.preventDefault();
|
|
51
|
-
|
|
97
|
+
depth = 0;
|
|
98
|
+
setOver(false);
|
|
52
99
|
if (disabled) return;
|
|
53
100
|
emit(e.dataTransfer?.files);
|
|
54
101
|
}
|
|
55
102
|
</script>
|
|
56
103
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
{
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
{#if overlay}
|
|
105
|
+
<div
|
|
106
|
+
class="dz-host"
|
|
107
|
+
class:over
|
|
108
|
+
class:disabled
|
|
109
|
+
role="presentation"
|
|
110
|
+
ondragenter={onDragEnter}
|
|
111
|
+
ondragleave={onDragLeave}
|
|
112
|
+
ondragover={onDragOver}
|
|
113
|
+
ondrop={onDrop}
|
|
114
|
+
>
|
|
115
|
+
{@render children?.()}
|
|
116
|
+
{#if over}
|
|
117
|
+
<div class="dz-overlay" aria-hidden="true">
|
|
118
|
+
<Icon name="upload" size={28} />
|
|
119
|
+
<span class="dz-label">{label}</span>
|
|
120
|
+
</div>
|
|
121
|
+
{/if}
|
|
122
|
+
</div>
|
|
123
|
+
{:else}
|
|
124
|
+
<div
|
|
125
|
+
class="dz"
|
|
126
|
+
class:over
|
|
127
|
+
class:disabled
|
|
128
|
+
role="button"
|
|
129
|
+
tabindex={disabled ? -1 : 0}
|
|
130
|
+
aria-label="{label}. {hint}"
|
|
131
|
+
aria-disabled={disabled || undefined}
|
|
132
|
+
ondragenter={onDragEnter}
|
|
133
|
+
ondragleave={onDragLeave}
|
|
134
|
+
ondragover={onDragOver}
|
|
135
|
+
ondrop={onDrop}
|
|
136
|
+
onclick={() => !disabled && input?.click()}
|
|
137
|
+
onkeydown={(e) => {
|
|
138
|
+
if ((e.key === 'Enter' || e.key === ' ') && !disabled) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
input?.click();
|
|
141
|
+
}
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<input
|
|
145
|
+
bind:this={input}
|
|
146
|
+
class="sr-only"
|
|
147
|
+
type="file"
|
|
148
|
+
{accept}
|
|
149
|
+
{multiple}
|
|
150
|
+
{disabled}
|
|
151
|
+
tabindex="-1"
|
|
152
|
+
onchange={(e) => emit((e.currentTarget as HTMLInputElement).files)}
|
|
153
|
+
/>
|
|
154
|
+
{#if children}
|
|
155
|
+
{@render children()}
|
|
156
|
+
{:else}
|
|
157
|
+
<Icon name="upload" size={28} />
|
|
158
|
+
<span class="dz-label">{label}</span>
|
|
159
|
+
<span class="dz-hint">{hint}</span>
|
|
160
|
+
{/if}
|
|
161
|
+
</div>
|
|
162
|
+
{/if}
|
|
97
163
|
|
|
98
164
|
<style>
|
|
99
165
|
.dz {
|
|
@@ -129,6 +195,37 @@
|
|
|
129
195
|
opacity: 0.45;
|
|
130
196
|
cursor: not-allowed;
|
|
131
197
|
}
|
|
198
|
+
|
|
199
|
+
/* Overlay mode: don't impose a box model on the host layout. The wrapper is
|
|
200
|
+
a positioning context for the absolute overlay; otherwise it passes
|
|
201
|
+
through (full size, transparent). */
|
|
202
|
+
.dz-host {
|
|
203
|
+
position: relative;
|
|
204
|
+
display: flex;
|
|
205
|
+
flex-direction: column;
|
|
206
|
+
min-height: 0;
|
|
207
|
+
min-width: 0;
|
|
208
|
+
width: 100%;
|
|
209
|
+
height: 100%;
|
|
210
|
+
}
|
|
211
|
+
.dz-overlay {
|
|
212
|
+
position: absolute;
|
|
213
|
+
inset: 0;
|
|
214
|
+
z-index: 10;
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
align-items: center;
|
|
218
|
+
justify-content: center;
|
|
219
|
+
gap: var(--sp-2);
|
|
220
|
+
text-align: center;
|
|
221
|
+
color: var(--text);
|
|
222
|
+
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
|
223
|
+
border: 2px dashed var(--accent);
|
|
224
|
+
border-radius: var(--r-lg);
|
|
225
|
+
pointer-events: none;
|
|
226
|
+
backdrop-filter: blur(1px);
|
|
227
|
+
}
|
|
228
|
+
|
|
132
229
|
.dz-label {
|
|
133
230
|
font-weight: var(--fw-medium);
|
|
134
231
|
font-size: var(--fs-sm);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
type $$ComponentProps = {
|
|
3
3
|
onfiles: (files: File[]) => void;
|
|
4
|
+
/** Fired when the drag-over (active) state changes — host can dim/highlight. */
|
|
5
|
+
onactive?: (active: boolean) => void;
|
|
4
6
|
accept?: string;
|
|
5
7
|
multiple?: boolean;
|
|
6
8
|
disabled?: boolean;
|
|
9
|
+
/** Wrap interactive content; show the drop UI as an overlay only while dragging. */
|
|
10
|
+
overlay?: boolean;
|
|
7
11
|
label?: string;
|
|
8
12
|
hint?: string;
|
|
9
13
|
children?: Snippet;
|
package/package.json
CHANGED