svelte-comp 1.3.5 → 1.3.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.
Files changed (46) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +101 -101
  3. package/dist/App.svelte +1046 -1046
  4. package/dist/Container.svelte +59 -59
  5. package/dist/app.css +234 -234
  6. package/dist/app.d.ts +10 -10
  7. package/dist/lib/Accordion.svelte +155 -155
  8. package/dist/lib/Badge.svelte +44 -44
  9. package/dist/lib/Button.svelte +185 -185
  10. package/dist/lib/Calendar.svelte +384 -384
  11. package/dist/lib/Card.svelte +103 -103
  12. package/dist/lib/Carousel.svelte +293 -293
  13. package/dist/lib/CheckBox.svelte +210 -210
  14. package/dist/lib/CodeView.svelte +308 -308
  15. package/dist/lib/ColorPicker.svelte +159 -159
  16. package/dist/lib/ContextMenu.svelte +328 -328
  17. package/dist/lib/DatePicker.svelte +246 -246
  18. package/dist/lib/Dialog.svelte +233 -233
  19. package/dist/lib/Field.svelte +299 -299
  20. package/dist/lib/FilePicker.svelte +295 -295
  21. package/dist/lib/Form.svelte +438 -438
  22. package/dist/lib/Hamburger.svelte +217 -217
  23. package/dist/lib/InstallPWA.svelte +94 -94
  24. package/dist/lib/Menu.svelte +623 -623
  25. package/dist/lib/NoticeBase.svelte +140 -140
  26. package/dist/lib/PaginatedCard.svelte +73 -73
  27. package/dist/lib/Pagination.svelte +119 -119
  28. package/dist/lib/PrimaryColorSelect.svelte +111 -111
  29. package/dist/lib/ProgressBar.svelte +141 -141
  30. package/dist/lib/ProgressCircle.svelte +190 -190
  31. package/dist/lib/Radio.svelte +189 -189
  32. package/dist/lib/SearchInput.svelte +104 -104
  33. package/dist/lib/Select.svelte +524 -524
  34. package/dist/lib/Slider.svelte +253 -253
  35. package/dist/lib/Splitter.svelte +159 -159
  36. package/dist/lib/Switch.svelte +168 -168
  37. package/dist/lib/Table.svelte +299 -299
  38. package/dist/lib/Tabs.svelte +213 -213
  39. package/dist/lib/ThemeToggle.svelte +128 -128
  40. package/dist/lib/TimePicker.svelte +312 -312
  41. package/dist/lib/TimePickerNew.svelte +634 -634
  42. package/dist/lib/Toast.svelte +123 -123
  43. package/dist/lib/Tooltip.svelte +110 -110
  44. package/dist/lib/Topbar.svelte +112 -112
  45. package/dist/styles.css +234 -234
  46. package/package.json +52 -52
