@kolkrabbi/kol-component 0.296.0 → 0.297.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.296.0",
3
+ "version": "0.297.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "embla-carousel-react": "^8.6.0",
27
27
  "pdfjs-dist": "^6.3.289",
28
28
  "react-syntax-highlighter": "^16.1.1",
29
- "@kolkrabbi/kol-search": "^0.3.0",
30
- "@kolkrabbi/kol-markdown": "^0.1.3"
29
+ "@kolkrabbi/kol-markdown": "^0.1.3",
30
+ "@kolkrabbi/kol-search": "^0.3.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@kolkrabbi/kol-icons": ">=0.22.0",
@@ -68,20 +68,25 @@ const placeholder = (
68
68
  * cover's other corner and reads in the rail. Always runs the same hooks (one
69
69
  * context read), so ContentCard / ContentRow call it unconditionally.
70
70
  */
71
- export function useAppItem(variant, { title, verbs, download, menuItems, date, size, media, tone, tags, details, onTags, note, onNote, mark }) {
71
+ export function useAppItem(variant, { title, verbs, download, menuItems, date, size, media, tone, tags, details, onTags, note, onNote, mark, onCover, onInsert, row = false }) {
72
72
  const ctx = useContext(MenuCtx)
73
73
  if (variant !== 'app') return null
74
74
  const menu = ctx?.menu
75
75
  const hasMenu = !!menu && !!(verbs?.rename || verbs?.duplicate || verbs?.remove || menuItems)
76
76
  const openMenu = hasMenu ? (e) => menu.openAt(e, { name: title, verbs, menuItems }) : undefined
77
- /* the cog opens the file's info rail (user ruling 2026-10-23); right-click keeps the menu */
78
- const openInfo = ctx ? () => ctx.openInfo({ name: title, verbs, download, tags, details, onTags, note, onNote, mark }) : undefined
77
+ /* the card's date and size, as text — the rail prints the same two under Details (user 2026-10-24: *"why is date
78
+ * and size not included in file info?"*) */
79
+ const dateText = typeof date === 'number' ? new Date(date).toISOString().slice(0, 10) : date
80
+ const sizeText = typeof size === 'number' ? formatSize(size) : size
81
+ /* the cog opens the file's info rail (user ruling 2026-10-23); right-click keeps the menu. `onCover(src)` is the
82
+ * rail's Upload image (2026-10-24) */
83
+ const openInfo = ctx ? () => ctx.openInfo({ name: title, verbs, download, tags, details, onTags, note, onNote, mark, date: dateText, size: sizeText, onCover }) : undefined
79
84
  /* the cover's download stops its click at the control, as the plate does — a card that opens on click
80
85
  * opened under the download too (AppCardDownloadClickBubbles, kol-monitor 2026-10-23) */
81
86
  return {
82
87
  tone: tone ?? 'secondary',
83
- date: typeof date === 'number' ? new Date(date).toISOString().slice(0, 10) : date,
84
- size: typeof size === 'number' ? formatSize(size) : size,
88
+ date: dateText,
89
+ size: sizeText,
85
90
  media: typeof media === 'string' ? <img src={media} alt={title ?? ''} className="size-full object-cover" /> : media ?? placeholder,
86
91
  control: download ? <ActionButton chrome="media" icon="download" confirmIcon="check" label="Download" confirmLabel="Downloaded" onAction={(e) => { e?.stopPropagation(); return download(e) }} /> : undefined,
87
92
  /* THE MARK (user 2026-10-24, FXR's files: *"show together with a label on the card … an icon of each chrome as an
@@ -95,8 +100,18 @@ export function useAppItem(variant, { title, verbs, download, menuItems, date, s
95
100
  <span className="kol-action-glyph inline-grid place-items-center" style={{ width: 20, height: 20 }}><Icon name={mark.icon} size={20} /></span>
96
101
  </span>
97
102
  </Tooltip>
103
+ /* INSERT ON A CARD (StudioCreate's parts, 2026-10-24 — every card the same fields and icons, so a part keeps its plate):
104
+ * the cover's other corner, in the download's box — a mark and Insert never meet (a part carries no mark) */
105
+ ) : onInsert && !row ? (
106
+ <ActionButton chrome="media" icon="plus" confirmIcon="check" label="Insert" confirmLabel="Inserted" onAction={(e) => { e?.stopPropagation(); return onInsert(e) }} />
107
+ ) : undefined,
108
+ /* the plate — cog over trash; on a row, Insert sits before the plate (the row has no cover corner to spare) */
109
+ actions: openInfo || verbs?.remove || (onInsert && row) ? (
110
+ <div className="flex h-full items-stretch gap-2">
111
+ {onInsert && row && <div className="flex items-center" onClick={(e) => e.stopPropagation()}><ActionButton chrome="inline" size="sm" icon="plus" confirmIcon="check" label="Insert" confirmLabel="Inserted" onAction={(e) => { e?.stopPropagation(); return onInsert(e) }} /></div>}
112
+ {(openInfo || verbs?.remove) && <AppPlate name={title} verbs={verbs} onSettings={openInfo} />}
113
+ </div>
98
114
  ) : undefined,
99
- actions: openInfo || verbs?.remove ? <AppPlate name={title} verbs={verbs} onSettings={openInfo} /> : undefined,
100
115
  onContextMenu: openMenu,
101
116
  }
102
117
  }
