Skip to content

Commit 332c365

Browse files
authored
Ensure defaultNode has highest priority (#4985)
1 parent 0ca7c7f commit 332c365

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

modules/@apostrophecms/rich-text-widget/ui/apos/components/AposRichTextWidgetEditor.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ export default {
435435
.filter(Boolean)
436436
.concat(this.aposTiptapExtensions());
437437
438+
this.ensureExtensionsPriority(extensions);
439+
438440
this.editor = new Editor({
439441
content: this.initialContent,
440442
autofocus: this.autofocus,
@@ -670,6 +672,21 @@ export default {
670672
types: this.tiptapTypes
671673
}));
672674
},
675+
// Find the `defaultNode` extension and ensure it's registered first.
676+
// Any other priority related logic should be handled here.
677+
// Why sorting is important?
678+
// See https://github.com/ProseMirror/prosemirror/issues/1534#issuecomment-2984216986
679+
// related with list item issues and `defaultNode`.
680+
// NOTE: this handler mutates the input array for performance reasons.
681+
ensureExtensionsPriority(extensions) {
682+
const defaultNodeIndex = extensions.findIndex(ext => ext.name === 'defaultNode');
683+
if (defaultNodeIndex > 0) {
684+
const defaultNode = extensions.splice(defaultNodeIndex, 1)[0];
685+
extensions.unshift(defaultNode);
686+
}
687+
688+
return extensions;
689+
},
673690
showFloatingMenu({
674691
state, oldState
675692
}) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@tiptap/extension-underline": "^2.0.3",
5656
"@tiptap/starter-kit": "^2.0.3",
5757
"@tiptap/vue-3": "^2.0.3",
58-
"prosemirror-model": "1.25.0",
5958
"@vue/compiler-sfc": "^3.3.8",
6059
"autoprefixer": "^10.4.1",
6160
"bluebird": "^3.7.2",
@@ -143,4 +142,4 @@
143142
"browserslist": [
144143
"ie >= 10"
145144
]
146-
}
145+
}

0 commit comments

Comments
 (0)