Files
boris/node_modules/applesauce-factory/dist/operations/highlight.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

47 lines
2.1 KiB
JavaScript

import { getAddressPointerForEvent, isAddressPointer, isEvent, isEventPointer, isReplaceable, } from "applesauce-core/helpers";
import { ensureMarkedProfilePointerTag } from "../helpers/common-tags.js";
import { addAddressTag, addEventTag } from "./tag/common.js";
import { includeSingletonTag, modifyPublicTags } from "./tags.js";
/** Sets the content (highlighted text) for a highlight event */
export function setHighlightContent(content) {
return (draft) => ({ ...draft, content });
}
/** Sets the source event that was highlighted using an 'e' tag */
export function setSource(source) {
if (isEvent(source)) {
if (isReplaceable(source.kind))
return modifyPublicTags(addEventTag(source, true), addAddressTag(getAddressPointerForEvent(source), true));
else
return modifyPublicTags(addEventTag(source, true));
}
else if (isAddressPointer(source)) {
return modifyPublicTags(addAddressTag(source, true));
}
else if (isEventPointer(source))
return modifyPublicTags(addEventTag(source, true));
else if (typeof source === "string")
return includeSingletonTag(["r", source]);
else
throw new Error("Invalid source");
}
/** Sets attribution for a pubkey with optional role using 'p' tags */
export function addAttribution(attribution) {
return modifyPublicTags((tags) => ensureMarkedProfilePointerTag(tags, attribution, attribution.role || "mention"));
}
/** Sets the context text for the highlight using a 'context' tag */
export function setContext(context) {
return includeSingletonTag(["context", context]);
}
/** Sets a comment for the highlight using a 'comment' tag to create a quote highlight */
export function setComment(comment) {
return includeSingletonTag(["comment", comment]);
}
/** Sets multiple attributions at once */
export function setAttributions(attributions) {
return modifyPublicTags(async (tags) => {
for (const attribution of attributions)
tags = ensureMarkedProfilePointerTag(tags, attribution, attribution.role || "mention");
return tags;
});
}