Commit 3fae4a41 authored by jan.koester's avatar jan.koester
Browse files

test

parent b41df3cc
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ extern "C" {
            std::string margin = "";
            std::string maxWidth = "";
            std::string minHeight = "";
            std::string width = "";
            std::string height = "";

            // Light mode overrides (empty = inherit dark value)
            std::string l_backgroundColor = "";
@@ -62,6 +64,8 @@ extern "C" {
            std::string m_margin = "";
            std::string m_maxWidth = "";
            std::string m_minHeight = "";
            std::string m_width = "";
            std::string m_height = "";

            // Vertical alignment
            std::string verticalAlign = "";
@@ -171,6 +175,8 @@ extern "C" {
                addField("margin", "Margin", "text", "e.g. 0 auto", true);
                addField("max_width", "Max Width", "text", "e.g. 800px", true);
                addField("min_height", "Min Height", "text", "e.g. 200px", true);
                addField("width", "Width", "text", "e.g. 100%", true);
                addField("height", "Height", "text", "e.g. auto", true);
                addField("border_radius", "Border Radius", "text", "e.g. 24px", true);
                addField("border_style", "Border", "text", "e.g. 1px solid #ccc", true);
                addField("opacity", "Opacity", "text", "0.0 - 1.0", true);
@@ -196,6 +202,8 @@ extern "C" {
                element->SetAttribute("margin", margin.c_str());
                element->SetAttribute("max_width", maxWidth.c_str());
                element->SetAttribute("min_height", minHeight.c_str());
                element->SetAttribute("width", width.c_str());
                element->SetAttribute("height", height.c_str());

                element->SetAttribute("l_background_color", l_backgroundColor.c_str());

@@ -207,6 +215,8 @@ extern "C" {
                element->SetAttribute("m_margin", m_margin.c_str());
                element->SetAttribute("m_max_width", m_maxWidth.c_str());
                element->SetAttribute("m_min_height", m_minHeight.c_str());
                element->SetAttribute("m_width", m_width.c_str());
                element->SetAttribute("m_height", m_height.c_str());

                element->SetAttribute("vertical_align", verticalAlign.c_str());
                element->SetAttribute("m_vertical_align", m_verticalAlign.c_str());
@@ -259,6 +269,10 @@ extern "C" {
                if (val) maxWidth = val;
                val = xml_data->Attribute("min_height");
                if (val) minHeight = val;
                val = xml_data->Attribute("width");
                if (val) width = val;
                val = xml_data->Attribute("height");
                if (val) height = val;

                val = xml_data->Attribute("l_background_color");
                if (val) l_backgroundColor = val;
@@ -279,6 +293,10 @@ extern "C" {
                if (val) m_maxWidth = val;
                val = xml_data->Attribute("m_min_height");
                if (val) m_minHeight = val;
                val = xml_data->Attribute("m_width");
                if (val) m_width = val;
                val = xml_data->Attribute("m_height");
                if (val) m_height = val;

                val = xml_data->Attribute("vertical_align");
                if (val) verticalAlign = val;
@@ -310,6 +328,8 @@ extern "C" {
                json_object_object_add(obj, "margin", json_object_new_string(margin.c_str()));
                json_object_object_add(obj, "max_width", json_object_new_string(maxWidth.c_str()));
                json_object_object_add(obj, "min_height", json_object_new_string(minHeight.c_str()));
                json_object_object_add(obj, "width", json_object_new_string(width.c_str()));
                json_object_object_add(obj, "height", json_object_new_string(height.c_str()));
                json_object_object_add(obj, "l_background_color", json_object_new_string(l_backgroundColor.c_str()));
                json_object_object_add(obj, "m_background_color", json_object_new_string(m_backgroundColor.c_str()));
                json_object_object_add(obj, "m_border_radius", json_object_new_string(m_borderRadius.c_str()));
@@ -319,6 +339,8 @@ extern "C" {
                json_object_object_add(obj, "m_margin", json_object_new_string(m_margin.c_str()));
                json_object_object_add(obj, "m_max_width", json_object_new_string(m_maxWidth.c_str()));
                json_object_object_add(obj, "m_min_height", json_object_new_string(m_minHeight.c_str()));
                json_object_object_add(obj, "m_width", json_object_new_string(m_width.c_str()));
                json_object_object_add(obj, "m_height", json_object_new_string(m_height.c_str()));
                json_object_object_add(obj, "vertical_align", json_object_new_string(verticalAlign.c_str()));
                json_object_object_add(obj, "m_vertical_align", json_object_new_string(m_verticalAlign.c_str()));
                json_object_object_add(obj, "hidden", json_object_new_boolean(hidden));
@@ -372,6 +394,12 @@ extern "C" {
                    val = json_object_get_string(val_obj);
                    if (val) minHeight = val;
                }
                if (json_object_object_get_ex(obj, "width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) width = val;
                }
                if (json_object_object_get_ex(obj, "height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) height = val;
                }
                if (json_object_object_get_ex(obj, "l_background_color", &val_obj)) {
                    val = json_object_get_string(val_obj);
                    if (val) l_backgroundColor = val;
@@ -408,6 +436,12 @@ extern "C" {
                    val = json_object_get_string(val_obj);
                    if (val) m_minHeight = val;
                }
                if (json_object_object_get_ex(obj, "m_width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_width = val;
                }
                if (json_object_object_get_ex(obj, "m_height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_height = val;
                }
                if (json_object_object_get_ex(obj, "vertical_align", &val_obj)) {
                    val = json_object_get_string(val_obj);
                    if (val) verticalAlign = val;
@@ -464,6 +498,12 @@ extern "C" {
                if (!minHeight.empty()) {
                    style += " min-height: " + minHeight + ";";
                }
                if (!width.empty()) {
                    style += " width: " + width + ";";
                }
                if (!height.empty()) {
                    style += " height: " + height + ";";
                }
                if (!verticalAlign.empty()) {
                    style += " display: flex; flex-direction: column;";
                    if (verticalAlign == "top") style += " justify-content: flex-start;";
@@ -495,6 +535,8 @@ extern "C" {
                if (!m_margin.empty()) mobileCSS += " margin: " + m_margin + " !important;";
                if (!m_maxWidth.empty()) mobileCSS += " max-width: " + m_maxWidth + " !important;";
                if (!m_minHeight.empty()) mobileCSS += " min-height: " + m_minHeight + " !important;";
                if (!m_width.empty()) mobileCSS += " width: " + m_width + " !important;";
                if (!m_height.empty()) mobileCSS += " height: " + m_height + " !important;";
                if (!m_verticalAlign.empty()) {
                    mobileCSS += " display: flex !important; flex-direction: column !important;";
                    if (m_verticalAlign == "top") mobileCSS += " justify-content: flex-start !important;";
+36 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ extern "C" {
            std::string borderRadius    = "4px";
            std::string borderStyle     = "none";
            std::string textAlign       = "center";
            std::string width           = "";
            std::string height          = "";
            bool openInNewTab           = false;

            // Light mode overrides (empty = inherit dark value)
@@ -60,6 +62,8 @@ extern "C" {
            std::string m_fontSize      = "";
            std::string m_padding       = "";
            std::string m_borderRadius  = "";
            std::string m_width         = "";
            std::string m_height        = "";

            // Visibility
            bool hidden = false;
@@ -348,6 +352,8 @@ extern "C" {
                addField("font_size", "Font Size", "text", "16px", true);
                addField("border_radius", "Border Radius", "text", "4px", true);
                addField("padding", "Padding", "text", "10px 20px", true);
                addField("width", "Width", "text", "e.g. 200px", true);
                addField("height", "Height", "text", "e.g. auto", true);
                addField("hidden", "Hidden", "checkbox", nullptr, true);
                addField("custom_css", "Custom CSS", "textarea", ".we-xxx { color: red; }");
                addField("g_event_enabled", "Enable Google Event", "checkbox");
@@ -375,6 +381,8 @@ extern "C" {
                element->SetAttribute("border_radius", borderRadius.c_str());
                element->SetAttribute("border_style", borderStyle.c_str());
                element->SetAttribute("text_align", textAlign.c_str());
                element->SetAttribute("width", width.c_str());
                element->SetAttribute("height", height.c_str());
                element->SetAttribute("open_new_tab", openInNewTab ? "true" : "false");

                // Light mode overrides
@@ -385,6 +393,8 @@ extern "C" {
                element->SetAttribute("m_font_size", m_fontSize.c_str());
                element->SetAttribute("m_padding", m_padding.c_str());
                element->SetAttribute("m_border_radius", m_borderRadius.c_str());
                element->SetAttribute("m_width", m_width.c_str());
                element->SetAttribute("m_height", m_height.c_str());

                // Visibility
                element->SetAttribute("hidden", hidden ? "true" : "false");
@@ -420,6 +430,8 @@ extern "C" {
                val = xml_data->Attribute("border_radius");    if (val) borderRadius = val;
                val = xml_data->Attribute("border_style");     if (val) borderStyle = val;
                val = xml_data->Attribute("text_align");       if (val) textAlign = val;
                val = xml_data->Attribute("width");            if (val) width = val;
                val = xml_data->Attribute("height");           if (val) height = val;
                val = xml_data->Attribute("open_new_tab");
                if (val) openInNewTab = (strcmp(val, "true") == 0);

@@ -436,6 +448,10 @@ extern "C" {
                if (val) m_padding = val;
                val = xml_data->Attribute("m_border_radius");
                if (val) m_borderRadius = val;
                val = xml_data->Attribute("m_width");
                if (val) m_width = val;
                val = xml_data->Attribute("m_height");
                if (val) m_height = val;

                // Visibility
                val = xml_data->Attribute("hidden");
@@ -478,12 +494,16 @@ extern "C" {
                json_object_object_add(obj, "border_radius", json_object_new_string(borderRadius.c_str()));
                json_object_object_add(obj, "border_style", json_object_new_string(borderStyle.c_str()));
                json_object_object_add(obj, "text_align", json_object_new_string(textAlign.c_str()));
                json_object_object_add(obj, "width", json_object_new_string(width.c_str()));
                json_object_object_add(obj, "height", json_object_new_string(height.c_str()));
                json_object_object_add(obj, "open_new_tab", json_object_new_boolean(openInNewTab));
                json_object_object_add(obj, "l_background_color", json_object_new_string(l_backgroundColor.c_str()));
                json_object_object_add(obj, "l_text_color", json_object_new_string(l_textColor.c_str()));
                json_object_object_add(obj, "m_font_size", json_object_new_string(m_fontSize.c_str()));
                json_object_object_add(obj, "m_padding", json_object_new_string(m_padding.c_str()));
                json_object_object_add(obj, "m_border_radius", json_object_new_string(m_borderRadius.c_str()));
                json_object_object_add(obj, "m_width", json_object_new_string(m_width.c_str()));
                json_object_object_add(obj, "m_height", json_object_new_string(m_height.c_str()));
                json_object_object_add(obj, "hidden", json_object_new_boolean(hidden));
                json_object_object_add(obj, "m_hidden", json_object_new_boolean(m_hidden));
                json_object_object_add(obj, "custom_css", json_object_new_string(customCss.c_str()));
@@ -538,6 +558,12 @@ extern "C" {
                if (json_object_object_get_ex(obj, "text_align", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val && val[0]) textAlign = val;
                }
                if (json_object_object_get_ex(obj, "width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) width = val;
                }
                if (json_object_object_get_ex(obj, "height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) height = val;
                }
                if (json_object_object_get_ex(obj, "open_new_tab", &val_obj)) {
                    openInNewTab = json_object_get_boolean(val_obj);
                }
@@ -556,6 +582,12 @@ extern "C" {
                if (json_object_object_get_ex(obj, "m_border_radius", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_borderRadius = val;
                }
                if (json_object_object_get_ex(obj, "m_width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_width = val;
                }
                if (json_object_object_get_ex(obj, "m_height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_height = val;
                }
                if (json_object_object_get_ex(obj, "hidden", &val_obj)) {
                    hidden = json_object_get_boolean(val_obj);
                }
@@ -665,6 +697,8 @@ extern "C" {
                style += " border-radius: " + borderRadius + ";";
                style += " border: " + borderStyle + ";";
                style += " text-decoration: none; cursor: pointer;";
                if (!width.empty()) style += " width: " + width + ";";
                if (!height.empty()) style += " height: " + height + ";";
                if (hidden) style += " display: none;";

                a.setAttribute("style", style.c_str());
@@ -676,6 +710,8 @@ extern "C" {
                if (!m_fontSize.empty()) mobileCSS += " font-size: " + m_fontSize + " !important;";
                if (!m_padding.empty()) mobileCSS += " padding: " + m_padding + " !important;";
                if (!m_borderRadius.empty()) mobileCSS += " border-radius: " + m_borderRadius + " !important;";
                if (!m_width.empty()) mobileCSS += " width: " + m_width + " !important;";
                if (!m_height.empty()) mobileCSS += " height: " + m_height + " !important;";
                if (m_hidden) mobileCSS += " display: none !important;";
                else if (hidden) mobileCSS += " display: inline-block !important;";

+76 −25
Original line number Diff line number Diff line
@@ -40,7 +40,11 @@ extern "C" {
        class Container : public EditPlugin {
        private:
            std::string content;
            std::string backgroundColor = ""; // NEW: Member to store the background color
            std::string backgroundColor = "";
            std::string width = "";
            std::string height = "";
            std::string m_width = "";
            std::string m_height = "";

        public:
            Container() {
@@ -219,6 +223,8 @@ extern "C" {
                };
                addField("background_color", "Background Color (Dark)", "color_var", nullptr, true);
                addField("l_background_color", "Background Color (Light)", "color_var");
                addField("width", "Width", "text", "e.g. 100%", true);
                addField("height", "Height", "text", "e.g. auto", true);
                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);
@@ -240,6 +246,10 @@ extern "C" {

                // Persist background color
                element->SetAttribute("background_color", backgroundColor.c_str());
                element->SetAttribute("width", width.c_str());
                element->SetAttribute("height", height.c_str());
                element->SetAttribute("m_width", m_width.c_str());
                element->SetAttribute("m_height", m_height.c_str());

                // Add content
                if (!content.empty()) {
@@ -266,6 +276,15 @@ extern "C" {
                if (loaded_color) {
                    backgroundColor = loaded_color;
                }
                const char* val = nullptr;
                val = xml_data->Attribute("width");
                if (val) width = val;
                val = xml_data->Attribute("height");
                if (val) height = val;
                val = xml_data->Attribute("m_width");
                if (val) m_width = val;
                val = xml_data->Attribute("m_height");
                if (val) m_height = val;
                // NOTE: Loading children from XML requires an EditPluginFactory which is not available here.
            }

@@ -273,31 +292,42 @@ extern "C" {

            // Serialize properties to JSON for the API/UI (Read operation)
            std::string toPropertiesJson() {
                // Returns a JSON string containing all editable properties.
                std::stringstream ss;
                ss << "{"
                   << "\"background_color\": \"" << backgroundColor << "\""
                   << "}";
                return ss.str();
                json_object *obj = json_object_new_object();
                json_object_object_add(obj, "background_color", json_object_new_string(backgroundColor.c_str()));
                json_object_object_add(obj, "width", json_object_new_string(width.c_str()));
                json_object_object_add(obj, "height", json_object_new_string(height.c_str()));
                json_object_object_add(obj, "m_width", json_object_new_string(m_width.c_str()));
                json_object_object_add(obj, "m_height", json_object_new_string(m_height.c_str()));
                std::string result = json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE);
                json_object_put(obj);
                return result;
            }

            // Deserialize properties from JSON received from the API/UI (Modify/Delete operation)
            void fromPropertiesJson(const std::string &json) {
                // This function handles the "modify" operation on properties.
                std::string key = "\"background_color\":";
                size_t key_pos = json.find(key);
                json_object *obj = json_tokener_parse(json.c_str());
                if (!obj) return;

                if (key_pos != std::string::npos) {
                    size_t start = json.find("\"", key_pos + key.length());
                    if (start != std::string::npos) {
                        start++; // Move past the opening quote
                        size_t end = json.find("\"", start);
                        if (end != std::string::npos) {
                            // Extract the new value (which can be empty, effectively clearing the style)
                            backgroundColor = json.substr(start, end - start);
                json_object *val_obj = nullptr;
                const char *val = nullptr;

                if (json_object_object_get_ex(obj, "background_color", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) backgroundColor = val;
                }
                if (json_object_object_get_ex(obj, "width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) width = val;
                }
                if (json_object_object_get_ex(obj, "height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) height = val;
                }
                if (json_object_object_get_ex(obj, "m_width", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_width = val;
                }
                if (json_object_object_get_ex(obj, "m_height", &val_obj)) {
                    val = json_object_get_string(val_obj); if (val) m_height = val;
                }

                json_object_put(obj);
            }

            // --- HTML Rendering ---
@@ -308,15 +338,36 @@ extern "C" {
            void Render(libhtmlpp::HtmlElement &el) const override {
                libhtmlpp::HtmlElement cnt("div");

                // Default style for visibility when no color is set
                std::string style = "padding: 10px; min-height: 50px; border: 1px dashed #ccc;";
                std::string responsiveClass = std::string("we-") + getInstanceId().c_str();

                std::string style = "padding: 10px; min-height: 50px;";

                if (!backgroundColor.empty() && backgroundColor != "none" && backgroundColor != "transparent") {
                    // Apply custom background color
                    style = "background-color: " + backgroundColor + "; padding: 10px; min-height: 50px;";
                    style += " background-color: " + backgroundColor + ";";
                } else {
                    style += " border: 1px dashed #ccc;";
                }
                if (!width.empty()) {
                    style += " width: " + width + ";";
                }
                if (!height.empty()) {
                    style += " height: " + height + ";";
                }

                cnt.setAttribute("style", style.c_str());
                cnt.setAttribute("class", responsiveClass.c_str());

                // Mobile responsive overrides
                std::string mobileCSS;
                if (!m_width.empty()) mobileCSS += " width: " + m_width + " !important;";
                if (!m_height.empty()) mobileCSS += " height: " + m_height + " !important;";

                if (!mobileCSS.empty()) {
                    libhtmlpp::HtmlElement styleTag("style");
                    std::string mediaRule = "@media (max-width: 768px) { ." + responsiveClass + " {" + mobileCSS + " } }";
                    styleTag.appendChild(libhtmlpp::TextElement(mediaRule.c_str()));
                    el.appendChild(styleTag);
                }

                // Placeholder: Add content if any
                if (!content.empty()) {
+46 −0

File changed.

Preview size limit exceeded, changes collapsed.

+43 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading