@functionalcms/svelte-components 2.34.9 → 2.34.12

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.
@@ -1,167 +0,0 @@
1
- /**
2
- * Copied from https://github.com/react-dropzone/file-selector/tree/master
3
- */
4
- import { FileWithPath, toFileWithPath } from './file.js';
5
- const FILES_TO_IGNORE = [
6
- // Thumbnail cache files for macOS and Windows
7
- '.DS_Store', // macOs
8
- 'Thumbs.db' // Windows
9
- ];
10
- /**
11
- * Convert a DragEvent's DataTrasfer object to a list of File objects
12
- * NOTE: If some of the items are folders,
13
- * everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
14
- *
15
- * EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg
16
- * and a list of File objects will be returned.
17
- *
18
- * @param evt
19
- */
20
- export async function fromEvent(evt) {
21
- if (isObject(evt) && isDataTransfer(evt.dataTransfer)) {
22
- return getDataTransferFiles(evt.dataTransfer, evt.type);
23
- }
24
- else if (isChangeEvt(evt)) {
25
- return getInputFiles(evt);
26
- }
27
- else if (Array.isArray(evt) && evt.every(item => 'getFile' in item && typeof item.getFile === 'function')) {
28
- return getFsHandleFiles(evt);
29
- }
30
- return [];
31
- }
32
- function isDataTransfer(value) {
33
- return isObject(value);
34
- }
35
- function isChangeEvt(value) {
36
- return isObject(value) && isObject(value.target);
37
- }
38
- function isObject(v) {
39
- return typeof v === 'object' && v !== null;
40
- }
41
- function getInputFiles(evt) {
42
- return fromList(evt.target.files).map(file => toFileWithPath(file));
43
- }
44
- // Ee expect each handle to be https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
45
- async function getFsHandleFiles(handles) {
46
- const files = await Promise.all(handles.map(h => h.getFile()));
47
- return files.map(file => toFileWithPath(file));
48
- }
49
- async function getDataTransferFiles(dt, type) {
50
- // IE11 does not support dataTransfer.items
51
- // See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/items#Browser_compatibility
52
- if (dt.items) {
53
- const items = fromList(dt.items)
54
- .filter(item => item.kind === 'file');
55
- // According to https://html.spec.whatwg.org/multipage/dnd.html#dndevents,
56
- // only 'dragstart' and 'drop' has access to the data (source node)
57
- if (type !== 'drop') {
58
- return items;
59
- }
60
- const files = await Promise.all(items.map(toFilePromises));
61
- return noIgnoredFiles(flatten(files));
62
- }
63
- return noIgnoredFiles(fromList(dt.files)
64
- .map(file => toFileWithPath(file)));
65
- }
66
- function noIgnoredFiles(files) {
67
- return files.filter(file => FILES_TO_IGNORE.indexOf(file.name) === -1);
68
- }
69
- // IE11 does not support Array.from()
70
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Browser_compatibility
71
- // https://developer.mozilla.org/en-US/docs/Web/API/FileList
72
- // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItemList
73
- function fromList(items) {
74
- if (items === null) {
75
- return [];
76
- }
77
- const files = [];
78
- // tslint:disable: prefer-for-of
79
- for (let i = 0; i < items.length; i++) {
80
- const file = items[i];
81
- files.push(file);
82
- }
83
- return files;
84
- }
85
- // https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem
86
- function toFilePromises(item) {
87
- if (typeof item.webkitGetAsEntry !== 'function') {
88
- return fromDataTransferItem(item);
89
- }
90
- const entry = item.webkitGetAsEntry();
91
- // Safari supports dropping an image node from a different window and can be retrieved using
92
- // the DataTransferItem.getAsFile() API
93
- // NOTE: FileSystemEntry.file() throws if trying to get the file
94
- if (entry && entry.isDirectory) {
95
- return fromDirEntry(entry);
96
- }
97
- return fromDataTransferItem(item, entry);
98
- }
99
- function flatten(items) {
100
- return items.reduce((acc, files) => [
101
- ...acc,
102
- ...(Array.isArray(files) ? flatten(files) : [files])
103
- ], []);
104
- }
105
- function fromDataTransferItem(item, entry) {
106
- if (typeof item.getAsFileSystemHandle === 'function') {
107
- return item.getAsFileSystemHandle()
108
- .then(async (h) => {
109
- const file = await h.getFile();
110
- file.handle = h;
111
- return toFileWithPath(file);
112
- });
113
- }
114
- const file = item.getAsFile();
115
- if (!file) {
116
- return Promise.reject(`${item} is not a File`);
117
- }
118
- const fwp = toFileWithPath(file, entry?.fullPath ?? undefined);
119
- return Promise.resolve(fwp);
120
- }
121
- // https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry
122
- async function fromEntry(entry) {
123
- return entry.isDirectory ? fromDirEntry(entry) : fromFileEntry(entry);
124
- }
125
- // https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry
126
- function fromDirEntry(entry) {
127
- const reader = entry.createReader();
128
- return new Promise((resolve, reject) => {
129
- const entries = [];
130
- function readEntries() {
131
- // https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader
132
- // https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries
133
- reader.readEntries(async (batch) => {
134
- if (!batch.length) {
135
- // Done reading directory
136
- try {
137
- const files = await Promise.all(entries);
138
- resolve(files);
139
- }
140
- catch (err) {
141
- reject(err);
142
- }
143
- }
144
- else {
145
- const items = Promise.all(batch.map(fromEntry));
146
- entries.push(items);
147
- // Continue reading
148
- readEntries();
149
- }
150
- }, (err) => {
151
- reject(err);
152
- });
153
- }
154
- readEntries();
155
- });
156
- }
157
- // https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry
158
- async function fromFileEntry(entry) {
159
- return new Promise((resolve, reject) => {
160
- entry.file((file) => {
161
- const fwp = toFileWithPath(file, entry.fullPath);
162
- resolve(fwp);
163
- }, (err) => {
164
- reject(err);
165
- });
166
- });
167
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Copied from https://github.com/react-dropzone/file-selector/tree/master
3
- */
4
- export declare const COMMON_MIME_TYPES: Map<string, string>;
5
- export declare function toFileWithPath(file: FileWithPath, path?: string, h?: FileSystemHandle): FileWithPath;
6
- export interface FileWithPath extends File {
7
- readonly path?: string;
8
- readonly handle?: FileSystemFileHandle;
9
- readonly relativePath?: string;
10
- }