@kolkrabbi/kol-component 0.289.0 → 0.291.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.289.0",
3
+ "version": "0.291.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -55,6 +55,7 @@ export { usePopover, PopoverPanel, Tooltip } from './utilities/Popover.jsx'
55
55
  /* armLongPress — the touch hold the panel value controls report (moved from kol-hardware 2026-10-01) */
56
56
  export { armLongPress } from './utilities/armLongPress.js'
57
57
  export { default as ContextMenu, useContextMenu } from './molecules/ContextMenu.jsx'
58
+ export { AppItemMenuProvider } from './molecules/AppItem.jsx'
58
59
  export { default as ProsePreview } from './utilities/ProsePreview.jsx'
59
60
  export { default as QuantityInput } from './molecules/QuantityInput.jsx'
60
61
  /* Knob — the survivor's name (2026-10-02): `variant` dial · panel. `RotaryDial` is the alias, on the ledger. */
@@ -0,0 +1,93 @@
1
+ import { createContext, useContext } from 'react'
2
+ import { Icon } from '@kolkrabbi/kol-icons'
3
+ import ActionButton from './ActionButton.jsx'
4
+ import ContextMenu, { useContextMenu } from './ContextMenu.jsx'
5
+ import { MenuDropdownItem } from './MenuItem.jsx'
6
+ import { useModal } from './Modal.jsx'
7
+ import formatSize from '../utilities/formatSize.js'
8
+
9
+ /**
10
+ * The `app` variant of ContentCard and ContentRow (CatalogAppVariant, kol-fxr 2026-10-23): kol-fxr's
11
+ * approved saved-file card, so every app's library takes it by a bump. It is the `file` card and row
12
+ * with the parts slotted — download on the cover, a cog over a trash in the plate, Rename · Duplicate ·
13
+ * Delete on the cog and on right-click. The consumer passes raw writes (`verbs`); the dialogs are asked
14
+ * here. A verb not passed is not drawn.
15
+ *
16
+ * The menu is ONE per page: `AppItemMenuProvider` (CatalogPage mounts it) holds it, and every app card
17
+ * and row opens it. Without a provider the card still draws download and trash, but no cog and no
18
+ * right-click menu.
19
+ */
20
+
21
+ const MenuCtx = createContext(null)
22
+
23
+ const useAsk = () => {
24
+ const modal = useModal()
25
+ return {
26
+ rename: async (name, verbs) => {
27
+ const next = await modal.prompt('Rename:', name ?? '')
28
+ if (next != null && next.trim() && next.trim() !== name) verbs.rename(next.trim())
29
+ },
30
+ remove: async (name, verbs) => {
31
+ if (await modal.confirm(`Delete “${name || 'Untitled'}”?`, { okLabel: 'Delete' })) verbs.remove()
32
+ },
33
+ }
34
+ }
35
+
36
+ const glyph = (name) => <Icon name={name} size={14} />
37
+
38
+ export function AppItemMenuProvider({ children }) {
39
+ const menu = useContextMenu()
40
+ const ask = useAsk()
41
+ return (
42
+ <MenuCtx.Provider value={menu}>
43
+ {children}
44
+ <ContextMenu menu={menu}>
45
+ {(item) => item && (
46
+ <>
47
+ {item.verbs?.rename && <MenuDropdownItem iconLeft={glyph('edit')} onClick={() => ask.rename(item.name, item.verbs)}>Rename</MenuDropdownItem>}
48
+ {item.verbs?.duplicate && <MenuDropdownItem iconLeft={glyph('copy')} onClick={item.verbs.duplicate}>Duplicate</MenuDropdownItem>}
49
+ {item.verbs?.remove && <MenuDropdownItem iconLeft={glyph('trash')} onClick={() => ask.remove(item.name, item.verbs)}>Delete</MenuDropdownItem>}
50
+ {item.menuItems}
51
+ </>
52
+ )}
53
+ </ContextMenu>
54
+ </MenuCtx.Provider>
55
+ )
56
+ }
57
+
58
+ /* the plate's two actions, stacked over its padded height; a plate press never opens the card */
59
+ function AppPlate({ name, verbs, onSettings }) {
60
+ const ask = useAsk()
61
+ return (
62
+ <div className="flex h-full flex-col items-center justify-between" onClick={(e) => e.stopPropagation()}>
63
+ {onSettings && <ActionButton chrome="inline" size="sm" icon="settings-01" confirmIcon="settings-01" label="Settings" onAction={onSettings} />}
64
+ {verbs?.remove && <ActionButton chrome="inline" size="sm" icon="trash" confirmIcon="trash" label="Delete" onAction={() => ask.remove(name, verbs)} />}
65
+ </div>
66
+ )
67
+ }
68
+
69
+ const placeholder = (
70
+ <div className="size-full flex items-center justify-center bg-oq-04 text-fg-24" aria-label="No preview yet">
71
+ <Icon name="image" size={24} />
72
+ </div>
73
+ )
74
+
75
+ /**
76
+ * useAppItem(variant, props) — the `file` props an `app` item draws with, or null for any other variant.
77
+ * Always runs the same hooks (one context read), so ContentCard / ContentRow call it unconditionally.
78
+ */
79
+ export function useAppItem(variant, { title, verbs, download, menuItems, date, size, media, tone }) {
80
+ const menu = useContext(MenuCtx)
81
+ if (variant !== 'app') return null
82
+ const hasMenu = !!menu && !!(verbs?.rename || verbs?.duplicate || verbs?.remove || menuItems)
83
+ const openMenu = hasMenu ? (e) => menu.openAt(e, { name: title, verbs, menuItems }) : undefined
84
+ return {
85
+ tone: tone ?? 'secondary',
86
+ date: typeof date === 'number' ? new Date(date).toISOString().slice(0, 10) : date,
87
+ size: typeof size === 'number' ? formatSize(size) : size,
88
+ media: typeof media === 'string' ? <img src={media} alt={title ?? ''} className="size-full object-cover" /> : media ?? placeholder,
89
+ control: download ? <ActionButton chrome="media" icon="download" confirmIcon="check" label="Download" confirmLabel="Downloaded" onAction={download} /> : undefined,
90
+ actions: openMenu || verbs?.remove ? <AppPlate name={title} verbs={verbs} onSettings={openMenu} /> : undefined,
91
+ onContextMenu: openMenu,
92
+ }
93
+ }
@@ -1,5 +1,7 @@
1
+ import { useLayoutEffect, useRef, useState } from 'react'
1
2
  import ContentMedia from './ContentMedia.jsx'
2
3
  import ContentText from './ContentText.jsx'
4
+ import { useAppItem } from './AppItem.jsx'
3
5
  import { toneClass } from '../utilities/tone.js'
4
6
 
5
7
  /**
@@ -25,6 +27,11 @@ import { toneClass } from '../utilities/tone.js'
25
27
  * (named `pad`, not `size` — `size` is the ruled TEXT slot). Image-only cards
26
28
  * (print) pass no text slots and render no plate. Exotic chrome (drawers,
27
29
  * keylines, specimens) is consumer content through `media`.
30
+ *
31
+ * APP (CatalogAppVariant, kol-fxr 2026-10-23): `variant="app"` is the `file` card with an app
32
+ * library's parts slotted from `verbs` (`{ rename?, duplicate?, remove? }`), `download` and
33
+ * `menuItems` — download on the cover, cog over trash in the plate, the page's one menu on
34
+ * right-click. `date` takes ms, `size` bytes, `media` a src. See AppItem.jsx.
28
35
  */
29
36
 
30
37
  /* ruled defaults — defaults, not hardcodes; `ratio` stays overridable while
@@ -203,6 +210,20 @@ export default function ContentCard({
203
210
  className = '',
204
211
  ...text
205
212
  }) {
213
+ /* `app` (CatalogAppVariant, kol-fxr 2026-10-23) is the `file` card with its parts slotted from
214
+ * `verbs` · `download` · `menuItems` — AppItem.jsx. They never reach ContentText. */
215
+ const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone })
216
+ delete text.verbs; delete text.download; delete text.menuItems
217
+ if (app) {
218
+ variantProp = 'file'
219
+ tone = app.tone
220
+ media = app.media
221
+ control = app.control ?? control
222
+ actions = app.actions ?? actions
223
+ onContextMenu = app.onContextMenu ?? onContextMenu
224
+ text.date = app.date
225
+ text.size = app.size
226
+ }
206
227
  const aliased = ALIAS[variantProp] ?? variantProp
207
228
  /* `layout` only re-keys inside the showcase family — it is not a general
208
229
  * escape hatch that would let any variant borrow another's box. */
