@estiva-app/ui 0.91.2 → 0.92.1

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.
Files changed (106) hide show
  1. package/dist/AppProvider.d.ts +7 -3
  2. package/dist/AppProvider.d.ts.map +1 -1
  3. package/dist/AttachedCard.d.ts +5 -1
  4. package/dist/AttachedCard.d.ts.map +1 -1
  5. package/dist/BlockNodes.d.ts +14 -1
  6. package/dist/BlockNodes.d.ts.map +1 -1
  7. package/dist/Button.d.ts +11 -1
  8. package/dist/Button.d.ts.map +1 -1
  9. package/dist/CommentBox.d.ts +9 -2
  10. package/dist/CommentBox.d.ts.map +1 -1
  11. package/dist/ComposerTriggers.d.ts +11 -2
  12. package/dist/ComposerTriggers.d.ts.map +1 -1
  13. package/dist/DocumentEditor.d.ts.map +1 -1
  14. package/dist/LinkCard.d.ts.map +1 -1
  15. package/dist/LinkChip.d.ts.map +1 -1
  16. package/dist/LinkChips.d.ts +2 -1
  17. package/dist/LinkChips.d.ts.map +1 -1
  18. package/dist/LinkParts.d.ts +6 -1
  19. package/dist/LinkParts.d.ts.map +1 -1
  20. package/dist/LinkPlaces.d.ts +7 -0
  21. package/dist/LinkPlaces.d.ts.map +1 -1
  22. package/dist/LinkRow.d.ts +29 -6
  23. package/dist/LinkRow.d.ts.map +1 -1
  24. package/dist/PartCard.d.ts +9 -2
  25. package/dist/PartCard.d.ts.map +1 -1
  26. package/dist/ReferenceCards.d.ts +9 -39
  27. package/dist/ReferenceCards.d.ts.map +1 -1
  28. package/dist/ReferenceMenu.d.ts.map +1 -1
  29. package/dist/editor.d.ts +1 -1
  30. package/dist/editor.d.ts.map +1 -1
  31. package/dist/editor.js +204 -183
  32. package/dist/editor.js.map +3 -3
  33. package/dist/index.d.ts +2 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +211 -97
  36. package/dist/index.js.map +3 -3
  37. package/dist/linked.d.ts +48 -3
  38. package/dist/linked.d.ts.map +1 -1
  39. package/dist/linked.examples.d.ts +6 -0
  40. package/dist/linked.examples.d.ts.map +1 -1
  41. package/dist/linkedFrom.d.ts +7 -3
  42. package/dist/linkedFrom.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/registry.json +65 -56
  45. package/src/AppProvider.mdx +7 -5
  46. package/src/AppProvider.test.tsx +15 -1
  47. package/src/AppProvider.tsx +13 -4
  48. package/src/AttachedCard.mdx +2 -1
  49. package/src/AttachedCard.test.tsx +28 -0
  50. package/src/AttachedCard.tsx +12 -2
  51. package/src/BlockNodes.mdx +8 -1
  52. package/src/BlockNodes.tsx +98 -11
  53. package/src/Button.mdx +25 -3
  54. package/src/Button.stories.tsx +15 -1
  55. package/src/Button.test.tsx +33 -0
  56. package/src/Button.tsx +65 -49
  57. package/src/CommentBox.mdx +8 -2
  58. package/src/CommentBox.stories.tsx +28 -1
  59. package/src/CommentBox.test.tsx +64 -1
  60. package/src/CommentBox.tsx +44 -5
  61. package/src/ComposerTriggers.mdx +1 -0
  62. package/src/ComposerTriggers.tsx +34 -15
  63. package/src/DocumentEditor.mdx +1 -1
  64. package/src/DocumentEditor.stories.tsx +2 -2
  65. package/src/DocumentEditor.test.tsx +37 -7
  66. package/src/DocumentEditor.tsx +2 -1
  67. package/src/LinkCard.mdx +9 -5
  68. package/src/LinkCard.stories.tsx +17 -2
  69. package/src/LinkCard.test.tsx +21 -0
  70. package/src/LinkCard.tsx +35 -16
  71. package/src/LinkChip.mdx +6 -1
  72. package/src/LinkChip.stories.tsx +7 -1
  73. package/src/LinkChip.test.tsx +12 -0
  74. package/src/LinkChip.tsx +6 -2
  75. package/src/LinkChips.mdx +4 -3
  76. package/src/LinkChips.stories.tsx +2 -2
  77. package/src/LinkChips.test.tsx +1 -2
  78. package/src/LinkChips.ts +2 -1
  79. package/src/LinkParts.mdx +3 -2
  80. package/src/LinkParts.stories.tsx +8 -0
  81. package/src/LinkParts.tsx +40 -6
  82. package/src/LinkPlaces.mdx +3 -0
  83. package/src/LinkPlaces.ts +19 -0
  84. package/src/LinkRow.mdx +8 -2
  85. package/src/LinkRow.stories.tsx +14 -2
  86. package/src/LinkRow.test.tsx +31 -1
  87. package/src/LinkRow.tsx +69 -25
  88. package/src/PartCard.mdx +9 -1
  89. package/src/PartCard.stories.tsx +9 -0
  90. package/src/PartCard.test.tsx +13 -0
  91. package/src/PartCard.tsx +19 -5
  92. package/src/ReferenceCards.test.tsx +4 -35
  93. package/src/ReferenceCards.ts +10 -119
  94. package/src/ReferenceMenu.mdx +6 -4
  95. package/src/ReferenceMenu.test.tsx +67 -5
  96. package/src/ReferenceMenu.tsx +18 -7
  97. package/src/editor.ts +0 -3
  98. package/src/index.ts +4 -1
  99. package/src/linked.examples.ts +6 -0
  100. package/src/linked.test.ts +35 -1
  101. package/src/linked.ts +108 -3
  102. package/src/linkedFrom.test.tsx +42 -2
  103. package/src/linkedFrom.ts +15 -7
  104. package/src/registry/registry.test.ts +25 -6
  105. package/src/ReferenceCards.mdx +0 -86
  106. package/src/ReferenceCards.stories.tsx +0 -66
