@estiva-app/ui 0.80.0 → 0.81.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/CardUnder.d.ts +24 -3
- package/dist/CardUnder.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +39 -5
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/editor.d.ts +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +112 -26
- package/dist/editor.js.map +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +9 -9
- package/src/CardUnder.mdx +1 -0
- package/src/CardUnder.tsx +10 -6
- package/src/CommentBox.mdx +8 -0
- package/src/CommentBox.stories.tsx +62 -2
- package/src/CommentBox.test.tsx +169 -1
- package/src/CommentBox.tsx +164 -16
- package/src/editor.ts +3 -0
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"kind": "package",
|
|
5
5
|
"repo": "estiva-ui",
|
|
6
6
|
"package": "@estiva-app/ui",
|
|
7
|
-
"packageVersion": "0.
|
|
7
|
+
"packageVersion": "0.81.0",
|
|
8
8
|
"exports": 204,
|
|
9
|
-
"typeExports":
|
|
9
|
+
"typeExports": 200,
|
|
10
10
|
"files": null
|
|
11
11
|
},
|
|
12
12
|
"storybook": {
|
|
@@ -1040,12 +1040,6 @@
|
|
|
1040
1040
|
"purpose": "The one card added under a piece of text, and the ✕ that removes it.",
|
|
1041
1041
|
"purposeFrom": "page",
|
|
1042
1042
|
"props": [
|
|
1043
|
-
{
|
|
1044
|
-
"name": "link",
|
|
1045
|
-
"takes": "LinkState",
|
|
1046
|
-
"required": true,
|
|
1047
|
-
"note": null
|
|
1048
|
-
},
|
|
1049
1043
|
{
|
|
1050
1044
|
"name": "onRemove",
|
|
1051
1045
|
"takes": "a handler",
|
|
@@ -2018,7 +2012,13 @@
|
|
|
2018
2012
|
"name": "send",
|
|
2019
2013
|
"takes": "a handler",
|
|
2020
2014
|
"required": true,
|
|
2021
|
-
"note": "Send what is written, with the files that are ready; resolves with the relay's answer."
|
|
2015
|
+
"note": "Send what is written, with the files that are ready and the card still shown; resolves with the relay's answer."
|
|
2016
|
+
},
|
|
2017
|
+
{
|
|
2018
|
+
"name": "under",
|
|
2019
|
+
"takes": "BoxUnder",
|
|
2020
|
+
"required": false,
|
|
2021
|
+
"note": "The card and parts under the box while something is written, with ✕ on the card."
|
|
2022
2022
|
},
|
|
2023
2023
|
{
|
|
2024
2024
|
"name": "showsAtOnce",
|
package/src/CardUnder.mdx
CHANGED
|
@@ -33,6 +33,7 @@ import { CardUnder } from '@estiva-app/ui'
|
|
|
33
33
|
- **Which link gets the card is the app's**, by the rule every app reads by (`defaultCardOf` in `@estiva-app/protocol`). This draws the one it is given.
|
|
34
34
|
- `onRemove` is the app's: before sending it drops the card from what will be sent; after, it sends the edit that removes it.
|
|
35
35
|
- It is at most 480px wide.
|
|
36
|
+
- **An app that draws its sent cards itself** passes its card as `children` instead of `link`, so the card under a box and under a sent message are the same: `<CardUnder onRemove={remove}>{appCard}</CardUnder>`. `CommentBox` draws its card this way.
|
|
36
37
|
|
|
37
38
|
## What it owns
|
|
38
39
|
|
package/src/CardUnder.tsx
CHANGED
|
@@ -7,26 +7,30 @@
|
|
|
7
7
|
* focus, and always on a screen that cannot hover, so a tap reaches it (Miky,
|
|
8
8
|
* 16 Oct, kickoff).
|
|
9
9
|
*/
|
|
10
|
+
import type { ReactNode } from 'react'
|
|
10
11
|
import { IconX } from '@tabler/icons-react'
|
|
11
12
|
import { cn } from './cn'
|
|
12
13
|
import { IconButton } from './IconButton'
|
|
13
14
|
import { LinkCard } from './LinkCard'
|
|
14
15
|
import type { LinkState } from './linked'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
link: LinkState
|
|
17
|
+
interface CardUnderBase {
|
|
18
18
|
/** Draws the ✕. Without it the card shows with none, as it does to anyone but the author. */
|
|
19
19
|
onRemove?: () => void
|
|
20
20
|
/** The ✕ waits for hover or focus: under text already sent. Always shown on a screen that cannot hover. */
|
|
21
21
|
revealOnHover?: boolean
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The card is a `LinkCard` of `link`, or the app's own card as `children`: an
|
|
26
|
+
* app that draws a sent card itself draws the one under its box the same way.
|
|
27
|
+
*/
|
|
28
|
+
export type CardUnderProps = CardUnderBase & ({ link: LinkState; children?: never } | { link?: never; children: ReactNode })
|
|
29
|
+
|
|
30
|
+
export function CardUnder({ link, children, onRemove, revealOnHover = false }: CardUnderProps) {
|
|
25
31
|
return (
|
|
26
32
|
<div className="group/card flex max-w-[480px] items-start gap-1">
|
|
27
|
-
<div className="min-w-0 flex-1">
|
|
28
|
-
<LinkCard link={link} />
|
|
29
|
-
</div>
|
|
33
|
+
<div className="min-w-0 flex-1">{link ? <LinkCard link={link} /> : children}</div>
|
|
30
34
|
{onRemove && (
|
|
31
35
|
// At the card's top corner: halfway down a tall card a ✕ reads as belonging to nothing.
|
|
32
36
|
<div
|
package/src/CommentBox.mdx
CHANGED
|
@@ -15,10 +15,13 @@ The one box every app writes a comment, a reply and a line of a conversation in:
|
|
|
15
15
|
- `showsAtOnce` when the app shows a send before the relay answers: the box empties at once, and a refusal puts the words back. Without it the box holds the words, shut, until the answer.
|
|
16
16
|
- `edit` to change something already sent: the same box with Cancel and Save, and only its keys on the left.
|
|
17
17
|
- `upload` to offer files: the paperclip, `/` → File, a pasted picture and a dropped file.
|
|
18
|
+
- `under` to show, while something is written, the one card it will be sent with (✕ takes it off) and the live part of each block link, drawn as the app draws them under a sent message. An edit box shows the card and no part.
|
|
18
19
|
- `closed` where nothing can be written (archived, signed out): a line saying why, in the box's place. No greyed box.
|
|
19
20
|
|
|
20
21
|
<Canvas of={CommentBoxStories.Refused} />
|
|
21
22
|
|
|
23
|
+
<Canvas of={CommentBoxStories.CardUnderTheBox} />
|
|
24
|
+
|
|
22
25
|
## When not
|
|
23
26
|
|
|
24
27
|
- Writing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
|
|
@@ -56,6 +59,9 @@ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(roo
|
|
|
56
59
|
- **`insert` is the app's Insert rows**, after the shared Format section: `commentBoxRows` and the app's own. An edit drops File and Urgent itself; with no `upload` there is no File.
|
|
57
60
|
- **Give the box a `key` per destination.** The editor, the rows and `code` are made once, as the box opens; a new thread is a new box.
|
|
58
61
|
- A send shown at once and refused after its box went away writes the words into its draft instead.
|
|
62
|
+
- **`under.read` is the app's reading of the draft**: `@estiva-app/conversation`'s `boxReadOf(body, context)` says which file gets the card and which parts show; the app adds its own view of each. Call `under.changed`'s listener when what a link names comes back. `send`'s third argument is `{ card }`, the card still shown, which the app writes with `embedsToSend` (or `embedsToEdit` for `onSave`).
|
|
63
|
+
- **An edit box's `read` passes `previous: namedBefore(<the message's text>)`**, so only a file the edit names first gets a card. A card the message already has, or one taken off with ✕ before or after sending, never shows again in the edit box, and Save leaves it as it was.
|
|
64
|
+
- **A link chip for a pasted app URL** is the app's `LinkChips`, passed in `extensions`.
|
|
59
65
|
|
|
60
66
|
## What it owns
|
|
61
67
|
|
|
@@ -69,6 +75,8 @@ It does these by itself. Write none of them around it.
|
|
|
69
75
|
| A refusal: the words back, and a line under the box | a toast, or putting text back |
|
|
70
76
|
| The draft, written as you type and forgotten once sent | an update listener |
|
|
71
77
|
| Files: picking, pasting, dropping, uploading, failing; Send waits for an upload and holds on a failed file until its ✕ removes it | a file list |
|
|
78
|
+
| The card under the box, its ✕, and a ✕ forgotten once the link is taken out; a refused send puts back what ✕ took off | a card state |
|
|
79
|
+
| A URL pasted over words links them when a message can carry them as a link (one line of plain words, no bracket, no chip, no `)` in the URL); otherwise the URL goes in after the words. Typing after linked words is not linked | a paste handler |
|
|
72
80
|
| The read-only line | a disabled box |
|
|
73
81
|
|
|
74
82
|
## Keys
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState } from 'react'
|
|
3
3
|
import type { JSONContent } from '@tiptap/react'
|
|
4
|
-
import { userEvent, within } from 'storybook/test'
|
|
4
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test'
|
|
5
5
|
import { Button } from './Button'
|
|
6
|
-
import { CommentBox, commentBoxRows, type CommentBoxDraft, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
6
|
+
import { CommentBox, commentBoxRows, type BoxUnder, type CommentBoxDraft, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
7
7
|
import type { CaptionedItem, MentionPerson, ReferenceSection } from './ComposerTriggers'
|
|
8
8
|
import { Kbd } from './Kbd'
|
|
9
|
+
import { LinkCard } from './LinkCard'
|
|
10
|
+
import { ITEM, ready } from './linked.examples'
|
|
11
|
+
import { PartCard } from './PartCard'
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* The one box every app writes in. Every story is live: write, open a list,
|
|
@@ -204,6 +207,63 @@ export const ReadOnlyArchived: Story = { render: () => <Live closed={{ reason: '
|
|
|
204
207
|
/** Read-only, signed out: a line in the box's place. */
|
|
205
208
|
export const ReadOnlySignedOut: Story = { render: () => <Live closed={{ reason: 'Sign in to write here.' }} /> }
|
|
206
209
|
|
|
210
|
+
const ITEM_URL = 'https://app.example/item/one'
|
|
211
|
+
const PART_URL = 'https://app.example/page/two#block'
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* What the app reads under the box: one item named gets its card; a link to
|
|
215
|
+
* a block of something is its live part, and then no card.
|
|
216
|
+
*/
|
|
217
|
+
const under: BoxUnder = {
|
|
218
|
+
read: (body) => {
|
|
219
|
+
const text = plain(body)
|
|
220
|
+
const item = text.includes(ITEM_URL)
|
|
221
|
+
const part = text.includes(PART_URL)
|
|
222
|
+
return {
|
|
223
|
+
card: item && !part ? { value: 'item-one', view: <LinkCard link={ready(ITEM)} /> } : undefined,
|
|
224
|
+
parts: part
|
|
225
|
+
? [
|
|
226
|
+
{
|
|
227
|
+
key: 'item-two',
|
|
228
|
+
view: (
|
|
229
|
+
<PartCard state="ready" kind="issue" heading="Item two" partKey="ABC-3" href="#part">
|
|
230
|
+
<p className="text-body-2 text-text-secondary">The block, as it is now. It changes when the text it came from changes.</p>
|
|
231
|
+
</PartCard>
|
|
232
|
+
),
|
|
233
|
+
},
|
|
234
|
+
]
|
|
235
|
+
: [],
|
|
236
|
+
names: [...(item ? ['item-one'] : []), ...(part ? ['item-two'] : [])],
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** One item named: its card under the box, with ✕ to take it off. Take the link out and put it back and the card comes back. */
|
|
242
|
+
export const CardUnderTheBox: Story = { render: () => <Live under={under} />, play: typeInto(`As in ${ITEM_URL} `) }
|
|
243
|
+
|
|
244
|
+
/** A link to a block: its live part under the box, and no card. */
|
|
245
|
+
export const PartUnderTheBox: Story = { render: () => <Live under={under} />, play: typeInto(`As in ${ITEM_URL} and ${PART_URL} `) }
|
|
246
|
+
|
|
247
|
+
/** Editing: a link the edit adds shows the card Save will add. A part never shows here, since an edit carries none. */
|
|
248
|
+
export const EditingWithACard: Story = {
|
|
249
|
+
render: () => (
|
|
250
|
+
<Live
|
|
251
|
+
under={under}
|
|
252
|
+
edit={{
|
|
253
|
+
body: { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'As in' }] }] },
|
|
254
|
+
onCancel: () => {},
|
|
255
|
+
onSave: answering,
|
|
256
|
+
}}
|
|
257
|
+
/>
|
|
258
|
+
),
|
|
259
|
+
// The edit box puts the caret at the end as it opens; a click would move it.
|
|
260
|
+
play: async ({ canvasElement }) => {
|
|
261
|
+
const box = within(canvasElement).getByRole('textbox', { name: 'Write' })
|
|
262
|
+
await waitFor(() => expect(box.ownerDocument.activeElement).toBe(box))
|
|
263
|
+
await userEvent.keyboard(` ${ITEM_URL} `)
|
|
264
|
+
},
|
|
265
|
+
}
|
|
266
|
+
|
|
207
267
|
/** The narrowest column it sits in, 320px, with a file uploading. */
|
|
208
268
|
export const Narrow: Story = {
|
|
209
269
|
decorators: [
|
package/src/CommentBox.test.tsx
CHANGED
|
@@ -8,8 +8,9 @@ import { act } from 'react'
|
|
|
8
8
|
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
9
9
|
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
|
|
10
10
|
import type { Editor } from '@tiptap/core'
|
|
11
|
+
import { Fragment, Slice } from '@tiptap/pm/model'
|
|
11
12
|
import type { JSONContent } from '@tiptap/react'
|
|
12
|
-
import { CommentBox, commentBoxRows, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
13
|
+
import { CommentBox, commentBoxRows, type BoxUnder, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
13
14
|
import type { MentionPerson } from './ComposerTriggers'
|
|
14
15
|
|
|
15
16
|
const PEOPLE: MentionPerson[] = [{ id: 'one', name: 'Person one', pubkey: 'b'.repeat(64) }]
|
|
@@ -277,3 +278,170 @@ describe('read-only', () => {
|
|
|
277
278
|
expect(screen.queryByRole('button', { name: 'Send' })).toBeNull()
|
|
278
279
|
})
|
|
279
280
|
})
|
|
281
|
+
|
|
282
|
+
describe('under the box: the one card, with ✕, and the live parts', () => {
|
|
283
|
+
const ISSUE = 'https://app.example/item/one'
|
|
284
|
+
const BLOCK = 'https://app.example/page/two#block'
|
|
285
|
+
/** The app's read, by what the text names: one item gets the card; a block link is a part and leaves no card. */
|
|
286
|
+
const reader = (known = () => true): BoxUnder => ({
|
|
287
|
+
read: (body) => {
|
|
288
|
+
const text = textOf(body)
|
|
289
|
+
const item = known() && text.includes(ISSUE)
|
|
290
|
+
const part = text.includes(BLOCK)
|
|
291
|
+
return {
|
|
292
|
+
card: item && !part ? { value: 'item-one', view: <span>Card of item one</span> } : undefined,
|
|
293
|
+
parts: part ? [{ key: 'page-two', view: <span>Live part of page two</span> }] : [],
|
|
294
|
+
names: [...(item ? ['item-one'] : []), ...(part ? ['page-two'] : [])],
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
})
|
|
298
|
+
const removeCard = () => act(async () => fireEvent.click(screen.getByRole('button', { name: 'Remove card' })))
|
|
299
|
+
|
|
300
|
+
it('a draft naming one item shows its card under the box, and it is sent with the words', async () => {
|
|
301
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
302
|
+
render(<Box send={send} under={reader()} />)
|
|
303
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
304
|
+
await type(`see ${ISSUE}`)
|
|
305
|
+
expect(screen.getByText('Card of item one')).toBeTruthy()
|
|
306
|
+
await press('Enter')
|
|
307
|
+
await settle()
|
|
308
|
+
expect(send.mock.calls[0][2]).toEqual({ card: 'item-one' })
|
|
309
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('✕ takes the card off, and the message is sent with none', async () => {
|
|
313
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
314
|
+
render(<Box send={send} under={reader()} />)
|
|
315
|
+
await type(`see ${ISSUE}`)
|
|
316
|
+
await removeCard()
|
|
317
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
318
|
+
await press('Enter')
|
|
319
|
+
await settle()
|
|
320
|
+
expect(send.mock.calls[0][2]).toEqual({})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
it('a link taken out and put back gets its card again', async () => {
|
|
324
|
+
render(<Box under={reader()} />)
|
|
325
|
+
await type(`see ${ISSUE}`)
|
|
326
|
+
await removeCard()
|
|
327
|
+
await act(async () => {
|
|
328
|
+
editorOf().commands.setContent('see')
|
|
329
|
+
})
|
|
330
|
+
await type(` ${ISSUE}`)
|
|
331
|
+
expect(screen.getByText('Card of item one')).toBeTruthy()
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('a card the app learns of later shows when the app says its answers changed', async () => {
|
|
335
|
+
let known = false
|
|
336
|
+
let listener = () => {}
|
|
337
|
+
const under: BoxUnder = {
|
|
338
|
+
...reader(() => known),
|
|
339
|
+
changed: (l) => {
|
|
340
|
+
listener = l
|
|
341
|
+
return () => {}
|
|
342
|
+
},
|
|
343
|
+
}
|
|
344
|
+
render(<Box under={under} />)
|
|
345
|
+
await type(`see ${ISSUE}`)
|
|
346
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
347
|
+
known = true
|
|
348
|
+
await act(async () => listener())
|
|
349
|
+
expect(screen.getByText('Card of item one')).toBeTruthy()
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('a refused send shown at once puts the words back without the card ✕ took off', async () => {
|
|
353
|
+
const answer = later<SendAnswer>()
|
|
354
|
+
const send = vi.fn<CommentBoxProps['send']>(() => answer.promise)
|
|
355
|
+
render(<Box send={send} under={reader()} showsAtOnce />)
|
|
356
|
+
await type(`see ${ISSUE}`)
|
|
357
|
+
await removeCard()
|
|
358
|
+
await press('Enter')
|
|
359
|
+
expect(send.mock.calls[0][2]).toEqual({})
|
|
360
|
+
await act(async () => answer.answer({ accepted: false, reason: 'the relay is busy' }))
|
|
361
|
+
await settle()
|
|
362
|
+
expect(editorOf().getText()).toBe(`see ${ISSUE}`)
|
|
363
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
it('a block link shows its live part under the box and no card', async () => {
|
|
367
|
+
render(<Box under={reader()} />)
|
|
368
|
+
await type(`see ${ISSUE} and ${BLOCK}`)
|
|
369
|
+
expect(screen.getByText('Live part of page two')).toBeTruthy()
|
|
370
|
+
expect(screen.queryByText('Card of item one')).toBeNull()
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('the edit box shows the card it would add and no part, and Save carries the card', async () => {
|
|
374
|
+
const onSave = vi.fn<CommentBoxEdit['onSave']>(async () => ({ accepted: true }))
|
|
375
|
+
const under: BoxUnder = {
|
|
376
|
+
read: (body) => ({
|
|
377
|
+
card: { value: 'item-one', view: <span>Card of item one</span> },
|
|
378
|
+
parts: [{ key: 'page-two', view: <span>Live part of page two</span> }],
|
|
379
|
+
names: textOf(body) ? ['item-one', 'page-two'] : [],
|
|
380
|
+
}),
|
|
381
|
+
}
|
|
382
|
+
const body: JSONContent = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: `see ${ISSUE}` }] }] }
|
|
383
|
+
render(<Box under={under} edit={{ body, onSave, onCancel: () => {} }} />)
|
|
384
|
+
expect(screen.getByText('Card of item one')).toBeTruthy()
|
|
385
|
+
expect(screen.queryByText('Live part of page two')).toBeNull()
|
|
386
|
+
await press('Enter')
|
|
387
|
+
expect(onSave.mock.calls[0][2]).toEqual({ card: 'item-one' })
|
|
388
|
+
})
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
describe('a URL pasted over words', () => {
|
|
392
|
+
const URL_ = 'https://app.example/item/one'
|
|
393
|
+
const doc = (...content: JSONContent[]): JSONContent => ({ type: 'doc', content: [{ type: 'paragraph', content }] })
|
|
394
|
+
const editing = (body: JSONContent) => ({ body, onSave: async (): Promise<SendAnswer> => ({ accepted: true }), onCancel: () => {} })
|
|
395
|
+
|
|
396
|
+
/** Selects `from`–`to` (1 is the paragraph's start; 'all' selects everything) and pastes `text`, in one act so the box's
|
|
397
|
+
* opening focus (a frame later) cannot collapse the selection in between. */
|
|
398
|
+
async function pasteOver(from: number | 'all', to: number, text: string) {
|
|
399
|
+
await act(async () => {
|
|
400
|
+
const editor = editorOf()
|
|
401
|
+
if (from === 'all') editor.commands.selectAll()
|
|
402
|
+
else editor.commands.setTextSelection({ from, to })
|
|
403
|
+
const event = { clipboardData: { getData: (type: string) => (type === 'text/plain' ? text : '') }, preventDefault: () => {} } as unknown as ClipboardEvent
|
|
404
|
+
const slice = new Slice(Fragment.from(editor.state.schema.text(text)), 0, 0)
|
|
405
|
+
editor.view.someProp('handlePaste', (handle) => handle(editor.view, event, slice))
|
|
406
|
+
})
|
|
407
|
+
}
|
|
408
|
+
const runs = () =>
|
|
409
|
+
((editorOf().getJSON() as JSONContent).content?.[0].content ?? []).map((n) => {
|
|
410
|
+
const link = n.marks?.find((m) => m.type === 'link')
|
|
411
|
+
return link ? `link:${n.text}>${link.attrs?.href}` : `${n.type}:${n.text ?? ''}`
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
it('links the words, and what is typed after them is not linked', async () => {
|
|
415
|
+
render(<Box edit={editing(doc({ type: 'text', text: 'see the plan now' }))} />)
|
|
416
|
+
await pasteOver(5, 13, URL_)
|
|
417
|
+
expect(runs()).toEqual(['text:see ', `link:the plan>${URL_}`, 'text: now'])
|
|
418
|
+
await act(async () => {
|
|
419
|
+
editorOf().chain().setTextSelection(13).insertContent('!').run()
|
|
420
|
+
})
|
|
421
|
+
expect(runs()).toEqual(['text:see ', `link:the plan>${URL_}`, 'text:! now'])
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
it('select-all over one line links all its words, without the full stop copied after the URL', async () => {
|
|
425
|
+
render(<Box edit={editing(doc({ type: 'text', text: 'the plan' }))} />)
|
|
426
|
+
await pasteOver('all', 0, `${URL_}.`)
|
|
427
|
+
expect(runs()).toEqual([`link:the plan>${URL_}`])
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
it('words holding a bracket keep their words, and the URL goes in after them', async () => {
|
|
431
|
+
render(<Box edit={editing(doc({ type: 'text', text: 'see [the] plan' }))} />)
|
|
432
|
+
await pasteOver(5, 15, URL_)
|
|
433
|
+
expect(runs()).toEqual([`text:see [the] plan ${URL_}`])
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
it('words across a line break keep their words, and the URL goes in after them', async () => {
|
|
437
|
+
render(<Box edit={editing(doc({ type: 'text', text: 'one' }, { type: 'hardBreak' }, { type: 'text', text: 'two' }))} />)
|
|
438
|
+
await pasteOver(1, 8, URL_)
|
|
439
|
+
expect(runs()).toEqual(['text:one', 'hardBreak:', `text:two ${URL_}`])
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
it('a URL a message cannot carry on words, with a parenthesis, goes in after the words', async () => {
|
|
443
|
+
render(<Box edit={editing(doc({ type: 'text', text: 'the spec' }))} />)
|
|
444
|
+
await pasteOver(1, 9, 'https://wiki.example/Nostr_(protocol)')
|
|
445
|
+
expect(runs()).toEqual(['text:the spec https://wiki.example/Nostr_(protocol)'])
|
|
446
|
+
})
|
|
447
|
+
})
|