This commit is contained in:
2026-01-11 22:32:03 +01:00
parent bc82e04789
commit 335cef892a
2 changed files with 26 additions and 36 deletions

View File

@@ -53,6 +53,7 @@
addOnce(bm, 'cust-text', { id:'cust-text', label:'📝 Text', addOnce(bm, 'cust-text', { id:'cust-text', label:'📝 Text',
content:{ content:{
type:'text', type:'text',
tagName:'p',
content:'Dies ist ein Absatz. Doppelklick zum Bearbeiten.', content:'Dies ist ein Absatz. Doppelklick zum Bearbeiten.',
style:{ style:{
'font-family':'Arial,sans-serif', 'font-family':'Arial,sans-serif',

View File

@@ -309,42 +309,30 @@
log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn'); log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn');
} }
const wrapPlainTextNodes = (el) => { const hasPlainTextNodes = (el) => {
if (!el || !el.ownerDocument) return false; if (!el) return false;
const doc = el.ownerDocument; const nodes = Array.from(el.childNodes || []);
const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null); return nodes.some((node) => node && node.nodeType === 3 && node.textContent !== '');
const toWrap = [];
while (walker.nextNode()) {
const node = walker.currentNode;
if (!node || !node.parentNode) continue;
if (node.textContent === '') continue;
if (node.parentNode.nodeName && node.parentNode.nodeName.toLowerCase() === 'span') continue;
if (node.textContent.trim() === '') continue;
toWrap.push(node);
}
if (!toWrap.length) return false;
toWrap.forEach((node) => {
const span = doc.createElement('span');
span.setAttribute('data-gjs-text', '1');
span.textContent = node.textContent || '';
node.parentNode.replaceChild(span, node);
});
return true;
}; };
const hasPlainTextNodes = (el) => { const buildTextnodeComponents = (el) => {
if (!el || !el.ownerDocument) return false; if (!el) return [];
const doc = el.ownerDocument; const nodes = Array.from(el.childNodes || []);
const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null); const comps = [];
while (walker.nextNode()) { nodes.forEach((node) => {
const node = walker.currentNode; if (!node) return;
if (!node || !node.parentNode) continue; if (node.nodeType === 3) {
if (node.textContent === '') continue; const text = node.textContent;
if (node.parentNode.nodeName && node.parentNode.nodeName.toLowerCase() === 'span') continue; if (text !== null && text !== undefined && text !== '') {
if (node.textContent.trim() === '') continue; comps.push({ type: 'textnode', content: text });
return true;
} }
return false; return;
}
if (node.nodeType === 1 && node.outerHTML) {
comps.push(node.outerHTML);
}
});
return comps;
}; };
const isTextLike = (cmp) => { const isTextLike = (cmp) => {
@@ -357,10 +345,11 @@
if (!isTextLike(cmp)) return; if (!isTextLike(cmp)) return;
const el = cmp.view.el; const el = cmp.view.el;
if (!hasPlainTextNodes(el)) return; if (!hasPlainTextNodes(el)) return;
if (!wrapPlainTextNodes(el)) return; const comps = buildTextnodeComponents(el);
if (!comps.length) return;
try { try {
if (typeof cmp.components === 'function') { if (typeof cmp.components === 'function') {
cmp.components(el.innerHTML); cmp.components(comps);
} else if (typeof cmp.set === 'function') { } else if (typeof cmp.set === 'function') {
cmp.set('content', el.innerHTML); cmp.set('content', el.innerHTML);
} }