@@ -3,7 +3,7 @@ import { Extension, InputRule, Node, type Editor } from '@tiptap/core'
3
3
  import { DOMSerializer, type Node as ProseMirrorNode, type Slice } from '@tiptap/pm/model'
4
4
  import { Plugin, PluginKey, type EditorState, type Transaction } from '@tiptap/pm/state'
5
5
  import { Mapping, ReplaceAroundStep } from '@tiptap/pm/transform'
6
- import type { EditorView, NodeView } from '@tiptap/pm/view'
6
+ import { Decoration, DecorationSet, type EditorView, type NodeView } from '@tiptap/pm/view'
7
7
  import { NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer, type ReactNodeViewProps } from '@tiptap/react'
8
8
  import { Checkbox, type CheckboxProps } from './Checkbox'
9
9
  import { calloutLook } from './RichText'
@@ -380,7 +380,11 @@ export interface ReferenceViewProps {
380
380
  * editor without `LinkPlaces`.
381
381
  */
382
382
  place?: LinkPlace
383
- /** Being edited: a click opens its menu rather than it, so a row or card shows no hover preview. */
383
+ /**
384
+ * Being edited, so a chip or a row shows no hover preview: a click on it opens its menu, or does nothing in a box
385
+ * being written in. In a box, always while it can be written in; in a document (`editingLine`), only while the
386
+ * caret is on its line, so a link elsewhere on the page previews on hover.
387
+ */
384
388
  editing?: boolean
385
389
  }
386
390
 
@@ -390,6 +394,58 @@ export interface ReferenceNodeOptions {
390
394
  * knows how to resolve it. Without one, the URI is drawn as text.
391
395
  */
392
396
  view: ComponentType<ReferenceViewProps> | null
397
+ /**
398
+ * A link counts as being edited (`editing`) only while the caret is on its
399
+ * line: its textblock, between the hard breaks either side, while the editor
400
+ * has focus. `DocumentEditor` sets it, so a page that is always editable
401
+ * still previews the links its writer is not working on (Katerina, 30 Oct).
402
+ * Off, every link is being edited while the editor is editable, as in a
403
+ * message's box.
404
+ */
405
+ editingLine: boolean
406
+ }
407
+
408
+ /** A card's own controls: a press on one stays theirs, see `keepCardPresses`. */
409
+ const CARD_CONTROLS = 'button, [role="combobox"]'
410
+
411
+ /** What a click in a card goes on to: its links (the title, the count) and its controls. Its empty space opens the menu. */
412
+ const CARD_CLICKS = `a[href], input, select, ${CARD_CONTROLS}`
413
+
414
+ /**
415
+ * ProseMirror sees a press before React does and takes the caret into the
416
+ * text, which closed a card's picker before it opened (Leaf's fix, moved here
417
+ * so every app has it). It leaves alone a press whose default is prevented.
418
+ */
419
+ function keepCardPresses(element: HTMLElement | null): (() => void) | undefined {
420
+ if (!element) return undefined
421
+ const keep = (event: globalThis.MouseEvent) => {
422
+ if (event.target instanceof Element && event.target.closest(CARD_CONTROLS)) event.preventDefault()
423
+ }
424
+ element.addEventListener('mousedown', keep)
425
+ return () => element.removeEventListener('mousedown', keep)
426
+ }
427
+
428
+ /** Every reference on the caret's line: the textblock it is in, between the hard breaks either side of it. */
429
+ function caretLineReferences(state: EditorState): { pos: number; size: number }[] {
430
+ const { $head } = state.selection
431
+ const block = $head.parent
432
+ if (!block.isTextblock) return []
433
+ const start = $head.start()
434
+ const at = $head.parentOffset
435
+ const lines: { from: number; to: number; references: { pos: number; size: number }[] }[] = [{ from: 0, to: block.content.size, references: [] }]
436
+ block.forEach((child, offset) => {
437
+ const line = lines[lines.length - 1]
438
+ if (child.type.name === 'hardBreak') {
439
+ line.to = offset
440
+ lines.push({ from: offset + child.nodeSize, to: block.content.size, references: [] })
441
+ } else if (child.type.name === 'reference') line.references.push({ pos: start + offset, size: child.nodeSize })
442
+ })
443
+ return lines.find((line) => at >= line.from && at <= line.to)?.references ?? []
444
+ }
445
+
446
+ /** Whether a node view's decorations put it on the caret's line. */
447
+ function onCaretLine(decorations: readonly Decoration[] | undefined): boolean {
448
+ return (decorations ?? []).some((decoration) => (decoration.spec as { caretLine?: boolean }).caretLine === true)
393
449
  }
394
450
 
