Don’t mind me, I found this forum post with Nico’s excellent feedback (Custom writer node works in panel but not on site - #2 by distantnative) and modified my plugin to the following.
index.js:
window.panel.plugin("frwssr/custom-nodes", {
writerNodes: {
centeredtext: {
get button() {
return {
icon: "text-center",
label: window.panel.$t("Text zentrieren")
}
},
commands({ type, utils }) {
return () => utils.setBlockType(type)
},
get name() {
return "centeredtext"
},
get schema() {
return {
content: "text*",
group: "block",
defining: true,
draggable: false,
parseDOM: [{
tag: "p",
priority: 51,
getAttrs: (node) =>
node.classList.contains("centeredtext") ? {} : false,
}],
toDOM: () => ["p", { class: "centeredtext" }, 0]
}
}
}
}
});
index.php:
<?php
use Kirby\Sane\Html;
Html::$allowedTags['p'] = ['class'];
Kirby::plugin('frwssr/custom-nodes', []);
Now it is working. Thanks, @distantnative!
Only flaw: I have another custom node to right-align text. Activating one of the two custom nodes marks both as active in the nodes dropdown.
