Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbar revival #331

Merged
merged 41 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2f8c5b7
start splitting toolbar core and ui
dmail Dec 6, 2022
e3c6bd0
update toolbar imports and exports
dmail Dec 6, 2022
f5ea8aa
fix toolbar urls
dmail Dec 6, 2022
a68bcb7
reorg some files
dmail Dec 6, 2022
cf1fb54
use flexbox, split css
dmail Dec 6, 2022
87c9b0d
reorg toolbar notification
dmail Dec 6, 2022
51b167f
organizing files
dmail Dec 6, 2022
1f92175
reorg files
dmail Dec 6, 2022
e5b0e3c
rework overflow menu
dmail Dec 6, 2022
7a2b913
renaming into toolbar settings
dmail Dec 6, 2022
12c8c88
update case for remaing classes
dmail Dec 6, 2022
e119fa0
prepare testing toolbar
dmail Dec 6, 2022
328dbf2
testing jsenv toolbar
dmail Dec 6, 2022
419916f
fix errors, adjust tooltips
dmail Dec 6, 2022
e5ccd3f
use preact signals to manage state
dmail Dec 6, 2022
ee5476d
use preact signals
dmail Dec 6, 2022
e1cec67
update some code
dmail Dec 6, 2022
6d05ac0
use iframe.name to pass params
dmail Dec 7, 2022
def515a
introduce logs
dmail Dec 7, 2022
ad14457
fix animations and ensure settings stays visible when toolbar is togg…
dmail Dec 7, 2022
fcfc689
rebuild jsenv toolbar dist
dmail Dec 7, 2022
6f00df9
connect server indicator to the websocket
dmail Dec 8, 2022
5297da2
working on tooltip
dmail Dec 8, 2022
2302312
start prefering signal for execution too
dmail Dec 8, 2022
a638b7f
put more things into signals
dmail Dec 8, 2022
d8189df
use settings signal to update toolbar overlay
dmail Dec 8, 2022
c066151
properly handle server connection from toolbar
dmail Dec 8, 2022
bd1ef78
connect autoreload setting to parent window reloader
dmail Dec 8, 2022
ee98f70
restore the changes indicator section
dmail Dec 8, 2022
ee5180f
rebuild jsenv toolbar
dmail Dec 8, 2022
1be4a62
forward toolbar params with url, add .toolbar_control, add window.__r…
dmail Dec 8, 2022
0e2614a
test and fix changes while autoreload is disabed
dmail Dec 8, 2022
e46c0a5
remove unused file + rebuild jsenv toolbar
dmail Dec 8, 2022
368818d
0.1.0 for jsenv toolbar
dmail Dec 8, 2022
921879c
fix autoreload test failure
dmail Dec 8, 2022
87017aa
fix reloading on client main file
dmail Dec 8, 2022
7038649
fix autoreload removing syntax error
dmail Dec 8, 2022
f87b665
fix toolbar search params handling
dmail Dec 9, 2022
28fbe70
update node version in readme
dmail Dec 9, 2022
88cb986
add autoreload to jsenv toolbar params
dmail Dec 13, 2022
a034786
publish 29.9.1
dmail Dec 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ https://github.com/jsenv/jsenv-core/wiki
npm install --save-dev @jsenv/core
```

_@jsenv/core_ is tested on Mac, Windows, Linux with Node.js 18.12.1.
_@jsenv/core_ is tested on Mac, Windows, Linux with Node.js 18.
Other operating systems and Node.js versions are not tested.

# Name
Expand Down
7 changes: 4 additions & 3 deletions dist/html/explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
padding-top: 25px;
padding-left: 25px;
padding-right: 25px;
position: relative;
}

#explorables_header_bottom_spacing {
Expand Down Expand Up @@ -177,7 +178,7 @@
fill: #24b1b0;
}

#fileIconSvgConfig {
#explorables_icon {
width: 25px;
height: 25px;
stroke: none;
Expand Down Expand Up @@ -285,8 +286,8 @@ <h2>
<section id="explorables">
<div id="explorables-header">
<div id="explorables_header_and_menu">
<h2 style="white-space: nowrap">
<svg id="fileIconSvgConfig" viewBox="0 0 24 24" width="32" height="32">
<h2>
<svg id="explorables_icon" viewBox="0 0 24 24" width="32" height="32">
<path d="M0 0h24v24H0V0z" fill="none"></path>
<path d="M8 16h8v2H8zm0-4h8v2H8zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z"></path>
</svg>
Expand Down
96 changes: 58 additions & 38 deletions dist/js/autoreload.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { urlHotMetas } from "./import_meta_hot.js";
import { parseSrcSet, stringifySrcSet } from "@jsenv/ast/src/html/html_src_set.js";

const isAutoreloadEnabled = () => {
const value = window.localStorage.getItem("autoreload");
if (value === "0") {
return false;
}
return true;
};
const setAutoreloadPreference = value => {
window.localStorage.setItem("autoreload", value ? "1" : "0");
};

const compareTwoUrlPaths = (url, otherUrl) => {
if (url === otherUrl) {
return true;
}
const urlObject = new URL(url);
const otherUrlObject = new URL(otherUrl);
return urlObject.origin === otherUrlObject.origin && urlObject.pathname === otherUrlObject.pathname;
if (urlObject.origin !== otherUrlObject.origin) {
return false;
}
if (urlObject.pathname !== otherUrlObject.pathname) {
return false;
}
return true;
};
const injectQuery = (url, query) => {
const urlObject = new URL(url);
Expand Down Expand Up @@ -157,44 +152,68 @@ const reloadJsImport = async url => {

const reloader = {
urlHotMetas,
isAutoreloadEnabled,
setAutoreloadPreference,
status: "idle",
currentExecution: null,
onstatuschange: () => {},
setStatus: status => {
reloader.status = status;
reloader.onstatuschange();
status: {
value: "idle",
onchange: () => {},
goTo: value => {
reloader.status.value = value;
reloader.status.onchange();
}
},
messages: [],
addMessage: reloadMessage => {
reloader.messages.push(reloadMessage);
if (isAutoreloadEnabled()) {
reloader.reload();
} else {
reloader.setStatus("can_reload");
autoreload: {
enabled: ["1", null].includes(window.localStorage.getItem("autoreload")),
onchange: () => {},
enable: () => {
reloader.autoreload.enabled = true;
window.localStorage.setItem("autoreload", "1");
reloader.autoreload.onchange();
},
disable: () => {
reloader.autoreload.enabled = false;
window.localStorage.setItem("autoreload", "0");
reloader.autoreload.onchange();
}
},
changes: {
value: [],
onchange: () => {},
add: reloadMessage => {
reloader.changes.value.push(reloadMessage);
reloader.changes.onchange();
if (reloader.autoreload.enabled) {
reloader.reload();
} else {
reloader.status.goTo("can_reload");
}
},
remove: reloadMessage => {
const index = reloader.changes.value.indexOf(reloadMessage);
if (index > -1) {
reloader.changes.value.splice(index, 1);
if (reloader.changes.value.length === 0) {
reloader.status.goTo("idle");
}
reloader.changes.onchange();
}
}
},
currentExecution: null,
reload: () => {
const someEffectIsFullReload = reloader.messages.some(reloadMessage => reloadMessage.type === "full");
const someEffectIsFullReload = reloader.changes.value.some(reloadMessage => reloadMessage.type === "full");
if (someEffectIsFullReload) {
reloadHtmlPage();
return;
}
reloader.setStatus("reloading");
reloader.status.goTo("reloading");
const onApplied = reloadMessage => {
const index = reloader.messages.indexOf(reloadMessage);
reloader.messages.splice(index, 1);
if (reloader.messages.length === 0) {
reloader.setStatus("idle");
}
reloader.changes.remove(reloadMessage);
};
const setReloadMessagePromise = (reloadMessage, promise) => {
promise.then(() => {
onApplied(reloadMessage);
reloader.currentExecution = null;
}, e => {
reloader.setStatus("failed");
reloader.status.goTo("failed");
if (typeof window.reportError === "function") {
window.reportError(e);
} else {
Expand All @@ -205,7 +224,7 @@ This could be due to syntax errors or importing non-existent modules (see errors
reloader.currentExecution = null;
});
};
reloader.messages.forEach(reloadMessage => {
reloader.changes.value.forEach(reloadMessage => {
if (reloadMessage.type === "hot") {
const promise = addToHotQueue(() => {
return applyHotReload(reloadMessage);
Expand Down Expand Up @@ -297,7 +316,8 @@ const applyHotReload = async ({
return namespace;
}
if (type === "html") {
if (!compareTwoUrlPaths(urlToFetch, window.location.href)) {
const isRootHtmlFile = window.location.pathname === "/" && new URL(urlToFetch).pathname.slice(1).indexOf("/") === -1;
if (!isRootHtmlFile && !compareTwoUrlPaths(urlToFetch, window.location.href)) {
// we are not in that HTML page
return null;
}
Expand Down Expand Up @@ -325,6 +345,6 @@ const applyHotReload = async ({
window.__reloader__ = reloader;
window.__server_events__.listenEvents({
reload: reloadServerEvent => {
reloader.addMessage(reloadServerEvent.data);
reloader.changes.add(reloadServerEvent.data);
}
});
13 changes: 9 additions & 4 deletions dist/js/server_events_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const createConnectionManager = (attemptConnection, {
let msSpent = 0;
const attempt = () => {
readyState.goTo(READY_STATES.CONNECTING);
_disconnect = attemptConnection({
let timeout;
const cancelAttempt = attemptConnection({
onClosed: () => {
if (!retry) {
readyState.goTo(READY_STATES.CLOSED);
Expand All @@ -47,15 +48,14 @@ const createConnectionManager = (attemptConnection, {
console.info(`[jsenv] could not connect to server in less than ${retryAllocatedMs}ms`);
return;
}

// if closed while open -> connection lost
// otherwise it's the attempt to connect for the first time
// or to reconnect
if (readyState.value === READY_STATES.OPEN) {
console.info(`[jsenv] server connection lost; retrying to connect`);
}
retryCount++;
setTimeout(() => {
timeout = setTimeout(() => {
msSpent += retryAfter;
attempt();
}, retryAfter);
Expand All @@ -65,8 +65,13 @@ const createConnectionManager = (attemptConnection, {
// console.info(`[jsenv] connected to server`)
}
});
};

_disconnect = () => {
cancelAttempt();
clearTimeout(timeout);
readyState.goTo(READY_STATES.CLOSED);
};
};
attempt();
};
const disconnect = () => {
Expand Down
6 changes: 4 additions & 2 deletions dist/js/supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,10 @@ window.__supervisor__ = (() => {
errorDetailsPromise
});
if (window.__reloader__) {
window.__reloader__.onstatuschange = () => {
if (window.__reloader__.status === "reloading") {
const onchange = window.__reloader__.status.onchange;
window.__reloader__.status.onchange = () => {
onchange();
if (window.__reloader__.status.value === "reloading") {
removeErrorOverlay();
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20701,7 +20701,7 @@ const jsenvPluginRibbon = ({
appliesDuring: "dev",
transformUrlContent: {
html: (urlInfo, context) => {
if (urlInfo.data.noribbon) {
if (urlInfo.data.isJsenvToolbar || urlInfo.data.noribbon) {
return null;
}
const {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/core",
"version": "29.9.0",
"version": "29.9.1",
"description": "Tool to develop, test and build js projects",
"license": "MIT",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jsenv/demo-node-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@jsenv/assert": "2.8.0",
"@jsenv/core": "29.9.0",
"@jsenv/core": "29.9.1",
"@jsenv/eslint-config": "16.2.9",
"@jsenv/eslint-import-resolver": "0.4.1",
"eslint": "8.28.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jsenv/demo-web-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@babel/plugin-syntax-import-assertions": "7.20.0",
"@babel/plugin-transform-react-jsx": "7.19.0",
"@jsenv/assert": "2.8.0",
"@jsenv/core": "29.9.0",
"@jsenv/core": "29.9.1",
"@jsenv/plugin-preact": "1.2.7",
"@jsenv/eslint-config": "16.2.9",
"@jsenv/eslint-import-resolver": "0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jsenv/demo-web-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@babel/plugin-syntax-import-assertions": "7.20.0",
"@babel/plugin-transform-react-jsx": "7.19.0",
"@jsenv/assert": "2.8.0",
"@jsenv/core": "29.9.0",
"@jsenv/core": "29.9.1",
"@jsenv/plugin-react": "1.1.10",
"@jsenv/eslint-config": "16.2.9",
"@jsenv/eslint-import-resolver": "0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jsenv/demo-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@babel/eslint-parser": "7.19.1",
"@babel/plugin-syntax-import-assertions": "7.20.0",
"@jsenv/assert": "2.8.0",
"@jsenv/core": "29.9.0",
"@jsenv/core": "29.9.1",
"@jsenv/eslint-config": "16.2.9",
"@jsenv/eslint-import-resolver": "0.4.1",
"eslint": "8.28.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jsenv/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-jsenv",
"version": "1.4.4",
"version": "1.4.5",
"description": "npm initializer for jsenv",
"license": "MIT",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions packages/jsenv-plugin-toolbar/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.jsenv/
dist/
node_modules/
Loading