395
451
  /**
@@ -420,7 +476,26 @@ export const ReferenceNode = Node.create<ReferenceNodeOptions>({
420
476
  selectable: true,
421
477
  draggable: false,
422
478
  addOptions() {
423
- return { view: null }
479
+ return { view: null, editingLine: false }
480
+ },
481
+ addProseMirrorPlugins() {
482
+ if (!this.options.editingLine) return []
483
+ const editor = this.editor
484
+ return [
485
+ new Plugin({
486
+ key: new PluginKey('referenceCaretLine'),
487
+ props: {
488
+ // Read on every update, a focus and a blur included (Tiptap sends a transaction for each), so it follows the caret.
489
+ decorations: (state) =>
490
+ editor.isFocused && editor.isEditable
491
+ ? DecorationSet.create(
492
+ state.doc,
493
+ caretLineReferences(state).map(({ pos, size }) => Decoration.node(pos, pos + size, {}, { caretLine: true })),
494
+ )
495
+ : null,
496
+ },
497
+ }),
498
+ ]
424
499
  },
425
500
  addAttributes() {
426
501
  return {
@@ -452,15 +527,19 @@ export const ReferenceNode = Node.create<ReferenceNodeOptions>({
452
527
  addNodeView() {
453
528
  const View = this.options.view
454
529
  if (!View) return null
530
+ const { editingLine } = this.options
455
531
  return ReactNodeViewRenderer(({ node, editor, getPos, decorations }: ReactNodeViewProps) => {
456
532
  const uri = String(node.attrs.uri ?? '')
457
533
  const href = typeof node.attrs.href === 'string' && node.attrs.href ? node.attrs.href : undefined
458
534
  const place = placeOf(decorations)
535
+ const editing = editor.isEditable && (!editingLine || onCaretLine(decorations))
459
536
  return (
460
537
  <NodeViewWrapper
461
538
  as="span"
462
539
  // A row or a card is the whole line.
463
540
  className={place === 'chip' ? 'inline' : 'block w-full'}
541
+ // A card keeps its pickers while the text is edited too (Katerina, 30 Oct): a press on one is not the text's.
542
+ ref={place === 'card' ? keepCardPresses : undefined}
464
543
  // While editing, a click opens the chip's menu (`ReferenceMenu`) rather than following the chip.
465
544
  onClickCapture={(event: MouseEvent) => {
466
545
  // A click in something the view portals out — a picker's list, a hover card — reaches here through React's
@@ -470,21 +549,29 @@ export const ReferenceNode = Node.create<ReferenceNodeOptions>({
470
549
  // (`Node` here is Tiptap's; a click's target is an Element.)
471
550
  const own = editor.view.nodeDOM(pos)
472
551
  if (!(event.target instanceof Element) || !own || !own.contains(event.target)) return
473
- // A card's own controls — its status, its owner — change it from the card, while editing too.
474
- if (place === 'card' && event.target.closest('button, input, select, [role="combobox"]')) return
475
- if (!referenceMenuClick(editor, pos)) return
476
- event.preventDefault()
477
- event.stopPropagation()
552
+ // A card's own links and controls take the click, while editing too: its title opens the file, its count the
553
+ // conversation, its status and owner change it. Only its empty space opens the menu (Katerina, 30 Oct).
554
+ if (place === 'card' && event.target.closest(CARD_CLICKS)) return
555
+ if (referenceMenuClick(editor, pos)) {
556
+ event.preventDefault()
557
+ event.stopPropagation()
558
+ return
559
+ }
560
+ // Being written with no menu to open — a message's box: a click on the link does not leave the draft
561
+ // (Katerina, 30 Oct: a chip in the box does not follow a click).
562
+ if (!editingLine && editor.isEditable && event.target.closest('a[href]')) event.preventDefault()
478
563
  }}
479
564
  >
480
565
  {/* A URL chip not resolved yet reads as the URL it was written as. */}
481
- {uri ? <View uri={uri} {...(href ? { href } : {})} place={place} editing={editor.isEditable} /> : <span>{href}</span>}
566
+ {uri ? <View uri={uri} {...(href ? { href } : {})} place={place} editing={editing} /> : <span>{href}</span>}
482
567
  </NodeViewWrapper>
483
568
  )
484
569
  }, {
485
- // Words typed beside a link leave its node as it was, and Tiptap then skips the redraw; its place has changed (code review).
570
+ // Words typed beside a link leave its node as it was, and Tiptap then skips the redraw; its place has changed (code
571
+ // review), or the caret came onto its line or left it.
486
572
  update: ({ oldNode, newNode, oldDecorations, newDecorations, updateProps }) => {
487
- if (oldNode !== newNode || placeOf(oldDecorations) !== placeOf(newDecorations)) updateProps()
573
+ const moved = placeOf(oldDecorations) !== placeOf(newDecorations) || onCaretLine(oldDecorations) !== onCaretLine(newDecorations)
574
+ if (oldNode !== newNode || moved) updateProps()
488
575
  return true
489
576
  },
490
577
  })
package/src/Button.mdx CHANGED
@@ -28,7 +28,9 @@ The push-button for an action: a verb, clicked once — "Create", "Save",
28
28
 
29
29
  - An icon with no label → **IconButton**.
30
30
  - Going somewhere rather than doing something → **Link**; **Tabs** or
31
- **Breadcrumb** when it is a view or a trail.
31
+ **Breadcrumb** when it is a view or a trail. A way somewhere that must
32
+ stand as a button (the way out to another app) is this Button with
33
+ `href`, still a link.
32
34
  - Choosing a value → **Select**. Acting from a popover list → **MenuItem**.
