@things-factory/import-ui 10.1.122 → 10.1.123
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/client/bootstrap.ts +22 -0
- package/package.json +5 -5
package/client/bootstrap.ts
CHANGED
|
@@ -37,8 +37,30 @@ function onFileChanged(event) {
|
|
|
37
37
|
: reader.readAsBinaryString(fileObj)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A page that reads files itself — on the server, or several at once — gives `importable.files(files)`
|
|
42
|
+
* and, optionally, `importable.accept` (extensions such as ['xls', 'xlsx']). The files are handed over
|
|
43
|
+
* as chosen: not read here, not parsed by an import extension.
|
|
44
|
+
*/
|
|
45
|
+
function chooseFiles(importable: { files: (files: File[]) => void; accept?: string[] }) {
|
|
46
|
+
const input = document.createElement('input')
|
|
47
|
+
input.setAttribute('type', 'file')
|
|
48
|
+
input.multiple = true
|
|
49
|
+
if (importable.accept?.length) input.setAttribute('accept', importable.accept.map(one => `.${one}`).join(','))
|
|
50
|
+
input.hidden = true
|
|
51
|
+
input.addEventListener('change', () => {
|
|
52
|
+
const files = Array.from(input.files ?? [])
|
|
53
|
+
input.remove()
|
|
54
|
+
if (files.length) importable.files(files)
|
|
55
|
+
})
|
|
56
|
+
document.body.appendChild(input)
|
|
57
|
+
input.click()
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
function uploadFile() {
|
|
41
61
|
const state = store.getState()
|
|
62
|
+
const importable = state.route?.context?.importable
|
|
63
|
+
if (typeof importable?.files === 'function') return chooseFiles(importable)
|
|
42
64
|
if (!state.importing || !state.importing.extensions || Object.keys(state.importing.extensions).length === 0) return
|
|
43
65
|
|
|
44
66
|
const fileTypes = Object.keys(state.importing.extensions).map(fileType => `.${fileType}`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/import-ui",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.123",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.ts",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@operato/data-grist": "^10.0.0",
|
|
28
28
|
"@operato/layout": "^10.0.0",
|
|
29
|
-
"@things-factory/context-ui": "^10.1.
|
|
30
|
-
"@things-factory/i18n-base": "^10.1.
|
|
31
|
-
"@things-factory/import-base": "^10.1.
|
|
29
|
+
"@things-factory/context-ui": "^10.1.123",
|
|
30
|
+
"@things-factory/i18n-base": "^10.1.123",
|
|
31
|
+
"@things-factory/import-base": "^10.1.123"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "9781f1eb37a7e6a37285878cff16f8683747eb7a"
|
|
34
34
|
}
|