@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
@@ -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 /> }