33
35
  - A control the person may never be allowed to use is **absent, not
34
36
  disabled**. `disabled` is for *momentarily* unavailable — and it says why,
@@ -62,6 +64,26 @@ import { IconPlus } from '@tabler/icons-react'
62
64
  wrapper — what a caller gets is the `<button>`, and a `Menu.Trigger` or
63
65
  a `Dialog.Close` can be it.
64
66
 
67
+ - **A link that looks like a button**: give it `href`. It draws an `<a>`
68
+ with the same look, so a modified click, a new tab and "copy link
69
+ address" work. `external` opens another site or another app in a new
70
+ tab, with `noopener noreferrer`, as Link's does. A link cannot be
71
+ disabled: with `disabled` or `disabledReason` it is the button again,
72
+ and says why.
73
+
74
+ ```tsx
75
+ import { Button, WithTooltip } from '@estiva-app/ui'
76
+ import { IconExternalLink } from '@tabler/icons-react'
77
+
78
+ <WithTooltip label="Open in the app that owns it">
79
+ <Button href={url} external size="small" leadingIcon={<IconExternalLink stroke={1.5} className="size-3.5" />}>
80
+ Open
81
+ </Button>
82
+ </WithTooltip>
83
+ ```
84
+
85
+ <Canvas of={ButtonStories.OpensAnotherApp} />
86
+
65
87
  - `variant="resolve"` is `primary` in every theme but Signal, where it is
66
88
  outlined at rest and green when pointed at — the Resolve button. `IconButton`
67
89
  has the same look.
@@ -75,7 +97,7 @@ It does these by itself. Write none of them around it.
75
97
 
76
98
  | It does | So you never write | Refused when written by hand |
77
99
  |---|---|---|
78
- | Says what it is to assistive technology: a button | `role="button"` | ✓ |
100
+ | Says what it is to assistive technology: a button, or a link with `href` | `role="button"` | ✓ |
79
101
  | Is reachable with Tab, also when it is disabled with a reason | a `tabIndex` | ✓ |
80
102
  | Presses on Enter and Space, and does nothing while disabled | a key handler | |
81
103
  | Keeps its 32px (24px small) in a scrolling column | `shrink-0` | |
@@ -85,7 +107,7 @@ It does these by itself. Write none of them around it.
85
107
  | Key | Does |
86
108
  |---|---|
87
109
  | Tab | Onto the button, also when it is disabled with a reason; never when it is plain `disabled`. |
88
- | Space / Enter | The action. Nothing while disabled. |
110
+ | Space / Enter | The action. Nothing while disabled. With `href`, Enter follows the link, as on any link. |
89
111
 
90
112
  ## Props
91
113
 
@@ -1,5 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { IconPlus } from '@tabler/icons-react'
2
+ import { IconExternalLink, IconPlus } from '@tabler/icons-react'
3
3
  import { Button } from './Button'
4
4
 
5
5
  const meta = {
@@ -86,3 +86,17 @@ export const AllVariants: Story = {
86
86
 
87
87
  /** `resolve`: primary, and in Signal outlined at rest and green when pointed at — Resolve. */
88
88
  export const Resolve: Story = { args: { variant: 'resolve', children: 'Resolve' } }
89
+
90
+ /** With `href` it is a link that looks like a button: Ctrl-click, a new tab and "copy link address" work as on any link. */
91
+ export const AsALink: Story = { args: { href: '#', children: 'Go to the list' } }
92
+
93
+ /**
94
+ * `external`: another site or another app, in a new tab. The small quiet button with the external-link icon is the
95
+ * way out to the app that owns a file; its tooltip names that app.
96
+ */
97
+ export const OpensAnotherApp: Story = {
98
+ args: { href: 'https://example.com', external: true, size: 'small', leadingIcon: <IconExternalLink stroke={1.5} className="size-3.5" />, children: 'Open' },
99
+ }
100
+
101
+ /** A link cannot be disabled: with `disabledReason` (or `disabled`) it draws as the button, and says why. */
102
+ export const ALinkWithAReason: Story = { args: { href: 'https://example.com', external: true, disabledReason: 'Sign in to open it', children: 'Open' } }
@@ -135,4 +135,37 @@ describe('Button', () => {
135
135
  expect(button.getAttribute('data-x')).toBe('y')
136
136
  expect(button.classList.contains('mt-2')).toBe(true)
137
137
  })
138
+
139
+ it('with an address it is a link a person can follow; another app opens in a new tab', () => {
140
+ render(
141
+ <>
142
+ <Button href="/list">Go to the list</Button>
143
+ <Button href="https://example.com/file" external size="small">
144
+ Open
145
+ </Button>
146
+ </>,
147
+ )
148
+ const inPlace = screen.getByRole('link', { name: 'Go to the list' })
149
+ expect(inPlace.getAttribute('href')).toBe('/list')
150
+ expect(inPlace.hasAttribute('target')).toBe(false)
151
+ const out = screen.getByRole('link', { name: 'Open' })
152
+ expect(out.getAttribute('href')).toBe('https://example.com/file')
153
+ expect(out.getAttribute('target')).toBe('_blank')
154
+ expect(out.getAttribute('rel')).toBe('noopener noreferrer')
155
+ expect(screen.queryByRole('button')).toBeNull()
156
+ })
157
+
158
+ it('a link that cannot be followed right now is the button, saying why', async () => {
159
+ const user = userEvent.setup()
160
+ render(
161
+ <Button href="https://example.com/file" external disabledReason="Sign in to open it">
162
+ Open
163
+ </Button>,
164
+ )
165
+ expect(screen.queryByRole('link')).toBeNull()
166
+ const button = screen.getByRole('button', { name: 'Open' })
167
+ expect(button.getAttribute('aria-disabled')).toBe('true')
168
+ await user.hover(button)
169
+ expect((await screen.findByRole('tooltip')).textContent).toBe('Sign in to open it')
170
+ })
138
171
  })