@@ -1,295 +1,295 @@
1
- <!-- src/lib/FilePicker.svelte -->
2
- <script lang="ts">
3
- /**
4
- * @component FilePicker
5
- * @description Lightweight file selector with click support and drag-and-drop. Internally uses a hidden `<input type="file">` plus a drop zone.
6
- *
7
- * @prop accept {string} - Accepted file types
8
- * @default "*\\/*"
9
- *
10
- * @prop multiple {boolean} - Allows selecting multiple files
11
- * @default false
12
- *
13
- * @prop label {string} - Button label; falls back to localized text
14
- *
15
- * @prop disabled {boolean} - Disables all interactions
16
- * @default false
17
- *
18
- * @prop clearable {boolean} - Shows a clear button to reset selection
19
- * @default true
20
- *
21
- * @prop maxBytes {number} - Maximum allowed file size in bytes
22
- *
23
- * @prop onError {(error: string) => void} - Fired when selected files are rejected
24
- *
25
- * @prop placeholder {string} - Placeholder text for the drop zone
26
- *
27
- * @prop value {FileList | null} - Controlled selected files (bindable)
28
- * @default null
29
- *
30
- * @prop onFilesSelected {(files: FileList | null) => void} - Fired when files are chosen
31
- *
32
- * @prop class {string} - Additional classes for the wrapper
33
- * @default ""
34
- *
35
- * @note The entire area is clickable and supports drag-and-drop.
36
- * @note After a selection, the underlying input resets its value, so choosing the same file twice still triggers updates.
37
- * @note `accept` and `maxBytes` are enforced for both input and dropped files.
38
- * @note When `clearable=true`, the user can clear selected files and the callback receives `null`.
39
- * @note When `disabled=true`, clicks, drag events, focus, and keyboard input are blocked.
40
- */
41
- import type { HTMLAttributes } from "svelte/elements";
42
- import Button from "./Button.svelte";
43
- import { cx, formatFileSize } from "../utils";
44
- import { getComponentText, getLangContext, getLangKey } from "./lang-context";
45
-
46
- type Props = HTMLAttributes<HTMLDivElement> & {
47
- accept?: string;
48
- multiple?: boolean;
49
- label?: string;
50
- disabled?: boolean;
51
- clearable?: boolean;
52
- placeholder?: string;
53
- value?: FileList | null;
54
- maxBytes?: number;
55
- onFilesSelected?: (files: FileList | null) => void;
56
- onError?: (error: string) => void;
57
- class?: string;
58
- };
59
-
60
- let {
61
- accept = "*/*",
62
- multiple = false,
63
- label,
64
- disabled = false,
65
- clearable = true,
66
- placeholder,
67
- value = $bindable<FileList | null>(null),
68
- maxBytes = Number.POSITIVE_INFINITY,
69
- onFilesSelected,
70
- onError,
71
- class: externalClass = "",
72
- ...rest
73
- }: Props = $props();
74
-
75
- const langCtx = getLangContext();
76
- const langKey = $derived(getLangKey(langCtx));
77
- const L = $derived(getComponentText("filePicker", langKey));
78
-
79
- const labelFinal = $derived(label ?? L.text);
80
- const placeholderFinal = $derived(placeholder ?? L.placeholder);
81
-
82
- let inputEl: HTMLInputElement;
83
- let isDragOver = $state(false);
84
-
85
- const base = "inline-block w-full";
86
- const pickerClass = $derived(cx(base, externalClass));
87
-
88
- const hasValue = $derived(Boolean(value && value.length > 0));
89
- const fileNames = $derived(
90
- value
91
- ? Array.from(value)
92
- .map((file) => file.name)
93
- .join(", ")
94
- : ""
95
- );
96
- const totalBytes = $derived(
97
- value ? Array.from(value).reduce((acc, file) => acc + file.size, 0) : 0
98
- );
99
-
100
- function handleButtonClick() {
101
- if (disabled) return;
102
- inputEl?.click();
103
- }
104
-
105
- function handleFileChange(event: Event) {
106
- const target = event.target as HTMLInputElement;
107
- selectFiles(target.files);
108
- if (inputEl) {
109
- inputEl.value = "";
110
- }
111
- }
112
-
113
- function handleDrop(event: DragEvent) {
114
- event.preventDefault();
115
- isDragOver = false;
116
- if (disabled) return;
117
- selectFiles(event.dataTransfer?.files ?? null);
118
- if (inputEl) {
119
- inputEl.value = "";
120
- }
121
- }
122
-
123
- function handleDragOver(event: DragEvent) {
124
- event.preventDefault();
125
- }
126
-
127
- function handleDragEnter(event: DragEvent) {
128
- event.preventDefault();
129
- if (!disabled) {
130
- isDragOver = true;
131
- }
132
- }
133
-
134
- function handleDragLeave(event: DragEvent) {
135
- event.preventDefault();
136
- isDragOver = false;
137
- }
138
-
139
- function handleKeyDown(event: KeyboardEvent) {
140
- if (disabled) return;
141
- if (event.key === "Enter" || event.key === " ") {
142
- event.preventDefault();
143
- handleButtonClick();
144
- }
145
- }
146
-
147
- function clearSelection() {
148
- if (!clearable) return;
149
- value = null;
150
- if (inputEl) {
151
- inputEl.value = "";
152
- }
153
- onFilesSelected?.(null);
154
- }
155
-
156
- function selectFiles(files: FileList | null) {
157
- const acceptedFiles = filterFiles(files);
158
- value = acceptedFiles;
159
- if (acceptedFiles && acceptedFiles.length > 0) {
160
- onFilesSelected?.(acceptedFiles);
161
- }
162
- }
163
-
164
- function filterFiles(files: FileList | null) {
165
- if (!files || files.length === 0) return null;
166
-
167
- const selected = Array.from(files);
168
- const accepted = selected.filter(isAllowedFile);
169
-
170
- if (accepted.length !== selected.length) {
171
- onError?.("Some files were rejected by type or size constraints.");
172
- }
173
-
174
- if (accepted.length === 0) return null;
175
- if (accepted.length === selected.length) return files;
176
-
177
- return toFileList(accepted);
178
- }
179
-
180
- function isAllowedFile(file: File) {
181
- if (Number.isFinite(maxBytes) && file.size > maxBytes) return false;
182
- return matchesAccept(file, accept);
183
- }
184
-
185
- function matchesAccept(file: File, acceptValue: string) {
186
- const rules = acceptValue
187
- .split(",")
188
- .map((rule) => rule.trim().toLowerCase())
189
- .filter(Boolean);
190
-
191
- if (rules.length === 0 || rules.includes("*/*")) return true;
192
-
193
- const fileName = file.name.toLowerCase();
194
- const fileType = file.type.toLowerCase();
195
-
196
- return rules.some((rule) => {
197
- if (rule.startsWith(".")) return fileName.endsWith(rule);
198
- if (rule.endsWith("/*")) return fileType.startsWith(rule.slice(0, -1));
199
- return fileType === rule;
200
- });
201
- }
202
-
203
- function toFileList(files: File[]) {
204
- if (typeof DataTransfer === "undefined") return null;
205
- const transfer = new DataTransfer();
206
- for (const file of files) {
207
- transfer.items.add(file);
208
- }
209
- return transfer.files;
210
- }
211
- </script>
212
-
213
- <div class={pickerClass} {...rest}>
214
- <input
215
- bind:this={inputEl}
216
- type="file"
217
- {accept}
218
- {multiple}
219
- class="hidden"
220
- onchange={handleFileChange}
221
- />
222
-
223
- <div class="flex flex-wrap items-center gap-x-3 gap-y-2">
224
- <Button {disabled} onClick={handleButtonClick} class="relative" sz="xs">
225
- {labelFinal}
226
- </Button>
227
-
228
- {#if clearable}
229
- <Button
230
- onClick={clearSelection}
231
- variant="danger"
232
- disabled={!hasValue || disabled}
233
- sz="xs"
234
- >
235
- {L.clear}
236
- </Button>
237
- {/if}
238
- </div>
239
-
240
- <div
241
- class="mt-2 p-4 border-2 border-dashed rounded-[var(--radius-md)] text-center transition-colors duration-200"
242
- class:border-[var(--color-primary)]={isDragOver && !disabled}
243
- class:border-[var(--border-color-default)]={!isDragOver || disabled}
244
- class:bg-[var(--color-bg-hover)]={isDragOver && !disabled}
245
- class:cursor-pointer={!disabled}
246
- class:opacity-[var(--opacity-disabled)]={disabled}
247
- class:cursor-not-allowed={disabled}
248
- class:cursor-copy={isDragOver && !disabled}
249
- role="button"
250
- tabindex={disabled ? -1 : 0}
251
- aria-disabled={disabled}
252
- ondrop={handleDrop}
253
- ondragover={handleDragOver}
254
- ondragenter={handleDragEnter}
255
- ondragleave={handleDragLeave}
256
- onclick={handleButtonClick}
257
- onkeydown={handleKeyDown}
258
- >
259
- <p class="text-sm [color:var(--color-text-muted)]">
260
- {L.dragDrop}
261
- </p>
262
- {#if accept !== "*/*"}
263
- <p class="text-xs mt-1 [color:var(--color-text-muted)]">
264
- {L.accepted}: {accept}
265
- </p>
266
- {/if}
267
- </div>
268
-
269
- <div
270
- class="mt-3 p-4 bg-[var(--color-bg-surface)] text-center"
271
- aria-live="polite"
272
- >
273
- <p class="text-xs uppercase tracking-wide [color:var(--color-text-muted)]">
274
- {L.selectedFiles}
275
- </p>
276
- <p
277
- class="text-sm font-semibold mt-1 [color:var(--color-text-default)] break-words"
278
- >
279
- {#if hasValue}
280
- {fileNames}
281
- {:else}
282
- {placeholderFinal}
283
- {/if}
284
- </p>
285
- {#if hasValue && value}
286
- <p class="text-sm mt-1 [color:var(--color-text-muted)]">
287
- {L.fileCount.replace("{n}", String(value.length))}
288
-
289
- {#if multiple && value.length > 1}
290
- - {L.totalSize}: {formatFileSize(totalBytes)}
291
- {/if}
292
- </p>
293
- {/if}
294
- </div>
295
- </div>
1
+ <!-- src/lib/FilePicker.svelte -->
2
+ <script lang="ts">
3
+ /**
4
+ * @component FilePicker
5
+ * @description Lightweight file selector with click support and drag-and-drop. Internally uses a hidden `<input type="file">` plus a drop zone.
6
+ *
7
+ * @prop accept {string} - Accepted file types
8
+ * @default "*\\/*"
9
+ *
10
+ * @prop multiple {boolean} - Allows selecting multiple files
11
+ * @default false
12
+ *
13
+ * @prop label {string} - Button label; falls back to localized text
14
+ *
15
+ * @prop disabled {boolean} - Disables all interactions
16
+ * @default false
17
+ *
18
+ * @prop clearable {boolean} - Shows a clear button to reset selection
19
+ * @default true
20
+ *
21
+ * @prop maxBytes {number} - Maximum allowed file size in bytes
22
+ *
23
+ * @prop onError {(error: string) => void} - Fired when selected files are rejected
24
+ *
25
+ * @prop placeholder {string} - Placeholder text for the drop zone
26
+ *
27
+ * @prop value {FileList | null} - Controlled selected files (bindable)
28
+ * @default null
29
+ *
30
+ * @prop onFilesSelected {(files: FileList | null) => void} - Fired when files are chosen
31
+ *
32
+ * @prop class {string} - Additional classes for the wrapper
33
+ * @default ""
34
+ *
35
+ * @note The entire area is clickable and supports drag-and-drop.
36
+ * @note After a selection, the underlying input resets its value, so choosing the same file twice still triggers updates.
37
+ * @note `accept` and `maxBytes` are enforced for both input and dropped files.
38
+ * @note When `clearable=true`, the user can clear selected files and the callback receives `null`.
39
+ * @note When `disabled=true`, clicks, drag events, focus, and keyboard input are blocked.
40
+ */
41
+ import type { HTMLAttributes } from "svelte/elements";
42
+ import Button from "./Button.svelte";
43
+ import { cx, formatFileSize } from "../utils";
44
+ import { getComponentText, getLangContext, getLangKey } from "./lang-context";
45
+
46
+ type Props = HTMLAttributes<HTMLDivElement> & {
47
+ accept?: string;
48
+ multiple?: boolean;
49
+ label?: string;
50
+ disabled?: boolean;
51
+ clearable?: boolean;
52
+ placeholder?: string;
53
+ value?: FileList | null;
54
+ maxBytes?: number;
55
+ onFilesSelected?: (files: FileList | null) => void;
56
+ onError?: (error: string) => void;
57
+ class?: string;
58
+ };
59
+
60
+ let {
61
+ accept = "*/*",
62
+ multiple = false,
63
+ label,
64
+ disabled = false,
65
+ clearable = true,
66
+ placeholder,
67
+ value = $bindable<FileList | null>(null),
68
+ maxBytes = Number.POSITIVE_INFINITY,
69
+ onFilesSelected,
70
+ onError,
71
+ class: externalClass = "",
72
+ ...rest
73
+ }: Props = $props();
74
+
75
+ const langCtx = getLangContext();
76
+ const langKey = $derived(getLangKey(langCtx));
77
+ const L = $derived(getComponentText("filePicker", langKey));
78
+
79
+ const labelFinal = $derived(label ?? L.text);
80
+ const placeholderFinal = $derived(placeholder ?? L.placeholder);
81
+
82
+ let inputEl: HTMLInputElement;
83
+ let isDragOver = $state(false);
84
+
85
+ const base = "inline-block w-full";
86
+ const pickerClass = $derived(cx(base, externalClass));
87
+
88
+ const hasValue = $derived(Boolean(value && value.length > 0));
89
+ const fileNames = $derived(
90
+ value
91
+ ? Array.from(value)
92
+ .map((file) => file.name)
93
+ .join(", ")
94
+ : ""
95
+ );
96
+ const totalBytes = $derived(
97
+ value ? Array.from(value).reduce((acc, file) => acc + file.size, 0) : 0
98
+ );
99
+
100
+ function handleButtonClick() {
101
+ if (disabled) return;
102
+ inputEl?.click();
103
+ }
104
+
105
+ function handleFileChange(event: Event) {
106
+ const target = event.target as HTMLInputElement;
107
+ selectFiles(target.files);
108
+ if (inputEl) {
109
+ inputEl.value = "";
110
+ }
111
+ }
112
+
113
+ function handleDrop(event: DragEvent) {
114
+ event.preventDefault();
115
+ isDragOver = false;
116
+ if (disabled) return;
117
+ selectFiles(event.dataTransfer?.files ?? null);
118
+ if (inputEl) {
119
+ inputEl.value = "";
120
+ }
121
+ }
122
+
123
+ function handleDragOver(event: DragEvent) {
124
+ event.preventDefault();
125
+ }
126
+
127
+ function handleDragEnter(event: DragEvent) {
128
+ event.preventDefault();
129
+ if (!disabled) {
130
+ isDragOver = true;
131
+ }
132
+ }
133
+
134
+ function handleDragLeave(event: DragEvent) {
135
+ event.preventDefault();
136
+ isDragOver = false;
137
+ }
138
+
139
+ function handleKeyDown(event: KeyboardEvent) {
140
+ if (disabled) return;
141
+ if (event.key === "Enter" || event.key === " ") {
142
+ event.preventDefault();
143
+ handleButtonClick();
144
+ }
145
+ }
146
+
147
+ function clearSelection() {
148
+ if (!clearable) return;
149
+ value = null;
150
+ if (inputEl) {
151
+ inputEl.value = "";
152
+ }
153
+ onFilesSelected?.(null);
154
+ }
155
+
156
+ function selectFiles(files: FileList | null) {
157
+ const acceptedFiles = filterFiles(files);
158
+ value = acceptedFiles;
159
+ if (acceptedFiles && acceptedFiles.length > 0) {
160
+ onFilesSelected?.(acceptedFiles);
161
+ }
162
+ }
163
+
164
+ function filterFiles(files: FileList | null) {
165
+ if (!files || files.length === 0) return null;
166
+
167
+ const selected = Array.from(files);
168
+ const accepted = selected.filter(isAllowedFile);
169
+
170
+ if (accepted.length !== selected.length) {
171
+ onError?.("Some files were rejected by type or size constraints.");
172
+ }
173
+
174
+ if (accepted.length === 0) return null;
175
+ if (accepted.length === selected.length) return files;
176
+
177
+ return toFileList(accepted);
178
+ }
179
+
180
+ function isAllowedFile(file: File) {
181
+ if (Number.isFinite(maxBytes) && file.size > maxBytes) return false;
182
+ return matchesAccept(file, accept);
183
+ }
184
+
185
+ function matchesAccept(file: File, acceptValue: string) {
186
+ const rules = acceptValue
187
+ .split(",")
188
+ .map((rule) => rule.trim().toLowerCase())
189
+ .filter(Boolean);
190
+
191
+ if (rules.length === 0 || rules.includes("*/*")) return true;
192
+
193
+ const fileName = file.name.toLowerCase();
194
+ const fileType = file.type.toLowerCase();
195
+
196
+ return rules.some((rule) => {
197
+ if (rule.startsWith(".")) return fileName.endsWith(rule);
198
+ if (rule.endsWith("/*")) return fileType.startsWith(rule.slice(0, -1));
199
+ return fileType === rule;
200
+ });
201
+ }
202
+
203
+ function toFileList(files: File[]) {
204
+ if (typeof DataTransfer === "undefined") return null;
205
+ const transfer = new DataTransfer();
206
+ for (const file of files) {
207
+ transfer.items.add(file);
208
+ }
209
+ return transfer.files;
210
+ }
211
+ </script>
212
+
213
+ <div class={pickerClass} {...rest}>
214
+ <input
215
+ bind:this={inputEl}
216
+ type="file"
217
+ {accept}
218
+ {multiple}
219
+ class="hidden"
220
+ onchange={handleFileChange}
221
+ />
222
+
223
+ <div class="flex flex-wrap items-center gap-x-3 gap-y-2">
224
+ <Button {disabled} onClick={handleButtonClick} class="relative" sz="xs">
225
+ {labelFinal}
226
+ </Button>
227
+
228
+ {#if clearable}
229
+ <Button
230
+ onClick={clearSelection}
231
+ variant="danger"
232
+ disabled={!hasValue || disabled}
233
+ sz="xs"
234
+ >
235
+ {L.clear}
236
+ </Button>
237
+ {/if}
238
+ </div>
239
+
240
+ <div
241
+ class="mt-2 p-4 border-2 border-dashed rounded-[var(--radius-md)] text-center transition-colors duration-200"
242
+ class:border-[var(--color-primary)]={isDragOver && !disabled}
243
+ class:border-[var(--border-color-default)]={!isDragOver || disabled}
244
+ class:bg-[var(--color-bg-hover)]={isDragOver && !disabled}
245
+ class:cursor-pointer={!disabled}
246
+ class:opacity-[var(--opacity-disabled)]={disabled}
247
+ class:cursor-not-allowed={disabled}
248
+ class:cursor-copy={isDragOver && !disabled}
249
+ role="button"
250
+ tabindex={disabled ? -1 : 0}
251
+ aria-disabled={disabled}
252
+ ondrop={handleDrop}
253
+ ondragover={handleDragOver}
254
+ ondragenter={handleDragEnter}
255
+ ondragleave={handleDragLeave}
256
+ onclick={handleButtonClick}
257
+ onkeydown={handleKeyDown}
258
+ >
259
+ <p class="text-sm [color:var(--color-text-muted)]">
260
+ {L.dragDrop}
261
+ </p>
262
+ {#if accept !== "*/*"}
263
+ <p class="text-xs mt-1 [color:var(--color-text-muted)]">
264
+ {L.accepted}: {accept}
265
+ </p>
266
+ {/if}
267
+ </div>
268
+
269
+ <div
270
+ class="mt-3 p-4 bg-[var(--color-bg-surface)] text-center"
271
+ aria-live="polite"
272
+ >
273
+ <p class="text-xs uppercase tracking-wide [color:var(--color-text-muted)]">
274
+ {L.selectedFiles}
275
+ </p>
276
+ <p
277
+ class="text-sm font-semibold mt-1 [color:var(--color-text-default)] break-words"
278
+ >
279
+ {#if hasValue}
280
+ {fileNames}
281
+ {:else}
282
+ {placeholderFinal}
283
+ {/if}
284
+ </p>
285
+ {#if hasValue && value}
286
+ <p class="text-sm mt-1 [color:var(--color-text-muted)]">
287
+ {L.fileCount.replace("{n}", String(value.length))}
288
+
289
+ {#if multiple && value.length > 1}
290
+ - {L.totalSize}: {formatFileSize(totalBytes)}
291
+ {/if}
292
+ </p>
293
+ {/if}
294
+ </div>
295
+ </div>