Skip to content

Commit da85a5b

Browse files
committed
refactor: move all the strings used in remote functions to its helper file
1 parent 3b03b41 commit da85a5b

File tree

4 files changed

+86
-36
lines changed

4 files changed

+86
-36
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,7 +4688,7 @@ function RemoteFunctions(config = {}) {
46884688
// if element is not editable and user clicks on it, then we show a toast notification saying
46894689
// that this element is not editable
46904690
if (!element.hasAttribute("data-brackets-id")) {
4691-
showToastMessage(config.strings.toastNotEditable);
4691+
showToastMessage("notEditable");
46924692
}
46934693

46944694
// make sure that the element is actually visible to the user
@@ -5514,13 +5514,18 @@ function RemoteFunctions(config = {}) {
55145514

55155515
let _toastTimeout = null;
55165516

5517+
const TOAST_TYPE_MAPPING = {
5518+
notEditable: config.strings.toastNotEditable,
5519+
copyFirstTime: config.strings.toastCopyFirstTime
5520+
};
5521+
55175522
/**
55185523
* this function is to show a toast notification at the bottom center of the screen
55195524
* this toast message is used when user tries to edit a non-editable element
5520-
* @param {String} message - the message to display in the toast
5525+
* @param {String} toastType - toastType determines the message to display in the toast
55215526
* @param {Number} duration - optional duration in milliseconds (default: 3000)
55225527
*/
5523-
function showToastMessage(message, duration = 3000) {
5528+
function showToastMessage(toastType, duration = 3000) {
55245529
// clear any existing toast & timer, if there are any
55255530
dismissToastMessage();
55265531

@@ -5569,7 +5574,7 @@ function RemoteFunctions(config = {}) {
55695574

55705575
const content = `
55715576
<div class="toast-container">
5572-
<div class="toast-message">${message}</div>
5577+
<div class="toast-message">${TOAST_TYPE_MAPPING[toastType]}</div>
55735578
</div>
55745579
`;
55755580

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,7 @@ define(function (require, exports, module) {
849849
if (!hasShownToast) {
850850
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
851851
if (currLiveDoc && currLiveDoc.protocol && currLiveDoc.protocol.evaluate) {
852-
const message = Strings.LIVE_DEV_COPY_TOAST_MESSAGE;
853-
const evalString = `_LD.showToastMessage(${JSON.stringify(message)}, 6000)`;
852+
const evalString = `_LD.showToastMessage('copyFirstTime', 6000)`;
854853
currLiveDoc.protocol.evaluate(evalString);
855854
StateManager.set(COPY_CUT_TOAST_SHOWN_KEY, true);
856855
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
/*
23+
* This is a helper file for LiveDevelopment/BrowserScripts/RemoteFunctions.js
24+
* since that file runs in the browser context, it doesn't have access to the phoenix editor,
25+
* so this file stores all the data that the remoteFunctions require.
26+
*
27+
* Everything from this file will be exported. and this file is loaded by LiveDevelopment/main.js which then
28+
* passes everything to RemoteFunctions via the config object.
29+
* Read `LiveDevelopment/main.js` for more details
30+
*
31+
* NOTE: this file cannot pass anything directly to RemoteFunctions. Everything has to go through:
32+
* `LiveDevelopment/main.js`.
33+
* This file is only present so that we can keep RemoteFunctions logic clean and keep its code concise.
34+
*/
35+
36+
define(function (require, exports, module) {
37+
const Strings = require('strings');
38+
39+
// list of all the strings that are used in the remoteFunctions file
40+
const remoteStrings = {
41+
selectParent: Strings.LIVE_DEV_MORE_OPTIONS_SELECT_PARENT,
42+
editText: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_TEXT,
43+
editHyperlink: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_HYPERLINK,
44+
hyperlinkNoHref: Strings.LIVE_DEV_HYPERLINK_NO_HREF,
45+
duplicate: Strings.LIVE_DEV_MORE_OPTIONS_DUPLICATE,
46+
delete: Strings.LIVE_DEV_MORE_OPTIONS_DELETE,
47+
ai: Strings.LIVE_DEV_MORE_OPTIONS_AI,
48+
imageGallery: Strings.LIVE_DEV_MORE_OPTIONS_IMAGE_GALLERY,
49+
moreOptions: Strings.LIVE_DEV_MORE_OPTIONS_MORE,
50+
cut: Strings.LIVE_DEV_MORE_OPTIONS_CUT,
51+
copy: Strings.LIVE_DEV_MORE_OPTIONS_COPY,
52+
paste: Strings.LIVE_DEV_MORE_OPTIONS_PASTE,
53+
showRulerLines: Strings.LIVE_PREVIEW_SHOW_RULER_LINES,
54+
aiPromptPlaceholder: Strings.LIVE_DEV_AI_PROMPT_PLACEHOLDER,
55+
imageGalleryUseImage: Strings.LIVE_DEV_IMAGE_GALLERY_USE_IMAGE,
56+
imageGallerySelectDownloadFolder: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_DOWNLOAD_FOLDER,
57+
imageGallerySearchPlaceholder: Strings.LIVE_DEV_IMAGE_GALLERY_SEARCH_PLACEHOLDER,
58+
imageGallerySearchButton: Strings.LIVE_DEV_IMAGE_GALLERY_SEARCH_BUTTON,
59+
imageGalleryLoadingInitial: Strings.LIVE_DEV_IMAGE_GALLERY_LOADING_INITIAL,
60+
imageGalleryLoadingMore: Strings.LIVE_DEV_IMAGE_GALLERY_LOADING_MORE,
61+
imageGalleryNoImages: Strings.LIVE_DEV_IMAGE_GALLERY_NO_IMAGES,
62+
imageGalleryLoadError: Strings.LIVE_DEV_IMAGE_GALLERY_LOAD_ERROR,
63+
imageGalleryClose: Strings.LIVE_DEV_IMAGE_GALLERY_CLOSE,
64+
imageGallerySelectFromComputer: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER,
65+
imageGallerySelectFromComputerTooltip: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER_TOOLTIP,
66+
imageGalleryDialogOverlayMessage: Strings.LIVE_DEV_IMAGE_GALLERY_DIALOG_OVERLAY_MESSAGE,
67+
toastNotEditable: Strings.LIVE_DEV_TOAST_NOT_EDITABLE,
68+
toastCopyFirstTime: Strings.LIVE_DEV_COPY_TOAST_MESSAGE
69+
};
70+
71+
exports.remoteStrings = remoteStrings;
72+
});
73+

src/LiveDevelopment/main.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ define(function main(require, exports, module) {
4545
StringUtils = require("utils/StringUtils"),
4646
EventDispatcher = require("utils/EventDispatcher"),
4747
WorkspaceManager = require("view/WorkspaceManager"),
48-
EditorManager = require("editor/EditorManager");
48+
RemoteHelper = require("LiveDevelopment/RemoteHelper");
4949

5050

5151
const KernalModeTrust = window.KernalModeTrust;
@@ -94,36 +94,9 @@ define(function main(require, exports, module) {
9494
// this strings are used in RemoteFunctions.js
9595
// we need to pass this through config as remoteFunctions runs in browser context and cannot
9696
// directly reference Strings file
97-
strings: {
98-
selectParent: Strings.LIVE_DEV_MORE_OPTIONS_SELECT_PARENT,
99-
editText: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_TEXT,
100-
editHyperlink: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_HYPERLINK,
101-
hyperlinkNoHref: Strings.LIVE_DEV_HYPERLINK_NO_HREF,
102-
duplicate: Strings.LIVE_DEV_MORE_OPTIONS_DUPLICATE,
103-
delete: Strings.LIVE_DEV_MORE_OPTIONS_DELETE,
104-
ai: Strings.LIVE_DEV_MORE_OPTIONS_AI,
105-
imageGallery: Strings.LIVE_DEV_MORE_OPTIONS_IMAGE_GALLERY,
106-
moreOptions: Strings.LIVE_DEV_MORE_OPTIONS_MORE,
107-
cut: Strings.LIVE_DEV_MORE_OPTIONS_CUT,
108-
copy: Strings.LIVE_DEV_MORE_OPTIONS_COPY,
109-
paste: Strings.LIVE_DEV_MORE_OPTIONS_PASTE,
110-
showRulerLines: Strings.LIVE_PREVIEW_SHOW_RULER_LINES,
111-
aiPromptPlaceholder: Strings.LIVE_DEV_AI_PROMPT_PLACEHOLDER,
112-
imageGalleryUseImage: Strings.LIVE_DEV_IMAGE_GALLERY_USE_IMAGE,
113-
imageGallerySelectDownloadFolder: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_DOWNLOAD_FOLDER,
114-
imageGallerySearchPlaceholder: Strings.LIVE_DEV_IMAGE_GALLERY_SEARCH_PLACEHOLDER,
115-
imageGallerySearchButton: Strings.LIVE_DEV_IMAGE_GALLERY_SEARCH_BUTTON,
116-
imageGalleryLoadingInitial: Strings.LIVE_DEV_IMAGE_GALLERY_LOADING_INITIAL,
117-
imageGalleryLoadingMore: Strings.LIVE_DEV_IMAGE_GALLERY_LOADING_MORE,
118-
imageGalleryNoImages: Strings.LIVE_DEV_IMAGE_GALLERY_NO_IMAGES,
119-
imageGalleryLoadError: Strings.LIVE_DEV_IMAGE_GALLERY_LOAD_ERROR,
120-
imageGalleryClose: Strings.LIVE_DEV_IMAGE_GALLERY_CLOSE,
121-
imageGallerySelectFromComputer: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER,
122-
imageGallerySelectFromComputerTooltip: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_FROM_COMPUTER_TOOLTIP,
123-
imageGalleryDialogOverlayMessage: Strings.LIVE_DEV_IMAGE_GALLERY_DIALOG_OVERLAY_MESSAGE,
124-
toastNotEditable: Strings.LIVE_DEV_TOAST_NOT_EDITABLE
125-
}
97+
strings: RemoteHelper.remoteStrings
12698
};
99+
127100
// Status labels/styles are ordered: error, not connected, progress1, progress2, connected.
128101
var _status,
129102
_allStatusStyles = ["warning", "info", "success", "out-of-sync", "sync-error"].join(" ");

0 commit comments

Comments
 (0)