@things-factory/import-ui 10.1.122 → 10.1.141

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.
@@ -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.122",
3
+ "version": "10.1.141",
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.122",
30
- "@things-factory/i18n-base": "^10.1.122",
31
- "@things-factory/import-base": "^10.1.122"
29
+ "@things-factory/context-ui": "^10.1.141",
30
+ "@things-factory/i18n-base": "^10.1.141",
31
+ "@things-factory/import-base": "^10.1.141"
32
32
  },
33
- "gitHead": "a66715e94ef6064cade05229de57d0fe5798d1fb"
33
+ "gitHead": "931866a13b9149be42a294f207e245aba11e57f8"
34
34
  }