@myissue/vue-website-page-builder 3.2.92 → 3.2.93

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myissue/vue-website-page-builder",
3
- "version": "v3.2.92",
3
+ "version": "v3.2.93",
4
4
  "description": "Vue 3 page builder component with drag & drop functionality.",
5
5
  "type": "module",
6
6
  "main": "./dist/vue-website-page-builder.umd.cjs",
@@ -17,7 +17,7 @@ const getIsLoadingImage = ref(false)
17
17
  const getSearchTerm = ref('')
18
18
  const getCurrentPageNumber = ref(1)
19
19
  const getOrientationValue = ref('')
20
- const getCurrentImage = ref('')
20
+ const getApplyImageToSelection = ref('')
21
21
  const getCurrentUser = ref('')
22
22
 
23
23
  const getUnsplashImages = ref([])
@@ -72,7 +72,7 @@ const handleImageClick = async function (data) {
72
72
  }
73
73
 
74
74
  await delay(100)
75
- getCurrentImage.value = data.url || ''
75
+ getApplyImageToSelection.value = data.url || ''
76
76
 
77
77
  getIsLoadingImage.value = false
78
78
  }
@@ -100,11 +100,11 @@ const nextPage = async function () {
100
100
 
101
101
  const applySelectedImage = async function (imageURL) {
102
102
  // Ensure the current image is set in the store with proper structure
103
- pageBuilderStateStore.setCurrentImage({
103
+ pageBuilderService.stageImageForSelectedElement({
104
104
  src: `${imageURL}`,
105
105
  })
106
106
 
107
- await pageBuilderService.updateBasePrimaryImage()
107
+ await pageBuilderService.applyPendingImageToSelectedElement()
108
108
 
109
109
  closeMediaLibraryModal()
110
110
  }
@@ -341,10 +341,10 @@ onMounted(async () => {
341
341
  </div>
342
342
  </div>
343
343
  </template>
344
- <template v-if="getCurrentImage && !getIsLoadingImage">
344
+ <template v-if="getApplyImageToSelection && !getIsLoadingImage">
345
345
  <img
346
346
  class="pbx-mx-auto pbx-block pbx-w-full pbx-object-cover pbx-object-center pbx-cursor-pointer"
347
- :src="`${getCurrentImage}`"
347
+ :src="`${getApplyImageToSelection}`"
348
348
  alt="file"
349
349
  />
350
350
  <div class="md:pbx-px-3 pbx-px-2">
@@ -392,8 +392,8 @@ onMounted(async () => {
392
392
  Close
393
393
  </button>
394
394
  <button
395
- v-if="getCurrentImage && typeof getCurrentImage === 'string'"
396
- @click="applySelectedImage(getCurrentImage)"
395
+ v-if="getApplyImageToSelection && typeof getApplyImageToSelection === 'string'"
396
+ @click="applySelectedImage(getApplyImageToSelection)"
397
397
  class="pbx-myPrimaryButton"
398
398
  type="button"
399
399
  >
@@ -24,7 +24,7 @@ export class PageBuilderService {
24
24
  private pageBuilderStateStore: ReturnType<typeof usePageBuilderStateStore>
25
25
  private getTextAreaVueModel: ComputedRef<string | null>
26
26
  private getLocalStorageItemName: ComputedRef<string | null>
27
- private getCurrentImage: ComputedRef<ImageObject>
27
+ private getApplyImageToSelection: ComputedRef<ImageObject>
28
28
  private getHyberlinkEnable: ComputedRef<boolean>
29
29
  private getComponents: ComputedRef<ComponentObject[] | null>
30
30
  private getComponent: ComputedRef<ComponentObject | null>
@@ -49,7 +49,9 @@ export class PageBuilderService {
49
49
  () => this.pageBuilderStateStore.getLocalStorageItemName,
50
50
  )
51
51
 
52
- this.getCurrentImage = computed(() => this.pageBuilderStateStore.getCurrentImage)
52
+ this.getApplyImageToSelection = computed(
53
+ () => this.pageBuilderStateStore.getApplyImageToSelection,
54
+ )
53
55
  this.getHyberlinkEnable = computed(() => this.pageBuilderStateStore.getHyberlinkEnable)
54
56
  this.getComponents = computed(() => this.pageBuilderStateStore.getComponents)
55
57
 
@@ -1366,39 +1368,56 @@ export class PageBuilderService {
1366
1368
 
1367
1369
  return false
1368
1370
  }
1369
- //
1370
- //
1371
- async updateBasePrimaryImage(): Promise<void> {
1371
+
1372
+ /**
1373
+ * Sets the image selected from the media library as the "pending" image
1374
+ * to be applied to the currently selected element in the builder.
1375
+ * This does not update the DOM immediately—call `applyPendingImageToSelectedElement` to commit.
1376
+ * @param image - The image object to be staged for application
1377
+ */
1378
+ stageImageForSelectedElement(image: ImageObject) {
1379
+ this.pageBuilderStateStore.setApplyImageToSelection(image)
1380
+ }
1381
+
1382
+ /**
1383
+ * Applies the staged image (set by `stageImageForSelectedElement`) to the currently selected element.
1384
+ * This updates the builder state and triggers an auto-save.
1385
+ * If no element is selected or no image is staged, nothing happens.
1386
+ */
1387
+ async applyPendingImageToSelectedElement(): Promise<void> {
1372
1388
  if (!this.getElement.value) return
1373
1389
 
1374
- // If no data provided, apply current image if available (new simplified usage)
1375
- if (this.getCurrentImage.value && this.getCurrentImage.value.src) {
1390
+ // Only apply if an image is staged
1391
+ if (this.getApplyImageToSelection.value && this.getApplyImageToSelection.value.src) {
1376
1392
  await this.nextTick
1377
- this.pageBuilderStateStore.setBasePrimaryImage(`${this.getCurrentImage.value.src}`)
1393
+ this.pageBuilderStateStore.setBasePrimaryImage(`${this.getApplyImageToSelection.value.src}`)
1394
+
1378
1395
  await this.handleAutoSave()
1379
1396
  }
1380
1397
  }
1381
1398
 
1382
- setBasePrimaryImageFromCurrent() {
1399
+ /**
1400
+ * Inspects the currently selected element and, if it contains exactly one <img> and no <div>,
1401
+ * sets that image's src as the base primary image in the builder state.
1402
+ * If the element does not meet these criteria, clears the base primary image.
1403
+ */
1404
+ setBasePrimaryImageFromSelectedElement() {
1383
1405
  if (!this.getElement.value) return
1384
1406
 
1385
1407
  const currentImageContainer = document.createElement('div')
1386
-
1387
1408
  currentImageContainer.innerHTML = this.getElement.value.outerHTML
1388
1409
 
1389
1410
  // Get all img and div within the current image container
1390
1411
  const imgElements = currentImageContainer.getElementsByTagName('img')
1391
1412
  const divElements = currentImageContainer.getElementsByTagName('div')
1392
1413
 
1393
- // Check if there is exactly one img and no div
1414
+ // If exactly one img and no div, set as base primary image
1394
1415
  if (imgElements.length === 1 && divElements.length === 0) {
1395
- // Return the source of the only img
1396
-
1397
1416
  this.pageBuilderStateStore.setBasePrimaryImage(imgElements[0].src)
1398
-
1399
1417
  return
1400
1418
  }
1401
1419
 
1420
+ // Otherwise, clear the base primary image
1402
1421
  this.pageBuilderStateStore.setBasePrimaryImage(null)
1403
1422
  }
1404
1423
 
@@ -1818,7 +1837,7 @@ export class PageBuilderService {
1818
1837
  // handle BG opacity
1819
1838
  this.handleBackgroundOpacity(undefined)
1820
1839
  // displayed image
1821
- this.setBasePrimaryImageFromCurrent()
1840
+ this.setBasePrimaryImageFromSelectedElement()
1822
1841
  // border style
1823
1842
  this.handleBorderStyle(undefined)
1824
1843
  // border width
@@ -56,7 +56,7 @@ interface PageBuilderState {
56
56
  configPageBuilder: PageBuilderConfig | null
57
57
 
58
58
  // Media Library State
59
- currentImage: ImageObject
59
+ applyImageToSelection: ImageObject
60
60
  currentPreviewImage: string | null
61
61
 
62
62
  // User State
@@ -117,7 +117,7 @@ export const usePageBuilderStateStore = defineStore('pageBuilderState', {
117
117
  configPageBuilder: null,
118
118
 
119
119
  // Media Library State
120
- currentImage: { src: '' },
120
+ applyImageToSelection: { src: '' },
121
121
  currentPreviewImage: null,
122
122
 
123
123
  // User State
@@ -264,10 +264,10 @@ export const usePageBuilderStateStore = defineStore('pageBuilderState', {
264
264
  return state.configPageBuilder
265
265
  },
266
266
 
267
- // Media Library Getters
268
- getCurrentImage(state: PageBuilderState): ImageObject {
269
- return state.currentImage
267
+ getApplyImageToSelection(state: PageBuilderState): ImageObject {
268
+ return state.applyImageToSelection
270
269
  },
270
+
271
271
  getCurrentPreviewImage(state: PageBuilderState): string | null {
272
272
  return state.currentPreviewImage
273
273
  },
@@ -455,9 +455,8 @@ export const usePageBuilderStateStore = defineStore('pageBuilderState', {
455
455
  this.configPageBuilder = payload
456
456
  },
457
457
 
458
- // Media Library Actions
459
- setCurrentImage(payload: ImageObject): void {
460
- this.currentImage = payload
458
+ setApplyImageToSelection(payload: ImageObject): void {
459
+ this.applyImageToSelection = payload
461
460
  },
462
461
  setCurrentPreviewImage(payload: string | null): void {
463
462
  this.currentPreviewImage = payload
@@ -83,7 +83,7 @@ export interface PageBuilderStateStore {
83
83
  setTextColor: (color: string) => void
84
84
  setBackgroundOpacity: (opacity: string) => void
85
85
  setOpacity: (opacity: string) => void
86
- getCurrentImage: ImageObject | null
86
+ getApplyImageToSelection: ImageObject | null
87
87
  setCurrentImage: (image: ImageObject) => void
88
88
  getCurrentPreviewImage: string | null
89
89
  setCurrentPreviewImage: (url: string | null) => void