package/src/Button.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ComponentPropsWithRef, ReactNode } from 'react'
2
2
  import { Button as BaseButton } from '@base-ui/react/button'
3
+ import { useInAppClick } from './AppProvider'
3
4
  import { cn } from './cn'
4
5
  import { useFormBusy } from './formBusy'
5
6
  import { TooltipTrigger } from './Tooltip'
@@ -56,6 +57,16 @@ export interface ButtonProps extends ComponentPropsWithRef<'button'> {
56
57
  /** Why the action cannot succeed right now. Disables the button, keeps it
57
58
  * reachable by keyboard, and shows the reason as a tooltip on hover. */
58
59
  disabledReason?: string
60
+ /**
61
+ * A link that looks like a button: an anchor, so the address stays real for a
62
+ * modified click, a new tab or "copy link address", as `IconButton` and `Link`
63
+ * keep it. A router app's `navigate` (AppProvider) moves in place. A link
64
+ * cannot be disabled, so while it would be (`disabled`, `disabledReason`, a
65
+ * busy Form) it is the button (Katerina, 30 October).
66
+ */
67
+ href?: string
68
+ /** With `href`: another site, or another app. Opens in a new tab, with `noopener noreferrer`, as `Link`'s does. */
69
+ external?: boolean
59
70
  children: ReactNode
60
71
  }
61
72
 
