Commit 6fc244cc authored by jan.koester's avatar jan.koester
Browse files

test

parent 6ba8b2c2
Loading
Loading
Loading
Loading
+6 −101
Changes for data/template/default/editor.html: 6 added lines, 101 removed lines.
Original line number Diff line number Diff line
@@ -1215,106 +1215,8 @@
            loadElementSettings(elementId);
        }

        // --- Property Editor: Schema definitions per widget type ---
        // Each key is the plugin name (from the tree's typeId or resolved name).
        // Fields define the form controls to render.
        const WIDGET_SCHEMAS = {
            'Container': [
                { key: 'background_color', label: 'Background Color (Dark)', type: 'color', responsive: true },
                { key: 'l_background_color', label: 'Background Color (Light)', type: 'color' },
                { key: 'css_class', label: 'CSS Class', type: 'text', placeholder: 'e.g. my-container' },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: 'e.g. 8px', responsive: true },
                { key: 'border_style', label: 'Border', type: 'text', placeholder: 'e.g. 1px solid #ccc', responsive: true },
                { key: 'opacity', label: 'Opacity', type: 'text', placeholder: '0.0 - 1.0', responsive: true },
                { key: 'vertical_align', label: 'Vertical Align', type: 'select', options: ['top','center','bottom'], responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'TextBox': [
                { key: 'content', label: 'Content', type: 'richtext' },
                { key: 'font_family', label: 'Font Family', type: 'text', placeholder: 'e.g. Arial, sans-serif' },
                { key: 'font_size', label: 'Font Size', type: 'text', placeholder: 'e.g. 16px', responsive: true },
                { key: 'font_color', label: 'Font Color (Dark)', type: 'color', responsive: true },
                { key: 'l_font_color', label: 'Font Color (Light)', type: 'color' },
                { key: 'text_align', label: 'Text Align', type: 'select', options: ['left','center','right','justify'], responsive: true },
                { key: 'font_weight', label: 'Font Weight', type: 'select', options: ['normal','bold','lighter','bolder'] },
                { key: 'font_style', label: 'Font Style', type: 'select', options: ['normal','italic','oblique'] },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Button': [
                { key: 'label', label: 'Button Label', type: 'text' },
                { key: 'link_type', label: 'Link Type', type: 'select', options: ['url','section'] },
                { key: 'link_url', label: 'Link URL', type: 'text', placeholder: 'https://...', visibleWhen: { key: 'link_type', value: 'url' } },
                { key: 'open_new_tab', label: 'Open in New Tab', type: 'checkbox', visibleWhen: { key: 'link_type', value: 'url' } },
                { key: 'section_id', label: 'Target Section', type: 'section_select', visibleWhen: { key: 'link_type', value: 'section' } },
                { key: 'background_color', label: 'Background Color (Dark)', type: 'color' },
                { key: 'l_background_color', label: 'Background Color (Light)', type: 'color' },
                { key: 'text_color', label: 'Text Color (Dark)', type: 'color' },
                { key: 'l_text_color', label: 'Text Color (Light)', type: 'color' },
                { key: 'font_size', label: 'Font Size', type: 'text', placeholder: '16px', responsive: true },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: '4px', responsive: true },
                { key: 'padding', label: 'Padding', type: 'text', placeholder: '10px 20px', responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Grid': [
                { key: 'columns', label: 'Columns', type: 'text', placeholder: 'e.g. 1fr 1fr 1fr', responsive: true },
                { key: 'rows', label: 'Rows', type: 'text', placeholder: 'e.g. auto auto', responsive: true },
                { key: 'gap', label: 'Gap', type: 'text', placeholder: '10px', responsive: true },
                { key: 'background_color', label: 'Background Color (Dark)', type: 'color', responsive: true },
                { key: 'l_background_color', label: 'Background Color (Light)', type: 'color' },
                { key: 'padding', label: 'Padding', type: 'text', placeholder: '10px', responsive: true },
                { key: 'css_class', label: 'CSS Class', type: 'text', placeholder: 'e.g. my-grid' },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: 'e.g. 8px', responsive: true },
                { key: 'border_style', label: 'Border', type: 'text', placeholder: 'e.g. 1px solid #ccc', responsive: true },
                { key: 'opacity', label: 'Opacity', type: 'text', placeholder: '0.0 - 1.0', responsive: true },
                { key: 'vertical_align', label: 'Vertical Align', type: 'select', options: ['top','center','bottom'], responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Image': [
                { key: 'media_id', label: 'Media (from MediaDB)', type: 'media_browse' },
                { key: 'media_ext', label: 'Format', type: 'select', options: ['webp','png','jpg','jpeg','gif','avif','svg'] },
                { key: 'real_width', label: 'Preview Width (px)', type: 'number', min: 0 },
                { key: 'real_height', label: 'Preview Height (px)', type: 'number', min: 0 },
                { key: 'src', label: 'Image Path (manual)', type: 'text', placeholder: '/path/to/image.jpg' },
                { key: 'alt', label: 'Alt Text', type: 'text' },
                { key: 'width', label: 'CSS Width', type: 'text', placeholder: '100%', responsive: true },
                { key: 'height', label: 'CSS Height', type: 'text', placeholder: 'auto', responsive: true },
                { key: 'object_fit', label: 'Object Fit', type: 'select', options: ['cover','contain','fill','none','scale-down'] },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: '0' },
                { key: 'link_url', label: 'Link URL', type: 'text', placeholder: '/page or https://...' },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Table': [
                { key: 'num_rows', label: 'Rows', type: 'number', min: 1 },
                { key: 'num_cols', label: 'Columns', type: 'number', min: 1 },
                { key: 'has_header', label: 'Has Header Row', type: 'checkbox' },
                { key: 'border_style', label: 'Border Style', type: 'text', placeholder: '1px solid #ccc', responsive: true },
                { key: 'cell_padding', label: 'Cell Padding', type: 'text', placeholder: '8px', responsive: true },
                { key: 'background_color', label: 'Background Color (Dark)', type: 'color' },
                { key: 'l_background_color', label: 'Background Color (Light)', type: 'color' },
                { key: 'vertical_align', label: 'Vertical Align', type: 'select', options: ['top','center','bottom'], responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'CustomHtml': [
                { key: 'html_content', label: 'HTML Content', type: 'textarea', placeholder: '<div>Your custom HTML here</div>' },
                { key: 'css_content', label: 'CSS', type: 'textarea', placeholder: 'color: red; font-size: 16px;' },
                { key: 'js_content', label: 'JavaScript', type: 'textarea', placeholder: 'console.log("Hello from widget");' },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ],
            'Section': [
                { key: 'background_color', label: 'Background Color (Dark)', type: 'color', responsive: true },
                { key: 'l_background_color', label: 'Background Color (Light)', type: 'color' },
                { key: 'css_class', label: 'CSS Class', type: 'text', placeholder: 'e.g. hero-section' },
                { key: 'padding', label: 'Padding', type: 'text', placeholder: 'e.g. 40px 20px', responsive: true },
                { key: 'margin', label: 'Margin', type: 'text', placeholder: 'e.g. 0 auto', responsive: true },
                { key: 'max_width', label: 'Max Width', type: 'text', placeholder: 'e.g. 1200px', responsive: true },
                { key: 'min_height', label: 'Min Height', type: 'text', placeholder: 'e.g. 400px', responsive: true },
                { key: 'border_radius', label: 'Border Radius', type: 'text', placeholder: 'e.g. 8px', responsive: true },
                { key: 'border_style', label: 'Border', type: 'text', placeholder: 'e.g. 1px solid #ccc', responsive: true },
                { key: 'opacity', label: 'Opacity', type: 'text', placeholder: '0.0 - 1.0', responsive: true },
                { key: 'vertical_align', label: 'Vertical Align', type: 'select', options: ['top','center','bottom'], responsive: true },
                { key: 'hidden', label: 'Hidden', type: 'checkbox', responsive: true }
            ]
        };
        // --- Property Editor: Schema cache (fetched from backend per widget type) ---
        const WIDGET_SCHEMAS = {};

        // Cache: stores { uuid -> { name, typeId, properties } } for the currently loaded element
        let currentEditingElement = null;
@@ -1383,7 +1285,10 @@
                typeEl.textContent = widgetName;
                typeEl.style.display = 'inline-block';

                // Get schema for this widget type
                // Get schema from API response (cached per widget type)
                if (result.schema && Array.isArray(result.schema) && result.schema.length > 0) {
                    WIDGET_SCHEMAS[widgetName] = result.schema;
                }
                const schema = WIDGET_SCHEMAS[widgetName];

                if (!schema || schema.length === 0) {
+15 −0
Changes for src/edit.cpp: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1219,6 +1219,21 @@ void blogi::webedit::WebEditor::JsonApi(const int tid, json_object *request, jso

                    json_object_put(read_req);
                    json_object_put(plugin_resp);

                    // Fetch widget schema
                    json_object *schema_req = json_object_new_object();
                    json_object_object_add(schema_req, "action", json_object_new_string("get_schema"));
                    json_object *schema_resp = json_object_new_object();
                    el->JsonApi(schema_req, schema_resp);

                    json_object *schema_obj = nullptr;
                    if (json_object_object_get_ex(schema_resp, "schema", &schema_obj)) {
                        json_object_object_add(single_response, "schema", json_object_get(schema_obj));
                    }

                    json_object_put(schema_req);
                    json_object_put(schema_resp);

                    handled = true;
                } else {
                    json_object_object_add(single_response, "status", json_object_new_string("error"));
+48 −0
Changes for src/webedit/button/button.cpp: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -226,6 +226,10 @@ extern "C" {
                    if (response) {
                        json_object_object_add(response, "data", result_obj);
                    }
                } else if (strcmp(action, "get_schema") == 0) {
                    if (response) {
                        json_object_object_add(response, "schema", getSchemaJson());
                    }
                }

                if (response != nullptr) {
@@ -234,6 +238,50 @@ extern "C" {
                }
            }

            // --- Schema ---
            static json_object* getSchemaJson() {
                json_object *arr = json_object_new_array();
                auto addField = [&](const char *key, const char *label, const char *type,
                                    const char *placeholder = nullptr, bool responsive = false,
                                    json_object *options = nullptr,
                                    json_object *visibleWhen = nullptr) {
                    json_object *f = json_object_new_object();
                    json_object_object_add(f, "key", json_object_new_string(key));
                    json_object_object_add(f, "label", json_object_new_string(label));
                    json_object_object_add(f, "type", json_object_new_string(type));
                    if (placeholder) json_object_object_add(f, "placeholder", json_object_new_string(placeholder));
                    if (responsive) json_object_object_add(f, "responsive", json_object_new_boolean(true));
                    if (options) json_object_object_add(f, "options", options);
                    if (visibleWhen) json_object_object_add(f, "visibleWhen", visibleWhen);
                    json_object_array_add(arr, f);
                };
                auto mkOpts = [](std::initializer_list<const char*> vals) {
                    json_object *a = json_object_new_array();
                    for (auto v : vals) json_object_array_add(a, json_object_new_string(v));
                    return a;
                };
                auto mkVisible = [](const char *key, const char *value) {
                    json_object *o = json_object_new_object();
                    json_object_object_add(o, "key", json_object_new_string(key));
                    json_object_object_add(o, "value", json_object_new_string(value));
                    return o;
                };
                addField("label", "Button Label", "text");
                addField("link_type", "Link Type", "select", nullptr, false, mkOpts({"url","section"}));
                addField("link_url", "Link URL", "text", "https://...", false, nullptr, mkVisible("link_type","url"));
                addField("open_new_tab", "Open in New Tab", "checkbox", nullptr, false, nullptr, mkVisible("link_type","url"));
                addField("section_id", "Target Section", "section_select", nullptr, false, nullptr, mkVisible("link_type","section"));
                addField("background_color", "Background Color (Dark)", "color");
                addField("l_background_color", "Background Color (Light)", "color");
                addField("text_color", "Text Color (Dark)", "color");
                addField("l_text_color", "Text Color (Light)", "color");
                addField("font_size", "Font Size", "text", "16px", true);
                addField("border_radius", "Border Radius", "text", "4px", true);
                addField("padding", "Padding", "text", "10px 20px", true);
                addField("hidden", "Hidden", "checkbox", nullptr, true);
                return arr;
            }

            // --- XML Persistence ---
            tinyxml2::XMLElement* toXmlObject(tinyxml2::XMLDocument* doc) override {
                tinyxml2::XMLElement* element = doc->NewElement(getName().c_str());
+35 −0
Changes for src/webedit/container.cpp: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -184,6 +184,10 @@ extern "C" {
                    if (response) {
                        json_object_object_add(response, "data", result_obj);
                    }
                } else if (strcmp(action, "get_schema") == 0) {
                    if (response) {
                        json_object_object_add(response, "schema", getSchemaJson());
                    }
                }

                // --- 4. Final Response Construction ---
@@ -193,6 +197,37 @@ extern "C" {
                }
            }

            // --- Schema ---
            static json_object* getSchemaJson() {
                json_object *arr = json_object_new_array();
                auto addField = [&](const char *key, const char *label, const char *type,
                                    const char *placeholder = nullptr, bool responsive = false,
                                    json_object *options = nullptr) {
                    json_object *f = json_object_new_object();
                    json_object_object_add(f, "key", json_object_new_string(key));
                    json_object_object_add(f, "label", json_object_new_string(label));
                    json_object_object_add(f, "type", json_object_new_string(type));
                    if (placeholder) json_object_object_add(f, "placeholder", json_object_new_string(placeholder));
                    if (responsive) json_object_object_add(f, "responsive", json_object_new_boolean(true));
                    if (options) json_object_object_add(f, "options", options);
                    json_object_array_add(arr, f);
                };
                auto mkOpts = [](std::initializer_list<const char*> vals) {
                    json_object *a = json_object_new_array();
                    for (auto v : vals) json_object_array_add(a, json_object_new_string(v));
                    return a;
                };
                addField("background_color", "Background Color (Dark)", "color", nullptr, true);
                addField("l_background_color", "Background Color (Light)", "color");
                addField("css_class", "CSS Class", "text", "e.g. my-container");
                addField("border_radius", "Border Radius", "text", "e.g. 8px", true);
                addField("border_style", "Border", "text", "e.g. 1px solid #ccc", true);
                addField("opacity", "Opacity", "text", "0.0 - 1.0", true);
                addField("vertical_align", "Vertical Align", "select", nullptr, true, mkOpts({"top","center","bottom"}));
                addField("hidden", "Hidden", "checkbox", nullptr, true);
                return arr;
            }

            // --- XML Persistence (Save/Load State) ---

            /**
+35 −0
Changes for src/webedit/container/container.cpp: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -204,6 +204,10 @@ extern "C" {
                    if (response) {
                        json_object_object_add(response, "data", result_obj);
                    }
                } else if (strcmp(action, "get_schema") == 0) {
                    if (response) {
                        json_object_object_add(response, "schema", getSchemaJson());
                    }
                }

                // --- 4. Final Response Construction ---
@@ -213,6 +217,37 @@ extern "C" {
                }
            }

            // --- Schema ---
            static json_object* getSchemaJson() {
                json_object *arr = json_object_new_array();
                auto addField = [&](const char *key, const char *label, const char *type,
                                    const char *placeholder = nullptr, bool responsive = false,
                                    json_object *options = nullptr) {
                    json_object *f = json_object_new_object();
                    json_object_object_add(f, "key", json_object_new_string(key));
                    json_object_object_add(f, "label", json_object_new_string(label));
                    json_object_object_add(f, "type", json_object_new_string(type));
                    if (placeholder) json_object_object_add(f, "placeholder", json_object_new_string(placeholder));
                    if (responsive) json_object_object_add(f, "responsive", json_object_new_boolean(true));
                    if (options) json_object_object_add(f, "options", options);
                    json_object_array_add(arr, f);
                };
                auto mkOpts = [](std::initializer_list<const char*> vals) {
                    json_object *a = json_object_new_array();
                    for (auto v : vals) json_object_array_add(a, json_object_new_string(v));
                    return a;
                };
                addField("background_color", "Background Color (Dark)", "color", nullptr, true);
                addField("l_background_color", "Background Color (Light)", "color");
                addField("css_class", "CSS Class", "text", "e.g. my-container");
                addField("border_radius", "Border Radius", "text", "e.g. 8px", true);
                addField("border_style", "Border", "text", "e.g. 1px solid #ccc", true);
                addField("opacity", "Opacity", "text", "0.0 - 1.0", true);
                addField("vertical_align", "Vertical Align", "select", nullptr, true, mkOpts({"top","center","bottom"}));
                addField("hidden", "Hidden", "checkbox", nullptr, true);
                return arr;
            }

            // --- XML Persistence (Save/Load State) ---

            /**
Loading