@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
@@ -5,7 +5,7 @@ import { BlockId, ReferenceNode, type ReferenceViewProps } from './BlockNodes'
5
5
  import { Card } from './Card'
6
6
  import { InlineChip } from './InlineChip'
7
7
  import { LinkChips } from './LinkChips'
8
- import { ReferenceCards } from './ReferenceCards'
8
+ import { LinkPlaces } from './LinkPlaces'
9
9
  import { richTextClassName } from './RichText'
10
10
 
11
11
  /**
@@ -35,7 +35,7 @@ function Box() {
35
35
  StarterKit.configure({ link: false }),
36
36
  BlockId,
37
37
  ReferenceNode.configure({ view: Placeholder }),
38
- ReferenceCards,
38
+ LinkPlaces,
39
39
  LinkChips.configure({
40
40
  referenceOf: (url) => answered.get(url),
41
41
  ask: (urls) =>
@@ -10,7 +10,7 @@ import { TextSelection } from '@tiptap/pm/state'
10
10
  import StarterKit from '@tiptap/starter-kit'
11
11
  import { BlockId, ReferenceNode } from './BlockNodes'
12
12
  import { LinkChips, refreshLinkChips } from './LinkChips'
13
- import { ReferenceCards, referenceAtSelection, referenceCardPlacements } from './ReferenceCards'
13
+ import { referenceAtSelection, referenceCardPlacements } from './ReferenceCards'
14
14
 
15
15
  const URL_ = 'https://app.example/i/one'
16
16
  const V = 'nostr:naddr1example'
@@ -32,7 +32,6 @@ const make = (content: Record<string, unknown>, known: Map<string, string>, aske
32
32
  StarterKit.configure({ link: false }),
33
33
  BlockId,
34
34
  ReferenceNode,
35
- ReferenceCards,
36
35
  LinkChips.configure({
37
36
  referenceOf: (url) => known.get(url),
38
37
  ask: (urls) => {
package/src/LinkChips.ts CHANGED
@@ -176,7 +176,8 @@ export function refreshLinkChips(editor: Editor): void {
176
176
 
177
177
  /**
178
178
  * Turns the app URLs in a document into URL chips. Pair it with `ReferenceNode`;
179
- * `ReferenceCards` then draws a card a URL chip asks for.
179
+ * `LinkPlaces` then draws a lone one as its row or its card, and
180
+ * `ReferenceMenu` lets its writer choose.
180
181
  */
