Add NIP definitions when hovering over "NIP-xx"

This commit is contained in:
hzrd149 2023-12-21 09:28:50 -06:00
parent c77a457972
commit 1191d99cd4
7 changed files with 45 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
"nostrudel": minor
---
Add NIP definitions when hovering over "NIP-xx"

View File

@ -1,4 +1,4 @@
import { Link } from "@chakra-ui/react";
import { Link, Text, Tooltip } from "@chakra-ui/react";
import { Link as RouterLink } from "react-router-dom";
import { EmbedableContent, embedJSX } from "../../helpers/embeds";
@ -7,6 +7,7 @@ import UserLink from "../user-link";
import { getMatchHashtag, getMatchNostrLink, stripInvisibleChar } from "../../helpers/regexp";
import { safeDecode } from "../../helpers/nip19";
import { EmbedEventPointer } from "../embed-event";
import { NIP_NAMES } from "../../views/relays/components/supported-nips";
// nostr:nevent1qqsthg2qlxp9l7egtwa92t8lusm7pjknmjwa75ctrrpcjyulr9754fqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduq36amnwvaz7tmwdaehgu3dwp6kytnhv4kxcmmjv3jhytnwv46q2qg5q9
// nostr:nevent1qqsq3wc73lqxd70lg43m5rul57d4mhcanttjat56e30yx5zla48qzlspz9mhxue69uhkummnw3e82efwvdhk6qgdwaehxw309ahx7uewd3hkcq5hsum
@ -93,3 +94,22 @@ export function embedNostrHashtags(content: EmbedableContent, event: NostrEvent
},
});
}
export function embedNipDefinitions(content: EmbedableContent) {
return embedJSX(content, {
name: "nip-definition",
regexp: /nip-?(\d\d)/gi,
render: (match) => {
if (NIP_NAMES[match[1]]) {
return (
<Tooltip label={NIP_NAMES[match[1]]} aria-label="NIP Definition">
<Text as="abbr" title={NIP_NAMES[match[1]]}>
{match[0]}
</Text>
</Tooltip>
);
}
return null;
},
});
}

View File

@ -26,6 +26,7 @@ import {
renderSoundCloudUrl,
renderSimpleXLink,
renderRedditUrl,
embedNipDefinitions,
} from "../embed-types";
import { LightboxProvider } from "../lightbox-provider";
@ -63,6 +64,7 @@ function buildContents(event: NostrEvent | DraftNostrEvent, simpleLinks = false)
content = embedNostrLinks(content);
content = embedNostrMentions(content, event);
content = embedNostrHashtags(content, event);
content = embedNipDefinitions(content);
content = embedEmoji(content, event);
return content;

View File

@ -9,6 +9,7 @@ import {
embedEmoji,
embedImageGallery,
embedLightningInvoice,
embedNipDefinitions,
embedNostrHashtags,
embedNostrLinks,
embedNostrMentions,
@ -64,6 +65,7 @@ const ChannelMessageContent = memo(({ message, children, ...props }: BoxProps &
c = embedNostrLinks(c);
c = embedNostrMentions(c, message);
c = embedNostrHashtags(c, message);
c = embedNipDefinitions(c);
c = embedEmoji(c, message);
return c;

View File

@ -1,7 +1,7 @@
import { Flex, Tag, Tooltip } from "@chakra-ui/react";
// copied from github
const NIP_NAMES: Record<string, string> = {
export const NIP_NAMES: Record<string, string> = {
"01": "Basic protocol",
"02": "Contact List and Petnames",
"03": "OpenTimestamps Attestations for Events",
@ -17,13 +17,13 @@ const NIP_NAMES: Record<string, string> = {
"13": "Proof of Work",
"14": "Subject tag in text events",
"15": "Nostr Marketplace",
"16": "Event Treatment",
"18": "Reposts",
"19": "bech32-encoded entities",
"20": "Command Results",
"21": "nostr: URI scheme",
"22": "Event created_at Limits",
"22": "Event created_at Limits", // removed
"23": "Long-form Content",
"24": "Extra metadata fields and tags",
"25": "Reactions",
"26": "Delegated Event Signing",
"27": "Text Note References",
@ -31,14 +31,17 @@ const NIP_NAMES: Record<string, string> = {
"30": "Custom Emoji",
"31": "Dealing with Unknown Events",
"32": "Labeling",
"33": "Parameterized Replaceable Events",
"33": "Parameterized Replaceable Events", //removed
"36": "Sensitive Content",
"38": "User Statuses",
"39": "External Identities in Profiles",
"40": "Expiration Timestamp",
"42": "Authentication of clients to relays",
"44": "Versioned Encryption",
"45": "Counting results",
"46": "Nostr Connect",
"47": "Wallet Connect",
"48": "Proxy Tags",
"50": "Keywords filter",
"51": "Lists",
"52": "Calendar Events",
@ -47,8 +50,12 @@ const NIP_NAMES: Record<string, string> = {
"57": "Lightning Zaps",
"58": "Badges",
"65": "Relay List Metadata",
"72": "Moderated Communities",
"75": "Zap Goals",
"78": "Application-specific data",
"84": "Highlights",
"89": "Recommended Application Handlers",
"90": "Data Vending Machines",
"94": "File Metadata",
"98": "HTTP Auth",
"99": "Classified Listings",

View File

@ -3,6 +3,7 @@ import { ParsedStream } from "../../../helpers/nostr/stream";
import { EmbedableContent, embedUrls } from "../../../helpers/embeds";
import {
embedEmoji,
embedNipDefinitions,
embedNostrHashtags,
embedNostrLinks,
embedNostrMentions,
@ -23,6 +24,7 @@ export default function StreamSummaryContent({ stream, ...props }: BoxProps & {
c = embedNostrLinks(c);
c = embedNostrMentions(c, stream.event);
c = embedNostrHashtags(c, stream.event);
c = embedNipDefinitions(c);
c = embedEmoji(c, stream.event);
return c;

View File

@ -3,6 +3,7 @@ import React, { useMemo } from "react";
import { EmbedableContent, embedUrls } from "../../../../helpers/embeds";
import {
embedEmoji,
embedNipDefinitions,
embedNostrHashtags,
embedNostrLinks,
embedNostrMentions,
@ -24,6 +25,7 @@ const ChatMessageContent = React.memo(({ event }: { event: NostrEvent }) => {
c = embedNostrLinks(c);
c = embedNostrMentions(c, event);
c = embedNostrHashtags(c, event);
c = embedNipDefinitions(c);
c = embedEmoji(c, event);
return c;