@x33025/sveltely 0.0.35 → 0.0.36
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.
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
tags: string[];
|
|
9
9
|
selection?: string[];
|
|
10
|
+
disabled?: boolean;
|
|
10
11
|
action?: Snippet;
|
|
11
12
|
};
|
|
12
13
|
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
placeholder = 'Add a tag...',
|
|
15
16
|
tags = $bindable<string[]>(),
|
|
16
17
|
selection = $bindable<string[] | undefined>(),
|
|
18
|
+
disabled = false,
|
|
17
19
|
action
|
|
18
20
|
}: Props = $props();
|
|
19
21
|
|
|
@@ -56,7 +58,7 @@
|
|
|
56
58
|
};
|
|
57
59
|
|
|
58
60
|
const beginRangeSelection = (event: PointerEvent, index: number) => {
|
|
59
|
-
if (!selectionEnabled || event.button !== 0) return;
|
|
61
|
+
if (disabled || !selectionEnabled || event.button !== 0) return;
|
|
60
62
|
dragStartIndex = index;
|
|
61
63
|
dragHoverIndex = index;
|
|
62
64
|
isPointerSelecting = true;
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
const extendRangeSelection = (index: number) => {
|
|
67
|
-
if (!selectionEnabled || !isPointerSelecting || dragStartIndex === null) return;
|
|
69
|
+
if (disabled || !selectionEnabled || !isPointerSelecting || dragStartIndex === null) return;
|
|
68
70
|
dragHoverIndex = index;
|
|
69
71
|
if (dragStartIndex === index && !rangeSelectionMoved) return;
|
|
70
72
|
rangeSelectionMoved = true;
|
|
@@ -81,6 +83,7 @@
|
|
|
81
83
|
};
|
|
82
84
|
|
|
83
85
|
const onChipClick = (tag: string) => {
|
|
86
|
+
if (disabled) return;
|
|
84
87
|
if (suppressNextClick) {
|
|
85
88
|
suppressNextClick = false;
|
|
86
89
|
return;
|
|
@@ -89,13 +92,14 @@
|
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
const handleWindowPointerDown = (event: PointerEvent) => {
|
|
92
|
-
if (!selectionEnabled || !selection || !rootEl) return;
|
|
95
|
+
if (disabled || !selectionEnabled || !selection || !rootEl) return;
|
|
93
96
|
const target = event.target as Node | null;
|
|
94
97
|
if (target && rootEl.contains(target)) return;
|
|
95
98
|
selection = [];
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
const onKeydown = (event: KeyboardEvent) => {
|
|
102
|
+
if (disabled) return;
|
|
99
103
|
if ((event.key === 'Enter' || event.key === ',') && inputValue.trim()) {
|
|
100
104
|
event.preventDefault();
|
|
101
105
|
addTag(inputValue);
|
|
@@ -122,12 +126,14 @@
|
|
|
122
126
|
};
|
|
123
127
|
|
|
124
128
|
const openInput = async () => {
|
|
129
|
+
if (disabled) return;
|
|
125
130
|
showInput = true;
|
|
126
131
|
await tick();
|
|
127
132
|
inputEl?.focus();
|
|
128
133
|
};
|
|
129
134
|
|
|
130
135
|
const startEditing = async (tag: string) => {
|
|
136
|
+
if (disabled) return;
|
|
131
137
|
editingTag = tag;
|
|
132
138
|
editingValue = tag;
|
|
133
139
|
await tick();
|
|
@@ -177,6 +183,7 @@
|
|
|
177
183
|
};
|
|
178
184
|
|
|
179
185
|
const onEditKeydown = async (event: KeyboardEvent, tag: string) => {
|
|
186
|
+
if (disabled) return;
|
|
180
187
|
if (event.key === 'Enter') {
|
|
181
188
|
event.preventDefault();
|
|
182
189
|
await commitEdit('enter', tag);
|
|
@@ -208,6 +215,14 @@
|
|
|
208
215
|
selection = nextSelected;
|
|
209
216
|
}
|
|
210
217
|
});
|
|
218
|
+
|
|
219
|
+
$effect(() => {
|
|
220
|
+
if (!disabled) return;
|
|
221
|
+
endRangeSelection();
|
|
222
|
+
suppressNextClick = false;
|
|
223
|
+
showInput = false;
|
|
224
|
+
cancelEdit();
|
|
225
|
+
});
|
|
211
226
|
</script>
|
|
212
227
|
|
|
213
228
|
<svelte:window
|
|
@@ -216,7 +231,12 @@
|
|
|
216
231
|
onpointerdown={handleWindowPointerDown}
|
|
217
232
|
/>
|
|
218
233
|
|
|
219
|
-
<div
|
|
234
|
+
<div
|
|
235
|
+
bind:this={rootEl}
|
|
236
|
+
class="chip-row flex w-full flex-wrap items-center"
|
|
237
|
+
class:chip-disabled={disabled}
|
|
238
|
+
aria-disabled={disabled}
|
|
239
|
+
>
|
|
220
240
|
{#each tags as tag, index (tag)}
|
|
221
241
|
{#if editingTag === tag}
|
|
222
242
|
<input
|
|
@@ -224,6 +244,7 @@
|
|
|
224
244
|
bind:value={editingValue}
|
|
225
245
|
size={Math.max(editingValue.length, 1)}
|
|
226
246
|
class="chip-surface chip-input-field outline-none"
|
|
247
|
+
{disabled}
|
|
227
248
|
onblur={() => commitEdit('blur', tag)}
|
|
228
249
|
onkeydown={(event) => onEditKeydown(event, tag)}
|
|
229
250
|
/>
|
|
@@ -238,6 +259,7 @@
|
|
|
238
259
|
onclick={() => onChipClick(tag)}
|
|
239
260
|
ondblclick={() => startEditing(tag)}
|
|
240
261
|
aria-pressed={selection?.includes(tag)}
|
|
262
|
+
{disabled}
|
|
241
263
|
>
|
|
242
264
|
{tag}
|
|
243
265
|
</button>
|
|
@@ -245,6 +267,7 @@
|
|
|
245
267
|
<button
|
|
246
268
|
type="button"
|
|
247
269
|
class="chip-surface inline-flex items-center gap-2"
|
|
270
|
+
{disabled}
|
|
248
271
|
ondblclick={() => startEditing(tag)}>{tag}</button
|
|
249
272
|
>
|
|
250
273
|
{/if}
|
|
@@ -257,6 +280,7 @@
|
|
|
257
280
|
size={Math.max(inputValue.length, placeholder.length, 1)}
|
|
258
281
|
class="chip-surface chip-input-field outline-none"
|
|
259
282
|
{placeholder}
|
|
283
|
+
{disabled}
|
|
260
284
|
onkeydown={onKeydown}
|
|
261
285
|
onblur={onBlur}
|
|
262
286
|
/>
|
|
@@ -265,6 +289,7 @@
|
|
|
265
289
|
type="button"
|
|
266
290
|
class="chip-surface chip-input-action inline-flex items-center justify-center font-semibold"
|
|
267
291
|
aria-label="Add tag"
|
|
292
|
+
{disabled}
|
|
268
293
|
onclick={openInput}
|
|
269
294
|
>
|
|
270
295
|
<Plus style="width: var(--chip-input-font-size); height: var(--chip-input-font-size);" />
|
|
@@ -306,4 +331,17 @@
|
|
|
306
331
|
.chip-input-field:hover {
|
|
307
332
|
background: var(--chip-input-background);
|
|
308
333
|
}
|
|
334
|
+
|
|
335
|
+
.chip-disabled .chip-surface {
|
|
336
|
+
cursor: not-allowed;
|
|
337
|
+
opacity: 0.55;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.chip-disabled {
|
|
341
|
+
pointer-events: none;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.chip-disabled .chip-surface:hover {
|
|
345
|
+
background: var(--chip-input-background);
|
|
346
|
+
}
|
|
309
347
|
</style>
|
package/dist/style/index.css
CHANGED
package/dist/style.css
CHANGED
|
@@ -581,6 +581,9 @@
|
|
|
581
581
|
height: 1px;
|
|
582
582
|
width: 100%;
|
|
583
583
|
}
|
|
584
|
+
.overflow-auto > .vstack, .overflow-auto > .hstack {
|
|
585
|
+
flex-shrink: 0;
|
|
586
|
+
}
|
|
584
587
|
.chip-input-action {
|
|
585
588
|
width: calc(var(--chip-input-font-size) + 16px);
|
|
586
589
|
height: calc(var(--chip-input-font-size) + 16px);
|