@estiva-app/ui 0.91.2 → 0.92.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.
Files changed (100) 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/CommentBox.d.ts +9 -2
  8. package/dist/CommentBox.d.ts.map +1 -1
  9. package/dist/ComposerTriggers.d.ts +11 -2
  10. package/dist/ComposerTriggers.d.ts.map +1 -1
  11. package/dist/DocumentEditor.d.ts.map +1 -1
  12. package/dist/LinkCard.d.ts.map +1 -1
  13. package/dist/LinkChip.d.ts.map +1 -1
  14. package/dist/LinkChips.d.ts +2 -1
  15. package/dist/LinkChips.d.ts.map +1 -1
  16. package/dist/LinkParts.d.ts +6 -1
  17. package/dist/LinkParts.d.ts.map +1 -1
  18. package/dist/LinkPlaces.d.ts +7 -0
  19. package/dist/LinkPlaces.d.ts.map +1 -1
  20. package/dist/LinkRow.d.ts +29 -6
  21. package/dist/LinkRow.d.ts.map +1 -1
  22. package/dist/PartCard.d.ts +9 -2
  23. package/dist/PartCard.d.ts.map +1 -1
  24. package/dist/ReferenceCards.d.ts +9 -39
  25. package/dist/ReferenceCards.d.ts.map +1 -1
  26. package/dist/ReferenceMenu.d.ts.map +1 -1
  27. package/dist/editor.d.ts +1 -1
  28. package/dist/editor.d.ts.map +1 -1
  29. package/dist/editor.js +204 -183
  30. package/dist/editor.js.map +3 -3
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +165 -50
  34. package/dist/index.js.map +3 -3
  35. package/dist/linked.d.ts +48 -3
  36. package/dist/linked.d.ts.map +1 -1
  37. package/dist/linked.examples.d.ts +6 -0
  38. package/dist/linked.examples.d.ts.map +1 -1
  39. package/dist/linkedFrom.d.ts +7 -3
  40. package/dist/linkedFrom.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/registry.json +53 -56
  43. package/src/AppProvider.mdx +7 -5
  44. package/src/AppProvider.test.tsx +15 -1
  45. package/src/AppProvider.tsx +13 -4
  46. package/src/AttachedCard.mdx +2 -1
  47. package/src/AttachedCard.test.tsx +28 -0
  48. package/src/AttachedCard.tsx +12 -2
  49. package/src/BlockNodes.mdx +8 -1
  50. package/src/BlockNodes.tsx +98 -11
  51. package/src/CommentBox.mdx +8 -2
  52. package/src/CommentBox.stories.tsx +28 -1
  53. package/src/CommentBox.test.tsx +64 -1
  54. package/src/CommentBox.tsx +44 -5
  55. package/src/ComposerTriggers.mdx +1 -0
  56. package/src/ComposerTriggers.tsx +34 -15
  57. package/src/DocumentEditor.mdx +1 -1
  58. package/src/DocumentEditor.stories.tsx +2 -2
  59. package/src/DocumentEditor.test.tsx +37 -7
  60. package/src/DocumentEditor.tsx +2 -1
  61. package/src/LinkCard.mdx +9 -5
  62. package/src/LinkCard.stories.tsx +17 -2
  63. package/src/LinkCard.test.tsx +21 -0
  64. package/src/LinkCard.tsx +35 -16
  65. package/src/LinkChip.mdx +6 -1
  66. package/src/LinkChip.stories.tsx +7 -1
  67. package/src/LinkChip.test.tsx +12 -0
  68. package/src/LinkChip.tsx +6 -2
  69. package/src/LinkChips.mdx +4 -3
  70. package/src/LinkChips.stories.tsx +2 -2
  71. package/src/LinkChips.test.tsx +1 -2
  72. package/src/LinkChips.ts +2 -1
  73. package/src/LinkParts.mdx +3 -2
  74. package/src/LinkParts.stories.tsx +8 -0
  75. package/src/LinkParts.tsx +40 -6
  76. package/src/LinkPlaces.mdx +3 -0
  77. package/src/LinkPlaces.ts +19 -0
  78. package/src/LinkRow.mdx +8 -2
  79. package/src/LinkRow.stories.tsx +14 -2
  80. package/src/LinkRow.test.tsx +31 -1
  81. package/src/LinkRow.tsx +69 -25
  82. package/src/PartCard.mdx +9 -1
  83. package/src/PartCard.stories.tsx +9 -0
  84. package/src/PartCard.test.tsx +13 -0
  85. package/src/PartCard.tsx +19 -5
  86. package/src/ReferenceCards.test.tsx +4 -35
  87. package/src/ReferenceCards.ts +10 -119
  88. package/src/ReferenceMenu.mdx +6 -4
  89. package/src/ReferenceMenu.test.tsx +67 -5
  90. package/src/ReferenceMenu.tsx +18 -7
  91. package/src/editor.ts +0 -3
  92. package/src/index.ts +4 -1
  93. package/src/linked.examples.ts +6 -0
  94. package/src/linked.test.ts +35 -1
  95. package/src/linked.ts +108 -3
  96. package/src/linkedFrom.test.tsx +42 -2
  97. package/src/linkedFrom.ts +15 -7
  98. package/src/registry/registry.test.ts +25 -6
  99. package/src/ReferenceCards.mdx +0 -86
  100. package/src/ReferenceCards.stories.tsx +0 -66
