From 335cef892a24e5b7bf581e5a9d86a5a8a7865b3d Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sun, 11 Jan 2026 22:32:03 +0100 Subject: [PATCH] adsasd --- public/assets/js/bridge/blocks-custom.js | 1 + public/editor/bridge-core.js | 61 ++++++++++-------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/public/assets/js/bridge/blocks-custom.js b/public/assets/js/bridge/blocks-custom.js index 6273a40..111278b 100644 --- a/public/assets/js/bridge/blocks-custom.js +++ b/public/assets/js/bridge/blocks-custom.js @@ -53,6 +53,7 @@ addOnce(bm, 'cust-text', { id:'cust-text', label:'📝 Text', content:{ type:'text', + tagName:'p', content:'Dies ist ein Absatz. Doppelklick zum Bearbeiten.', style:{ 'font-family':'Arial,sans-serif', diff --git a/public/editor/bridge-core.js b/public/editor/bridge-core.js index 947ef21..0f1153b 100644 --- a/public/editor/bridge-core.js +++ b/public/editor/bridge-core.js @@ -309,42 +309,30 @@ log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn'); } - const wrapPlainTextNodes = (el) => { - if (!el || !el.ownerDocument) return false; - const doc = el.ownerDocument; - const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null); - 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) => { + if (!el) return false; + const nodes = Array.from(el.childNodes || []); + return nodes.some((node) => node && node.nodeType === 3 && node.textContent !== ''); }; - const hasPlainTextNodes = (el) => { - if (!el || !el.ownerDocument) return false; - const doc = el.ownerDocument; - const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null); - 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; - return true; - } - return false; + const buildTextnodeComponents = (el) => { + if (!el) return []; + const nodes = Array.from(el.childNodes || []); + const comps = []; + nodes.forEach((node) => { + if (!node) return; + if (node.nodeType === 3) { + const text = node.textContent; + if (text !== null && text !== undefined && text !== '') { + comps.push({ type: 'textnode', content: text }); + } + return; + } + if (node.nodeType === 1 && node.outerHTML) { + comps.push(node.outerHTML); + } + }); + return comps; }; const isTextLike = (cmp) => { @@ -357,10 +345,11 @@ if (!isTextLike(cmp)) return; const el = cmp.view.el; if (!hasPlainTextNodes(el)) return; - if (!wrapPlainTextNodes(el)) return; + const comps = buildTextnodeComponents(el); + if (!comps.length) return; try { if (typeof cmp.components === 'function') { - cmp.components(el.innerHTML); + cmp.components(comps); } else if (typeof cmp.set === 'function') { cmp.set('content', el.innerHTML); }