@lvce-editor/renderer-process 30.69.2 → 30.69.3
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/rendererProcessMain.js +47 -1
- package/package.json +1 -1
|
@@ -10491,7 +10491,53 @@ const showDirectoryPicker = options => {
|
|
|
10491
10491
|
};
|
|
10492
10492
|
const showFilePicker = options => {
|
|
10493
10493
|
// @ts-expect-error
|
|
10494
|
-
|
|
10494
|
+
if (typeof window.showOpenFilePicker === 'function') {
|
|
10495
|
+
// @ts-expect-error
|
|
10496
|
+
return window.showOpenFilePicker(options);
|
|
10497
|
+
}
|
|
10498
|
+
return showFilePickerFallback(options);
|
|
10499
|
+
};
|
|
10500
|
+
const showFilePickerFallback = options => {
|
|
10501
|
+
const input = document.createElement('input');
|
|
10502
|
+
input.type = 'file';
|
|
10503
|
+
input.multiple = Boolean(options?.multiple);
|
|
10504
|
+
if (options?.accept) {
|
|
10505
|
+
input.accept = options.accept;
|
|
10506
|
+
}
|
|
10507
|
+
document.body.append(input);
|
|
10508
|
+
return new Promise((resolve, reject) => {
|
|
10509
|
+
const cleanup = () => {
|
|
10510
|
+
input.removeEventListener('change', onChange);
|
|
10511
|
+
input.removeEventListener('cancel', onCancel);
|
|
10512
|
+
input.remove();
|
|
10513
|
+
};
|
|
10514
|
+
const onChange = () => {
|
|
10515
|
+
const files = Array.from(input.files || [], file => ({
|
|
10516
|
+
file,
|
|
10517
|
+
kind: 'file',
|
|
10518
|
+
name: file.name,
|
|
10519
|
+
readonly: true
|
|
10520
|
+
}));
|
|
10521
|
+
cleanup();
|
|
10522
|
+
resolve(files);
|
|
10523
|
+
};
|
|
10524
|
+
const onCancel = () => {
|
|
10525
|
+
cleanup();
|
|
10526
|
+
resolve([]);
|
|
10527
|
+
};
|
|
10528
|
+
input.addEventListener('change', onChange, {
|
|
10529
|
+
once: true
|
|
10530
|
+
});
|
|
10531
|
+
input.addEventListener('cancel', onCancel, {
|
|
10532
|
+
once: true
|
|
10533
|
+
});
|
|
10534
|
+
try {
|
|
10535
|
+
input.click();
|
|
10536
|
+
} catch (error) {
|
|
10537
|
+
cleanup();
|
|
10538
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
10539
|
+
}
|
|
10540
|
+
});
|
|
10495
10541
|
};
|
|
10496
10542
|
const showSaveFilePicker = options => {
|
|
10497
10543
|
// @ts-expect-error
|