@@ -2,7 +2,7 @@
2
2
  /** What the LinkRow page claims, pinned: where the row and its count lead, and when the count shows. */
3
3
  import { cleanup, render, screen } from '@testing-library/react'
4
4
  import { afterEach, describe, expect, it } from 'vitest'
5
- import { ITEM, ITEM_UNREAD, LOADING, PLACE, ready, UNAVAILABLE } from './linked.examples'
5
+ import { DELETED, ITEM, ITEM_UNREAD, LOADING, PLACE, ready, SAID, UNAVAILABLE } from './linked.examples'
6
6
  import { LinkRow } from './LinkRow'
7
7
 
8
8
  afterEach(cleanup)
@@ -35,4 +35,34 @@ describe('LinkRow', () => {
35
35
  render(<LinkRow link={UNAVAILABLE} />)
36
36
  expect(screen.getByText('Issue not available')).toBeTruthy()
37
37
  })
38
+
39
+ it('says its count whole, one comment or several, never the figure run into the noun', () => {
40
+ const { rerender } = render(<LinkRow link={ready({ ...ITEM, conversation: { count: 1, href: '#c' } })} preview={false} />)
41
+ expect(screen.getByRole('link', { name: '1 comment — open the conversation' })).toBeTruthy()
42
+ rerender(<LinkRow link={ready({ ...ITEM, conversation: { count: 3, href: '#c' } })} preview={false} />)
43
+ expect(screen.getByRole('link', { name: '3 comments — open the conversation' })).toBeTruthy()
44
+ rerender(<LinkRow link={ready({ ...ITEM, conversation: { count: 1, href: '#c', noun: 'conversations' } })} preview={false} />)
45
+ expect(screen.getByRole('link', { name: '1 conversation — open the conversation' })).toBeTruthy()
46
+ })
47
+
48
+ it('draws a file with no address to open as words, its title and its count no links', () => {
49
+ const { container } = render(<LinkRow link={ready({ ...ITEM, href: '', conversation: { count: 3, href: '' } })} preview={false} />)
50
+ expect(screen.queryByRole('link')).toBeNull()
51
+ expect(container.querySelector('a')).toBeNull()
52
+ expect(screen.getByText(ITEM.title)).toBeTruthy()
53
+ expect(screen.getByText('3 comments')).toBeTruthy()
54
+ })
55
+
56
+ it('says it was deleted, apart from not available, with no way out', () => {
57
+ render(<LinkRow link={DELETED} />)
58
+ expect(screen.getByText('Issue deleted')).toBeTruthy()
59
+ expect(screen.queryByRole('link')).toBeNull()
60
+ })
61
+
62
+ it('draws a person’s words on one line: the face, the name, the words cut to fit, the time', () => {
63
+ render(<LinkRow link={ready(SAID)} preview={false} />)
64
+ const name = screen.getByRole('link', { name: SAID.author!.name })
65
+ const line = name.parentElement!.parentElement!
66
+ expect(line.textContent).toBe(`${SAID.author!.name}${SAID.body}${SAID.updated}`)
67
+ })
38
68
  })
package/src/LinkRow.tsx CHANGED
@@ -28,25 +28,41 @@ export interface LinkUnavailableProps {
28
28
  openIn?: { app: string; href: string }
29
29
  /** In a card's place: a card's 12px round it. Default a row's. */
30
30
  card?: boolean
31
+ /** Deleted (SPEC §13.6.1): "Issue deleted", and no way out, since there is nothing left to open. */
32
+ deleted?: boolean
31
33
  }
32
34
 
33
35
  /** A row's frame: the tile, the two lines and the marks, 6px round the tile. */
34
36
  const ROW_CLASSES = 'flex items-center gap-3 p-1.5 pr-3'
35
37
 
36
38
  /**
37
- * Not available: deleted, or not this reader's to see, which read the same.
38
- * Drawn as the row or the card it would have been, on the same fill and edge
39
- * (Katerina, 29 Oct: "same styling as the linkcard default"), its words muted.
40
- * The way out stays, since the app it lives in may still open it for you.
39
+ * Not available: not this reader's to see, or deleted, which says so (SPEC
40
+ * §13.6.1: deleted is not not-permitted). Drawn as the row or the card it
41
+ * would have been, on the same fill and edge (Katerina, 29 Oct: "same styling
42
+ * as the linkcard default"), its words muted. The way out stays, since the app
43
+ * it lives in may still open it for you; a deleted one has none.
41
44
  */
