@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
@@ -19,7 +19,9 @@
19
19
  *
20
20
  * Open does what a click on the chip does when reading: the app's own chip
21
21
  * gets the click, so it opens where the app opens it. A chip with nothing to
22
- * click opens its URL in a new tab.
22
+ * click opens its URL in a new tab; one with neither — a person, a link still
23
+ * loading or not available — offers no Open, and a menu left with nothing in
24
+ * it does not open.
23
25
  *
24
26
  * Two parts: the extension `ReferenceMenu` holds which chip the menu is open
25
27
  * on, and `ReferenceMenuView` draws it beside `EditorContent`. Pair them with
@@ -27,7 +29,7 @@
27
29
  *
28
30
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-lone-links-chip-menu-offers-row-or-card.md
29
31
  */
30
- import { useCallback } from 'react'
32
+ import { useCallback, useEffect, useReducer } from 'react'
31
33
  import { Extension, type Editor } from '@tiptap/core'
32
34
  import { useEditorState } from '@tiptap/react'
33
35
  import { NodeSelection, Plugin, PluginKey, TextSelection, type EditorState, type Transaction } from '@tiptap/pm/state'
@@ -74,13 +76,13 @@ function webHref(view: EditorView, pos: number): string {
74
76
 
75
77
  /**
76
78
  * The menu's rows: Open when there is something to open — the link's own
77
- * control, or its URL — and Row and Card when it is alone on its line and is
78
- * neither a person nor a Folder (`linkPlaceAt`).
79
+ * control as the app drew it, or its URL — and Row and Card when it is alone
80
+ * on its line and is neither a person nor a Folder (`linkPlaceAt`). A person,
81
+ * and a link still loading or not available, draw nothing to click: no Open
82
+ * (Katerina, 30 Oct). The view asks again as the app's drawing changes.
79
83
  */
80
84
  function rowsOf(view: EditorView, pos: number): Row[] {
81
- // A link the app draws has its own control even before React has drawn it, as right after a `[` pick.
82
- const drawn = !!view.state.doc.nodeAt(pos)?.attrs.uri && !!view.someProp('nodeViews', (views) => views?.reference)
83
- const open: Row[] = drawn || chipTarget(view, pos) || webHref(view, pos) ? ['open'] : []
85
+ const open: Row[] = chipTarget(view, pos) || webHref(view, pos) ? ['open'] : []
84
86
  return linkPlaceAt(view.state.doc, pos) === 'chip' ? open : [...open, ...SHOW_AS.map((show) => show.as)]
85
87
  }
86
88
 
@@ -290,6 +292,15 @@ export function ReferenceMenuView({ editor }: ReferenceMenuViewProps) {
290
292
  const live = shown && editor && !editor.isDestroyed ? editor : null
291
293
  const dom = live && shown ? live.view.nodeDOM(shown.pos) : null
292
294
  const anchor = dom instanceof HTMLElement ? dom : null
295
+ // Whether there is something to open is the app's drawing, which can arrive after the menu (right after a `[` pick)
296
+ // or change under it (a link that loads): the rows are asked again when it does.
297
+ const [, redraw] = useReducer((count: number) => count + 1, 0)
298
+ useEffect(() => {
299
+ if (!anchor || typeof MutationObserver === 'undefined') return
300
+ const observer = new MutationObserver(redraw)
301
+ observer.observe(anchor, { childList: true, subtree: true, attributes: true, attributeFilter: ['href'] })
302
+ return () => observer.disconnect()
303
+ }, [anchor])
293
304
  const rows = live && shown ? rowsOf(live.view, shown.pos) : []
294
305
  const opens = rows[0] === 'open'
295
306
  const showAs = rows.includes('card')
package/src/editor.ts CHANGED
@@ -103,15 +103,12 @@ export {
103
103
  type AttachmentViewProps,
104
104
  } from './BlockNodes'
105
105
  export {
106
- ReferenceCards,
107
- useReferenceCards,
108
106
  referenceAtSelection,
109
107
  referenceCardPlacements,
110
108
  setReferenceCard,
111
109
  setReferenceCardAt,
112
110
  type ReferenceCard,
113
111
  type ReferenceCardLayout,
114
- type ReferenceCardSlot,
115
112
  } from './ReferenceCards'
116
113
  export { LinkChips, findLinkChips, refreshLinkChips, type LinkChipsOptions, type PastedRange } from './LinkChips'
117
114
  export { LinkPlaces, linkPlaceAt, staysChip, type LinkPlace } from './LinkPlaces'
package/src/index.ts CHANGED
@@ -87,6 +87,7 @@ export { Toolbar, ToolbarButton, ToolbarInput, ToolbarLink, ToolbarSeparator, ty
87
87
  export { PreviewCard, type PreviewCardProps } from './PreviewCard'
88
88
  // How a link draws, wherever it sits: one kit for every app (Widgets 2).
89
89
  export {
90
+ cardShapeMemory,
90
91
  chosenOf,
91
92
  inTheBox,
92
93
  loadingShapeOf,
@@ -98,6 +99,8 @@ export {
98
99
  type LinkedPerson,
99
100
  type LinkedPicker,
100
101
  type LinkedStatus,
102
+ type CardShape,
103
+ type CardShapeMemory,
101
104
  type LinkState,
102
105
  type LoadingShape,
103
106
  type PickerOption,
@@ -120,7 +123,7 @@ export { LinkRow, LinkUnavailable, type LinkRowProps, type LinkUnavailableProps
120
123
  export { LinkCard, LinkCardLoading, type LinkCardProps, type LinkCardLoadingProps } from './LinkCard'
121
124
  export { LinkPreview, LinkPreviewOpen, useCanHover, type LinkPreviewProps } from './LinkPreview'
122
125
  export { AttachedCard, type AttachedCardProps } from './AttachedCard'
123
- export { PartCard, type PartCardProps } from './PartCard'
126
+ export { PartCard, type PartCardProps, type PartCardState } from './PartCard'
124
127
  export { Person, type PersonProps } from './Person'
125
128
  export { Rail, type RailProps } from './Rail'
126
129
  export { RailItem, type RailItemProps } from './RailItem'
@@ -105,3 +105,9 @@ export const SAID: Linked = {
105
105
  export const ready = (linked: Linked): LinkState => ({ state: 'ready', linked })
106
106
  export const LOADING: LinkState = { state: 'loading', kind: 'issue' }
107
107
  export const UNAVAILABLE: LinkState = { state: 'unavailable', kind: 'issue', noun: 'Issue', openIn: { app: 'App one', href: '#elsewhere' } }
108
+ /** Deleted, as a trusted deletion naming its address says: told apart from not available (SPEC §13.6.1). */
109
+ export const DELETED: LinkState = { state: 'unavailable', kind: 'issue', noun: 'Issue', deleted: true }
110
+ /** Written as a URL that cannot be shown: it stays that URL. */
111
+ export const WRITTEN_AS_A_URL: LinkState = { state: 'unavailable', kind: 'issue', noun: 'Issue', url: 'https://app.example/item/one' }
112
+ /** The item, archived: its row and card say so, and its values read as words. */
113
+ export const ITEM_ARCHIVED: Linked = { ...ITEM_READ_ONLY, archived: true }
@@ -5,10 +5,44 @@
5
5
  * when the link can be read again or at sign-out.
6
6
  */
7
7
  import { afterEach, describe, expect, it } from 'vitest'
8
- import { unavailableMemory } from './linked'
8
+ import { cardShapeMemory, unavailableMemory } from './linked'
9
9
 
10
10
  afterEach(() => localStorage.clear())
11
11
 
12
+ describe('cardShapeMemory', () => {
13
+ const SHAPE = { subtitle: true, summary: true, rows: 2, latest: false, ring: true, footer: 'pickers' as const, height: 180 }
14
+
15
+ it('remembers the shape a card drew at across a reload, and nothing for one never drawn', () => {
16
+ cardShapeMemory('test.shapes').note('a', SHAPE)
17
+ expect(cardShapeMemory('test.shapes').of('a', 'issue')).toEqual(SHAPE)
18
+ expect(cardShapeMemory('test.shapes').of('b', 'issue')).toBeUndefined()
19
+ })
20
+
21
+ it('answers the app’s first shape for a kind it has not drawn yet', () => {
22
+ const memory = cardShapeMemory('test.shapes', { firstDraw: { issue: { summary: false, footer: 'pickers' } } })
23
+ expect(memory.of('b', 'issue')).toEqual({ summary: false, footer: 'pickers' })
24
+ expect(memory.of('b', 'project')).toBeUndefined()
25
+ })
26
+
27
+ it('keeps only the parts a placeholder draws, and a bad stored value draws no page of bars', () => {
28
+ localStorage.setItem('test.shapes', JSON.stringify([['a', { rows: 9999, footer: 'nonsense', height: -4, extra: 'x' }], ['b', 'not a shape'], 'junk']))
29
+ expect(cardShapeMemory('test.shapes').of('a', 'issue')).toEqual({ subtitle: false, summary: false, rows: 10, latest: false, ring: false, footer: 'line' })
30
+ expect(cardShapeMemory('test.shapes').of('b', 'issue')).toBeUndefined()
31
+ })
32
+
33
+ it('keeps only the newest, up to its limit, and forgets everything at sign-out', () => {
34
+ const memory = cardShapeMemory('test.shapes', { limit: 2 })
35
+ memory.note('a', SHAPE)
36
+ memory.note('b', SHAPE)
37
+ memory.note('c', SHAPE)
38
+ const next = cardShapeMemory('test.shapes', { limit: 2 })
39
+ expect(next.of('a', 'issue')).toBeUndefined()
40
+ expect(next.of('c', 'issue')).toEqual(SHAPE)
41
+ next.clear()
42
+ expect(cardShapeMemory('test.shapes').of('c', 'issue')).toBeUndefined()
43
+ })
44
+ })
45
+
12
46
  describe('unavailableMemory', () => {
13
47
  it('remembers a link it could not show across a reload', () => {
14
48
  unavailableMemory('test.unavailable').note('a', false)
package/src/linked.ts CHANGED
@@ -91,8 +91,14 @@ export interface Linked {
91
91
  href: string
92
92
  /** What the reader calls it, quietly before the title: "ABC-2". */
93
93
  key?: string
94
- /** What the app calls it, from its description of its files: "Issue", "Project", "Topic", "Document". Absent, the kind's own word. */
94
+ /**
95
+ * What it is, in a word, from its app's description of its files: "Issue", "Project", "Topic", "Document"; the app's
96
+ * name when its type has none (record a-file-is-labelled-by-its-type-not-its-app; `linkedFrom` does both). Absent,
97
+ * the kind's own word.
98
+ */
95
99
  noun?: string
100
+ /** Archived: its row and card say "Archived" in the line under the title, and its values read as words. */
101
+ archived?: boolean
96
102
  /** The line under a card's title: what it is in. Drawn after the key. */
97
103
  subtitle?: string
98
104
  /** Its short summary, a sentence or two. Without one a card shows the title alone. */
@@ -136,8 +142,10 @@ export interface LoadingShape {
136
142
 
137
143
  /**
138
144
  * Where a link's lookup stands. `loading` knows the kind from the address, and
139
- * a shape when the app remembers one; `unavailable` is deleted or not the
140
- * reader's to see, which read the same (Miky, 15 Oct).
145
+ * a shape when the app remembers one; `unavailable` is not the reader's to see
146
+ * ("Issue not available"), or `deleted` ("Issue deleted"), which a reader tells
147
+ * apart by a deletion naming the address (SPEC §13.6.1: deleted is not
148
+ * not-permitted). Written as a URL, it is that URL either way (`url`).
141
149
  */
142
150
  export type LinkState =
143
151
  | { state: 'loading'; kind: LinkedKind; shape?: LoadingShape }
@@ -148,6 +156,13 @@ export type LinkState =
148
156
  noun: string
149
157
  /** Where it may still open for someone who can: the app that owns it, and its address. */
150
158
  openIn?: { app: string; href: string }
159
+ /** Deleted, as a trusted deletion naming its address says (SPEC §13.6.1): "Issue deleted", with no way out. */
160
+ deleted?: boolean
161
+ /**
162
+ * The URL it was written as: drawn as that URL, a plain link, in place of "not available" or "deleted" (SPEC
163
+ * §13.1, C21). Those words are only for a link with no URL to fall back on, a `nostr:` reference.
164
+ */
165
+ url?: string
151
166
  }
152
167
  | { state: 'ready'; linked: Linked }
153
168
 
@@ -168,6 +183,96 @@ export function loadingShapeOf(linked: Linked): LoadingShape {
168
183
  }
169
184
  }
170
185
 
186
+ /** A card's shape, and the height it drew at in px: the height holds what the shape cannot say, a summary of two lines. */
187
+ export type CardShape = LoadingShape & { height?: number }
188
+
189
+ /**
190
+ * The shape each card last drew at on this device, so its placeholder the next
191
+ * time is the card's own height and nothing around it moves as it loads
192
+ * (Peek's peek#533 and #534, then Ship's copy). One per app, under its own
193
+ * key, in localStorage because the first paint reads it synchronously; the app
194
+ * clears it with the rest of the device's copy at sign-out.
195
+ */
196
+ export interface CardShapeMemory {
197
+ /** The shape the card for `id` took the last time this device drew it; before that, `firstDraw`'s for its kind, if any. */
198
+ of: (id: string, kind: LinkedKind) => CardShape | undefined
199
+ /** The shape a card just drew at: `loadingShapeOf(linked)`, and the height it measured. */
200
+ note: (id: string, shape: CardShape) => void
201
+ /** Sign-out. */
202
+ clear: () => void
203
+ }
204
+
205
+ const FOOTERS: readonly LoadingFooter[] = ['pickers', 'people', 'line', 'none']
206
+
207
+ /** A stored shape read back, only the parts a placeholder draws; anything else stored there is dropped. */
208
+ function storedCardShape(value: unknown): CardShape | undefined {
209
+ if (!value || typeof value !== 'object') return undefined
210
+ const { subtitle, summary, rows, latest, ring, footer, height } = value as Record<string, unknown>
211
+ return {
212
+ subtitle: subtitle === true,
213
+ summary: summary === true,
214
+ // A card lists a few of its items; a bad number must not draw a page of bars.
215
+ rows: typeof rows === 'number' && Number.isInteger(rows) ? Math.min(Math.max(rows, 0), 10) : 0,
216
+ latest: latest === true,
217
+ ring: ring === true,
218
+ footer: FOOTERS.find((one) => one === footer) ?? 'line',
219
+ ...(typeof height === 'number' && height > 0 && height < 2000 ? { height: Math.round(height) } : {}),
220
+ }
221
+ }
222
+
223
+ /**
224
+ * The device's memory of the shapes its cards drew at, under the app's own
225
+ * `storageKey`, keeping the newest `limit`. `firstDraw` is a kind's shape for
226
+ * a card this device has not drawn yet, where the kit's own placeholder for
227
+ * the kind is not the app's usual card. Peek's and Ship's `cardShapes`, lifted
228
+ * here for Leaf, the third app to need one.
229
+ */
230
+ export function cardShapeMemory(storageKey: string, options: { limit?: number; firstDraw?: Partial<Record<LinkedKind, LoadingShape>> } = {}): CardShapeMemory {
231
+ const { limit = 300, firstDraw = {} } = options
232
+ // Read once per page: a screen of cards asks many times.
233
+ let held: Map<string, CardShape> | undefined
234
+ const shapes = () => {
235
+ if (held) return held
236
+ held = new Map()
237
+ try {
238
+ const stored: unknown = JSON.parse(localStorage.getItem(storageKey) ?? '[]')
239
+ for (const entry of Array.isArray(stored) ? stored : []) {
240
+ const shape = Array.isArray(entry) && typeof entry[0] === 'string' ? storedCardShape(entry[1]) : undefined
241
+ if (shape) held.set(entry[0] as string, shape)
242
+ }
243
+ } catch {
244
+ held = new Map()
245
+ }
246
+ return held
247
+ }
248
+ return {
249
+ of: (id, kind) => shapes().get(id) ?? firstDraw[kind],
250
+ note: (id, shape) => {
251
+ const current = shapes()
252
+ // Already the card drawn last, as it is now: nothing to move or write.
253
+ if ([...current.keys()].at(-1) === id && JSON.stringify(current.get(id)) === JSON.stringify(shape)) return
254
+ const next = new Map(current)
255
+ // Newest last, so the limit drops the cards drawn longest ago.
256
+ next.delete(id)
257
+ next.set(id, shape)
258
+ held = new Map([...next].slice(-limit))
259
+ try {
260
+ localStorage.setItem(storageKey, JSON.stringify([...held]))
261
+ } catch {
262
+ // Full or blocked storage: the shape is still held for this page.
263
+ }
264
+ },
265
+ clear: () => {
266
+ held = undefined
267
+ try {
268
+ localStorage.removeItem(storageKey)
269
+ } catch {
270
+ // Nothing to clear where storage is blocked.
271
+ }
272
+ },
273
+ }
274
+ }
275
+
171
276
  /**
172
277
  * What this device last found it could not show, kept so the next open draws
173
278
  * "not available." from the first paint instead of a card's height that then
@@ -11,6 +11,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
11
11
  import { LinkCard } from './LinkCard'
12
12
  import { LinkChip } from './LinkChip'
13
13
  import { linkStateFrom, type LinkedFromOptions, type LinkedSource } from './linkedFrom'
14
+ import { LinkRow } from './LinkRow'
14
15
 
15
16
  afterEach(cleanup)
16
17
 
@@ -215,15 +216,54 @@ describe('a file the reader cannot read', () => {
215
216
  expect(screen.queryByRole('link')).toBeNull()
216
217
  })
217
218
 
218
- it('is named by its address when its app gives it no noun', () => {
219
+ it('is named by its app when its type has no name, as the record a-file-is-labelled-by-its-type-not-its-app says', () => {
219
220
  render(<LinkCard link={linkStateFrom({ ...GROUP, unreachable: true, appName: 'App one' }, { kind: 'file', noun: 'Record' }, options())} />)
220
- expect(screen.getByText('Record not available')).toBeTruthy()
221
+ expect(screen.getByText('App one not available')).toBeTruthy()
221
222
  })
222
223
 
223
224
  it('reads as the address says while it loads and when nothing came back', () => {
224
225
  render(<LinkCard link={linkStateFrom(null, { kind: 'file', noun: 'Record' }, options())} />)
225
226
  expect(screen.getByText('Record not available')).toBeTruthy()
226
227
  })
228
+
229
+ it('says it was deleted when a trusted deletion names it, and offers no way out', () => {
230
+ render(<LinkCard link={linkStateFrom(null, { kind: 'file', noun: 'Record', deleted: true }, options())} />)
231
+ expect(screen.getByText('Record deleted')).toBeTruthy()
232
+ expect(screen.queryByRole('link')).toBeNull()
233
+ })
234
+
235
+ it('stays the URL it was written as, deleted or not available, in a chip, a row and a card alike', () => {
236
+ const url = 'https://app.example/item/one'
237
+ for (const unread of [{ kind: 'file' as const, noun: 'Record', url }, { kind: 'file' as const, noun: 'Record', url, deleted: true }]) {
238
+ for (const Widget of [LinkChip, LinkRow, LinkCard]) {
239
+ render(<Widget link={linkStateFrom(null, unread, options())} />)
240
+ expect(screen.getByRole('link', { name: url }).getAttribute('href')).toBe(url)
241
+ expect(screen.queryByText(/not available|deleted/)).toBeNull()
242
+ cleanup()
243
+ }
244
+ }
245
+ render(<LinkRow link={linkStateFrom({ ...GROUP, unreachable: true, appName: 'App one' }, { kind: 'file', noun: 'Record', url }, options())} />)
246
+ expect(screen.getByRole('link', { name: url })).toBeTruthy()
247
+ })
248
+ })
249
+
250
+ describe('what it is called, and whether it is archived', () => {
251
+ it('is called by its app when its type has no name, and by its type when it has one', () => {
252
+ const { rerender } = render(<LinkRow link={linkStateFrom({ ...GROUP, appName: 'App one' }, UNREAD, options())} preview={false} />)
253
+ expect(screen.getByText(/^ABC · App one/)).toBeTruthy()
254
+ rerender(<LinkRow link={linkStateFrom({ ...GROUP, noun: 'group', appName: 'App one' }, UNREAD, options())} preview={false} />)
255
+ expect(screen.getByText(/^ABC · Group/)).toBeTruthy()
256
+ })
257
+
258
+ it('says "Archived" on its row and its card, its values words', () => {
259
+ const archived = { ...GROUP, noun: 'group', archived: true }
260
+ render(<LinkRow link={linkStateFrom(archived, UNREAD, options())} preview={false} />)
261
+ expect(screen.getByText(/^ABC · Group · Archived/)).toBeTruthy()
262
+ cleanup()
263
+ render(<LinkCard link={linkStateFrom(archived, UNREAD, options({ onAct: () => {} }))} />)
264
+ expect(screen.getByText(/^ABC · Group · Archived/)).toBeTruthy()
265
+ expect(screen.queryByRole('combobox')).toBeNull()
266
+ })
227
267
  })
228
268
 
229
269
  describe('a message', () => {
package/src/linkedFrom.ts CHANGED
@@ -280,6 +280,7 @@ export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFro
280
280
  }
281
281
  const onAct = object.archived ? undefined : options.onAct
282
282
  const key = keyOf(object)
283
+ const noun = nounOf(object)
283
284
  const status = statusOf(object, onAct)
284
285
  const owner = ownerOf(object, options, onAct)
285
286
  const children = childrenOf(object, options)
@@ -292,7 +293,10 @@ export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFro
292
293
  title: titleOf(object),
293
294
  href,
294
295
  ...(key ? { key } : {}),
295
- ...(object.noun ? { noun: object.noun.charAt(0).toUpperCase() + object.noun.slice(1) } : {}),
296
+ // Its type's word, or its app's name when the type has none (record a-file-is-labelled-by-its-type-not-its-app).
297
+ ...(noun ? { noun } : {}),
298
+ // Its row and card say so, as its values turn to words above (Katerina, 30 Oct).
299
+ ...(object.archived ? { archived: true } : {}),
296
300
  // Interop reads every file kind's summary into its subtitle (SPEC §6.12).
297
301
  ...(slots.subtitle?.value ? { summary: slots.subtitle.value } : {}),
298
302
  ...(status ? { status } : {}),
@@ -307,24 +311,28 @@ export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFro
307
311
 
308
312
  /**
309
313
  * Where a reference's read stands, for the kit: `undefined` is still read,
310
- * `null` an answer of nothing. `unread` is what the app knows from the address
311
- * alone, for those two. Nothing, and a file the reader may not read, draw
312
- * alike: "not available." (Miky, 15 Oct).
314
+ * `null` an answer of nothing. `unread` is what the app knows without the
315
+ * object: its kind and noun from the address, whether a trusted deletion names
316
+ * it (`deleted`, SPEC §13.6.1: "Issue deleted", where nothing otherwise and a
317
+ * file the reader may not read draw alike, "not available"), and the URL it
318
+ * was written as (`url`), which it then reads as instead of either (§13.1).
313
319
  */
314
320
  export function linkStateFrom<T extends LinkedSource>(
315
321
  object: T | null | undefined,
316
- unread: { kind: LinkedKind; noun: string },
322
+ unread: { kind: LinkedKind; noun: string; deleted?: boolean; url?: string },
317
323
  options: LinkedFromOptions<T>,
318
324
  ): LinkState {
319
325
  if (object === undefined) return { state: 'loading', kind: unread.kind }
320
- if (object === null) return { state: 'unavailable', kind: unread.kind, noun: unread.noun }
326
+ const written = unread.url ? { url: unread.url } : {}
327
+ if (object === null) return { state: 'unavailable', kind: unread.kind, noun: unread.noun, ...(unread.deleted ? { deleted: true } : {}), ...written }
321
328
  if (object.unreachable) {
322
329
  const href = object.openUrl && /^https:\/\//i.test(object.openUrl) ? object.openUrl : undefined
323
330
  return {
324
331
  state: 'unavailable',
325
332
  kind: linkedKindOfKind(object.kind),
326
- noun: (object.noun && nounOf(object)) || unread.noun,
333
+ noun: nounOf(object) || unread.noun,
327
334
  ...(href ? { openIn: { app: object.appName ?? 'its app', href } } : {}),
335
+ ...written,
328
336
  }
329
337
  }
330
338
  return { state: 'ready', linked: linkedFrom(object, options) }
@@ -26,7 +26,7 @@ import { SCHEMA_VERSION, validateRegistry, type Registry, type RegistryEntry } f
26
26
  const root = process.cwd()
27
27
  const registry = buildRegistry({ root })
28
28
  /** Editor extensions: named like components by the catalogue, and not React components. */
29
- const EDITOR_EXTENSIONS = ['KeptSelection', 'BlockId', 'UnknownBlock', 'ReferenceNode', 'AttachmentNode', 'PersonMention', 'UrgentPersonMention', 'PersonReference', 'CaptionedReference', 'ReferenceTrigger', 'SlashCommands', 'PastedImages', 'PastedMarkdown', 'CodeBlockColours', 'Checklist', 'Callout', 'ReferenceCards', 'LinkChips', 'LinkPlaces', 'ReferenceMenu', 'CommentHighlights', 'ComposeKeys']
29
+ const EDITOR_EXTENSIONS = ['KeptSelection', 'BlockId', 'UnknownBlock', 'ReferenceNode', 'AttachmentNode', 'PersonMention', 'UrgentPersonMention', 'PersonReference', 'CaptionedReference', 'ReferenceTrigger', 'SlashCommands', 'PastedImages', 'PastedMarkdown', 'CodeBlockColours', 'Checklist', 'Callout', 'LinkChips', 'LinkPlaces', 'ReferenceMenu', 'CommentHighlights', 'ComposeKeys']
30
30
  const entry = (name: string): RegistryEntry => {
31
31
  const found = registry.entries.find((candidate) => candidate.name === name)
32
32
  if (!found) throw new Error(`no entry for ${name}`)
@@ -48,19 +48,19 @@ describe('the registry builds', () => {
48
48
  expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
49
49
  })
50
50
 
51
- it('counts 211 names over 98 files: 139 components, 69 helpers and 3 hooks (inTheBox, a card or part in a box being written in, on the files’ fill and in words, on 29 October; archivedLine, the line on an archived file in every app (PEEKM-2), on 23 October; keepCommentBoxWarm, a box built ahead, exported as 0.84.0 promised (PEEKM-1), on 21 October;linkedFrom and linkStateFrom, one card for a file in every app (5ebf2756), on 21 October; ComposeBox, ComposeKeys and COMPOSE_EDITOR_CLASSES gone into CommentBox’s own frame (one box), on 21 October; LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
51
+ it('counts 210 names over 98 files: 138 components, 70 helpers and 2 hooks (cardShapeMemory, a card’s last shape on this device, lifted from Peek and Ship for Leaf, and ReferenceCards and useReferenceCards gone with their deprecated page, in the widget review, on 30 October; inTheBox, a card or part in a box being written in, on the files’ fill and in words, on 29 October; archivedLine, the line on an archived file in every app (PEEKM-2), on 23 October; keepCommentBoxWarm, a box built ahead, exported as 0.84.0 promised (PEEKM-1), on 21 October;linkedFrom and linkStateFrom, one card for a file in every app (5ebf2756), on 21 October; ComposeBox, ComposeKeys and COMPOSE_EDITOR_CLASSES gone into CommentBox’s own frame (one box), on 21 October; LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
52
52
  // The reconciliation GATES.md §24 explains. If this changes, that changes.
53
53
  // The `EDITOR_EXTENSIONS` count as components by their names; they are
54
54
  // editor extensions, documented on SelectionToolbar's, BlockNodes' and
55
55
  // ComposerTriggers' pages.
56
56
  const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
57
- expect(kinds).toEqual({ component: 139, helper: 69, hook: 3 })
57
+ expect(kinds).toEqual({ component: 138, helper: 70, hook: 2 })
58
58
  expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(98)
59
59
  })
60
60
 
61
61
  it('gives every entry a purpose, from its own page or from the comment above it', () => {
62
62
  expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
63
- expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(90)
63
+ expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(89)
64
64
  expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(121)
65
65
  })
66
66
 
@@ -262,8 +262,27 @@ describe('the ids point at something', () => {
262
262
 
263
263
  it('gives every component a page and a story, and only a helper none', () => {
264
264
  const without = registry.entries.filter((one) => one.docsId === null || one.storyId === null)
265
- // The helpers in a file with no page: cn, the shortcut names, the editor's suggestion wiring (documented on SuggestionMenu's page), and the link widgets' data helpers (documented on LinkCard's and LinkChip's pages; linkedFrom's on LinkCard's).
266
- expect(without.map((one) => one.name).sort()).toEqual(['archivedLine', 'chosenOf', 'cn', 'inTheBox', 'isApplePlatform', 'isSuggestionActive', 'isSuggestionOpen', 'linkStateFrom', 'linkedFrom', 'loadingShapeOf', 'shortcutLabel', 'suggestionPopup', 'unavailableMemory'])
265
+ // The helpers in a file with no page: cn, the shortcut names, the editor's suggestion wiring (documented on SuggestionMenu's page), the link widgets' data helpers (documented on LinkCard's and LinkChip's pages; linkedFrom's and cardShapeMemory's on LinkCard's), and a chip's card choice (ReferenceMenu writes it).
266
+ expect(without.map((one) => one.name).sort()).toEqual([
267
+ 'archivedLine',
268
+ 'cardShapeMemory',
269
+ 'chosenOf',
270
+ 'cn',
271
+ 'inTheBox',
272
+ 'isApplePlatform',
273
+ 'isSuggestionActive',
274
+ 'isSuggestionOpen',
275
+ 'linkStateFrom',
276
+ 'linkedFrom',
277
+ 'loadingShapeOf',
278
+ 'referenceAtSelection',
279
+ 'referenceCardPlacements',
280
+ 'setReferenceCard',
281
+ 'setReferenceCardAt',
282
+ 'shortcutLabel',
283
+ 'suggestionPopup',
284
+ 'unavailableMemory',
285
+ ])
267
286
  expect(without.every((one) => one.kind !== 'component')).toBe(true)
268
287
  })
269
288
 
@@ -1,86 +0,0 @@
1
- import { Meta, Canvas } from '@storybook/addon-docs/blocks'
2
- import * as ReferenceCardsStories from './ReferenceCards.stories'
3
-
4
- <Meta of={ReferenceCardsStories} />
5
-
6
- # ReferenceCards
7
-
8
- **Deprecated.** A new editor uses **LinkPlaces**. This stays only for an editor
9
- that has not moved yet.
10
-
11
- A chip in a document can ask for a card after its line: compact, detailed or
12
- none. The choice is the chip's own `embed`, so the card moves and goes with it.
13
- This draws no card itself. It places a slot after each line that asks for
14
- one, and the app draws its own card into it.
15
-
16
- <Canvas of={ReferenceCardsStories.InAnEditor} />
17
-
18
- ## When
19
-
20
- - **An editor of a document whose chips can carry a card**: pair it with
21
- **ReferenceNode**, which holds the choice, and **SelectionToolbar**, where
22
- the app offers it for the selected chip.
23
-
24
- ## When not
25
-
26
- - A new editor of a document → **LinkPlaces**: since §13.3's line rule, a
27
- card draws in a lone link's row's place, and a card on a link in a sentence
28
- draws nothing. **DocumentEditor** uses it; this stays for an editor that has
29
- not moved yet.
30
- - A document that is only read → **RichText**, with each block's cards drawn
31
- after it from the text's own description of them.
32
- - A text whose cards travel beside it rather than on its chips → the app keeps
33
- that choice itself, and this has nothing to read.
34
-
35
- ## How
36
-
37
- ```tsx
38
- import { createPortal } from 'react-dom'
39
- import { EditorContent, useEditor } from '@tiptap/react'
40
- import StarterKit from '@tiptap/starter-kit'
41
- import { ToolbarButton } from '@estiva-app/ui'
42
- import {
43
- BlockId,
44
- ReferenceCards,
45
- ReferenceNode,
46
- SelectionToolbar,
47
- referenceAtSelection,
48
- setReferenceCard,
49
- useReferenceCards,
50
- type ReferenceCard,
51
- type ReferenceViewProps,
52
- } from '@estiva-app/ui/editor'
53
-
54
- const Reference = ({ uri }: ReferenceViewProps) => <span>{uri}</span>
55
- const Cards = ({ cards }: { cards: ReferenceCard[] }) => <div>{cards.map((card) => card.layout).join(', ')}</div>
56
-
57
- const editor = useEditor({ extensions: [StarterKit, BlockId, ReferenceNode.configure({ view: Reference }), ReferenceCards] })
58
- const slots = useReferenceCards(editor)
59
- const chip = editor ? referenceAtSelection(editor.state) : null
60
-
61
- ;<>
62
- <EditorContent editor={editor} />
63
- {slots.map((slot) => createPortal(<Cards cards={slot.cards} />, slot.element, slot.key))}
64
- <SelectionToolbar editor={editor}>
65
- {chip && editor && (
66
- <ToolbarButton aria-label="Detailed" pressed={chip.layout === 'detailed'} onMouseDown={(e) => e.preventDefault()} onClick={() => setReferenceCard(editor, chip.layout === 'detailed' ? 'none' : 'detailed')}>
67
- D
68
- </ToolbarButton>
69
- )}
70
- </SelectionToolbar>
71
- </>
72
- ```
73
-
74
- - **A slot keeps its element while its line lives.** It is keyed by the
75
- line's block id, so typing above a card does not make it load again.
76
- - **The slot is not text.** It cannot be typed into or selected, and a click
77
- on a card stays the card's.
78
- - **A layout this version does not know draws as compact.** The writer asked
79
- for a card, and the smallest is the safe reading.
80
- - **Press without taking the focus.** A button in the toolbar prevents its
81
- press's default, or the editor loses the chip's selection and the toolbar
82
- goes.
83
-
84
- ## What it owns
85
-
86
- Nothing. It only draws. Clicks and keys are yours.
@@ -1,66 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite'
2
- // @estiva-escape(no-hand-rolled-behaviour): the slots ReferenceCards places inside the document are drawn into by a portal, which keeps the app's providers around its card
3
- import { createPortal } from 'react-dom'
4
- import { EditorContent, useEditor } from '@tiptap/react'
5
- import StarterKit from '@tiptap/starter-kit'
6
- import { BlockId, ReferenceNode } from './BlockNodes'
7
- import { Card } from './Card'
8
- import { ReferenceCards, useReferenceCards } from './ReferenceCards'
9
- import { richTextClassName } from './RichText'
10
-
11
- /**
12
- * A chip that asks for a card gets a slot after its line, and the app draws
13
- * its card there. Here the "card" is a stand-in box naming the layout: the real
14
- * one is the app's, which knows how to resolve what the chip points at.
15
- */
16
- const meta = {
17
- title: 'Writing/ReferenceCards',
18
- // On its way out: the sidebar says "deprecated" beside its name (.storybook/manager.ts).
19
- tags: ['deprecated'],
20
- parameters: { layout: 'padded' },
21
- } satisfies Meta
22
-
23
- export default meta
24
- type Story = StoryObj
25
-
26
- const ref = (uri: string, embed?: string) => ({ type: 'reference', attrs: { uri, ...(embed ? { embed } : {}) } })
27
-
28
- function Box() {
29
- const editor = useEditor({
30
- extensions: [StarterKit, BlockId, ReferenceNode, ReferenceCards],
31
- content: {
32
- type: 'doc',
33
- content: [
34
- { type: 'paragraph', attrs: { blockId: 'p1' }, content: [{ type: 'text', text: 'Blocked by ' }, ref('nostr:naddr1first', 'detailed'), { type: 'text', text: ' until it ships.' }] },
35
- { type: 'paragraph', attrs: { blockId: 'p2' }, content: [{ type: 'text', text: 'See also ' }, ref('nostr:naddr1second')] },
36
- { type: 'paragraph', attrs: { blockId: 'p3' }, content: [ref('nostr:naddr1third', 'compact')] },
37
- ],
38
- },
39
- editorProps: { attributes: { class: richTextClassName('default', 'outline-none'), 'aria-label': 'Text' } },
40
- })
41
- const slots = useReferenceCards(editor)
42
- // @estiva-escape(no-hand-rolled-behaviour): the app's card goes into the slot ReferenceCards placed after its line, inside the document; no Base UI part owns a place in an editor's text
43
- return (
44
- <Card fill="surface" className="flex w-[520px] flex-col gap-2 p-3">
45
- <EditorContent editor={editor} />
46
- {slots.map((slot) =>
47
- createPortal(
48
- <div className="mt-2 flex flex-col gap-2">
49
- {slot.cards.map((card, i) => (
50
- <Card key={`${card.uri}-${i}`} fill="surface" className="p-3">
51
- <span className="text-body-2 text-text-secondary">
52
- {card.layout} card for {card.uri}
53
- </span>
54
- </Card>
55
- ))}
56
- </div>,
57
- slot.element,
58
- slot.key,
59
- ),
60
- )}
61
- </Card>
62
- )
63
- }
64
-
65
- /** Three chips: a detailed card after the first line, none for the second, a compact one after the third. */
66
- export const InAnEditor: Story = { render: () => <Box /> }