adsasd
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user