Skip to content

Commit 8268bc1

Browse files
committed
refactor: move css styles for edit boxes to extension
1 parent 451539f commit 8268bc1

File tree

4 files changed

+19
-48
lines changed

4 files changed

+19
-48
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
/*jslint forin: true */
23-
/*global Node, MessageEvent, strings, icons */
23+
/*global Node, MessageEvent, strings, icons, cssStyles */
2424
/*theseus instrument: false */
2525

2626
/**
@@ -1797,10 +1797,10 @@ function RemoteFunctions(config = {}) {
17971797
</span>
17981798
</div>`;
17991799

1800-
let styles = config.styles.optionsBox;
1800+
let styles = cssStyles.optionsBox;
18011801
// to highlight that in a different color, to show the selected state
18021802
if (imageGallerySelected) {
1803-
styles += config.styles.optionsBoxImageGallerySelected;
1803+
styles += cssStyles.optionsBoxImageGallerySelected;
18041804
}
18051805

18061806
// add everything to the shadow box
@@ -1891,7 +1891,7 @@ function RemoteFunctions(config = {}) {
18911891
// Create input HTML + styles
18921892
const html = `
18931893
<style>
1894-
${config.styles.hyperlinkEditor}
1894+
${cssStyles.hyperlinkEditor}
18951895
</style>
18961896
<div class="hyperlink-input-box">
18971897
<div class="link-icon" title="${currentHref.trim() || strings.hyperlinkNoHref}">
@@ -2133,7 +2133,7 @@ function RemoteFunctions(config = {}) {
21332133
</div>
21342134
`;
21352135

2136-
let styles = config.styles.optionsBoxDropdown;
2136+
let styles = cssStyles.optionsBoxDropdown;
21372137
shadow.innerHTML = `<style>${styles}</style><div class="phoenix-dropdown">${content}</div>`;
21382138
this._shadow = shadow;
21392139
},
@@ -2265,7 +2265,7 @@ function RemoteFunctions(config = {}) {
22652265
// add everything to the shadow box with CSS variables for dynamic color
22662266
shadow.innerHTML = `
22672267
<style>
2268-
${config.styles.infoBox}
2268+
${cssStyles.infoBox}
22692269
:host {
22702270
--info-box-bg-color: ${bgColor};
22712271
}
@@ -2388,7 +2388,7 @@ function RemoteFunctions(config = {}) {
23882388

23892389
shadow.innerHTML = `
23902390
<style>
2391-
${config.styles.aiPromptBox}
2391+
${cssStyles.aiPromptBox}
23922392
:host {
23932393
--ai-box-width: ${boxWidth}px;
23942394
--ai-box-height: ${boxHeight}px;
@@ -2607,7 +2607,7 @@ function RemoteFunctions(config = {}) {
26072607

26082608
this._shadow.innerHTML = `
26092609
<style>
2610-
${config.styles.imageGallery}
2610+
${cssStyles.imageGallery}
26112611
</style>
26122612
26132613
<div class='phoenix-image-gallery-container'>
@@ -3321,7 +3321,7 @@ function RemoteFunctions(config = {}) {
33213321
</div>
33223322
</div>`;
33233323

3324-
shadow.innerHTML = `<style>${config.styles.hotCorner}</style>${content}`;
3324+
shadow.innerHTML = `<style>${cssStyles.hotCorner}</style>${content}`;
33253325

33263326
this.element = container;
33273327
this.button = shadow.querySelector(".hot-corner-play-btn");
@@ -3703,7 +3703,7 @@ function RemoteFunctions(config = {}) {
37033703

37043704
shadow.innerHTML = `
37053705
<style>
3706-
${config.styles.ruler}
3706+
${cssStyles.ruler}
37073707
</style>
37083708
${html}
37093709
`;
@@ -3865,7 +3865,7 @@ function RemoteFunctions(config = {}) {
38653865

38663866
// use shadow DOM for style isolation
38673867
const shadow = overlay.attachShadow({ mode: 'open' });
3868-
const styles = config.styles.dialogOverlay;
3868+
const styles = cssStyles.dialogOverlay;
38693869

38703870
const content = `
38713871
<div class="phoenix-dialog-overlay">
@@ -4916,7 +4916,7 @@ function RemoteFunctions(config = {}) {
49164916
toast.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true");
49174917
const shadow = toast.attachShadow({ mode: 'open' });
49184918

4919-
const styles = config.styles.toastMessage;
4919+
const styles = cssStyles.toastMessage;
49204920

49214921
const content = `
49224922
<div class="toast-container">

src/LiveDevelopment/main.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ define(function main(require, exports, module) {
4444
ExtensionUtils = require("utils/ExtensionUtils"),
4545
StringUtils = require("utils/StringUtils"),
4646
EventDispatcher = require("utils/EventDispatcher"),
47-
WorkspaceManager = require("view/WorkspaceManager"),
48-
RemoteHelper = require("LiveDevelopment/RemoteHelper");
47+
WorkspaceManager = require("view/WorkspaceManager");
4948

5049

5150
const KernalModeTrust = window.KernalModeTrust;
@@ -90,8 +89,7 @@ define(function main(require, exports, module) {
9089
mode: _getDefaultMode(), // 'edit', 'highlight', or 'preview' - will be updated when preference loads
9190
elemHighlights: "hover", // default value, this will get updated when the extension loads
9291
showRulerLines: false, // default value, this will get updated when the extension loads
93-
imageGalleryState: _getImageGalleryState(), // image gallery selected state
94-
styles: RemoteHelper.remoteStyles
92+
imageGalleryState: _getImageGalleryState() // image gallery selected state
9593
};
9694

9795
// Status labels/styles are ordered: error, not connected, progress1, progress2, connected.

src/extensionsIntegrated/phoenix-pro/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ define(function (require, exports, module) {
77
require("./LivePreviewEdit");
88
require("./remote-constants");
99
require("./remote-icons");
10+
require("./remote-styles");
1011

1112
const AppInit = require("utils/AppInit"),
1213
Strings = require("strings");

src/LiveDevelopment/RemoteHelper.js renamed to src/extensionsIntegrated/phoenix-pro/remote-styles.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
11
/*
2-
* GNU AGPL-3.0 License
3-
*
42
* 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.
3+
* Proprietary code, all rights reserved.
344
*/
355

366
define(function (require, exports, module) {
7+
const LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol");
378
const optionsBoxStyles = `
389
:host {
3910
all: initial !important;
@@ -1020,5 +991,6 @@ define(function (require, exports, module) {
1020991
hotCorner: hotCornerStyles
1021992
};
1022993

1023-
exports.remoteStyles = remoteStyles;
994+
LiveDevProtocol.addRemoteFunctionConstantsScript("styles",
995+
`const cssStyles = ${JSON.stringify(remoteStyles)};`);
1024996
});

0 commit comments

Comments
 (0)