Commit 11f5fe77 authored by jan.koester's avatar jan.koester
Browse files

new renderer

parent fafa8156
Loading
Loading
Loading
Loading
+31 −4
Changes for data/template/default/editor.html: 31 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -2673,6 +2673,7 @@

            if (!targetName || !window._publishTargets) {
                formEl.innerHTML = '';
                reloadIframe(); // Reset preview to default
                return;
            }

@@ -2687,9 +2688,9 @@
            for (const field of fields) {
                html += `<label class="text-xs text-gray-300 block mt-2 mb-1">${escapeHtml(field.label || field.key)}</label>`;
                if (field.type === 'textarea') {
                    html += `<textarea class="prop-textarea" id="pub-${field.key}" name="${field.key}" placeholder="${escapeHtml(field.placeholder || '')}"></textarea>`;
                    html += `<textarea class="prop-textarea" id="pub-${field.key}" name="${field.key}" placeholder="${escapeHtml(field.placeholder || '')}" oninput="previewPublish('${escapeHtml(targetName)}')"></textarea>`;
                } else if (field.type === 'select' && field.options) {
                    html += `<select class="prop-select" id="pub-${field.key}" name="${field.key}">`;
                    html += `<select class="prop-select" id="pub-${field.key}" name="${field.key}" onchange="previewPublish('${escapeHtml(targetName)}')">`;
                    for (const opt of field.options) {
                        const optLabel = (typeof opt === 'object') ? opt.label : opt;
                        const optVal = (typeof opt === 'object') ? opt.value : opt;
@@ -2697,13 +2698,39 @@
                    }
                    html += '</select>';
                } else {
                    html += `<input class="prop-input" type="${field.type || 'text'}" id="pub-${field.key}" name="${field.key}" placeholder="${escapeHtml(field.placeholder || '')}" ${field.required ? 'required' : ''}>`;
                    html += `<input class="prop-input" type="${field.type || 'text'}" id="pub-${field.key}" name="${field.key}" placeholder="${escapeHtml(field.placeholder || '')}" ${field.required ? 'required' : ''} oninput="previewPublish('${escapeHtml(targetName)}')">`;
                }
            }
            html += `<button class="tpl-btn tpl-btn-primary mt-3" style="background:#d97706;" onclick="doPublish('${escapeHtml(targetName)}')">&#x1F680; ${I18N.PUBLISH_NOW}</button>`;
            html += '<div class="flex gap-2 mt-3">';
            html += `<button class="tpl-btn" style="background:#2563eb;color:#fff;" onclick="previewPublish('${escapeHtml(targetName)}')">&#x1F441; Preview</button>`;
            html += `<button class="tpl-btn tpl-btn-primary" style="background:#d97706;" onclick="doPublish('${escapeHtml(targetName)}')">&#x1F680; ${I18N.PUBLISH_NOW}</button>`;
            html += '</div>';
            formEl.innerHTML = html;
        }

        /**
         * Update the preview iframe to show a publish preview with the target plugin's rendering.
         */
        function previewPublish(targetName) {
            if (!targetName) { reloadIframe(); return; }
            const target = (window._publishTargets || []).find(t => t.name === targetName);
            const fields = (target && target.fields) || [];

            const isMobile = renderingIframe.classList.contains('mobile-frame');
            const mobile = isMobile ? 'mobile=true&' : '';
            const authIdParam = getAuthId() ? `authid=${getAuthId()}&` : '';

            let params = `target=${encodeURIComponent(targetName)}`;
            for (const field of fields) {
                const el = document.getElementById(`pub-${field.key}`);
                if (el && el.value) {
                    params += `&${encodeURIComponent(field.key)}=${encodeURIComponent(el.value)}`;
                }
            }

            renderingIframe.src = `${PREFIX}/render?${mobile}${authIdParam}rootel=WebEditor&${params}`;
        }

        /**
         * Execute the publish action: collect form data and send to backend.
         */