@@ -240,6 +261,20 @@ export default function ContentCard({
240
261
  * left, instead of bottom-right (the 2026-08-15 ruling). Block from the
241
262
  * first value, inline from the second (or the same one). */
242
263
  const [padBlock, padInline = padBlock] = String(padding ?? '0').trim().split(/\s+/)
264
+ /* the copy stops BEFORE the actions (FileCardTitleClearsActions, kol-fxr 2026-10-22): they are
265
+ * absolute, so the text column spanned the plate and a long title's ellipsis landed under the cog.
266
+ * Their measured width (+ one pad) is reserved on the text side, so `truncate` ends left of them. */
267
+ const actionsRef = useRef(null)
268
+ const [actionsW, setActionsW] = useState(0)
269
+ useLayoutEffect(() => {
270
+ const el = actionsRef.current
271
+ if (!el) { setActionsW(0); return undefined }
272
+ const measure = () => setActionsW(el.offsetWidth)
273
+ measure()
274
+ const ro = new ResizeObserver(measure)
275
+ ro.observe(el)
276
+ return () => ro.disconnect()
277
+ }, [actions != null])
243
278
  /* image-only cards (print) pass no text slots — the empty plate must not render */
244
279
  const hasText = ['title', 'body', 'kicker', 'detail', 'date', 'size', 'meta', 'tags'].some((k) => textSlots[k] != null)
245
280
  /* `actions` sit IN THE TEXT PLATE, bottom-right (user ruling 2026-08-15:
@@ -280,6 +315,7 @@ export default function ContentCard({
280
315
  className="kol-card-plate relative"
281
316
  style={{
282
317
  '--kol-plate-pad': padding,
318
+ '--kol-plate-actions-w': actionsW ? `calc(${actionsW}px + ${padInline})` : undefined,
283
319
  '--kol-plate-pad-md': box.padMd,
284
320
  padding,
285
321
  /* a fill-card with no cover keeps its frame and its plate keeps the FOOT — dropping the media
@@ -293,13 +329,14 @@ export default function ContentCard({
293
329
  zIndex: box.layout === 'canvas' ? 1 : undefined,
294
330
  }}
295
331
  >
296
- {hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...textSlots} />}
332
+ {hasText && <ContentText variant={variant} form={isHero ? 'hero' : 'card'} className={actionsW ? 'min-w-0 pr-[var(--kol-plate-actions-w)]' : ''} tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...textSlots} />}
297
333
  {/* ABSOLUTE, not a flex sibling: the plate's height moves with the title
298
334
  * and the meta, so a laid-out stack would stretch or drift with it. The
299
335
  * inset reads the SAME pad token the plate uses, so the icons sit the
300
336
  * same distance from the top and right edges as the copy does. */}
301
337
  {actions && (
302
338
  <div
339
+ ref={actionsRef}
303
340
  className="absolute flex"
304
341
  style={{ top: padBlock, bottom: padBlock, right: padInline }}
305
342
  >
@@ -1,5 +1,6 @@
1
1
  import ContentMedia from './ContentMedia.jsx'
2
2
  import ContentText from './ContentText.jsx'
3
+ import { useAppItem } from './AppItem.jsx'
3
4
  import { toneClass } from '../utilities/tone.js'
4
5
 
5
6
  /**
@@ -11,7 +12,8 @@ import { toneClass } from '../utilities/tone.js'
11
12
  * 36 square thumb when `media` is passed (none without); article rides a 120px 16:9 thumb; work a framed 64px row; typeface a
12
13
  * framed no-thumb block.
13
14
  *
14
- * @param {string} variant file | catalog | print | article | work | typeface | roster
15
+ * @param {string} variant file | app | catalog | print | article | work | typeface | roster
16
+ * (`app` = the file row with `verbs` · `menuItems` slotted — AppItem.jsx)
15
17
  * (`default` is an alias of `file`). `roster` is the pickable
16
18
  * row: filled tile, no border or divider, a FIXED 56px height the
17
19
  * content fills, a 40px square thumb and two truncated lines.
@@ -191,6 +193,19 @@ export default function ContentRow({
191
193
  className = '',
192
194
  ...text
193
195
  }) {
196
+ /* `app` (CatalogAppVariant, kol-fxr 2026-10-23) is the `file` row with its parts slotted from
197
+ * `verbs` · `download` · `menuItems` — AppItem.jsx. They never reach ContentText. */
198
+ const app = useAppItem(variantProp, { title: text.title, verbs: text.verbs, download: text.download, menuItems: text.menuItems, date: text.date, size: text.size, media, tone })
199
+ delete text.verbs; delete text.download; delete text.menuItems
200
+ if (app) {
201
+ variantProp = 'file'
202
+ tone = app.tone
203
+ media = app.media
204
+ actions = app.actions ?? actions
205
+ onContextMenu = app.onContextMenu ?? onContextMenu
206
+ text.date = app.date
207
+ text.size = app.size
208
+ }
194
209
  const aliased = ALIAS[variantProp] ?? variantProp
195
210
  const variant = aliased.startsWith('showcase') && layout ? LAYOUT_KEY[layout] ?? aliased : aliased
196
211
  const box = BOX[variant] ?? BOX.file
@@ -305,7 +320,7 @@ export default function ContentRow({
305
320
  <div className="flex flex-1 min-w-0 items-stretch" style={{ padding: box.plate, gap: box.plateGap ?? box.plate }}>
306
321
  {/* the meta line's leading is its type size, so its baseline lands on the bottom pad, level with the last
307
322
  * control — at its 16px line the digits sat ~4px above it (user 2026-10-22) */}
308
- <ContentText variant={variant} form="row" className="flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
323
+ <ContentText variant={variant} form="row" className="min-w-0 flex-1 justify-between [&_.kol-mono-12]:leading-none" tagVariant={tagVariant ?? (/surface-/.test(ground ?? '') ? 'tertiary' : 'primary')} {...text} />
309
324
  {actions && <div className="shrink-0">{actions}</div>}
310
325
  </div>
311
326
  ) : (