@estiva-app/ui 0.91.1 → 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.
- package/dist/AppProvider.d.ts +7 -3
- package/dist/AppProvider.d.ts.map +1 -1
- package/dist/AttachedCard.d.ts +5 -1
- package/dist/AttachedCard.d.ts.map +1 -1
- package/dist/BlockNodes.d.ts +14 -1
- package/dist/BlockNodes.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +9 -2
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ComposerTriggers.d.ts +11 -2
- package/dist/ComposerTriggers.d.ts.map +1 -1
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/LinkCard.d.ts.map +1 -1
- package/dist/LinkChip.d.ts.map +1 -1
- package/dist/LinkChips.d.ts +2 -1
- package/dist/LinkChips.d.ts.map +1 -1
- package/dist/LinkParts.d.ts +6 -1
- package/dist/LinkParts.d.ts.map +1 -1
- package/dist/LinkPlaces.d.ts +7 -0
- package/dist/LinkPlaces.d.ts.map +1 -1
- package/dist/LinkRow.d.ts +29 -6
- package/dist/LinkRow.d.ts.map +1 -1
- package/dist/PartCard.d.ts +9 -2
- package/dist/PartCard.d.ts.map +1 -1
- package/dist/ReferenceCards.d.ts +9 -39
- package/dist/ReferenceCards.d.ts.map +1 -1
- package/dist/ReferenceMenu.d.ts.map +1 -1
- package/dist/Select.d.ts +7 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/editor.d.ts +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +204 -183
- package/dist/editor.js.map +3 -3
- package/dist/eslint/index.js +1 -1
- package/dist/eslint/index.js.map +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +172 -52
- package/dist/index.js.map +3 -3
- package/dist/linked.d.ts +48 -3
- package/dist/linked.d.ts.map +1 -1
- package/dist/linked.examples.d.ts +6 -0
- package/dist/linked.examples.d.ts.map +1 -1
- package/dist/linkedFrom.d.ts +7 -3
- package/dist/linkedFrom.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +78 -65
- package/src/AppProvider.mdx +7 -5
- package/src/AppProvider.test.tsx +15 -1
- package/src/AppProvider.tsx +13 -4
- package/src/AttachedCard.mdx +2 -1
- package/src/AttachedCard.test.tsx +28 -0
- package/src/AttachedCard.tsx +12 -2
- package/src/BlockNodes.mdx +8 -1
- package/src/BlockNodes.tsx +98 -11
- package/src/CommentBox.mdx +8 -2
- package/src/CommentBox.stories.tsx +28 -1
- package/src/CommentBox.test.tsx +64 -1
- package/src/CommentBox.tsx +44 -5
- package/src/ComposerTriggers.mdx +1 -0
- package/src/ComposerTriggers.tsx +34 -15
- package/src/DocumentEditor.mdx +1 -1
- package/src/DocumentEditor.stories.tsx +2 -2
- package/src/DocumentEditor.test.tsx +37 -7
- package/src/DocumentEditor.tsx +2 -1
- package/src/LinkCard.mdx +9 -5
- package/src/LinkCard.stories.tsx +17 -2
- package/src/LinkCard.test.tsx +21 -0
- package/src/LinkCard.tsx +35 -16
- package/src/LinkChip.mdx +6 -1
- package/src/LinkChip.stories.tsx +7 -1
- package/src/LinkChip.test.tsx +12 -0
- package/src/LinkChip.tsx +6 -2
- package/src/LinkChips.mdx +4 -3
- package/src/LinkChips.stories.tsx +2 -2
- package/src/LinkChips.test.tsx +1 -2
- package/src/LinkChips.ts +2 -1
- package/src/LinkParts.mdx +3 -2
- package/src/LinkParts.stories.tsx +8 -0
- package/src/LinkParts.tsx +43 -6
- package/src/LinkPlaces.mdx +3 -0
- package/src/LinkPlaces.ts +19 -0
- package/src/LinkRow.mdx +8 -2
- package/src/LinkRow.stories.tsx +14 -2
- package/src/LinkRow.test.tsx +31 -1
- package/src/LinkRow.tsx +69 -25
- package/src/PartCard.mdx +9 -1
- package/src/PartCard.stories.tsx +9 -0
- package/src/PartCard.test.tsx +13 -0
- package/src/PartCard.tsx +19 -5
- package/src/ReferenceCards.test.tsx +4 -35
- package/src/ReferenceCards.ts +10 -119
- package/src/ReferenceMenu.mdx +6 -4
- package/src/ReferenceMenu.test.tsx +67 -5
- package/src/ReferenceMenu.tsx +18 -7
- package/src/Select.mdx +4 -0
- package/src/Select.stories.tsx +11 -1
- package/src/Select.tsx +10 -2
- package/src/editor.ts +0 -3
- package/src/eslint/no-restyled-part.ts +1 -1
- package/src/index.ts +4 -1
- package/src/linked.examples.ts +6 -0
- package/src/linked.test.ts +35 -1
- package/src/linked.ts +108 -3
- package/src/linkedFrom.test.tsx +42 -2
- package/src/linkedFrom.ts +15 -7
- package/src/registry/registry.test.ts +25 -6
- package/src/ReferenceCards.mdx +0 -86
- package/src/ReferenceCards.stories.tsx +0 -66
|
@@ -260,13 +260,14 @@ describe('ReferenceMenu', () => {
|
|
|
260
260
|
})
|
|
261
261
|
|
|
262
262
|
describe('ReferenceMenuView', () => {
|
|
263
|
-
/** The app's drawing: a link, named by its place, that follows on a click. */
|
|
263
|
+
/** The app's drawing: a link, named by its place, that follows on a click; a card has room around its link. */
|
|
264
264
|
function Linked({ uri, place = 'chip' }: ReferenceViewProps) {
|
|
265
|
-
|
|
265
|
+
const link = (
|
|
266
266
|
<a href={`/o/${uri}`} data-place={place} onClick={(event) => (followed(uri), event.preventDefault())}>
|
|
267
267
|
Item
|
|
268
268
|
</a>
|
|
269
269
|
)
|
|
270
|
+
return place === 'card' ? <span data-testid="card">{link} Summary</span> : link
|
|
270
271
|
}
|
|
271
272
|
const followed = vi.fn()
|
|
272
273
|
|
|
@@ -323,7 +324,8 @@ describe('ReferenceMenuView', () => {
|
|
|
323
324
|
await waitFor(() => expect(screen.getByRole('link', { name: 'Item' }).getAttribute('data-place')).toBe('card'))
|
|
324
325
|
await waitFor(() => expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull())
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
// On a card, its empty space opens the menu; its own link takes the click (below).
|
|
328
|
+
fireEvent.click(screen.getByTestId('card'))
|
|
327
329
|
expect((await screen.findByRole('menuitemradio', { name: 'Card' })).getAttribute('aria-checked')).toBe('true')
|
|
328
330
|
fireEvent.mouseDown(screen.getByRole('menuitemradio', { name: 'Row' }))
|
|
329
331
|
// Row writes no `embed` at all, not `none`.
|
|
@@ -370,17 +372,77 @@ describe('ReferenceMenuView', () => {
|
|
|
370
372
|
expect(isReferenceMenuOpen(editor!.state)).toBe(false)
|
|
371
373
|
})
|
|
372
374
|
|
|
373
|
-
it('offers Open
|
|
375
|
+
it('offers Open on a link picked on an empty line once the app has drawn it', async () => {
|
|
374
376
|
render(<Harness content={para()} />)
|
|
375
377
|
await screen.findByRole('textbox')
|
|
376
378
|
act(() => {
|
|
377
|
-
editor!.commands.
|
|
379
|
+
editor!.commands.setTextSelection(editor!.state.doc.content.size - 1)
|
|
378
380
|
editor!.commands.insertContent([ref(V), { type: 'text', text: ' ' }])
|
|
379
381
|
})
|
|
380
382
|
expect((await screen.findAllByRole('menuitem', { name: 'Open' })).length).toBe(1)
|
|
381
383
|
expect(screen.getByRole('menuitemradio', { name: 'Row' }).getAttribute('aria-checked')).toBe('true')
|
|
382
384
|
})
|
|
383
385
|
|
|
386
|
+
it('follows a click on a card\'s own link while editing; its empty space opens the menu', async () => {
|
|
387
|
+
followed.mockClear()
|
|
388
|
+
render(<Harness content={para(ref(V, 'detailed'))} />)
|
|
389
|
+
fireEvent.click(await screen.findByRole('link', { name: 'Item' }))
|
|
390
|
+
expect(followed).toHaveBeenCalledWith(V)
|
|
391
|
+
expect(isReferenceMenuOpen(editor!.state)).toBe(false)
|
|
392
|
+
fireEvent.click(screen.getByTestId('card'))
|
|
393
|
+
expect(followed).toHaveBeenCalledTimes(1)
|
|
394
|
+
await screen.findByRole('menuitemradio', { name: 'Card' })
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
it('keeps a press on a card\'s picker from the text, so the caret does not take it and close the picker', async () => {
|
|
398
|
+
function WithPicker({ place = 'chip' }: ReferenceViewProps) {
|
|
399
|
+
return place === 'card' ? (
|
|
400
|
+
<span>
|
|
401
|
+
<button type="button">
|
|
402
|
+
<span>Status</span>
|
|
403
|
+
</button>
|
|
404
|
+
<span>Summary</span>
|
|
405
|
+
</span>
|
|
406
|
+
) : (
|
|
407
|
+
<span>Item</span>
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
function PickerHarness() {
|
|
411
|
+
const e = useEditor({ extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: WithPicker }), LinkPlaces, ReferenceMenu], content: para(ref(V, 'detailed')) })
|
|
412
|
+
editor = e ?? undefined
|
|
413
|
+
return <EditorContent editor={e} />
|
|
414
|
+
}
|
|
415
|
+
render(<PickerHarness />)
|
|
416
|
+
// fireEvent answers false when the press's default was prevented, which ProseMirror leaves alone.
|
|
417
|
+
expect(fireEvent.mouseDown(await screen.findByText('Status'))).toBe(false)
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
it('offers no Open on a link the app draws with nothing to click (a person, loading, not available), and no menu in a sentence', async () => {
|
|
421
|
+
// As the kit's chip draws a link still loading or not available, and a person with no page: words, no link.
|
|
422
|
+
const Words = () => <span>Item</span>
|
|
423
|
+
function WordsHarness({ content }: { content: Record<string, unknown> }) {
|
|
424
|
+
const e = useEditor({ extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Words }), LinkPlaces, ReferenceMenu], content })
|
|
425
|
+
editor = e ?? undefined
|
|
426
|
+
return (
|
|
427
|
+
<>
|
|
428
|
+
<EditorContent editor={e} />
|
|
429
|
+
<ReferenceMenuView editor={e} />
|
|
430
|
+
</>
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
render(<WordsHarness content={para(ref(V))} />)
|
|
434
|
+
fireEvent.click(await screen.findByText('Item'))
|
|
435
|
+
await screen.findByRole('menuitemradio', { name: 'Card' })
|
|
436
|
+
expect(screen.queryByRole('menuitem', { name: 'Open' })).toBeNull()
|
|
437
|
+
cleanup()
|
|
438
|
+
editor?.destroy()
|
|
439
|
+
|
|
440
|
+
render(<WordsHarness content={para({ type: 'text', text: 'See ' }, ref(V))} />)
|
|
441
|
+
fireEvent.click(await screen.findByText('Item'))
|
|
442
|
+
expect(isReferenceMenuOpen(editor!.state)).toBe(false)
|
|
443
|
+
expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull()
|
|
444
|
+
})
|
|
445
|
+
|
|
384
446
|
it('lets a click follow the link when the editor is not editable', async () => {
|
|
385
447
|
followed.mockClear()
|
|
386
448
|
render(<Harness content={para(ref(V))} />)
|
package/src/ReferenceMenu.tsx
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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/Select.mdx
CHANGED
|
@@ -20,6 +20,10 @@ corners and scrolling panels.
|
|
|
20
20
|
trigger and the list alike.
|
|
21
21
|
- Two sizes; `small` for dense rows and rails (it sits well inside
|
|
22
22
|
**Property**).
|
|
23
|
+
- Two fills: a form's `field` (default), and `wash` on a see-through card
|
|
24
|
+
(`Card fill="inset"`), one step over it, as a link card's pickers are. A
|
|
25
|
+
field's own fill there reads as a hole when the message behind is selected.
|
|
26
|
+
Leaf's fields are white and stay white.
|
|
23
27
|
|
|
24
28
|
<Canvas of={SelectStories.WithLeading} />
|
|
25
29
|
|
package/src/Select.stories.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState, type ComponentProps } from 'react'
|
|
3
3
|
import { Avatar } from './Avatar'
|
|
4
|
+
import { Card } from './Card'
|
|
4
5
|
import { Field } from './Field'
|
|
5
6
|
import { Select } from './Select'
|
|
6
7
|
import { TextInput } from './TextInput'
|
|
@@ -32,7 +33,7 @@ const meta = {
|
|
|
32
33
|
],
|
|
33
34
|
ariaLabel: 'Status',
|
|
34
35
|
},
|
|
35
|
-
argTypes: { size: { control: 'inline-radio', options: ['default', 'small'] } },
|
|
36
|
+
argTypes: { size: { control: 'inline-radio', options: ['default', 'small'] }, fill: { control: 'inline-radio', options: ['field', 'wash'] } },
|
|
36
37
|
} satisfies Meta<typeof Select>
|
|
37
38
|
|
|
38
39
|
export default meta
|
|
@@ -59,6 +60,15 @@ export const Empty: Story = {
|
|
|
59
60
|
/** The dense size, matching `Button`'s small — for property rows, where a full-height field would dominate the label beside it. */
|
|
60
61
|
export const Small: Story = { render: (args) => <Demo {...args} size="small" initial="todo" /> }
|
|
61
62
|
|
|
63
|
+
/** `fill="wash"` on a see-through card, as a link card's pickers: one step over the card, so a selected message's tint shows through both. */
|
|
64
|
+
export const OnASeeThroughCard: Story = {
|
|
65
|
+
render: (args) => (
|
|
66
|
+
<Card fill="inset" className="flex gap-2 p-3">
|
|
67
|
+
<Demo {...args} size="small" fill="wash" className="w-auto" initial="in_progress" />
|
|
68
|
+
</Card>
|
|
69
|
+
),
|
|
70
|
+
}
|
|
71
|
+
|
|
62
72
|
/** An option may carry a `leading` node — a face beside a person's name — shown in the trigger and in the list. Ship's addition. */
|
|
63
73
|
export const WithLeading: Story = {
|
|
64
74
|
render: (args) => (
|
package/src/Select.tsx
CHANGED
|
@@ -47,6 +47,12 @@ export interface SelectProps {
|
|
|
47
47
|
onChange: (value: string) => void
|
|
48
48
|
options: SelectOption[]
|
|
49
49
|
size?: 'default' | 'small'
|
|
50
|
+
/**
|
|
51
|
+
* What the trigger is filled with: a form's `field` (default), or the see-through `wash` on a see-through card,
|
|
52
|
+
* one step over it, as the card is over the message (a link card's pickers; Katerina, 30 Oct: the field's fill
|
|
53
|
+
* read as a dark hole in a card on a selected message). Leaf's white fields stay white.
|
|
54
|
+
*/
|
|
55
|
+
fill?: 'field' | 'wash'
|
|
50
56
|
ariaLabel?: string
|
|
51
57
|
/** Set by a `Field` with `required`; a caller inside one owes nothing. */
|
|
52
58
|
'aria-required'?: boolean | 'true' | 'false'
|
|
@@ -68,7 +74,7 @@ export interface SelectProps {
|
|
|
68
74
|
const GAP = 4
|
|
69
75
|
const VIEWPORT_PAD = 8
|
|
70
76
|
|
|
71
|
-
export function Select({ value, onChange, options, size = 'default', ariaLabel, placeholder = 'Select…', disabled, disabledReason, className, ...aria }: SelectProps) {
|
|
77
|
+
export function Select({ value, onChange, options, size = 'default', fill = 'field', ariaLabel, placeholder = 'Select…', disabled, disabledReason, className, ...aria }: SelectProps) {
|
|
72
78
|
const selected = options.find((o) => o.value === value)
|
|
73
79
|
// With a reason it is held shut rather than disabled: a disabled trigger is
|
|
74
80
|
// a native `disabled` button, which Tab skips and a tooltip cannot open on.
|
|
@@ -88,7 +94,9 @@ export function Select({ value, onChange, options, size = 'default', ariaLabel,
|
|
|
88
94
|
* `truncate` from ever engaging; in a block container max-w-full is
|
|
89
95
|
* the cap. Full-width callers are unaffected.
|
|
90
96
|
*/
|
|
91
|
-
'flex w-full min-w-0 max-w-full items-center justify-between gap-2 rounded-lg border
|
|
97
|
+
'flex w-full min-w-0 max-w-full items-center justify-between gap-2 rounded-lg border text-left',
|
|
98
|
+
// Leaf's fields are white, raised on their shadow, and stay so on a card: they never read as a hole (Katerina, 30 Oct).
|
|
99
|
+
fill === 'wash' ? 'bg-bg-wash leaf:bg-bg-field leaf:shadow-field' : 'bg-bg-field shadow-field',
|
|
92
100
|
'border-border-field outline-none transition-colors',
|
|
93
101
|
FIELD_TEXT_CLASSES,
|
|
94
102
|
// The focused border survives a hover: hover alone strengthens the
|
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'
|
|
@@ -159,7 +159,7 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
|
|
|
159
159
|
SectionHeader: ['hover', 'look'],
|
|
160
160
|
SectionLabel: ['tone', 'truncate'],
|
|
161
161
|
ShowMore: ['surface'],
|
|
162
|
-
Select: ['size'],
|
|
162
|
+
Select: ['size', 'fill'],
|
|
163
163
|
Tabs: ['size'],
|
|
164
164
|
TextInput: ['size'],
|
|
165
165
|
Toast: ['type'],
|
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'
|
package/src/linked.examples.ts
CHANGED
|
@@ -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 }
|
package/src/linked.test.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
140
|
-
*
|
|
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
|
package/src/linkedFrom.test.tsx
CHANGED
|
@@ -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
|
|
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('
|
|
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
|
-
|
|
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
|
|
311
|
-
*
|
|
312
|
-
*
|
|
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
|
-
|
|
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:
|
|
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) }
|