@kolkrabbi/kol-component 0.309.0 → 0.311.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.311.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) : []
|
|
@@ -42,6 +42,10 @@ import { RAIL_ROW } from '../hooks/railRow.js'
|
|
|
42
42
|
* the transport both compose, so the two stay one size and one look):
|
|
43
43
|
* @param {'bottom'|'top'} [edge='bottom'] the pill's edge; `top` sits TABBAR_PILL_INSET under the top safe-area inset
|
|
44
44
|
* @param {boolean} [border=true] the pill's 1px oq-08 hairline
|
|
45
|
+
* @param {boolean} [dock=false] THE DOCK (PhoneNavDock, kol-fxr 2026-10-28, frame B2 — user: *"I moved the Phone nav in desktop,
|
|
46
|
+
* that component shoudl probablyget its own variant"*): the pill on a DESK — shown from md up, hidden
|
|
47
|
+
* below (the phone has its own nav), placed at the content's bottom-left, 64 in from the rail's edge
|
|
48
|
+
* (`--kol-shell-rail-width`) and 64 up, not centred
|
|
45
49
|
* @param {boolean} [shadow=false] a drop shadow — for a pill that floats over content (the transport), not the nav
|
|
46
50
|
* @param {'fill'|'circle'} [active='fill'] the lit slot: `fill` its whole 56 slot (today), `circle` a 44×44 1:1 circle
|
|
47
51
|
* @param {boolean} [foldable=false] a sideways swipe (> 40px) folds the pill into a 28×72 edge tab; a tap restores it
|
|
@@ -59,11 +63,11 @@ export const tabbarPillWidth = (count) => count * TABBAR_PILL_TAB + 14
|
|
|
59
63
|
/* the collapse's motion — one duration for the width and the glyph swap (300, user 2026-10-23: 180 read as abrupt) */
|
|
60
64
|
const COLLAPSE_MS = 300
|
|
61
65
|
|
|
62
|
-
export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, edge, border, shadow, active, foldable, folded, onFoldChange, foldSide, size, tracked = false, ariaLabel, className, style }) {
|
|
66
|
+
export default function TabsRow({ tabs: raw = [], value, onChange, onClose, onMinimise, look = 'underline', placement = 'inline', shape = 'bar', collapsed = false, onExpand, edge, border, shadow, dock, active, foldable, folded, onFoldChange, foldSide, size, tracked = false, ariaLabel, className, style }) {
|
|
63
67
|
const tabs = raw.map((t) => ({ ...t, id: t.id ?? t.value }))
|
|
64
68
|
if (look === 'chip') return <ChipTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 'sm'} ariaLabel={ariaLabel} className={className ?? ''} />
|
|
65
69
|
if (look === 'text') return <TextTabs tabs={tabs} value={value} onChange={onChange} size={size ?? 14} tracked={tracked} className={className ?? 'gap-6'} style={style} />
|
|
66
|
-
if (look === 'stacked') return <StackedTabs tabs={tabs} value={value} onChange={onChange} placement={placement} shape={shape} collapsed={collapsed} onExpand={onExpand} edge={edge} border={border} shadow={shadow} active={active} foldable={foldable} folded={folded} onFoldChange={onFoldChange} foldSide={foldSide} ariaLabel={ariaLabel} className={className ?? ''} />
|
|
70
|
+
if (look === 'stacked') return <StackedTabs tabs={tabs} value={value} onChange={onChange} placement={placement} shape={shape} collapsed={collapsed} onExpand={onExpand} edge={edge} border={border} shadow={shadow} dock={dock} active={active} foldable={foldable} folded={folded} onFoldChange={onFoldChange} foldSide={foldSide} ariaLabel={ariaLabel} className={className ?? ''} />
|
|
67
71
|
return <UnderlineTabs tabs={tabs} value={value} onChange={onChange} onClose={onClose} onMinimise={onMinimise} />
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -106,7 +110,7 @@ function TextTabs({ tabs, value, onChange, size, tracked, className, style }) {
|
|
|
106
110
|
/* the fold: a sideways swipe past this folds the pill, as frame E's prototype measures it */
|
|
107
111
|
const FOLD_SWIPE = 40
|
|
108
112
|
|
|
109
|
-
function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapsed = false, onExpand, edge = 'bottom', border = true, shadow = false, active: activeShape = 'fill', foldable = false, folded: foldedProp, onFoldChange, foldSide = 'left', ariaLabel = 'Sections', className }) {
|
|
113
|
+
function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapsed = false, onExpand, edge = 'bottom', border = true, shadow = false, dock = false, active: activeShape = 'fill', foldable = false, folded: foldedProp, onFoldChange, foldSide = 'left', ariaLabel = 'Sections', className }) {
|
|
110
114
|
const [foldedOwn, setFoldedOwn] = useState(false)
|
|
111
115
|
const swipe = useRef({ x: null, swiped: false })
|
|
112
116
|
if (tabs.length === 0) return null
|
|
@@ -154,7 +158,7 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
|
|
|
154
158
|
<nav
|
|
155
159
|
{...swipeProps}
|
|
156
160
|
className={`${pill
|
|
157
|
-
?
|
|
161
|
+
? `kol-mobile-tabbar kol-mobile-tabbar-pill ${dock ? 'hidden md:flex' : 'md:hidden'} fixed z-[calc(var(--kol-z-sticky)+1)] rounded-full p-1.5 overflow-hidden `
|
|
158
162
|
: phone ? 'kol-mobile-tabbar md:hidden fixed inset-x-0 bottom-0 z-[var(--kol-z-sticky)] ' : ''}flex items-stretch ${className}`.trim()}
|
|
159
163
|
style={pill ? {
|
|
160
164
|
/* THE PILL (user 2026-10-23, iOS Files beside the full-width bar): floats off the bottom edge, hugs its tabs,
|
|
@@ -162,8 +166,9 @@ function StackedTabs({ tabs, value, onChange, placement, shape = 'bar', collapse
|
|
|
162
166
|
* centre line, so the collapse shrinks it toward where More was and the × lands under the same thumb. */
|
|
163
167
|
height: TABBAR_H,
|
|
164
168
|
width: isCollapsed ? TABBAR_H : W,
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
...(dock
|
|
170
|
+
? { left: 'calc(var(--kol-shell-rail-width, 48px) + 64px)', bottom: 64 }
|
|
171
|
+
: { right: `calc(50% - ${W / 2}px)`, [top ? 'top' : 'bottom']: inset }),
|
|
167
172
|
background: 'var(--kol-surface-secondary)',
|
|
168
173
|
/* without the hairline the 1px it took stays, transparent, so the slots never move */
|
|
169
174
|
border: `1px solid ${border ? 'var(--kol-oq-08)' : 'transparent'}`,
|
|
@@ -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
|
+
}
|