@fctc/sme-widget-ui 3.10.6 → 3.10.8
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/chunk-5Y4EK5OE.mjs +2 -0
- package/dist/chunk-BJCU5X7S.mjs +1 -0
- package/dist/chunk-KVH366MY.mjs +1 -0
- package/dist/chunk-U7MAFS3I.mjs +1 -0
- package/dist/chunk-UMFSRQPI.mjs +44 -0
- package/dist/chunk-YEKQJ4YC.mjs +1 -0
- package/dist/hooks.mjs +1 -249
- package/dist/icons.mjs +1 -1734
- package/dist/index.css +1 -799
- package/dist/index.mjs +1 -34456
- package/dist/types.mjs +1 -13
- package/dist/utils.mjs +1 -7474
- package/dist/widgets.css +1 -799
- package/dist/widgets.mjs +1 -33684
- package/package.json +1 -1
- package/dist/hooks.d.ts +0 -46
- package/dist/hooks.js +0 -277
- package/dist/icons.d.ts +0 -100
- package/dist/icons.js +0 -1802
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -34584
- package/dist/types.d.ts +0 -62
- package/dist/types.js +0 -50
- package/dist/utils.d.ts +0 -30
- package/dist/utils.js +0 -7498
- package/dist/widgets.d.ts +0 -490
- package/dist/widgets.js +0 -33748
package/dist/hooks.mjs
CHANGED
|
@@ -1,249 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
var DEFAULT_EVENTS = ["mousedown", "touchstart"];
|
|
4
|
-
var useClickOutside = ({
|
|
5
|
-
handler,
|
|
6
|
-
events = DEFAULT_EVENTS,
|
|
7
|
-
nodes = [],
|
|
8
|
-
// Default to empty array to avoid undefined errors
|
|
9
|
-
refs
|
|
10
|
-
}) => {
|
|
11
|
-
const ref = useRef(null);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const listener = (event) => {
|
|
14
|
-
const { target } = event;
|
|
15
|
-
if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (!(target instanceof HTMLElement)) return;
|
|
19
|
-
const shouldIgnore = target.hasAttribute("data-ignore-outside-clicks") || !document.body.contains(target) && target.tagName !== "HTML";
|
|
20
|
-
const shouldTrigger = nodes.length > 0 ? nodes.every((node) => node && !event.composedPath().includes(node)) : ref.current && !ref.current.contains(target);
|
|
21
|
-
if (shouldTrigger && !shouldIgnore) {
|
|
22
|
-
handler(event);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
events.forEach((event) => document.addEventListener(event, listener));
|
|
26
|
-
return () => {
|
|
27
|
-
events.forEach((event) => document.removeEventListener(event, listener));
|
|
28
|
-
};
|
|
29
|
-
}, [handler, nodes, events]);
|
|
30
|
-
return ref;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/hooks/use-get-file-infor.ts
|
|
34
|
-
import { useEffect as useEffect2, useRef as useRef2, useState } from "react";
|
|
35
|
-
function getFileName(source, mime) {
|
|
36
|
-
if (source instanceof File) return source.name;
|
|
37
|
-
if (typeof source === "string") {
|
|
38
|
-
if (source.startsWith("data:")) {
|
|
39
|
-
const ext2 = mime?.split("/")[1] || "bin";
|
|
40
|
-
return `file.${ext2}`;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
const pathname = new URL(source).pathname;
|
|
44
|
-
const filename = decodeURIComponent(pathname.split("/").pop() || "");
|
|
45
|
-
if (filename) return filename;
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
return "file.bin";
|
|
49
|
-
}
|
|
50
|
-
const ext = mime?.split("/")[1] || "bin";
|
|
51
|
-
return `file.${ext}`;
|
|
52
|
-
}
|
|
53
|
-
function useFileInfo(source, options) {
|
|
54
|
-
const { readAs = "all" } = options ?? {};
|
|
55
|
-
const [info, setInfo] = useState(null);
|
|
56
|
-
const [loading, setLoading] = useState(false);
|
|
57
|
-
const [error, setError] = useState(null);
|
|
58
|
-
const abortRef = useRef2({ aborted: false });
|
|
59
|
-
useEffect2(() => {
|
|
60
|
-
abortRef.current.aborted = false;
|
|
61
|
-
if (!source) {
|
|
62
|
-
setInfo(null);
|
|
63
|
-
setLoading(false);
|
|
64
|
-
setError(null);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
let localUrl = null;
|
|
68
|
-
let fr = null;
|
|
69
|
-
let mediaEl = null;
|
|
70
|
-
const makeExtension = (name, type) => {
|
|
71
|
-
if (name) {
|
|
72
|
-
const idx = name.lastIndexOf(".");
|
|
73
|
-
if (idx > -1) return name.slice(idx + 1).toLowerCase();
|
|
74
|
-
}
|
|
75
|
-
if (type) {
|
|
76
|
-
const match = /\/([a-z0-9.+-]+)$/.exec(type);
|
|
77
|
-
return match ? match[1] : null;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
};
|
|
81
|
-
const toBlobFromSource = async (src) => {
|
|
82
|
-
if (src instanceof Blob) return src;
|
|
83
|
-
if (typeof src === "string") {
|
|
84
|
-
const s = src.trim();
|
|
85
|
-
if (s.startsWith("data:")) {
|
|
86
|
-
const parts = s.split(",");
|
|
87
|
-
const meta = parts[0];
|
|
88
|
-
const isBase64 = meta.includes(";base64");
|
|
89
|
-
const mimeMatch = meta.match(/data:([^;]+)/);
|
|
90
|
-
const mime = mimeMatch ? mimeMatch[1] : "application/octet-stream";
|
|
91
|
-
const dataPart = parts.slice(1).join(",");
|
|
92
|
-
if (isBase64) {
|
|
93
|
-
const binary = atob(dataPart);
|
|
94
|
-
const len = binary.length;
|
|
95
|
-
const arr = new Uint8Array(len);
|
|
96
|
-
for (let i = 0; i < len; i++) arr[i] = binary.charCodeAt(i);
|
|
97
|
-
return new Blob([arr], { type: mime });
|
|
98
|
-
} else {
|
|
99
|
-
const decoded = decodeURIComponent(dataPart);
|
|
100
|
-
return new Blob([decoded], { type: mime });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const resp = await fetch(s);
|
|
104
|
-
if (!resp.ok) throw new Error(`Fetch failed with status ${resp.status}`);
|
|
105
|
-
const blob = await resp.blob();
|
|
106
|
-
return blob;
|
|
107
|
-
}
|
|
108
|
-
throw new Error("Unsupported source type");
|
|
109
|
-
};
|
|
110
|
-
const run = async () => {
|
|
111
|
-
setLoading(true);
|
|
112
|
-
setError(null);
|
|
113
|
-
setInfo(null);
|
|
114
|
-
try {
|
|
115
|
-
const blob = await toBlobFromSource(source);
|
|
116
|
-
if (abortRef.current.aborted) return;
|
|
117
|
-
const fileInfo = {
|
|
118
|
-
rawBlob: blob,
|
|
119
|
-
size: blob.size,
|
|
120
|
-
type: blob.type || "application/octet-stream",
|
|
121
|
-
dataUrl: null,
|
|
122
|
-
text: null,
|
|
123
|
-
arrayBuffer: null,
|
|
124
|
-
image: null,
|
|
125
|
-
video: null,
|
|
126
|
-
audio: null
|
|
127
|
-
};
|
|
128
|
-
if (source instanceof File || source instanceof Blob || typeof source === "string" && !source.startsWith("data:")) {
|
|
129
|
-
fileInfo.name = getFileName(source, fileInfo.type);
|
|
130
|
-
}
|
|
131
|
-
fileInfo.extension = makeExtension(fileInfo.name, fileInfo.type);
|
|
132
|
-
localUrl = URL.createObjectURL(blob);
|
|
133
|
-
const readPromises = [];
|
|
134
|
-
if (readAs === "dataUrl" || readAs === "all") {
|
|
135
|
-
fr = new FileReader();
|
|
136
|
-
const p = new Promise((resolve, reject) => {
|
|
137
|
-
fr.onload = () => {
|
|
138
|
-
if (abortRef.current.aborted) return resolve();
|
|
139
|
-
fileInfo.dataUrl = fr.result;
|
|
140
|
-
resolve();
|
|
141
|
-
};
|
|
142
|
-
fr.onerror = () => reject(fr.error);
|
|
143
|
-
fr.readAsDataURL(blob);
|
|
144
|
-
});
|
|
145
|
-
readPromises.push(p);
|
|
146
|
-
}
|
|
147
|
-
if (readAs === "text" || readAs === "all") {
|
|
148
|
-
const frText = new FileReader();
|
|
149
|
-
const p = new Promise((resolve, reject) => {
|
|
150
|
-
frText.onload = () => {
|
|
151
|
-
if (abortRef.current.aborted) return resolve();
|
|
152
|
-
fileInfo.text = frText.result;
|
|
153
|
-
resolve();
|
|
154
|
-
};
|
|
155
|
-
frText.onerror = () => reject(frText.error);
|
|
156
|
-
frText.readAsText(blob);
|
|
157
|
-
});
|
|
158
|
-
readPromises.push(p);
|
|
159
|
-
}
|
|
160
|
-
if (readAs === "arrayBuffer" || readAs === "all") {
|
|
161
|
-
const frBuf = new FileReader();
|
|
162
|
-
const p = new Promise((resolve, reject) => {
|
|
163
|
-
frBuf.onload = () => {
|
|
164
|
-
if (abortRef.current.aborted) return resolve();
|
|
165
|
-
fileInfo.arrayBuffer = frBuf.result;
|
|
166
|
-
resolve();
|
|
167
|
-
};
|
|
168
|
-
frBuf.onerror = () => reject(frBuf.error);
|
|
169
|
-
frBuf.readAsArrayBuffer(blob);
|
|
170
|
-
});
|
|
171
|
-
readPromises.push(p);
|
|
172
|
-
}
|
|
173
|
-
if (fileInfo?.type?.startsWith("image/")) {
|
|
174
|
-
const p = new Promise((resolve, reject) => {
|
|
175
|
-
const img = new Image();
|
|
176
|
-
img.onload = () => {
|
|
177
|
-
if (abortRef.current.aborted) return resolve();
|
|
178
|
-
fileInfo.image = {
|
|
179
|
-
width: img.naturalWidth,
|
|
180
|
-
height: img.naturalHeight
|
|
181
|
-
};
|
|
182
|
-
resolve();
|
|
183
|
-
};
|
|
184
|
-
img.onerror = () => resolve();
|
|
185
|
-
img.src = localUrl;
|
|
186
|
-
});
|
|
187
|
-
readPromises.push(p);
|
|
188
|
-
}
|
|
189
|
-
if (fileInfo && fileInfo?.type?.startsWith("video/") || fileInfo?.type?.startsWith("audio/")) {
|
|
190
|
-
const p = new Promise((resolve) => {
|
|
191
|
-
const el = document.createElement(
|
|
192
|
-
fileInfo?.type?.startsWith("video/") ? "video" : "audio"
|
|
193
|
-
);
|
|
194
|
-
mediaEl = el;
|
|
195
|
-
mediaEl.preload = "metadata";
|
|
196
|
-
mediaEl.onloadedmetadata = () => {
|
|
197
|
-
if (abortRef.current.aborted) return resolve();
|
|
198
|
-
const duration = isFinite(mediaEl.duration) ? mediaEl.duration : void 0;
|
|
199
|
-
if (fileInfo?.type?.startsWith("video/")) {
|
|
200
|
-
fileInfo.video = {
|
|
201
|
-
width: mediaEl.videoWidth || void 0,
|
|
202
|
-
height: mediaEl.videoHeight || void 0,
|
|
203
|
-
duration
|
|
204
|
-
};
|
|
205
|
-
} else {
|
|
206
|
-
fileInfo.audio = { duration };
|
|
207
|
-
}
|
|
208
|
-
resolve();
|
|
209
|
-
};
|
|
210
|
-
mediaEl.onerror = () => resolve();
|
|
211
|
-
mediaEl.src = localUrl;
|
|
212
|
-
});
|
|
213
|
-
readPromises.push(p);
|
|
214
|
-
}
|
|
215
|
-
await Promise.all(readPromises);
|
|
216
|
-
if (abortRef.current.aborted) return;
|
|
217
|
-
setInfo(fileInfo);
|
|
218
|
-
} catch (err) {
|
|
219
|
-
if (!abortRef.current.aborted) setError(err?.message ?? String(err));
|
|
220
|
-
} finally {
|
|
221
|
-
if (!abortRef.current.aborted) setLoading(false);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
run();
|
|
225
|
-
return () => {
|
|
226
|
-
abortRef.current.aborted = true;
|
|
227
|
-
if (fr && fr.readyState === 1) {
|
|
228
|
-
try {
|
|
229
|
-
fr.abort();
|
|
230
|
-
} catch {
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (mediaEl) {
|
|
234
|
-
try {
|
|
235
|
-
mediaEl.src = "";
|
|
236
|
-
mediaEl.load();
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (localUrl) URL.revokeObjectURL(localUrl);
|
|
241
|
-
};
|
|
242
|
-
}, [source, readAs]);
|
|
243
|
-
return { info, loading, error, reload: () => {
|
|
244
|
-
} };
|
|
245
|
-
}
|
|
246
|
-
export {
|
|
247
|
-
useClickOutside,
|
|
248
|
-
useFileInfo
|
|
249
|
-
};
|
|
1
|
+
export{a as useClickOutside,b as useFileInfo}from'./chunk-U7MAFS3I.mjs';import'./chunk-YEKQJ4YC.mjs';
|