Compare commits

...

1 Commits

Author SHA1 Message Date
01zulfi
fce3f3bfed editor: migrate collapsed headings inside tables
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
2025-11-12 13:46:11 +05:00

View File

@@ -162,7 +162,7 @@ export const Heading = TiptapHeading.extend({
},
addProseMirrorPlugins() {
return [headingUpdatePlugin];
return [headingUnderTablesMigration, headingUpdatePlugin];
},
addNodeView() {
@@ -394,3 +394,35 @@ const headingUpdatePlugin = new Plugin({
return modified ? tr : null;
}
});
const headingUnderTablesMigration = new Plugin({
key: new PluginKey("headingUnderTablesMigration"),
appendTransaction(_, __, newState) {
const tr = newState.tr;
let modified = false;
newState.doc.descendants((node, pos) => {
if (node.type.name === "table") {
node.descendants((childNode, childPos) => {
const absolutePos = pos + childPos + 1;
if (childNode.type.name === "heading" && childNode.attrs.collapsed) {
tr.setNodeAttribute(absolutePos, "collapsed", false);
modified = true;
}
if (
COLLAPSIBLE_BLOCK_TYPES.includes(childNode.type.name) &&
childNode.attrs.hidden
) {
tr.setNodeAttribute(absolutePos, "hidden", false);
modified = true;
}
});
}
});
return modified ? tr : null;
}
});