@@ -68,59 +79,64 @@ export function Button({
68
79
  disabled,
69
80
  disabledReason,
70
81
  type = 'button',
82
+ href,
83
+ external = false,
71
84
  ...props
72
85
  }: ButtonProps) {
73
86
  const hasLeadingIcon = !!leadingIcon
74
87
  // Inside a busy Form: switched off, and looking it (formBusy.ts).
75
88
  const formBusy = useFormBusy()
76
- const button = (
77
- <BaseButton
78
- type={type}
79
- disabled={disabled || !!disabledReason || formBusy}
80
- focusableWhenDisabled={!!disabledReason}
81
- className={(state) =>
82
- cn(
83
- // No `self-center` here, deliberately — `IconButton` needs it and this
84
- // does not, and the difference is the `h-8` / `h-6` on the next two
85
- // lines. `align-items: stretch` only stretches a child whose cross
86
- // size is `auto`; a Button always states its height, so a stretching
87
- // parent cannot change it. Measured in Chrome on 2026-09-12, in the
88
- // 260px row of Finding 49: 32px with `self-center` and 32px without.
89
- // What the class DID do was override the caller on the other axis —
90
- // in a column it beats the parent's `items-start`, which centred the
91
- // four actions in Ship's `ProjectRail` and the trigger in five of
92
- // this package's own story frames, each of which asks for the top.
93
- // A control does not get to decide where its caller puts it.
94
- 'inline-flex items-center justify-center gap-1 rounded-md transition-colors font-sans font-medium',
95
- size === 'default' && 'h-8 min-h-8 text-btn-default',
96
- size === 'small' && 'h-6 min-h-6 text-btn-small',
97
- // Extra right padding beside a leading icon, for optical balance.
98
- size === 'default' && (hasLeadingIcon ? 'pl-2 pr-3' : 'px-2'),
99
- size === 'small' && (hasLeadingIcon ? 'pl-1.5 pr-2' : 'px-1.5'),
100
- !state.disabled && (variant === 'primary' || variant === 'resolve') && 'bg-accent-primary hover:bg-accent-hover text-text-inverse cursor-pointer signal:font-semibold',
101
- // @estiva-escape(no-copied-look): W2 (Katerina, 24 September: leave alone): an outlined button shares four words with Reaction's pill by coincidence
102
- !state.disabled && variant === 'outlined' && 'border border-border-default hover:bg-bg-hover text-text-primary cursor-pointer',
103
- !state.disabled && variant === 'muted' && 'hover:bg-bg-hover text-text-primary cursor-pointer',
104
- !state.disabled && variant === 'destructive' && 'hover:bg-error-muted text-error-default cursor-pointer',
105
- state.disabled && 'bg-bg-disabled text-text-disabled',
106
- // `pointer-events-none` only where the button is truly out of reach.
107
- // With a `disabledReason` the button IS the tooltip's trigger, and a
108
- // trigger the pointer cannot land on never opens one — Base UI already
109
- // swallows the click (`focusableWhenDisabled` gives `aria-disabled`
110
- // and a prevented `onClick`), so nothing else needs it.
111
- state.disabled && !disabledReason && 'pointer-events-none',
112
- state.disabled && variant === 'outlined' && 'border border-border-default',
113
- // Disabled too, as it always drew.
114
- variant === 'resolve' &&
115
- 'signal:bg-transparent signal:border signal:border-border-default signal:text-text-primary signal:shadow-none signal:hover:bg-success-muted signal:hover:border-success-outline signal:hover:text-success-default signal:transition-colors',
116
- className,
117
- )
118
- }
119
- {...props}
120
- >
121
- {leadingIcon}
122
- {children}
123
- </BaseButton>
124
- )
89
+ const unusable = disabled || !!disabledReason || formBusy
90
+ const anchor = props as unknown as ComponentPropsWithRef<'a'>
91
+ const inApp = useInAppClick(href, anchor.onClick)
92
+ const look = (off: boolean) =>
93
+ cn(
94
+ // No `self-center` here, deliberately — `IconButton` needs it and this
95
+ // does not, and the difference is the `h-8` / `h-6` on the next two
96
+ // lines. `align-items: stretch` only stretches a child whose cross
97
+ // size is `auto`; a Button always states its height, so a stretching
98
+ // parent cannot change it. Measured in Chrome on 2026-09-12, in the
99
+ // 260px row of Finding 49: 32px with `self-center` and 32px without.
100
+ // What the class DID do was override the caller on the other axis —
101
+ // in a column it beats the parent's `items-start`, which centred the
102
+ // four actions in Ship's `ProjectRail` and the trigger in five of
103
+ // this package's own story frames, each of which asks for the top.
104
+ // A control does not get to decide where its caller puts it.
105
+ 'inline-flex items-center justify-center gap-1 rounded-md transition-colors font-sans font-medium',
106
+ size === 'default' && 'h-8 min-h-8 text-btn-default',
107
+ size === 'small' && 'h-6 min-h-6 text-btn-small',
108
+ // Extra right padding beside a leading icon, for optical balance.
109
+ size === 'default' && (hasLeadingIcon ? 'pl-2 pr-3' : 'px-2'),
110
+ size === 'small' && (hasLeadingIcon ? 'pl-1.5 pr-2' : 'px-1.5'),
111
+ !off && (variant === 'primary' || variant === 'resolve') && 'bg-accent-primary hover:bg-accent-hover text-text-inverse cursor-pointer signal:font-semibold',
112
+ // @estiva-escape(no-copied-look): W2 (Katerina, 24 September: leave alone): an outlined button shares four words with Reaction's pill by coincidence
113
+ !off && variant === 'outlined' && 'border border-border-default hover:bg-bg-hover text-text-primary cursor-pointer',
114
+ !off && variant === 'muted' && 'hover:bg-bg-hover text-text-primary cursor-pointer',
115
+ !off && variant === 'destructive' && 'hover:bg-error-muted text-error-default cursor-pointer',
116
+ off && 'bg-bg-disabled text-text-disabled',
117
+ // `pointer-events-none` only where the button is truly out of reach.
118
+ // With a `disabledReason` the button IS the tooltip's trigger, and a
119
+ // trigger the pointer cannot land on never opens one — Base UI already
120
+ // swallows the click (`focusableWhenDisabled` gives `aria-disabled`
121
+ // and a prevented `onClick`), so nothing else needs it.
122
+ off && !disabledReason && 'pointer-events-none',
123
+ off && variant === 'outlined' && 'border border-border-default',
124
+ // Disabled too, as it always drew.
125
+ variant === 'resolve' &&
126
+ 'signal:bg-transparent signal:border signal:border-border-default signal:text-text-primary signal:shadow-none signal:hover:bg-success-muted signal:hover:border-success-outline signal:hover:text-success-default signal:transition-colors',
127
+ className,
128
+ )
129
+ const button =
130
+ href && !unusable ? (
131
+ <a href={href} {...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})} className={look(false)} {...anchor} onClick={inApp}>
132
+ {leadingIcon}
133
+ {children}
134
+ </a>
135
+ ) : (
136
+ <BaseButton type={type} disabled={unusable} focusableWhenDisabled={!!disabledReason} className={(state) => look(state.disabled)} {...props}>
137
+ {leadingIcon}
138
+ {children}
139
+ </BaseButton>
140
+ )
125
141
  return disabledReason ? <TooltipTrigger label={disabledReason}>{button}</TooltipTrigger> : button
126
142
  }
@@ -15,7 +15,8 @@ The one box every app writes a comment, a reply and a line of a conversation in:
15
15
  - `showsAtOnce` when the app shows a send before the relay answers: the box empties at once, and a refusal puts the words back. Without it the box holds the words, shut, until the answer.
