Stop trying to use editor to view notes

This commit is contained in:
Jon Staab
2024-09-24 11:03:19 -07:00
parent 256a70d6fb
commit 148208f072
8 changed files with 12 additions and 67 deletions
+7 -4
View File
@@ -1,8 +1,8 @@
import {last} from '@welshman/lib'
import {Node, InputRule, nodePasteRule, type PasteRuleMatch} from "@tiptap/core"
import {last} from "@welshman/lib"
import {Node, InputRule, nodePasteRule} from "@tiptap/core"
import type {Node as ProsemirrorNode} from "@tiptap/pm/model"
import type {MarkdownSerializerState} from "prosemirror-markdown"
import {createPasteRuleMatch, createInputRuleMatch} from './util'
import {createPasteRuleMatch} from "./util"
export const LINK_REGEX =
/([a-z\+:]{2,30}:\/\/)?[^<>\(\)\s]+\.[a-z]{2,6}[^\s]*[^<>"'\.!?,:\s\)\(]*/gi
@@ -87,7 +87,10 @@ export const LinkExtension = Node.create({
try {
tr.insert(range.from - 1, this.type.create(match.data))
.delete(tr.mapping.map(range.from - 1), tr.mapping.map(range.to))
.insert(tr.mapping.map(range.to), this.editor.schema.text(last(Array.from(match.input!))))
.insert(
tr.mapping.map(range.to),
this.editor.schema.text(last(Array.from(match.input!))),
)
} catch (e) {
// If the node was already linkified, the above code breaks for whatever reason
}
+1 -35
View File
@@ -52,7 +52,6 @@ type EditorOptions = {
loading: Writable<boolean>
getPubkeyHints: (pubkey: string) => string[]
submitOnEnter?: boolean
content?: string
autofocus?: boolean
}
@@ -80,11 +79,10 @@ export const getEditorOptions = ({
loading,
getPubkeyHints,
submitOnEnter,
content = "",
autofocus = false,
}: EditorOptions) => ({
content,
autofocus,
content: "",
extensions: [
Code,
CodeBlock,
@@ -141,36 +139,4 @@ export const getEditorOptions = ({
},
}),
],
// onTransaction() {
// // @ts-ignore
// console.log(this.getJSON())
// }
})
type ViewOptions = {
content: string
}
export const getViewOptions = ({content}: ViewOptions) => ({
content,
editable: false,
shouldRerenderOnTransaction: false,
extensions: [
Code,
CodeBlock,
Document,
Paragraph,
Text,
LinkExtension.extend({
addNodeView: () => SvelteNodeViewRenderer(EditLink),
}),
Bolt11Extension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditBolt11)})),
NProfileExtension.extend({
addNodeView: () => SvelteNodeViewRenderer(EditMention),
}),
NEventExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditEvent)})),
NAddrExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditEvent)})),
ImageExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditImage)})),
VideoExtension.extend(asInline({addNodeView: () => SvelteNodeViewRenderer(EditVideo)})),
],
})