@mindfiredigital/page-builder-web-component
Version:
UI Page builder Web-Component
179 lines (177 loc) • 5.25 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
PageBuilderComponent: () => PageBuilderComponent
});
module.exports = __toCommonJS(src_exports);
// src/components/PageBuilder.ts
var import_PageBuilder = require("@mindfiredigital/page-builder/dist/PageBuilder.js");
var PageBuilderComponent = class extends HTMLElement {
constructor() {
super();
this.initialized = false;
this._initialDesign = null;
this._editable = null;
this.config = { Basic: [], Extra: [], Custom: [] };
this.template = `<div id="app">
<div id="sidebar"></div>
<div id="canvas" class="canvas"></div>
<div id="customization">
<h4 id="component-name">Component: None</h4>
<div id="controls"></div>
<div id="layers-view" class="hidden"></div>
</div>
<div id="notification" class="notification hidden"></div>
<div id="dialog" class="dialog hidden">
<div class="dialog-content">
<p id="dialog-message"></p>
<button id="dialog-yes" class="dialog-btn">Yes</button>
<button id="dialog-no" class="dialog-btn">No</button>
</div>
</div>
</div>`;
}
set editable(value) {
if (this._editable !== value) {
this._editable = value;
if (this.initialized) {
this.initialized = false;
this.initializePageBuilder();
}
}
}
// Corrected getter for 'editable'
get editable() {
return this._editable;
}
set brandTitle(value) {
if (this._brandTitle !== value) {
this._brandTitle = value;
if (this.initialized) {
this.initialized = false;
this.initializePageBuilder();
}
}
}
get brandTitle() {
return this._brandTitle;
}
set showAttributeTab(value) {
if (this._showAttributeTab !== value) {
this._showAttributeTab = value;
if (this.initialized) {
this.initialized = false;
this.initializePageBuilder();
}
}
}
get showAttributeTab() {
return this._showAttributeTab;
}
set layoutMode(value) {
if (this._layoutMode !== value) {
this._layoutMode = value;
if (this.initialized) {
this.initialized = false;
this.initializePageBuilder();
}
}
}
get layoutMode() {
return this._layoutMode;
}
set initialDesign(value) {
if (this._initialDesign !== value) {
this._initialDesign = value;
if (this.initialized) {
this.initialized = false;
if (value !== null || this.initialized) {
this.initialized = false;
this.initializePageBuilder();
}
}
}
}
get initialDesign() {
return this._initialDesign;
}
// Lifecycle method: Called when the element is added to the DOM
connectedCallback() {
if (this.initialized) {
return;
}
setTimeout(() => {
if (!this.firstElementChild) {
this.innerHTML = this.template;
}
this.initializePageBuilder();
}, 0);
}
hasValidConfig() {
var _a, _b;
return this.config && (((_a = this.config.Basic) == null ? void 0 : _a.length) > 0 || ((_b = this.config.Extra) == null ? void 0 : _b.length) > 0 || this.config.Custom && Object.keys(this.config.Custom).length > 0);
}
set configData(value) {
this.config = value;
this.initialized = false;
this.initializePageBuilder();
}
get configData() {
return this.config;
}
// Initializes the PageBuilder instance
initializePageBuilder() {
if (this.initialized) {
return;
}
try {
const app = this.querySelector("#app");
if (app === null) {
console.error("Error: #app element not found.");
return;
}
if (app && this.pageBuilder) {
app.innerHTML = "";
this.innerHTML = this.template;
}
this.pageBuilder = new import_PageBuilder.PageBuilder(
this.config,
this._initialDesign,
this._editable,
this._brandTitle,
this.showAttributeTab,
this._layoutMode
);
this.initialized = true;
} catch (error) {
console.error("Failed to initialize PageBuilder:", error);
this.initialized = false;
}
}
};
if (!customElements.get("page-builder")) {
customElements.define("page-builder", PageBuilderComponent);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PageBuilderComponent
});
//# sourceMappingURL=index.cjs.map