@functionalcms/svelte-components 4.8.11 → 4.8.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.
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
</script>
|
|
47
47
|
|
|
48
48
|
<script lang="ts">
|
|
49
|
-
import { Upload } from '@lucide/svelte';
|
|
50
49
|
import { displaySize } from './dropzone.ts';
|
|
51
50
|
import { cn } from '../../utils.ts';
|
|
52
51
|
|
|
@@ -182,7 +181,6 @@
|
|
|
182
181
|
<div
|
|
183
182
|
class="flex size-14 place-items-center justify-center rounded-full border border-dashed border-border text-muted-foreground"
|
|
184
183
|
>
|
|
185
|
-
<Upload class="size-7" />
|
|
186
184
|
</div>
|
|
187
185
|
<div class="flex flex-col gap-0.5 text-center">
|
|
188
186
|
<span class="font-medium text-muted-foreground">
|
|
@@ -1,58 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default function (file: any, acceptedFiles: any): any;
|
|
12
|
-
export declare const FILE_INVALID_TYPE = "file-invalid-type";
|
|
13
|
-
export declare const FILE_TOO_LARGE = "file-too-large";
|
|
14
|
-
export declare const FILE_TOO_SMALL = "file-too-small";
|
|
15
|
-
export declare const TOO_MANY_FILES = "too-many-files";
|
|
16
|
-
export declare const getInvalidTypeRejectionErr: (accept: any) => {
|
|
17
|
-
code: string;
|
|
18
|
-
message: string;
|
|
19
|
-
};
|
|
20
|
-
export declare const getTooLargeRejectionErr: (maxSize: any) => {
|
|
21
|
-
code: string;
|
|
22
|
-
message: string;
|
|
23
|
-
};
|
|
24
|
-
export declare const getTooSmallRejectionErr: (minSize: any) => {
|
|
25
|
-
code: string;
|
|
26
|
-
message: string;
|
|
27
|
-
};
|
|
28
|
-
export declare const TOO_MANY_FILES_REJECTION: {
|
|
29
|
-
code: string;
|
|
30
|
-
message: string;
|
|
31
|
-
};
|
|
32
|
-
export declare function fileAccepted(file: any, accept: any): any[];
|
|
33
|
-
export declare function fileMatchSize(file: any, minSize: any, maxSize: any): (boolean | {
|
|
34
|
-
code: string;
|
|
35
|
-
message: string;
|
|
36
|
-
})[] | (boolean | null)[];
|
|
37
|
-
export declare function allFilesAccepted({ files, accept, minSize, maxSize, multiple, }: {
|
|
38
|
-
files: any;
|
|
39
|
-
accept: any;
|
|
40
|
-
minSize: any;
|
|
41
|
-
maxSize: any;
|
|
42
|
-
multiple: any;
|
|
43
|
-
}): any;
|
|
44
|
-
export declare function isPropagationStopped(event: any): any;
|
|
45
|
-
export declare function isEvtWithFiles(event: any): boolean;
|
|
46
|
-
export declare function isKindFile(item: any): boolean;
|
|
47
|
-
export declare function isIeOrEdge(userAgent?: string): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* This is intended to be used to compose event handlers
|
|
50
|
-
* They are executed in order until one of them calls `event.isPropagationStopped()`.
|
|
51
|
-
* Note that the check is done on the first invoke too,
|
|
52
|
-
* meaning that if propagation was stopped before invoking the fns,
|
|
53
|
-
* no handlers will be executed.
|
|
54
|
-
*
|
|
55
|
-
* @param {Function} fns the event hanlder functions
|
|
56
|
-
* @return {Function} the event handler to add to an element
|
|
57
|
-
*/
|
|
58
|
-
export declare function composeEventHandlers(...fns: any[]): (event: any, ...args: any[]) => boolean;
|
|
1
|
+
import FileDropZone, { type FileRejectedReason, type FileDropZoneProps } from './file-drop-zone.svelte';
|
|
2
|
+
export declare const displaySize: (bytes: number) => string;
|
|
3
|
+
export declare const BYTE = 1;
|
|
4
|
+
export declare const KILOBYTE = 1024;
|
|
5
|
+
export declare const MEGABYTE: number;
|
|
6
|
+
export declare const GIGABYTE: number;
|
|
7
|
+
export declare const ACCEPT_IMAGE = "image/*";
|
|
8
|
+
export declare const ACCEPT_VIDEO = "video/*";
|
|
9
|
+
export declare const ACCEPT_AUDIO = "audio/*";
|
|
10
|
+
export { FileDropZone, type FileRejectedReason, type FileDropZoneProps };
|
|
@@ -1,151 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export default function (file, acceptedFiles) {
|
|
12
|
-
if (file && acceptedFiles) {
|
|
13
|
-
const acceptedFilesArray = Array.isArray(acceptedFiles)
|
|
14
|
-
? acceptedFiles
|
|
15
|
-
: acceptedFiles.split(",");
|
|
16
|
-
const fileName = file.name || "";
|
|
17
|
-
const mimeType = (file.type || "").toLowerCase();
|
|
18
|
-
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
19
|
-
return acceptedFilesArray.some((type) => {
|
|
20
|
-
const validType = type.trim().toLowerCase();
|
|
21
|
-
if (validType.charAt(0) === ".") {
|
|
22
|
-
return fileName.toLowerCase().endsWith(validType);
|
|
23
|
-
}
|
|
24
|
-
else if (validType.endsWith("/*")) {
|
|
25
|
-
// This is something like a image/* mime type
|
|
26
|
-
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
27
|
-
}
|
|
28
|
-
return mimeType === validType;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
// Error codes
|
|
34
|
-
export const FILE_INVALID_TYPE = "file-invalid-type";
|
|
35
|
-
export const FILE_TOO_LARGE = "file-too-large";
|
|
36
|
-
export const FILE_TOO_SMALL = "file-too-small";
|
|
37
|
-
export const TOO_MANY_FILES = "too-many-files";
|
|
38
|
-
// File Errors
|
|
39
|
-
export const getInvalidTypeRejectionErr = (accept) => {
|
|
40
|
-
accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
|
|
41
|
-
const messageSuffix = Array.isArray(accept)
|
|
42
|
-
? `one of ${accept.join(", ")}`
|
|
43
|
-
: accept;
|
|
44
|
-
return {
|
|
45
|
-
code: FILE_INVALID_TYPE,
|
|
46
|
-
message: `File type must be ${messageSuffix}`,
|
|
47
|
-
};
|
|
1
|
+
import FileDropZone, {} from './file-drop-zone.svelte';
|
|
2
|
+
export const displaySize = (bytes) => {
|
|
3
|
+
if (bytes < KILOBYTE)
|
|
4
|
+
return `${bytes.toFixed(0)} B`;
|
|
5
|
+
if (bytes < MEGABYTE)
|
|
6
|
+
return `${(bytes / KILOBYTE).toFixed(0)} KB`;
|
|
7
|
+
if (bytes < GIGABYTE)
|
|
8
|
+
return `${(bytes / MEGABYTE).toFixed(0)} MB`;
|
|
9
|
+
return `${(bytes / GIGABYTE).toFixed(0)} GB`;
|
|
48
10
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export const TOO_MANY_FILES_REJECTION = {
|
|
62
|
-
code: TOO_MANY_FILES,
|
|
63
|
-
message: "Too many files",
|
|
64
|
-
};
|
|
65
|
-
// Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
66
|
-
// that MIME type will always be accepted
|
|
67
|
-
export function fileAccepted(file, accept) {
|
|
68
|
-
const isAcceptable = file.type === "application/x-moz-file" || accepts(file, accept);
|
|
69
|
-
return [
|
|
70
|
-
isAcceptable,
|
|
71
|
-
isAcceptable ? null : getInvalidTypeRejectionErr(accept),
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
export function fileMatchSize(file, minSize, maxSize) {
|
|
75
|
-
if (isDefined(file.size)) {
|
|
76
|
-
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
77
|
-
if (file.size > maxSize)
|
|
78
|
-
return [false, getTooLargeRejectionErr(maxSize)];
|
|
79
|
-
if (file.size < minSize)
|
|
80
|
-
return [false, getTooSmallRejectionErr(minSize)];
|
|
81
|
-
}
|
|
82
|
-
else if (isDefined(minSize) && file.size < minSize)
|
|
83
|
-
return [false, getTooSmallRejectionErr(minSize)];
|
|
84
|
-
else if (isDefined(maxSize) && file.size > maxSize)
|
|
85
|
-
return [false, getTooLargeRejectionErr(maxSize)];
|
|
86
|
-
}
|
|
87
|
-
return [true, null];
|
|
88
|
-
}
|
|
89
|
-
function isDefined(value) {
|
|
90
|
-
return value !== undefined && value !== null;
|
|
91
|
-
}
|
|
92
|
-
export function allFilesAccepted({ files, accept, minSize, maxSize, multiple, }) {
|
|
93
|
-
if (!multiple && files.length > 1) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return files.every((file) => {
|
|
97
|
-
const [accepted] = fileAccepted(file, accept);
|
|
98
|
-
const [sizeMatch] = fileMatchSize(file, minSize, maxSize);
|
|
99
|
-
return accepted && sizeMatch;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
// React's synthetic events has event.isPropagationStopped,
|
|
103
|
-
// but to remain compatibility with other libs (Preact) fall back
|
|
104
|
-
// to check event.cancelBubble
|
|
105
|
-
export function isPropagationStopped(event) {
|
|
106
|
-
if (typeof event.isPropagationStopped === "function") {
|
|
107
|
-
return event.isPropagationStopped();
|
|
108
|
-
}
|
|
109
|
-
else if (typeof event.cancelBubble !== "undefined") {
|
|
110
|
-
return event.cancelBubble;
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
export function isEvtWithFiles(event) {
|
|
115
|
-
if (!event.dataTransfer) {
|
|
116
|
-
return !!event.target && !!event.target.files;
|
|
117
|
-
}
|
|
118
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
|
119
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
|
|
120
|
-
return Array.prototype.some.call(event.dataTransfer.types, (type) => type === "Files" || type === "application/x-moz-file");
|
|
121
|
-
}
|
|
122
|
-
export function isKindFile(item) {
|
|
123
|
-
return typeof item === "object" && item !== null && item.kind === "file";
|
|
124
|
-
}
|
|
125
|
-
function isIe(userAgent) {
|
|
126
|
-
return (userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1);
|
|
127
|
-
}
|
|
128
|
-
function isEdge(userAgent) {
|
|
129
|
-
return userAgent.indexOf("Edge/") !== -1;
|
|
130
|
-
}
|
|
131
|
-
export function isIeOrEdge(userAgent = window.navigator.userAgent) {
|
|
132
|
-
return isIe(userAgent) || isEdge(userAgent);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* This is intended to be used to compose event handlers
|
|
136
|
-
* They are executed in order until one of them calls `event.isPropagationStopped()`.
|
|
137
|
-
* Note that the check is done on the first invoke too,
|
|
138
|
-
* meaning that if propagation was stopped before invoking the fns,
|
|
139
|
-
* no handlers will be executed.
|
|
140
|
-
*
|
|
141
|
-
* @param {Function} fns the event hanlder functions
|
|
142
|
-
* @return {Function} the event handler to add to an element
|
|
143
|
-
*/
|
|
144
|
-
export function composeEventHandlers(...fns) {
|
|
145
|
-
return (event, ...args) => fns.some((fn) => {
|
|
146
|
-
if (!isPropagationStopped(event) && fn) {
|
|
147
|
-
fn(event, ...args);
|
|
148
|
-
}
|
|
149
|
-
return isPropagationStopped(event);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
11
|
+
// Utilities for working with file sizes
|
|
12
|
+
export const BYTE = 1;
|
|
13
|
+
export const KILOBYTE = 1024;
|
|
14
|
+
export const MEGABYTE = 1024 * KILOBYTE;
|
|
15
|
+
export const GIGABYTE = 1024 * MEGABYTE;
|
|
16
|
+
// utilities for limiting accepted files
|
|
17
|
+
export const ACCEPT_IMAGE = 'image/*';
|
|
18
|
+
export const ACCEPT_VIDEO = 'video/*';
|
|
19
|
+
export const ACCEPT_AUDIO = 'audio/*';
|
|
20
|
+
export { FileDropZone };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@functionalcms/svelte-components",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.13",
|
|
4
4
|
"watch": {
|
|
5
5
|
"build": {
|
|
6
6
|
"patterns": [
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"zod": "^3.24.1"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
+
"@lucide/svelte": "^0.501.0",
|
|
70
71
|
"embla-carousel-svelte": "^8.5.2",
|
|
71
72
|
"ioredis": "^5.4.2",
|
|
72
73
|
"marked": "^15.0.6",
|