Skip to content

Commit

Permalink
Merge pull request #9 from cesardeazevedo/pr-2349
Browse files Browse the repository at this point in the history
Pr 2349
  • Loading branch information
cesardeazevedo authored Dec 19, 2024
2 parents 35cac0d + 069fdde commit 010a1c8
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
7 changes: 4 additions & 3 deletions examples/svelte/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import StarterKit from '@tiptap/starter-kit'
import { SvelteNodeViewRenderer } from 'svelte-tiptap'
import MentionEditor from './lib/Mention/MentionEditor.svelte'
import NEventEditor from './lib/NEvent/NEventEditor.svelte'
let element: HTMLDivElement
let editor: Editor
Expand All @@ -21,12 +22,12 @@
NostrExtension.configure({
extend: {
nprofile: {
// @ts-ignore
addNodeView: () => SvelteNodeViewRenderer(MentionEditor),
},
nevent: {
// TODO
// addNodeView: () => SvelteNodeViewRenderer(NEventEditor),
inline: true,
group: "inline",
addNodeView: () => SvelteNodeViewRenderer(NEventEditor),
},
},
}),
Expand Down
34 changes: 34 additions & 0 deletions examples/svelte/src/lib/NEvent/NEvent.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script lang="ts">
import { onMount } from 'svelte'
import { pool } from '../../nostr'
import type { NostrEvent } from 'nostr-tools/core'
export let id: string
export let nevent: string
export let relays: string[]
let event: any = null
onMount(async () => {
const subscription = pool.subscribeMany(relays, [{ ids: [id] }], {
onevent(e: NostrEvent) {
event = e
},
})
return () => subscription.close()
})
</script>

<span
data-tooltip={`
Id: ${id}
.
Relays: ${JSON.stringify(relays)}
`}>
{#if event}
<a href="#">{nevent.replace('nostr:', '').slice(0, 12)}: {event.content.slice(0, 20)}...</a>
{:else}
<span class="text-gray-600">loading</span>
{/if}
</span>
14 changes: 14 additions & 0 deletions examples/svelte/src/lib/NEvent/NEventEditor.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import type { NodeViewProps, NodeViewRendererProps } from '@tiptap/core'
import type { NEventAttributes } from 'nostr-editor'
import { NodeViewWrapper, NodeViewContent } from 'svelte-tiptap'
import NEvent from './NEvent.svelte'
export let node: NodeViewProps['node']
$: attrs = node.attrs as NEventAttributes
</script>

<NodeViewWrapper data-type="nevent" as="span">
<NEvent id={attrs.id} relays={attrs.relays} nevent={attrs.nevent} />
</NodeViewWrapper>
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"url": "https://github.com/cesardeazevedo/nostr-editor"
},
"files": [
"dist"
"dist",
"src"
],
"main": "./dist/nostr-editor.umd.cjs",
"module": "./dist/nostr-editor.js",
Expand All @@ -27,7 +28,8 @@
"type-check": "tsc --noEmit",
"format": "prettier --write .",
"test": "vitest",
"preview": "vite preview"
"preview": "vite preview",
"prepare": "npm run build"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/LinkExtension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { PasteRuleMatch } from '@tiptap/core'
import { Link } from '@tiptap/extension-link'
import { Link, type LinkOptions } from '@tiptap/extension-link'
import * as linkifyjs from 'linkifyjs'
import { getLinkKind } from '../helpers/utils'

export {LinkOptions}

export type LinkAttributes = {
href: string
}
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/NSecRejectExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Extension } from '@tiptap/core'

const NSEC_REGEX = /(nsec1[0-9a-z]+)/g

export type NSecRejectionOptions = {
export type NSecRejectOptions = {
onError?: (props: unknown) => void
}

export const NSecRejectExtension = Extension.create<NSecRejectionOptions>({
export const NSecRejectExtension = Extension.create<NSecRejectOptions>({
name: 'nsecReject',

addOptions() {
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/NostrExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { NEventAttributes } from './NEventExtension'
import { NEventExtension } from './NEventExtension'
import type { NProfileAttributes } from './NProfileExtension'
import { NProfileExtension } from './NProfileExtension'
import { NSecRejectExtension, type NSecRejectionOptions } from './NSecRejectExtension'
import { NSecRejectExtension, type NSecRejectOptions } from './NSecRejectExtension'
import type { TagAttributes } from './TagExtension'
import { TagExtension } from './TagExtension'
import { TweetExtension } from './TweetExtension'
Expand All @@ -44,7 +44,7 @@ export interface NostrOptions {
video?: Partial<NodeConfig>
tag?: Partial<MarkConfig>
bolt11?: Partial<NodeConfig>
nsecReject?: Partial<NSecRejectionOptions>
nsecReject?: Partial<NSecRejectOptions>
fileUpload?: Partial<FileUploadOptions>
}
nprofile?: boolean
Expand All @@ -57,7 +57,7 @@ export interface NostrOptions {
image?: Partial<ImageOptions> | false
video?: Partial<NodeConfig> | false
youtube?: Partial<YoutubeOptions> | false
nsecReject?: Partial<NSecRejectionOptions> | false
nsecReject?: Partial<NSecRejectOptions> | false
fileUpload?: Partial<FileUploadOptions> | false
}

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export { Bolt11Extension, type Bolt11Attributes } from './extensions/Bolt11Extension'
export { FileUploadExtension, type FileUploadOptions, type FileUploadStorage } from './extensions/FileUploadExtension'
export { ImageExtension, type ImageAttributes } from './extensions/ImageExtension'
export { LinkExtension, type LinkAttributes } from './extensions/LinkExtension'
export { ImageExtension, type ImageOptions, type ImageAttributes } from './extensions/ImageExtension'
export { LinkExtension, type LinkOptions, type LinkAttributes } from './extensions/LinkExtension'
export { NAddrExtension, type NAddrAttributes } from './extensions/NAddrExtension'
export { NEventExtension, type NEventAttributes } from './extensions/NEventExtension'
export { NostrExtension, type NostrOptions, type NostrStorage } from './extensions/NostrExtension'
export { NProfileExtension, type NProfileAttributes } from './extensions/NProfileExtension'
export { NSecRejectExtension, type NSecRejectionOptions } from './extensions/NSecRejectExtension'
export { NSecRejectExtension, type NSecRejectOptions } from './extensions/NSecRejectExtension'
export { TagExtension, type TagAttributes } from './extensions/TagExtension'
export { TweetExtension, type TweetAttributes } from './extensions/TweetExtension'
export { VideoExtension, type VideoAttributes } from './extensions/VideoExtension'
Expand Down

0 comments on commit 010a1c8

Please sign in to comment.