@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
package/src/LinkRow.stories.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
-
import { GROUP, ITEM, ITEM_UNREAD, LOADING, PAGE, PLACE, ready, SAID, UNAVAILABLE } from './linked.examples'
|
|
2
|
+
import { DELETED, GROUP, ITEM, ITEM_ARCHIVED, ITEM_UNREAD, LOADING, PAGE, PLACE, ready, SAID, UNAVAILABLE, WRITTEN_AS_A_URL } from './linked.examples'
|
|
3
3
|
import { LinkRow, LinkUnavailable } from './LinkRow'
|
|
4
4
|
|
|
5
5
|
const meta = {
|
|
@@ -32,12 +32,24 @@ export const EachKind: Story = {
|
|
|
32
32
|
/** Something unread in its conversation, to a member: the count shows, with its dot. */
|
|
33
33
|
export const Unread: Story = { args: { link: ready(ITEM_UNREAD) } }
|
|
34
34
|
|
|
35
|
+
/** Words a person wrote, on one line: their face, their name, the words cut to fit, the time. */
|
|
36
|
+
export const WordsAPersonWrote: Story = { args: { link: ready(SAID) } }
|
|
37
|
+
|
|
38
|
+
/** Archived: "Archived" in the line under its title. */
|
|
39
|
+
export const Archived: Story = { args: { link: ready(ITEM_ARCHIVED) } }
|
|
40
|
+
|
|
35
41
|
/** Still being looked up: the row in bars, at the row's height. */
|
|
36
42
|
export const Loading: Story = { args: { link: LOADING } }
|
|
37
43
|
|
|
38
|
-
/**
|
|
44
|
+
/** Not this reader's to see: one line, and where it may still open. */
|
|
39
45
|
export const NotAvailable: Story = { args: { link: UNAVAILABLE } }
|
|
40
46
|
|
|
47
|
+
/** Deleted, as a trusted deletion naming it says: the same line, its own words, and no way out. */
|
|
48
|
+
export const Deleted: Story = { args: { link: DELETED } }
|
|
49
|
+
|
|
50
|
+
/** Written as a URL that cannot be shown: it stays that URL, a plain link, in the row's place. */
|
|
51
|
+
export const WrittenAsAUrl: Story = { args: { link: WRITTEN_AS_A_URL } }
|
|
52
|
+
|
|
41
53
|
/** The not-available line on its own, as a card or a part draws it too; without `openIn`, no way out. */
|
|
42
54
|
export const NotAvailableLine: Story = {
|
|
43
55
|
render: () => (
|
package/src/LinkRow.test.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/** What the LinkRow page claims, pinned: where the row and its count lead, and when the count shows. */
|
|
3
3
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
4
4
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
-
import { ITEM, ITEM_UNREAD, LOADING, PLACE, ready, UNAVAILABLE } from './linked.examples'
|
|
5
|
+
import { DELETED, ITEM, ITEM_UNREAD, LOADING, PLACE, ready, SAID, UNAVAILABLE } from './linked.examples'
|
|
6
6
|
import { LinkRow } from './LinkRow'
|
|
7
7
|
|
|
8
8
|
afterEach(cleanup)
|
|
@@ -35,4 +35,34 @@ describe('LinkRow', () => {
|
|
|
35
35
|
render(<LinkRow link={UNAVAILABLE} />)
|
|
36
36
|
expect(screen.getByText('Issue not available')).toBeTruthy()
|
|
37
37
|
})
|
|
38
|
+
|
|
39
|
+
it('says its count whole, one comment or several, never the figure run into the noun', () => {
|
|
40
|
+
const { rerender } = render(<LinkRow link={ready({ ...ITEM, conversation: { count: 1, href: '#c' } })} preview={false} />)
|
|
41
|
+
expect(screen.getByRole('link', { name: '1 comment — open the conversation' })).toBeTruthy()
|
|
42
|
+
rerender(<LinkRow link={ready({ ...ITEM, conversation: { count: 3, href: '#c' } })} preview={false} />)
|
|
43
|
+
expect(screen.getByRole('link', { name: '3 comments — open the conversation' })).toBeTruthy()
|
|
44
|
+
rerender(<LinkRow link={ready({ ...ITEM, conversation: { count: 1, href: '#c', noun: 'conversations' } })} preview={false} />)
|
|
45
|
+
expect(screen.getByRole('link', { name: '1 conversation — open the conversation' })).toBeTruthy()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('draws a file with no address to open as words, its title and its count no links', () => {
|
|
49
|
+
const { container } = render(<LinkRow link={ready({ ...ITEM, href: '', conversation: { count: 3, href: '' } })} preview={false} />)
|
|
50
|
+
expect(screen.queryByRole('link')).toBeNull()
|
|
51
|
+
expect(container.querySelector('a')).toBeNull()
|
|
52
|
+
expect(screen.getByText(ITEM.title)).toBeTruthy()
|
|
53
|
+
expect(screen.getByText('3 comments')).toBeTruthy()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('says it was deleted, apart from not available, with no way out', () => {
|
|
57
|
+
render(<LinkRow link={DELETED} />)
|
|
58
|
+
expect(screen.getByText('Issue deleted')).toBeTruthy()
|
|
59
|
+
expect(screen.queryByRole('link')).toBeNull()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('draws a person’s words on one line: the face, the name, the words cut to fit, the time', () => {
|
|
63
|
+
render(<LinkRow link={ready(SAID)} preview={false} />)
|
|
64
|
+
const name = screen.getByRole('link', { name: SAID.author!.name })
|
|
65
|
+
const line = name.parentElement!.parentElement!
|
|
66
|
+
expect(line.textContent).toBe(`${SAID.author!.name}${SAID.body}${SAID.updated}`)
|
|
67
|
+
})
|
|
38
68
|
})
|
package/src/LinkRow.tsx
CHANGED
|
@@ -28,25 +28,41 @@ export interface LinkUnavailableProps {
|
|
|
28
28
|
openIn?: { app: string; href: string }
|
|
29
29
|
/** In a card's place: a card's 12px round it. Default a row's. */
|
|
30
30
|
card?: boolean
|
|
31
|
+
/** Deleted (SPEC §13.6.1): "Issue deleted", and no way out, since there is nothing left to open. */
|
|
32
|
+
deleted?: boolean
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/** A row's frame: the tile, the two lines and the marks, 6px round the tile. */
|
|
34
36
|
const ROW_CLASSES = 'flex items-center gap-3 p-1.5 pr-3'
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
|
-
* Not available:
|
|
38
|
-
* Drawn as the row or the card it
|
|
39
|
-
* (Katerina, 29 Oct: "same styling
|
|
40
|
-
* The way out stays, since the app
|
|
39
|
+
* Not available: not this reader's to see, or deleted, which says so (SPEC
|
|
40
|
+
* §13.6.1: deleted is not not-permitted). Drawn as the row or the card it
|
|
41
|
+
* would have been, on the same fill and edge (Katerina, 29 Oct: "same styling
|
|
42
|
+
* as the linkcard default"), its words muted. The way out stays, since the app
|
|
43
|
+
* it lives in may still open it for you; a deleted one has none.
|
|
41
44
|
*/
|
|
42
|
-
export function LinkUnavailable({ kind, noun, openIn, card = false }: LinkUnavailableProps) {
|
|
45
|
+
export function LinkUnavailable({ kind, noun, openIn, card = false, deleted = false }: LinkUnavailableProps) {
|
|
46
|
+
return <UnavailableRow kind={kind} words={`${noun} ${deleted ? 'deleted' : 'not available'}`} openIn={deleted ? undefined : openIn} card={card} />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The not-available row with the words it is given; `href` makes the words a link (a part that can't be shown opens its whole file). */
|
|
50
|
+
export function UnavailableRow({ kind, words, href, openIn, card = false }: { kind: LinkedKind; words: string; href?: string; openIn?: { app: string; href: string }; card?: boolean }) {
|
|
43
51
|
const wide = useContext(inTheBox)
|
|
44
52
|
return (
|
|
45
53
|
<Card fill={wide ? 'elevated' : 'inset'} className={cn(card ? 'flex items-center gap-3 p-3' : ROW_CLASSES, 'max-w-[480px]')}>
|
|
46
54
|
<span className={TYPE_TILE_CLASSES}>
|
|
47
55
|
<LinkedIcon kind={kind} />
|
|
48
56
|
</span>
|
|
49
|
-
<span className="min-w-0 flex-1 truncate text-body-2 text-text-muted">
|
|
57
|
+
<span className="min-w-0 flex-1 truncate text-body-2 text-text-muted">
|
|
58
|
+
{href && !wide ? (
|
|
59
|
+
<Link href={href} variant="quiet">
|
|
60
|
+
{words}
|
|
61
|
+
</Link>
|
|
62
|
+
) : (
|
|
63
|
+
words
|
|
64
|
+
)}
|
|
65
|
+
</span>
|
|
50
66
|
{openIn && (
|
|
51
67
|
<span className="shrink-0 text-caption text-text-secondary">
|
|
52
68
|
<Link href={openIn.href} variant="quiet" external>
|
|
@@ -58,9 +74,23 @@ export function LinkUnavailable({ kind, noun, openIn, card = false }: LinkUnavai
|
|
|
58
74
|
)
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
/** The line under a row's or a card's title: its key and what it is, then where it lives and when, as far as the app says. */
|
|
77
|
+
/** The line under a row's or a card's title: its key and what it is, whether it is archived, then where it lives and when, as far as the app says. */
|
|
62
78
|
export function linkMetaOf(linked: Linked, withWhen = false): string {
|
|
63
|
-
return [linked.key, kindNounOf(linked), linked.subtitle, withWhen ? linked.updated : undefined].filter(Boolean).join(' · ')
|
|
79
|
+
return [linked.key, kindNounOf(linked), linked.archived ? 'Archived' : undefined, linked.subtitle, withWhen ? linked.updated : undefined].filter(Boolean).join(' · ')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A link written as a URL that cannot be shown stays that URL, a plain link as
|
|
84
|
+
* a message draws one (SPEC §13.1, C21), in a chip's, a row's or a card's
|
|
85
|
+
* place alike.
|
|
86
|
+
*/
|
|
87
|
+
export function WrittenUrl({ url, block = false }: { url: string; block?: boolean }) {
|
|
88
|
+
const link = (
|
|
89
|
+
<Link href={url} external>
|
|
90
|
+
{url}
|
|
91
|
+
</Link>
|
|
92
|
+
)
|
|
93
|
+
return block ? <span className="block min-w-0 truncate text-body-2">{link}</span> : link
|
|
64
94
|
}
|
|
65
95
|
|
|
66
96
|
export interface LinkRowProps {
|
|
@@ -87,35 +117,49 @@ export function LinkRow({ link, preview = true }: LinkRowProps) {
|
|
|
87
117
|
</div>
|
|
88
118
|
)
|
|
89
119
|
}
|
|
90
|
-
if (link.state === 'unavailable')
|
|
120
|
+
if (link.state === 'unavailable') {
|
|
121
|
+
if (link.url) return <WrittenUrl url={link.url} block />
|
|
122
|
+
return <LinkUnavailable kind={link.kind} noun={link.noun} openIn={link.openIn} deleted={link.deleted} />
|
|
123
|
+
}
|
|
91
124
|
const { linked } = link
|
|
92
125
|
const status = chosenOf(linked.status)
|
|
93
126
|
const owner = chosenOf(linked.owner)
|
|
94
127
|
const said = linked.kind === 'message' ? linked.author : undefined
|
|
95
|
-
const meta = said ?
|
|
128
|
+
const meta = said ? '' : linkMetaOf(linked, true) || linked.summary
|
|
96
129
|
const row = (
|
|
97
130
|
<Card fill="inset" hover="hairline" className={cn('relative', ROW_CLASSES, width)}>
|
|
98
131
|
<LinkTile kind={linked.kind} author={said} />
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
132
|
+
{said ? (
|
|
133
|
+
// Words a person wrote, on one line, as a quote is cut to one (Katerina, 30 Oct): the face, the name, the words
|
|
134
|
+
// cut to fit, the time.
|
|
135
|
+
<span className="flex min-w-0 flex-1 items-baseline gap-2">
|
|
136
|
+
<span className="contents text-body-2-strong text-text-primary">
|
|
137
|
+
{linked.href ? (
|
|
138
|
+
<Link href={linked.href} variant="quiet" cover truncate className="min-w-0">
|
|
105
139
|
{said.name}
|
|
106
140
|
</Link>
|
|
107
|
-
|
|
108
|
-
|
|
141
|
+
) : (
|
|
142
|
+
<span className="min-w-0 truncate">{said.name}</span>
|
|
143
|
+
)}
|
|
109
144
|
</span>
|
|
110
|
-
|
|
145
|
+
{linked.body && <span className="min-w-0 flex-1 truncate text-caption text-text-secondary">{linked.body}</span>}
|
|
146
|
+
{linked.updated && <span className={cn('ml-auto shrink-0 text-caption text-text-muted', TIME_CLASSES)}>{linked.updated}</span>}
|
|
147
|
+
</span>
|
|
148
|
+
) : (
|
|
149
|
+
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
111
150
|
<span className="contents text-body-2-strong text-text-primary">
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
151
|
+
{/* Another app's file with no address to open (none over https): its title is words, not a link to nowhere. */}
|
|
152
|
+
{linked.href ? (
|
|
153
|
+
<Link href={linked.href} variant="quiet" cover truncate>
|
|
154
|
+
{linked.title}
|
|
155
|
+
</Link>
|
|
156
|
+
) : (
|
|
157
|
+
<span className="truncate">{linked.title}</span>
|
|
158
|
+
)}
|
|
115
159
|
</span>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
160
|
+
{meta && <span className="truncate text-caption text-text-secondary">{meta}</span>}
|
|
161
|
+
</span>
|
|
162
|
+
)}
|
|
119
163
|
{/* On the title's line, not halfway down the row: the state, the comments, then the faces at the far right. */}
|
|
120
164
|
<span className="flex h-[19.6px] shrink-0 items-center gap-2 self-start">
|
|
121
165
|
{/* A ring already says how far along it is. */}
|
package/src/PartCard.mdx
CHANGED
|
@@ -14,7 +14,15 @@ A part of something longer, shared live: its blocks as they are now, under the t
|
|
|
14
14
|
- **ready** — what it is part of, as a card starts: its kind in a file's 36px tile, its title as the link, and "A part of ABC-2" under it; then the blocks the app draws as `children`, behind a quote bar that starts where the tile does. The apps draw the blocks with **RichText** `size="small"`.
|
|
15
15
|
- **with its way out** — `action`, a small `Button` ("Open in Leaf"), under the blocks at the right, outside the quote bar; with `maxHeight` a long part is cut behind Show more, the two level on one row.
|
|
16
16
|
- **loading** — at a card's height.
|
|
17
|
-
- **unavailable** — one row: "A part of this issue not available", in the app's word for it, else its kind's.
|
|
17
|
+
- **unavailable** — one row: "A part of this issue not available", in the app's word for it, else its kind's. Not the reader's to see.
|
|
18
|
+
- **deleted** — what it is part of was deleted, as a trusted deletion naming it says (SPEC §13.6.1): the same row, "A part of this issue deleted".
|
|
19
|
+
- **detached** — what it is part of is still there and the part's block is gone: the same row, "This part was deleted".
|
|
20
|
+
- **unaddressable** — what it is part of has no blocks to take a part of: the same row, "This part can't be shown", its words opening the whole of it (`href`). Nothing was deleted.
|
|
21
|
+
|
|
22
|
+
The five are SPEC §13.6.1's, with its words; a reader tells them apart.
|
|
23
|
+
|
|
24
|
+
<Canvas of={PartCardStories.Detached} />
|
|
25
|
+
<Canvas of={PartCardStories.Unaddressable} />
|
|
18
26
|
|
|
19
27
|
## When not
|
|
20
28
|
|
package/src/PartCard.stories.tsx
CHANGED
|
@@ -60,3 +60,12 @@ export const Loading: Story = { args: { state: 'loading', kind: 'issue' } }
|
|
|
60
60
|
|
|
61
61
|
/** The part, or what it is part of, is gone or not this reader's to see. */
|
|
62
62
|
export const NotAvailable: Story = { args: { state: 'unavailable', kind: 'issue', noun: 'Issue', openIn: { app: 'App one', href: '#elsewhere' } } }
|
|
63
|
+
|
|
64
|
+
/** What it is part of was deleted, as a trusted deletion naming it says: no title. */
|
|
65
|
+
export const Deleted: Story = { args: { state: 'deleted', kind: 'issue', noun: 'Issue' } }
|
|
66
|
+
|
|
67
|
+
/** What it is part of is still there, and the part's block is gone. */
|
|
68
|
+
export const Detached: Story = { args: { state: 'detached', kind: 'issue', heading: 'Item one' } }
|
|
69
|
+
|
|
70
|
+
/** What it is part of has no blocks to show a part of: the words open the whole of it. */
|
|
71
|
+
export const Unaddressable: Story = { args: { state: 'unaddressable', kind: 'file', heading: 'Item one', href: '#whole' } }
|
package/src/PartCard.test.tsx
CHANGED
|
@@ -24,6 +24,19 @@ describe('PartCard', () => {
|
|
|
24
24
|
expect(screen.getByText('A part of this issue not available')).toBeTruthy()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
it('says what became of a part in the SPEC’s words: deleted with its file, its block deleted, or no part to show', () => {
|
|
28
|
+
render(<PartCard state="deleted" kind="issue" noun="Issue" />)
|
|
29
|
+
expect(screen.getByText('A part of this issue deleted')).toBeTruthy()
|
|
30
|
+
cleanup()
|
|
31
|
+
render(<PartCard state="detached" kind="issue" heading="Item one" href="#part" />)
|
|
32
|
+
expect(screen.getByText('This part was deleted')).toBeTruthy()
|
|
33
|
+
expect(screen.queryByRole('link')).toBeNull()
|
|
34
|
+
cleanup()
|
|
35
|
+
// What it is part of has no blocks: the words open the whole of it.
|
|
36
|
+
render(<PartCard state="unaddressable" kind="file" heading="Item one" href="#whole" />)
|
|
37
|
+
expect(screen.getByRole('link', { name: "This part can't be shown" }).getAttribute('href')).toBe('#whole')
|
|
38
|
+
})
|
|
39
|
+
|
|
27
40
|
it('while it loads, is busy and shows nothing of it', () => {
|
|
28
41
|
const { container } = render(<PartCard state="loading" kind="issue" />)
|
|
29
42
|
expect(container.querySelector('[aria-busy="true"]')).not.toBeNull()
|
package/src/PartCard.tsx
CHANGED
|
@@ -16,18 +16,26 @@ import { Link } from './Link'
|
|
|
16
16
|
import { LinkCardLoading } from './LinkCard'
|
|
17
17
|
import { inTheBox, type LinkedKind } from './linked'
|
|
18
18
|
import { kindNounOf, LinkTile } from './LinkParts'
|
|
19
|
-
import { LinkUnavailable } from './LinkRow'
|
|
19
|
+
import { LinkUnavailable, UnavailableRow } from './LinkRow'
|
|
20
20
|
import { QUOTE_BAR_CLASSES } from './looks'
|
|
21
21
|
import { ShowMore } from './ShowMore'
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Where a part's lookup stands, SPEC §13.6.1's five states and loading:
|
|
25
|
+
* `ready` (resolved), `unaddressable` (what it is part of has no blocks),
|
|
26
|
+
* `detached` (readable, its block gone), `deleted` (a trusted deletion names
|
|
27
|
+
* what it is part of) and `unavailable` (not the reader's to see).
|
|
28
|
+
*/
|
|
29
|
+
export type PartCardState = 'ready' | 'loading' | 'unavailable' | 'deleted' | 'detached' | 'unaddressable'
|
|
30
|
+
|
|
23
31
|
export interface PartCardProps {
|
|
24
32
|
/** Where its lookup stands. Default `ready`. */
|
|
25
|
-
state?:
|
|
33
|
+
state?: PartCardState
|
|
26
34
|
/** What it is part of, by its icon. */
|
|
27
35
|
kind: LinkedKind
|
|
28
36
|
/** The title of what it is part of. */
|
|
29
37
|
heading?: string
|
|
30
|
-
/** Opens what it is part of, at the part. */
|
|
38
|
+
/** Opens what it is part of, at the part; `unaddressable`, the whole of it. */
|
|
31
39
|
href?: string
|
|
32
40
|
/** The key of what it is part of: "ABC-2". */
|
|
33
41
|
partKey?: string
|
|
@@ -51,7 +59,12 @@ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun,
|
|
|
51
59
|
const word = noun ?? kindNounOf({ kind }) ?? 'File'
|
|
52
60
|
const boxed = useContext(inTheBox)
|
|
53
61
|
if (state === 'loading') return <LinkCardLoading kind={kind} shape={{ summary: true, rows: 0, footer: 'none' }} />
|
|
54
|
-
if (state === 'unavailable'
|
|
62
|
+
if (state === 'unavailable' || state === 'deleted') {
|
|
63
|
+
return <LinkUnavailable kind={kind} noun={`A part of this ${word.toLowerCase()}`} openIn={openIn} deleted={state === 'deleted'} card />
|
|
64
|
+
}
|
|
65
|
+
// The SPEC's words (§13.6.1): what it is part of is still there; the part is not, or cannot be one.
|
|
66
|
+
if (state === 'detached') return <UnavailableRow kind={kind} words="This part was deleted" card />
|
|
67
|
+
if (state === 'unaddressable') return <UnavailableRow kind={kind} words="This part can't be shown" href={href} card />
|
|
55
68
|
return (
|
|
56
69
|
// At most 480px wide, in a box too; in a box being written in, on the files' fill as the card beside it is.
|
|
57
70
|
<Card fill={boxed ? 'elevated' : 'inset'} className="flex max-w-[480px] flex-col gap-3 p-3">
|
|
@@ -59,7 +72,8 @@ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun,
|
|
|
59
72
|
<LinkTile kind={kind} />
|
|
60
73
|
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
61
74
|
<span className="block min-w-0 text-body-2-strong text-text-primary">
|
|
62
|
-
{
|
|
75
|
+
{/* In a box being written in, its words alone: the draft is not left for it. */}
|
|
76
|
+
{href && !boxed ? (
|
|
63
77
|
<Link href={href} variant="quiet" truncate className="block">
|
|
64
78
|
{heading}
|
|
65
79
|
</Link>
|
|
@@ -5,15 +5,14 @@
|
|
|
5
5
|
* after its line and keeps its element while the line lives.
|
|
6
6
|
*/
|
|
7
7
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
8
|
-
import {
|
|
9
|
-
import { createPortal } from 'react-dom'
|
|
8
|
+
import { cleanup } from '@testing-library/react'
|
|
10
9
|
import { Editor } from '@tiptap/core'
|
|
11
10
|
import { NodeSelection, TextSelection } from '@tiptap/pm/state'
|
|
12
11
|
import StarterKit from '@tiptap/starter-kit'
|
|
13
12
|
import { BlockId, ReferenceNode } from './BlockNodes'
|
|
14
|
-
import {
|
|
13
|
+
import { referenceAtSelection, referenceCardPlacements, setReferenceCard } from './ReferenceCards'
|
|
15
14
|
|
|
16
|
-
const EXTENSIONS = [StarterKit, BlockId, ReferenceNode
|
|
15
|
+
const EXTENSIONS = [StarterKit, BlockId, ReferenceNode]
|
|
17
16
|
const V = 'nostr:naddr1example'
|
|
18
17
|
const W = 'nostr:naddr1other'
|
|
19
18
|
|
|
@@ -55,7 +54,7 @@ describe('ReferenceNode keeps the card', () => {
|
|
|
55
54
|
})
|
|
56
55
|
|
|
57
56
|
describe('referenceCardPlacements', () => {
|
|
58
|
-
it('
|
|
57
|
+
it('finds each line whose chips chose a card, keyed by block id', () => {
|
|
59
58
|
editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
|
|
60
59
|
const placements = referenceCardPlacements(editor.state.doc)
|
|
61
60
|
expect(placements.map((p) => [p.key, p.cards])).toEqual([
|
|
@@ -64,14 +63,6 @@ describe('referenceCardPlacements', () => {
|
|
|
64
63
|
['b:i1', [{ uri: W, layout: 'compact' }]],
|
|
65
64
|
])
|
|
66
65
|
})
|
|
67
|
-
|
|
68
|
-
it('draws an empty, non-editable slot inside the line', () => {
|
|
69
|
-
editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
|
|
70
|
-
const slot = editor.view.dom.querySelector('[data-reference-cards="b:p1"]')
|
|
71
|
-
expect(slot?.getAttribute('contenteditable')).toBe('false')
|
|
72
|
-
expect(slot?.closest('p')?.textContent).toContain('for now')
|
|
73
|
-
expect(editor.view.dom.querySelectorAll('[data-reference-cards]')).toHaveLength(2)
|
|
74
|
-
})
|
|
75
66
|
})
|
|
76
67
|
|
|
77
68
|
describe('choosing a card', () => {
|
|
@@ -119,25 +110,3 @@ describe('choosing a card', () => {
|
|
|
119
110
|
expect(setReferenceCard(editor, 'compact')).toBe(false)
|
|
120
111
|
})
|
|
121
112
|
})
|
|
122
|
-
|
|
123
|
-
describe('useReferenceCards', () => {
|
|
124
|
-
function Cards({ ed }: { ed: Editor }) {
|
|
125
|
-
const slots = useReferenceCards(ed)
|
|
126
|
-
return <>{slots.map((s) => createPortal(<span data-card={s.cards.map((c) => c.layout).join(',')} />, s.element, s.key))}</>
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
it('portals the app\'s cards into the slots, and typing keeps the slot\'s element', () => {
|
|
130
|
-
editor = new Editor({ extensions: EXTENSIONS, content: DOCUMENT })
|
|
131
|
-
const ed = editor
|
|
132
|
-
render(<Cards ed={ed} />)
|
|
133
|
-
const before = ed.view.dom.querySelector('[data-reference-cards="b:p1"]')
|
|
134
|
-
expect(before?.querySelector('[data-card="detailed"]')).not.toBeNull()
|
|
135
|
-
|
|
136
|
-
act(() => {
|
|
137
|
-
ed.commands.insertContentAt(1, 'Still ')
|
|
138
|
-
})
|
|
139
|
-
const after = ed.view.dom.querySelector('[data-reference-cards="b:p1"]')
|
|
140
|
-
expect(after).toBe(before)
|
|
141
|
-
expect(after?.querySelector('[data-card="detailed"]')).not.toBeNull()
|
|
142
|
-
})
|
|
143
|
-
})
|
package/src/ReferenceCards.ts
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The card a block document's writer chose for a reference — SPEC §13.3, "A
|
|
3
|
+
* reference's card": `embed` on the `reference` node (`ReferenceNode`), so the
|
|
4
|
+
* card moves and goes with its chip. `ReferenceMenu` writes it (Show as Row or
|
|
5
|
+
* Card) and `LinkPlaces` draws it in the row's place.
|
|
4
6
|
*
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* draws nothing itself: after every textblock whose chips ask for a card it
|
|
9
|
-
* places one empty, non-editable slot, and `useReferenceCards` hands the app
|
|
10
|
-
* those slots to portal its cards into. A portal, rather than a React root per
|
|
11
|
-
* slot, keeps the app's providers around the card.
|
|
12
|
-
*
|
|
13
|
-
* **A slot keeps its element while its block lives.** It is keyed by the
|
|
14
|
-
* nearest block id (the `blockId` attribute), so typing above a card does not
|
|
15
|
-
* re-make its element, and the card does not reload on every keystroke.
|
|
16
|
-
*
|
|
17
|
-
* The slot sits at the end of the textblock, inside it: a paragraph's card is
|
|
18
|
-
* under the paragraph, a list item's under the item at its indent, a table
|
|
19
|
-
* cell's in the cell.
|
|
7
|
+
* The extension that placed a slot after each line for the app's card, and its
|
|
8
|
+
* hook, were deprecated by `LinkPlaces` and are gone (Katerina's widget review,
|
|
9
|
+
* 30 Oct): no app used them. What stays reads and writes the choice.
|
|
20
10
|
*/
|
|
21
|
-
import {
|
|
11
|
+
import type { Editor } from '@tiptap/core'
|
|
22
12
|
import type { Node as PmNode } from '@tiptap/pm/model'
|
|
23
|
-
import { NodeSelection,
|
|
24
|
-
import { Decoration, DecorationSet } from '@tiptap/pm/view'
|
|
25
|
-
import { useEffect, useState } from 'react'
|
|
13
|
+
import { NodeSelection, type EditorState } from '@tiptap/pm/state'
|
|
26
14
|
|
|
27
15
|
/** A layout a writer can choose; `none` is no card. */
|
|
28
16
|
export type ReferenceCardLayout = 'none' | 'compact' | 'detailed'
|
|
@@ -33,16 +21,9 @@ export interface ReferenceCard {
|
|
|
33
21
|
layout: Exclude<ReferenceCardLayout, 'none'>
|
|
34
22
|
}
|
|
35
23
|
|
|
36
|
-
/** One slot: where an app draws the cards of one line. */
|
|
37
|
-
export interface ReferenceCardSlot {
|
|
38
|
-
key: string
|
|
39
|
-
element: HTMLElement
|
|
40
|
-
cards: ReferenceCard[]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
24
|
interface Placement {
|
|
44
25
|
key: string
|
|
45
|
-
/** The end of the textblock's content
|
|
26
|
+
/** The end of the textblock's content. */
|
|
46
27
|
pos: number
|
|
47
28
|
cards: ReferenceCard[]
|
|
48
29
|
}
|
|
@@ -79,96 +60,6 @@ export function referenceCardPlacements(doc: PmNode): Placement[] {
|
|
|
79
60
|
return out
|
|
80
61
|
}
|
|
81
62
|
|
|
82
|
-
interface ReferenceCardsStorage {
|
|
83
|
-
/** One element per slot key, made once and reused, so the app's portal stays put. */
|
|
84
|
-
elements: Map<string, HTMLElement>
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const key = new PluginKey<DecorationSet>('referenceCards')
|
|
88
|
-
|
|
89
|
-
function elementFor(storage: ReferenceCardsStorage, slotKey: string): HTMLElement {
|
|
90
|
-
let element = storage.elements.get(slotKey)
|
|
91
|
-
if (!element) {
|
|
92
|
-
element = document.createElement('div')
|
|
93
|
-
element.setAttribute('data-reference-cards', slotKey)
|
|
94
|
-
element.setAttribute('contenteditable', 'false')
|
|
95
|
-
storage.elements.set(slotKey, element)
|
|
96
|
-
}
|
|
97
|
-
return element
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function storageOf(editor: Editor): ReferenceCardsStorage | undefined {
|
|
101
|
-
return (editor.storage as unknown as { referenceCards?: ReferenceCardsStorage }).referenceCards
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Places a slot after each line whose chips ask for a card. Pair it with
|
|
106
|
-
* `ReferenceNode`, and draw the cards with `useReferenceCards`.
|
|
107
|
-
*/
|
|
108
|
-
export const ReferenceCards = Extension.create<Record<string, never>, ReferenceCardsStorage>({
|
|
109
|
-
name: 'referenceCards',
|
|
110
|
-
addStorage() {
|
|
111
|
-
return { elements: new Map() }
|
|
112
|
-
},
|
|
113
|
-
addProseMirrorPlugins() {
|
|
114
|
-
const storage = this.storage
|
|
115
|
-
const decorate = (doc: PmNode) =>
|
|
116
|
-
DecorationSet.create(
|
|
117
|
-
doc,
|
|
118
|
-
referenceCardPlacements(doc).map((p) =>
|
|
119
|
-
Decoration.widget(p.pos, () => elementFor(storage, p.key), {
|
|
120
|
-
key: p.key,
|
|
121
|
-
side: 1,
|
|
122
|
-
ignoreSelection: true,
|
|
123
|
-
// A click on a card is the card's, not a caret placement in the line.
|
|
124
|
-
stopEvent: () => true,
|
|
125
|
-
}),
|
|
126
|
-
),
|
|
127
|
-
)
|
|
128
|
-
return [
|
|
129
|
-
new Plugin<DecorationSet>({
|
|
130
|
-
key,
|
|
131
|
-
state: {
|
|
132
|
-
init: (_, state) => decorate(state.doc),
|
|
133
|
-
apply: (tr, set) => (tr.docChanged ? decorate(tr.doc) : set),
|
|
134
|
-
},
|
|
135
|
-
props: { decorations: (state) => key.getState(state) },
|
|
136
|
-
}),
|
|
137
|
-
]
|
|
138
|
-
},
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The slots to draw cards into, kept current as the document changes. Draw
|
|
143
|
-
* each with `createPortal(<cards/>, slot.element)`, keyed by `slot.key`.
|
|
144
|
-
*/
|
|
145
|
-
export function useReferenceCards(editor: Editor | null): ReferenceCardSlot[] {
|
|
146
|
-
const [slots, setSlots] = useState<ReferenceCardSlot[]>([])
|
|
147
|
-
useEffect(() => {
|
|
148
|
-
if (!editor) return
|
|
149
|
-
const storage = storageOf(editor)
|
|
150
|
-
if (!storage) return
|
|
151
|
-
let last = ''
|
|
152
|
-
const read = () => {
|
|
153
|
-
if (editor.isDestroyed) return
|
|
154
|
-
const next = referenceCardPlacements(editor.state.doc).map((p) => ({ key: p.key, element: elementFor(storage, p.key), cards: p.cards }))
|
|
155
|
-
// Only a change in what is drawn re-renders the app; typing does not.
|
|
156
|
-
const signature = JSON.stringify(next.map((s) => [s.key, s.cards]))
|
|
157
|
-
if (signature === last) return
|
|
158
|
-
last = signature
|
|
159
|
-
const live = new Set(next.map((s) => s.key))
|
|
160
|
-
for (const k of storage.elements.keys()) if (!live.has(k)) storage.elements.delete(k)
|
|
161
|
-
setSlots(next)
|
|
162
|
-
}
|
|
163
|
-
read()
|
|
164
|
-
editor.on('transaction', read)
|
|
165
|
-
return () => {
|
|
166
|
-
editor.off('transaction', read)
|
|
167
|
-
}
|
|
168
|
-
}, [editor])
|
|
169
|
-
return slots
|
|
170
|
-
}
|
|
171
|
-
|
|
172
63
|
/**
|
|
173
64
|
* The chip the person has selected, with what it names and its card — or null.
|
|
174
65
|
*
|
package/src/ReferenceMenu.mdx
CHANGED
|
@@ -48,8 +48,9 @@ const editor = useEditor({
|
|
|
48
48
|
|
|
49
49
|
- **A click on a link while editing** — its chip, row or card — opens the menu
|
|
50
50
|
under it, instead of following it. Not editing, the click follows it. A
|
|
51
|
-
card's own
|
|
52
|
-
|
|
51
|
+
card's own links and controls take their click while editing too: its title
|
|
52
|
+
opens the file, its count the conversation, its status and owner change it.
|
|
53
|
+
Only a click on the card's empty space opens the menu.
|
|
53
54
|
- **A link just put in alone on its line** — pasted, picked with `[`, or a
|
|
54
55
|
pasted URL becoming its chip — opens the menu by itself. It takes no focus:
|
|
55
56
|
typing on closes it, and nothing is written. In a sentence it does not open:
|
|
@@ -60,8 +61,9 @@ const editor = useEditor({
|
|
|
60
61
|
- **Open** does what a click on the link does when reading: the app's link gets
|
|
61
62
|
the click. A link with nothing to click opens its URL in a new tab.
|
|
62
63
|
- Open is offered only when there is something to open: the link's own
|
|
63
|
-
control, or its URL. A
|
|
64
|
-
|
|
64
|
+
control as the app drew it, or its URL. A person, and a link still loading
|
|
65
|
+
or not available, have neither: no Open. A link in a sentence with neither
|
|
66
|
+
has no menu, and a click goes on to it.
|
|
65
67
|
- The menu closes when the editor loses focus, so a card is never chosen after
|
|
66
68
|
the editor has saved on leaving.
|
|
67
69
|
- Choosing Row or Card is an undo step; the menu closes.
|