Skip to content

Commit b34b701

Browse files
committed
feat: show first time copy cut toast message
1 parent b97dfe4 commit b34b701

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5269,8 +5269,9 @@ function RemoteFunctions(config = {}) {
52695269
* this function is to show a toast notification at the bottom center of the screen
52705270
* this toast message is used when user tries to edit a non-editable element
52715271
* @param {String} message - the message to display in the toast
5272+
* @param {Number} duration - optional duration in milliseconds (default: 3000)
52725273
*/
5273-
function showToastMessage(message) {
5274+
function showToastMessage(message, duration = 3000) {
52745275
// clear any existing toast & timer, if there are any
52755276
dismissToastMessage();
52765277

@@ -5326,13 +5327,13 @@ function RemoteFunctions(config = {}) {
53265327
shadow.innerHTML = `<style>${styles}</style>${content}`;
53275328
window.document.body.appendChild(toast);
53285329

5329-
// Auto-dismiss after 3 seconds
5330+
// Auto-dismiss after the given time
53305331
_toastTimeout = setTimeout(() => {
53315332
if (toast && toast.parentNode) {
53325333
toast.remove();
53335334
}
53345335
_toastTimeout = null;
5335-
}, 3000);
5336+
}, duration);
53365337
}
53375338

53385339
/**
@@ -5600,6 +5601,7 @@ function RemoteFunctions(config = {}) {
56005601
"resetState" : resetState,
56015602
"enableHoverListeners" : enableHoverListeners,
56025603
"registerHandlers" : registerHandlers,
5603-
"handleDownloadEvent" : handleDownloadEvent
5604+
"handleDownloadEvent" : handleDownloadEvent,
5605+
"showToastMessage" : showToastMessage
56045606
};
56055607
}

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ define(function (require, exports, module) {
4747
const IMAGE_DOWNLOAD_FOLDER_KEY = "imageGallery.downloadFolder";
4848
const IMAGE_DOWNLOAD_PERSIST_FOLDER_KEY = "imageGallery.persistFolder";
4949

50+
// state manager key for tracking if copy/cut toast has been shown
51+
const COPY_CUT_TOAST_SHOWN_KEY = "livePreviewEdit.copyToastShown";
52+
5053
const DOWNLOAD_EVENTS = {
5154
DIALOG_OPENED: 'dialogOpened',
5255
DIALOG_CLOSED: 'dialogClosed',
@@ -339,6 +342,7 @@ define(function (require, exports, module) {
339342
const text = editor.getTextBetween(startPos, endPos);
340343

341344
Phoenix.app.copyToClipboard(text);
345+
_showCopyToastIfNeeded();
342346

343347
// delete the elements source code
344348
editor.document.batchOperation(function () {
@@ -368,6 +372,7 @@ define(function (require, exports, module) {
368372
const text = editor.getTextBetween(startPos, endPos);
369373

370374
Phoenix.app.copyToClipboard(text);
375+
_showCopyToastIfNeeded();
371376
}
372377

373378
/**
@@ -799,6 +804,19 @@ define(function (require, exports, module) {
799804
}
800805
}
801806

807+
function _showCopyToastIfNeeded() {
808+
const hasShownToast = StateManager.get(COPY_CUT_TOAST_SHOWN_KEY);
809+
if (!hasShownToast) {
810+
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
811+
if (currLiveDoc && currLiveDoc.protocol && currLiveDoc.protocol.evaluate) {
812+
const message = Strings.LIVE_DEV_COPY_TOAST_MESSAGE;
813+
const evalString = `_LD.showToastMessage(${JSON.stringify(message)}, 6000)`;
814+
currLiveDoc.protocol.evaluate(evalString);
815+
StateManager.set(COPY_CUT_TOAST_SHOWN_KEY, true);
816+
}
817+
}
818+
}
819+
802820
function _trackDownload(downloadLocation) {
803821
if (!downloadLocation) {
804822
return;

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ define({
208208
"LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER": "Select from device",
209209
"LIVE_DEV_IMAGE_GALLERY_DIALOG_OVERLAY_MESSAGE": "Select image download location in the editor to continue",
210210
"LIVE_DEV_TOAST_NOT_EDITABLE": "Element not editable - generated by script.",
211+
"LIVE_DEV_COPY_TOAST_MESSAGE": "Element copied! Click 'Paste' on any element to insert it above.",
211212
"LIVE_DEV_IMAGE_FOLDER_DIALOG_TITLE": "Select Folder to Save Image",
212213
"LIVE_DEV_IMAGE_FOLDER_DIALOG_DESCRIPTION": "Choose where to download the image:",
213214
"LIVE_DEV_IMAGE_FOLDER_DIALOG_PLACEHOLDER": "Type folder path (e.g., assets/images/)",

0 commit comments

Comments
 (0)