react-planner
Version:
react-planner is a React Component for plans design. Draw a 2D floorplan and navigate it in 3D mode.
38 lines (31 loc) • 1.13 kB
JavaScript
export function browserDownload(json) {
let fileOutputLink = document.createElement('a');
let filename = 'output' + Date.now() + '.json';
filename = window.prompt('Insert output filename', filename);
if (!filename) return;
let output = JSON.stringify(json);
let data = new Blob([output], {type: 'text/plain'});
let url = window.URL.createObjectURL(data);
fileOutputLink.setAttribute('download', filename);
fileOutputLink.href = url;
fileOutputLink.style.display = 'none';
document.body.appendChild(fileOutputLink);
fileOutputLink.click();
document.body.removeChild(fileOutputLink);
}
export function browserUpload() {
return new Promise(function (resolve, reject) {
let fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.addEventListener('change', function (event) {
let file = event.target.files[0];
let reader = new FileReader();
reader.addEventListener('load', (fileEvent) => {
let loadedData = fileEvent.target.result;
resolve(loadedData);
});
reader.readAsText(file);
});
fileInput.click();
});
}