Parse content seeded into the editor so it contributes tags
This commit is contained in:
parent
32878e6e11
commit
d1da119389
5 changed files with 12 additions and 11 deletions
|
|
@ -959,7 +959,9 @@ test("US-045 turn a chat message into a thread", async ({seed, as}) => {
|
||||||
const composer = modal(page, "Create a Thread")
|
const composer = modal(page, "Create a Thread")
|
||||||
const nevent = nip19.neventEncode({id: promoted.id, kind: MESSAGE, relays: [url]})
|
const nevent = nip19.neventEncode({id: promoted.id, kind: MESSAGE, relays: [url]})
|
||||||
|
|
||||||
await expect(editorOf(composer)).toContainText(`nostr:${nevent}`)
|
// The seeded entity is parsed, so the composer shows the editor's chip for it rather than
|
||||||
|
// the raw uri — which is also what makes the thread carry a q tag for the message.
|
||||||
|
await expect(editorOf(composer)).toContainText(`${nevent.slice(0, 16)}...`)
|
||||||
|
|
||||||
await composer.getByPlaceholder("What is this thread about?").fill("Deploy failures")
|
await composer.getByPlaceholder("What is this thread about?").fill("Deploy failures")
|
||||||
await composer.getByRole("button", {name: "Create Thread"}).click()
|
await composer.getByRole("button", {name: "Create Thread"}).click()
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@
|
||||||
pushModal(ThreadCreate, {
|
pushModal(ThreadCreate, {
|
||||||
url,
|
url,
|
||||||
h,
|
h,
|
||||||
quote: event,
|
|
||||||
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
|
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@
|
||||||
{
|
{
|
||||||
url,
|
url,
|
||||||
h,
|
h,
|
||||||
quote: event,
|
|
||||||
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
|
initialValues: {content: toNostrURI(nip19.neventEncode({...event, relays: [url]}))},
|
||||||
},
|
},
|
||||||
{replaceState: true},
|
{replaceState: true},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {writable} from "svelte/store"
|
import {writable} from "svelte/store"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
|
||||||
import {relay} from "@welshman/util"
|
import {relay} from "@welshman/util"
|
||||||
import {Thread} from "@welshman/domain"
|
import {Thread} from "@welshman/domain"
|
||||||
import {publish} from "@welshman/app"
|
import {publish} from "@welshman/app"
|
||||||
|
|
@ -34,11 +33,10 @@
|
||||||
url: string
|
url: string
|
||||||
h?: string
|
h?: string
|
||||||
shareToChat?: boolean
|
shareToChat?: boolean
|
||||||
quote?: TrustedEvent
|
|
||||||
initialValues?: Values
|
initialValues?: Values
|
||||||
}
|
}
|
||||||
|
|
||||||
const {url, h, shareToChat = false, quote, initialValues}: Props = $props()
|
const {url, h, shareToChat = false, initialValues}: Props = $props()
|
||||||
const draftKey = new DraftKey<Values>(`thread:${url}:${h ?? ""}`)
|
const draftKey = new DraftKey<Values>(`thread:${url}:${h ?? ""}`)
|
||||||
const draft = draftKey.get()
|
const draft = draftKey.get()
|
||||||
const shouldProtect = $relays.hasNip(url, 70)
|
const shouldProtect = $relays.hasNip(url, 70)
|
||||||
|
|
@ -85,10 +83,6 @@
|
||||||
eventWriter.setRoom(url, room)
|
eventWriter.setRoom(url, room)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quote) {
|
|
||||||
eventWriter.addQuote(quote)
|
|
||||||
}
|
|
||||||
|
|
||||||
const thunk = await command(eventWriter).then(publish)
|
const thunk = await command(eventWriter).then(publish)
|
||||||
const error = await thunk.waitForError()
|
const error = await thunk.waitForError()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ export const makeEditor = async ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const ed = new Editor({
|
const ed = new Editor({
|
||||||
content: typeof content === "string" ? escapeHtml(content) : content,
|
content: typeof content === "string" ? undefined : content,
|
||||||
editorProps,
|
editorProps,
|
||||||
element: document.createElement("div"),
|
element: document.createElement("div"),
|
||||||
extensions: [
|
extensions: [
|
||||||
|
|
@ -305,6 +305,13 @@ export const makeEditor = async ({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// nostr-editor turns a `nostr:` entity into a node from a paste rule, and the constructor's
|
||||||
|
// `content` option runs none, so seeded text stays text and contributes no tags. Set it here
|
||||||
|
// instead, flagged as a paste. A restored draft is already a document and needs no parse.
|
||||||
|
if (typeof content === "string" && content) {
|
||||||
|
ed.chain().setMeta("uiEvent", "paste").setContent(escapeHtml(content)).run()
|
||||||
|
}
|
||||||
|
|
||||||
// Seed the caller's store from the document tiptap actually parsed — a restored draft is a
|
// Seed the caller's store from the document tiptap actually parsed — a restored draft is a
|
||||||
// document even when it holds no text, so the caller can't tell from `content` alone. Callers
|
// document even when it holds no text, so the caller can't tell from `content` alone. Callers
|
||||||
// clear their draft when this reads true, so it has to be set before they render: keep every
|
// clear their draft when this reads true, so it has to be set before they render: keep every
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue