@myissue/vue-website-page-builder 3.2.68 → 3.2.70

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.
package/README.md CHANGED
@@ -303,9 +303,10 @@ let contentFromPageBuilder = "";
303
303
 
304
304
  try {
305
305
  storedComponents = JSON.parse(storedComponents);
306
- contentFromPageBuilder = Array.isArray(storedComponents)
307
- ? storedComponents.map((component) => component.html_code).join("")
308
- : "";
306
+ contentFromPageBuilder = storedComponents && Array.isArray(storedComponents.components)
307
+ ? storedComponents.components
308
+ .map((component) => component.html_code).join("")
309
+ : "";
309
310
  } catch (e) {
310
311
  console.error(
311
312
  "Unable to parse storedComponents from localStorage:",
@@ -318,7 +319,7 @@ try {
318
319
  <script>
319
320
  ```
320
321
 
321
- #### Clearing the Draft After Successful Creation
322
+ #### Resetting the Builder After Successful Resource Creation
322
323
 
323
324
  After you have successfully created a new resource (such as a post, article, or listing) using the Page Builder with formType: 'create', it is important to clear the builder’s draft state and remove the corresponding local storage entry. This ensures that old drafts do not appear the next time the builder is opened for a new resource.
324
325
 
@@ -347,8 +348,45 @@ const configPageBuilder = {
347
348
 
348
349
  pageBuilderClass.setConfigPageBuilder(configPageBuilder);
349
350
 
351
+ const createResource = async function(){
350
352
  pageBuilderClass.deleteAllComponents();
351
- await pageBuilderClass.removeItemComponentsLocalStorageCreate();
353
+ await pageBuilderClass.removeItemComponentsLocalStorage();
354
+ };
355
+ <script>
356
+ ```
357
+
358
+ #### Resetting the Builder After Successful Resource Update
359
+
360
+ After you have successfully updated an existing resource (such as a post, article, or listing) using the Page Builder with formType: 'update', you should clear the builder’s state and remove the corresponding local storage entry. This prevents outdated drafts from being loaded the next time you edit the same resource.
361
+
362
+ ```js
363
+ <script setup>
364
+ import {
365
+ PageBuilder,
366
+ PageBuilderClass,
367
+ sharedPageBuilderStore,
368
+ } from "@myissue/vue-website-page-builder";
369
+ import "@myissue/vue-website-page-builder/style.css";
370
+
371
+ // Make sure to initialize these before using
372
+ const pageBuilderStateStore = sharedPageBuilderStore;
373
+ const pageBuilderClass = new PageBuilderClass(pageBuilderStateStore);
374
+
375
+
376
+ const configPageBuilder = {
377
+ updateOrCreate: {
378
+ formType: 'update',
379
+ formName: 'article',
380
+ },
381
+ };
382
+
383
+ pageBuilderClass.setConfigPageBuilder(configPageBuilder);
384
+
385
+ const updateResource = async function() {
386
+ pageBuilderClass.deleteAllComponents();
387
+ await pageBuilderClass.removeItemComponentsLocalStorage();
388
+ };
389
+
352
390
  <script>
353
391
  ```
354
392
 
@@ -1160,13 +1160,28 @@ class Se {
1160
1160
  const t = e.querySelector("[hovered]");
1161
1161
  t && t.removeAttribute("hovered");
1162
1162
  const o = [];
1163
- e.querySelectorAll("section[data-componentid]").forEach((n) => {
1163
+ if (e.querySelectorAll("section[data-componentid]").forEach((n) => {
1164
1164
  o.push({
1165
1165
  html_code: n.outerHTML,
1166
1166
  id: n.getAttribute("data-componentid"),
1167
1167
  title: n.getAttribute("title") || n.getAttribute("data-componentid") || "Untitled Component"
1168
1168
  });
1169
- }), this.getLocalStorageItemName.value && localStorage.setItem(this.getLocalStorageItemName.value, JSON.stringify(o)), await new Promise((n) => n());
1169
+ }), this.pageBuilderStateStore.getConfigPageBuilder && this.pageBuilderStateStore.getConfigPageBuilder.updateOrCreate && typeof this.pageBuilderStateStore.getConfigPageBuilder.updateOrCreate.formType == "string" && this.pageBuilderStateStore.getConfigPageBuilder.updateOrCreate.formType === "update") {
1170
+ const n = {
1171
+ components: o,
1172
+ savedAt: (/* @__PURE__ */ new Date()).toISOString()
1173
+ };
1174
+ localStorage.setItem(this.getLocalStorageItemName.value, JSON.stringify(n));
1175
+ return;
1176
+ }
1177
+ if (this.getLocalStorageItemName.value) {
1178
+ const n = {
1179
+ components: o,
1180
+ savedAt: (/* @__PURE__ */ new Date()).toISOString()
1181
+ };
1182
+ localStorage.setItem(this.getLocalStorageItemName.value, JSON.stringify(n));
1183
+ }
1184
+ await new Promise((n) => n());
1170
1185
  });
1171
1186
  this.nextTick = Ve(), this.containsPagebuilder = document.querySelector("#contains-pagebuilder"), this.pageBuilderStateStore = e, this.getTextAreaVueModel = $(() => this.pageBuilderStateStore.getTextAreaVueModel), this.getLocalStorageItemName = $(
1172
1187
  () => this.pageBuilderStateStore.getLocalStorageItemName
@@ -1478,11 +1493,11 @@ class Se {
1478
1493
  async saveComponentsLocalStorage() {
1479
1494
  await this.nextTick, await Go(this, Os).call(this);
1480
1495
  }
1481
- async removeItemComponentsLocalStorageCreate() {
1496
+ async removeItemComponentsLocalStorage() {
1482
1497
  await this.nextTick, this.getLocalStorageItemName.value && localStorage.removeItem(this.getLocalStorageItemName.value);
1483
1498
  }
1484
- async removeItemComponentsLocalStorageUpdate() {
1485
- this.getLocalStorageItemName.value && localStorage.removeItem(this.getLocalStorageItemName.value);
1499
+ getStorageItemNameForResource() {
1500
+ return this.getLocalStorageItemName.value;
1486
1501
  }
1487
1502
  areComponentsStoredInLocalStorage() {
1488
1503
  if (!this.getLocalStorageItemName.value) return !1;
@@ -23000,7 +23015,7 @@ const k3 = ["src"], S3 = {
23000
23015
  }, Xk = { class: "overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg" }, Zk = { class: "overflow-x-auto" }, e6 = { class: "w-max" }, t6 = { class: "bg-white divide-y divide-gray-200" }, r6 = { class: "px-6 py-4 whitespace-nowrap text-sm text-gray-500" }, o6 = { class: "min-w-[30rem] w-max" }, n6 = { key: 0 }, i6 = { key: 1 }, s6 = { key: 0 }, a6 = { class: "px-6 py-4 whitespace-nowrap text-sm text-gray-500" }, l6 = { class: "min-w-[30rem] w-max" }, d6 = { class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium" }, c6 = { class: "mt-4 mb-4 py-8 border-b border-myPrimbryLightGrayColor" }, p6 = { class: "mt-4 whitespace-pre-wrap text-white overflow-hidden bg-gray-900" }, u6 = { class: "px-4 pb-8 pt-4 text-white text-xs break-all" }, m6 = { class: "myPrimaryParagraph text-xs text-white" }, h6 = {
23001
23016
  __name: "PageBuilderSettings",
23002
23017
  setup(r) {
23003
- const e = "v3.2.68", t = be;
23018
+ const e = "v3.2.70", t = be;
23004
23019
  new Se(t);
23005
23020
  const o = O(null), n = $(() => t.getConfigPageBuilder), i = $(() => t.getComponents), s = function(l, d) {
23006
23021
  const c = document.createElement("a");
@@ -23620,7 +23635,7 @@ const k3 = ["src"], S3 = {
23620
23635
  n.value = !0, i.value = "delete", s.value = 2, a.value = "Remove all Components", l.value = "Are you sure you want to remove all Components?", d.value = "Close", c.value = null, p.value = "Delete", m.value = function() {
23621
23636
  n.value = !1;
23622
23637
  }, g.value = async function() {
23623
- o.deleteAllComponents(), await o.clearHtmlSelection(), t.value.updateOrCreate && typeof t.value.updateOrCreate.formType == "string" && (t.value.updateOrCreate.formType === "create" && await o.removeItemComponentsLocalStorageCreate(), t.value.updateOrCreate.formType === "update" && await o.removeItemComponentsLocalStorageUpdate()), n.value = !1;
23638
+ o.deleteAllComponents(), await o.clearHtmlSelection(), t.value.updateOrCreate && typeof t.value.updateOrCreate.formType == "string" && (t.value.updateOrCreate.formType === "create" && await o.removeItemComponentsLocalStorage(), t.value.updateOrCreate.formType === "update" && await o.removeItemComponentsLocalStorage()), n.value = !1;
23624
23639
  };
23625
23640
  }, b = O(!1), w = function() {
23626
23641
  b.value = !1;