planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
import { Editor, Transforms } from 'slate';
function splitIntoParagraph(editor) {
Editor.withoutNormalizing(editor, () => {
Transforms.splitNodes(editor, { always: true });
Transforms.setNodes(editor, { type: 'paragraph' });
});
Editor.normalize(editor, { force: true });
return true;
}
export default splitIntoParagraph;

View File

@@ -0,0 +1,43 @@
import { Editor, Transforms } from 'slate';
import lowestMatchedAncestor from '../../matchers/lowestMatchedAncestor';
function unwrapIfCursorAtStart(editor, mergeWithPrevious = false) {
if (editor.selection.anchor.offset !== 0) return false;
let [node, path] = Editor.above(editor, lowestMatchedAncestor(editor, 'non-default'));
if (path.length == 0) return false;
const isHeading = `${node.type}`.startsWith('heading-');
if (isHeading) {
Transforms.setNodes(editor, { type: 'paragraph' });
return false;
}
const isBlock = Editor.isBlock(editor, node);
const [parentBlock, parentBlockPath] = Editor.above(
editor,
lowestMatchedAncestor(editor, 'block'),
);
if (!isBlock) {
if (!Editor.isStart(editor, path, parentBlockPath)) {
return false;
}
[node, path] = [parentBlock, parentBlockPath];
}
Editor.withoutNormalizing(editor, () => {
Transforms.unwrapNodes(editor, { match: n => n.type === node.type, split: true });
if (mergeWithPrevious) {
Transforms.mergeNodes(editor);
}
});
Editor.normalize(editor, { force: true });
return true;
}
export default unwrapIfCursorAtStart;

View File

@@ -0,0 +1,11 @@
import { Editor, Transforms } from 'slate';
function wrapListItemsInBlock(editor, blockType, listType) {
Editor.withoutNormalizing(editor, () => {
Transforms.wrapNodes(editor, { type: listType });
Transforms.wrapNodes(editor, { type: blockType }, { match: n => n.type === listType });
Transforms.liftNodes(editor, { match: n => n.type === blockType });
});
Editor.normalize(editor, { force: true });
}
export default wrapListItemsInBlock;