181
182
  export const LinkChips = Extension.create<LinkChipsOptions>({
182
183
  name: 'linkChips',
package/src/LinkParts.mdx CHANGED
@@ -11,13 +11,14 @@ The small parts the link widgets are built from: the pickers, the conversation c
11
11
 
12
12
  ## When
13
13
 
14
- - **LinkPickers** — a status and an owner, changed in place. A picker with no `onChange`, or `readOnly`, reads as words in the same place.
15
- - **CommentCount** — how much was said, as a link to where it is read; brighter, with a dot, when there is something unread for a member.
14
+ - **LinkPickers** — a status and an owner, changed in place. A picker with no `onChange`, or `readOnly`, reads as words in the same place. Nobody — no owner, or the option whose value is `''`, "Unassigned" — is the silhouette, never a letter.
15
+ - **CommentCount** — how much was said, as a link to where it is read; brighter, with a dot, when there is something unread for a member. In a box being written in, or with nowhere to open (an empty `href`), the count alone, no link. A screen reader hears it whole: "1 comment", "3 comments" (`noun` is the plural; one is its singular).
16
16
  - **StatusMark** — a status as its shape, which reads without colour; its words on hover.
17
17
  - **ProgressRing** — how far along, as a ring and a count.
18
18
  - **LinkedIcon**, **LinkKey** — the icon for what a link stands for, and its key.
19
19
 
20
20
  <Canvas of={LinkPartsStories.PickersReadOnly} />
21
+ <Canvas of={LinkPartsStories.Unassigned} />
21
22
  <Canvas of={LinkPartsStories.Conversation} />
22
23
  <Canvas of={LinkPartsStories.Marks} />
23
24
 
@@ -37,6 +37,14 @@ export const NoOwner: Story = {
37
37
  args: { status: { value: 'todo', options: STATUS_OPTIONS }, owner: { value: undefined, options: PEOPLE } },
38
38
  }
39
39
 
40
+ /** "Unassigned" as an owner the reader may pick: the silhouette, never a letter, in the picker and its list. */
41
+ export const Unassigned: Story = {
42
+ render: () => {
43
+ const [owner, setOwner] = useState('')
44
+ return <LinkPickers owner={{ value: owner, options: [{ value: '', label: 'Unassigned' }, ...PEOPLE], onChange: setOwner }} ownerLabel="Owner" />
45
+ },
46
+ }
47
+
40
48
  /** The count of what was said, opening where it is read. With something unread, to a member: brighter, with a dot. */
41
49
  export const Conversation: Story = {
42
50
  render: () => (
package/src/LinkParts.tsx CHANGED
@@ -4,12 +4,13 @@
4
4
  * count with its unread dot, and the pickers. LinkChip, LinkRow and LinkCard
5
5
  * place them; an app may place them too.
6
6
  */
7
+ import { useContext } from 'react'
7
8
  import { IconCircle, IconCircleCheck, IconCircleDashed, IconCircleHalf2, IconCircleX, IconFileText, IconMessage2 } from '@tabler/icons-react'
8
9
  import { Avatar } from './Avatar'
9
10
  import { cn } from './cn'
10
11
  import { KindIcon } from './KindIcon'
11
12
  import { Link } from './Link'
12
- import { chosenOf, type Linked, type LinkedConversation, type LinkedKind, type LinkedPicker, type LinkedStatus, type StatusColour } from './linked'
13
+ import { chosenOf, inTheBox, type Linked, type LinkedConversation, type LinkedKind, type LinkedPicker, type LinkedStatus, type StatusColour } from './linked'
13
14
  import { TYPE_TILE_CLASSES } from './looks'
14
15
  import { Select } from './Select'
15
16
  import { WithTooltip } from './Tooltip'
@@ -92,14 +93,41 @@ export function ProgressRing({ done, total }: { done: number; total: number }) {
92
93
  )
93
94
  }
94
95
 
96
+ /**
97
+ * A count in words, as the kit says one elsewhere ("3 members"): `noun` is the
98
+ * plural, and one is its singular — "1 comment", "1 conversation", "1 reply".
99
+ */
100
+ function countWords(count: number, noun: string): string {
101
+ if (count !== 1) return `${count} ${noun}`
102
+ const one = /ies$/.test(noun) ? noun.replace(/ies$/, 'y') : noun.replace(/s$/, '')
103
+ return `${count} ${one}`
104
+ }
105
+
95
106
  /**
96
107
  * The count of what was said, a link to where it is read. With something
97
108
  * unread there the words are brighter and a dot follows. It sits above a
98
109
  * row's covering link, so the row opens the thing and the count its
99
- * conversation.
110
+ * conversation. In a box being written in it is the count alone, no link: the
111
+ * draft is not left for it (Katerina, 30 Oct); and so it is where the app gives
112
+ * it nowhere to open (an empty `href`).
113
+ *
114
+ * A screen reader hears it whole, "3 comments — open the conversation": the
115
+ * figure drawn is hidden from it, so it never runs into the noun ("3comments").
100
116
  */
101
117
  export function CommentCount({ conversation, noun = 'comments' }: { conversation: LinkedConversation; noun?: string }) {
102
118
  const { count, href, unread = false } = conversation
119
+ const boxed = useContext(inTheBox)
120
+ const said = countWords(count, noun)
121
+ if (boxed || !href) {
122
+ return (
123
+ <span className={cn('inline-flex h-6 shrink-0 items-center gap-1 px-1.5 text-small tabular-nums', unread ? 'font-medium text-text-primary' : 'text-text-secondary')}>
124
+ <IconMessage2 size={14} stroke={1.5} aria-hidden />
125
+ <span aria-hidden>{count}</span>
126
+ <span className="sr-only">{unread ? `${said}, unread` : said}</span>
127
+ {unread && <UnreadDot className="h-auto w-auto" />}
128
+ </span>
129
+ )
130
+ }
103
131
  return (
104
132
  /*
105
133
  * A small button's shape, as Button's small one is: 24px tall like the pickers beside it, 6px each side, its corners
@@ -111,8 +139,8 @@ export function CommentCount({ conversation, noun = 'comments' }: { conversation
111
139
  <span className={cn('relative z-10 inline-flex h-6 shrink-0 rounded-md text-small tabular-nums transition-colors hover:bg-bg-hover', unread ? 'font-medium text-text-primary' : 'text-text-secondary')}>
112
140
  <Link href={href} variant="plain" className="flex h-full items-center gap-1 px-1.5">
113
141
  <IconMessage2 size={14} stroke={1.5} aria-hidden />
114
- {count}
115
- <span className="sr-only">{unread ? `${noun}, unread — open the conversation` : `${noun} — open the conversation`}</span>
142
+ <span aria-hidden>{count}</span>
143
+ <span className="sr-only">{unread ? `${said}, unread — open the conversation` : `${said} — open the conversation`}</span>
116
144
  {unread && <UnreadDot className="h-auto w-auto" />}
117
145
  </Link>
118
146
  </span>
@@ -128,6 +156,12 @@ export interface LinkPickersProps {
128
156
  readOnly?: boolean
129
157
  }
130
158
 
159
+ /** The face for an owner option: nobody (value `''`, "Unassigned") is the silhouette, never a letter (Katerina, 30 Oct). */
160
+ function OwnerFace({ option }: { option: { value: string; label: string; picture?: string } | undefined }) {
161
+ const nobody = !option || option.value === ''
162
+ return <Avatar name={nobody ? undefined : option.label} src={nobody ? undefined : option.picture} size={16} />
163
+ }
164
+
131
165
  /**
132
166
  * A status and an owner, where the reader can change them from the card. A
133
167
  * picker whose app passed no `onChange` reads as words in the same place: the
@@ -162,7 +196,7 @@ export function LinkPickers({ status, owner, ownerLabel = 'Owner', readOnly = fa
162
196
  {owner &&
163
197
  (ownerWords ? (
164
198
  <span className="inline-flex min-w-0 items-center gap-1">
165
- <Avatar name={ownerNow?.label} src={ownerNow?.picture} size={16} />
199
+ <OwnerFace option={ownerNow} />
166
200
  <span className="truncate">{ownerNow?.label ?? 'Unassigned'}</span>
167
201
  </span>
168
202
  ) : (
@@ -174,7 +208,7 @@ export function LinkPickers({ status, owner, ownerLabel = 'Owner', readOnly = fa
174
208
  placeholder="Unassigned"
175
209
  onChange={(value) => owner.onChange?.(value)}
176
210
  ariaLabel={ownerLabel}
177
- options={owner.options.map((option) => ({ value: option.value, label: option.label, leading: <Avatar name={option.label} src={option.picture} size={16} /> }))}
211
+ options={owner.options.map((option) => ({ value: option.value, label: option.label, leading: <OwnerFace option={option} /> }))}
178
212
  />
179
213
  ))}
180
214
  </span>
@@ -53,6 +53,9 @@ const editor = useEditor({ extensions: [StarterKit, BlockId, ReferenceNode.confi
53
53
  - **The same rule as the protocol's** `documentLineDrawOf`, read off the
54
54
  editor's tree on every change; a test holds the two to one answer.
55
55
  - **A row or a card is the whole line**: its view's wrapper is a block.
56
+ - **`editing` is true while the editor is editable**, or with
57
+ `ReferenceNode`'s `editingLine` only while the caret is on the link's line,
58
+ as `DocumentEditor` has it: elsewhere the chip and the row preview.
56
59
 
57
60
  ## What it owns
58
61
 
package/src/LinkPlaces.ts CHANGED
@@ -27,6 +27,8 @@ import { Extension } from '@tiptap/core'
27
27
  import type { Node as PmNode } from '@tiptap/pm/model'
28
28
  import { Plugin, PluginKey } from '@tiptap/pm/state'
29
29
  import { Decoration, DecorationSet } from '@tiptap/pm/view'
30
+ import { thingKindOf } from './KindIcon'
31
+ import type { LinkedKind } from './linked'
30
32
 
31
33
  /** How a reference draws: its chip, its row, or its card in the row's place. */
32
34
  export type LinkPlace = 'chip' | 'row' | 'card'
@@ -76,6 +78,23 @@ function naddrKind(naddr: string): number | null {
76
78
  /** A Folder's kind. */
77
79
  const FOLDER = 39000
78
80
 
81
+ /** A document's kind: it draws a page, as `linkedFrom` draws it. */
82
+ const PAGE = 30842
83
+
84
+ /**
85
+ * What a `nostr:` reference names, by the icon it draws, read off its address
86
+ * alone: a message (`nevent`, `note`), a file by its kind (`naddr`, a document
87
+ * a page), or undefined for what has no kind icon (a person, anything else).
88
+ */
89
+ export function linkedKindOfReference(uri: string): LinkedKind | undefined {
90
+ const bare = uri.toLowerCase().replace(/^nostr:/, '')
91
+ if (bare.startsWith('nevent1') || bare.startsWith('note1')) return 'message'
92
+ if (!bare.startsWith('naddr1')) return undefined
93
+ const kind = naddrKind(bare)
94
+ if (kind === null) return undefined
95
+ return kind === PAGE ? 'page' : thingKindOf(kind)
96
+ }
97
+
79
98
  /**
80
99
  * Whether what `uri` names stays a chip alone on its line: a person (`npub`,
81
100
  * `nprofile`) or a Folder (an `naddr` of kind 39000).
package/src/LinkRow.mdx CHANGED
@@ -12,13 +12,19 @@ A link alone on its line: its kind in a file's tile, the title and its key under
12
12
  ## When
13
13
 
14
14
  - **ready** — its kind in the 36px tile a file's type has (**AttachmentCard**), the title as the link, and under it the key and what it is ("ABC-2 · Issue"), in the app's word for it, else its kind's. On the title's line: its status or its ring, its comment count, then the owner, members or authors at the far right. Hovering it shows its card; a tap opens it.
15
- - **words a person wrote** — their face in the tile, their name with the time beside it, and the words under them.
15
+ - **ready** and archived — `linked.archived`: "Archived" in the line under the title ("ABC-2 · Issue · Archived"). `linkStateFrom` sets it, and words for its values, from an archived file.
16
+ - **words a person wrote** — on one line, as a quote is cut to one: their face in the tile, their name, the words cut to fit, the time.
16
17
  - **width** — at most 480px, in a box being written in too.
17
18
  - **unread** — the count is brighter, with its dot.
18
19
  - **loading** — the row in bars, in the row's own shape.
19
20
  - **unavailable** — a row's shape, "Issue not available", with where it may still open (`openIn`). This is also what a card draws when it is not available: **LinkUnavailable**, from this file.
21
+ - **deleted** — `deleted` on the state, when a trusted deletion names it (SPEC §13.6.1): the same row, "Issue deleted", and no way out.
22
+ - **written as a URL** — `url` on the state: the URL as it was written, a plain link in the row's place, deleted or not available alike (SPEC §13.1).
20
23
 
21
24
  <Canvas of={LinkRowStories.NotAvailable} />
25
+ <Canvas of={LinkRowStories.Deleted} />
26
+ <Canvas of={LinkRowStories.WordsAPersonWrote} />
27
+ <Canvas of={LinkRowStories.Archived} />
22
28
 
23
29
  ## When not
24
30
 
@@ -33,7 +39,7 @@ import { LinkRow } from '@estiva-app/ui'
33
39
  <LinkRow link={{ state: 'ready', linked }} />
34
40
  ```
35
41
 
36
- - The whole row opens `linked.href`; the conversation count opens `linked.conversation.href` on its own.
42
+ - The whole row opens `linked.href`; the conversation count opens `linked.conversation.href` on its own. With no address (an empty `href`, as for another app's file with none over https), its title, or its count, is words and not a link.
37
43
  - `linked.conversation.unread` is the app's to say, and only for a member of it.
38
44
 
39
45
  ## What it owns
@@ -1,5 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { GROUP, ITEM, ITEM_UNREAD, LOADING, PAGE, PLACE, ready, SAID, UNAVAILABLE } from './linked.examples'
2
+ import { DELETED, GROUP, ITEM, ITEM_ARCHIVED, ITEM_UNREAD, LOADING, PAGE, PLACE, ready, SAID, UNAVAILABLE, WRITTEN_AS_A_URL } from './linked.examples'
3
3
  import { LinkRow, LinkUnavailable } from './LinkRow'
4
4
 
5
5
  const meta = {
@@ -32,12 +32,24 @@ export const EachKind: Story = {
32
32
  /** Something unread in its conversation, to a member: the count shows, with its dot. */
33
33
  export const Unread: Story = { args: { link: ready(ITEM_UNREAD) } }
34
34
 
35
+ /** Words a person wrote, on one line: their face, their name, the words cut to fit, the time. */
36
+ export const WordsAPersonWrote: Story = { args: { link: ready(SAID) } }
37
+
38
+ /** Archived: "Archived" in the line under its title. */
39
+ export const Archived: Story = { args: { link: ready(ITEM_ARCHIVED) } }
40
+
35
41
  /** Still being looked up: the row in bars, at the row's height. */
36
42
  export const Loading: Story = { args: { link: LOADING } }
37
43
 
38
- /** Deleted, or not this reader's to see: one line, and where it may still open. */
44
+ /** Not this reader's to see: one line, and where it may still open. */
39
45
  export const NotAvailable: Story = { args: { link: UNAVAILABLE } }
40
46
 
47
+ /** Deleted, as a trusted deletion naming it says: the same line, its own words, and no way out. */
48
+ export const Deleted: Story = { args: { link: DELETED } }
49
+
50
+ /** Written as a URL that cannot be shown: it stays that URL, a plain link, in the row's place. */
51
+ export const WrittenAsAUrl: Story = { args: { link: WRITTEN_AS_A_URL } }
52
+
41
53
  /** The not-available line on its own, as a card or a part draws it too; without `openIn`, no way out. */
42
54
  export const NotAvailableLine: Story = {
43
55
  render: () => (
@@ -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>