vanjs-jsf 0.2.1 → 0.2.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/VanJsfField.js +16 -3
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/VanJsfField.js
CHANGED
|
@@ -252,7 +252,11 @@ export class VanJsfField extends VanJSComponent {
|
|
|
252
252
|
case FieldType.file: {
|
|
253
253
|
const accept = this.field.accept || "";
|
|
254
254
|
const maxSizeMB = this.field.maxSizeMB;
|
|
255
|
-
const readAs = this.field.readAs || "
|
|
255
|
+
const readAs = this.field.readAs || "auto";
|
|
256
|
+
const TEXT_EXTENSIONS = new Set([
|
|
257
|
+
"json", "csv", "tsv", "txt", "xml", "yaml", "yml",
|
|
258
|
+
"log", "md", "html", "css", "js", "ts", "sql", "env",
|
|
259
|
+
]);
|
|
256
260
|
// Reactive states
|
|
257
261
|
const fileNameState = van.state("");
|
|
258
262
|
const fileSizeState = van.state("");
|
|
@@ -283,8 +287,8 @@ export class VanJsfField extends VanJSComponent {
|
|
|
283
287
|
reader.onload = () => {
|
|
284
288
|
readingState.val = false;
|
|
285
289
|
let result = reader.result;
|
|
286
|
-
if (
|
|
287
|
-
//
|
|
290
|
+
if (reader.result instanceof ArrayBuffer) {
|
|
291
|
+
// Convert binary to base64 (applies to "arrayBuffer" and "auto" for binary files)
|
|
288
292
|
const bytes = new Uint8Array(reader.result);
|
|
289
293
|
let binary = "";
|
|
290
294
|
for (let i = 0; i < bytes.byteLength; i++) {
|
|
@@ -304,6 +308,15 @@ export class VanJsfField extends VanJSComponent {
|
|
|
304
308
|
else if (readAs === "arrayBuffer") {
|
|
305
309
|
reader.readAsArrayBuffer(file);
|
|
306
310
|
}
|
|
311
|
+
else if (readAs === "auto") {
|
|
312
|
+
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
313
|
+
if (TEXT_EXTENSIONS.has(ext)) {
|
|
314
|
+
reader.readAsText(file);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
reader.readAsArrayBuffer(file);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
307
320
|
else {
|
|
308
321
|
reader.readAsText(file);
|
|
309
322
|
}
|