@functionalcms/svelte-components 4.16.1 → 4.19.2
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/components/form/Button.svelte +118 -129
- package/dist/components/form/Button.svelte.d.ts +0 -3
- package/dist/components/form/ChoiceInput.svelte +37 -80
- package/dist/components/form/ChoiceInput.svelte.d.ts +1 -17
- package/dist/components/form/Dropzone.svelte +183 -0
- package/dist/components/form/Dropzone.svelte.d.ts +4 -0
- package/dist/components/form/Form.svelte +43 -95
- package/dist/components/form/Form.svelte.d.ts +8 -14
- package/dist/components/form/Input.svelte +3 -3
- package/dist/components/form/Input.svelte.d.ts +3 -3
- package/dist/components/form/Select.svelte +39 -73
- package/dist/components/form/Switch.svelte +17 -19
- package/dist/components/form/dropzone.d.ts +49 -0
- package/dist/components/form/dropzone.js +18 -0
- package/dist/components/form/form.d.ts +32 -11
- package/dist/components/form/form.js +29 -33
- package/dist/components/layouts/Tabs.svelte +3 -3
- package/dist/components/layouts/TwoColumnsLayout.svelte +1 -1
- package/dist/components/layouts/TwoColumnsLayout.svelte.d.ts +3 -2
- package/dist/components/menu/CollapsibleMenu.svelte +4 -1
- package/dist/components/presentation/Carousel.svelte +4 -2
- package/dist/index-server.d.ts +1 -1
- package/dist/index-server.js +1 -1
- package/dist/index.d.ts +2 -9
- package/dist/index.js +2 -8
- package/dist/index.server.d.ts +1 -1
- package/dist/index.server.js +1 -1
- package/dist/server-side/getRedirectPipeline.d.ts +6 -0
- package/dist/server-side/getRedirectPipeline.js +16 -0
- package/package.json +82 -86
- package/dist/components/form/dropzone/DefaultDropzone.svelte +0 -37
- package/dist/components/form/dropzone/DefaultDropzone.svelte.d.ts +0 -8
- package/dist/components/form/dropzone/Dropzone.svelte +0 -306
- package/dist/components/form/dropzone/Dropzone.svelte.d.ts +0 -4
- package/dist/components/form/dropzone/UseDropzone.d.ts +0 -3
- package/dist/components/form/dropzone/UseDropzone.js +0 -19
- package/dist/components/form/dropzone/attr-accept.d.ts +0 -12
- package/dist/components/form/dropzone/attr-accept.js +0 -29
- package/dist/components/form/dropzone/default.d.ts +0 -31
- package/dist/components/form/dropzone/default.js +0 -78
- package/dist/components/form/dropzone/types.d.ts +0 -62
- package/dist/components/form/dropzone/types.js +0 -1
- package/dist/components/form/utils.d.ts +0 -13
- package/dist/components/form/utils.js +0 -1
- package/dist/server-side/redirection.d.ts +0 -6
- package/dist/server-side/redirection.js +0 -16
- package/dist/translations/translator.d.ts +0 -2
- package/dist/translations/translator.js +0 -11
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const useDropzone = (element, events) => {
|
|
2
|
-
if (!element)
|
|
3
|
-
return () => { };
|
|
4
|
-
Object.entries(events)
|
|
5
|
-
.forEach(([eventName, handler]) => {
|
|
6
|
-
if (handler) {
|
|
7
|
-
element.addEventListener(eventName, handler);
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
return () => {
|
|
11
|
-
Object.entries(events)
|
|
12
|
-
.forEach(([eventName, handler]) => {
|
|
13
|
-
if (handler) {
|
|
14
|
-
element.removeEventListener(eventName, handler);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export default useDropzone;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
3
|
-
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
4
|
-
*
|
|
5
|
-
* Inspired by https://github.com/enyo/dropzone
|
|
6
|
-
*
|
|
7
|
-
* @param file {File} https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
8
|
-
* @param accept {string}
|
|
9
|
-
* @returns {boolean}
|
|
10
|
-
*/
|
|
11
|
-
import type { FromEventFileTypes, MimeTypes } from "./types.js";
|
|
12
|
-
export default function (file: FromEventFileTypes, accept: MimeTypes[] | string[]): boolean;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
3
|
-
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
4
|
-
*
|
|
5
|
-
* Inspired by https://github.com/enyo/dropzone
|
|
6
|
-
*
|
|
7
|
-
* @param file {File} https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
8
|
-
* @param accept {string}
|
|
9
|
-
* @returns {boolean}
|
|
10
|
-
*/
|
|
11
|
-
export default function (file, accept) {
|
|
12
|
-
if (file && accept.length > 0) {
|
|
13
|
-
const fileName = "name" in file ? file.name : "";
|
|
14
|
-
const mimeType = (file.type || "").toLowerCase();
|
|
15
|
-
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
16
|
-
return accept.some((type) => {
|
|
17
|
-
const validType = type.trim().toLowerCase();
|
|
18
|
-
if (validType.charAt(0) === ".") {
|
|
19
|
-
return fileName.toLowerCase().endsWith(validType);
|
|
20
|
-
}
|
|
21
|
-
else if (validType.endsWith("/*")) {
|
|
22
|
-
// This is something like a image/* mime type
|
|
23
|
-
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
24
|
-
}
|
|
25
|
-
return mimeType === validType;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { FromEventFileTypes, MimeTypes, DropzoneErrorCode } from "./types.js";
|
|
2
|
-
export declare const FILE_INVALID_TYPE = "file-invalid-type";
|
|
3
|
-
export declare const FILE_TOO_LARGE = "file-too-large";
|
|
4
|
-
export declare const FILE_TOO_SMALL = "file-too-small";
|
|
5
|
-
export declare const TOO_MANY_FILES = "too-many-files";
|
|
6
|
-
export declare const generateErrorMessage: (code: DropzoneErrorCode, props?: {
|
|
7
|
-
accept?: string[];
|
|
8
|
-
minSize?: number;
|
|
9
|
-
maxSize?: number;
|
|
10
|
-
maxFileCountPerUpload?: number;
|
|
11
|
-
}) => {
|
|
12
|
-
code: DropzoneErrorCode;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function checkFiles({ file, accept, minSize, maxSize }: {
|
|
16
|
-
file: FromEventFileTypes;
|
|
17
|
-
accept: MimeTypes[] | string[] | undefined;
|
|
18
|
-
minSize: number;
|
|
19
|
-
maxSize: number;
|
|
20
|
-
}): {
|
|
21
|
-
errors: {
|
|
22
|
-
code: DropzoneErrorCode;
|
|
23
|
-
message: string;
|
|
24
|
-
}[];
|
|
25
|
-
isAccepted: boolean;
|
|
26
|
-
};
|
|
27
|
-
export declare function getFileTypeErrors(file: FromEventFileTypes, accept?: string[]): DropzoneErrorCode[];
|
|
28
|
-
export declare function getFileSizeErrors(file: FromEventFileTypes, minSize: number, maxSize: number): DropzoneErrorCode[];
|
|
29
|
-
export declare function isPropagationStopped(event: Event): boolean;
|
|
30
|
-
export declare function isEventWithFiles(event: Event | DragEvent): boolean | FileList | null | undefined;
|
|
31
|
-
export declare function isIeOrEdge(userAgent?: string): boolean;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import accepts from "./attr-accept.js";
|
|
2
|
-
// Error codes
|
|
3
|
-
export const FILE_INVALID_TYPE = "file-invalid-type";
|
|
4
|
-
export const FILE_TOO_LARGE = "file-too-large";
|
|
5
|
-
export const FILE_TOO_SMALL = "file-too-small";
|
|
6
|
-
export const TOO_MANY_FILES = "too-many-files";
|
|
7
|
-
export const generateErrorMessage = (code, props) => {
|
|
8
|
-
const errorMessages = {
|
|
9
|
-
INVALID_FILE_TYPE: `File type must be one of ${props?.accept?.join(",")}.`,
|
|
10
|
-
FILE_TOO_LARGE: `File is larger than ${props?.maxSize} bytes.`,
|
|
11
|
-
FILE_TOO_SMALL: `File is smaller than ${props?.minSize} bytes.`,
|
|
12
|
-
TOO_MANY_FILES: `File count cannot be more than ${props?.maxFileCountPerUpload}.`,
|
|
13
|
-
CANNOT_UPLOAD_MULTIPLE_FILES: `Cannot upload multiple files.`,
|
|
14
|
-
UNKOWN: "Unkown error"
|
|
15
|
-
};
|
|
16
|
-
return { code, message: errorMessages[code] || errorMessages["UNKOWN"] };
|
|
17
|
-
};
|
|
18
|
-
export function checkFiles({ file, accept = [], minSize, maxSize }) {
|
|
19
|
-
const fileTypeErrors = getFileTypeErrors(file, accept);
|
|
20
|
-
const fileSizeErrors = getFileSizeErrors(file, minSize, maxSize);
|
|
21
|
-
const errors = [...fileSizeErrors, ...fileTypeErrors];
|
|
22
|
-
const errorWithMessages = errors.map((error) => (generateErrorMessage(error, { accept, minSize, maxSize })));
|
|
23
|
-
return { errors: errorWithMessages, isAccepted: errors?.length === 0 };
|
|
24
|
-
}
|
|
25
|
-
// Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
26
|
-
// that MIME type will always be accepted
|
|
27
|
-
export function getFileTypeErrors(file, accept = []) {
|
|
28
|
-
const errors = [];
|
|
29
|
-
const isAcceptableType = file.type === "application/x-moz-file" || accepts(file, accept);
|
|
30
|
-
if (!isAcceptableType) {
|
|
31
|
-
errors.push("INVALID_FILE_TYPE");
|
|
32
|
-
}
|
|
33
|
-
return errors;
|
|
34
|
-
}
|
|
35
|
-
export function getFileSizeErrors(file, minSize, maxSize) {
|
|
36
|
-
let errors = [];
|
|
37
|
-
if (!("size" in file))
|
|
38
|
-
return errors;
|
|
39
|
-
if (isDefined(file.size)) {
|
|
40
|
-
if (isDefined(maxSize) && file.size > maxSize) {
|
|
41
|
-
errors.push("FILE_TOO_LARGE");
|
|
42
|
-
}
|
|
43
|
-
else if (isDefined(minSize) && file.size < minSize) {
|
|
44
|
-
errors.push("FILE_TOO_SMALL");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return errors;
|
|
48
|
-
}
|
|
49
|
-
function isDefined(value) {
|
|
50
|
-
return value !== undefined && value !== null;
|
|
51
|
-
}
|
|
52
|
-
// React's synthetic events has event.isPropagationStopped,
|
|
53
|
-
// but to remain compatibility with other libs (Preact) fall back
|
|
54
|
-
// to check event.cancelBubble
|
|
55
|
-
export function isPropagationStopped(event) {
|
|
56
|
-
if (typeof event.cancelBubble !== "undefined") {
|
|
57
|
-
return event.cancelBubble;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
export function isEventWithFiles(event) {
|
|
62
|
-
if ('dataTransfer' in event && event.dataTransfer) {
|
|
63
|
-
return Array.prototype.some.call(event.dataTransfer.types, (type) => type === "Files" || type === "application/x-moz-file");
|
|
64
|
-
}
|
|
65
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
|
66
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
|
|
67
|
-
const target = event.target;
|
|
68
|
-
return target?.files;
|
|
69
|
-
}
|
|
70
|
-
function isIe(userAgent) {
|
|
71
|
-
return (userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1);
|
|
72
|
-
}
|
|
73
|
-
function isEdge(userAgent) {
|
|
74
|
-
return userAgent.indexOf("Edge/") !== -1;
|
|
75
|
-
}
|
|
76
|
-
export function isIeOrEdge(userAgent = window.navigator.userAgent) {
|
|
77
|
-
return isIe(userAgent) || isEdge(userAgent);
|
|
78
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export type DropzoneErrorCode = "INVALID_FILE_TYPE" | "FILE_TOO_LARGE" | "FILE_TOO_SMALL" | "TOO_MANY_FILES" | "CANNOT_UPLOAD_MULTIPLE_FILES" | "UNKOWN";
|
|
2
|
-
export type DropzoneErrorTypes = {
|
|
3
|
-
message: string;
|
|
4
|
-
code: DropzoneErrorCode;
|
|
5
|
-
} | null;
|
|
6
|
-
import type { Snippet } from "svelte";
|
|
7
|
-
import type { EventHandler } from "svelte/elements";
|
|
8
|
-
export type FromEventFileTypes = File | DataTransferItem;
|
|
9
|
-
export type RejectedFile<T> = {
|
|
10
|
-
file: T;
|
|
11
|
-
errors: DropzoneErrorTypes[];
|
|
12
|
-
};
|
|
13
|
-
export type DropzoneEvent<T> = {
|
|
14
|
-
acceptedFiles: T[];
|
|
15
|
-
rejectedFiles: RejectedFile<T>[];
|
|
16
|
-
event: DragEvent | Event;
|
|
17
|
-
};
|
|
18
|
-
export type DropzoneEventHandler<T> = (data: DropzoneEvent<T>) => void | undefined;
|
|
19
|
-
export type MimeTypes = "audio/aac" | "application/x-abiword" | "image/apng" | "application/x-freearc" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "application/x-cdf" | "application/x-csh" | "text/css" | "text/csv" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-fontobject" | "application/epub+zip" | "application/gzip." | "image/gif" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "application/java-archive" | "image/jpeg" | "text/javascript" | "application/json" | "application/ld+json" | "audio/midi, audio/x-midi" | "text/javascript" | "audio/mpeg" | "video/mp4" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "audio/ogg" | "font/otf" | "image/png" | "application/pdf" | "application/x-httpd-php" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/vnd.rar" | "application/rtf" | "application/x-sh" | "image/svg+xml" | "application/x-tar" | "image/tiff" | "video/mp2t" | "font/ttf" | "text/plain" | "application/vnd.visio" | "audio/wav" | "audio/webm" | "video/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/xml" | "application/vnd.mozilla.xul+xml" | "application/zip." | "video/3gpp" | "audio/3gpp" | "video/3gpp2" | "audio/3gpp2" | "application/x-7z-compressed";
|
|
20
|
-
export interface DropzoneAreaEvents {
|
|
21
|
-
dragenter: EventHandler<DragEvent> | null;
|
|
22
|
-
dragover: EventHandler<DragEvent> | null;
|
|
23
|
-
dragleave: EventHandler<DragEvent> | null;
|
|
24
|
-
drop: EventHandler<DragEvent> | null;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Custom Dropzone Event Handlers and props to make element act as dropzone inside the library.
|
|
28
|
-
* Don't override listeners in order to make library function.
|
|
29
|
-
*/
|
|
30
|
-
export interface CustomDropzoneProps {
|
|
31
|
-
'data-drozone-element-type': string;
|
|
32
|
-
id: string;
|
|
33
|
-
tabindex: number;
|
|
34
|
-
role: string;
|
|
35
|
-
onkeydown?: EventHandler<KeyboardEvent> | null;
|
|
36
|
-
onclick?: EventHandler<MouseEvent> | null;
|
|
37
|
-
}
|
|
38
|
-
export interface DropzoneProps {
|
|
39
|
-
accept?: MimeTypes[] | string[];
|
|
40
|
-
disabled?: boolean;
|
|
41
|
-
maxSize?: number;
|
|
42
|
-
minSize?: number;
|
|
43
|
-
multiple?: boolean;
|
|
44
|
-
dropzoneText?: string;
|
|
45
|
-
maxFileCountPerUpload?: number;
|
|
46
|
-
preventDropOnDocument?: boolean;
|
|
47
|
-
disableDropzoneClick?: boolean;
|
|
48
|
-
disableDropzoneKeydown?: boolean;
|
|
49
|
-
disableDropzoneDrag?: boolean;
|
|
50
|
-
name?: string;
|
|
51
|
-
required?: boolean;
|
|
52
|
-
inputElement?: HTMLInputElement;
|
|
53
|
-
dropzoneElement?: HTMLElement | undefined;
|
|
54
|
-
appendOnDrop: boolean;
|
|
55
|
-
CustomDropzone?: Snippet<[CustomDropzoneProps]> | undefined;
|
|
56
|
-
children?: Snippet;
|
|
57
|
-
onDragenter?: DropzoneEventHandler<DataTransferItem>;
|
|
58
|
-
onDragover?: DropzoneEventHandler<DataTransferItem>;
|
|
59
|
-
onDragleave?: DropzoneEventHandler<DataTransferItem>;
|
|
60
|
-
onDrop?: DropzoneEventHandler<File>;
|
|
61
|
-
onFileDialogCancel?: () => void;
|
|
62
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type Type = 'text' | 'textarea' | 'email' | 'search' | 'password' | 'tel' | 'number' | 'url' | 'month' | 'time' | 'week' | 'date' | 'datetime-local' | 'color';
|
|
2
|
-
export type LabelSize = 'small' | 'large' | '';
|
|
3
|
-
export interface HtmlParts {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
css: string;
|
|
7
|
-
}
|
|
8
|
-
export type ChoiceInputOption = {
|
|
9
|
-
value: string;
|
|
10
|
-
label: string;
|
|
11
|
-
};
|
|
12
|
-
export type ChoiceInputType = "checkbox" | "radio";
|
|
13
|
-
export type ChoiceInputSize = "small" | "large" | "";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { redirect } from '@sveltejs/kit';
|
|
2
|
-
const getRedirection = (redirects) => {
|
|
3
|
-
const redirection = async ({ event, resolve }) => {
|
|
4
|
-
const { url } = event;
|
|
5
|
-
const redirectUrl = redirects.find(redirect => redirect.path === url.pathname);
|
|
6
|
-
;
|
|
7
|
-
if (redirectUrl) {
|
|
8
|
-
throw redirect(307, redirectUrl.destination);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
return await resolve(event);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
return redirection;
|
|
15
|
-
};
|
|
16
|
-
export default getRedirection;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const translator = (translations) => {
|
|
2
|
-
return (key) => {
|
|
3
|
-
return translations[key] || key;
|
|
4
|
-
};
|
|
5
|
-
};
|
|
6
|
-
export const prefixedTranslator = (prefix, translations) => {
|
|
7
|
-
return (key) => {
|
|
8
|
-
const prefixedKey = `${prefix}.${key}`;
|
|
9
|
-
return translations[prefixedKey] || key;
|
|
10
|
-
};
|
|
11
|
-
};
|