@estiva-app/ui 0.82.0 → 0.83.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/BlockNodes.d.ts +16 -5
- package/dist/BlockNodes.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +2 -1
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/DocumentEditor.d.ts +8 -7
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/LinkPlaces.d.ts +51 -0
- package/dist/LinkPlaces.d.ts.map +1 -0
- package/dist/ReferenceMenu.d.ts.map +1 -1
- package/dist/editor.d.ts +1 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +260 -128
- package/dist/editor.js.map +4 -4
- package/dist/linked.examples.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +66 -15
- package/src/BlockNodes.tsx +36 -9
- package/src/CommentBox.mdx +2 -2
- package/src/CommentBox.test.tsx +7 -6
- package/src/CommentBox.tsx +3 -2
- package/src/DocumentEditor.mdx +9 -4
- package/src/DocumentEditor.stories.tsx +101 -15
- package/src/DocumentEditor.test.tsx +76 -11
- package/src/DocumentEditor.tsx +29 -19
- package/src/LinkPlaces.mdx +59 -0
- package/src/LinkPlaces.stories.tsx +60 -0
- package/src/LinkPlaces.test.ts +134 -0
- package/src/LinkPlaces.ts +169 -0
- package/src/ReferenceCards.mdx +4 -0
- package/src/ReferenceMenu.mdx +32 -24
- package/src/ReferenceMenu.stories.tsx +15 -16
- package/src/ReferenceMenu.test.tsx +161 -57
- package/src/ReferenceMenu.tsx +48 -44
- package/src/editor.ts +1 -0
- package/src/linked.examples.ts +4 -3
- package/src/pages.test.ts +2 -2
- package/src/registry/registry.test.ts +6 -6
- package/stories/Choosing.mdx +3 -2
package/src/ReferenceCards.mdx
CHANGED
|
@@ -20,6 +20,10 @@ one, and the app draws its own card into it.
|
|
|
20
20
|
|
|
21
21
|
## When not
|
|
22
22
|
|
|
23
|
+
- A new editor of a document → **LinkPlaces**: since §13.3's line rule, a
|
|
24
|
+
card draws in a lone link's row's place, and a card on a link in a sentence
|
|
25
|
+
draws nothing. **DocumentEditor** uses it; this stays for an editor that has
|
|
26
|
+
not moved yet.
|
|
23
27
|
- A document that is only read → **RichText**, with each block's cards drawn
|
|
24
28
|
after it from the text's own description of them.
|
|
25
29
|
- A text whose cards travel beside it rather than on its chips → the app keeps
|
package/src/ReferenceMenu.mdx
CHANGED
|
@@ -5,32 +5,34 @@ import * as ReferenceMenuStories from './ReferenceMenu.stories'
|
|
|
5
5
|
|
|
6
6
|
# ReferenceMenu
|
|
7
7
|
|
|
8
|
-
What a
|
|
9
|
-
|
|
8
|
+
What a link in a document offers whoever is writing it: **Open**, and — when
|
|
9
|
+
it is alone on its line — **Show as** Row or Card. Card puts its card in the
|
|
10
|
+
row's place; Row puts the row back. A link in a sentence, and a person or a
|
|
11
|
+
Folder alone on its line (which stay chips), offer Open only.
|
|
10
12
|
|
|
11
13
|
<Canvas of={ReferenceMenuStories.InAnEditor} />
|
|
12
14
|
|
|
13
15
|
## When
|
|
14
16
|
|
|
15
|
-
- **An editor of a document
|
|
16
|
-
**
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
- **An editor of a document**: pair it with **ReferenceNode**, which draws the
|
|
18
|
+
link, and **LinkPlaces**, which tells it where it sits. With **LinkChips**, a
|
|
19
|
+
pasted URL that becomes its chip opens the menu too. **DocumentEditor** has
|
|
20
|
+
all of them.
|
|
19
21
|
|
|
20
22
|
## When not
|
|
21
23
|
|
|
22
|
-
- A document that is only read → **RichText**: a click on a
|
|
23
|
-
-
|
|
24
|
-
|
|
24
|
+
- A document that is only read → **RichText**: a click on a link follows it.
|
|
25
|
+
- A message's box, where every link is a chip and its card goes under the
|
|
26
|
+
message → **CardUnder**; leave this out, and a click on a chip follows it.
|
|
25
27
|
|
|
26
28
|
## How
|
|
27
29
|
|
|
28
30
|
```tsx
|
|
29
31
|
import { EditorContent, useEditor } from '@tiptap/react'
|
|
30
|
-
import {
|
|
32
|
+
import { LinkPlaces, ReferenceMenu, ReferenceMenuView, ReferenceNode, isReferenceMenuOpen } from '@estiva-app/ui/editor'
|
|
31
33
|
|
|
32
34
|
const editor = useEditor({
|
|
33
|
-
extensions: [/* … */ ReferenceNode.configure({ view: Chip }),
|
|
35
|
+
extensions: [/* … */ ReferenceNode.configure({ view: Chip }), LinkPlaces, ReferenceMenu],
|
|
34
36
|
editorProps: {
|
|
35
37
|
handleKeyDown: (view, event) => {
|
|
36
38
|
// While the menu is open, Escape is its own: it closes the menu.
|
|
@@ -44,29 +46,35 @@ const editor = useEditor({
|
|
|
44
46
|
<ReferenceMenuView editor={editor} />
|
|
45
47
|
```
|
|
46
48
|
|
|
47
|
-
- **A click on a
|
|
48
|
-
following
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
- **A click on a link while editing** — its chip, row or card — opens the menu
|
|
50
|
+
under it, instead of following it. Not editing, the click follows it. A
|
|
51
|
+
card's own controls (its status, its owner) take their click while editing
|
|
52
|
+
too.
|
|
53
|
+
- **A link just put in alone on its line** — pasted, picked with `[`, or a
|
|
54
|
+
pasted URL becoming its chip — opens the menu by itself. It takes no focus:
|
|
55
|
+
typing on closes it, and nothing is written. In a sentence it does not open:
|
|
56
|
+
Open would be all it offers.
|
|
57
|
+
- **What it writes:** Card writes `embed` `detailed`; Row removes `embed`.
|
|
58
|
+
Nothing writes `compact`; an older writer's is kept until Row or Card is
|
|
59
|
+
chosen, and draws, and reads in the menu, as Row.
|
|
60
|
+
- **Open** does what a click on the link does when reading: the app's link gets
|
|
61
|
+
the click. A link with nothing to click opens its URL in a new tab.
|
|
62
|
+
- Open is offered only when there is something to open: the link's own
|
|
63
|
+
control, or its URL. A link in a sentence with neither has no menu, and a
|
|
64
|
+
click goes on to it.
|
|
57
65
|
- The menu closes when the editor loses focus, so a card is never chosen after
|
|
58
66
|
the editor has saved on leaving.
|
|
59
|
-
- Choosing
|
|
67
|
+
- Choosing Row or Card is an undo step; the menu closes.
|
|
60
68
|
|
|
61
69
|
## What it owns
|
|
62
70
|
|
|
63
|
-
Nothing. Its box is the Popover; it holds which
|
|
71
|
+
Nothing. Its box is the Popover; it holds which link the menu is open on, and its keys.
|
|
64
72
|
|
|
65
73
|
## Keys
|
|
66
74
|
|
|
67
75
|
| Key | Does |
|
|
68
76
|
| --- | --- |
|
|
69
|
-
| Enter, on a selected
|
|
77
|
+
| Enter, on a selected link | Opens the menu, its first row highlighted |
|
|
70
78
|
| ↓ / ↑ | Moves through the rows; nothing is highlighted until then |
|
|
71
79
|
| Enter | Chooses the highlighted row; with none, the editor's own Enter |
|
|
72
80
|
| Escape | Closes the menu |
|
|
@@ -4,14 +4,14 @@ import StarterKit from '@tiptap/starter-kit'
|
|
|
4
4
|
import { BlockId, ReferenceNode, type ReferenceViewProps } from './BlockNodes'
|
|
5
5
|
import { Card } from './Card'
|
|
6
6
|
import { InlineChip } from './InlineChip'
|
|
7
|
-
import {
|
|
7
|
+
import { LinkPlaces } from './LinkPlaces'
|
|
8
8
|
import { ReferenceMenu, ReferenceMenuView } from './ReferenceMenu'
|
|
9
9
|
import { richTextClassName } from './RichText'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Click
|
|
13
|
-
* or
|
|
14
|
-
*
|
|
12
|
+
* Click a link: its menu opens under it — Open, and alone on its line Show as
|
|
13
|
+
* Row or Card. The link is a placeholder naming where it sits: the real chip,
|
|
14
|
+
* row and card are the app's.
|
|
15
15
|
*/
|
|
16
16
|
const meta = {
|
|
17
17
|
title: 'Primitives/ReferenceMenu',
|
|
@@ -21,39 +21,38 @@ const meta = {
|
|
|
21
21
|
export default meta
|
|
22
22
|
type Story = StoryObj
|
|
23
23
|
|
|
24
|
-
function Placeholder({
|
|
25
|
-
return <InlineChip>Item
|
|
24
|
+
function Placeholder({ place = 'chip' }: ReferenceViewProps) {
|
|
25
|
+
if (place === 'chip') return <InlineChip>Item one</InlineChip>
|
|
26
|
+
return (
|
|
27
|
+
<Card fill="inset" className={place === 'card' ? 'flex h-24 items-start p-3' : 'flex h-9 items-center px-3'}>
|
|
28
|
+
<span className="text-body-2 text-text-secondary">Item two, its {place}</span>
|
|
29
|
+
</Card>
|
|
30
|
+
)
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
function Box() {
|
|
29
34
|
const editor = useEditor({
|
|
30
|
-
extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Placeholder }),
|
|
35
|
+
extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Placeholder }), LinkPlaces, ReferenceMenu],
|
|
31
36
|
content: {
|
|
32
37
|
type: 'doc',
|
|
33
38
|
content: [
|
|
34
39
|
{
|
|
35
40
|
type: 'paragraph',
|
|
36
41
|
attrs: { blockId: 'p1' },
|
|
37
|
-
content: [
|
|
38
|
-
{ type: 'text', text: 'See ' },
|
|
39
|
-
{ type: 'reference', attrs: { uri: 'nostr:naddr1one' } },
|
|
40
|
-
{ type: 'text', text: ' for the details.' },
|
|
41
|
-
],
|
|
42
|
+
content: [{ type: 'text', text: 'See ' }, { type: 'reference', attrs: { uri: 'nostr:naddr1one' } }, { type: 'text', text: ' for the details.' }],
|
|
42
43
|
},
|
|
44
|
+
{ type: 'paragraph', attrs: { blockId: 'p2' }, content: [{ type: 'reference', attrs: { uri: 'nostr:naddr1two' } }] },
|
|
43
45
|
],
|
|
44
46
|
},
|
|
45
47
|
editorProps: { attributes: { class: richTextClassName('default', 'outline-none'), 'aria-label': 'Text' } },
|
|
46
48
|
})
|
|
47
|
-
const slots = useReferenceCards(editor)
|
|
48
|
-
const cards = slots.flatMap((slot) => slot.cards.map((card) => `${card.layout} card for ${card.uri}`))
|
|
49
49
|
return (
|
|
50
50
|
<Card fill="surface" className="flex w-[520px] flex-col gap-2 p-3">
|
|
51
51
|
<EditorContent editor={editor} />
|
|
52
52
|
<ReferenceMenuView editor={editor} />
|
|
53
|
-
<p className="text-caption text-text-secondary">{cards.length ? cards.join(', ') : 'No card'}</p>
|
|
54
53
|
</Card>
|
|
55
54
|
)
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
/** A
|
|
57
|
+
/** A link in a sentence, whose menu has Open only, and one alone on its line: choose Card, then Row. */
|
|
59
58
|
export const InAnEditor: Story = { render: () => <Box /> }
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
/**
|
|
3
|
-
* A
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A link's menu while writing a document (the record
|
|
4
|
+
* a-lone-links-chip-menu-offers-row-or-card): a click on a link opens Open, and
|
|
5
|
+
* alone on its line Show as Row or Card, instead of following it; a lone-line
|
|
6
|
+
* link just pasted or picked opens the menu by itself, without taking the
|
|
7
|
+
* caret, and typing on closes it with no card.
|
|
6
8
|
*/
|
|
7
9
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
10
|
+
import { createPortal } from 'react-dom'
|
|
8
11
|
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
9
12
|
import { Editor } from '@tiptap/core'
|
|
10
13
|
import { NodeSelection, TextSelection } from '@tiptap/pm/state'
|
|
11
14
|
import { EditorContent, useEditor } from '@tiptap/react'
|
|
12
15
|
import StarterKit from '@tiptap/starter-kit'
|
|
16
|
+
import { encodeNaddr, encodeNpub } from '@estiva-app/protocol'
|
|
13
17
|
import { BlockId, ReferenceNode, type ReferenceViewProps } from './BlockNodes'
|
|
14
18
|
import { LinkChips } from './LinkChips'
|
|
15
|
-
import {
|
|
19
|
+
import { LinkPlaces } from './LinkPlaces'
|
|
16
20
|
import { ReferenceMenu, ReferenceMenuView, isReferenceMenuOpen, referenceMenuClick } from './ReferenceMenu'
|
|
17
21
|
|
|
18
22
|
const URL_ = 'https://app.example/i/one'
|
|
19
23
|
const V = 'nostr:naddr1example'
|
|
24
|
+
const FOLDER = `nostr:${encodeNaddr({ kind: 39000, pubkey: 'a'.repeat(64), identifier: 'place-one', relays: [] })}`
|
|
25
|
+
const PERSON = `nostr:${encodeNpub('b'.repeat(64))}`
|
|
20
26
|
|
|
21
27
|
type Json = { type: string; text?: string; attrs?: Record<string, unknown>; content?: Json[] }
|
|
22
28
|
const inline = (ed: Editor) => (ed.getJSON() as Json).content?.[0].content ?? []
|
|
23
29
|
const chipOf = (ed: Editor) => inline(ed).find((n) => n.type === 'reference')
|
|
24
30
|
const para = (...content: unknown[]): Record<string, unknown> => ({ type: 'doc', content: [{ type: 'paragraph', attrs: { blockId: 'p1' }, content }] })
|
|
31
|
+
const ref = (uri: string, embed?: string) => ({ type: 'reference', attrs: { uri, ...(embed ? { embed } : {}) } })
|
|
25
32
|
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
|
|
26
33
|
// jsdom has no ClipboardEvent; `pasteText` takes the paste's event, so a plain one stands in.
|
|
27
34
|
const paste = (ed: Editor, text: string) => ed.view.pasteText(text, new Event('paste') as ClipboardEvent)
|
|
@@ -45,7 +52,7 @@ const make = (content: Record<string, unknown>, known: Map<string, string>, answ
|
|
|
45
52
|
StarterKit.configure({ link: false }),
|
|
46
53
|
BlockId,
|
|
47
54
|
ReferenceNode,
|
|
48
|
-
|
|
55
|
+
LinkPlaces,
|
|
49
56
|
ReferenceMenu,
|
|
50
57
|
LinkChips.configure({
|
|
51
58
|
referenceOf: (url) => known.get(url),
|
|
@@ -67,23 +74,44 @@ const make = (content: Record<string, unknown>, known: Map<string, string>, answ
|
|
|
67
74
|
const toEnd = (ed: Editor) => ed.view.dispatch(ed.state.tr.setSelection(TextSelection.create(ed.state.doc, ed.state.doc.content.size - 1)))
|
|
68
75
|
|
|
69
76
|
describe('ReferenceMenu', () => {
|
|
70
|
-
it('opens by itself on a pasted
|
|
71
|
-
const ed = make(para(
|
|
77
|
+
it('opens by itself on a URL pasted on an empty line that becomes its chip, and typing on closes it with no card', async () => {
|
|
78
|
+
const ed = make(para(), new Map([[URL_, V]]))
|
|
72
79
|
await tick()
|
|
73
80
|
toEnd(ed)
|
|
74
81
|
paste(ed, URL_)
|
|
75
82
|
expect(chipOf(ed)?.attrs).toMatchObject({ uri: V, href: URL_ })
|
|
76
83
|
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
77
|
-
// The caret stayed in the text, after the
|
|
84
|
+
// The caret stayed in the text, after the link.
|
|
78
85
|
expect(ed.state.selection.empty).toBe(true)
|
|
79
86
|
ed.view.dispatch(ed.state.tr.insertText(' and more'))
|
|
80
87
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
81
88
|
expect(chipOf(ed)?.attrs?.embed).toBeNull()
|
|
82
89
|
})
|
|
83
90
|
|
|
91
|
+
it('does not open by itself on a link pasted or picked into a sentence, where it would offer Open alone', async () => {
|
|
92
|
+
const ed = make(para({ type: 'text', text: 'See ' }), new Map([[URL_, V]]))
|
|
93
|
+
await tick()
|
|
94
|
+
toEnd(ed)
|
|
95
|
+
paste(ed, URL_)
|
|
96
|
+
expect(chipOf(ed)?.attrs).toMatchObject({ uri: V, href: URL_ })
|
|
97
|
+
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
98
|
+
ed.commands.insertContent([ref(V), { type: 'text', text: ' ' }])
|
|
99
|
+
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('does not open by itself on a person or a Folder picked on an empty line, which stay chips', () => {
|
|
103
|
+
for (const uri of [PERSON, FOLDER]) {
|
|
104
|
+
const ed = make(para(), new Map())
|
|
105
|
+
toEnd(ed)
|
|
106
|
+
ed.commands.insertContent([ref(uri), { type: 'text', text: ' ' }])
|
|
107
|
+
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
108
|
+
ed.destroy()
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
|
|
84
112
|
it('opens when a pasted URL\'s answer comes back with the caret still after it, not once the person typed on', async () => {
|
|
85
113
|
const answers: (() => void)[] = []
|
|
86
|
-
const ed = make(para(
|
|
114
|
+
const ed = make(para(), new Map(), answers)
|
|
87
115
|
await tick()
|
|
88
116
|
toEnd(ed)
|
|
89
117
|
paste(ed, URL_)
|
|
@@ -96,7 +124,7 @@ describe('ReferenceMenu', () => {
|
|
|
96
124
|
|
|
97
125
|
const later: (() => void)[] = []
|
|
98
126
|
const other = 'https://app.example/i/two'
|
|
99
|
-
const ed2 = make(para(
|
|
127
|
+
const ed2 = make(para(), new Map(), later)
|
|
100
128
|
await tick()
|
|
101
129
|
toEnd(ed2)
|
|
102
130
|
paste(ed2, other)
|
|
@@ -113,13 +141,13 @@ describe('ReferenceMenu', () => {
|
|
|
113
141
|
const doc = {
|
|
114
142
|
type: 'doc',
|
|
115
143
|
content: [
|
|
116
|
-
{ type: 'paragraph', attrs: { blockId: 'p1' }, content: [
|
|
144
|
+
{ type: 'paragraph', attrs: { blockId: 'p1' }, content: [ref(V)] },
|
|
117
145
|
{ type: 'paragraph', attrs: { blockId: 'p2' }, content: [{ type: 'text', text: other }] },
|
|
118
146
|
],
|
|
119
147
|
}
|
|
120
148
|
const ed = make(doc, new Map(), answers)
|
|
121
149
|
await tick()
|
|
122
|
-
expect(referenceMenuClick(ed,
|
|
150
|
+
expect(referenceMenuClick(ed, 1)).toBe(true)
|
|
123
151
|
answers[0]()
|
|
124
152
|
await tick()
|
|
125
153
|
expect((ed.getJSON() as Json).content?.[1].content?.[0].type).toBe('reference')
|
|
@@ -128,31 +156,30 @@ describe('ReferenceMenu', () => {
|
|
|
128
156
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
129
157
|
})
|
|
130
158
|
|
|
131
|
-
it('opens on a chip pasted right before an identical one', () => {
|
|
132
|
-
const ed = make(para({ type: 'text', text: 'a ' }, { type: 'reference', attrs: { uri: V } }), new Map())
|
|
133
|
-
ed.view.dispatch(ed.state.tr.setSelection(TextSelection.create(ed.state.doc, 3)))
|
|
134
|
-
ed.view.dispatch(ed.state.tr.insert(3, ed.schema.nodes.reference.create({ uri: V })).setMeta('uiEvent', 'paste'))
|
|
135
|
-
expect(ed.state.selection.from).toBe(4)
|
|
136
|
-
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
137
|
-
})
|
|
138
|
-
|
|
139
159
|
it('leaves a key with a modifier to the editor', async () => {
|
|
140
|
-
const ed = make(para(
|
|
160
|
+
const ed = make(para(), new Map([[URL_, V]]))
|
|
141
161
|
await tick()
|
|
142
162
|
toEnd(ed)
|
|
143
163
|
paste(ed, URL_)
|
|
164
|
+
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
144
165
|
const shifted = new KeyboardEvent('keydown', { key: 'ArrowDown', shiftKey: true, bubbles: true, cancelable: true })
|
|
145
166
|
ed.view.dom.dispatchEvent(shifted)
|
|
146
167
|
expect(shifted.defaultPrevented).toBe(false)
|
|
147
168
|
})
|
|
148
169
|
|
|
149
|
-
it('offers no Open for a
|
|
150
|
-
// No view: the
|
|
151
|
-
const ed = make(para(
|
|
170
|
+
it('offers no Open for a link with nothing to open, and still Show as', () => {
|
|
171
|
+
// No view: the link draws no control of its own, and it has no URL.
|
|
172
|
+
const ed = make(para(ref(V)), new Map())
|
|
152
173
|
render(<ReferenceMenuView editor={ed} />)
|
|
153
|
-
act(() => void referenceMenuClick(ed,
|
|
174
|
+
act(() => void referenceMenuClick(ed, 1))
|
|
154
175
|
expect(screen.queryByRole('menuitem', { name: 'Open' })).toBeNull()
|
|
155
|
-
expect(screen.getByRole('menuitemradio', { name: '
|
|
176
|
+
expect(screen.getByRole('menuitemradio', { name: 'Card' })).toBeDefined()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('has no menu for a link in a sentence with nothing to open', () => {
|
|
180
|
+
const ed = make(para({ type: 'text', text: 'See ' }, ref(V)), new Map())
|
|
181
|
+
expect(referenceMenuClick(ed, 5)).toBe(false)
|
|
182
|
+
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
156
183
|
})
|
|
157
184
|
|
|
158
185
|
it('forgets a paste edited inside: each keystroke in it is not an ask', async () => {
|
|
@@ -171,33 +198,33 @@ describe('ReferenceMenu', () => {
|
|
|
171
198
|
expect(answers).toHaveLength(1)
|
|
172
199
|
})
|
|
173
200
|
|
|
174
|
-
it('opens on a
|
|
175
|
-
const ed = make(para(
|
|
201
|
+
it('opens on a link picked from a list on an empty line, which puts a space after it', () => {
|
|
202
|
+
const ed = make(para(), new Map())
|
|
176
203
|
toEnd(ed)
|
|
177
|
-
ed.commands.insertContent([
|
|
204
|
+
ed.commands.insertContent([ref(V), { type: 'text', text: ' ' }])
|
|
178
205
|
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
179
206
|
})
|
|
180
207
|
|
|
181
208
|
it('does not open on a URL typed by hand, an undo, or a document loaded over the editor', async () => {
|
|
182
|
-
const ed = make(para(
|
|
209
|
+
const ed = make(para(), new Map([[URL_, V]]))
|
|
183
210
|
await tick()
|
|
184
211
|
toEnd(ed)
|
|
185
212
|
for (const ch of URL_) ed.view.dispatch(ed.state.tr.insertText(ch))
|
|
186
213
|
ed.view.dispatch(ed.state.tr.insertText(' '))
|
|
187
214
|
expect(chipOf(ed)?.attrs).toMatchObject({ uri: V })
|
|
188
215
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
189
|
-
ed.commands.setContent(para(
|
|
216
|
+
ed.commands.setContent(para(ref(V)))
|
|
190
217
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
191
218
|
})
|
|
192
219
|
|
|
193
220
|
it('keeps Enter for a new line after a paste until an arrow highlights a row; then Enter chooses it', async () => {
|
|
194
|
-
const ed = make(para(
|
|
221
|
+
const ed = make(para(), new Map([[URL_, V]]))
|
|
195
222
|
await tick()
|
|
196
223
|
toEnd(ed)
|
|
197
224
|
paste(ed, URL_)
|
|
198
225
|
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
199
|
-
// ↓ to Open, ↓ to
|
|
200
|
-
for (let i = 0; i <
|
|
226
|
+
// ↓ to Open, ↓ to Row, ↓ to Card.
|
|
227
|
+
for (let i = 0; i < 3; i++) expect(press(ed, 'ArrowDown')).toBe(true)
|
|
201
228
|
expect(press(ed, 'Enter')).toBe(true)
|
|
202
229
|
expect(chipOf(ed)?.attrs?.embed).toBe('detailed')
|
|
203
230
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
@@ -205,36 +232,38 @@ describe('ReferenceMenu', () => {
|
|
|
205
232
|
expect((ed.getJSON() as Json).content).toHaveLength(1)
|
|
206
233
|
})
|
|
207
234
|
|
|
208
|
-
it('opens from the keyboard with Enter on a selected
|
|
209
|
-
const ed = make(para(
|
|
210
|
-
ed.view.dispatch(ed.state.tr.setSelection(NodeSelection.create(ed.state.doc,
|
|
235
|
+
it('opens from the keyboard with Enter on a selected link, and Escape closes it without writing', () => {
|
|
236
|
+
const ed = make(para(ref(V, 'compact')), new Map())
|
|
237
|
+
ed.view.dispatch(ed.state.tr.setSelection(NodeSelection.create(ed.state.doc, 1)))
|
|
211
238
|
expect(press(ed, 'Enter')).toBe(true)
|
|
212
239
|
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
213
|
-
// The
|
|
240
|
+
// The link is still there: Enter did not replace it with a line break.
|
|
214
241
|
expect(chipOf(ed)).toBeDefined()
|
|
215
|
-
//
|
|
242
|
+
// Row is highlighted; ↑ wraps to Card.
|
|
216
243
|
press(ed, 'ArrowUp')
|
|
217
244
|
expect(press(ed, 'Escape')).toBe(true)
|
|
218
245
|
expect(isReferenceMenuOpen(ed.state)).toBe(false)
|
|
246
|
+
// An older writer's compact is kept as written until Row or Card is chosen.
|
|
219
247
|
expect(chipOf(ed)?.attrs?.embed).toBe('compact')
|
|
220
248
|
})
|
|
221
249
|
|
|
222
250
|
it('opens on a click only while editing', () => {
|
|
223
|
-
const ed = make(para(
|
|
251
|
+
const ed = make(para(ref(V)), new Map())
|
|
224
252
|
ed.setEditable(false)
|
|
225
|
-
expect(referenceMenuClick(ed,
|
|
253
|
+
expect(referenceMenuClick(ed, 1)).toBe(false)
|
|
226
254
|
ed.setEditable(true)
|
|
227
|
-
expect(referenceMenuClick(ed,
|
|
255
|
+
expect(referenceMenuClick(ed, 1)).toBe(true)
|
|
228
256
|
expect(isReferenceMenuOpen(ed.state)).toBe(true)
|
|
229
|
-
// The caret right after the
|
|
230
|
-
expect(ed.state.selection.empty && ed.state.selection.from).toBe(
|
|
257
|
+
// The caret right after the link, not the link selected: no selection toolbar beside the menu, and typing does not replace it.
|
|
258
|
+
expect(ed.state.selection.empty && ed.state.selection.from).toBe(2)
|
|
231
259
|
})
|
|
232
260
|
})
|
|
233
261
|
|
|
234
262
|
describe('ReferenceMenuView', () => {
|
|
235
|
-
|
|
263
|
+
/** The app's drawing: a link, named by its place, that follows on a click. */
|
|
264
|
+
function Linked({ uri, place = 'chip' }: ReferenceViewProps) {
|
|
236
265
|
return (
|
|
237
|
-
<a href={`/o/${uri}`} onClick={(event) => (followed(uri), event.preventDefault())}>
|
|
266
|
+
<a href={`/o/${uri}`} data-place={place} onClick={(event) => (followed(uri), event.preventDefault())}>
|
|
238
267
|
Item
|
|
239
268
|
</a>
|
|
240
269
|
)
|
|
@@ -243,7 +272,7 @@ describe('ReferenceMenuView', () => {
|
|
|
243
272
|
|
|
244
273
|
function Harness({ content }: { content: Record<string, unknown> }) {
|
|
245
274
|
const e = useEditor({
|
|
246
|
-
extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Linked }),
|
|
275
|
+
extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: Linked }), LinkPlaces, ReferenceMenu],
|
|
247
276
|
content,
|
|
248
277
|
})
|
|
249
278
|
editor = e ?? undefined
|
|
@@ -255,31 +284,106 @@ describe('ReferenceMenuView', () => {
|
|
|
255
284
|
)
|
|
256
285
|
}
|
|
257
286
|
|
|
258
|
-
it('takes a click on
|
|
287
|
+
it('takes a click on a link in a sentence for its menu, which offers Open only, and Open hands the click to the link', async () => {
|
|
259
288
|
followed.mockClear()
|
|
260
|
-
render(<Harness content={para({ type: 'text', text: 'See ' },
|
|
289
|
+
render(<Harness content={para({ type: 'text', text: 'See ' }, ref(V))} />)
|
|
261
290
|
const chip = await screen.findByRole('link', { name: 'Item' })
|
|
262
291
|
fireEvent.click(chip)
|
|
263
292
|
expect(followed).not.toHaveBeenCalled()
|
|
264
293
|
await screen.findByRole('menu', { name: 'Link' })
|
|
294
|
+
expect(screen.queryByRole('group', { name: 'Show as' })).toBeNull()
|
|
295
|
+
expect(screen.queryAllByRole('menuitemradio')).toHaveLength(0)
|
|
265
296
|
fireEvent.mouseDown(screen.getByRole('menuitem', { name: 'Open' }))
|
|
266
297
|
expect(followed).toHaveBeenCalledWith(V)
|
|
267
298
|
await waitFor(() => expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull())
|
|
268
299
|
})
|
|
269
300
|
|
|
270
|
-
it('
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
301
|
+
it('offers Open only on a person or a Folder alone on its line, which stay chips', async () => {
|
|
302
|
+
for (const uri of [PERSON, FOLDER]) {
|
|
303
|
+
render(<Harness content={para(ref(uri))} />)
|
|
304
|
+
const link = await screen.findByRole('link', { name: 'Item' })
|
|
305
|
+
expect(link.getAttribute('data-place')).toBe('chip')
|
|
306
|
+
fireEvent.click(link)
|
|
307
|
+
await screen.findByRole('menuitem', { name: 'Open' })
|
|
308
|
+
expect(screen.queryAllByRole('menuitemradio')).toHaveLength(0)
|
|
309
|
+
cleanup()
|
|
310
|
+
editor?.destroy()
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
it('draws a lone link as its row with Row checked; Card puts its card in the row\'s place, and Row puts the row back', async () => {
|
|
315
|
+
render(<Harness content={para(ref(V))} />)
|
|
316
|
+
const link = await screen.findByRole('link', { name: 'Item' })
|
|
317
|
+
expect(link.getAttribute('data-place')).toBe('row')
|
|
318
|
+
fireEvent.click(link)
|
|
319
|
+
expect((await screen.findByRole('group', { name: 'Show as' })).textContent).toContain('Row')
|
|
320
|
+
expect(screen.getByRole('menuitemradio', { name: 'Row' }).getAttribute('aria-checked')).toBe('true')
|
|
321
|
+
fireEvent.mouseDown(screen.getByRole('menuitemradio', { name: 'Card' }))
|
|
276
322
|
expect(chipOf(editor!)?.attrs?.embed).toBe('detailed')
|
|
323
|
+
await waitFor(() => expect(screen.getByRole('link', { name: 'Item' }).getAttribute('data-place')).toBe('card'))
|
|
277
324
|
await waitFor(() => expect(screen.queryByRole('menu', { name: 'Link' })).toBeNull())
|
|
325
|
+
|
|
326
|
+
fireEvent.click(screen.getByRole('link', { name: 'Item' }))
|
|
327
|
+
expect((await screen.findByRole('menuitemradio', { name: 'Card' })).getAttribute('aria-checked')).toBe('true')
|
|
328
|
+
fireEvent.mouseDown(screen.getByRole('menuitemradio', { name: 'Row' }))
|
|
329
|
+
// Row writes no `embed` at all, not `none`.
|
|
330
|
+
expect(chipOf(editor!)?.attrs?.embed).toBeNull()
|
|
331
|
+
await waitFor(() => expect(screen.getByRole('link', { name: 'Item' }).getAttribute('data-place')).toBe('row'))
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('lets a click on a card\'s own control reach it while editing, instead of opening the menu', async () => {
|
|
335
|
+
const changed = vi.fn()
|
|
336
|
+
function WithControl({ place = 'chip' }: ReferenceViewProps) {
|
|
337
|
+
return place === 'card' ? (
|
|
338
|
+
<>
|
|
339
|
+
<button type="button" onClick={changed}>
|
|
340
|
+
Status
|
|
341
|
+
</button>
|
|
342
|
+
{/* A picker's list, portalled out as a Select's is: its click travels React's tree through the link. */}
|
|
343
|
+
{createPortal(
|
|
344
|
+
<div role="option" aria-selected={false} onClick={changed}>
|
|
345
|
+
Done
|
|
346
|
+
</div>,
|
|
347
|
+
document.body,
|
|
348
|
+
)}
|
|
349
|
+
</>
|
|
350
|
+
) : (
|
|
351
|
+
<a href="/o/item">Item</a>
|
|
352
|
+
)
|
|
353
|
+
}
|
|
354
|
+
function CardHarness() {
|
|
355
|
+
const e = useEditor({ extensions: [StarterKit.configure({ link: false }), BlockId, ReferenceNode.configure({ view: WithControl }), LinkPlaces, ReferenceMenu], content: para(ref(V, 'detailed')) })
|
|
356
|
+
editor = e ?? undefined
|
|
357
|
+
return (
|
|
358
|
+
<>
|
|
359
|
+
<EditorContent editor={e} />
|
|
360
|
+
<ReferenceMenuView editor={e} />
|
|
361
|
+
</>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
render(<CardHarness />)
|
|
365
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Status' }))
|
|
366
|
+
expect(changed).toHaveBeenCalledTimes(1)
|
|
367
|
+
expect(isReferenceMenuOpen(editor!.state)).toBe(false)
|
|
368
|
+
fireEvent.click(screen.getByRole('option', { name: 'Done' }))
|
|
369
|
+
expect(changed).toHaveBeenCalledTimes(2)
|
|
370
|
+
expect(isReferenceMenuOpen(editor!.state)).toBe(false)
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('offers Open at once on a link picked on an empty line, before the app has drawn it', async () => {
|
|
374
|
+
render(<Harness content={para()} />)
|
|
375
|
+
await screen.findByRole('textbox')
|
|
376
|
+
act(() => {
|
|
377
|
+
editor!.commands.focus('end')
|
|
378
|
+
editor!.commands.insertContent([ref(V), { type: 'text', text: ' ' }])
|
|
379
|
+
})
|
|
380
|
+
expect((await screen.findAllByRole('menuitem', { name: 'Open' })).length).toBe(1)
|
|
381
|
+
expect(screen.getByRole('menuitemradio', { name: 'Row' }).getAttribute('aria-checked')).toBe('true')
|
|
278
382
|
})
|
|
279
383
|
|
|
280
|
-
it('lets a click follow the
|
|
384
|
+
it('lets a click follow the link when the editor is not editable', async () => {
|
|
281
385
|
followed.mockClear()
|
|
282
|
-
render(<Harness content={para(
|
|
386
|
+
render(<Harness content={para(ref(V))} />)
|
|
283
387
|
const chip = await screen.findByRole('link', { name: 'Item' })
|
|
284
388
|
act(() => editor!.setEditable(false))
|
|
285
389
|
fireEvent.click(chip)
|