@@ -213,8 +213,8 @@ export default function ContentCard({
213
213
  /* `app` (CatalogAppVariant, kol-fxr 2026-10-23) is the `file` card with its parts slotted from
214
214
  * `verbs`, `download`, `menuItems`, and `tags`, `details`, `onTags` for the info rail — AppItem.jsx.
215
215
  * None of them reach ContentText; an app card's `tags` are the rail's, never chips on the plate. */
216
- const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone, tags: text.tags, details: text.details, onTags: text.onTags, note: text.note, onNote: text.onNote, mark: text.mark })
217
- delete text.verbs; delete text.download; delete text.menuItems; delete text.details; delete text.onTags; delete text.note; delete text.onNote; delete text.mark
216
+ const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone, tags: text.tags, details: text.details, onTags: text.onTags, note: text.note, onNote: text.onNote, mark: text.mark, onCover: text.onCover, onInsert: text.onInsert })
217
+ delete text.verbs; delete text.download; delete text.menuItems; delete text.details; delete text.onTags; delete text.note; delete text.onNote; delete text.mark; delete text.onCover; delete text.onInsert
218
218
  if (app) {
219
219
  delete text.tags
220
220
  variantProp = 'file'
@@ -196,8 +196,8 @@ export default function ContentRow({
196
196
  /* `app` (CatalogAppVariant, kol-fxr 2026-10-23) is the `file` row with its parts slotted from
197
197
  * `verbs`, `download`, `menuItems`, and `tags`, `details`, `onTags` for the info rail — AppItem.jsx.
198
198
  * None of them reach ContentText; an app row's `tags` are the rail's, never chips in the row. */
199
- const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone, tags: text.tags, details: text.details, onTags: text.onTags, note: text.note, onNote: text.onNote, mark: text.mark })
200
- delete text.verbs; delete text.download; delete text.menuItems; delete text.details; delete text.onTags; delete text.note; delete text.onNote; delete text.mark
199
+ const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone, tags: text.tags, details: text.details, onTags: text.onTags, note: text.note, onNote: text.onNote, mark: text.mark, onCover: text.onCover, onInsert: text.onInsert, row: true })
200
+ delete text.verbs; delete text.download; delete text.menuItems; delete text.details; delete text.onTags; delete text.note; delete text.onNote; delete text.mark; delete text.onCover; delete text.onInsert
201
201
  if (app) {
202
202
  delete text.tags
203
203
  variantProp = 'file'
@@ -6,7 +6,9 @@ import Tag from '../atoms/Tag.jsx'
6
6
  import Input from '../atoms/Input.jsx'
7
7
  import Textarea from '../atoms/Textarea.jsx'
8
8
  import IconFrame from '../atoms/IconFrame.jsx'
9
+ import Button from '../atoms/Button.jsx'
9
10
  import { Tooltip } from '../utilities/Popover.jsx'
11
+ import { pickImage } from '../utilities/imageToDataUrl.js'
10
12
  import SettingsPanel, { SettingsFooter } from './SettingsPanel.jsx'
11
13
  import SettingsSections from './SettingsSections.jsx'
12
14
 
@@ -27,6 +29,11 @@ import SettingsSections from './SettingsSections.jsx'
27
29
  * READ AND EDIT (user 2026-10-23): the rail opens read-only — name, tags, note, details as text — and the pencil on its
28
30
  * header line (Create's rename glyph, `IconFrame nav`) toggles edit mode. `note` / `onNote` arrived the same day: a plain
29
31
  * description on a file, HubHome's `note` and `onNote(file, text)`.
32
+ *
33
+ * DATE · SIZE · COVER (user 2026-10-24: *"why is date and size not included in file info? same with upload image?"* ·
34
+ * *"why is edit 32px icon when others are 26px??"*): Details opens with the card's own Date and Size; in edit mode a
35
+ * Cover row offers Upload image — the DS picker, a webp data URL, handed to the file's `onCover(src)` (HubHome's
36
+ * `onCover(file, src)`); and the pencil is the rows' `sm` frame (26), as the × beside it.
30
37
  */
31
38
  /* the rail's body — READ MODE by default, the header's pencil opens EDIT MODE (user 2026-10-23: *"use the same edit icon
32
39
  * from create? to edit mode or read mode?"*): read shows the name, the tag chips and the note as text; edit swaps in the
@@ -34,7 +41,7 @@ import SettingsSections from './SettingsSections.jsx'
34
41
  * stays while the consumer's state catches up. ONE row per field, no section label over a lone row of the same name
35
42
  * (user 2026-10-23: the rail read NAME / NAME, TAGS / TAGS / ADD). */
36
43
  function FileRailBody({ item, editing, onRenamed }) {
37
- const { name, verbs, tags, details, note, onTags, onNote, mark } = item
44
+ const { name, verbs, tags, details, note, onTags, onNote, mark, date, size, onCover } = item
38
45
  const [draftName, setDraftName] = useState(name ?? '')
39
46
  const [draftTags, setDraftTags] = useState(tags ?? [])
40
47
  const [newTag, setNewTag] = useState('')
@@ -80,11 +87,18 @@ function FileRailBody({ item, editing, onRenamed }) {
80
87
  ...((editNote || draftNote.trim()) ? [editNote
81
88
  ? { label: 'Note', align: 'fill', render: () => <Textarea size="sm" rows={3} value={draftNote} onChange={(e) => setDraftNote(e.target.value)} onBlur={commitNote} placeholder="Add a note" aria-label="Note" /> }
82
89
  : { label: 'Note', text: true, value: text(draftNote.trim(), 'text-right') }] : []),
90
+ /* edit mode: the cover — Upload image hands the DS picker's data URL to `onCover` (2026-10-24) */
91
+ ...((editing && onCover) ? [{ label: 'Cover', align: 'fill', render: () => (
92
+ <Button size="sm" tone="grey" onClick={async () => { const src = await pickImage(); if (src) onCover(src) }}>Upload image</Button>
93
+ ) }] : []),
83
94
  ]
84
95
  const sections = [
85
96
  { rows },
86
- ...((mark || details?.length) ? [{ label: 'Details', rows: [
87
- /* the mark first — FXR's chrome: Chrome, Editor (`of` names the axis; `label` the value) */
97
+ ...((date || size || mark || details?.length) ? [{ label: 'Details', rows: [
98
+ /* the card's own date and size first (user 2026-10-24) */
99
+ ...(date ? [{ label: 'Date', text: true, value: text(date) }] : []),
100
+ ...(size ? [{ label: 'Size', text: true, value: text(size) }] : []),
101
+ /* then the mark — FXR's chrome: Chrome, Editor (`of` names the axis; `label` the value) */
88
102
  ...(mark ? [{ label: mark.of ?? 'Kind', text: true, value: text(mark.label) }] : []),
89
103
  ...(details ?? []).map(({ label, value }) => ({ label, text: true, value: text(value) })),
90
104
  ] }] : []),
@@ -115,7 +129,7 @@ export default function AppItemMenuProvider({ children }) {
115
129
  const [info, setInfo] = useState(null)
116
130
  const [editing, setEditing] = useState(false)
117
131
  const close = () => setInfo(null)
118
- const editable = !!(info?.verbs?.rename || info?.onTags || info?.onNote)
132
+ const editable = !!(info?.verbs?.rename || info?.onTags || info?.onNote || info?.onCover)
119
133
  return (
120
134
  /* each open is stamped, so the rail keeps its drafts across a rename (the key no longer follows the name) and the
121
135
  * foot's Delete confirm names the file as renamed, not as opened */
@@ -133,8 +147,9 @@ export default function AppItemMenuProvider({ children }) {
133
147
  </ContextMenu>
134
148
  <SettingsPanel
135
149
  open={!!info} variant="rail" title="File" onClose={close} footer={info ? fileRailFoot(info, ask, close) : undefined}
136
- /* the pencil — bare, as Create's rename and the catalog's filter and search are (IconFrame nav, 16 in the 32 box) */
137
- headerActions={editable ? <IconFrame name="edit" variant="nav" size="md" iconSize={16} onClick={() => setEditing((v) => !v)} aria-label={editing ? 'Done editing' : 'Edit'} /> : undefined}
150
+ /* the pencil — bare, as Create's rename is; the rows' `sm` frame (26), the same box as the × beside it (user
151
+ * 2026-10-24: *"why is edit 32px icon when others are 26px??"*) */
152
+ headerActions={editable ? <IconFrame name="edit" variant="nav" size="sm" onClick={() => setEditing((v) => !v)} aria-label={editing ? 'Done editing' : 'Edit'} /> : undefined}
138
153
  >
139
154
  {/* `key` resets the drafts per file */}
140
155
  {info && <FileRailBody key={info.openId} item={info} editing={editing} onRenamed={(name) => setInfo((i) => i && { ...i, name })} />}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * imageToDataUrl — a picked image file as a small data URL, for a card's cover (the file rail's Upload
3
+ * image, 2026-10-24 — plan home-library-detail-one-card 2.2). Decodes the file, fits it inside `max`
4
+ * on its longer side, encodes webp at `quality`. What the editor's `captureThumb` writes for a save,
5
+ * for a picture the user supplies.
6
+ *
7
+ * @param {File} file
8
+ * @param {Object} [opts]
9
+ * @param {number} [opts.max=640] the longer side, px
10
+ * @param {number} [opts.quality=0.82]
11
+ * @returns {Promise<string>} `data:image/webp;base64,…`
12
+ */
13
+ export default async function imageToDataUrl(file, { max = 640, quality = 0.82 } = {}) {
14
+ const bitmap = await createImageBitmap(file)
15
+ const scale = Math.min(1, max / Math.max(bitmap.width, bitmap.height))
16
+ const w = Math.max(1, Math.round(bitmap.width * scale))
17
+ const h = Math.max(1, Math.round(bitmap.height * scale))
18
+ const canvas = document.createElement('canvas')
19
+ canvas.width = w
20
+ canvas.height = h
21
+ canvas.getContext('2d').drawImage(bitmap, 0, 0, w, h)
22
+ bitmap.close?.()
23
+ return canvas.toDataURL('image/webp', quality)
24
+ }
25
+
26
+ /** pickImage — opens the file chooser for one image and resolves with its data URL, or null when cancelled. */
27
+ export function pickImage(opts) {
28
+ return new Promise((resolve) => {
29
+ const input = document.createElement('input')
30
+ input.type = 'file'
31
+ input.accept = 'image/*'
32
+ input.onchange = async () => {
33
+ const f = input.files?.[0]
34
+ resolve(f ? await imageToDataUrl(f, opts).catch(() => null) : null)
35
+ }
36
+ input.oncancel = () => resolve(null)
37
+ input.click()
38
+ })
39
+ }