Skip to content

Commit ae3266c

Browse files
committed
refactor: headers and remote fn import fn wrapping to prevent name collision
1 parent 454ea3c commit ae3266c

File tree

10 files changed

+39
-40
lines changed

10 files changed

+39
-40
lines changed

src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ define(function (require, exports, module) {
7474
this._onActiveEditorChange = this._onActiveEditorChange.bind(this);
7575
this._onCursorActivity = this._onCursorActivity.bind(this);
7676

77+
// we cant use file paths for event registration - paths may have spaces(treated as an event list separator)
7778
this.fileHashForEvents = _simpleHash(this.doc.file.fullPath);
7879
EditorManager.off(`activeEditorChange.LiveDocument-${this.fileHashForEvents}`);
7980
EditorManager.on(`activeEditorChange.LiveDocument-${this.fileHashForEvents}`, this._onActiveEditorChange);

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ define(function (require, exports, module) {
365365
console.error(`Remote function script ${scriptName} already exists. Script wont be added.`);
366366
return false;
367367
}
368+
scriptText = `(()=>{${scriptText}})();`;
368369
remoteFunctionsScripts.set(scriptName, scriptText);
369370
if(!RemoteFunctions.includes("// DONT_STRIP_MINIFY:REPLACE_WITH_ADDED_REMOTE_SCRIPTS")){
370371
throw new Error("RemoteFunctions script is missing the placeholder // REPLACE_WITH_ADDED_REMOTE_SCRIPTS");

src/extensionsIntegrated/phoenix-pro/LivePreviewEdit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
/*

src/extensionsIntegrated/phoenix-pro/browser-context/remote-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
/*global customReturns, enableHoverListeners, dismissUIAndCleanupState, cancelSVGDragIfActive */

src/extensionsIntegrated/phoenix-pro/main.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
define(function (require, exports, module) {
77
require("./LivePreviewEdit");
8-
require("./remote-constants");
9-
require("./remote-icons");
10-
require("./remote-styles");
8+
const remoteConstants = require("./remote-constants");
9+
const remoteIcons = require("./remote-icons");
10+
const remoteStyles = require("./remote-styles");
1111

1212
const KernalModeTrust = window.KernalModeTrust;
1313
if(!KernalModeTrust){
@@ -22,7 +22,6 @@ define(function (require, exports, module) {
2222

2323
const remoteUtilsCode = require("text!./browser-context/remote-utils.js");
2424
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
25-
LiveDevProtocol.addRemoteFunctionScript("remoteUtilsCode", remoteUtilsCode);
2625

2726
// this will later be assigned its correct values once entitlementsManager loads
2827
let isProEditActivated = false;
@@ -55,6 +54,21 @@ define(function (require, exports, module) {
5554
// Escape is mainly to hide boxes if they are visible
5655
WorkspaceManager.addEscapeKeyEventHandler("livePreview", _handleLivePreviewEscapeKey);
5756

57+
function _addRemoteScripts() {
58+
// the ordering here is important
59+
// constants first
60+
LiveDevProtocol.addRemoteFunctionConstantsScript("strings",
61+
`strings = ${JSON.stringify(remoteConstants.remoteStrings)};`);
62+
LiveDevProtocol.addRemoteFunctionConstantsScript("icons",
63+
`icons = ${JSON.stringify(remoteIcons.svgIcons)};`);
64+
LiveDevProtocol.addRemoteFunctionConstantsScript("styles",
65+
`cssStyles = ${JSON.stringify(remoteStyles.cssStyles)};`);
66+
67+
// functions start here
68+
LiveDevProtocol.addRemoteFunctionScript("remoteUtilsCode", remoteUtilsCode);
69+
}
70+
_addRemoteScripts();
71+
5872
AppInit.appReady(function () {
5973
_entitlementsChanged();
6074
KernalModeTrust.EntitlementsManager.on(

src/extensionsIntegrated/phoenix-pro/remote-constants.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
define(function (require, exports, module) {
77
const Strings = require("strings");
8-
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
98

109
// list of all the strings that are used in the remoteFunctions file
1110
// we dont pass in the full strings object as its more data to load in every live preview reload.
12-
const remoteStrings = {
11+
exports.remoteStrings = {
1312
selectParent: Strings.LIVE_DEV_MORE_OPTIONS_SELECT_PARENT,
1413
editText: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_TEXT,
1514
editHyperlink: Strings.LIVE_DEV_MORE_OPTIONS_EDIT_HYPERLINK,
@@ -44,7 +43,4 @@ define(function (require, exports, module) {
4443
toastCopyFirstTime: Strings.LIVE_DEV_COPY_TOAST_MESSAGE,
4544
togglePreviewMode: Strings.LIVE_PREVIEW_MODE_TOGGLE_PREVIEW
4645
};
47-
48-
LiveDevProtocol.addRemoteFunctionConstantsScript("strings",
49-
`strings = ${JSON.stringify(remoteStrings)};`);
5046
});

src/extensionsIntegrated/phoenix-pro/remote-icons.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
define(function (require, exports, module) {
7-
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
87

98
// these are all the icons that are used in the remote functions file
10-
const remoteIcons = {
9+
exports.svgIcons = {
1110
ai: `
1211
<svg x="0px" y="0px" width="100" height="100" viewBox="0,0,256,256">
1312
<g fill="#fffbfb" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal"><g transform="scale(4,4)"><path d="M30.701,41.663l-2.246,5.145c-0.864,1.978 -3.6,1.978 -4.464,0l-2.247,-5.145c-1.999,-4.579 -5.598,-8.224 -10.086,-10.216l-6.183,-2.745c-1.966,-0.873 -1.966,-3.733 0,-4.605l5.99,-2.659c4.604,-2.044 8.267,-5.824 10.232,-10.559l2.276,-5.483c0.844,-2.035 3.656,-2.035 4.5,0l2.276,5.483c1.965,4.735 5.628,8.515 10.232,10.559l5.99,2.659c1.966,0.873 1.966,3.733 0,4.605l-6.183,2.745c-4.489,1.992 -8.088,5.637 -10.087,10.216z"></path><path d="M30.701,41.663l-2.246,5.145c-0.864,1.978 -3.6,1.978 -4.464,0l-2.247,-5.145c-1.999,-4.579 -5.598,-8.224 -10.086,-10.216l-6.183,-2.745c-1.966,-0.873 -1.966,-3.733 0,-4.605l5.99,-2.659c4.604,-2.044 8.267,-5.824 10.232,-10.559l2.276,-5.483c0.844,-2.035 3.656,-2.035 4.5,0l2.276,5.483c1.965,4.735 5.628,8.515 10.232,10.559l5.99,2.659c1.966,0.873 1.966,3.733 0,4.605l-6.183,2.745c-4.489,1.992 -8.088,5.637 -10.087,10.216z"></path><g><path d="M51.578,57.887l-0.632,1.448c-0.462,1.06 -1.93,1.06 -2.393,0l-0.632,-1.448c-1.126,-2.582 -3.155,-4.637 -5.686,-5.762l-1.946,-0.865c-1.052,-0.468 -1.052,-1.998 0,-2.465l1.838,-0.816c2.596,-1.153 4.661,-3.285 5.768,-5.955l0.649,-1.565c0.452,-1.091 1.96,-1.091 2.412,0l0.649,1.565c1.107,2.669 3.172,4.801 5.768,5.955l1.837,0.816c1.053,0.468 1.053,1.998 0,2.465l-1.946,0.865c-2.531,1.125 -4.56,3.18 -5.686,5.762z"></path><path d="M51.578,57.887l-0.632,1.448c-0.462,1.06 -1.93,1.06 -2.393,0l-0.632,-1.448c-1.126,-2.582 -3.155,-4.637 -5.686,-5.762l-1.946,-0.865c-1.052,-0.468 -1.052,-1.998 0,-2.465l1.838,-0.816c2.596,-1.153 4.661,-3.285 5.768,-5.955l0.649,-1.565c0.452,-1.091 1.96,-1.091 2.412,0l0.649,1.565c1.107,2.669 3.172,4.801 5.768,5.955l1.837,0.816c1.053,0.468 1.053,1.998 0,2.465l-1.946,0.865c-2.531,1.125 -4.56,3.18 -5.686,5.762z"></path></g></g></g>
@@ -142,7 +141,4 @@ define(function (require, exports, module) {
142141
<path d="M187.2 100.9C174.8 94.1 159.8 94.4 147.6 101.6C135.4 108.8 128 121.9 128 136L128 504C128 518.1 135.5 531.2 147.6 538.4C159.7 545.6 174.8 545.9 187.2 539.1L523.2 355.1C536 348.1 544 334.6 544 320C544 305.4 536 291.9 523.2 284.9L187.2 100.9z"/>
143142
</svg>`
144143
};
145-
146-
LiveDevProtocol.addRemoteFunctionConstantsScript("icons",
147-
`icons = ${JSON.stringify(remoteIcons)};`);
148144
});

src/extensionsIntegrated/phoenix-pro/remote-styles.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
define(function (require, exports, module) {
7-
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
8-
97
// this is the box that comes up with the tools like select parent, duplicate, delete, etc..
108
const optionsBoxStyles = require("text!./browser-css/options-box.css");
119
// this is the more options dropdown that comes up when clicking the ... icon in the option box.
@@ -29,7 +27,7 @@ define(function (require, exports, module) {
2927
const hotCornerStyles = require("text!./browser-css/hot-corners.css");
3028

3129

32-
const remoteStyles = {
30+
exports.cssStyles = {
3331
optionsBox: optionsBoxStyles,
3432
optionsBoxDropdown: optionsBoxDropdownStyles,
3533
infoBox: infoBoxStyles,
@@ -41,7 +39,4 @@ define(function (require, exports, module) {
4139
ruler: rulerStyles,
4240
hotCorner: hotCornerStyles
4341
};
44-
45-
LiveDevProtocol.addRemoteFunctionConstantsScript("styles",
46-
`cssStyles = ${JSON.stringify(remoteStyles)};`);
4742
});

src/extensionsIntegrated/phoenix-pro/unit-tests/LivePreviewEdit-test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
4-
*/
5-
/*
6-
* Copyright (c) 2021 - present core.ai . All rights reserved.
7-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
84
*/
95

106
/*global describe, beforeAll, afterAll, awaitsFor, it, awaitsForDone, expect, awaits, jsPromise*/

src/extensionsIntegrated/phoenix-pro/unittests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2021 - present core.ai . All rights reserved.
3-
* Proprietary code, all rights reserved.
2+
* Copyright (c) 2021 - present core.ai
3+
* SPDX-License-Identifier: LicenseRef-Proprietary
44
*/
55

66
define(function (require, exports, module) {

0 commit comments

Comments
 (0)