@nxgt/material-core 0.2.0 → 0.3.1
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/README.md +143 -1
- package/dist/file-preview/describe-file.d.ts +30 -0
- package/dist/file-preview/describe-file.d.ts.map +1 -0
- package/dist/file-preview/file-kind.d.ts +41 -0
- package/dist/file-preview/file-kind.d.ts.map +1 -0
- package/dist/file-preview/index.d.ts +10 -0
- package/dist/file-preview/index.d.ts.map +1 -0
- package/dist/file-preview/index.js +260 -0
- package/dist/file-preview/index.js.map +13 -0
- package/dist/file-preview/safe-url.d.ts +22 -0
- package/dist/file-preview/safe-url.d.ts.map +1 -0
- package/dist/file-preview/text-preview.d.ts +32 -0
- package/dist/file-preview/text-preview.d.ts.map +1 -0
- package/dist/lib/date-range.d.ts +84 -0
- package/dist/lib/date-range.d.ts.map +1 -0
- package/dist/lib/date-range.js +105 -0
- package/dist/lib/date-range.js.map +10 -0
- package/dist/lib/slider-ticks.d.ts +7 -0
- package/dist/lib/slider-ticks.d.ts.map +1 -0
- package/dist/lib/slider-ticks.js +16 -0
- package/dist/lib/slider-ticks.js.map +10 -0
- package/dist/pdf-viewer/index.d.ts +1 -0
- package/dist/pdf-viewer/index.d.ts.map +1 -1
- package/dist/pdf-viewer/index.js +68 -33
- package/dist/pdf-viewer/index.js.map +6 -4
- package/dist/pdf-viewer/pdf-pin-page.d.ts +16 -0
- package/dist/pdf-viewer/pdf-pin-page.d.ts.map +1 -0
- package/dist/pdf-viewer/pdf-scroll-spy.d.ts +2 -8
- package/dist/pdf-viewer/pdf-scroll-spy.d.ts.map +1 -1
- package/dist/pdf-viewer/pdf-user-input.d.ts +7 -0
- package/dist/pdf-viewer/pdf-user-input.d.ts.map +1 -0
- package/docs/roadmap.md +15 -5
- package/docs/troubleshooting.md +65 -0
- package/package.json +20 -2
package/docs/roadmap.md
CHANGED
|
@@ -31,14 +31,24 @@ Nothing in progress right now; see Next.
|
|
|
31
31
|
|
|
32
32
|
## Shipped
|
|
33
33
|
|
|
34
|
+
- **Date range presets and times** (`/date-range`) — the built-in presets'
|
|
35
|
+
ranges, whether a field's rules rule a range out, and the time of day on
|
|
36
|
+
each end, for both libraries' `DateRangeField`. 0.3.0.
|
|
37
|
+
- **File preview** (`/file-preview`) — which kind of preview a file gets from
|
|
38
|
+
its MIME type or extension, which URLs it may link to or load, and the
|
|
39
|
+
first bytes of a text file read with a size cap in its own charset, for
|
|
40
|
+
both libraries' `FilePreview`. 0.3.0.
|
|
41
|
+
- **Slider ticks** (`/slider-ticks`) — the values a slider's tick marks sit
|
|
42
|
+
at, which both libraries' `SliderField` (`ticks`) read from here instead of
|
|
43
|
+
keeping a copy each. 0.3.0.
|
|
44
|
+
- **`formatFileSize` and the pdfkit fonts resolution** — the byte-count
|
|
45
|
+
formatter both libraries' file list and upload field use
|
|
46
|
+
(`/format-file-size`), and the Node-only resolution of pdfkit's standard
|
|
47
|
+
fonts behind `@nxgt/material/next` and `@nxgt/material-vue`'s Nuxt module
|
|
48
|
+
(`/pdfkit-fonts`), each kept once instead of in both libraries. 0.2.0.
|
|
34
49
|
- **A first release** — the PDF model and renderer, the print formatters,
|
|
35
50
|
the PDF file helpers, the PDF reader's framework-free modules
|
|
36
51
|
(`/pdf-viewer`: search, geometry, page sizes, scroll spy), the currency
|
|
37
52
|
digits, the fields' blur layers and the fonts plugin, which
|
|
38
53
|
`@nxgt/material` and `@nxgt/material-vue` shared file by file, are this one
|
|
39
54
|
package, and both libraries depend on it. 0.1.0.
|
|
40
|
-
- **`formatFileSize` and the pdfkit fonts resolution** — the byte-count
|
|
41
|
-
formatter both libraries' file list and upload field use
|
|
42
|
-
(`/format-file-size`), and the Node-only resolution of pdfkit's standard
|
|
43
|
-
fonts behind `@nxgt/material/next` and `@nxgt/material-vue`'s Nuxt module
|
|
44
|
-
(`/pdfkit-fonts`), each kept once instead of in both libraries. 0.2.0.
|
package/docs/troubleshooting.md
CHANGED
|
@@ -17,6 +17,11 @@ file) is an example — search for the words around it.
|
|
|
17
17
|
|
|
18
18
|
- [`PdfReader cannot open …: pass a URL, a Blob, an ArrayBuffer, a Uint8Array or { url, httpHeaders }.`](#pdfreader-cannot-open--pass-a-url-a-blob-an-arraybuffer-a-uint8array-or--url-httpheaders-)
|
|
19
19
|
|
|
20
|
+
**File preview**
|
|
21
|
+
|
|
22
|
+
- [`Could not read <url>: HTTP <status>` (`FilePreviewHttpError`)](#could-not-read-url-http-status-filepreviewhttperror)
|
|
23
|
+
- [`Refused to preview a URL with an unsafe scheme` (`FilePreviewUnsafeUrlError`)](#refused-to-preview-a-url-with-an-unsafe-scheme-filepreviewunsafeurlerror)
|
|
24
|
+
|
|
20
25
|
**Build**
|
|
21
26
|
|
|
22
27
|
- [`… still references '#standard-fonts/' after the transform — …`](#-still-references-standard-fonts-after-the-transform--)
|
|
@@ -92,6 +97,66 @@ yet, or a `Response` instead of its bytes:
|
|
|
92
97
|
const bytes = await (await fetch(url)).arrayBuffer(); // not the Response
|
|
93
98
|
```
|
|
94
99
|
|
|
100
|
+
## File preview
|
|
101
|
+
|
|
102
|
+
### `Could not read <url>: HTTP <status>` (`FilePreviewHttpError`)
|
|
103
|
+
|
|
104
|
+
**When:** `readTextPreview(url)` from `/file-preview` — behind both
|
|
105
|
+
libraries' `FilePreview`, for a text, JSON, CSV or Markdown file given as a
|
|
106
|
+
URL — rejects with a `FilePreviewHttpError`, its message the URL as passed
|
|
107
|
+
and the status, as in `Could not read /files/notes.txt: HTTP 404`, and its
|
|
108
|
+
`status` the number. `FilePreview` shows "This file could not be previewed."
|
|
109
|
+
and hands this error to `onError` (`@error` in Vue).
|
|
110
|
+
**Why:** the server answered, but not with a `2xx`: a missing file (`404`),
|
|
111
|
+
a URL that needs credentials the request did not carry (`401`, `403` —
|
|
112
|
+
`fetch` sends cookies to the same origin only, and no `Authorization`
|
|
113
|
+
header), or a server error (`5xx`). Nothing of the body is read.
|
|
114
|
+
**Fix:** check the URL in the message. For a file behind authentication,
|
|
115
|
+
fetch it yourself with your credentials and pass the `Blob`, which is read
|
|
116
|
+
without a request; branch on `status` to tell a missing file from the rest:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { FilePreviewHttpError, readTextPreview } from '@nxgt/material-core/file-preview';
|
|
120
|
+
|
|
121
|
+
const response = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
122
|
+
const preview = await readTextPreview(await response.blob()); // a Blob: no request
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await readTextPreview(url);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (error instanceof FilePreviewHttpError && error.status === 404) showMissing();
|
|
128
|
+
else throw error;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A cross-origin URL whose server sends no CORS headers is not this error: it
|
|
133
|
+
is `fetch`'s own `TypeError` (`Failed to fetch` in Chrome), with no status.
|
|
134
|
+
|
|
135
|
+
### `Refused to preview a URL with an unsafe scheme` (`FilePreviewUnsafeUrlError`)
|
|
136
|
+
|
|
137
|
+
**When:** both libraries' `FilePreview` is given a URL that
|
|
138
|
+
`safePreviewUrl` returns `null` for: it shows "This file could not be
|
|
139
|
+
previewed." with no Download link, and `onError` (`@error` in Vue) receives
|
|
140
|
+
this error. Nothing was linked, loaded or fetched.
|
|
141
|
+
**Why:** only `http:`, `https:`, a relative URL, `blob:` and a `data:` URL
|
|
142
|
+
of an image, video, audio file, plain text, CSV, Markdown, JSON or PDF may
|
|
143
|
+
reach an `href`, a `src` or `fetch`. Anything else — `javascript:`,
|
|
144
|
+
`data:text/html`, `file:`, and also a `data:` URL of XML, TSV or YAML — could
|
|
145
|
+
run script in your page or reach what it should not, so it is refused
|
|
146
|
+
whatever the file would have been. A URL with a colon before its first `/`,
|
|
147
|
+
`?` or `#` (`c:/files/a.txt`) reads as a scheme and is refused too.
|
|
148
|
+
**Fix:** serve the file over `https:` (or from your own origin), or turn its
|
|
149
|
+
content into a `Blob` and pass that — a `Blob` is previewed
|
|
150
|
+
through a `blob:` URL. Check a URL before rendering with `safePreviewUrl`:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { safePreviewUrl } from '@nxgt/material-core/file-preview';
|
|
154
|
+
|
|
155
|
+
safePreviewUrl('https://example.com/a.csv'); // 'https://example.com/a.csv'
|
|
156
|
+
safePreviewUrl('javascript:alert(1)'); // null
|
|
157
|
+
const file = safePreviewUrl(url) ?? new Blob([text], { type: 'text/yaml' });
|
|
158
|
+
```
|
|
159
|
+
|
|
95
160
|
## Build
|
|
96
161
|
|
|
97
162
|
### `… still references '#standard-fonts/' after the transform — …`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxgt/material-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The framework-free core of @nxgt/material and @nxgt/material-vue: the PDF document model and its react-pdf renderer, print formatters, PDF file helpers, the PDF viewer's pure modules, the currency digits, the file-size formatter, the field-blur layers, the pdfkit fonts Vite plugin and the Node-only pdfkit fonts resolution for Next.js and Nuxt builds",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "The framework-free core of @nxgt/material and @nxgt/material-vue: the PDF document model and its react-pdf renderer, print formatters, PDF file helpers, the PDF viewer's pure modules, the currency digits, the file-size formatter, the field-blur layers, the date range presets, the file preview's kind detection and text reader, the pdfkit fonts Vite plugin and the Node-only pdfkit fonts resolution for Next.js and Nuxt builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"email": "stevegires@gmail.com"
|
|
@@ -97,6 +97,21 @@
|
|
|
97
97
|
"import": "./dist/lib/format-file-size.js",
|
|
98
98
|
"default": "./dist/lib/format-file-size.js"
|
|
99
99
|
},
|
|
100
|
+
"./slider-ticks": {
|
|
101
|
+
"types": "./dist/lib/slider-ticks.d.ts",
|
|
102
|
+
"import": "./dist/lib/slider-ticks.js",
|
|
103
|
+
"default": "./dist/lib/slider-ticks.js"
|
|
104
|
+
},
|
|
105
|
+
"./date-range": {
|
|
106
|
+
"types": "./dist/lib/date-range.d.ts",
|
|
107
|
+
"import": "./dist/lib/date-range.js",
|
|
108
|
+
"default": "./dist/lib/date-range.js"
|
|
109
|
+
},
|
|
110
|
+
"./file-preview": {
|
|
111
|
+
"types": "./dist/file-preview/index.d.ts",
|
|
112
|
+
"import": "./dist/file-preview/index.js",
|
|
113
|
+
"default": "./dist/file-preview/index.js"
|
|
114
|
+
},
|
|
100
115
|
"./pdf-viewer": {
|
|
101
116
|
"types": "./dist/pdf-viewer/index.d.ts",
|
|
102
117
|
"import": "./dist/pdf-viewer/index.js",
|
|
@@ -157,6 +172,9 @@
|
|
|
157
172
|
"src/lib/currency-digits.ts",
|
|
158
173
|
"src/lib/field-blur-layers.ts",
|
|
159
174
|
"src/lib/format-file-size.ts",
|
|
175
|
+
"src/lib/slider-ticks.ts",
|
|
176
|
+
"src/lib/date-range.ts",
|
|
177
|
+
"src/file-preview/index.ts",
|
|
160
178
|
"src/pdf-viewer/index.ts",
|
|
161
179
|
"src/vite/index.ts",
|
|
162
180
|
"src/pdfkit-fonts/index.ts"
|