@innovastudio/contentbuilder-interactive-runtime 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8935,7 +8935,7 @@ class yn {
|
|
|
8935
8935
|
if (r.querySelector(`[name="${w}"]`) && (o++, w = w + "_" + o), b === "short-text") {
|
|
8936
8936
|
let g = this.getId();
|
|
8937
8937
|
const v = document.createElement("label");
|
|
8938
|
-
if (v.setAttribute("for", `short_text_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8938
|
+
if (v.setAttribute("for", `short_text_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8939
8939
|
const m = document.createElement("div");
|
|
8940
8940
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
8941
8941
|
}
|
|
@@ -8945,7 +8945,7 @@ class yn {
|
|
|
8945
8945
|
if (b === "long-text") {
|
|
8946
8946
|
let g = this.getId();
|
|
8947
8947
|
const v = document.createElement("label");
|
|
8948
|
-
if (v.setAttribute("for", `long_text_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8948
|
+
if (v.setAttribute("for", `long_text_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8949
8949
|
const m = document.createElement("div");
|
|
8950
8950
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
8951
8951
|
}
|
|
@@ -8955,7 +8955,7 @@ class yn {
|
|
|
8955
8955
|
if (b === "number") {
|
|
8956
8956
|
let g = this.getId();
|
|
8957
8957
|
const v = document.createElement("label");
|
|
8958
|
-
if (v.setAttribute("for", `number_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8958
|
+
if (v.setAttribute("for", `number_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8959
8959
|
const m = document.createElement("div");
|
|
8960
8960
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
8961
8961
|
}
|
|
@@ -8966,7 +8966,7 @@ class yn {
|
|
|
8966
8966
|
p.classList.add("input-slider");
|
|
8967
8967
|
let g = this.getId();
|
|
8968
8968
|
const v = document.createElement("label");
|
|
8969
|
-
if (v.setAttribute("for", `number_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8969
|
+
if (v.setAttribute("for", `number_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8970
8970
|
const E = document.createElement("div");
|
|
8971
8971
|
E.className = "field-note", E.innerHTML = l.fieldNote, p.appendChild(E);
|
|
8972
8972
|
}
|
|
@@ -8988,7 +8988,7 @@ class yn {
|
|
|
8988
8988
|
if (b === "select") {
|
|
8989
8989
|
let g = this.getId();
|
|
8990
8990
|
const v = document.createElement("div");
|
|
8991
|
-
if (v.id = `radio_group_label_${g}`, v.className = "field-label-normal", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8991
|
+
if (v.id = `radio_group_label_${g}`, v.className = "field-label-normal", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
8992
8992
|
const m = document.createElement("div");
|
|
8993
8993
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
8994
8994
|
}
|
|
@@ -9026,7 +9026,7 @@ class yn {
|
|
|
9026
9026
|
if (b === "multi-select") {
|
|
9027
9027
|
let g = this.getId();
|
|
9028
9028
|
const v = document.createElement("div");
|
|
9029
|
-
if (v.id = `checkbox_group_label_${g}`, v.className = "field-label-normal", v.innerHTML = l.title + (l.isRequired ?
|
|
9029
|
+
if (v.id = `checkbox_group_label_${g}`, v.className = "field-label-normal", v.innerHTML = l.title + (l.isRequired ? ` <span class="text-red-500" aria-hidden="true">*</span><span style="position:absolute;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;white-space:nowrap;">(${this.out("required")})</span>` : ""), p.appendChild(v), l.fieldNote) {
|
|
9030
9030
|
const m = document.createElement("div");
|
|
9031
9031
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9032
9032
|
}
|
|
@@ -9068,7 +9068,7 @@ class yn {
|
|
|
9068
9068
|
if (b === "switch") {
|
|
9069
9069
|
let g = this.getId();
|
|
9070
9070
|
const v = document.createElement("label");
|
|
9071
|
-
if (v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), v.id = `switch_${g}`, p.appendChild(v), l.fieldNote) {
|
|
9071
|
+
if (v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), v.id = `switch_${g}`, p.appendChild(v), l.fieldNote) {
|
|
9072
9072
|
const x = document.createElement("div");
|
|
9073
9073
|
x.className = "field-note", x.innerHTML = l.fieldNote, p.appendChild(x);
|
|
9074
9074
|
}
|
|
@@ -9077,7 +9077,7 @@ class yn {
|
|
|
9077
9077
|
const m = document.createElement("div");
|
|
9078
9078
|
m.className = "switch-thumb", f.appendChild(m);
|
|
9079
9079
|
const y = document.createElement("input");
|
|
9080
|
-
y.id = `
|
|
9080
|
+
y.id = `switch_input_${g}`, y.setAttribute("aria-hidden", "true"), y.type = "text", y.name = w, y.style.cssText = "position:absolute;bottom:0px;left:25px;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;", y.setAttribute("tabindex", "-1"), l.isRequired && (y.setAttribute("required", "required"), y.setCustomValidity(this.out("Please toggle this switch to proceed.")), f.setAttribute("aria-required", "true")), p.appendChild(y), l.value === "true" ? (f.setAttribute("aria-checked", "true"), f.setAttribute("data-checked", "true"), y.value = "true", l.isRequired && y.setCustomValidity("")) : (f.setAttribute("aria-checked", "false"), f.setAttribute("data-checked", "false"), y.value = "false", l.isRequired && y.setCustomValidity(this.out("Please toggle this switch to proceed."))), v.addEventListener("click", () => {
|
|
9081
9081
|
f.focus();
|
|
9082
9082
|
});
|
|
9083
9083
|
const k = () => {
|
|
@@ -9095,7 +9095,7 @@ class yn {
|
|
|
9095
9095
|
if (b === "dropdown") {
|
|
9096
9096
|
let g = this.getId();
|
|
9097
9097
|
const v = document.createElement("label");
|
|
9098
|
-
if (v.setAttribute("for", `dropdown_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9098
|
+
if (v.setAttribute("for", `dropdown_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9099
9099
|
const A = document.createElement("div");
|
|
9100
9100
|
A.className = "field-note", A.innerHTML = l.fieldNote, p.appendChild(A);
|
|
9101
9101
|
}
|
|
@@ -9133,7 +9133,7 @@ class yn {
|
|
|
9133
9133
|
if (b === "date") {
|
|
9134
9134
|
let g = this.getId();
|
|
9135
9135
|
const v = document.createElement("label");
|
|
9136
|
-
if (v.setAttribute("for", `date_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9136
|
+
if (v.setAttribute("for", `date_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9137
9137
|
const m = document.createElement("div");
|
|
9138
9138
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9139
9139
|
}
|
|
@@ -9143,7 +9143,7 @@ class yn {
|
|
|
9143
9143
|
if (b === "time") {
|
|
9144
9144
|
let g = this.getId();
|
|
9145
9145
|
const v = document.createElement("label");
|
|
9146
|
-
if (v.setAttribute("for", `time_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9146
|
+
if (v.setAttribute("for", `time_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9147
9147
|
const m = document.createElement("div");
|
|
9148
9148
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9149
9149
|
}
|
|
@@ -9153,7 +9153,7 @@ class yn {
|
|
|
9153
9153
|
if (b === "datetime") {
|
|
9154
9154
|
let g = this.getId();
|
|
9155
9155
|
const v = document.createElement("label");
|
|
9156
|
-
if (v.setAttribute("for", `datetime_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9156
|
+
if (v.setAttribute("for", `datetime_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9157
9157
|
const m = document.createElement("div");
|
|
9158
9158
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9159
9159
|
}
|
|
@@ -9163,7 +9163,7 @@ class yn {
|
|
|
9163
9163
|
if (b === "color") {
|
|
9164
9164
|
let g = this.getId();
|
|
9165
9165
|
const v = document.createElement("label");
|
|
9166
|
-
if (v.setAttribute("for", `color_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9166
|
+
if (v.setAttribute("for", `color_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9167
9167
|
const m = document.createElement("div");
|
|
9168
9168
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9169
9169
|
}
|
|
@@ -9173,7 +9173,7 @@ class yn {
|
|
|
9173
9173
|
if (b === "file" || b === "multifile") {
|
|
9174
9174
|
let g = this.getId();
|
|
9175
9175
|
const v = document.createElement("label");
|
|
9176
|
-
if (v.setAttribute("for", `file_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9176
|
+
if (v.setAttribute("for", `file_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9177
9177
|
const P = document.createElement("div");
|
|
9178
9178
|
P.className = "field-note", P.innerHTML = l.fieldNote, p.appendChild(P);
|
|
9179
9179
|
}
|
|
@@ -9548,7 +9548,7 @@ class yn {
|
|
|
9548
9548
|
if (b === "email") {
|
|
9549
9549
|
let g = this.getId();
|
|
9550
9550
|
const v = document.createElement("label");
|
|
9551
|
-
if (v.setAttribute("for", `email_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9551
|
+
if (v.setAttribute("for", `email_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9552
9552
|
const m = document.createElement("div");
|
|
9553
9553
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9554
9554
|
}
|
|
@@ -9558,7 +9558,7 @@ class yn {
|
|
|
9558
9558
|
if (b === "phone") {
|
|
9559
9559
|
let g = this.getId();
|
|
9560
9560
|
const v = document.createElement("label");
|
|
9561
|
-
if (v.setAttribute("for", `phone_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9561
|
+
if (v.setAttribute("for", `phone_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9562
9562
|
const m = document.createElement("div");
|
|
9563
9563
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9564
9564
|
}
|
|
@@ -9568,7 +9568,7 @@ class yn {
|
|
|
9568
9568
|
if (b === "url") {
|
|
9569
9569
|
let g = this.getId();
|
|
9570
9570
|
const v = document.createElement("label");
|
|
9571
|
-
if (v.setAttribute("for", `url_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9571
|
+
if (v.setAttribute("for", `url_label_${g}`), v.className = "field-label", v.innerHTML = l.title + (l.isRequired ? ' <span class="text-red-500" aria-hidden="true">*</span>' : ""), p.appendChild(v), l.fieldNote) {
|
|
9572
9572
|
const m = document.createElement("div");
|
|
9573
9573
|
m.className = "field-note", m.innerHTML = l.fieldNote, p.appendChild(m);
|
|
9574
9574
|
}
|
|
@@ -10979,6 +10979,24 @@ class vn {
|
|
|
10979
10979
|
getComponent(e) {
|
|
10980
10980
|
return this.components.get(e);
|
|
10981
10981
|
}
|
|
10982
|
+
/**
|
|
10983
|
+
* Unmount a single component and remove it from the map
|
|
10984
|
+
* Runs the plugin's unmount (cleanup, e.g. removing a popover). Call this before
|
|
10985
|
+
* removing the element from the DOM — reinitialize() only unmounts elements still
|
|
10986
|
+
* inside the container.
|
|
10987
|
+
* @param {HTMLElement} element - The element to unmount
|
|
10988
|
+
* @returns {boolean} True if a component was unmounted
|
|
10989
|
+
*/
|
|
10990
|
+
unmountComponent(e) {
|
|
10991
|
+
if (!e || !this.components.has(e)) return !1;
|
|
10992
|
+
const t = this.components.get(e), i = e.dataset.cbType, s = this.plugins.get(i);
|
|
10993
|
+
if (s && typeof s.unmount == "function")
|
|
10994
|
+
try {
|
|
10995
|
+
s.unmount(e, t);
|
|
10996
|
+
} catch {
|
|
10997
|
+
}
|
|
10998
|
+
return this.components.delete(e), !0;
|
|
10999
|
+
}
|
|
10982
11000
|
/**
|
|
10983
11001
|
* Reinitialize components in a specific container
|
|
10984
11002
|
* Useful when content is dynamically updated
|
|
@@ -11026,6 +11044,10 @@ class vn {
|
|
|
11026
11044
|
else {
|
|
11027
11045
|
let b = document.createRange();
|
|
11028
11046
|
o.innerHTML = "", o.appendChild(b.createContextualFragment(o.getAttribute("data-cb-original-content")));
|
|
11047
|
+
let w = !1;
|
|
11048
|
+
o.querySelectorAll(".edit:not([data-edit-id])").forEach((_, g) => {
|
|
11049
|
+
_.setAttribute("data-edit-id", `content-${Date.now()}-${r}-new-${g}`), w = !0;
|
|
11050
|
+
}), w && o.setAttribute("data-cb-original-content", o.innerHTML);
|
|
11029
11051
|
}
|
|
11030
11052
|
const p = await d.mount(o, u);
|
|
11031
11053
|
this.components.set(o, p), this.setupInlineEditing(o, u), o.setAttribute("data-cb-loaded", "true"), typeof o.mount == "function" && o.mount(), r++;
|
|
@@ -11263,6 +11285,15 @@ class wn {
|
|
|
11263
11285
|
getComponents() {
|
|
11264
11286
|
return this.pluginManager.components;
|
|
11265
11287
|
}
|
|
11288
|
+
/**
|
|
11289
|
+
* Unmount a single component (runs its plugin's cleanup)
|
|
11290
|
+
* Call this before removing the element from the DOM.
|
|
11291
|
+
* @param {HTMLElement} element - The element to unmount
|
|
11292
|
+
* @returns {boolean} True if a component was unmounted
|
|
11293
|
+
*/
|
|
11294
|
+
unmountComponent(e) {
|
|
11295
|
+
return this.pluginManager.unmountComponent(e);
|
|
11296
|
+
}
|
|
11266
11297
|
/**
|
|
11267
11298
|
* Reinitialize components (after content update)
|
|
11268
11299
|
* @param {HTMLElement} container - Container to reinitialize (optional, defaults to document)
|
|
@@ -329,15 +329,15 @@ Check the information and return the details.
|
|
|
329
329
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z" /><path d="M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1" />
|
|
330
330
|
</svg>
|
|
331
331
|
<span>${this.out("Copy")}</span>
|
|
332
|
-
`},600)}),l.addEventListener("click",h=>{h.preventDefault(),localStorage.removeItem("_results"),localStorage.removeItem("_results_html"),e.innerHTML=""})}getScrollableParent(e){for(;e.parentElement;){const i=window.getComputedStyle(e.parentElement).overflowY;if((i==="auto"||i==="scroll")&&e.parentElement.scrollHeight>e.parentElement.clientHeight)return e.parentElement;e=e.parentElement}return null}stickyElement(e){if(!this.settings.alwaysVisibleSubmit)return;const t=this.getScrollableParent(e);this._scrollListener&&(t?t.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._resizeListener));let i;const s=()=>{e.style.position="",t?i=e.offsetTop+e.offsetHeight-t.offsetTop:i=e.offsetTop+e.offsetHeight},n=()=>{if(t)if(t.offsetHeight+t.scrollTop>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}else if(window.innerHeight+window.scrollY>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}e.parentNode.offsetWidth!==0&&(e.style.width=`${e.parentNode.offsetWidth}px`)};this._scrollListener=n;let r;this._resizeListener=()=>{r&&clearTimeout(r),r=setTimeout(()=>{let o=null;const a=()=>{const d=e.offsetTop;d===o?(s(),n()):(o=d,requestAnimationFrame(a))};a()},200)},s(),n(),t?t.addEventListener("scroll",n):window.addEventListener("scroll",n),window.addEventListener("resize",this._resizeListener)}view(e){if(!e)return;let t;try{t=JSON.parse(e)}catch{console.log("Invalid JSON Form.");return}this.json=t,this.inputListener=()=>{clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)},300)},this.changeListener=()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)};let i;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}i=document.querySelector(this.settings.previewSelector)}else i=this.element;if(i){if(i.classList.remove("hidden"),i.classList.add("formview-container"),i.classList.add("fb-ui"),i.innerHTML="",!(t.hideHeader||!1)){const l=document.createElement("div");l.className="form-header",i.appendChild(l);const h=document.createElement("h1");h.className="form-title",h.innerText=t.title||this.out("Your Form Title Here"),l.appendChild(h);const p=document.createElement("p");p.className="form-desc",p.innerText=t.description||this.out("Your Description Here"),l.appendChild(p)}let r;this.settings.isBuilder?r=document.createElement("form"):r=document.createElement("div"),r.className="form-wrapper",r.style.flexFlow="wrap",i.appendChild(r);let o=1;t.elements&&t.elements.forEach(l=>{if(l.type==="spacer"){const g=document.createElement("div");g.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(g.style.height=l.spacerHeight+"px"),l.displayInOutput||r.appendChild(g);return}if(l.type==="separator"){const g=document.createElement("hr");g.style.borderTopColor=l.color,l.displayInOutput||r.appendChild(g);return}if(l.type==="html"){if(l.html){const g=document.createElement("div");g.innerHTML=l.html,l.displayInOutput||r.appendChild(g)}return}if(l.type==="heading"){const g=document.createElement(l.heading||"h2");g.innerHTML=l.headingText||this.out("Your Heading Here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="paragraph"){const g=document.createElement("p");g.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="media"){if(l.tag==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",g.appendChild(h),l.displayInOutput||r.appendChild(g)}else if(l.tag==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g)}else if(l.tag==="img"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g)}return}if(l.type==="image"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g);return}if(l.type==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="video/mp4",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}if(l.type==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}const p=document.createElement("div");p.className="form-field",l.type==="hidden"&&(p.className="hidden"),l.displayInOutput||r.appendChild(p),l.type==="color"&&p.classList.add("field-color");const b=l.type;let w=l.name;if(r.querySelector(`[name="${w}"]`)&&(o++,w=w+"_"+o),b==="short-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`short_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`short_text_label_${g}`,f.type="text",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="long-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`long_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("textarea");f.id=`long_text_label_${g}`,f.name=w,f.value=l.value||"",f.className="inp-base",f.style.height=l.height+"px",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="number"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`number_label_${g}`,f.type="number",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="slider"){p.classList.add("input-slider");let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const E=document.createElement("div");E.className="field-note",E.innerHTML=l.fieldNote,p.appendChild(E)}const f=document.createElement("div");f.className="slider-container",p.appendChild(f);const m=document.createElement("div");m.className="slider-values",f.appendChild(m);const y=document.createElement("span");m.appendChild(y),y.innerText=l.minValue;const k=document.createElement("span");m.appendChild(k),k.innerText=l.maxValue;const x=document.createElement("input");x.id=`number_label_${g}`,x.type="range",x.name=w,x.setAttribute("min",l.minValue),x.setAttribute("max",l.maxValue),x.setAttribute("step",l.step),x.setAttribute("value",l.value||0),f.appendChild(x);const S=document.createElement("div");S.className="current-value",f.appendChild(S),f.querySelector(".current-value").textContent=l.value||0,x.addEventListener("input",()=>{f.querySelector(".current-value").textContent=x.value})}if(b==="select"){let g=this.getId();const v=document.createElement("div");if(v.id=`radio_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`radio_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="radio",S.className="peer",S.id=`${g}_${y}`,S.name=w,S.value=m,x.appendChild(S),y===l.selected&&(S.checked=!0);const E=document.createElement("span");E.className="peer-span-rounded",x.appendChild(E);const C='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';E.innerHTML=C,y===0&&l.isRequired&&S.setAttribute("required","required");const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const y=document.createElement("input");y.type="radio",y.className="peer",y.id=g+"_other",y.name=w,y.value="other",m.appendChild(y);const k=document.createElement("span");k.className="peer-span-rounded",m.appendChild(k);const x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="multi-select"){let g=this.getId();const v=document.createElement("div");if(v.id=`checkbox_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`checkbox_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="checkbox",S.className="peer",S.id=`${g}_${y}`,S.name=w+"[]",S.value=m,x.appendChild(S);const E=document.createElement("span");E.className="peer-span-square",x.appendChild(E);const C=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
|
|
332
|
+
`},600)}),l.addEventListener("click",h=>{h.preventDefault(),localStorage.removeItem("_results"),localStorage.removeItem("_results_html"),e.innerHTML=""})}getScrollableParent(e){for(;e.parentElement;){const i=window.getComputedStyle(e.parentElement).overflowY;if((i==="auto"||i==="scroll")&&e.parentElement.scrollHeight>e.parentElement.clientHeight)return e.parentElement;e=e.parentElement}return null}stickyElement(e){if(!this.settings.alwaysVisibleSubmit)return;const t=this.getScrollableParent(e);this._scrollListener&&(t?t.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._resizeListener));let i;const s=()=>{e.style.position="",t?i=e.offsetTop+e.offsetHeight-t.offsetTop:i=e.offsetTop+e.offsetHeight},n=()=>{if(t)if(t.offsetHeight+t.scrollTop>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}else if(window.innerHeight+window.scrollY>i)e.style.position="",e.style.top="";else{const a=window.innerHeight-e.offsetHeight;e.style.position="fixed",e.style.top=`${a}px`}e.parentNode.offsetWidth!==0&&(e.style.width=`${e.parentNode.offsetWidth}px`)};this._scrollListener=n;let r;this._resizeListener=()=>{r&&clearTimeout(r),r=setTimeout(()=>{let o=null;const a=()=>{const d=e.offsetTop;d===o?(s(),n()):(o=d,requestAnimationFrame(a))};a()},200)},s(),n(),t?t.addEventListener("scroll",n):window.addEventListener("scroll",n),window.addEventListener("resize",this._resizeListener)}view(e){if(!e)return;let t;try{t=JSON.parse(e)}catch{console.log("Invalid JSON Form.");return}this.json=t,this.inputListener=()=>{clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)},300)},this.changeListener=()=>{const n=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(n)};let i;if(this.settings.isBuilder){if(!this.settings.previewSelector){this.settings.consoleLog&&console.log("previewSelector not set.");return}i=document.querySelector(this.settings.previewSelector)}else i=this.element;if(i){if(i.classList.remove("hidden"),i.classList.add("formview-container"),i.classList.add("fb-ui"),i.innerHTML="",!(t.hideHeader||!1)){const l=document.createElement("div");l.className="form-header",i.appendChild(l);const h=document.createElement("h1");h.className="form-title",h.innerText=t.title||this.out("Your Form Title Here"),l.appendChild(h);const p=document.createElement("p");p.className="form-desc",p.innerText=t.description||this.out("Your Description Here"),l.appendChild(p)}let r;this.settings.isBuilder?r=document.createElement("form"):r=document.createElement("div"),r.className="form-wrapper",r.style.flexFlow="wrap",i.appendChild(r);let o=1;t.elements&&t.elements.forEach(l=>{if(l.type==="spacer"){const g=document.createElement("div");g.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(g.style.height=l.spacerHeight+"px"),l.displayInOutput||r.appendChild(g);return}if(l.type==="separator"){const g=document.createElement("hr");g.style.borderTopColor=l.color,l.displayInOutput||r.appendChild(g);return}if(l.type==="html"){if(l.html){const g=document.createElement("div");g.innerHTML=l.html,l.displayInOutput||r.appendChild(g)}return}if(l.type==="heading"){const g=document.createElement(l.heading||"h2");g.innerHTML=l.headingText||this.out("Your Heading Here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="paragraph"){const g=document.createElement("p");g.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),l.displayInOutput||r.appendChild(g);return}if(l.type==="media"){if(l.tag==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",g.appendChild(h),l.displayInOutput||r.appendChild(g)}else if(l.tag==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g)}else if(l.tag==="img"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g)}return}if(l.type==="image"){const g=document.createElement("img");g.src=l.url,g.setAttribute("alt",this.out("Output Image")),l.displayInOutput||r.appendChild(g);return}if(l.type==="video"){const g=document.createElement("video");g.style.width="100%",g.style.height="auto",g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="video/mp4",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}if(l.type==="audio"){const g=document.createElement("audio");g.controls=!0;let v=document.createElement("source");v.src=l.url,v.type="audio/mp3",g.appendChild(v),l.displayInOutput||r.appendChild(g);return}const p=document.createElement("div");p.className="form-field",l.type==="hidden"&&(p.className="hidden"),l.displayInOutput||r.appendChild(p),l.type==="color"&&p.classList.add("field-color");const b=l.type;let w=l.name;if(r.querySelector(`[name="${w}"]`)&&(o++,w=w+"_"+o),b==="short-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`short_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`short_text_label_${g}`,f.type="text",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="long-text"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`long_text_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("textarea");f.id=`long_text_label_${g}`,f.name=w,f.value=l.value||"",f.className="inp-base",f.style.height=l.height+"px",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="number"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`number_label_${g}`,f.type="number",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="slider"){p.classList.add("input-slider");let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`number_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const E=document.createElement("div");E.className="field-note",E.innerHTML=l.fieldNote,p.appendChild(E)}const f=document.createElement("div");f.className="slider-container",p.appendChild(f);const m=document.createElement("div");m.className="slider-values",f.appendChild(m);const y=document.createElement("span");m.appendChild(y),y.innerText=l.minValue;const k=document.createElement("span");m.appendChild(k),k.innerText=l.maxValue;const x=document.createElement("input");x.id=`number_label_${g}`,x.type="range",x.name=w,x.setAttribute("min",l.minValue),x.setAttribute("max",l.maxValue),x.setAttribute("step",l.step),x.setAttribute("value",l.value||0),f.appendChild(x);const S=document.createElement("div");S.className="current-value",f.appendChild(S),f.querySelector(".current-value").textContent=l.value||0,x.addEventListener("input",()=>{f.querySelector(".current-value").textContent=x.value})}if(b==="select"){let g=this.getId();const v=document.createElement("div");if(v.id=`radio_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`radio_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="radio",S.className="peer",S.id=`${g}_${y}`,S.name=w,S.value=m,x.appendChild(S),y===l.selected&&(S.checked=!0);const E=document.createElement("span");E.className="peer-span-rounded",x.appendChild(E);const C='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';E.innerHTML=C,y===0&&l.isRequired&&S.setAttribute("required","required");const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const y=document.createElement("input");y.type="radio",y.className="peer",y.id=g+"_other",y.name=w,y.value="other",m.appendChild(y);const k=document.createElement("span");k.className="peer-span-rounded",m.appendChild(k);const x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z"></path></svg>';k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="multi-select"){let g=this.getId();const v=document.createElement("div");if(v.id=`checkbox_group_label_${g}`,v.className="field-label-normal",v.innerHTML=l.title+(l.isRequired?` <span class="text-red-500" aria-hidden="true">*</span><span style="position:absolute;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;white-space:nowrap;">(${this.out("required")})</span>`:""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("div");if(f.setAttribute("aria-labelledby",`checkbox_group_label_${g}`),f.setAttribute("role","group"),f.className="div-options",p.appendChild(f),l.choices&&l.choices.forEach((m,y)=>{let k=m;l.choicesText&&(k=l.choicesText[y]||m);const x=document.createElement("label");x.setAttribute("for",`${g}_${y}`),x.className="option-label",f.appendChild(x);const S=document.createElement("input");S.type="checkbox",S.className="peer",S.id=`${g}_${y}`,S.name=w+"[]",S.value=m,x.appendChild(S);const E=document.createElement("span");E.className="peer-span-square",x.appendChild(E);const C=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
|
|
333
333
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" />
|
|
334
334
|
</svg>`;E.innerHTML=C;const A=document.createElement("span");A.innerText=k,x.appendChild(A),S.addEventListener("change",this.changeListener)}),l.showOtherItem){const m=document.createElement("label");m.setAttribute("for",g+"_other"),m.className="option-label",f.appendChild(m);const y=document.createElement("input");y.type="checkbox",y.className="peer",y.id=g+"_other",y.name=w,y.value="other",m.appendChild(y);const k=document.createElement("span");k.className="peer-span-square",m.appendChild(k);const x=`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
|
|
335
335
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" />
|
|
336
|
-
</svg>`;k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="switch"){let g=this.getId();const v=document.createElement("label");if(v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),v.id=`switch_${g}`,p.appendChild(v),l.fieldNote){const x=document.createElement("div");x.className="field-note",x.innerHTML=l.fieldNote,p.appendChild(x)}const f=document.createElement("div");f.className="switch",f.tabIndex=0,f.role="switch",f.setAttribute("aria-labelledby",`switch_${g}`),f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),p.appendChild(f);const m=document.createElement("div");m.className="switch-thumb",f.appendChild(m);const y=document.createElement("input");y.id=`
|
|
336
|
+
</svg>`;k.innerHTML=x;const S=document.createElement("span");S.innerText=l.otherText,m.appendChild(S);const E=document.createElement("div");p.appendChild(E);const C=document.createElement("input");C.type="text",C.name=w+"_other",C.className="inp-base",E.appendChild(C),y.addEventListener("change",this.changeListener),C.addEventListener("input",this.inputListener)}}if(b==="switch"){let g=this.getId();const v=document.createElement("label");if(v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),v.id=`switch_${g}`,p.appendChild(v),l.fieldNote){const x=document.createElement("div");x.className="field-note",x.innerHTML=l.fieldNote,p.appendChild(x)}const f=document.createElement("div");f.className="switch",f.tabIndex=0,f.role="switch",f.setAttribute("aria-labelledby",`switch_${g}`),f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),p.appendChild(f);const m=document.createElement("div");m.className="switch-thumb",f.appendChild(m);const y=document.createElement("input");y.id=`switch_input_${g}`,y.setAttribute("aria-hidden","true"),y.type="text",y.name=w,y.style.cssText="position:absolute;bottom:0px;left:25px;width:1px;height:1px;clip-path:inset(50%);overflow:hidden;",y.setAttribute("tabindex","-1"),l.isRequired&&(y.setAttribute("required","required"),y.setCustomValidity(this.out("Please toggle this switch to proceed.")),f.setAttribute("aria-required","true")),p.appendChild(y),l.value==="true"?(f.setAttribute("aria-checked","true"),f.setAttribute("data-checked","true"),y.value="true",l.isRequired&&y.setCustomValidity("")):(f.setAttribute("aria-checked","false"),f.setAttribute("data-checked","false"),y.value="false",l.isRequired&&y.setCustomValidity(this.out("Please toggle this switch to proceed."))),v.addEventListener("click",()=>{f.focus()});const k=()=>{const x=f.getAttribute("aria-checked")==="true";f.setAttribute("aria-checked",!x),f.setAttribute("data-checked",!x),x?(y.value="false",l.isRequired&&y.setCustomValidity(this.out("Please toggle this switch to proceed."))):(y.value="true",l.isRequired&&y.setCustomValidity(""));const S=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(S)};f.addEventListener("keydown",x=>{(x.key===" "||x.key==="Enter")&&(x.preventDefault(),k())}),f.addEventListener("click",()=>{k()})}if(b==="dropdown"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`dropdown_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const A=document.createElement("div");A.className="field-note",A.innerHTML=l.fieldNote,p.appendChild(A)}const f=document.createElement("div");f.className="relative",p.appendChild(f);const m=document.createElement("div");m.className="relative inline-block",f.appendChild(m);const y=document.createElement("select");y.id=`dropdown_${g}`,y.name=w,l.isRequired&&y.setAttribute("required","required"),m.appendChild(y);const k=document.createElement("option");if(k.setAttribute("selected","selected"),k.setAttribute("disabled","disabled"),k.value="",k.innerText=l.placeholder,y.appendChild(k),l.choices&&l.choices.forEach((A,L)=>{let D=A;l.choicesText&&(D=l.choicesText[L]||A);const I=document.createElement("option");I.value=A,I.innerText=D,y.appendChild(I),L===l.selected&&(k.remove(),I.setAttribute("selected","selected"))}),l.showOtherItem){const A=document.createElement("option");A.value="other",A.innerText=l.otherText,y.appendChild(A)}const x=document.createElement("div");x.className="select-arrow",m.appendChild(x),this.appendHtml(x,`
|
|
337
337
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
338
338
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
|
339
339
|
</svg>
|
|
340
|
-
`);const S=document.createElement("input");S.type="text",S.id=`input_other_${g}`,S.name=w+"_other",S.className="input-other hidden inp-base",p.appendChild(S);const E=p.querySelector(`#dropdown_${g}`),C=p.querySelector(`#input_other_${g}`);E.addEventListener("change",()=>{E.value==="other"?(C.classList.remove("hidden"),C.focus()):C.classList.add("hidden");const A=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(A)}),S.addEventListener("input",this.inputListener)}if(b==="date"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`date_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`date_${g}`,f.type="date",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="time"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`time_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`time_${g}`,f.type="time",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="datetime"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`datetime_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`datetime_${g}`,f.type="datetime-local",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="color"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`color_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`color_${g}`,f.type="color",f.name=w,f.value=l.value||"",f.className="input-color",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="file"||b==="multifile"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`file_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const P=document.createElement("div");P.className="field-note",P.innerHTML=l.fieldNote,p.appendChild(P)}const f=document.createElement("div");f.className="file-input-wrapper",b==="file"&&f.setAttribute("aria-label",this.out(this.settings.fileUploadText)),b==="multifile"&&f.setAttribute("aria-label",this.out(this.settings.multiFileUploadText)),p.appendChild(f);const m=document.createElement("input");m.id=`input_url_label_${g}`,m.type="text",m.name=w+"__url",m.value=l.value||"",m.className="inp-base input-file-url",m.placeholder=l.placeholder||this.out("Enter URL."),p.appendChild(m),m.addEventListener("input",()=>{const P=p.querySelector(".btn-clearfile");P&&P.click(),this.inputListener(),m.value!==""?l.isRequired&&y.removeAttribute("required"):l.isRequired&&y.setAttribute("required","required"),Lt(m.value),this.clearSelectedFiles()}),l.useURL?m.style.display="":m.style.display="none";const y=document.createElement("input");y.id=`file_${g}`,y.type="file",b==="multifile"&&(y.multiple=!0),y.name=w,l.isRequired&&y.setAttribute("required","required"),y.className="peer",f.appendChild(y);const k=document.createElement("div");k.className="file-drop-area",f.appendChild(k);const x=document.createElement("div");x.className="file-controls",x.id=`drag_message_${g}`,f.appendChild(x);let S;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(S=document.createElement("div"),S.className="file-drop-info",b==="file"&&(S.innerHTML=this.out(this.settings.fileUploadText)),b==="multifile"&&(S.innerHTML=this.out(this.settings.multiFileUploadText)),x.appendChild(S));let E;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(E=document.createElement("button"),E.className="btn-selectfile",E.innerHTML=`
|
|
340
|
+
`);const S=document.createElement("input");S.type="text",S.id=`input_other_${g}`,S.name=w+"_other",S.className="input-other hidden inp-base",p.appendChild(S);const E=p.querySelector(`#dropdown_${g}`),C=p.querySelector(`#input_other_${g}`);E.addEventListener("change",()=>{E.value==="other"?(C.classList.remove("hidden"),C.focus()):C.classList.add("hidden");const A=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(A)}),S.addEventListener("input",this.inputListener)}if(b==="date"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`date_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`date_${g}`,f.type="date",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="time"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`time_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`time_${g}`,f.type="time",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="datetime"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`datetime_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`datetime_${g}`,f.type="datetime-local",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("change",this.changeListener)}if(b==="color"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`color_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`color_${g}`,f.type="color",f.name=w,f.value=l.value||"",f.className="input-color",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="file"||b==="multifile"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`file_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const P=document.createElement("div");P.className="field-note",P.innerHTML=l.fieldNote,p.appendChild(P)}const f=document.createElement("div");f.className="file-input-wrapper",b==="file"&&f.setAttribute("aria-label",this.out(this.settings.fileUploadText)),b==="multifile"&&f.setAttribute("aria-label",this.out(this.settings.multiFileUploadText)),p.appendChild(f);const m=document.createElement("input");m.id=`input_url_label_${g}`,m.type="text",m.name=w+"__url",m.value=l.value||"",m.className="inp-base input-file-url",m.placeholder=l.placeholder||this.out("Enter URL."),p.appendChild(m),m.addEventListener("input",()=>{const P=p.querySelector(".btn-clearfile");P&&P.click(),this.inputListener(),m.value!==""?l.isRequired&&y.removeAttribute("required"):l.isRequired&&y.setAttribute("required","required"),Lt(m.value),this.clearSelectedFiles()}),l.useURL?m.style.display="":m.style.display="none";const y=document.createElement("input");y.id=`file_${g}`,y.type="file",b==="multifile"&&(y.multiple=!0),y.name=w,l.isRequired&&y.setAttribute("required","required"),y.className="peer",f.appendChild(y);const k=document.createElement("div");k.className="file-drop-area",f.appendChild(k);const x=document.createElement("div");x.className="file-controls",x.id=`drag_message_${g}`,f.appendChild(x);let S;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(S=document.createElement("div"),S.className="file-drop-info",b==="file"&&(S.innerHTML=this.out(this.settings.fileUploadText)),b==="multifile"&&(S.innerHTML=this.out(this.settings.multiFileUploadText)),x.appendChild(S));let E;(!l.source||l.source&&l.source==="local"||l.source&&l.source==="local_and_camera")&&(E=document.createElement("button"),E.className="btn-selectfile",E.innerHTML=`
|
|
341
341
|
<svg style="fill:none"xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" class="icon-folder-open"><path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
|
342
342
|
<path d="M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2" />
|
|
343
343
|
</svg>
|
|
@@ -391,7 +391,7 @@ Check the information and return the details.
|
|
|
391
391
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
|
392
392
|
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
|
|
393
393
|
</svg>
|
|
394
|
-
`,ue.appendChild(pe),pe.addEventListener("click",j=>{const we=pe.closest(".image-item");we&&we.remove(),(yn=>{const mi=new DataTransfer,vn=y.files;Array.from(vn).forEach(bi=>{bi!==yn&&mi.items.add(bi)}),y.files=mi.files})(P);const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),P.type.startsWith("image/")){const j=new FileReader;j.onload=function(we){let Te=document.createElement("img");Te.className="img-preview",se.appendChild(Te),Te.src=we.target.result},j.readAsDataURL(P)}const K=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(K);const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)}}}if(b==="email"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`email_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`email_label_${g}`,f.type="email",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="phone"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`phone_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`phone_label_${g}`,f.type="tel",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="url"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`url_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`url_label_${g}`,f.type="url",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="hidden"){let g=this.getId();const v=document.createElement("label");v.setAttribute("for",`hidden_label_${g}`),v.className="field-label hidden",v.innerText=l.title,p.appendChild(v);const f=document.createElement("input");f.id=`hidden_label_${g}`,f.type="hidden",f.name=w,f.value=l.value,p.appendChild(f)}});const a=r.closest("[data-site-token]");if(a){const l=a.getAttribute("data-site-token"),h=document.createElement("input");h.type="hidden",h.name="form_token",h.value=l,r.appendChild(h)}if(this.settings.isBuilder){const l=document.createElement("div");l.className="submit-container",r.appendChild(l);let h=!0;if("hideReset"in t&&(h=t.hideReset),!h){const _=document.createElement("button");_.className="btn-resetform";const g=t.resetText||this.settings.resetText;_.innerText=g,l.appendChild(_),_.addEventListener("click",f=>{f.preventDefault();const m=_.closest("form");m&&(m.reset(),m.querySelectorAll(".btn-clearfile").forEach(x=>{x.click()}),m.querySelectorAll(".slider-container").forEach(x=>{const S=x.querySelector("input");x.querySelector(".current-value").textContent=S.value}))}),(t.fullWidthButton||!1)&&_.classList.add("w-full")}const p=document.createElement("button");p.className="btn-submitform";const b=t.submitText||this.settings.submitText;p.innerText=b,l.appendChild(p),(t.fullWidthButton||!1)&&p.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&l.classList.add("always-visible"),this.stickyElement(l),r.addEventListener("submit",async _=>{_.preventDefault(),this.steps&&this.steps.length>0&&this.process()})}else{let l="Reference Code:",h="reference_code",p="reference_code";const b=document.createElement("div");b.className="form-field ",b.classList.add(p),r.appendChild(b);let w=this.getId();const _=document.createElement("label");_.setAttribute("for",`short_text_label_${w}`),_.className="field-label",_.innerHTML=l,b.appendChild(_);const g=document.createElement("input");if(g.id=`short_text_label_${w}`,g.type="text",g.name=h,g.autocomplete="off",g.setAttribute("aria-hidden","true"),g.setAttribute("tabindex","-1"),g.className="inp-base",b.appendChild(g),this.settings.captchaContainer){const v=this.settings.captchaContainerClassName,f=document.createElement("div");f.className="captcha-container",v&&f.classList.add(v),r.appendChild(f)}if(t.useSubmitButton){const v=document.createElement("div");v.className="submit-container",r.appendChild(v);let f=!0;if("hideReset"in t&&(f=t.hideReset),!f){const S=document.createElement("button");S.className="btn-resetform";const E=t.resetText||this.settings.resetText;S.innerText=E,v.appendChild(S),S.addEventListener("click",A=>{A.preventDefault();const L=S.closest("form");L&&(L.reset(),L.querySelectorAll(".btn-clearfile").forEach(O=>{O.click()}),L.querySelectorAll(".slider-container").forEach(O=>{const R=O.querySelector("input");O.querySelector(".current-value").textContent=R.value}))}),(t.fullWidthButton||!1)&&S.classList.add("w-full")}const m=document.createElement("button");m.className="btn-submitform";const y=t.submitText;m.innerText=y,v.appendChild(m),(t.fullWidthButton||!1)&&m.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&v.classList.add("always-visible"),this.stickyElement(v),m.addEventListener("click",async S=>{this.trigger("submit",S)});const x=r.closest("form");x?x.addEventListener("submit",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),S.stopImmediatePropagation(),this.process())}):m.addEventListener("click",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),this.process())})}}let d,u;this.settings.resultSelector&&(d=document.querySelector(this.settings.resultSelector),d.classList.add("result-wrapper"),d.innerHTML="",u=document.createElement("div"),u.classList.add("result-container"),d.appendChild(u)),t.elements&&d&&t.elements.forEach(l=>{if(l.displayInOutput){if(l.type==="spacer"){const p=document.createElement("div");p.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(p.style.height=l.spacerHeight+"px"),u.appendChild(p);return}if(l.type==="separator"){const p=document.createElement("hr");p.style.borderTopColor=l.color,u.appendChild(p);return}if(l.type==="html"){if(l.html){const p=document.createElement("div");p.innerHTML=l.html,u.appendChild(p)}return}if(l.type==="heading"){const p=document.createElement(l.heading||"h2");p.innerHTML=l.headingText||this.out("Your Heading Here!"),u.appendChild(p);return}if(l.type==="paragraph"){const p=document.createElement("p");p.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),u.appendChild(p);return}if(l.type==="media"){if(l.tag==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",p.appendChild(h),u.appendChild(p)}else if(l.tag==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p)}else if(l.tag==="img"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p)}return}if(l.type==="image"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p);return}if(l.type==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="video/mp4",p.appendChild(b),u.appendChild(p);return}if(l.type==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p);return}}})}if(this.settings.resultSelector&&document.querySelector(this.settings.resultSelector).classList.add("result-wrapper"),this.settings.saveResults&&this.settings.resultSelector&&localStorage.getItem("_results"))try{this.previousResults=JSON.parse(localStorage.getItem("_results"));let n=localStorage.getItem("_results_html");const r=document.querySelector(this.settings.resultSelector);r.innerHTML=n,this.addResultTool(),r.querySelectorAll(".link-download").forEach(a=>{a.addEventListener("click",async d=>{d.preventDefault();const u=d.target.href;try{const l=await fetch(u,{mode:"cors"});if(!l.ok)throw new Error("Failed to fetch the image.");const h=await l.blob(),p=u.substring(u.lastIndexOf("/")+1),b=document.createElement("a");b.href=URL.createObjectURL(h),b.download=p,b.click(),URL.revokeObjectURL(b.href)}catch(l){console.error("Error downloading the image:",l)}})})}catch{}const s=document.querySelector(".formview-container .submit-container");s&&setTimeout(()=>{this.stickyElement(s)},1e3)}abort(){this.controller&&this.controller.abort()}async search(e){let t={"Content-Type":"application/json",...this.settings.headers};try{const i=await fetch(this.settings.searchUrl,{method:"POST",headers:t,body:JSON.stringify({query:e,customData:this.settings.customData})});if(!i.ok)throw new Error("Failed to fetch data");const s=await i.json(),n=s.organic_results?"organic_results":"organic";return(s[n]||[]).map(r=>({title:r.title,link:r.link,snippet:r.snippet||r.description}))}catch(i){return console.error("Error in search:",i.message||i),[]}}async scrapeUrls(e){if(e.length===0)return{data:"",urls:[],failed:[]};this.settings.consoleLog&&console.log(e);let t={"Content-Type":"application/json",...this.settings.headers};const i=await fetch(this.settings.scrapeUrl,{method:"POST",headers:t,body:JSON.stringify({urls:e,customData:this.settings.customData})});if(!i.ok)throw new Error(`Error: ${i.statusText}`);let s="";const n=await i.json();if(this.settings.consoleLog&&console.log(n),n.error)return this.settings.consoleLog&&console.log(n.error),{data:"",urls:[],failed:[]};let r=[],o=[];if(this.settings.scrapeProvider==="firecrawl"&&n.forEach(a=>{if(a.success){const d=a.metadata.title,u=a.markdown,l=a.metadata.url;r.push(l),s+=`
|
|
394
|
+
`,ue.appendChild(pe),pe.addEventListener("click",j=>{const we=pe.closest(".image-item");we&&we.remove(),(yn=>{const mi=new DataTransfer,vn=y.files;Array.from(vn).forEach(bi=>{bi!==yn&&mi.items.add(bi)}),y.files=mi.files})(P);const He=document.querySelector(".formview-container .submit-container");He&&setTimeout(()=>{this.stickyElement(He)},1e3),j.preventDefault(),j.stopImmediatePropagation()}),P.type.startsWith("image/")){const j=new FileReader;j.onload=function(we){let Te=document.createElement("img");Te.className="img-preview",se.appendChild(Te),Te.src=we.target.result},j.readAsDataURL(P)}const K=this.getFormValues();this.settings.onInputChange&&this.settings.onInputChange(K);const ve=document.querySelector(".formview-container .submit-container");ve&&setTimeout(()=>{this.stickyElement(ve)},1e3)}}}if(b==="email"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`email_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`email_label_${g}`,f.type="email",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="phone"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`phone_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`phone_label_${g}`,f.type="tel",f.name=w,f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="url"){let g=this.getId();const v=document.createElement("label");if(v.setAttribute("for",`url_label_${g}`),v.className="field-label",v.innerHTML=l.title+(l.isRequired?' <span class="text-red-500" aria-hidden="true">*</span>':""),p.appendChild(v),l.fieldNote){const m=document.createElement("div");m.className="field-note",m.innerHTML=l.fieldNote,p.appendChild(m)}const f=document.createElement("input");f.id=`url_label_${g}`,f.type="url",f.name=w,f.value=l.value||"",f.className="inp-base",f.placeholder=l.placeholder,l.isRequired&&f.setAttribute("required","required"),p.appendChild(f),f.addEventListener("input",this.inputListener)}if(b==="hidden"){let g=this.getId();const v=document.createElement("label");v.setAttribute("for",`hidden_label_${g}`),v.className="field-label hidden",v.innerText=l.title,p.appendChild(v);const f=document.createElement("input");f.id=`hidden_label_${g}`,f.type="hidden",f.name=w,f.value=l.value,p.appendChild(f)}});const a=r.closest("[data-site-token]");if(a){const l=a.getAttribute("data-site-token"),h=document.createElement("input");h.type="hidden",h.name="form_token",h.value=l,r.appendChild(h)}if(this.settings.isBuilder){const l=document.createElement("div");l.className="submit-container",r.appendChild(l);let h=!0;if("hideReset"in t&&(h=t.hideReset),!h){const _=document.createElement("button");_.className="btn-resetform";const g=t.resetText||this.settings.resetText;_.innerText=g,l.appendChild(_),_.addEventListener("click",f=>{f.preventDefault();const m=_.closest("form");m&&(m.reset(),m.querySelectorAll(".btn-clearfile").forEach(x=>{x.click()}),m.querySelectorAll(".slider-container").forEach(x=>{const S=x.querySelector("input");x.querySelector(".current-value").textContent=S.value}))}),(t.fullWidthButton||!1)&&_.classList.add("w-full")}const p=document.createElement("button");p.className="btn-submitform";const b=t.submitText||this.settings.submitText;p.innerText=b,l.appendChild(p),(t.fullWidthButton||!1)&&p.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&l.classList.add("always-visible"),this.stickyElement(l),r.addEventListener("submit",async _=>{_.preventDefault(),this.steps&&this.steps.length>0&&this.process()})}else{let l="Reference Code:",h="reference_code",p="reference_code";const b=document.createElement("div");b.className="form-field ",b.classList.add(p),r.appendChild(b);let w=this.getId();const _=document.createElement("label");_.setAttribute("for",`short_text_label_${w}`),_.className="field-label",_.innerHTML=l,b.appendChild(_);const g=document.createElement("input");if(g.id=`short_text_label_${w}`,g.type="text",g.name=h,g.autocomplete="off",g.setAttribute("aria-hidden","true"),g.setAttribute("tabindex","-1"),g.className="inp-base",b.appendChild(g),this.settings.captchaContainer){const v=this.settings.captchaContainerClassName,f=document.createElement("div");f.className="captcha-container",v&&f.classList.add(v),r.appendChild(f)}if(t.useSubmitButton){const v=document.createElement("div");v.className="submit-container",r.appendChild(v);let f=!0;if("hideReset"in t&&(f=t.hideReset),!f){const S=document.createElement("button");S.className="btn-resetform";const E=t.resetText||this.settings.resetText;S.innerText=E,v.appendChild(S),S.addEventListener("click",A=>{A.preventDefault();const L=S.closest("form");L&&(L.reset(),L.querySelectorAll(".btn-clearfile").forEach(O=>{O.click()}),L.querySelectorAll(".slider-container").forEach(O=>{const R=O.querySelector("input");O.querySelector(".current-value").textContent=R.value}))}),(t.fullWidthButton||!1)&&S.classList.add("w-full")}const m=document.createElement("button");m.className="btn-submitform";const y=t.submitText;m.innerText=y,v.appendChild(m),(t.fullWidthButton||!1)&&m.classList.add("w-full"),this.settings.alwaysVisibleSubmit&&v.classList.add("always-visible"),this.stickyElement(v),m.addEventListener("click",async S=>{this.trigger("submit",S)});const x=r.closest("form");x?x.addEventListener("submit",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),S.stopImmediatePropagation(),this.process())}):m.addEventListener("click",async S=>{this.steps&&this.steps.length>0&&(S.preventDefault(),this.process())})}}let d,u;this.settings.resultSelector&&(d=document.querySelector(this.settings.resultSelector),d.classList.add("result-wrapper"),d.innerHTML="",u=document.createElement("div"),u.classList.add("result-container"),d.appendChild(u)),t.elements&&d&&t.elements.forEach(l=>{if(l.displayInOutput){if(l.type==="spacer"){const p=document.createElement("div");p.className="form-spacer",l.spacerHeight&&!isNaN(parseFloat(l.spacerHeight))&&(p.style.height=l.spacerHeight+"px"),u.appendChild(p);return}if(l.type==="separator"){const p=document.createElement("hr");p.style.borderTopColor=l.color,u.appendChild(p);return}if(l.type==="html"){if(l.html){const p=document.createElement("div");p.innerHTML=l.html,u.appendChild(p)}return}if(l.type==="heading"){const p=document.createElement(l.heading||"h2");p.innerHTML=l.headingText||this.out("Your Heading Here!"),u.appendChild(p);return}if(l.type==="paragraph"){const p=document.createElement("p");p.innerHTML=l.paragraphText||this.out("Your paragraph content here!"),u.appendChild(p);return}if(l.type==="media"){if(l.tag==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;var h=document.createElement("source");h.src=l.url,h.type="video/mp4",p.appendChild(h),u.appendChild(p)}else if(l.tag==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p)}else if(l.tag==="img"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p)}return}if(l.type==="image"){const p=document.createElement("img");p.src=l.url,p.setAttribute("alt",this.out("Output Image")),u.appendChild(p);return}if(l.type==="video"){const p=document.createElement("video");p.style.width="100%",p.style.height="auto",p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="video/mp4",p.appendChild(b),u.appendChild(p);return}if(l.type==="audio"){const p=document.createElement("audio");p.controls=!0;let b=document.createElement("source");b.src=l.url,b.type="audio/mp3",p.appendChild(b),u.appendChild(p);return}}})}if(this.settings.resultSelector&&document.querySelector(this.settings.resultSelector).classList.add("result-wrapper"),this.settings.saveResults&&this.settings.resultSelector&&localStorage.getItem("_results"))try{this.previousResults=JSON.parse(localStorage.getItem("_results"));let n=localStorage.getItem("_results_html");const r=document.querySelector(this.settings.resultSelector);r.innerHTML=n,this.addResultTool(),r.querySelectorAll(".link-download").forEach(a=>{a.addEventListener("click",async d=>{d.preventDefault();const u=d.target.href;try{const l=await fetch(u,{mode:"cors"});if(!l.ok)throw new Error("Failed to fetch the image.");const h=await l.blob(),p=u.substring(u.lastIndexOf("/")+1),b=document.createElement("a");b.href=URL.createObjectURL(h),b.download=p,b.click(),URL.revokeObjectURL(b.href)}catch(l){console.error("Error downloading the image:",l)}})})}catch{}const s=document.querySelector(".formview-container .submit-container");s&&setTimeout(()=>{this.stickyElement(s)},1e3)}abort(){this.controller&&this.controller.abort()}async search(e){let t={"Content-Type":"application/json",...this.settings.headers};try{const i=await fetch(this.settings.searchUrl,{method:"POST",headers:t,body:JSON.stringify({query:e,customData:this.settings.customData})});if(!i.ok)throw new Error("Failed to fetch data");const s=await i.json(),n=s.organic_results?"organic_results":"organic";return(s[n]||[]).map(r=>({title:r.title,link:r.link,snippet:r.snippet||r.description}))}catch(i){return console.error("Error in search:",i.message||i),[]}}async scrapeUrls(e){if(e.length===0)return{data:"",urls:[],failed:[]};this.settings.consoleLog&&console.log(e);let t={"Content-Type":"application/json",...this.settings.headers};const i=await fetch(this.settings.scrapeUrl,{method:"POST",headers:t,body:JSON.stringify({urls:e,customData:this.settings.customData})});if(!i.ok)throw new Error(`Error: ${i.statusText}`);let s="";const n=await i.json();if(this.settings.consoleLog&&console.log(n),n.error)return this.settings.consoleLog&&console.log(n.error),{data:"",urls:[],failed:[]};let r=[],o=[];if(this.settings.scrapeProvider==="firecrawl"&&n.forEach(a=>{if(a.success){const d=a.metadata.title,u=a.markdown,l=a.metadata.url;r.push(l),s+=`
|
|
395
395
|
|
|
396
396
|
|
|
397
397
|
## ${d}
|
|
@@ -508,4 +508,4 @@ ${q.data}
|
|
|
508
508
|
`}}this.tokenInput+=y,this.tokenOutput+=k}return!0}catch(l){return l.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",l),!1}}async assistant(e,t,i,s){this.controller=new AbortController,this.signal=this.controller.signal;let n=.6,r=.9,o=1;s||(s=[]);let a=this.settings.model;s.length>0&&(a=this.settings.model2);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:n,topP:r,num:o,model:a,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers},h=await(await fetch(this.settings.assistantUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)})).json();return h.error?(console.log(`Error:
|
|
509
509
|
`+h.error),!1):(h.usage&&(this.tokenInput+=h.usage.prompt_tokens,this.tokenOutput+=h.usage.completion_tokens),h.answer.content[0].text.value)}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}async assistantStream(e,t,i,s,n){this.controller=new AbortController,this.signal=this.controller.signal;let r=.6,o=.9,a=1;s||(s=[]);const d={assistantId:this.settings.assistantId,question:e,context:t,system:i,functs:s,temperature:r,topP:o,num:a,model:this.settings.model,customData:this.settings.customData};try{let u={"Content-Type":"application/json",...this.settings.headers};const l=await fetch(this.settings.assistantStreamUrl,{signal:this.signal,method:"POST",headers:u,body:JSON.stringify(d)});if(!l.ok)return console.error("Error:",l.statusText),!1;const h=l.body.getReader(),p=new TextDecoder;let b="",w=!1;for(;!w;){const{done:_,value:g}=await h.read();if(w=_,w)break;const v=p.decode(g,{stream:!0});b+=v;const f=b.split(`
|
|
510
510
|
`);b="";for(const m of f)if(m.trim()!=="")if(m.startsWith("data:")){const y=m.slice(5).trim();y==="[DONE]"&&this.settings.consoleLog&&console.log("Stream completed.");try{const k=JSON.parse(y);if(k.choices&&k.choices[0].delta&&k.choices[0].delta.content){const x=k.choices[0].delta.content;n&&n(x)}}catch{b+=m+`
|
|
511
|
-
`}}else{const y=JSON.parse(m);this.tokenInput+=y.prompt_tokens,this.tokenOutput+=y.completion_tokens;break}}return!0}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}hexToRgb(e){const t=e.replace("#",""),i=parseInt(t,16),s=i>>16&255,n=i>>8&255,r=i&255;return{red:s,green:n,blue:r}}getId(e="id"){return`${e}-${Math.random().toString(36).substr(2,9)}`}appendHtml(e,t){e&&t&&e.insertAdjacentHTML("beforeend",t)}cleanup(){if(this.element){let e=this.element.querySelectorAll('input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="url"], textarea');e.forEach(t=>{t.removeEventListener("input",this.inputListener)}),e=this.element.querySelectorAll('input[type="date"], input[type="radio"], input[type="checkbox"]'),e.forEach(t=>{t.removeEventListener("change",this.changeListener)}),this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null)}}destroy(){try{if(this._scrollListener){let e;this.settings.isBuilder?e=document.querySelector(this.settings.previewSelector):e=this.element;const t=e.querySelector(".submit-container"),i=this.getScrollableParent(t);i?i.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._scrollListener)}}catch{}this.element&&(this.cleanup(),this.element.innerHTML="",this.element=null);for(const e in this.listeners)this.listeners[e].clear();this.listeners={}}out(e){let t=this.settings.lang[e];return t||e}}class mn{constructor(e={}){this.config={plugins:{},autoLoad:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[],onReInit:()=>{},...e},this.plugins=new Map,this.loadedStyles=new Set,this.components=new Map,this.externalPlugins=new Map}async autoLoadPlugins(){const t=this.detectComponentTypes().filter(i=>this.config.plugins[i]&&!this.plugins.has(i));return t.length>0&&await Promise.all(t.map(i=>this.loadPlugin(i))),t}detectComponentTypes(){const e=new Set;return document.querySelectorAll("[data-cb-type]").forEach(t=>{e.add(t.dataset.cbType)}),document.querySelectorAll('[class*="cb-"]').forEach(t=>{t.classList.forEach(i=>{if(i.startsWith("cb-")){const s=i.replace("cb-","");e.add(s)}})}),Array.from(e)}async loadPlugin(e){if(this.plugins.has(e))return this.plugins.get(e);const t=this.config.plugins[e];if(!t)return console.warn(`[PluginManager] Plugin "${e}" not found in registry`),null;if(e==="code"){const i={name:"code",version:"1.0.0",mount:function(s,n){return{}}};return this.plugins.set(e,i),this.emit("plugin-loaded",{name:e,plugin:i}),i}try{t.css&&this.loadCSS(this.resolveUrl(t.css));const i=this.resolveUrl(t.url),s=await this.importModule(i),n=s.default||s;return this.plugins.set(e,n),typeof n.init=="function"&&await n.init(this),this.emit("plugin-loaded",{name:e,plugin:n}),n}catch(i){return console.error(`[PluginManager] Failed to load plugin "${e}":`,i),null}}async importModule(e){return import(e)}loadCSS(e){if(this.loadedStyles.has(e))return;const t=document.createElement("link");t.rel="stylesheet",t.href=e,t.onload=()=>{this.emit("css-loaded",{url:e})},t.onerror=()=>{console.error(`[PluginManager] Failed to load CSS: ${e}`)},document.head.appendChild(t),this.loadedStyles.add(e)}resolveUrl(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")?e:this.config.pluginBaseUrl+e}initializeComponents(){return document.querySelectorAll("[data-cb-type]").forEach((t,i)=>{const s=t.dataset.cbType,n=this.plugins.get(s);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let o=t.querySelector(".grid-sortable");o||t.classList.contains("grid-sortable")&&(o=t),o&&Array.from(o.children).forEach((u,l)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",l)}),t.querySelectorAll(".edit").forEach((u,l)=>{const h=`content-${Date.now()}-${i}-${l}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const d=n.mount(t,r);this.components.set(t,d),this.setupInlineEditing(t,r),t.setAttribute("data-cb-loaded","true"),typeof t.mount=="function"&&t.mount()}catch(r){console.error(`[PluginManager] Failed to mount component "${s}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(i=>{if(i.name.startsWith("data-cb-")){const s=i.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[s]=this.parseValue(i.value)}}),t}parseValue(e){if(e==="true")return!0;if(e==="false")return!1;if(!isNaN(e)&&e!=="")return Number(e);try{return JSON.parse(e)}catch{return e}}setupInlineEditing(e,t){if(!e.closest(".data-editor"))return;const i=e.querySelectorAll(".edit[data-edit-id]");if(i.length===0)return;e.querySelectorAll('.edit[contenteditable="true"]').forEach(r=>{r.removeAttribute("contenteditable"),r._cbObserver&&(r._cbObserver.disconnect(),delete r._cbObserver),r._cbKeydownHandler&&(r.removeEventListener("keydown",r._cbKeydownHandler),delete r._cbKeydownHandler)});const n=(r,o)=>{const a=e.getAttribute("data-cb-original-content");if(!a)return;const d=document.createElement("template");d.innerHTML=a.trim();const l=d.content.querySelector(`[data-edit-id="${r}"]`);if(l){l.innerHTML=o;const h=d.innerHTML;e.setAttribute("data-cb-original-content",h)}};i.forEach(r=>{r.setAttribute("contenteditable","true");const o=u=>{var l=document.createRange();l.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(l)},a=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let l;try{window.getSelection?l=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(l=document.selection.createRange().parentElement()),o(l),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",a),r._cbKeydownHandler=a;const d=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),l=r.innerHTML;n(u,l)});d.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=d})}async use(e){return await this.loadPlugin(e)}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.entries())}hasPlugin(e){return this.plugins.has(e)}getComponent(e){return this.components.get(e)}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const i=await this.reinitialize(e);t(i)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((o,a)=>{(e===document||e.contains(a))&&t.push({element:a,instance:o})}),t.forEach(({element:o,instance:a})=>{const d=o.dataset.cbType,u=this.plugins.get(d);u&&typeof u.unmount=="function"&&u.unmount(o,a),this.components.delete(o)});const s=this.detectComponentTypesInContainer(e).filter(o=>this.config.plugins[o]&&!this.plugins.has(o));s.length>0&&await Promise.all(s.map(o=>this.loadPlugin(o)));const n=e.querySelectorAll("[data-cb-type]");let r=0;for(const o of n){const a=o.dataset.cbType,d=this.plugins.get(a);if(d&&typeof d.mount=="function")try{const u=this.parseOptions(o);let l=o.querySelector(".grid-sortable");if(l||o.classList.contains("grid-sortable")&&(l=o),l&&Array.from(l.children).forEach((b,w)=>{b.nodeType===1&&b.tagName!=="STYLE"&&b.tagName!=="SCRIPT"&&b.setAttribute("data-index",w)}),o.querySelectorAll(".edit").forEach((b,w)=>{const _=`content-${Date.now()}-${r}-${w}`;b.setAttribute("data-edit-id",_)}),!o.hasAttribute("data-cb-original-content"))o.setAttribute("data-cb-original-content",o.innerHTML);else{let b=document.createRange();o.innerHTML="",o.appendChild(b.createContextualFragment(o.getAttribute("data-cb-original-content")))}const p=await d.mount(o,u);this.components.set(o,p),this.setupInlineEditing(o,u),o.setAttribute("data-cb-loaded","true"),typeof o.mount=="function"&&o.mount(),r++}catch(u){console.error(`[PluginManager] Failed to mount component "${a}":`,u)}}return typeof this.config.onReInit=="function"&&this.config.onReInit(),this.emit("reinitialized",{container:e,count:r}),r}finally{this.reinitializeInProgress=!1}}detectComponentTypesInContainer(e){const t=new Set;return e.querySelectorAll("[data-cb-type]").forEach(s=>{t.add(s.dataset.cbType)}),Array.from(t)}async loadExternalPlugin(e,t){if(!e||typeof e!="string")throw new Error("Plugin ID is required and must be a string");if(!t.url)throw new Error("Plugin URL is required");if(this.plugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is already loaded`),this.plugins.get(e);const i=this.validatePluginSource(t.url);if(!i.allowed)throw new Error(`Security: ${i.reason}`);i.warning&&(console.warn(`[PluginManager] ${i.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:i.warning}));try{this.config.plugins[e]={url:t.url,css:t.css||null,source:"external",loadedAt:new Date().toISOString()},this.externalPlugins.set(e,this.config.plugins[e]);const s=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),s}catch(s){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,s),s}}validatePluginSource(e){const t=e.includes("localhost")||e.includes("127.0.0.1");if(!e.startsWith("https://")&&!t)return{allowed:!1,reason:"Only HTTPS URLs are allowed (except localhost for development)"};if(!this.config.allowExternalPlugins)return{allowed:!1,reason:"External plugins are disabled. Enable allowExternalPlugins in configuration."};if(this.config.trustedDomains.length>0){const s=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const o=r.slice(2);return s===o||s.endsWith("."+o)}return s===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${s}. Only add plugins from sources you trust.`}}else return{allowed:!0,warning:`Loading external plugin from: ${new URL(e).hostname}. This plugin will have full access to your page.`};return{allowed:!0}}async loadExternalPlugins(e){const t=[];for(const[i,s]of Object.entries(e))try{const n=await this.loadExternalPlugin(i,s);t.push({pluginId:i,success:!0,plugin:n})}catch(n){t.push({pluginId:i,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${i}":`,n)}return t}unregisterPlugin(e){if(!this.externalPlugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is not an external plugin`),!1;const t=this.plugins.get(e),i=[];return this.components.forEach((s,n)=>{n.dataset.cbType===e&&i.push({element:n,instance:s})}),i.forEach(({element:s,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(s,n),this.components.delete(s)}),t&&typeof t.destroy=="function"&&t.destroy(this),this.plugins.delete(e),this.externalPlugins.delete(e),delete this.config.plugins[e],this.emit("plugin-unregistered",{pluginId:e}),!0}getExternalPlugins(){return Array.from(this.externalPlugins.entries()).map(([e,t])=>({id:e,...t}))}isExternalPlugin(e){return this.externalPlugins.has(e)}destroy(){this.components.forEach((e,t)=>{const i=t.dataset.cbType,s=this.plugins.get(i);s&&typeof s.unmount=="function"&&s.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(s=>{s.removeAttribute("contenteditable"),s._cbObserver&&(s._cbObserver.disconnect(),delete s._cbObserver),s._cbKeydownHandler&&(s.removeEventListener("keydown",s._cbKeydownHandler),delete s._cbKeydownHandler)})}),this.plugins.forEach((e,t)=>{typeof e.destroy=="function"&&e.destroy(this)}),this.components.clear(),this.plugins.clear()}emit(e,t){if(this.runtime&&typeof this.runtime.emit=="function")this.runtime.emit(e,t);else{const i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}}setRuntime(e){this.runtime=e}}class bn{constructor(e={}){const t={skin:"light",plugins:{},autoLoadPlugins:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new mn({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains}),this.pluginManager.setRuntime(this),window.Glide=Rs,window.FormViewer=gn}async use(e){return await this.pluginManager.use(e)}getPlugin(e){return this.pluginManager.getPlugin(e)}getPlugins(){return this.pluginManager.getAllPlugins()}hasPlugin(e){return this.pluginManager.hasPlugin(e)}getComponent(e){return this.pluginManager.getComponent(e)}getComponents(){return this.pluginManager.components}async reinitialize(e){const t=await this.pluginManager.reinitialize(e);return this.initCore(),t}async loadExternalPlugin(e,t){return await this.pluginManager.loadExternalPlugin(e,t)}async loadExternalPlugins(e){return await this.pluginManager.loadExternalPlugins(e)}unregisterPlugin(e){return this.pluginManager.unregisterPlugin(e)}emit(e,t){const i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}init(){this.initialized||(this.initCore(),this.initPlugins(),this.initialized=!0,this.emit("init"))}async initPlugins(){this.settings.autoLoadPlugins&&await this.pluginManager.autoLoadPlugins(),this.pluginManager.initializeComponents()}initCore(){const e={touchNavigation:!0,selector:".glightbox",loop:!0,autoplayVideos:!0,zoomable:!0,slideEffect:"slide",descPosition:"bottom",skin:this.settings.skin};this.refreshLightbox(e),document.querySelectorAll(".is-lightbox,.block-click").forEach(i=>{const s=n=>{if(i.closest('[contenteditable="true"]'))return n.preventDefault(),!1;{let r=i.getAttribute("href")||i.getAttribute("data-modal-url");this.openLightbox(r,i,e),n.preventDefault(),n.stopImmediatePropagation()}};i.addEventListener("click",s),i._lightboxHandler=s})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new jt(e),window.GLightbox=jt.default}openLightbox(e,t,i){let s=[],n=0;if(t){const o=t.closest("[data-gallery]");let a=[];o?a=o.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||a.push(u)}),a.forEach((d,u)=>{let l=d.getAttribute("href");l||(l=d.getAttribute("data-modal-url")),s.push({href:l}),e===l&&(n=u)})}const r=document.activeElement;r?.blur(),s.length>0?(this.glightbox.setElements(s),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(i),r?.focus()})}destroy(){this.glightbox&&(this.glightbox.destroy(),this.glightbox=null),document.querySelectorAll(".is-lightbox,.block-click").forEach(t=>{t._lightboxHandler&&(t.removeEventListener("click",t._lightboxHandler),delete t._lightboxHandler)}),this.pluginManager.destroy(),this.initialized=!1,this.emit("destroy")}}return bn})();
|
|
511
|
+
`}}else{const y=JSON.parse(m);this.tokenInput+=y.prompt_tokens,this.tokenOutput+=y.completion_tokens;break}}return!0}catch(u){return u.name==="AbortError"?this.settings.consoleLog&&console.log("Request aborted by user."):console.error("Error:",u),!1}}hexToRgb(e){const t=e.replace("#",""),i=parseInt(t,16),s=i>>16&255,n=i>>8&255,r=i&255;return{red:s,green:n,blue:r}}getId(e="id"){return`${e}-${Math.random().toString(36).substr(2,9)}`}appendHtml(e,t){e&&t&&e.insertAdjacentHTML("beforeend",t)}cleanup(){if(this.element){let e=this.element.querySelectorAll('input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="url"], textarea');e.forEach(t=>{t.removeEventListener("input",this.inputListener)}),e=this.element.querySelectorAll('input[type="date"], input[type="radio"], input[type="checkbox"]'),e.forEach(t=>{t.removeEventListener("change",this.changeListener)}),this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null)}}destroy(){try{if(this._scrollListener){let e;this.settings.isBuilder?e=document.querySelector(this.settings.previewSelector):e=this.element;const t=e.querySelector(".submit-container"),i=this.getScrollableParent(t);i?i.removeEventListener("scroll",this._scrollListener):window.removeEventListener("scroll",this._scrollListener),window.removeEventListener("resize",this._scrollListener)}}catch{}this.element&&(this.cleanup(),this.element.innerHTML="",this.element=null);for(const e in this.listeners)this.listeners[e].clear();this.listeners={}}out(e){let t=this.settings.lang[e];return t||e}}class mn{constructor(e={}){this.config={plugins:{},autoLoad:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[],onReInit:()=>{},...e},this.plugins=new Map,this.loadedStyles=new Set,this.components=new Map,this.externalPlugins=new Map}async autoLoadPlugins(){const t=this.detectComponentTypes().filter(i=>this.config.plugins[i]&&!this.plugins.has(i));return t.length>0&&await Promise.all(t.map(i=>this.loadPlugin(i))),t}detectComponentTypes(){const e=new Set;return document.querySelectorAll("[data-cb-type]").forEach(t=>{e.add(t.dataset.cbType)}),document.querySelectorAll('[class*="cb-"]').forEach(t=>{t.classList.forEach(i=>{if(i.startsWith("cb-")){const s=i.replace("cb-","");e.add(s)}})}),Array.from(e)}async loadPlugin(e){if(this.plugins.has(e))return this.plugins.get(e);const t=this.config.plugins[e];if(!t)return console.warn(`[PluginManager] Plugin "${e}" not found in registry`),null;if(e==="code"){const i={name:"code",version:"1.0.0",mount:function(s,n){return{}}};return this.plugins.set(e,i),this.emit("plugin-loaded",{name:e,plugin:i}),i}try{t.css&&this.loadCSS(this.resolveUrl(t.css));const i=this.resolveUrl(t.url),s=await this.importModule(i),n=s.default||s;return this.plugins.set(e,n),typeof n.init=="function"&&await n.init(this),this.emit("plugin-loaded",{name:e,plugin:n}),n}catch(i){return console.error(`[PluginManager] Failed to load plugin "${e}":`,i),null}}async importModule(e){return import(e)}loadCSS(e){if(this.loadedStyles.has(e))return;const t=document.createElement("link");t.rel="stylesheet",t.href=e,t.onload=()=>{this.emit("css-loaded",{url:e})},t.onerror=()=>{console.error(`[PluginManager] Failed to load CSS: ${e}`)},document.head.appendChild(t),this.loadedStyles.add(e)}resolveUrl(e){return e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")?e:this.config.pluginBaseUrl+e}initializeComponents(){return document.querySelectorAll("[data-cb-type]").forEach((t,i)=>{const s=t.dataset.cbType,n=this.plugins.get(s);if(n&&typeof n.mount=="function")try{const r=this.parseOptions(t);let o=t.querySelector(".grid-sortable");o||t.classList.contains("grid-sortable")&&(o=t),o&&Array.from(o.children).forEach((u,l)=>{u.nodeType===1&&u.tagName!=="STYLE"&&u.tagName!=="SCRIPT"&&u.setAttribute("data-index",l)}),t.querySelectorAll(".edit").forEach((u,l)=>{const h=`content-${Date.now()}-${i}-${l}`;u.setAttribute("data-edit-id",h)}),t.hasAttribute("data-cb-original-content")||t.setAttribute("data-cb-original-content",t.innerHTML);const d=n.mount(t,r);this.components.set(t,d),this.setupInlineEditing(t,r),t.setAttribute("data-cb-loaded","true"),typeof t.mount=="function"&&t.mount()}catch(r){console.error(`[PluginManager] Failed to mount component "${s}":`,r)}}),this.components.size}parseOptions(e){const t={};return Array.from(e.attributes).forEach(i=>{if(i.name.startsWith("data-cb-")){const s=i.name.replace("data-cb-","").replace(/-([a-z])/g,(n,r)=>r.toUpperCase());t[s]=this.parseValue(i.value)}}),t}parseValue(e){if(e==="true")return!0;if(e==="false")return!1;if(!isNaN(e)&&e!=="")return Number(e);try{return JSON.parse(e)}catch{return e}}setupInlineEditing(e,t){if(!e.closest(".data-editor"))return;const i=e.querySelectorAll(".edit[data-edit-id]");if(i.length===0)return;e.querySelectorAll('.edit[contenteditable="true"]').forEach(r=>{r.removeAttribute("contenteditable"),r._cbObserver&&(r._cbObserver.disconnect(),delete r._cbObserver),r._cbKeydownHandler&&(r.removeEventListener("keydown",r._cbKeydownHandler),delete r._cbKeydownHandler)});const n=(r,o)=>{const a=e.getAttribute("data-cb-original-content");if(!a)return;const d=document.createElement("template");d.innerHTML=a.trim();const l=d.content.querySelector(`[data-edit-id="${r}"]`);if(l){l.innerHTML=o;const h=d.innerHTML;e.setAttribute("data-cb-original-content",h)}};i.forEach(r=>{r.setAttribute("contenteditable","true");const o=u=>{var l=document.createRange();l.selectNodeContents(u);var h=window.getSelection();h.removeAllRanges(),h.addRange(l)},a=u=>{if((u.ctrlKey||u.metaKey)&&u.which===65){let l;try{window.getSelection?l=window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode:document.selection&&(l=document.selection.createRange().parentElement()),o(l),u.preventDefault(),u.stopImmediatePropagation()}catch{}}};r.addEventListener("keydown",a),r._cbKeydownHandler=a;const d=new MutationObserver(()=>{const u=r.getAttribute("data-edit-id"),l=r.innerHTML;n(u,l)});d.observe(r,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),r._cbObserver=d})}async use(e){return await this.loadPlugin(e)}getPlugin(e){return this.plugins.get(e)}getAllPlugins(){return Array.from(this.plugins.entries())}hasPlugin(e){return this.plugins.has(e)}getComponent(e){return this.components.get(e)}unmountComponent(e){if(!e||!this.components.has(e))return!1;const t=this.components.get(e),i=e.dataset.cbType,s=this.plugins.get(i);if(s&&typeof s.unmount=="function")try{s.unmount(e,t)}catch{}return this.components.delete(e),!0}async reinitialize(e=document){if(this.reinitializeInProgress)return clearTimeout(this.pendingReinitialize),new Promise(t=>{this.pendingReinitialize=setTimeout(async()=>{this.pendingReinitialize=null;const i=await this.reinitialize(e);t(i)},100)});this.reinitializeInProgress=!0;try{const t=[];this.components.forEach((o,a)=>{(e===document||e.contains(a))&&t.push({element:a,instance:o})}),t.forEach(({element:o,instance:a})=>{const d=o.dataset.cbType,u=this.plugins.get(d);u&&typeof u.unmount=="function"&&u.unmount(o,a),this.components.delete(o)});const s=this.detectComponentTypesInContainer(e).filter(o=>this.config.plugins[o]&&!this.plugins.has(o));s.length>0&&await Promise.all(s.map(o=>this.loadPlugin(o)));const n=e.querySelectorAll("[data-cb-type]");let r=0;for(const o of n){const a=o.dataset.cbType,d=this.plugins.get(a);if(d&&typeof d.mount=="function")try{const u=this.parseOptions(o);let l=o.querySelector(".grid-sortable");if(l||o.classList.contains("grid-sortable")&&(l=o),l&&Array.from(l.children).forEach((b,w)=>{b.nodeType===1&&b.tagName!=="STYLE"&&b.tagName!=="SCRIPT"&&b.setAttribute("data-index",w)}),o.querySelectorAll(".edit").forEach((b,w)=>{const _=`content-${Date.now()}-${r}-${w}`;b.setAttribute("data-edit-id",_)}),!o.hasAttribute("data-cb-original-content"))o.setAttribute("data-cb-original-content",o.innerHTML);else{let b=document.createRange();o.innerHTML="",o.appendChild(b.createContextualFragment(o.getAttribute("data-cb-original-content")));let w=!1;o.querySelectorAll(".edit:not([data-edit-id])").forEach((_,g)=>{_.setAttribute("data-edit-id",`content-${Date.now()}-${r}-new-${g}`),w=!0}),w&&o.setAttribute("data-cb-original-content",o.innerHTML)}const p=await d.mount(o,u);this.components.set(o,p),this.setupInlineEditing(o,u),o.setAttribute("data-cb-loaded","true"),typeof o.mount=="function"&&o.mount(),r++}catch(u){console.error(`[PluginManager] Failed to mount component "${a}":`,u)}}return typeof this.config.onReInit=="function"&&this.config.onReInit(),this.emit("reinitialized",{container:e,count:r}),r}finally{this.reinitializeInProgress=!1}}detectComponentTypesInContainer(e){const t=new Set;return e.querySelectorAll("[data-cb-type]").forEach(s=>{t.add(s.dataset.cbType)}),Array.from(t)}async loadExternalPlugin(e,t){if(!e||typeof e!="string")throw new Error("Plugin ID is required and must be a string");if(!t.url)throw new Error("Plugin URL is required");if(this.plugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is already loaded`),this.plugins.get(e);const i=this.validatePluginSource(t.url);if(!i.allowed)throw new Error(`Security: ${i.reason}`);i.warning&&(console.warn(`[PluginManager] ${i.warning}`),this.emit("plugin-security-warning",{pluginId:e,url:t.url,warning:i.warning}));try{this.config.plugins[e]={url:t.url,css:t.css||null,source:"external",loadedAt:new Date().toISOString()},this.externalPlugins.set(e,this.config.plugins[e]);const s=await this.loadPlugin(e);return this.emit("external-plugin-loaded",{pluginId:e,url:t.url}),s}catch(s){throw delete this.config.plugins[e],this.externalPlugins.delete(e),console.error(`[PluginManager] Failed to load external plugin "${e}":`,s),s}}validatePluginSource(e){const t=e.includes("localhost")||e.includes("127.0.0.1");if(!e.startsWith("https://")&&!t)return{allowed:!1,reason:"Only HTTPS URLs are allowed (except localhost for development)"};if(!this.config.allowExternalPlugins)return{allowed:!1,reason:"External plugins are disabled. Enable allowExternalPlugins in configuration."};if(this.config.trustedDomains.length>0){const s=new URL(e).hostname;if(!this.config.trustedDomains.some(r=>{if(r.startsWith("*.")){const o=r.slice(2);return s===o||s.endsWith("."+o)}return s===r}))return{allowed:!0,warning:`Loading plugin from external domain: ${s}. Only add plugins from sources you trust.`}}else return{allowed:!0,warning:`Loading external plugin from: ${new URL(e).hostname}. This plugin will have full access to your page.`};return{allowed:!0}}async loadExternalPlugins(e){const t=[];for(const[i,s]of Object.entries(e))try{const n=await this.loadExternalPlugin(i,s);t.push({pluginId:i,success:!0,plugin:n})}catch(n){t.push({pluginId:i,success:!1,error:n.message}),console.error(`[PluginManager] Failed to load external plugin "${i}":`,n)}return t}unregisterPlugin(e){if(!this.externalPlugins.has(e))return console.warn(`[PluginManager] Plugin "${e}" is not an external plugin`),!1;const t=this.plugins.get(e),i=[];return this.components.forEach((s,n)=>{n.dataset.cbType===e&&i.push({element:n,instance:s})}),i.forEach(({element:s,instance:n})=>{t&&typeof t.unmount=="function"&&t.unmount(s,n),this.components.delete(s)}),t&&typeof t.destroy=="function"&&t.destroy(this),this.plugins.delete(e),this.externalPlugins.delete(e),delete this.config.plugins[e],this.emit("plugin-unregistered",{pluginId:e}),!0}getExternalPlugins(){return Array.from(this.externalPlugins.entries()).map(([e,t])=>({id:e,...t}))}isExternalPlugin(e){return this.externalPlugins.has(e)}destroy(){this.components.forEach((e,t)=>{const i=t.dataset.cbType,s=this.plugins.get(i);s&&typeof s.unmount=="function"&&s.unmount(t,e)}),this.components.forEach((e,t)=>{t.querySelectorAll('.edit[contenteditable="true"]').forEach(s=>{s.removeAttribute("contenteditable"),s._cbObserver&&(s._cbObserver.disconnect(),delete s._cbObserver),s._cbKeydownHandler&&(s.removeEventListener("keydown",s._cbKeydownHandler),delete s._cbKeydownHandler)})}),this.plugins.forEach((e,t)=>{typeof e.destroy=="function"&&e.destroy(this)}),this.components.clear(),this.plugins.clear()}emit(e,t){if(this.runtime&&typeof this.runtime.emit=="function")this.runtime.emit(e,t);else{const i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}}setRuntime(e){this.runtime=e}}class bn{constructor(e={}){const t={skin:"light",plugins:{},autoLoadPlugins:!0,pluginBaseUrl:"",allowExternalPlugins:!0,trustedDomains:[]};this.settings={...t,...e},this.initialized=!1,this.pluginManager=new mn({plugins:this.settings.plugins,autoLoad:this.settings.autoLoadPlugins,pluginBaseUrl:this.settings.pluginBaseUrl,allowExternalPlugins:this.settings.allowExternalPlugins,trustedDomains:this.settings.trustedDomains}),this.pluginManager.setRuntime(this),window.Glide=Rs,window.FormViewer=gn}async use(e){return await this.pluginManager.use(e)}getPlugin(e){return this.pluginManager.getPlugin(e)}getPlugins(){return this.pluginManager.getAllPlugins()}hasPlugin(e){return this.pluginManager.hasPlugin(e)}getComponent(e){return this.pluginManager.getComponent(e)}getComponents(){return this.pluginManager.components}unmountComponent(e){return this.pluginManager.unmountComponent(e)}async reinitialize(e){const t=await this.pluginManager.reinitialize(e);return this.initCore(),t}async loadExternalPlugin(e,t){return await this.pluginManager.loadExternalPlugin(e,t)}async loadExternalPlugins(e){return await this.pluginManager.loadExternalPlugins(e)}unregisterPlugin(e){return this.pluginManager.unregisterPlugin(e)}emit(e,t){const i=new CustomEvent(`contentbox:${e}`,{detail:t});document.dispatchEvent(i)}on(e,t){document.addEventListener(`contentbox:${e}`,t)}off(e,t){document.removeEventListener(`contentbox:${e}`,t)}init(){this.initialized||(this.initCore(),this.initPlugins(),this.initialized=!0,this.emit("init"))}async initPlugins(){this.settings.autoLoadPlugins&&await this.pluginManager.autoLoadPlugins(),this.pluginManager.initializeComponents()}initCore(){const e={touchNavigation:!0,selector:".glightbox",loop:!0,autoplayVideos:!0,zoomable:!0,slideEffect:"slide",descPosition:"bottom",skin:this.settings.skin};this.refreshLightbox(e),document.querySelectorAll(".is-lightbox,.block-click").forEach(i=>{const s=n=>{if(i.closest('[contenteditable="true"]'))return n.preventDefault(),!1;{let r=i.getAttribute("href")||i.getAttribute("data-modal-url");this.openLightbox(r,i,e),n.preventDefault(),n.stopImmediatePropagation()}};i.addEventListener("click",s),i._lightboxHandler=s})}refreshLightbox(e){this.glightbox&&this.glightbox.destroy(),this.glightbox=new jt(e),window.GLightbox=jt.default}openLightbox(e,t,i){let s=[],n=0;if(t){const o=t.closest("[data-gallery]");let a=[];o?a=o.querySelectorAll(".is-lightbox"):document.querySelectorAll(".is-lightbox,.block-click").forEach(u=>{u.closest("[data-gallery]")||a.push(u)}),a.forEach((d,u)=>{let l=d.getAttribute("href");l||(l=d.getAttribute("data-modal-url")),s.push({href:l}),e===l&&(n=u)})}const r=document.activeElement;r?.blur(),s.length>0?(this.glightbox.setElements(s),this.glightbox.openAt(n)):(this.glightbox.setElements([{href:e}]),this.glightbox.open()),this.glightbox.on("close",()=>{this.refreshLightbox(i),r?.focus()})}destroy(){this.glightbox&&(this.glightbox.destroy(),this.glightbox=null),document.querySelectorAll(".is-lightbox,.block-click").forEach(t=>{t._lightboxHandler&&(t.removeEventListener("click",t._lightboxHandler),delete t._lightboxHandler)}),this.pluginManager.destroy(),this.initialized=!1,this.emit("destroy")}}return bn})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innovastudio/contentbuilder-interactive-runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.30",
|
|
5
5
|
"description": "Runtime libraries for ContentBuilder generated content",
|
|
6
6
|
"main": "dist/contentbuilder-interactive-runtime.esm.js",
|
|
7
7
|
"module": "dist/contentbuilder-interactive-runtime.esm.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@glidejs/glide": "^3.7.1",
|
|
33
|
-
"@innovastudio/formviewer": "^1.0.
|
|
33
|
+
"@innovastudio/formviewer": "^1.0.26",
|
|
34
34
|
"glightbox": "^3.3.1"
|
|
35
35
|
}
|
|
36
36
|
}
|