From 49bc1d79e9d187d18e2a256431164989f51947dd Mon Sep 17 00:00:00 2001
From: 01zulfi <85733202+01zulfi@users.noreply.github.com>
Date: Thu, 12 Dec 2024 16:19:14 +0500
Subject: [PATCH] editor: fix outline list toggle not handling nested lists
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
---
.../extensions/outline-list/outline-list.ts | 34 +++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/packages/editor/src/extensions/outline-list/outline-list.ts b/packages/editor/src/extensions/outline-list/outline-list.ts
index 22b780d94f..bc9037231b 100644
--- a/packages/editor/src/extensions/outline-list/outline-list.ts
+++ b/packages/editor/src/extensions/outline-list/outline-list.ts
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+import { Fragment } from "@tiptap/pm/model";
import { getParentAttributes } from "../../utils/prosemirror.js";
import { Node, mergeAttributes, wrappingInputRule } from "@tiptap/core";
@@ -56,7 +57,7 @@ export const OutlineList = Node.create({
group: "block list",
- content: `${outlineListItemName}+`,
+ content: `(${outlineListItemName}|listItem)+`,
parseHTML() {
return [
@@ -123,12 +124,41 @@ export const OutlineList = Node.create({
];
},
addNodeView() {
- return ({ node, HTMLAttributes }) => {
+ return ({ editor, node, getPos, HTMLAttributes }) => {
const ul = document.createElement("ul");
ul.classList.add("outline-list");
if (node.attrs.textDirection) ul.dir = node.attrs.textDirection;
for (const key in HTMLAttributes)
ul.setAttribute(key, HTMLAttributes[key]);
+
+ const processNestedNodes = (parentNode: Fragment, parentPos: number) => {
+ parentNode.forEach((child, offset) => {
+ const childPos = parentPos + offset + 1;
+ if (
+ child.type.name === "bulletList" ||
+ child.type.name === "orderedList"
+ ) {
+ editor.commands.command(({ tr }) => {
+ tr.setNodeMarkup(childPos, editor.schema.nodes.outlineList);
+ return true;
+ });
+ }
+ if (child.type.name === "listItem") {
+ editor.commands.command(({ tr }) => {
+ tr.setNodeMarkup(childPos, editor.schema.nodes.outlineListItem);
+ return true;
+ });
+ }
+ processNestedNodes(child.content, childPos);
+ });
+ };
+
+ if (typeof getPos === "function") {
+ processNestedNodes(node.content, getPos());
+ } else {
+ processNestedNodes(node.content, Number(getPos));
+ }
+
return {
dom: ul,
contentDOM: ul