@podoba/react 0.0.48 → 0.0.50
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/components/brand-page-header.tsx +22 -9
- package/src/components/context-menu.tsx +16 -22
- package/src/components/cta-pill.tsx +6 -5
- package/src/components/dropdown-menu.tsx +2 -2
- package/src/components/table.examples.tsx +5 -1
- package/src/components/table.tsx +38 -22
- package/src/editor/block-editor.tsx +107 -18
- package/src/utils/uic.ts +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"typecheck": "tsc --build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@podoba/tokens": "^0.0.
|
|
32
|
-
"@podoba/tailwind": "^0.0.
|
|
31
|
+
"@podoba/tokens": "^0.0.50",
|
|
32
|
+
"@podoba/tailwind": "^0.0.50",
|
|
33
33
|
"react-aria-components": "1.18.0",
|
|
34
34
|
"class-variance-authority": "0.7.1",
|
|
35
35
|
"clsx": "2.1.1",
|
|
@@ -9,8 +9,10 @@ import { DisplayHeading } from './text'
|
|
|
9
9
|
* gs-platform's header is a two-column grid: a left "welcome" section
|
|
10
10
|
* (optional breadcrumbs + a large greeting line) and a right section holding an
|
|
11
11
|
* `ExpandableCTA` — a collapsed teal pill that expands into a create-hub panel.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* On phones (below `sm`, 640px) the CTA docks to the safe bottom edge of the
|
|
13
|
+
* viewport; the page reserves that room with the `mobile-cta-dock-inset` utility
|
|
14
|
+
* from @podoba/tailwind. From `sm` the CTA sits in the header: two equal columns on
|
|
15
|
+
* a narrow tablet, then the desktop 2/3 + 1/3 grid from `md` (768px).
|
|
14
16
|
*
|
|
15
17
|
* The expandable CTA is a controlled disclosure: the collapsed teal pill is a
|
|
16
18
|
* React Aria `Button` (keyboard + focus ring + press handling) wired to a
|
|
@@ -79,8 +81,10 @@ export type BrandPageHeaderProps = {
|
|
|
79
81
|
/** Sticky header on scroll. */
|
|
80
82
|
sticky?: boolean
|
|
81
83
|
/**
|
|
82
|
-
* Dock the supplied CTA to the safe bottom edge below
|
|
83
|
-
* source Manager's collapsed ExpandableCTA.
|
|
84
|
+
* Dock the supplied CTA to the safe bottom edge on phones (below `sm`, 640px),
|
|
85
|
+
* like the source Manager's collapsed ExpandableCTA. Tablets keep it in the
|
|
86
|
+
* header. The docked wrapper carries `data-mobile-cta-dock`; reserve its room on
|
|
87
|
+
* the page with `mobile-cta-dock-inset`. Enabled by default.
|
|
84
88
|
*/
|
|
85
89
|
mobileCtaDocked?: boolean
|
|
86
90
|
className?: string
|
|
@@ -110,6 +114,7 @@ export function BrandPageHeader({
|
|
|
110
114
|
const expanded = isControlled ? expandedProp : internalExpanded
|
|
111
115
|
const hasExpandable = Boolean(createHub)
|
|
112
116
|
const HeadingTag = `h${headingLevel}` as const
|
|
117
|
+
const ctaDocked = Boolean(cta) && mobileCtaDocked
|
|
113
118
|
const panelId = useId()
|
|
114
119
|
const panelRef = useRef<HTMLDivElement>(null)
|
|
115
120
|
const contentRef = useRef<HTMLDivElement>(null)
|
|
@@ -270,8 +275,11 @@ export function BrandPageHeader({
|
|
|
270
275
|
>
|
|
271
276
|
<div
|
|
272
277
|
className={`grid grid-cols-1 grid-rows-[auto_auto] items-start gap-y-2 ${
|
|
273
|
-
|
|
274
|
-
|
|
278
|
+
// Between `sm` and `md` an undocked hero CTA shares the row as an equal column.
|
|
279
|
+
ctaDocked ? 'sm:grid-cols-2 sm:gap-x-5' : ''
|
|
280
|
+
} ${variant === 'navigation' ? 'md:grid-cols-2' : 'md:grid-cols-[2fr_1fr]'} ${
|
|
281
|
+
variant === 'dashboard' ? 'md:gap-x-5' : 'md:gap-x-4'
|
|
282
|
+
}`}
|
|
275
283
|
>
|
|
276
284
|
<div className="col-start-1 row-[1/-1] flex w-full min-w-0 flex-col gap-0">
|
|
277
285
|
{/* EXACTLY ONE Breadcrumb landmark. Rendering the trail and `parentLink`
|
|
@@ -327,12 +335,17 @@ export function BrandPageHeader({
|
|
|
327
335
|
{cta ? (
|
|
328
336
|
// Hero CTA spans 4 of 12 columns (one third) — the greeting takes the rest.
|
|
329
337
|
<div
|
|
338
|
+
data-mobile-cta-dock={ctaDocked ? '' : undefined}
|
|
330
339
|
className={
|
|
331
340
|
[
|
|
332
|
-
|
|
333
|
-
? 'fixed inset-x-0 bottom-0 z-40 min-w-0 px-3 pb-mobile-cta-bottom
|
|
341
|
+
ctaDocked
|
|
342
|
+
? 'fixed inset-x-0 bottom-0 z-40 min-w-0 px-3 pb-mobile-cta-bottom sm:static sm:inset-auto sm:col-start-2 sm:row-[1/-1] sm:z-auto sm:h-full sm:max-w-full sm:items-stretch sm:justify-end sm:self-stretch sm:p-0'
|
|
334
343
|
: 'min-w-0 md:col-start-2 md:row-[1/-1] md:flex md:h-full md:max-w-full md:items-stretch md:justify-end md:self-stretch',
|
|
335
|
-
|
|
344
|
+
// The open hub is a bottom sheet below `md` that takes the CTA's place, so the
|
|
345
|
+
// CTA hides there even on 640-767px tablets where it is no longer docked.
|
|
346
|
+
// `max-md:hidden` would lose to `sm:flex` (Tailwind emits max-* first), so the
|
|
347
|
+
// display switch itself moves to `md` while the hub is open.
|
|
348
|
+
expanded ? 'hidden md:flex' : ctaDocked ? 'sm:flex' : '',
|
|
336
349
|
].join(' ')
|
|
337
350
|
}
|
|
338
351
|
>
|
|
@@ -115,39 +115,33 @@ const visibleGroupsOf = (groups: ContextMenuGroup[]): ContextMenuGroup[] =>
|
|
|
115
115
|
const MenuItem = uic(RACMenuItem, {
|
|
116
116
|
displayName: 'ContextMenuItem',
|
|
117
117
|
// Source `.itemButton`: normal ink weight, with a weight bump on hover/focus.
|
|
118
|
-
// The panel is ALWAYS dark
|
|
119
|
-
// wash
|
|
120
|
-
// `[data-theme]` and would go dark-on-dark in
|
|
121
|
-
//
|
|
122
|
-
// this design system is generated into @podoba/tokens' `variables.css` from the
|
|
123
|
-
// upstream API — a hand-written custom property has nowhere to be defined and
|
|
124
|
-
// silently resolves to nothing.
|
|
118
|
+
// The panel is ALWAYS dark (it does not follow the theme), so its ink and hover
|
|
119
|
+
// wash come from the fixed `context-menu-*` tokens, not `text-fg` /
|
|
120
|
+
// `bg-surface-muted`, which flip with `[data-theme]` and would go dark-on-dark in
|
|
121
|
+
// a light shell.
|
|
125
122
|
baseClass:
|
|
126
|
-
'flex min-h-8.5 min-w-0 cursor-pointer select-none items-center gap-2.5 rounded-
|
|
127
|
-
'text-compact leading-4 tracking-normal font-normal text-
|
|
128
|
-
'data-[focused]:bg-
|
|
123
|
+
'flex min-h-8.5 min-w-0 cursor-pointer select-none items-center gap-2.5 rounded-context-menu-item px-3 py-1.5 ' +
|
|
124
|
+
'text-compact leading-4 tracking-normal font-normal text-context-menu-fg outline-none ' +
|
|
125
|
+
'data-[focused]:bg-context-menu-hover data-[focused]:font-medium data-[hovered]:bg-context-menu-hover data-[hovered]:font-medium ' +
|
|
129
126
|
'data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45',
|
|
130
127
|
variants: {
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
// (#dc2626) is a light-surface red that fails contrast on #242424.
|
|
136
|
-
destructive: { true: 'text-[#fee2e2] data-[focused]:text-[#fee2e2]' },
|
|
128
|
+
// `context-menu-danger` (#fee2e2), not `danger-light`, which flips to a ~15%
|
|
129
|
+
// translucent red under `[data-theme="dark"]` and would all but vanish here, and
|
|
130
|
+
// not `text-danger`, a light-surface red that fails contrast on the dark panel.
|
|
131
|
+
destructive: { true: 'text-context-menu-danger data-[focused]:text-context-menu-danger' },
|
|
137
132
|
},
|
|
138
133
|
}) as (
|
|
139
134
|
props: React.ComponentProps<typeof RACMenuItem> & { destructive?: boolean },
|
|
140
135
|
) => ReturnType<typeof RACMenuItem>
|
|
141
136
|
|
|
142
|
-
// gs `.panel`: 258px, radius 12px, 8px/6px padding,
|
|
143
|
-
//
|
|
144
|
-
// see the note on MenuItem for why these stay literal rather than becoming tokens.
|
|
137
|
+
// gs `.panel`: 258px (`--dimension-context-menu-width`), radius 12px, 8px/6px padding,
|
|
138
|
+
// the `context-menu-top` to `context-menu-bottom` gradient and `shadow-context-menu`.
|
|
145
139
|
// Constrain/scroll the entire panel, INCLUDING its 8px top/bottom padding —
|
|
146
140
|
// constraining the inner Menu instead makes a long panel exceed the viewport gutter.
|
|
147
141
|
const panelClass =
|
|
148
142
|
'w-[258px] max-w-[calc(100vw-16px)] max-h-[calc(100vh-16px)] box-border overflow-y-auto rounded-xl ' +
|
|
149
|
-
'bg-gradient-to-b from-
|
|
150
|
-
'px-1.5 py-2 shadow-
|
|
143
|
+
'bg-gradient-to-b from-context-menu-top to-context-menu-bottom ' +
|
|
144
|
+
'px-1.5 py-2 shadow-context-menu outline-none'
|
|
151
145
|
// `minmax(0, 1fr)` tracks: an `auto` grid column grows to the items' nowrap
|
|
152
146
|
// min-content, so a long label plus a trailing pill pushed rows past the 258px panel.
|
|
153
147
|
const menuClass = 'grid grid-cols-[minmax(0,1fr)] gap-0.5 outline-none'
|
|
@@ -300,7 +294,7 @@ function ContextMenuBody({
|
|
|
300
294
|
) : null}
|
|
301
295
|
<span className="min-w-0 flex-1 truncate" title={item.title}>{item.label}</span>
|
|
302
296
|
{badge ? (
|
|
303
|
-
<span className="ml-auto inline-flex h-6 items-center justify-center rounded-full bg-
|
|
297
|
+
<span className="ml-auto inline-flex h-6 items-center justify-center rounded-full bg-context-menu-badge-bg px-3 py-0.5 text-micro font-medium leading-5 tracking-tight text-context-menu-badge-fg">
|
|
304
298
|
{badge}
|
|
305
299
|
</span>
|
|
306
300
|
) : null}
|
|
@@ -6,9 +6,9 @@ import type { ReactNode } from 'react'
|
|
|
6
6
|
*
|
|
7
7
|
* The copy is three fragments (`lead` · `emphasis` · `tail`) so a consumer can
|
|
8
8
|
* translate each per-locale while keeping the middle-word highlight. With
|
|
9
|
-
* `mobileHeader`, it adopts the source ExpandableCTA's 99px mobile touch surface
|
|
10
|
-
* `BrandPageHeader`
|
|
11
|
-
*
|
|
9
|
+
* `mobileHeader`, it adopts the source ExpandableCTA's 99px mobile touch surface
|
|
10
|
+
* below `sm`, where `BrandPageHeader` docks it to the safe bottom edge; from `sm`
|
|
11
|
+
* it returns to the regular header density. Presentational only (hard rule #1): every
|
|
12
12
|
* string arrives via props — no i18n, no domain data.
|
|
13
13
|
*
|
|
14
14
|
* a11y NOTE: the background is the FIXED light brand-secondary (#6eddb1) — it does
|
|
@@ -28,7 +28,8 @@ export interface CtaPillProps {
|
|
|
28
28
|
children: ReactNode
|
|
29
29
|
/**
|
|
30
30
|
* Use the source mobile header density (99px minimum height and doubled
|
|
31
|
-
* horizontal content padding)
|
|
31
|
+
* horizontal content padding) below `sm`, matching where `BrandPageHeader`
|
|
32
|
+
* docks the CTA. Positioning stays with `BrandPageHeader`.
|
|
32
33
|
*/
|
|
33
34
|
mobileHeader?: boolean
|
|
34
35
|
}
|
|
@@ -39,7 +40,7 @@ export function CtaPill({ lead, emphasis, tail, children, mobileHeader = false }
|
|
|
39
40
|
className={[
|
|
40
41
|
'flex h-full w-full items-center justify-between gap-nav-x rounded-lg bg-brand-green',
|
|
41
42
|
mobileHeader
|
|
42
|
-
? 'min-h-mobile-cta px-12 py-5 shadow-mobile-cta
|
|
43
|
+
? 'min-h-mobile-cta px-12 py-5 shadow-mobile-cta sm:min-h-16 sm:py-2.75 sm:pr-3 sm:pl-4.5 sm:shadow-none'
|
|
43
44
|
: 'min-h-16 py-2.75 pr-3 pl-4.5',
|
|
44
45
|
].join(' ')}
|
|
45
46
|
>
|
|
@@ -49,8 +49,8 @@ import { uic } from '../utils/uic'
|
|
|
49
49
|
* out, 200ms `cubic-bezier(0.16, 1, 0.3, 1)` (`animate-dropdown-in` / `-out`).
|
|
50
50
|
* (#25: the source grey is 2.10:1 on `surface`; a section label is read, not ornament)
|
|
51
51
|
* · separator `#eceae1` → `border`. The destructive item uses `text-danger`
|
|
52
|
-
* (`#
|
|
53
|
-
* ContextMenu, which needs the lighter
|
|
52
|
+
* (`#d92323`), a light-surface red that reads correctly here (unlike the dark
|
|
53
|
+
* ContextMenu, which needs the lighter `context-menu-danger`).
|
|
54
54
|
*
|
|
55
55
|
* Presentational only (hard rule #1) — no app imports.
|
|
56
56
|
*/
|
|
@@ -39,10 +39,14 @@ function Composed() {
|
|
|
39
39
|
</tr>
|
|
40
40
|
</TableHead>
|
|
41
41
|
<TableBody>
|
|
42
|
-
<TableRow>
|
|
42
|
+
<TableRow onPress={() => {}} aria-label="Open Editor">
|
|
43
43
|
<TableRowHeader>Editor</TableRowHeader>
|
|
44
44
|
<TableCell align="right">4</TableCell>
|
|
45
45
|
</TableRow>
|
|
46
|
+
<TableRow>
|
|
47
|
+
<TableRowHeader>Viewer</TableRowHeader>
|
|
48
|
+
<TableCell align="right">12</TableCell>
|
|
49
|
+
</TableRow>
|
|
46
50
|
</TableBody>
|
|
47
51
|
</TableRoot>
|
|
48
52
|
</TableScroll>
|
package/src/components/table.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState, type CSSProperties, type HTMLAttributes, type ReactNode, type ThHTMLAttributes } from 'react'
|
|
1
|
+
import { useMemo, useState, type ComponentProps, type CSSProperties, type HTMLAttributes, type ReactNode, type ThHTMLAttributes } from 'react'
|
|
2
2
|
import { uic } from '../utils/uic'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -39,8 +39,7 @@ export const TableHead = uic('thead', { displayName: 'TableHead', baseClass: 'bo
|
|
|
39
39
|
|
|
40
40
|
export const TableBody = uic('tbody', { displayName: 'TableBody' })
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
export const TableRow = uic('tr', {
|
|
42
|
+
const TableRowBase = uic('tr', {
|
|
44
43
|
displayName: 'TableRow',
|
|
45
44
|
baseClass: 'border-b border-border-muted outline-none last:border-b-0',
|
|
46
45
|
variants: {
|
|
@@ -50,6 +49,41 @@ export const TableRow = uic('tr', {
|
|
|
50
49
|
},
|
|
51
50
|
})
|
|
52
51
|
|
|
52
|
+
export type TableRowProps = ComponentProps<typeof TableRowBase> & {
|
|
53
|
+
/**
|
|
54
|
+
* Makes the whole row one pressable control: pointer, hover fill, inset focus ring,
|
|
55
|
+
* `tabIndex={0}`, `role="button"` and Enter/Space activation. Name it with
|
|
56
|
+
* `aria-label`, since the button role hides the cells from assistive tech.
|
|
57
|
+
*/
|
|
58
|
+
onPress?: () => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A body row. `onPress` turns it into a pressable row; without it the row is plain. */
|
|
62
|
+
export function TableRow({ onPress, onClick, onKeyDown, ...rest }: TableRowProps) {
|
|
63
|
+
if (!onPress) return <TableRowBase onClick={onClick} onKeyDown={onKeyDown} {...rest} />
|
|
64
|
+
return (
|
|
65
|
+
<TableRowBase
|
|
66
|
+
tabIndex={0}
|
|
67
|
+
role="button"
|
|
68
|
+
{...rest}
|
|
69
|
+
interactive
|
|
70
|
+
onClick={(event) => {
|
|
71
|
+
onClick?.(event)
|
|
72
|
+
if (!event.defaultPrevented) onPress()
|
|
73
|
+
}}
|
|
74
|
+
onKeyDown={(event) => {
|
|
75
|
+
onKeyDown?.(event)
|
|
76
|
+
// Keys pressed in a control inside the row belong to that control.
|
|
77
|
+
if (event.defaultPrevented || event.target !== event.currentTarget) return
|
|
78
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
79
|
+
event.preventDefault()
|
|
80
|
+
onPress()
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
53
87
|
/** A column header cell: mono label in the muted ink. A row's own header is `TableRowHeader`. */
|
|
54
88
|
export const TableHeaderCell = uic('th', {
|
|
55
89
|
displayName: 'TableHeaderCell',
|
|
@@ -256,25 +290,7 @@ export function Table<Row>({
|
|
|
256
290
|
sorted.map((row, index) => {
|
|
257
291
|
const rowProps = getRowProps?.(row)
|
|
258
292
|
return (
|
|
259
|
-
<TableRow
|
|
260
|
-
key={rowKey(row, index)}
|
|
261
|
-
{...rowProps}
|
|
262
|
-
interactive={interactive}
|
|
263
|
-
{...(interactive
|
|
264
|
-
? {
|
|
265
|
-
// A pressable row is one control; callers name it via `getRowProps` (`aria-label`).
|
|
266
|
-
tabIndex: 0,
|
|
267
|
-
role: 'button',
|
|
268
|
-
onClick: () => onRowClick?.(row),
|
|
269
|
-
onKeyDown: (event: React.KeyboardEvent) => {
|
|
270
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
271
|
-
event.preventDefault()
|
|
272
|
-
onRowClick?.(row)
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
}
|
|
276
|
-
: {})}
|
|
277
|
-
>
|
|
293
|
+
<TableRow key={rowKey(row, index)} {...rowProps} onPress={interactive ? () => onRowClick?.(row) : undefined}>
|
|
278
294
|
{columns.map((column) => (
|
|
279
295
|
<TableCell key={column.key} align={column.align ?? 'left'}>
|
|
280
296
|
{column.render ? column.render(row) : String(defaultSortValue(column, row))}
|
|
@@ -30,9 +30,9 @@ import { SAFE_LINK_HINT, safeLinkUrl } from '../utils/safe-link-url'
|
|
|
30
30
|
*
|
|
31
31
|
* Notion features: `/` slash menu (self-contained — insert paragraph/heading/list/
|
|
32
32
|
* to-do/quote/code/divider), an inline bubble toolbar (bold/italic/strike/highlight/
|
|
33
|
-
* code/link), and StarterKit's markdown input rules.
|
|
34
|
-
* typography` (`prose`), which @podoba/tailwind already
|
|
35
|
-
* so it flips under `[data-theme="dark"]`.
|
|
33
|
+
* code/link, then bulleted/numbered list), and StarterKit's markdown input rules.
|
|
34
|
+
* Styling rides `@tailwindcss/typography` (`prose`), which @podoba/tailwind already
|
|
35
|
+
* registers, plus design tokens so it flips under `[data-theme="dark"]`.
|
|
36
36
|
*
|
|
37
37
|
* Prefer this over {@link ../components/rich-text-editor RichTextEditor} for
|
|
38
38
|
* document-shaped content; the dependency-free contentEditable one stays the right
|
|
@@ -64,6 +64,15 @@ type SlashCommand = {
|
|
|
64
64
|
run: (editor: Editor) => void
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// List toggles shared by the `/` palette and the bubble toolbar, so a title or command
|
|
68
|
+
// change lands in both. Keys are the Tiptap node names the toolbar's active state reads.
|
|
69
|
+
const LIST_COMMANDS = {
|
|
70
|
+
bulletList: { title: 'Bulleted list', run: (e: Editor) => e.chain().focus().toggleBulletList().run() },
|
|
71
|
+
orderedList: { title: 'Numbered list', run: (e: Editor) => e.chain().focus().toggleOrderedList().run() },
|
|
72
|
+
} as const
|
|
73
|
+
|
|
74
|
+
type ListKind = keyof typeof LIST_COMMANDS
|
|
75
|
+
|
|
67
76
|
// The `/` block palette. Kept generic (no domain blocks) — a CMS/app composes richer
|
|
68
77
|
// block types around this at the document level; this is the text-block vocabulary.
|
|
69
78
|
const SLASH_COMMANDS: readonly SlashCommand[] = [
|
|
@@ -71,8 +80,8 @@ const SLASH_COMMANDS: readonly SlashCommand[] = [
|
|
|
71
80
|
{ title: 'Heading 1', hint: 'Big section heading', keywords: ['h1', 'heading', 'title'], run: (e) => e.chain().focus().toggleHeading({ level: 1 }).run() },
|
|
72
81
|
{ title: 'Heading 2', hint: 'Medium heading', keywords: ['h2', 'subheading'], run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run() },
|
|
73
82
|
{ title: 'Heading 3', hint: 'Small heading', keywords: ['h3'], run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run() },
|
|
74
|
-
{
|
|
75
|
-
{
|
|
83
|
+
{ ...LIST_COMMANDS.bulletList, hint: 'Unordered list', keywords: ['bullet', 'unordered', 'ul', 'list'] },
|
|
84
|
+
{ ...LIST_COMMANDS.orderedList, hint: 'Ordered list', keywords: ['numbered', 'ordered', 'ol', 'list'] },
|
|
76
85
|
{ title: 'To-do list', hint: 'Checklist', keywords: ['todo', 'task', 'checkbox', 'check'], run: (e) => e.chain().focus().toggleTaskList().run() },
|
|
77
86
|
{ title: 'Quote', hint: 'Block quote', keywords: ['quote', 'blockquote', 'citation'], run: (e) => e.chain().focus().toggleBlockquote().run() },
|
|
78
87
|
{ title: 'Code', hint: 'Code block', keywords: ['code', 'snippet', 'pre'], run: (e) => e.chain().focus().toggleCodeBlock().run() },
|
|
@@ -135,7 +144,7 @@ export function canOpenSlash(state: EditorState, from: number): boolean {
|
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
const btn =
|
|
138
|
-
'inline-flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-md px-2 text-small text-fg-muted transition-colors hover:bg-surface-muted hover:text-fg data-[active=true]:bg-surface-muted data-[active=true]:text-fg'
|
|
147
|
+
'inline-flex h-8 min-w-8 cursor-pointer items-center justify-center rounded-md px-2 text-small text-fg-muted transition-colors enabled:hover:bg-surface-muted enabled:hover:text-fg disabled:cursor-default disabled:opacity-50 data-[active=true]:bg-surface-muted data-[active=true]:text-fg'
|
|
139
148
|
|
|
140
149
|
/** Marks the bubble toolbar toggles. `active` keys read off the useEditorState
|
|
141
150
|
* snapshot below — Tiptap 3 does NOT re-render on transactions, so a plain
|
|
@@ -148,6 +157,82 @@ const MARK_TOOLS = [
|
|
|
148
157
|
{ key: 'code', title: 'Inline code', label: '</>', run: (e: Editor) => e.chain().focus().toggleCode().run() },
|
|
149
158
|
] as const
|
|
150
159
|
|
|
160
|
+
const BulletListIcon = () => (
|
|
161
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
|
162
|
+
<path d="M9 6h11M9 12h11M9 18h11" />
|
|
163
|
+
<circle cx="4" cy="6" r="1" fill="currentColor" />
|
|
164
|
+
<circle cx="4" cy="12" r="1" fill="currentColor" />
|
|
165
|
+
<circle cx="4" cy="18" r="1" fill="currentColor" />
|
|
166
|
+
</svg>
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
const OrderedListIcon = () => (
|
|
170
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
|
171
|
+
<path d="M10 6h10M10 12h10M10 18h10" />
|
|
172
|
+
<path d="M4 4h1v4M4 8h2" />
|
|
173
|
+
<path d="M4 14.5a1 1 0 0 1 2 0c0 .8-2 1.5-2 3.5h2" />
|
|
174
|
+
</svg>
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
/** Block toggles in the bubble toolbar, after the marks. Lists were reachable only
|
|
178
|
+
* through the `/` palette (or markdown input rules), which nobody finds from a
|
|
179
|
+
* selection: someone who selects three lines to make them a list looks at the
|
|
180
|
+
* toolbar, and it had nothing for them. Exported for tests. */
|
|
181
|
+
export const BLOCK_TOOLS = [
|
|
182
|
+
{ key: 'bulletList', ...LIST_COMMANDS.bulletList, label: <BulletListIcon /> },
|
|
183
|
+
{ key: 'orderedList', ...LIST_COMMANDS.orderedList, label: <OrderedListIcon /> },
|
|
184
|
+
] as const
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The list the selection sits directly in. In a bulleted sublist inside a numbered
|
|
188
|
+
* list only the bullet tool reads as pressed, because that is the list a click on it
|
|
189
|
+
* turns off; `isActive` would report both. A to-do list in between ends the search.
|
|
190
|
+
*/
|
|
191
|
+
export function innermostList(state: EditorState): ListKind | null {
|
|
192
|
+
const { $from } = state.selection
|
|
193
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
194
|
+
const name = $from.node(depth).type.name
|
|
195
|
+
if (name === 'bulletList' || name === 'orderedList') return name
|
|
196
|
+
if (name === 'taskList') return null
|
|
197
|
+
}
|
|
198
|
+
return null
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Lists wrap paragraphs only. From a heading or code block Tiptap's toggleList clears
|
|
203
|
+
* the block to a paragraph first, silently dropping the heading level or the code, so
|
|
204
|
+
* the toolbar disables the list tools while the selection touches one.
|
|
205
|
+
*/
|
|
206
|
+
export function canToggleList(state: EditorState): boolean {
|
|
207
|
+
const { from, to, $from } = state.selection
|
|
208
|
+
if ($from.parent.isTextblock && $from.parent.type.name !== 'paragraph') return false
|
|
209
|
+
let ok = true
|
|
210
|
+
state.doc.nodesBetween(from, to, (node) => {
|
|
211
|
+
if (node.isTextblock && node.type.name !== 'paragraph') ok = false
|
|
212
|
+
return ok
|
|
213
|
+
})
|
|
214
|
+
return ok
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** One bubble-toolbar button. preventDefault on mousedown keeps the editor selection while it is clicked. */
|
|
218
|
+
function ToolButton({ title, active, disabled, onPress, children }: { title: string; active: boolean; disabled?: boolean; onPress: () => void; children: ReactNode }) {
|
|
219
|
+
return (
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
className={btn}
|
|
223
|
+
data-active={active}
|
|
224
|
+
aria-pressed={active}
|
|
225
|
+
disabled={disabled}
|
|
226
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
227
|
+
onClick={onPress}
|
|
228
|
+
title={title}
|
|
229
|
+
aria-label={title}
|
|
230
|
+
>
|
|
231
|
+
{children}
|
|
232
|
+
</button>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
151
236
|
const LinkIcon = () => (
|
|
152
237
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
|
153
238
|
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />
|
|
@@ -387,6 +472,8 @@ export function BlockEditor({ value, onChange, placeholder = "Write, or press '/
|
|
|
387
472
|
highlight: editor.isActive('highlight'),
|
|
388
473
|
code: editor.isActive('code'),
|
|
389
474
|
link: editor.isActive('link'),
|
|
475
|
+
list: innermostList(editor.state),
|
|
476
|
+
canToggleList: canToggleList(editor.state),
|
|
390
477
|
hasSelection: !editor.state.selection.empty,
|
|
391
478
|
}
|
|
392
479
|
: null,
|
|
@@ -497,23 +584,25 @@ export function BlockEditor({ value, onChange, placeholder = "Write, or press '/
|
|
|
497
584
|
) : (
|
|
498
585
|
<div className="flex items-center gap-0.5">
|
|
499
586
|
{MARK_TOOLS.map((tool) => (
|
|
500
|
-
|
|
501
|
-
|
|
587
|
+
<ToolButton key={tool.key} title={tool.title} active={active?.[tool.key] ?? false} onPress={() => tool.run(editor)}>
|
|
588
|
+
{tool.label}
|
|
589
|
+
</ToolButton>
|
|
590
|
+
))}
|
|
591
|
+
<ToolButton title="Link" active={active?.link ?? false} onPress={openLink}>
|
|
592
|
+
<LinkIcon />
|
|
593
|
+
</ToolButton>
|
|
594
|
+
<span aria-hidden="true" className="mx-0.5 h-5 w-px bg-border" />
|
|
595
|
+
{BLOCK_TOOLS.map((tool) => (
|
|
596
|
+
<ToolButton
|
|
502
597
|
key={tool.key}
|
|
503
|
-
type="button"
|
|
504
|
-
className={btn}
|
|
505
|
-
data-active={active?.[tool.key] ?? false}
|
|
506
|
-
aria-pressed={active?.[tool.key] ?? false}
|
|
507
|
-
onMouseDown={(e) => e.preventDefault()}
|
|
508
|
-
onClick={() => tool.run(editor)}
|
|
509
598
|
title={tool.title}
|
|
599
|
+
active={active?.list === tool.key}
|
|
600
|
+
disabled={!(active?.canToggleList ?? true)}
|
|
601
|
+
onPress={() => tool.run(editor)}
|
|
510
602
|
>
|
|
511
603
|
{tool.label}
|
|
512
|
-
</
|
|
604
|
+
</ToolButton>
|
|
513
605
|
))}
|
|
514
|
-
<button type="button" className={btn} data-active={active?.link ?? false} aria-pressed={active?.link ?? false} onMouseDown={(e) => e.preventDefault()} onClick={openLink} title="Link">
|
|
515
|
-
<LinkIcon />
|
|
516
|
-
</button>
|
|
517
606
|
</div>
|
|
518
607
|
)}
|
|
519
608
|
</BubbleMenu>
|
package/src/utils/uic.ts
CHANGED
|
@@ -67,6 +67,8 @@ const twMerge = extendTailwindMerge({
|
|
|
67
67
|
'display',
|
|
68
68
|
'display-large',
|
|
69
69
|
'panel-heading',
|
|
70
|
+
'document-display',
|
|
71
|
+
'document-lead',
|
|
70
72
|
// Heading ramp (size + line-height).
|
|
71
73
|
'heading1',
|
|
72
74
|
'heading2',
|
|
@@ -78,15 +80,15 @@ const twMerge = extendTailwindMerge({
|
|
|
78
80
|
],
|
|
79
81
|
},
|
|
80
82
|
theme: {
|
|
81
|
-
spacing: ['nav-x', 'control-tall'],
|
|
83
|
+
spacing: ['nav-x', 'control-tall', 'mobile-cta', 'mobile-cta-bottom', 'mobile-cta-dock'],
|
|
82
84
|
// Custom card/panel radius key (rounded-panel) → dedupes against other
|
|
83
85
|
// rounded-* utilities. xl/2xl are stock keys tailwind-merge already knows.
|
|
84
|
-
radius: ['panel'],
|
|
86
|
+
radius: ['panel', 'context-menu-item'],
|
|
85
87
|
// Custom blur/shadow keys, so `backdrop-blur-modal-backdrop` dedupes against
|
|
86
88
|
// a caller's `backdrop-blur-lg` (Dialog size="full" does exactly this) and
|
|
87
89
|
// `shadow-modal-surface` isn't misread as a shadow COLOR.
|
|
88
90
|
blur: ['modal-backdrop'],
|
|
89
|
-
shadow: ['modal-surface'],
|
|
91
|
+
shadow: ['modal-surface', 'context-menu', 'action-compact-hover'],
|
|
90
92
|
},
|
|
91
93
|
},
|
|
92
94
|
})
|