@kolkrabbi/kol-component 0.309.0 → 0.310.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.310.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kolkrabbi/kol-icons": "^0.
|
|
41
|
+
"@kolkrabbi/kol-icons": "^0.52.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src",
|
package/src/index.js
CHANGED
|
@@ -39,6 +39,8 @@ export { default as IconPlate, KeylineGuide } from './atoms/IconPlate.jsx'
|
|
|
39
39
|
export { default as IconToggle } from './atoms/IconToggle.jsx'
|
|
40
40
|
export { default as ExitPreview } from './utilities/ExitPreview.jsx'
|
|
41
41
|
export { default as Figure } from './atoms/Figure.jsx'
|
|
42
|
+
/* which file origins a preview fetches with the sign-in cookie (Quick Look on private files, 2026-10-28) */
|
|
43
|
+
export { registerCredentialedOrigin, credentialsFor } from './utilities/credentials.js'
|
|
42
44
|
export { default as FullscreenOverlay } from './utilities/FullscreenOverlay.jsx'
|
|
43
45
|
/* the overlay layer stack — which open layer owns Escape; exported so a layer in another package
|
|
44
46
|
* (kol-shell's walkthrough) joins the same stack instead of a second one (2026-10-09) */
|
|
@@ -9,6 +9,7 @@ import { kindOf as defaultKindOf, extOf as defaultExtOf, KIND_LABEL } from '../u
|
|
|
9
9
|
import markdownToHtml from '../utilities/markdownToHtml.js'
|
|
10
10
|
import { parseFrontmatter } from '@kolkrabbi/kol-markdown'
|
|
11
11
|
import DocPage from './DocPage.jsx'
|
|
12
|
+
import { credentialsFor } from '../utilities/credentials.js'
|
|
12
13
|
|
|
13
14
|
/* taxonomy-ok: molecule — nests the DS media atoms + CodeBlock (relative). */
|
|
14
15
|
|
|
@@ -51,13 +52,14 @@ const LANG = {
|
|
|
51
52
|
csv: 'text', tsv: 'text', pgn: 'text', txt: 'text', xml: 'xml',
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
function useTextContent(url, enabled, limit) {
|
|
55
|
+
function useTextContent(url, enabled, limit, credentials) {
|
|
55
56
|
const [result, setResult] = useState({ url: null, text: '', error: null, truncated: false })
|
|
56
57
|
useEffect(() => {
|
|
57
58
|
if (!enabled || !url) return undefined
|
|
58
59
|
let cancelled = false
|
|
59
60
|
const controller = new AbortController()
|
|
60
|
-
|
|
61
|
+
/* the sign-in cookie for a registered origin (utilities/credentials.js) */
|
|
62
|
+
fetch(url, { signal: controller.signal, credentials: credentialsFor(url, credentials) })
|
|
61
63
|
.then(async (res) => {
|
|
62
64
|
if (!res.ok) throw new Error(`${res.status}`)
|
|
63
65
|
const size = Number(res.headers.get('content-length') || 0)
|
|
@@ -68,7 +70,7 @@ function useTextContent(url, enabled, limit) {
|
|
|
68
70
|
})
|
|
69
71
|
.catch((e) => { if (!cancelled && e.name !== 'AbortError') setResult({ url, text: '', error: e.message, truncated: false }) })
|
|
70
72
|
return () => { cancelled = true; controller.abort() }
|
|
71
|
-
}, [url, enabled, limit])
|
|
73
|
+
}, [url, enabled, limit, credentials])
|
|
72
74
|
return { ...result, loading: enabled && result.url !== url }
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -116,6 +118,9 @@ const PDF_LIMIT = 8 * 1024 * 1024
|
|
|
116
118
|
export default function KindPreview({
|
|
117
119
|
o, text: textProp, kind: kindProp, urlOf = (x) => x.url, poster, kindOf = defaultKindOf,
|
|
118
120
|
extOf = defaultExtOf, kindLabel = KIND_LABEL, textLimit = TEXT_LIMIT,
|
|
121
|
+
/* `'include'` sends the sign-in cookie with this preview's own fetches (PDF, text); unset, a registered origin decides
|
|
122
|
+
* (`registerCredentialedOrigin`, utilities/credentials.js) */
|
|
123
|
+
credentials,
|
|
119
124
|
/* ONE RENDERER, THREE FITS (user 2026-09-23: *"theres just a bunch of different views, why? you
|
|
120
125
|
* know what consistency means?"*). Five surfaces each patched this component with their own CSS
|
|
121
126
|
* or bypassed it — the pane, the wall tile, the row thumb, the kind overview and the overlay. The
|
|
@@ -153,7 +158,7 @@ export default function KindPreview({
|
|
|
153
158
|
const ext = extOf(o.key)
|
|
154
159
|
const name = o.displayKey ?? o.key
|
|
155
160
|
const isText = kind === 'text' || kind === 'code' || kind === 'markdown' || kind === 'json' || kind === 'yaml'
|
|
156
|
-
const fetched = useTextContent(url, isText && textProp == null, textLimit)
|
|
161
|
+
const fetched = useTextContent(url, isText && textProp == null, textLimit, credentials)
|
|
157
162
|
/* content in hand is never loading and never errors — there is nothing to
|
|
158
163
|
* wait for. It still honours `textLimit`, so one long note cannot outgrow a
|
|
159
164
|
* tile the way a fetched one cannot. */
|
|
@@ -215,9 +220,9 @@ export default function KindPreview({
|
|
|
215
220
|
* pulled to paint one page. */
|
|
216
221
|
const servableUrl = /^(https?:|data:|blob:|\/)/.test(String(url ?? ''))
|
|
217
222
|
if (ext === 'pdf' && servableUrl && fit !== 'thumb' && (o.size ?? 0) <= pdfLimit) {
|
|
218
|
-
if (fit === 'sheet') return <PdfDocument src={url} fallback={icon} />
|
|
223
|
+
if (fit === 'sheet') return <PdfDocument src={url} fallback={icon} credentials={credentials} />
|
|
219
224
|
return (
|
|
220
|
-
<PdfPage src={url} fallback={icon}
|
|
225
|
+
<PdfPage src={url} fallback={icon} credentials={credentials}
|
|
221
226
|
className={fit === 'tile' ? 'w-full h-full object-cover object-top' : 'w-full h-auto rounded'} />
|
|
222
227
|
)
|
|
223
228
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { credentialsFor } from '../utilities/credentials.js'
|
|
1
2
|
import { useEffect, useRef, useState } from 'react'
|
|
2
3
|
|
|
3
4
|
/* taxonomy-ok: molecule — a renderer KindPreview composes; no DS parts of its own to nest. */
|
|
@@ -29,17 +30,18 @@ async function loadPdfjs() {
|
|
|
29
30
|
return lib
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
function usePdf(src) {
|
|
33
|
+
function usePdf(src, credentials) {
|
|
33
34
|
const [state, setState] = useState({ src: null, doc: null, failed: false })
|
|
34
35
|
useEffect(() => {
|
|
35
36
|
let cancelled = false
|
|
36
37
|
let loading = null
|
|
37
38
|
loadPdfjs()
|
|
38
|
-
|
|
39
|
+
/* the sign-in cookie for a registered origin (utilities/credentials.js) — a private file answers 401 without it */
|
|
40
|
+
.then((lib) => { loading = lib.getDocument({ url: src, withCredentials: credentialsFor(src, credentials) === 'include' }); return loading.promise })
|
|
39
41
|
.then((doc) => { if (!cancelled) setState({ src, doc, failed: false }) })
|
|
40
42
|
.catch(() => { if (!cancelled) setState({ src, doc: null, failed: true }) })
|
|
41
43
|
return () => { cancelled = true; loading?.destroy() }
|
|
42
|
-
}, [src])
|
|
44
|
+
}, [src, credentials])
|
|
43
45
|
return state.src === src ? state : { doc: null, failed: false }
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -68,14 +70,14 @@ function PdfCanvas({ doc, page, className = '' }) {
|
|
|
68
70
|
return <canvas ref={ref} className={`kol-pdf-page ${className}`.trim()} />
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
export default function PdfPage({ src, fallback = null, className = '' }) {
|
|
72
|
-
const { doc, failed } = usePdf(src)
|
|
73
|
+
export default function PdfPage({ src, fallback = null, className = '', credentials }) {
|
|
74
|
+
const { doc, failed } = usePdf(src, credentials)
|
|
73
75
|
if (failed) return fallback
|
|
74
76
|
return <PdfCanvas doc={doc} page={1} className={className} />
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
export function PdfDocument({ src, fallback = null }) {
|
|
78
|
-
const { doc, failed } = usePdf(src)
|
|
79
|
+
export function PdfDocument({ src, fallback = null, credentials }) {
|
|
80
|
+
const { doc, failed } = usePdf(src, credentials)
|
|
79
81
|
const [current, setCurrent] = useState(1)
|
|
80
82
|
const mainRef = useRef(null)
|
|
81
83
|
const pages = doc ? Array.from({ length: doc.numPages }, (_, i) => i + 1) : []
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fragment, createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import { registerCredentialedOrigin } from '../utilities/credentials.js'
|
|
2
3
|
import formatSize from '../utilities/formatSize.js'
|
|
3
4
|
import { ROW_HEIGHT, ROW_FILL } from '../molecules/OptionRow.jsx'
|
|
4
5
|
import { glyphSize } from '../hooks/glyphLadders.js'
|
|
@@ -190,6 +191,8 @@ function useBucketLibrary({ client, bucket, defaults, settings: controlled, onSe
|
|
|
190
191
|
const buckets = useMemo(() => client?.buckets?.() ?? [], [client])
|
|
191
192
|
const bucketMeta = buckets.find((b) => b.id === bucket) ?? buckets[0] ?? { id: null, label: '', writable: false }
|
|
192
193
|
const bucketId = bucketMeta.id
|
|
194
|
+
/* a signed-in bucket's files are fetched with the cookie by every preview (utilities/credentials.js, 2026-10-28) */
|
|
195
|
+
if (bucketMeta.signedIn && bucketMeta.publicBase) registerCredentialedOrigin(bucketMeta.publicBase)
|
|
193
196
|
const base = () => ({ ...SETTINGS_BASE, ...(defaults?.[bucketId] ?? defaults ?? {}) })
|
|
194
197
|
const [own, setOwn] = useState(base)
|
|
195
198
|
/* PERSONALISATION (the media D1 pass, 2026-09-25): an uncontrolled page whose client offers
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* credentials — which file URLs a preview fetches WITH the sign-in cookie (ArticleRendererHomeHeroSelection, kol-website
|
|
3
|
+
* 2026-10-28 — a PDF on private.kolkrabbi.io answered 401 in Quick Look: `PdfPage` and `KindPreview` fetch the file
|
|
4
|
+
* themselves, and a plain fetch sends no cookie, while an <img> or a download does).
|
|
5
|
+
*
|
|
6
|
+
* A REGISTRY OF ORIGINS, not "every cross-origin URL": a credentialed request to a public CDN that answers
|
|
7
|
+
* `Access-Control-Allow-Origin: *` is refused by the browser, so sending the cookie everywhere would break every public
|
|
8
|
+
* file. An origin is registered by whoever knows it is signed in — `MediaLibrary` registers its signed-in bucket's
|
|
9
|
+
* `publicBase` (kol-media-client marks the private bucket `signedIn`), an app registers its own once at boot. A
|
|
10
|
+
* `credentials` prop on `KindPreview` / `PdfPage` overrides per call.
|
|
11
|
+
*
|
|
12
|
+
* import { registerCredentialedOrigin } from '@kolkrabbi/kol-component'
|
|
13
|
+
* registerCredentialedOrigin('https://private.kolkrabbi.io')
|
|
14
|
+
*/
|
|
15
|
+
const ORIGINS = new Set()
|
|
16
|
+
|
|
17
|
+
const originOf = (url) => {
|
|
18
|
+
try { return new URL(url, typeof location !== 'undefined' ? location.href : 'http://localhost').origin } catch { return null }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function registerCredentialedOrigin(url) {
|
|
22
|
+
const o = originOf(url)
|
|
23
|
+
if (o) ORIGINS.add(o)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* 'include' for a registered origin, else undefined (the browser's same-origin default) */
|
|
27
|
+
export function credentialsFor(url, override) {
|
|
28
|
+
if (override) return override
|
|
29
|
+
const o = originOf(url)
|
|
30
|
+
return o && ORIGINS.has(o) ? 'include' : undefined
|
|
31
|
+
}
|