@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
30 lines (29 loc) • 1.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractHashtags = exports.getSelectedNode = void 0;
const selection_1 = require("@lexical/selection");
function getSelectedNode(selection) {
const anchor = selection.anchor;
const focus = selection.focus;
const anchorNode = selection.anchor.getNode();
const focusNode = selection.focus.getNode();
if (anchorNode === focusNode) {
return anchorNode;
}
const isBackward = selection.isBackward();
if (isBackward) {
return (0, selection_1.$isAtNodeEnd)(focus) ? anchorNode : focusNode;
}
else {
return (0, selection_1.$isAtNodeEnd)(anchor) ? anchorNode : focusNode;
}
}
exports.getSelectedNode = getSelectedNode;
/**
* Extract id of hashtags from html text
* @param html
*/
function extractHashtags(html) {
return Array.from(html.matchAll(/<hashtag id="(?<id>[0-9]+)">#(?<name>[^<>]+)<\/hashtag>/g)).map((match) => match.groups.id);
}
exports.extractHashtags = extractHashtags;
;