Skip to content

Commit a41ac65

Browse files
committed
feat: move image gallery inside more options box
1 parent a29143a commit a41ac65

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ function RemoteFunctions(config = {}) {
252252
_aiPromptBox = new AIPromptBox(element); // create a new one
253253
}
254254

255+
/**
256+
* This function gets called when the image gallery button is clicked
257+
* it shows the image ribbon gallery at the bottom of the live preview
258+
* @param {Event} event
259+
* @param {DOMElement} element - the HTML DOM element that was clicked (should be an image)
260+
*/
261+
function _handleImageGalleryOptionClick(event, element) {
262+
if (!_imageRibbonGallery && shouldShowImageRibbon()) {
263+
_imageRibbonGallery = new ImageRibbonGallery(element);
264+
}
265+
}
266+
255267
/**
256268
* This function gets called when the delete button is clicked
257269
* it sends a message to the editor using postMessage to delete the element from the source code
@@ -339,6 +351,8 @@ function RemoteFunctions(config = {}) {
339351
_handleDeleteOptionClick(e, element);
340352
} else if (action === "ai") {
341353
_handleAIOptionClick(e, element);
354+
} else if (action === "image-gallery") {
355+
_handleImageGalleryOptionClick(e, element);
342356
}
343357
}
344358

@@ -1257,6 +1271,13 @@ function RemoteFunctions(config = {}) {
12571271
<path d="M6 7V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v2h3v2h-2l-1.5 12.5a2 2 0 0
12581272
1-2 1.5H8.5a2 2 0 0 1-2-1.5L5 9H3V7h3zm2 0h8V5H8v2z"/>
12591273
</svg>
1274+
`,
1275+
1276+
imageGallery: `
1277+
<svg viewBox="0 0 24 24" fill="currentColor">
1278+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
1279+
<path d="M1 3v16h2V5h16V3H1z"/>
1280+
</svg>
12601281
`
12611282
};
12621283

@@ -1267,6 +1288,13 @@ function RemoteFunctions(config = {}) {
12671288
${ICONS.ai}
12681289
</span>`;
12691290

1291+
// if its an image element, we show the image gallery icon
1292+
if (this.element && this.element.tagName.toLowerCase() === 'img') {
1293+
content += `<span data-action="image-gallery" title="${config.strings.imageGallery}">
1294+
${ICONS.imageGallery}
1295+
</span>`;
1296+
}
1297+
12701298
// Only include select parent option if element supports it
12711299
if (showSelectParentOption) {
12721300
content += `<span data-action="select-parent" title="${config.strings.selectParent}">
@@ -3464,13 +3492,6 @@ function RemoteFunctions(config = {}) {
34643492
_nodeMoreOptionsBox = null;
34653493
}
34663494

3467-
// if the selected element is an image, show the image ribbon gallery (make sure its enabled in preferences)
3468-
if(element && element.tagName.toLowerCase() === 'img' && shouldShowImageRibbon()) {
3469-
if (!_imageRibbonGallery) {
3470-
_imageRibbonGallery = new ImageRibbonGallery(element);
3471-
}
3472-
}
3473-
34743495
element._originalOutline = element.style.outline;
34753496
element.style.outline = "1px solid #4285F4";
34763497

@@ -4108,6 +4129,7 @@ function RemoteFunctions(config = {}) {
41084129
dismissNodeMoreOptionsBox();
41094130
dismissAIPromptBox();
41104131
dismissNodeInfoBox();
4132+
dismissImageRibbonGallery();
41114133
}
41124134

41134135
/**
@@ -4309,7 +4331,6 @@ function RemoteFunctions(config = {}) {
43094331
"finishEditing" : finishEditing,
43104332
"hasVisibleLivePreviewBoxes" : hasVisibleLivePreviewBoxes,
43114333
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
4312-
"dismissImageRibbonGallery" : dismissImageRibbonGallery,
43134334
"enableHoverListeners" : enableHoverListeners,
43144335
"registerHandlers" : registerHandlers
43154336
};

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,6 @@ define(function (require, exports, module) {
716716
if (_protocol) {
717717
_protocol.evaluate("_LD.enableHoverListeners()"); // so that if hover lock is there it will get cleared
718718
_protocol.evaluate("_LD.dismissUIAndCleanupState()");
719-
_protocol.evaluate("_LD.dismissImageRibbonGallery()");
720-
}
721-
}
722-
723-
/**
724-
* Dismiss image ribbon gallery if it's open
725-
*/
726-
function dismissImageRibbonGallery() {
727-
if (_protocol) {
728-
_protocol.evaluate("_LD.dismissImageRibbonGallery()");
729719
}
730720
}
731721

