Skip to content

Commit 1f0949d

Browse files
committed
feat: limited live preview enable for user testing
1 parent 8fab9a4 commit 1f0949d

File tree

4 files changed

+95
-14
lines changed

4 files changed

+95
-14
lines changed

src/LiveDevelopment/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ define(function main(require, exports, module) {
226226
function _setupGoLiveButton() {
227227
if (!_$btnGoLive) {
228228
_$btnGoLive = $("#toolbar-go-live");
229-
_$btnGoLive.click(function onGoLive() {
230-
_handleGoLiveCommand();
231-
});
229+
// Phoenix disable old live preivew
230+
// _$btnGoLive.click(function onGoLive() {
231+
// _handleGoLiveCommand();
232+
// });
232233
}
233234
LiveDevImpl.on("statusChange", function statusChange(event, status, reason) {
234235
// status starts at -1 (error), so add one when looking up name and style

src/extensions/default/Phoenix-live-preview/main.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@
4040
//jshint-ignore:no-start
4141

4242
define(function (require, exports, module) {
43-
44-
45-
var CommandManager = brackets.getModule("command/CommandManager"),
46-
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
43+
let ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
4744
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
48-
AppInit = brackets.getModule("utils/AppInit");
45+
AppInit = brackets.getModule("utils/AppInit"),
46+
ProjectManager = brackets.getModule("project/ProjectManager"),
47+
EditorManager = brackets.getModule("editor/EditorManager"),
48+
utils = require('utils');
4949

5050

5151
// Templates
5252
var panelHTML = require("text!panel.html");
53+
ExtensionUtils.loadStyleSheet(module, "extension-store.css");
5354

5455
// jQuery objects
5556
var $icon,
@@ -79,10 +80,6 @@ define(function (require, exports, module) {
7980
toggleCmd.setChecked(visible);
8081
}
8182

82-
ExtensionUtils.loadStyleSheet(module, "extension-store.css");
83-
// todo: replace with extension manager dialogue command
84-
toggleCmd = CommandManager.register("Extensions Panel", "toggleExtensionsPanel", _toggleVisibility);
85-
8683
function _createExtensionPanel() {
8784
$icon = $("#toolbar-go-live");
8885
$icon.click(_toggleVisibility);
@@ -91,16 +88,23 @@ define(function (require, exports, module) {
9188
$iframe[0].onload = function () {
9289
$iframe.attr('srcdoc', null);
9390
};
94-
$iframe.attr('src', "https://core.ai");
91+
$iframe.attr('src', utils.getPreviewURL());
9592
let minSize = window.innerWidth/3;
9693

9794
panel = WorkspaceManager.createPluginPanel("live-preview-panel", $panel, minSize, $icon);
9895

9996
WorkspaceManager.recomputeLayout(false);
10097
}
10198

99+
function _loadPreview() {
100+
$iframe.attr('src', utils.getPreviewURL());
101+
}
102+
102103
AppInit.appReady(function () {
103104
_createExtensionPanel();
105+
ProjectManager.on(ProjectManager.EVENT_PROJECT_OPEN, _loadPreview);
106+
ProjectManager.on(ProjectManager.EVENT_PROJECT_FILE_CHANGED, _loadPreview);
107+
EditorManager.on("activeEditorChange", _loadPreview);
104108
});
105109
});
106110

src/extensions/default/Phoenix-live-preview/panel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="panel-live-preview">
2-
<div class="plugin-toolbar">Live Preview</div>
2+
<div class="plugin-toolbar">Live Preview (experimental)</div>
33
<div class="frame-container">
44
<div style="width: 3px;"></div>
55
<iframe id="panel-live-preview-frame" title="Extension Store" style="border: none"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Modified Work Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
* Permission is hereby granted, free of charge, to any person obtaining a copy
20+
* of this software and associated documentation files (the "Software"), to deal
21+
* in the Software without restriction, including without limitation the rights
22+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23+
* copies of the Software, and to permit persons to whom the Software is
24+
* furnished to do so, subject to the following conditions:
25+
*
26+
* The above copyright notice and this permission notice shall be included in all
27+
* copies or substantial portions of the Software.
28+
*
29+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
* SOFTWARE.
36+
*/
37+
38+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
39+
/*global define, brackets, fs, Phoenix, path */
40+
//jshint-ignore:no-start
41+
42+
define(function (require, exports, module) {
43+
const ProjectManager = brackets.getModule("project/ProjectManager"),
44+
DocumentManager = brackets.getModule("document/DocumentManager");
45+
46+
function _isPreviewableFile(filePath) {
47+
let pathSplit = filePath.split('.');
48+
let extension = pathSplit && pathSplit.length>1 ? pathSplit[pathSplit.length-1] : null;
49+
if(['html', 'htm', 'jpg', 'jpeg', 'png', 'svg', 'pdf'].includes(extension.toLowerCase())){
50+
return true;
51+
}
52+
return false;
53+
}
54+
55+
function getPreviewURL() {
56+
let projectRootName = ProjectManager.getProjectRoot().fullPath;
57+
let projectRootUrl = `${window.fsServerUrl}${projectRootName}`;
58+
let currentDocument = DocumentManager.getCurrentDocument();
59+
let currentFile = currentDocument? currentDocument.file : ProjectManager.getSelectedItem();
60+
let previewUrl = `${projectRootUrl}index.html`;
61+
if(currentFile){
62+
let fullPath = currentFile.fullPath;
63+
if(_isPreviewableFile(fullPath)){
64+
let projectRoot = ProjectManager.getProjectRoot().fullPath;
65+
let relativePath = path.relative(projectRoot, fullPath);
66+
previewUrl = `${projectRootUrl}${relativePath}`;
67+
}
68+
}
69+
70+
return previewUrl;
71+
}
72+
73+
exports.getPreviewURL = getPreviewURL;
74+
});
75+
76+

0 commit comments

Comments
 (0)