@liveblocks/react-ui
Version:
A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.
63 lines (59 loc) • 1.68 kB
JavaScript
var slate = require('slate');
var getCharacter = require('./get-character.cjs');
const defaultMarks = {
bold: false,
italic: false,
strikethrough: false,
code: false
};
function isMarkActive(editor, mark) {
const marks = slate.Editor.marks(editor);
return marks ? marks[mark] === true : false;
}
function getMarks(editor) {
if (!editor) {
return { ...defaultMarks };
}
const marks = slate.Editor.marks(editor);
return { ...defaultMarks, ...marks };
}
function filterActiveMarks(value) {
return Object.keys(value ?? {}).filter(
(key) => key !== "text"
);
}
function toggleMark(editor, mark) {
const isActive = isMarkActive(editor, mark);
if (isActive) {
slate.Editor.removeMark(editor, mark);
} else {
slate.Editor.addMark(editor, mark, true);
}
}
function removeMarks(editor) {
const marks = slate.Editor.marks(editor);
if (marks) {
for (const mark in marks) {
slate.Editor.removeMark(editor, mark);
}
}
}
function leaveMarkEdge(editor, edge) {
if (editor.selection && slate.Range.isCollapsed(editor.selection)) {
const marks = Object.keys(slate.Editor.marks(editor) ?? {});
if (marks.length > 0) {
const sibling = edge === "start" ? getCharacter.getCharacterBefore(editor, editor.selection) : getCharacter.getCharacterAfter(editor, editor.selection);
if (!sibling) {
removeMarks(editor);
}
}
}
}
exports.filterActiveMarks = filterActiveMarks;
exports.getMarks = getMarks;
exports.isMarkActive = isMarkActive;
exports.leaveMarkEdge = leaveMarkEdge;
exports.removeMarks = removeMarks;
exports.toggleMark = toggleMark;
//# sourceMappingURL=marks.cjs.map
;