@kolkrabbi/kol-component 0.290.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 +3 -3
- package/src/index.js +1 -0
- package/src/molecules/AppItem.jsx +93 -0
- package/src/molecules/ContentCard.jsx +20 -0
- package/src/molecules/ContentRow.jsx +16 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.291.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-
|
|
30
|
-
"@kolkrabbi/kol-
|
|
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",
|
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,6 +1,7 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import ContentMedia from './ContentMedia.jsx'
|
|
3
3
|
import ContentText from './ContentText.jsx'
|
|
4
|
+
import { useAppItem } from './AppItem.jsx'
|
|
4
5
|
import { toneClass } from '../utilities/tone.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -26,6 +27,11 @@ import { toneClass } from '../utilities/tone.js'
|
|
|
26
27
|
* (named `pad`, not `size` — `size` is the ruled TEXT slot). Image-only cards
|
|
27
28
|
* (print) pass no text slots and render no plate. Exotic chrome (drawers,
|
|
28
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.
|
|
29
35
|
*/
|
|
30
36
|
|
|
31
37
|
/* ruled defaults — defaults, not hardcodes; `ratio` stays overridable while
|
|
@@ -204,6 +210,20 @@ export default function ContentCard({
|
|
|
204
210
|
className = '',
|
|
205
211
|
...text
|
|
206
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
|
+
}
|
|
207
227
|
const aliased = ALIAS[variantProp] ?? variantProp
|
|
208
228
|
/* `layout` only re-keys inside the showcase family — it is not a general
|
|
209
229
|
* escape hatch that would let any variant borrow another's box. */
|
|
@@ -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
|