16
16
  - `edit` to change something already sent: the same box with Cancel and Save, its keys on the left, and the same selection strip over selected words. Its files can be taken off, and with `upload` and `edit.writesFiles` (the app's save writes them) more added. An app that closes the box as Save is pressed and reopens it on a refusal passes `edit.refused`, which is said under the box as it opens.
17
17
  - `upload` to offer files: the paperclip, `/` → Upload, a pasted picture and a dropped file. The edit box has no paperclip, since it shows only its keys; the other three work there too.
18
- - `under` to show, while something is written, the one card it will be sent with and the live part of each block link. They sit inside the box with the files, on the files' fill; the card's ✕ is a file's, on hover, and its values read as words until it is sent. An edit box shows the card and no part.
18
+ - `under` to show, while something is written, the one card it will be sent with and the live part of each block link. They sit inside the box with the files, on the files' fill; the card's ✕ is a file's, on hover, and its values and links read as words until it is sent, so a click on it never leaves the draft. An edit box shows the card and no part.
19
+ - `referenceView` to draw every link the box holds — a pasted app URL once it names something, a pasted `nostr:` address of a file or a message, and a `[` pick — as the app draws a link, with the kit's **LinkChip**: one chip look in every box. It is told it is being edited, so it shows no preview, and a click on it stays in the draft.
19
20
  - `closed` where nothing can be written (archived, signed out): a line saying why, in the box's place. No greyed box.
20
21
  - `marked` when the app has its own reason for the bar down the text, besides an urgent mention, which always draws it.
21
22
  - `onEditor` when something outside the box writes into it: the app keeps the editor it is handed and inserts into the box last used.
@@ -30,6 +31,8 @@ The one box every app writes a comment, a reply and a line of a conversation in:
30
31
 
31
32
  <Canvas of={CommentBoxStories.WithACard} />
32
33
 
34
+ <Canvas of={CommentBoxStories.WithLinkChips} />
35
+
33
36
  ## When not
34
37
 
35
38
  - Writing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
@@ -68,7 +71,8 @@ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(roo
68
71
  - A send shown at once and refused after its box went away writes the words into its draft instead.
69
72
  - **`under.read` is the app's reading of the draft**: `@estiva-app/conversation`'s `boxReadOf(body, context)` says which file gets the card and which parts show; the app adds its own view of each. Call `under.changed`'s listener when what a link names comes back. `send`'s third argument is `{ card }`, the card still shown, which the app writes with `embedsToSend` (or `embedsToEdit` for `onSave`).
70
73
  - **An edit box's `read` passes `previous: namedBefore(<the message's text>)`**, so only a file the edit names first gets a card. A card the message already has, or one taken off with ✕ before or after sending, never shows again in the edit box, and Save leaves it as it was.
71
- - **A link chip for a pasted app URL** is the app's `LinkChips`, passed in `extensions`.
74
+ - **A link chip for a pasted app URL** is the app's `LinkChips`, passed in `extensions`. A pasted `nostr:` address needs nothing: with a `referenceView`, the box makes it its link itself. A person's (`npub`) stays text; `@` names a person.
75
+ - **`referenceIcon` is optional.** Without it, `[`'s rows wear the kit's icon for the kind each address names (**LinkedIcon**: a message, an issue, a project, a topic, a document, another app's file), and a neutral square for one that names none.
72
76
  - **`keepCommentBoxWarm({ extensions, referenceView })`**, called once as the app starts, builds an editor while the page is idle, and the next empty box given those same `extensions` and `referenceView` (the same objects, in the same order) takes it, so it opens at once. A box opening with a draft or an edit, or with other extensions, builds its own. Keep `extensions` a module constant: a new array per render never matches.
73
77
  - **`onEditor` gets `null` as the box goes**, so a launcher never writes into a box that is gone.
74
78
 
@@ -79,6 +83,8 @@ It does these by itself. Write none of them around it.
79
83
  | It does | So you never write |
80
84
  |---|---|
81
85
  | `@`, `!@`, `[` and `/`, with their lists and chips | the triggers and their extensions |
86
+ | A `[` pick, a pasted link and a pasted `nostr:` address drawn alike, through `referenceView`; none previews while written, and a click on one, or on the card in the box, stays in the draft | a chip of your own for the box, a click guard |
87
+ | `[`'s rows wear the icon of the kind each address names | an icon lookup |
82
88
  | Enter and Ctrl/Cmd+Enter send; Escape cancels an edit | key handlers |
83
89
  | Holding the words until the answer, or showing the send at once | a sending state |
84
90
  | A refusal: the words back, and a line under the box | a toast, or putting text back |
@@ -10,7 +10,8 @@ import type { CaptionedItem, MentionPerson, ReferenceSection, SlashCommand } fro
10
10
  import { InlineChip } from './InlineChip'
11
11
  import { Kbd } from './Kbd'
12
12
  import { LinkCard } from './LinkCard'
13
- import { ITEM, ready } from './linked.examples'
13
+ import { LinkChip } from './LinkChip'
14
+ import { ITEM, ITEM_NO_SUMMARY, ready } from './linked.examples'
14
15
  import { PartCard } from './PartCard'
15
16
  import { RichText } from './RichText'
16
17
 
@@ -302,6 +303,32 @@ export const EditingWithACard: Story = {
302
303
  },
303
304
  }
304
305
 
306
+ /** The app's view of a link the box holds: the kit's chip, with no preview while it is written. */
307
+ const KitChip = ({ uri, editing }: ReferenceViewProps) => <LinkChip link={ready(uri === ITEMS[0].uri ? ITEM : ITEM_NO_SUMMARY)} preview={!editing} />
308
+
309
+ const WITH_LINKS: JSONContent = {
310
+ type: 'doc',
311
+ content: [
312
+ {
313
+ type: 'paragraph',
314
+ content: [
315
+ { type: 'text', text: 'Picked with [: ' },
316
+ { type: 'captionedReference', attrs: { id: ITEMS[0].id, label: 'Label', snippet: 'Item one', uri: ITEMS[0].uri } },
317
+ { type: 'text', text: ' and pasted: ' },
318
+ { type: 'reference', attrs: { uri: ITEMS[1].uri } },
319
+ ],
320
+ },
321
+ ],
322
+ }
323
+
324
+ /**
325
+ * Every link in the box is the kit's chip, through the app's `referenceView`: a
326
+ * `[` pick and a pasted link alike, each with its key, its title cut short and
327
+ * its status as a mark. Neither previews while written, and a click on one
328
+ * stays in the box. Type `[` to pick another.
329
+ */
330
+ export const WithLinkChips: Story = { render: () => <Live start={WITH_LINKS} referenceView={KitChip} /> }
331
+
305
332
  /** An app's own `/` rows, after the kit's: each puts a label at the start of the box, which the app marks. */
306
333
  const OWN_ROWS: SlashCommand[] = ['one', 'two', 'three', 'four', 'five'].map((n) => ({
307
334
  key: `own-${n}`,
@@ -10,8 +10,10 @@ import { cleanup, fireEvent, render, screen, within } from '@testing-library/rea
10
10
  import { Extension, type Editor } from '@tiptap/core'
11
11
  import { Fragment, Slice } from '@tiptap/pm/model'
12
12
  import type { JSONContent } from '@tiptap/react'
13
+ import { encodeNaddr, encodeNevent } from '@estiva-app/protocol'
14
+ import type { ReferenceViewProps } from './BlockNodes'
13
15
  import { CommentBox, commentBoxRows, keepCommentBoxWarm, type BoxUnder, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
14
- import type { MentionPerson } from './ComposerTriggers'
16
+ import type { MentionPerson, ReferenceSection } from './ComposerTriggers'
15
17
 
16
18
  const PEOPLE: MentionPerson[] = [{ id: 'one', name: 'Person one', pubkey: 'b'.repeat(64) }]
17
19
  const INSERT = [commentBoxRows.file, commentBoxRows.mention, commentBoxRows.urgent, commentBoxRows.reference]
@@ -668,6 +670,67 @@ describe('a box built ahead', () => {
668
670
  })
669
671
  })
670
672
 
673
+ describe('a link in the box', () => {
674
+ const ISSUE = `nostr:${encodeNaddr({ kind: 30851, pubkey: 'a'.repeat(64), identifier: 'item-one', relays: [] })}`
675
+ const MESSAGE = `nostr:${encodeNevent({ id: 'e'.repeat(64), relays: [] })}`
676
+ /** The app's view of a link: the kit's chip would be a link to it. */
677
+ const View = ({ uri, editing }: ReferenceViewProps) => (
678
+ <a href={`/o/${uri}`} data-uri={uri} data-editing={String(!!editing)}>
679
+ Linked
680
+ </a>
681
+ )
682
+ const drawn = () => [...document.querySelectorAll('[data-uri]')].map((el) => el.getAttribute('data-uri'))
683
+ const inline = () => ((editorOf().getJSON() as JSONContent).content?.[0].content ?? []).map((n) => n.type)
684
+
685
+ it('draws a [ pick, and a draft opening with one, as the app draws every other link in the box, being edited', async () => {
686
+ render(<Box referenceView={View} />)
687
+ await act(async () => {
688
+ editorOf()
689
+ .chain()
690
+ .focus('end')
691
+ .insertContent([{ type: 'captionedReference', attrs: { id: ISSUE, label: 'Item one', snippet: '', uri: ISSUE } }, { type: 'text', text: ' and ' }, { type: 'reference', attrs: { uri: MESSAGE } }])
692
+ .run()
693
+ })
694
+ expect(drawn()).toEqual([ISSUE, MESSAGE])
695
+ expect([...document.querySelectorAll('[data-editing]')].map((el) => el.getAttribute('data-editing'))).toEqual(['true', 'true'])
696
+ // The caption's own chip is not drawn beside it.
697
+ expect(screen.queryByText('Item one')).toBeNull()
698
+ })
699
+
700
+ it('never leaves the draft for a click on a link in it', async () => {
701
+ render(<Box referenceView={View} />)
702
+ await act(async () => {
703
+ editorOf()
704
+ .chain()
705
+ .focus('end')
706
+ .insertContent([{ type: 'captionedReference', attrs: { id: ISSUE, label: 'Item one', snippet: '', uri: ISSUE } }, { type: 'text', text: ' ' }, { type: 'reference', attrs: { uri: MESSAGE } }])
707
+ .run()
708
+ })
709
+ for (const link of screen.getAllByRole('link', { name: 'Linked' })) expect(fireEvent.click(link)).toBe(false)
710
+ })
711
+
712
+ it('makes a pasted nostr: address of a file or a message its link at once; a person stays text', async () => {
713
+ const PERSON = 'nostr:npub1' + 'q'.repeat(58)
714
+ render(<Box referenceView={View} />)
715
+ await act(async () => {
716
+ editorOf().commands.focus('end')
717
+ editorOf().view.pasteText(`see ${ISSUE} and ${MESSAGE} and ${PERSON}`, new Event('paste') as ClipboardEvent)
718
+ })
719
+ expect(drawn()).toEqual([ISSUE, MESSAGE])
720
+ expect(inline()).toEqual(['text', 'reference', 'text', 'reference', 'text'])
721
+ expect(editorOf().getText()).toContain(PERSON)
722
+ })
723
+
724
+ it('gives a [ row the icon of the kind its address names when the app gives none', async () => {
725
+ const sections: ReferenceSection[] = [{ label: 'Files', items: [{ id: 'one', label: 'Item one', snippet: '', uri: ISSUE }] }]
726
+ render(<Box references={() => sections} />)
727
+ await type(' [')
728
+ const row = within(screen.getByRole('listbox')).getByRole('option')
729
+ expect(row.querySelector('svg')?.getAttribute('class')).toContain('tabler-icon-list-details')
730
+ await press('Escape')
731
+ })
732
+ })
733
+
671
734
  describe('a long draft', () => {
672
735
  const said: JSONContent = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Said before' }] }] }
673
736