Skip to content

Commit c6a5cb8

Browse files
committed
feat: set selected state for image gallery when its clicked
1 parent 452af54 commit c6a5cb8

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function RemoteFunctions(config = {}) {
6060
const AUTO_SCROLL_SPEED = 12; // pixels per scroll
6161
const AUTO_SCROLL_EDGE_SIZE = 0.05; // 5% of viewport height (either top/bottom)
6262

63+
// to track the state as we want to have a selected state for image gallery
64+
let imageGallerySelected = false;
65+
6366
/**
6467
* this function is responsible to auto scroll the live preview when
6568
* dragging an element to the viewport edges
@@ -259,7 +262,12 @@ function RemoteFunctions(config = {}) {
259262
* @param {DOMElement} element - the HTML DOM element that was clicked (should be an image)
260263
*/
261264
function _handleImageGalleryOptionClick(event, element) {
262-
if (!_imageRibbonGallery) {
265+
dismissImageRibbonGallery();
266+
267+
if (imageGallerySelected) {
268+
imageGallerySelected = false;
269+
} else {
270+
imageGallerySelected = true;
263271
_imageRibbonGallery = new ImageRibbonGallery(element);
264272
}
265273
}
@@ -1389,7 +1397,7 @@ function RemoteFunctions(config = {}) {
13891397
</span>
13901398
</div>`;
13911399

1392-
const styles = `
1400+
let styles = `
13931401
:host {
13941402
all: initial !important;
13951403
}
@@ -1440,6 +1448,15 @@ function RemoteFunctions(config = {}) {
14401448
}
14411449
`;
14421450

1451+
// to highlight that in a different color, to show the selected state
1452+
if (imageGallerySelected) {
1453+
styles += `
1454+
.node-options span[data-action="image-gallery"] {
1455+
background-color: rgba(255, 255, 255, 0.25) !important;
1456+
}
1457+
`;
1458+
}
1459+
14431460
// add everything to the shadow box
14441461
shadow.innerHTML = `<style>${styles}</style><div class="phoenix-more-options-box">${content}</div>`;
14451462
this._shadow = shadow;
@@ -2862,6 +2879,8 @@ function RemoteFunctions(config = {}) {
28622879
closeButton.addEventListener('click', (e) => {
28632880
e.stopPropagation();
28642881
this.remove();
2882+
imageGallerySelected = false;
2883+
dismissUIAndCleanupState();
28652884
});
28662885
}
28672886

@@ -3584,6 +3603,12 @@ function RemoteFunctions(config = {}) {
35843603
return false;
35853604
}
35863605

3606+
// if imageGallerySelected is true, show the image gallery directly
3607+
if(element && element.tagName.toLowerCase() === 'img' && imageGallerySelected) {
3608+
if (!_imageRibbonGallery) {
3609+
_imageRibbonGallery = new ImageRibbonGallery(element);
3610+
}
3611+
}
35873612

35883613
// make sure that the element is actually visible to the user
35893614
if (isElementVisible(element)) {

0 commit comments

Comments
 (0)