native-file-system-adapter-ts
Version:
Native File System API
34 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.showOpenFilePicker = void 0;
const utils_1 = require("./utils");
async function showOpenFilePicker(options = {}) {
const opts = { multiple: false, ...options };
const input = document.createElement('input');
input.type = 'file';
input.multiple = opts.multiple;
// input.accept = (opts.types || [])
// .map((e) => [
// ...(e.extensions || []).map((e) => '.' + e),
// ...(e.mimeTypes || []),
// ])
// .flat()
// .join(',');
// See https://stackoverflow.com/questions/47664777/javascript-file-input-onchange-not-working-ios-safari-only
input.style.position = 'fixed';
input.style.top = '-100000px';
input.style.left = '-100000px';
document.body.appendChild(input);
await new Promise((resolve) => {
input.addEventListener('change', resolve);
input.click();
});
try {
return (0, utils_1.getFileHandlesFromInput)(input);
}
finally {
input.remove();
}
}
exports.showOpenFilePicker = showOpenFilePicker;
//# sourceMappingURL=show-open-file-picker.js.map