42
- export function LinkUnavailable({ kind, noun, openIn, card = false }: LinkUnavailableProps) {
45
+ export function LinkUnavailable({ kind, noun, openIn, card = false, deleted = false }: LinkUnavailableProps) {
46
+ return <UnavailableRow kind={kind} words={`${noun} ${deleted ? 'deleted' : 'not available'}`} openIn={deleted ? undefined : openIn} card={card} />
47
+ }
48
+
49
+ /** The not-available row with the words it is given; `href` makes the words a link (a part that can't be shown opens its whole file). */
50
+ export function UnavailableRow({ kind, words, href, openIn, card = false }: { kind: LinkedKind; words: string; href?: string; openIn?: { app: string; href: string }; card?: boolean }) {
43
51
  const wide = useContext(inTheBox)
44
52
  return (
45
53
  <Card fill={wide ? 'elevated' : 'inset'} className={cn(card ? 'flex items-center gap-3 p-3' : ROW_CLASSES, 'max-w-[480px]')}>
46
54
  <span className={TYPE_TILE_CLASSES}>
47
55
  <LinkedIcon kind={kind} />
48
56
  </span>
49
- <span className="min-w-0 flex-1 truncate text-body-2 text-text-muted">{noun} not available</span>
57
+ <span className="min-w-0 flex-1 truncate text-body-2 text-text-muted">
58
+ {href && !wide ? (
59
+ <Link href={href} variant="quiet">
60
+ {words}
61
+ </Link>
62
+ ) : (
63
+ words
64
+ )}
65
+ </span>
50
66
  {openIn && (
51
67
  <span className="shrink-0 text-caption text-text-secondary">
52
68
  <Link href={openIn.href} variant="quiet" external>
@@ -58,9 +74,23 @@ export function LinkUnavailable({ kind, noun, openIn, card = false }: LinkUnavai
58
74
  )
59
75
  }
60
76
 
61
- /** The line under a row's or a card's title: its key and what it is, then where it lives and when, as far as the app says. */
77
+ /** The line under a row's or a card's title: its key and what it is, whether it is archived, then where it lives and when, as far as the app says. */
62
78
  export function linkMetaOf(linked: Linked, withWhen = false): string {
63
- return [linked.key, kindNounOf(linked), linked.subtitle, withWhen ? linked.updated : undefined].filter(Boolean).join(' · ')
79
+ return [linked.key, kindNounOf(linked), linked.archived ? 'Archived' : undefined, linked.subtitle, withWhen ? linked.updated : undefined].filter(Boolean).join(' · ')
80
+ }
81
+
82
+ /**
83
+ * A link written as a URL that cannot be shown stays that URL, a plain link as
84
+ * a message draws one (SPEC §13.1, C21), in a chip's, a row's or a card's
85
+ * place alike.
86
+ */
87
+ export function WrittenUrl({ url, block = false }: { url: string; block?: boolean }) {
88
+ const link = (
89
+ <Link href={url} external>
90
+ {url}
91
+ </Link>
92
+ )
93
+ return block ? <span className="block min-w-0 truncate text-body-2">{link}</span> : link
64
94
  }
65
95
 
66
96
  export interface LinkRowProps {
@@ -87,35 +117,49 @@ export function LinkRow({ link, preview = true }: LinkRowProps) {
87
117
  </div>
88
118
  )
89
119
  }
90
- if (link.state === 'unavailable') return <LinkUnavailable kind={link.kind} noun={link.noun} openIn={link.openIn} />
120
+ if (link.state === 'unavailable') {
121
+ if (link.url) return <WrittenUrl url={link.url} block />
122
+ return <LinkUnavailable kind={link.kind} noun={link.noun} openIn={link.openIn} deleted={link.deleted} />
123
+ }
91
124
  const { linked } = link
92
125
  const status = chosenOf(linked.status)
93
126
  const owner = chosenOf(linked.owner)
94
127
  const said = linked.kind === 'message' ? linked.author : undefined
95
- const meta = said ? (linked.body ?? '') : linkMetaOf(linked, true) || linked.summary
128
+ const meta = said ? '' : linkMetaOf(linked, true) || linked.summary
96
129
  const row = (
97
130
  <Card fill="inset" hover="hairline" className={cn('relative', ROW_CLASSES, width)}>
98
131
  <LinkTile kind={linked.kind} author={said} />
99
- <span className="flex min-w-0 flex-1 flex-col gap-0.5">
100
- {said ? (
101
- // As a card of words a person wrote: the name, then the time beside it, muted.
102
- <span className="flex min-w-0 items-baseline gap-2">
103
- <span className="contents text-body-2-strong text-text-primary">
104
- <Link href={linked.href} variant="quiet" cover truncate>
132
+ {said ? (
133
+ // Words a person wrote, on one line, as a quote is cut to one (Katerina, 30 Oct): the face, the name, the words
134
+ // cut to fit, the time.
135
+ <span className="flex min-w-0 flex-1 items-baseline gap-2">
136
+ <span className="contents text-body-2-strong text-text-primary">
137
+ {linked.href ? (
138
+ <Link href={linked.href} variant="quiet" cover truncate className="min-w-0">
105
139
  {said.name}
106
140
  </Link>
107
- </span>
108
- {linked.updated && <span className={cn('shrink-0 text-caption text-text-muted', TIME_CLASSES)}>{linked.updated}</span>}
141
+ ) : (
142
+ <span className="min-w-0 truncate">{said.name}</span>
143
+ )}
109
144
  </span>
110
- ) : (
145
+ {linked.body && <span className="min-w-0 flex-1 truncate text-caption text-text-secondary">{linked.body}</span>}
146
+ {linked.updated && <span className={cn('ml-auto shrink-0 text-caption text-text-muted', TIME_CLASSES)}>{linked.updated}</span>}
147
+ </span>
148
+ ) : (
149
+ <span className="flex min-w-0 flex-1 flex-col gap-0.5">
111
150
  <span className="contents text-body-2-strong text-text-primary">
112
- <Link href={linked.href} variant="quiet" cover truncate>
113
- {linked.title}
114
- </Link>
151
+ {/* Another app's file with no address to open (none over https): its title is words, not a link to nowhere. */}
152
+ {linked.href ? (
153
+ <Link href={linked.href} variant="quiet" cover truncate>
154
+ {linked.title}
155
+ </Link>
156
+ ) : (
157
+ <span className="truncate">{linked.title}</span>
158
+ )}
115
159
  </span>
116
- )}
117
- {meta && <span className="truncate text-caption text-text-secondary">{meta}</span>}
118
- </span>
160
+ {meta && <span className="truncate text-caption text-text-secondary">{meta}</span>}
161
+ </span>
162
+ )}
119
163
  {/* On the title's line, not halfway down the row: the state, the comments, then the faces at the far right. */}
120
164
  <span className="flex h-[19.6px] shrink-0 items-center gap-2 self-start">
121
165
  {/* A ring already says how far along it is. */}
package/src/PartCard.mdx CHANGED
@@ -14,7 +14,15 @@ A part of something longer, shared live: its blocks as they are now, under the t
14
14
  - **ready** — what it is part of, as a card starts: its kind in a file's 36px tile, its title as the link, and "A part of ABC-2" under it; then the blocks the app draws as `children`, behind a quote bar that starts where the tile does. The apps draw the blocks with **RichText** `size="small"`.
15
15
  - **with its way out** — `action`, a small `Button` ("Open in Leaf"), under the blocks at the right, outside the quote bar; with `maxHeight` a long part is cut behind Show more, the two level on one row.
16
16
  - **loading** — at a card's height.
17
- - **unavailable** — one row: "A part of this issue not available", in the app's word for it, else its kind's.
17
+ - **unavailable** — one row: "A part of this issue not available", in the app's word for it, else its kind's. Not the reader's to see.
18
+ - **deleted** — what it is part of was deleted, as a trusted deletion naming it says (SPEC §13.6.1): the same row, "A part of this issue deleted".
19
+ - **detached** — what it is part of is still there and the part's block is gone: the same row, "This part was deleted".
20
+ - **unaddressable** — what it is part of has no blocks to take a part of: the same row, "This part can't be shown", its words opening the whole of it (`href`). Nothing was deleted.
21
+
22
+ The five are SPEC §13.6.1's, with its words; a reader tells them apart.
23
+
24
+ <Canvas of={PartCardStories.Detached} />
25
+ <Canvas of={PartCardStories.Unaddressable} />
18
26
 
19
27
  ## When not
20
28
 
@@ -60,3 +60,12 @@ export const Loading: Story = { args: { state: 'loading', kind: 'issue' } }
60
60
 
61
61
  /** The part, or what it is part of, is gone or not this reader's to see. */
62
62
  export const NotAvailable: Story = { args: { state: 'unavailable', kind: 'issue', noun: 'Issue', openIn: { app: 'App one', href: '#elsewhere' } } }
63
+
64
+ /** What it is part of was deleted, as a trusted deletion naming it says: no title. */
65
+ export const Deleted: Story = { args: { state: 'deleted', kind: 'issue', noun: 'Issue' } }
66
+
67
+ /** What it is part of is still there, and the part's block is gone. */
68
+ export const Detached: Story = { args: { state: 'detached', kind: 'issue', heading: 'Item one' } }
69
+
70
+ /** What it is part of has no blocks to show a part of: the words open the whole of it. */
71
+ export const Unaddressable: Story = { args: { state: 'unaddressable', kind: 'file', heading: 'Item one', href: '#whole' } }
@@ -24,6 +24,19 @@ describe('PartCard', () => {
24
24
  expect(screen.getByText('A part of this issue not available')).toBeTruthy()
25
25
  })
26
26
 
27
+ it('says what became of a part in the SPEC’s words: deleted with its file, its block deleted, or no part to show', () => {
28
+ render(<PartCard state="deleted" kind="issue" noun="Issue" />)
29
+ expect(screen.getByText('A part of this issue deleted')).toBeTruthy()
30
+ cleanup()
31
+ render(<PartCard state="detached" kind="issue" heading="Item one" href="#part" />)
32
+ expect(screen.getByText('This part was deleted')).toBeTruthy()
33
+ expect(screen.queryByRole('link')).toBeNull()
34
+ cleanup()
35
+ // What it is part of has no blocks: the words open the whole of it.
36
+ render(<PartCard state="unaddressable" kind="file" heading="Item one" href="#whole" />)
37
+ expect(screen.getByRole('link', { name: "This part can't be shown" }).getAttribute('href')).toBe('#whole')
38
+ })
39
+
27
40
  it('while it loads, is busy and shows nothing of it', () => {
28
41
  const { container } = render(<PartCard state="loading" kind="issue" />)
29
42
  expect(container.querySelector('[aria-busy="true"]')).not.toBeNull()
package/src/PartCard.tsx CHANGED
@@ -16,18 +16,26 @@ import { Link } from './Link'
16
16
  import { LinkCardLoading } from './LinkCard'
17
17
  import { inTheBox, type LinkedKind } from './linked'
18
18
  import { kindNounOf, LinkTile } from './LinkParts'
19
- import { LinkUnavailable } from './LinkRow'
19
+ import { LinkUnavailable, UnavailableRow } from './LinkRow'
20
20
  import { QUOTE_BAR_CLASSES } from './looks'
21
21
  import { ShowMore } from './ShowMore'
22
22
 
23
+ /**
24
+ * Where a part's lookup stands, SPEC §13.6.1's five states and loading:
25
+ * `ready` (resolved), `unaddressable` (what it is part of has no blocks),
26
+ * `detached` (readable, its block gone), `deleted` (a trusted deletion names
27
+ * what it is part of) and `unavailable` (not the reader's to see).
28
+ */
29
+ export type PartCardState = 'ready' | 'loading' | 'unavailable' | 'deleted' | 'detached' | 'unaddressable'
30
+
23
31
  export interface PartCardProps {
24
32
  /** Where its lookup stands. Default `ready`. */
25
- state?: 'ready' | 'loading' | 'unavailable'
33
+ state?: PartCardState
26
34
  /** What it is part of, by its icon. */
27
35
  kind: LinkedKind
28
36
  /** The title of what it is part of. */
29
37
  heading?: string
30
- /** Opens what it is part of, at the part. */
38
+ /** Opens what it is part of, at the part; `unaddressable`, the whole of it. */
31
39
  href?: string
32
40
  /** The key of what it is part of: "ABC-2". */
33
41
  partKey?: string
@@ -51,7 +59,12 @@ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun,
51
59
  const word = noun ?? kindNounOf({ kind }) ?? 'File'
52
60
  const boxed = useContext(inTheBox)
53
61
  if (state === 'loading') return <LinkCardLoading kind={kind} shape={{ summary: true, rows: 0, footer: 'none' }} />
54
- if (state === 'unavailable') return <LinkUnavailable kind={kind} noun={`A part of this ${word.toLowerCase()}`} openIn={openIn} card />
62
+ if (state === 'unavailable' || state === 'deleted') {
63
+ return <LinkUnavailable kind={kind} noun={`A part of this ${word.toLowerCase()}`} openIn={openIn} deleted={state === 'deleted'} card />
64
+ }
65
+ // The SPEC's words (§13.6.1): what it is part of is still there; the part is not, or cannot be one.
66
+ if (state === 'detached') return <UnavailableRow kind={kind} words="This part was deleted" card />
67
+ if (state === 'unaddressable') return <UnavailableRow kind={kind} words="This part can't be shown" href={href} card />
55
68
  return (
56
69
  // At most 480px wide, in a box too; in a box being written in, on the files' fill as the card beside it is.
57
70
  <Card fill={boxed ? 'elevated' : 'inset'} className="flex max-w-[480px] flex-col gap-3 p-3">
@@ -59,7 +72,8 @@ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun,
59
72
  <LinkTile kind={kind} />
60
73
  <span className="flex min-w-0 flex-1 flex-col gap-0.5">
61
74
  <span className="block min-w-0 text-body-2-strong text-text-primary">
62
- {href ? (
75
+ {/* In a box being written in, its words alone: the draft is not left for it. */}
76
+ {href && !boxed ? (
63
77
  <Link href={href} variant="quiet" truncate className="block">
64
78
  {heading}
65
79
  </Link>
@@ -5,15 +5,14 @@
5
5
  * after its line and keeps its element while the line lives.
6
6
  */
7
7
  import { afterEach, describe, expect, it } from 'vitest'
8
- import { act, cleanup, render } from '@testing-library/react'
9
- import { createPortal } from 'react-dom'
8
+ import { cleanup } from '@testing-library/react'
10
9
  import { Editor } from '@tiptap/core'
11
10
  import { NodeSelection, TextSelection } from '@tiptap/pm/state'
12
11
  import StarterKit from '@tiptap/starter-kit'
13
12
  import { BlockId, ReferenceNode } from './BlockNodes'
14
- import { ReferenceCards, referenceAtSelection, referenceCardPlacements, setReferenceCard, useReferenceCards } from './ReferenceCards'
13
+ import { referenceAtSelection, referenceCardPlacements, setReferenceCard } from './ReferenceCards'
15
14
 
16
- const EXTENSIONS = [StarterKit, BlockId, ReferenceNode, ReferenceCards]
15
+ const EXTENSIONS = [StarterKit, BlockId, ReferenceNode]
17
16
  const V = 'nostr:naddr1example'
18
17
  const W = 'nostr:naddr1other'
19
18
 
@@ -55,7 +54,7 @@ describe('ReferenceNode keeps the card', () => {
55
54
  })
56
55
 
57
56
  describe('referenceCardPlacements', () => {
58
- it('asks for a slot after each line whose chips chose a card, keyed by block id', () => {
57
+ it('finds each line whose chips chose a card, keyed by block id', () => {
59
58
  editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
60
59
  const placements = referenceCardPlacements(editor.state.doc)
61
60
  expect(placements.map((p) => [p.key, p.cards])).toEqual([
@@ -64,14 +63,6 @@ describe('referenceCardPlacements', () => {
64
63
  ['b:i1', [{ uri: W, layout: 'compact' }]],
65
64
  ])
66
65
  })
67
-
68
- it('draws an empty, non-editable slot inside the line', () => {
69
- editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
70
- const slot = editor.view.dom.querySelector('[data-reference-cards="b:p1"]')
71
- expect(slot?.getAttribute('contenteditable')).toBe('false')
72
- expect(slot?.closest('p')?.textContent).toContain('for now')
73
- expect(editor.view.dom.querySelectorAll('[data-reference-cards]')).toHaveLength(2)
74
- })
75
66
  })
76
67
 
77
68
  describe('choosing a card', () => {
@@ -119,25 +110,3 @@ describe('choosing a card', () => {
119
110
  expect(setReferenceCard(editor, 'compact')).toBe(false)
120
111
  })
121
112
  })
122
-
123
- describe('useReferenceCards', () => {
124
- function Cards({ ed }: { ed: Editor }) {
125
- const slots = useReferenceCards(ed)
126
- return <>{slots.map((s) => createPortal(<span data-card={s.cards.map((c) => c.layout).join(',')} />, s.element, s.key))}</>
127
- }
128
-
129
- it('portals the app\'s cards into the slots, and typing keeps the slot\'s element', () => {
130
- editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
131
- const ed = editor
132
- render(<Cards ed={ed} />)
133
- const before = ed.view.dom.querySelector('[data-reference-cards="b:p1"]')
134
- expect(before?.querySelector('[data-card="detailed"]')).not.toBeNull()
135
-
136
- act(() => {
137
- ed.commands.insertContentAt(1, 'Still ')
138
- })
139
- const after = ed.view.dom.querySelector('[data-reference-cards="b:p1"]')
140
- expect(after).toBe(before)
141
- expect(after?.querySelector('[data-card="detailed"]')).not.toBeNull()
142
- })
143
- })
@@ -1,28 +1,16 @@
1
1
  /**
2
- * The cards a block document's writer chose, drawn after the line that holds
3
- * each reference — SPEC §13.3, "A reference's card".
2
+ * The card a block document's writer chose for a reference — SPEC §13.3, "A
3
+ * reference's card": `embed` on the `reference` node (`ReferenceNode`), so the
4
+ * card moves and goes with its chip. `ReferenceMenu` writes it (Show as Row or
5
+ * Card) and `LinkPlaces` draws it in the row's place.
4
6
  *
5
- * The choice is `embed` on the `reference` node (`ReferenceNode`), so the card
6
- * moves and goes with its chip. What a card looks like is the app's — it knows
7
- * how to resolve an object and draw its row or its card — so this extension
8
- * draws nothing itself: after every textblock whose chips ask for a card it
9
- * places one empty, non-editable slot, and `useReferenceCards` hands the app
10
- * those slots to portal its cards into. A portal, rather than a React root per
11
- * slot, keeps the app's providers around the card.
12
- *
13
- * **A slot keeps its element while its block lives.** It is keyed by the
14
- * nearest block id (the `blockId` attribute), so typing above a card does not
15
- * re-make its element, and the card does not reload on every keystroke.
16
- *
17
- * The slot sits at the end of the textblock, inside it: a paragraph's card is
18
- * under the paragraph, a list item's under the item at its indent, a table
19
- * cell's in the cell.
7
+ * The extension that placed a slot after each line for the app's card, and its
8
+ * hook, were deprecated by `LinkPlaces` and are gone (Katerina's widget review,
9
+ * 30 Oct): no app used them. What stays reads and writes the choice.
20
10
  */
21
- import { Extension, type Editor } from '@tiptap/core'
11
+ import type { Editor } from '@tiptap/core'
22
12
  import type { Node as PmNode } from '@tiptap/pm/model'
23
- import { NodeSelection, Plugin, PluginKey, type EditorState } from '@tiptap/pm/state'
24
- import { Decoration, DecorationSet } from '@tiptap/pm/view'
25
- import { useEffect, useState } from 'react'
13
+ import { NodeSelection, type EditorState } from '@tiptap/pm/state'
26
14
 
27
15
  /** A layout a writer can choose; `none` is no card. */
28
16
  export type ReferenceCardLayout = 'none' | 'compact' | 'detailed'
@@ -33,16 +21,9 @@ export interface ReferenceCard {
33
21
  layout: Exclude<ReferenceCardLayout, 'none'>
34
22
  }
35
23
 
36
- /** One slot: where an app draws the cards of one line. */
37
- export interface ReferenceCardSlot {
38
- key: string
39
- element: HTMLElement
40
- cards: ReferenceCard[]
41
- }
42
-
43
24
  interface Placement {
44
25
  key: string
45
- /** The end of the textblock's content, where the slot goes. */
26
+ /** The end of the textblock's content. */
46
27
  pos: number
47
28
  cards: ReferenceCard[]
48
29
  }
@@ -79,96 +60,6 @@ export function referenceCardPlacements(doc: PmNode): Placement[] {
79
60
  return out
80
61
  }
81
62
 
82
- interface ReferenceCardsStorage {
83
- /** One element per slot key, made once and reused, so the app's portal stays put. */
84
- elements: Map<string, HTMLElement>
85
- }
86
-
87
- const key = new PluginKey<DecorationSet>('referenceCards')
88
-
89
- function elementFor(storage: ReferenceCardsStorage, slotKey: string): HTMLElement {
90
- let element = storage.elements.get(slotKey)
91
- if (!element) {
92
- element = document.createElement('div')
93
- element.setAttribute('data-reference-cards', slotKey)
94
- element.setAttribute('contenteditable', 'false')
95
- storage.elements.set(slotKey, element)
96
- }
97
- return element
98
- }
99
-
100
- function storageOf(editor: Editor): ReferenceCardsStorage | undefined {
101
- return (editor.storage as unknown as { referenceCards?: ReferenceCardsStorage }).referenceCards
102
- }
103
-
104
- /**
105
- * Places a slot after each line whose chips ask for a card. Pair it with
106
- * `ReferenceNode`, and draw the cards with `useReferenceCards`.
107
- */
108
- export const ReferenceCards = Extension.create<Record<string, never>, ReferenceCardsStorage>({
109
- name: 'referenceCards',
110
- addStorage() {
111
- return { elements: new Map() }
112
- },
113
- addProseMirrorPlugins() {
114
- const storage = this.storage
115
- const decorate = (doc: PmNode) =>
116
- DecorationSet.create(
117
- doc,
118
- referenceCardPlacements(doc).map((p) =>
119
- Decoration.widget(p.pos, () => elementFor(storage, p.key), {
120
- key: p.key,
121
- side: 1,
122
- ignoreSelection: true,
123
- // A click on a card is the card's, not a caret placement in the line.
124
- stopEvent: () => true,
125
- }),
126
- ),
127
- )
128
- return [
129
- new Plugin<DecorationSet>({
130
- key,
131
- state: {
132
- init: (_, state) => decorate(state.doc),
133
- apply: (tr, set) => (tr.docChanged ? decorate(tr.doc) : set),
134
- },
135
- props: { decorations: (state) => key.getState(state) },
136
- }),
137
- ]
138
- },
139
- })
140
-
141
- /**
142
- * The slots to draw cards into, kept current as the document changes. Draw
143
- * each with `createPortal(<cards/>, slot.element)`, keyed by `slot.key`.
144
- */
145
- export function useReferenceCards(editor: Editor | null): ReferenceCardSlot[] {
146
- const [slots, setSlots] = useState<ReferenceCardSlot[]>([])
147
- useEffect(() => {
148
- if (!editor) return
149
- const storage = storageOf(editor)
150
- if (!storage) return
151
- let last = ''
152
- const read = () => {
153
- if (editor.isDestroyed) return
154
- const next = referenceCardPlacements(editor.state.doc).map((p) => ({ key: p.key, element: elementFor(storage, p.key), cards: p.cards }))
155
- // Only a change in what is drawn re-renders the app; typing does not.
156
- const signature = JSON.stringify(next.map((s) => [s.key, s.cards]))
157
- if (signature === last) return
158
- last = signature
159
- const live = new Set(next.map((s) => s.key))
160
- for (const k of storage.elements.keys()) if (!live.has(k)) storage.elements.delete(k)
161
- setSlots(next)
162
- }
163
- read()
164
- editor.on('transaction', read)
165
- return () => {
166
- editor.off('transaction', read)
167
- }
168
- }, [editor])
169
- return slots
170
- }
171
-
172
63
  /**
173
64
  * The chip the person has selected, with what it names and its card — or null.
174
65
  *
@@ -48,8 +48,9 @@ const editor = useEditor({
48
48
 
49
49
  - **A click on a link while editing** — its chip, row or card — opens the menu
50
50
  under it, instead of following it. Not editing, the click follows it. A
51
- card's own controls (its status, its owner) take their click while editing
52
- too.
51
+ card's own links and controls take their click while editing too: its title
52
+ opens the file, its count the conversation, its status and owner change it.
53
+ Only a click on the card's empty space opens the menu.
53
54
  - **A link just put in alone on its line** — pasted, picked with `[`, or a
54
55
  pasted URL becoming its chip — opens the menu by itself. It takes no focus:
55
56
  typing on closes it, and nothing is written. In a sentence it does not open:
@@ -60,8 +61,9 @@ const editor = useEditor({
60
61
  - **Open** does what a click on the link does when reading: the app's link gets
61
62
  the click. A link with nothing to click opens its URL in a new tab.
62
63
  - Open is offered only when there is something to open: the link's own
63
- control, or its URL. A link in a sentence with neither has no menu, and a
64
- click goes on to it.
64
+ control as the app drew it, or its URL. A person, and a link still loading
65
+ or not available, have neither: no Open. A link in a sentence with neither
66
+ has no menu, and a click goes on to it.
65
67
  - The menu closes when the editor loses focus, so a card is never chosen after
66
68
  the editor has saved on leaving.
67
69
  - Choosing Row or Card is an undo step; the menu closes.
@@ -260,13 +260,14 @@ describe('ReferenceMenu', () => {
260
260
  })
261
261
 
262
262
  describe('ReferenceMenuView', () => {
263
- /** The app's drawing: a link, named by its place, that follows on a click. */
263
+ /** The app's drawing: a link, named by its place, that follows on a click; a card has room around its link. */
264
264
  function Linked({ uri, place = 'chip' }: ReferenceViewProps) {
265
- return (
265
+ const link = (
266
266
  <a href={`/o/${uri}`} data-place={place} onClick={(event) => (followed(uri), event.preventDefault())}>
267
267
  Item
268
268
  </a>
269
269
  )
270
+ return place === 'card' ? <span data-testid="card">{link} Summary</span> : link
270
271
  }
271
272
  const followed = vi.fn()
272
273
 
@@ -323,7 +324,8 @@ describe('ReferenceMenuView', () => {
323
324
  await waitFor(() => expect(screen.getByRole('link', { name: 'Item' }).getAttribute('data-place')).toBe('card'))
324
325
  await waitFor(() => expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull())
325
326
 
326
- fireEvent.click(screen.getByRole('link', { name: 'Item' }))
327
+ // On a card, its empty space opens the menu; its own link takes the click (below).
328
+ fireEvent.click(screen.getByTestId('card'))
327
329
  expect((await screen.findByRole('menuitemradio', { name: 'Card' })).getAttribute('aria-checked')).toBe('true')
328
330
  fireEvent.mouseDown(screen.getByRole('menuitemradio', { name: 'Row' }))
329
331
  // Row writes no `embed` at all, not `none`.
@@ -370,17 +372,77 @@ describe('ReferenceMenuView', () => {
370
372
  expect(isReferenceMenuOpen(editor!.state)).toBe(false)
371
373
  })
372
374
 
373
- it('offers Open at once on a link picked on an empty line, before the app has drawn it', async () => {
375
+ it('offers Open on a link picked on an empty line once the app has drawn it', async () => {
374
376
  render(<Harness content={para()} />)
375
377
  await screen.findByRole('textbox')
376
378
  act(() => {
377
- editor!.commands.focus('end')
379
+ editor!.commands.setTextSelection(editor!.state.doc.content.size - 1)
378
380
  editor!.commands.insertContent([ref(V), { type: 'text', text: ' ' }])
379
381
  })
380
382
  expect((await screen.findAllByRole('menuitem', { name: 'Open' })).length).toBe(1)
381
383
  expect(screen.getByRole('menuitemradio', { name: 'Row' }).getAttribute('aria-checked')).toBe('true')
382
384
  })
383
385
 
386
+ it('follows a click on a card\'s own link while editing; its empty space opens the menu', async () => {
387
+ followed.mockClear()
388
+ render(<Harness content={para(ref(V, 'detailed'))} />)
389
+ fireEvent.click(await screen.findByRole('link', { name: 'Item' }))
390
+ expect(followed).toHaveBeenCalledWith(V)
391
+ expect(isReferenceMenuOpen(editor!.state)).toBe(false)
392
+ fireEvent.click(screen.getByTestId('card'))
393
+ expect(followed).toHaveBeenCalledTimes(1)
394
+ await screen.findByRole('menuitemradio', { name: 'Card' })
395
+ })
396
+
397
+ it('keeps a press on a card\'s picker from the text, so the caret does not take it and close the picker', async () => {
398
+ function WithPicker({ place = 'chip' }: ReferenceViewProps) {
399
+ return place === 'card' ? (
400
+ <span>
401
+ <button type="button">
402
+ <span>Status</span>
403
+ </button>
404
+ <span>Summary</span>
405
+ </span>
406
+ ) : (
407
+ <span>Item</span>
408
+ )
409
+ }
410
+ function PickerHarness() {
411
+ const e = useEditor({ extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: WithPicker }), LinkPlaces, ReferenceMenu], content: para(ref(V, 'detailed')) })
412
+ editor = e ?? undefined
413
+ return <EditorContent editor={e} />
414
+ }
415
+ render(<PickerHarness />)
416
+ // fireEvent answers false when the press's default was prevented, which ProseMirror leaves alone.
417
+ expect(fireEvent.mouseDown(await screen.findByText('Status'))).toBe(false)
418
+ })
419
+
420
+ it('offers no Open on a link the app draws with nothing to click (a person, loading, not available), and no menu in a sentence', async () => {
421
+ // As the kit's chip draws a link still loading or not available, and a person with no page: words, no link.
422
+ const Words = () => <span>Item</span>
423
+ function WordsHarness({ content }: { content: Record<string, unknown> }) {
424
+ const e = useEditor({ extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Words }), LinkPlaces, ReferenceMenu], content })
425
+ editor = e ?? undefined
426
+ return (
427
+ <>
428
+ <EditorContent editor={e} />
429
+ <ReferenceMenuView editor={e} />
430
+ </>
431
+ )
432
+ }
433
+ render(<WordsHarness content={para(ref(V))} />)
434
+ fireEvent.click(await screen.findByText('Item'))
435
+ await screen.findByRole('menuitemradio', { name: 'Card' })
436
+ expect(screen.queryByRole('menuitem', { name: 'Open' })).toBeNull()
437
+ cleanup()
438
+ editor?.destroy()
439
+
440
+ render(<WordsHarness content={para({ type: 'text', text: 'See ' }, ref(V))} />)
441
+ fireEvent.click(await screen.findByText('Item'))
442
+ expect(isReferenceMenuOpen(editor!.state)).toBe(false)
443
+ expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull()
444
+ })
445
+
384
446
  it('lets a click follow the link when the editor is not editable', async () => {
385
447
  followed.mockClear()
386
448
  render(<Harness content={para(ref(V))} />)