|
@@ -1,7 +1,12 @@
|
|
|
import { Editor } from 'slate';
|
|
|
-import { HeadingBlockData, TodoListBlockData } from '$app/interfaces/document';
|
|
|
-import { getAfterRangeAt, getBeforeRangeAt } from '$app/utils/document/slate/text';
|
|
|
-import { getDeltaAfterSelection, getDeltaFromSlateNodes } from '$app/utils/document/blocks/common';
|
|
|
+import {
|
|
|
+ BulletListBlockData,
|
|
|
+ HeadingBlockData,
|
|
|
+ NumberedListBlockData,
|
|
|
+ TodoListBlockData,
|
|
|
+} from '$app/interfaces/document';
|
|
|
+import { getBeforeRangeAt } from '$app/utils/document/slate/text';
|
|
|
+import { getDeltaAfterSelection } from '$app/utils/document/blocks/common';
|
|
|
|
|
|
/**
|
|
|
* get heading data from editor, only support markdown
|
|
@@ -43,10 +48,36 @@ export function getTodoListDataFromEditor(editor: Editor): TodoListBlockData | u
|
|
|
if (!selection) return;
|
|
|
const hashTags = Editor.string(editor, getBeforeRangeAt(editor, selection));
|
|
|
const checked = hashTags.match(/x/g)?.length;
|
|
|
- const slateNodes = Editor.fragment(editor, getAfterRangeAt(editor, selection));
|
|
|
- const delta = getDeltaFromSlateNodes(slateNodes);
|
|
|
+ const delta = getDeltaAfterSelection(editor);
|
|
|
+ if (!delta) return;
|
|
|
return {
|
|
|
delta,
|
|
|
checked: !!checked,
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * get bulleted_list data from editor, only support markdown
|
|
|
+ * @param editor
|
|
|
+ */
|
|
|
+export function getBulletedDataFromEditor(editor: Editor): BulletListBlockData | undefined {
|
|
|
+ const delta = getDeltaAfterSelection(editor);
|
|
|
+ if (!delta) return;
|
|
|
+ return {
|
|
|
+ delta,
|
|
|
+ format: 'default',
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * get numbered_list data from editor, only support markdown
|
|
|
+ * @param editor
|
|
|
+ */
|
|
|
+export function getNumberedListDataFromEditor(editor: Editor): NumberedListBlockData | undefined {
|
|
|
+ const delta = getDeltaAfterSelection(editor);
|
|
|
+ if (!delta) return;
|
|
|
+ return {
|
|
|
+ delta,
|
|
|
+ format: 'default',
|
|
|
+ };
|
|
|
+}
|