@@ -815,7 +805,6 @@ define(function (require, exports, module) {
815805
exports.redrawHighlight = redrawHighlight;
816806
exports.hasVisibleLivePreviewBoxes = hasVisibleLivePreviewBoxes;
817807
exports.dismissLivePreviewBoxes = dismissLivePreviewBoxes;
818-
exports.dismissImageRibbonGallery = dismissImageRibbonGallery;
819808
exports.registerHandlers = registerHandlers;
820809
exports.updateConfig = updateConfig;
821810
exports.init = init;

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,10 @@ define(function (require, exports, module) {
693693
_updateImageSrcAttribute(tagId, filename);
694694
}
695695

696-
// dismiss the image ribbon gallery
696+
// dismiss all UI boxes including the image ribbon gallery
697697
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
698698
if (currLiveDoc && currLiveDoc.protocol && currLiveDoc.protocol.evaluate) {
699-
currLiveDoc.protocol.evaluate("_LD.dismissImageRibbonGallery()");
699+
currLiveDoc.protocol.evaluate("_LD.dismissUIAndCleanupState()");
700700
}
701701
}
702702

src/LiveDevelopment/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ define(function main(require, exports, module) {
8080
duplicate: Strings.LIVE_DEV_MORE_OPTIONS_DUPLICATE,
8181
delete: Strings.LIVE_DEV_MORE_OPTIONS_DELETE,
8282
ai: Strings.LIVE_DEV_MORE_OPTIONS_AI,
83+
imageGallery: Strings.LIVE_DEV_MORE_OPTIONS_IMAGE_GALLERY,
8384
aiPromptPlaceholder: Strings.LIVE_DEV_AI_PROMPT_PLACEHOLDER,
8485
imageGalleryUseImage: Strings.LIVE_DEV_IMAGE_GALLERY_USE_IMAGE,
8586
imageGallerySelectFromComputer: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER,
@@ -382,7 +383,7 @@ define(function main(require, exports, module) {
382383
config.imageRibbon = prefValue !== false; // default to true if undefined
383384

384385
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
385-
if (!prefValue) { MultiBrowserLiveDev.dismissImageRibbonGallery(); } // to remove any existing image ribbons
386+
if (!prefValue) { MultiBrowserLiveDev.dismissLivePreviewBoxes(); } // to remove any existing image ribbons and UI boxes
386387

387388
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
388389
MultiBrowserLiveDev.registerHandlers();

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ define({
189189
"LIVE_DEV_MORE_OPTIONS_DUPLICATE": "Duplicate",
190190
"LIVE_DEV_MORE_OPTIONS_DELETE": "Delete",
191191
"LIVE_DEV_MORE_OPTIONS_AI": "Edit with AI",
192+
"LIVE_DEV_MORE_OPTIONS_IMAGE_GALLERY": "Image Gallery",
192193
"LIVE_DEV_IMAGE_GALLERY_USE_IMAGE": "Use this image",
193194
"LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER": "Select image from computer",
194195
"LIVE_DEV_IMAGE_GALLERY_CHOOSE_FOLDER": "Choose download folder",

0 commit comments

Comments
 (0)