@jsenv/plugin-toolbar 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/{toolbar_main.css → toolbar.css} +285 -319
- package/dist/html/toolbar.html +91 -80
- package/dist/js/toolbar_core.js +1792 -0
- package/dist/js/toolbar_injector.js +60 -121
- package/dist/jsenv_plugin_toolbar.js +18 -12
- package/package.json +10 -3
- package/src/client/core/animation_actions.js +8 -0
- package/src/client/core/animation_effects.js +12 -0
- package/src/client/core/animation_signals.js +12 -0
- package/src/client/core/changes_actions.js +9 -0
- package/src/client/core/changes_signals.js +3 -0
- package/src/client/core/execution_actions.js +50 -0
- package/src/client/core/execution_effects.js +22 -0
- package/src/client/core/execution_signals.js +19 -0
- package/src/client/core/notification_actions.js +71 -0
- package/src/client/core/notification_context.js +1 -0
- package/src/client/core/notification_effects.js +11 -0
- package/src/client/core/notification_signals.js +13 -0
- package/src/client/{communication/parent_window_communication.js → core/parent_window_actions.js} +10 -0
- package/src/client/core/parent_window_context.js +7 -0
- package/src/client/core/parent_window_effects.js +20 -0
- package/src/client/core/parent_window_signals.js +34 -0
- package/src/client/core/server_actions.js +9 -0
- package/src/client/core/server_effects.js +11 -0
- package/src/client/core/server_signals.js +12 -0
- package/src/client/core/settings_actions.js +9 -0
- package/src/client/core/settings_signals.js +3 -0
- package/src/client/core/theme_actions.js +9 -0
- package/src/client/core/theme_effects.js +8 -0
- package/src/client/core/theme_signals.js +12 -0
- package/src/client/core/toolbar_logger.js +29 -0
- package/src/client/core/toolbar_open_actions.js +9 -0
- package/src/client/core/toolbar_open_effects.js +5 -0
- package/src/client/core/toolbar_open_signals.js +12 -0
- package/src/client/core/toolbar_state_context.js +5 -0
- package/src/client/core/toolbar_state_effects.js +10 -0
- package/src/client/core/toolbar_state_signals.js +20 -0
- package/src/client/core/tooltip_actions.js +7 -0
- package/src/client/toolbar.html +116 -89
- package/src/client/toolbar_core.js +8 -0
- package/src/client/toolbar_injector.js +64 -39
- package/src/client/ui/changes_indicator/changes_indicator.js +66 -0
- package/src/client/{execution/execution.css → ui/document_execution_indicator/document_execution_indicator.css} +10 -14
- package/src/client/ui/document_execution_indicator/document_execution_indicator.js +66 -0
- package/src/client/ui/document_index_link/document_index_link.js +8 -0
- package/src/client/ui/globals.css +103 -0
- package/src/client/{jsenv_logo.svg → ui/jsenv_logo.svg} +0 -0
- package/src/client/{eventsource/eventsource.css → ui/server_indicator/server_indicator.css} +14 -24
- package/src/client/ui/server_indicator/server_indicator.js +62 -0
- package/src/client/ui/toolbar.css +76 -0
- package/src/client/ui/toolbar_close_button/toolbar_close_button.js +15 -0
- package/src/client/{responsive/overflow_menu.css → ui/toolbar_menu_overflow/toolbar_menu_overflow.css} +10 -11
- package/src/client/{responsive/toolbar_responsive.js → ui/toolbar_menu_overflow/toolbar_menu_overflow.js} +25 -31
- package/src/client/ui/toolbar_opening/toolbar_opening.js +73 -0
- package/src/client/ui/toolbar_overlay/toolbar_overlay.js +76 -0
- package/src/client/{theme → ui/toolbar_settings}/jsenv_theme.css +6 -6
- package/src/client/{theme/light_theme.css → ui/toolbar_settings/theme_light.css} +9 -10
- package/src/client/ui/toolbar_settings/toolbar_animation_setting.js +27 -0
- package/src/client/ui/toolbar_settings/toolbar_autoreload_setting.js +79 -0
- package/src/client/ui/toolbar_settings/toolbar_notification_setting.js +88 -0
- package/src/client/{settings/settings.css → ui/toolbar_settings/toolbar_settings.css} +24 -23
- package/src/client/ui/toolbar_settings/toolbar_settings.js +54 -0
- package/src/client/ui/toolbar_settings/toolbar_theme_setting.js +17 -0
- package/src/client/ui/toolbar_ui.js +21 -0
- package/src/client/{tooltip/tooltip.css → ui/tooltips/tooltips.css} +13 -7
- package/src/client/{util → ui/util}/animation.js +0 -0
- package/src/client/ui/util/dom.js +57 -0
- package/src/client/{util → ui/util}/fetch_using_xhr.js +0 -0
- package/src/client/{util → ui/util}/fetching.js +0 -0
- package/src/client/{util → ui/util}/iframe_to_parent_href.js +0 -0
- package/src/client/{util → ui/util}/responsive.js +0 -0
- package/src/client/{util → ui/util}/util.js +0 -0
- package/src/client/{variant → ui}/variant.js +0 -0
- package/src/jsenv_plugin_toolbar.js +19 -7
- package/dist/js/toolbar_main.js +0 -900
- package/scripts/build.mjs +0 -20
- package/src/client/animation/toolbar_animation_core.js +0 -30
- package/src/client/animation/toolbar_animation_ui.js +0 -21
- package/src/client/eventsource/toolbar_eventsource.js +0 -57
- package/src/client/execution/toolbar_execution.js +0 -88
- package/src/client/focus/focus.css +0 -61
- package/src/client/focus/toolbar_focus.js +0 -19
- package/src/client/notification/toolbar_notification.js +0 -181
- package/src/client/settings/toolbar_settings.js +0 -47
- package/src/client/theme/toolbar_theme.js +0 -34
- package/src/client/toolbar_main.css +0 -173
- package/src/client/toolbar_main.js +0 -174
- package/src/client/toolbar_state.js +0 -16
- package/src/client/tooltip/tooltip.js +0 -39
- package/src/client/util/dom.js +0 -108
- package/src/client/util/jsenv_logger.js +0 -28
- package/src/client/util/preferences.js +0 -10
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/ast/src/html/html_src_set.js +0 -18
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation.js +0 -45
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_core.js +0 -32
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_core.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_ui.js +0 -23
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/animation/toolbar_animation_ui.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/communication/parent_window_communication.js +0 -33
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/eventsource.css +0 -87
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/toolbar_eventsource.js +0 -59
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/eventsource/toolbar_eventsource.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/execution.css +0 -88
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/toolbar_execution.js +0 -90
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/execution/toolbar_execution.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/focus/focus.css +0 -28
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/focus/toolbar_focus.js +0 -19
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/jsenv_logo.svg +0 -140
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/notification/toolbar_notification.js +0 -183
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/notification/toolbar_notification.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/overflow_menu.css +0 -60
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/toolbar_responsive.js +0 -105
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/responsive/toolbar_responsive.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/settings.css +0 -200
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/toolbar_settings.js +0 -49
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/settings/toolbar_settings.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/light_theme.css +0 -110
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/toolbar_theme.js +0 -36
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/theme/toolbar_theme.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar.html +0 -319
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_injector.js +0 -232
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_injector.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.css +0 -161
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.css.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.js +0 -176
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_main.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_state.js +0 -18
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/toolbar_state.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.css +0 -60
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.js +0 -41
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/tooltip/tooltip.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/animation.js +0 -307
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/animation.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/dom.js +0 -108
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/iframe_to_parent_href.js +0 -10
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/preferences.js +0 -10
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/util/responsive.js +0 -112
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/packages/jsenv-plugin-toolbar/src/client/variant/variant.js +0 -74
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload.js +0 -201
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/autoreload_preference.js +0 -11
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/reload.js +0 -138
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/reload.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/autoreload/client/url_helpers.js +0 -20
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html +0 -590
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L15C5-L20C12.js +0 -7
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L15C5-L20C12.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L368C5-L481C14.js +0 -114
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L482C5-L605C14.js +0 -124
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L69C5-L299C13.css +0 -227
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/explorer/client/explorer.html@L8C5-L68C13.css +0 -28
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/import_meta_hot/client/import_meta_hot.js +0 -82
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/ribbon/client/ribbon.js +0 -51
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/connection_manager.js +0 -165
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/events_manager.js +0 -75
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/server_events_client.js +0 -20
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/server_events_client.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/web_socket_connection.js +0 -83
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/server_events/client/web_socket_connection.js.map +0 -12
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/supervisor/client/script_type_module_supervisor.js +0 -98
- package/tests/toolbar_basic/.jsenv/chrome@107.00/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/plugins/supervisor/client/supervisor.js +0 -966
- package/tests/toolbar_basic/main.html +0 -18
- package/tests/toolbar_basic/start_dev_server.mjs +0 -7
- package/todo.txt +0 -0
package/dist/js/toolbar_main.js
DELETED
|
@@ -1,900 +0,0 @@
|
|
|
1
|
-
import { u as updateIframeOverflowOnParentWindow, t as toolbarSectionIsActive, d as deactivateToolbarSection, a as activateToolbarSection, r as removeForceHideElement, f as forceHideElement, g as getToolbarIframe, s as setStyles } from "./toolbar_injector.js";
|
|
2
|
-
|
|
3
|
-
const startJavaScriptAnimation = ({
|
|
4
|
-
duration = 300,
|
|
5
|
-
timingFunction = t => t,
|
|
6
|
-
onProgress = () => {},
|
|
7
|
-
onCancel = () => {},
|
|
8
|
-
onComplete = () => {}
|
|
9
|
-
}) => {
|
|
10
|
-
if (isNaN(duration)) {
|
|
11
|
-
// console.warn(`duration must be a number, received ${duration}`)
|
|
12
|
-
return () => {};
|
|
13
|
-
}
|
|
14
|
-
duration = parseInt(duration, 10);
|
|
15
|
-
const startMs = performance.now();
|
|
16
|
-
let currentRequestAnimationFrameId;
|
|
17
|
-
let done = false;
|
|
18
|
-
let rawProgress = 0;
|
|
19
|
-
let progress = 0;
|
|
20
|
-
const handler = () => {
|
|
21
|
-
currentRequestAnimationFrameId = null;
|
|
22
|
-
const nowMs = performance.now();
|
|
23
|
-
rawProgress = Math.min((nowMs - startMs) / duration, 1);
|
|
24
|
-
progress = timingFunction(rawProgress);
|
|
25
|
-
done = rawProgress === 1;
|
|
26
|
-
onProgress({
|
|
27
|
-
done,
|
|
28
|
-
rawProgress,
|
|
29
|
-
progress
|
|
30
|
-
});
|
|
31
|
-
if (done) {
|
|
32
|
-
onComplete();
|
|
33
|
-
} else {
|
|
34
|
-
currentRequestAnimationFrameId = window.requestAnimationFrame(handler);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
handler();
|
|
38
|
-
const stop = () => {
|
|
39
|
-
if (currentRequestAnimationFrameId) {
|
|
40
|
-
window.cancelAnimationFrame(currentRequestAnimationFrameId);
|
|
41
|
-
currentRequestAnimationFrameId = null;
|
|
42
|
-
}
|
|
43
|
-
if (!done) {
|
|
44
|
-
done = true;
|
|
45
|
-
onCancel({
|
|
46
|
-
rawProgress,
|
|
47
|
-
progress
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
return stop;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// handle data-last-interaction attr on html (focusring)
|
|
55
|
-
window.addEventListener("mousedown", mousedownEvent => {
|
|
56
|
-
if (mousedownEvent.defaultPrevented) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
document.documentElement.setAttribute("data-last-interaction", "mouse");
|
|
60
|
-
});
|
|
61
|
-
window.addEventListener("touchstart", touchstartEvent => {
|
|
62
|
-
if (touchstartEvent.defaultPrevented) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
document.documentElement.setAttribute("data-last-interaction", "mouse");
|
|
66
|
-
});
|
|
67
|
-
window.addEventListener("keydown", keydownEvent => {
|
|
68
|
-
if (keydownEvent.defaultPrevented) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
document.documentElement.setAttribute("data-last-interaction", "keyboard");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const setLinkHrefForParentWindow = (a, href) => {
|
|
75
|
-
a.href = href;
|
|
76
|
-
a.onclick = e => {
|
|
77
|
-
if (e.ctrlKey || e.metaKey) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
e.preventDefault();
|
|
81
|
-
window.parent.location.href = href;
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const createPreference = name => {
|
|
86
|
-
return {
|
|
87
|
-
has: () => localStorage.hasOwnProperty(name),
|
|
88
|
-
get: () => localStorage.hasOwnProperty(name) ? JSON.parse(localStorage.getItem(name)) : undefined,
|
|
89
|
-
set: value => localStorage.setItem(name, JSON.stringify(value))
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const toggleTooltip = element => {
|
|
94
|
-
if (element.hasAttribute("data-tooltip-visible")) {
|
|
95
|
-
hideTooltip(element);
|
|
96
|
-
} else {
|
|
97
|
-
showTooltip(element);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const hideTooltip = element => {
|
|
101
|
-
element.removeAttribute("data-tooltip-visible");
|
|
102
|
-
element.removeAttribute("data-tooltip-auto-visible");
|
|
103
|
-
updateIframeOverflowOnParentWindow();
|
|
104
|
-
};
|
|
105
|
-
const showTooltip = element => {
|
|
106
|
-
element.setAttribute("data-tooltip-visible", "");
|
|
107
|
-
updateIframeOverflowOnParentWindow();
|
|
108
|
-
};
|
|
109
|
-
const autoShowTooltip = element => {
|
|
110
|
-
element.setAttribute("data-tooltip-auto-visible", "");
|
|
111
|
-
updateIframeOverflowOnParentWindow();
|
|
112
|
-
};
|
|
113
|
-
const removeAutoShowTooltip = element => {
|
|
114
|
-
element.removeAttribute("data-tooltip-auto-visible");
|
|
115
|
-
updateIframeOverflowOnParentWindow();
|
|
116
|
-
};
|
|
117
|
-
const hideAllTooltip = () => {
|
|
118
|
-
const elementsWithTooltip = Array.from(document.querySelectorAll("[data-tooltip-visible]"));
|
|
119
|
-
elementsWithTooltip.forEach(elementWithTooltip => {
|
|
120
|
-
hideTooltip(elementWithTooltip);
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const enableVariant = (rootNode, variables) => {
|
|
125
|
-
const nodesNotMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingACondition}]`));
|
|
126
|
-
nodesNotMatching.forEach(nodeNotMatching => {
|
|
127
|
-
const conditionAttributeValue = nodeNotMatching.getAttribute(attributeIndicatingACondition);
|
|
128
|
-
const matches = testCondition(conditionAttributeValue, variables);
|
|
129
|
-
if (matches) {
|
|
130
|
-
renameAttribute(nodeNotMatching, attributeIndicatingACondition, attributeIndicatingAMatch);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
const nodesMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingAMatch}]`));
|
|
134
|
-
nodesMatching.forEach(nodeMatching => {
|
|
135
|
-
const conditionAttributeValue = nodeMatching.getAttribute(attributeIndicatingAMatch);
|
|
136
|
-
const matches = testCondition(conditionAttributeValue, variables);
|
|
137
|
-
if (!matches) {
|
|
138
|
-
renameAttribute(nodeMatching, attributeIndicatingAMatch, attributeIndicatingACondition);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
const testCondition = (conditionAttributeValue, variables) => {
|
|
143
|
-
const condition = parseCondition(conditionAttributeValue);
|
|
144
|
-
return Object.keys(variables).some(key => {
|
|
145
|
-
if (condition.key !== key) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
// the condition do not specify a value, any value is ok
|
|
149
|
-
if (condition.value === undefined) {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
if (condition.value === variables[key]) {
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
const parseCondition = conditionAttributeValue => {
|
|
159
|
-
const colonIndex = conditionAttributeValue.indexOf(":");
|
|
160
|
-
if (colonIndex === -1) {
|
|
161
|
-
return {
|
|
162
|
-
key: conditionAttributeValue,
|
|
163
|
-
value: undefined
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
key: conditionAttributeValue.slice(0, colonIndex),
|
|
168
|
-
value: conditionAttributeValue.slice(colonIndex + 1)
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
const attributeIndicatingACondition = `data-when`;
|
|
172
|
-
const attributeIndicatingAMatch = `data-when-active`;
|
|
173
|
-
const renameAttribute = (node, name, newName) => {
|
|
174
|
-
node.setAttribute(newName, node.getAttribute(name));
|
|
175
|
-
node.removeAttribute(name);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const renderToolbarSettings = () => {
|
|
179
|
-
document.querySelector("#settings-button").onclick = toggleSettings;
|
|
180
|
-
document.querySelector("#button-close-settings").onclick = toggleSettings;
|
|
181
|
-
disableWarningStyle();
|
|
182
|
-
};
|
|
183
|
-
const toggleSettings = () => {
|
|
184
|
-
if (settingsAreVisible()) {
|
|
185
|
-
hideSettings();
|
|
186
|
-
} else {
|
|
187
|
-
showSettings();
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
const disableWarningStyle = () => {
|
|
191
|
-
enableVariant(document.querySelector("#settings-button"), {
|
|
192
|
-
has_warning: "no"
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
const settingsAreVisible = () => {
|
|
196
|
-
return toolbarSectionIsActive(document.querySelector(`#settings`));
|
|
197
|
-
};
|
|
198
|
-
const hideSettings = () => {
|
|
199
|
-
deactivateToolbarSection(document.querySelector(`#settings`));
|
|
200
|
-
updateIframeOverflowOnParentWindow();
|
|
201
|
-
};
|
|
202
|
-
const showSettings = () => {
|
|
203
|
-
activateToolbarSection(document.querySelector(`#settings`));
|
|
204
|
-
updateIframeOverflowOnParentWindow();
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const notificationAvailable = typeof window.Notification === "function";
|
|
208
|
-
const notificationPreference = createPreference("notification");
|
|
209
|
-
const arrayOfOpenedNotifications = [];
|
|
210
|
-
const renderToolbarNotification = () => {
|
|
211
|
-
if (!notificationAvailable) {
|
|
212
|
-
applyNotificationNotAvailableEffects();
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
updatePermission();
|
|
216
|
-
};
|
|
217
|
-
const updatePermission = () => {
|
|
218
|
-
const notifPermission = Notification.permission;
|
|
219
|
-
if (notifPermission === "default") {
|
|
220
|
-
applyNotificationDefaultEffects();
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (notifPermission === "denied") {
|
|
224
|
-
applyNotificationDeniedEffects();
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (notifPermission === "granted") {
|
|
228
|
-
applyNotificationGrantedEffects();
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
const notifCheckbox = document.querySelector("#toggle-notifs");
|
|
233
|
-
const applyNotificationNotAvailableEffects = () => {
|
|
234
|
-
const notifSetting = document.querySelector(".settings-notification");
|
|
235
|
-
notifSetting.setAttribute("data-disabled", "true");
|
|
236
|
-
notifSetting.setAttribute("title", `Notification not available in the browser`);
|
|
237
|
-
notifCheckbox.disabled = true;
|
|
238
|
-
};
|
|
239
|
-
const applyNotificationDefaultEffects = () => {
|
|
240
|
-
applyNotificationNOTGrantedEffects();
|
|
241
|
-
const notifSetting = document.querySelector(".settings-notification");
|
|
242
|
-
notifSetting.removeAttribute("data-disabled");
|
|
243
|
-
notifSetting.removeAttribute("title");
|
|
244
|
-
};
|
|
245
|
-
const applyNotificationDeniedEffects = () => {
|
|
246
|
-
applyNotificationNOTGrantedEffects();
|
|
247
|
-
const notifSetting = document.querySelector(".settings-notification");
|
|
248
|
-
notifSetting.setAttribute("data-disabled", "true");
|
|
249
|
-
notifSetting.setAttribute("title", `Notification denied`);
|
|
250
|
-
};
|
|
251
|
-
const applyNotificationGrantedEffects = () => {
|
|
252
|
-
enableVariant(document.querySelector(".notification-text"), {
|
|
253
|
-
notif_granted: "yes"
|
|
254
|
-
});
|
|
255
|
-
notifCheckbox.disabled = false;
|
|
256
|
-
notifCheckbox.checked = getNotificationPreference();
|
|
257
|
-
notifCheckbox.onchange = () => {
|
|
258
|
-
setNotificationPreference(notifCheckbox.checked);
|
|
259
|
-
if (!notifCheckbox.checked) {
|
|
260
|
-
// slice because arrayOfOpenedNotifications can be mutated while looping
|
|
261
|
-
arrayOfOpenedNotifications.slice().forEach(notification => {
|
|
262
|
-
notification.close();
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
const applyNotificationNOTGrantedEffects = () => {
|
|
268
|
-
enableVariant(document.querySelector(".notification-text"), {
|
|
269
|
-
notif_granted: "no"
|
|
270
|
-
});
|
|
271
|
-
notifCheckbox.disabled = true;
|
|
272
|
-
notifCheckbox.checked = false;
|
|
273
|
-
document.querySelector("a.request_notification_permission").onclick = () => {
|
|
274
|
-
requestPermission().then(() => {
|
|
275
|
-
setNotificationPreference(true);
|
|
276
|
-
updatePermission();
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
const notifyExecutionResult = (executedFileRelativeUrl, execution, previousExecution) => {
|
|
281
|
-
const notificationEnabled = getNotificationPreference();
|
|
282
|
-
if (!notificationEnabled) return;
|
|
283
|
-
const notificationOptions = {
|
|
284
|
-
lang: "en",
|
|
285
|
-
icon: getFaviconHref(),
|
|
286
|
-
clickToFocus: true,
|
|
287
|
-
clickToClose: true
|
|
288
|
-
};
|
|
289
|
-
if (execution.status === "errored") {
|
|
290
|
-
if (previousExecution) {
|
|
291
|
-
if (previousExecution.status === "completed") {
|
|
292
|
-
notify("Broken", {
|
|
293
|
-
...notificationOptions,
|
|
294
|
-
body: `${executedFileRelativeUrl} execution now failing.`
|
|
295
|
-
});
|
|
296
|
-
} else {
|
|
297
|
-
notify("Still failing", {
|
|
298
|
-
...notificationOptions,
|
|
299
|
-
body: `${executedFileRelativeUrl} execution still failing.`
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
} else {
|
|
303
|
-
notify("Failing", {
|
|
304
|
-
...notificationOptions,
|
|
305
|
-
body: `${executedFileRelativeUrl} execution failed.`
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
} else if (previousExecution && previousExecution.status === "errored") {
|
|
309
|
-
notify("Fixed", {
|
|
310
|
-
...notificationOptions,
|
|
311
|
-
body: `${executedFileRelativeUrl} execution fixed.`
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
const getNotificationPreference = () => notificationPreference.has() ? notificationPreference.get() : true;
|
|
316
|
-
const setNotificationPreference = value => notificationPreference.set(value);
|
|
317
|
-
const getFaviconHref = () => {
|
|
318
|
-
const link = document.querySelector('link[rel="icon"]');
|
|
319
|
-
return link ? link.href : undefined;
|
|
320
|
-
};
|
|
321
|
-
let permission = "default";
|
|
322
|
-
const notify = notificationAvailable ? async (title, {
|
|
323
|
-
clickToFocus = false,
|
|
324
|
-
clickToClose = false,
|
|
325
|
-
...options
|
|
326
|
-
} = {}) => {
|
|
327
|
-
if (permission !== "granted") {
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
const notification = new Notification(title, options);
|
|
331
|
-
arrayOfOpenedNotifications.push(notification);
|
|
332
|
-
notification.onclick = () => {
|
|
333
|
-
// but if the user navigated inbetween
|
|
334
|
-
// focusing window will show something else
|
|
335
|
-
// in that case it could be great to do something
|
|
336
|
-
// maybe like showing a message saying this execution
|
|
337
|
-
// is no longer visible
|
|
338
|
-
// we could also navigauate to this file execution but
|
|
339
|
-
// there is no guarantee re-executing the file would give same output
|
|
340
|
-
// and it would also trigger an other notification
|
|
341
|
-
if (clickToFocus) window.focus();
|
|
342
|
-
if (clickToClose) notification.close();
|
|
343
|
-
};
|
|
344
|
-
notification.onclose = () => {
|
|
345
|
-
const index = arrayOfOpenedNotifications.indexOf(notification);
|
|
346
|
-
if (index > -1) {
|
|
347
|
-
arrayOfOpenedNotifications.splice(index, 1);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
return notification;
|
|
351
|
-
} : () => {};
|
|
352
|
-
let requestPromise;
|
|
353
|
-
const requestPermission = notificationAvailable ? async () => {
|
|
354
|
-
if (requestPromise) return requestPromise;
|
|
355
|
-
requestPromise = Notification.requestPermission();
|
|
356
|
-
permission = await requestPromise;
|
|
357
|
-
requestPromise = undefined;
|
|
358
|
-
return permission;
|
|
359
|
-
} : () => Promise.resolve("default");
|
|
360
|
-
|
|
361
|
-
const DARK_THEME = "dark";
|
|
362
|
-
const LIGHT_THEME = "light";
|
|
363
|
-
const themePreference = createPreference("theme");
|
|
364
|
-
const renderToolbarTheme = () => {
|
|
365
|
-
const theme = getThemePreference();
|
|
366
|
-
const checkbox = document.querySelector("#checkbox-dark-theme");
|
|
367
|
-
checkbox.checked = theme === DARK_THEME;
|
|
368
|
-
setTheme(theme);
|
|
369
|
-
checkbox.onchange = () => {
|
|
370
|
-
if (checkbox.checked) {
|
|
371
|
-
setThemePreference(DARK_THEME);
|
|
372
|
-
setTheme(DARK_THEME);
|
|
373
|
-
} else {
|
|
374
|
-
setThemePreference(LIGHT_THEME);
|
|
375
|
-
setTheme(LIGHT_THEME);
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
};
|
|
379
|
-
const getThemePreference = () => {
|
|
380
|
-
return themePreference.has() ? themePreference.get() : DARK_THEME;
|
|
381
|
-
};
|
|
382
|
-
const setThemePreference = value => {
|
|
383
|
-
themePreference.set(value);
|
|
384
|
-
setTheme(value);
|
|
385
|
-
};
|
|
386
|
-
const setTheme = theme => {
|
|
387
|
-
document.querySelector("html").setAttribute("data-theme", theme);
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
const animationPreference = createPreference("animation");
|
|
391
|
-
const renderToolbarAnimation = () => {
|
|
392
|
-
const animCheckbox = document.querySelector("#toggle-anims");
|
|
393
|
-
animCheckbox.checked = getAnimationPreference();
|
|
394
|
-
animCheckbox.onchange = () => {
|
|
395
|
-
setAnimationPreference(animCheckbox.checked);
|
|
396
|
-
onPreferenceChange(animCheckbox.checked);
|
|
397
|
-
};
|
|
398
|
-
onPreferenceChange();
|
|
399
|
-
|
|
400
|
-
// enable toolbar transition only after first render
|
|
401
|
-
setTimeout(() => {
|
|
402
|
-
document.querySelector("#toolbar").setAttribute("data-animate", "");
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
const onPreferenceChange = (value = getAnimationPreference()) => {
|
|
406
|
-
if (value) {
|
|
407
|
-
enableAnimation();
|
|
408
|
-
} else {
|
|
409
|
-
disableAnimation();
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
const getAnimationPreference = () => animationPreference.has() ? animationPreference.get() : true;
|
|
413
|
-
const setAnimationPreference = value => animationPreference.set(value);
|
|
414
|
-
const enableAnimation = () => {
|
|
415
|
-
document.documentElement.removeAttribute("data-animation-disabled");
|
|
416
|
-
};
|
|
417
|
-
const disableAnimation = () => {
|
|
418
|
-
document.documentElement.setAttribute("data-animation-disabled", "");
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
const renderExecutionInToolbar = async () => {
|
|
422
|
-
// reset file execution indicator ui
|
|
423
|
-
applyExecutionIndicator();
|
|
424
|
-
removeForceHideElement(document.querySelector("#execution-indicator"));
|
|
425
|
-
const {
|
|
426
|
-
status,
|
|
427
|
-
startTime,
|
|
428
|
-
endTime
|
|
429
|
-
} = await window.parent.__supervisor__.getDocumentExecutionResult();
|
|
430
|
-
const execution = {
|
|
431
|
-
status,
|
|
432
|
-
startTime,
|
|
433
|
-
endTime
|
|
434
|
-
};
|
|
435
|
-
applyExecutionIndicator(execution);
|
|
436
|
-
const executionStorageKey = window.location.href;
|
|
437
|
-
const previousExecution = sessionStorage.hasOwnProperty(executionStorageKey) ? JSON.parse(sessionStorage.getItem(executionStorageKey)) : undefined;
|
|
438
|
-
notifyExecutionResult(executionStorageKey, execution, previousExecution);
|
|
439
|
-
sessionStorage.setItem(executionStorageKey, JSON.stringify(execution));
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
// const changeLink = variantNode.querySelector(".eventsource-changes-link")
|
|
443
|
-
// changeLink.innerHTML = reloadMessageCount
|
|
444
|
-
// changeLink.onclick = () => {
|
|
445
|
-
// console.log(reloadMessages)
|
|
446
|
-
// // eslint-disable-next-line no-alert
|
|
447
|
-
// window.parent.alert(JSON.stringify(reloadMessages, null, " "))
|
|
448
|
-
// }
|
|
449
|
-
|
|
450
|
-
// const someFailed = reloadMessages.some((m) => m.status === "failed")
|
|
451
|
-
// const somePending = reloadMessages.some((m) => m.status === "pending")
|
|
452
|
-
// const applyLink = variantNode.querySelector(".eventsource-reload-link")
|
|
453
|
-
// applyLink.innerHTML = someFailed
|
|
454
|
-
// ? "failed"
|
|
455
|
-
// : somePending
|
|
456
|
-
// ? "applying..."
|
|
457
|
-
// : "apply changes"
|
|
458
|
-
// applyLink.onclick = someFailed
|
|
459
|
-
// ? () => {
|
|
460
|
-
// parentEventSourceClient.applyReloadMessageEffects()
|
|
461
|
-
// }
|
|
462
|
-
// : somePending
|
|
463
|
-
// ? () => {}
|
|
464
|
-
// : () => {
|
|
465
|
-
// parentEventSourceClient.applyReloadMessageEffects()
|
|
466
|
-
// }
|
|
467
|
-
|
|
468
|
-
// parentEventSourceClient.reloadMessagesSignal.onchange = () => {
|
|
469
|
-
// updateEventSourceIndicator()
|
|
470
|
-
// }
|
|
471
|
-
// const autoreloadCheckbox = document.querySelector("#toggle-autoreload")
|
|
472
|
-
// autoreloadCheckbox.checked = parentEventSourceClient.isAutoreloadEnabled()
|
|
473
|
-
// autoreloadCheckbox.onchange = () => {
|
|
474
|
-
// parentEventSourceClient.setAutoreloadPreference(autoreloadCheckbox.checked)
|
|
475
|
-
// updateEventSourceIndicator()
|
|
476
|
-
// }
|
|
477
|
-
|
|
478
|
-
const applyExecutionIndicator = ({
|
|
479
|
-
status = "running",
|
|
480
|
-
startTime,
|
|
481
|
-
endTime
|
|
482
|
-
} = {}) => {
|
|
483
|
-
const executionIndicator = document.querySelector("#execution-indicator");
|
|
484
|
-
enableVariant(executionIndicator, {
|
|
485
|
-
execution: status
|
|
486
|
-
});
|
|
487
|
-
const variantNode = executionIndicator.querySelector("[data-when-active]");
|
|
488
|
-
variantNode.querySelector("button").onclick = () => toggleTooltip(executionIndicator);
|
|
489
|
-
variantNode.querySelector(".tooltip").textContent = computeText({
|
|
490
|
-
status,
|
|
491
|
-
startTime,
|
|
492
|
-
endTime
|
|
493
|
-
});
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
// relative time: https://github.com/tc39/proposal-intl-relative-time/issues/118
|
|
497
|
-
const computeText = ({
|
|
498
|
-
status,
|
|
499
|
-
startTime,
|
|
500
|
-
endTime
|
|
501
|
-
}) => {
|
|
502
|
-
if (status === "completed") {
|
|
503
|
-
return `Execution completed in ${endTime - startTime}ms`;
|
|
504
|
-
}
|
|
505
|
-
if (status === "errored") {
|
|
506
|
-
return `Execution failed in ${endTime - startTime}ms`;
|
|
507
|
-
}
|
|
508
|
-
if (status === "running") {
|
|
509
|
-
return "Executing...";
|
|
510
|
-
}
|
|
511
|
-
return "";
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
const parentEventSourceClient = window.parent.__jsenv_event_source_client__;
|
|
515
|
-
const initToolbarEventSource = () => {
|
|
516
|
-
removeForceHideElement(document.querySelector("#eventsource-indicator"));
|
|
517
|
-
if (!parentEventSourceClient) {
|
|
518
|
-
disableAutoreloadSetting();
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
parentEventSourceClient.status.onchange = () => {
|
|
522
|
-
updateEventSourceIndicator();
|
|
523
|
-
};
|
|
524
|
-
updateEventSourceIndicator();
|
|
525
|
-
};
|
|
526
|
-
const updateEventSourceIndicator = () => {
|
|
527
|
-
const eventSourceIndicator = document.querySelector("#eventsource-indicator");
|
|
528
|
-
const eventSourceConnectionState = parentEventSourceClient.status.value;
|
|
529
|
-
enableVariant(eventSourceIndicator, {
|
|
530
|
-
eventsource: eventSourceConnectionState
|
|
531
|
-
});
|
|
532
|
-
const variantNode = document.querySelector("#eventsource-indicator > [data-when-active]");
|
|
533
|
-
variantNode.querySelector("button").onclick = () => {
|
|
534
|
-
toggleTooltip(eventSourceIndicator);
|
|
535
|
-
};
|
|
536
|
-
if (eventSourceConnectionState === "connecting") {
|
|
537
|
-
variantNode.querySelector("a").onclick = () => {
|
|
538
|
-
parentEventSourceClient.disconnect();
|
|
539
|
-
};
|
|
540
|
-
} else if (eventSourceConnectionState === "connected") {
|
|
541
|
-
removeAutoShowTooltip(eventSourceIndicator);
|
|
542
|
-
} else if (eventSourceConnectionState === "disconnected") {
|
|
543
|
-
autoShowTooltip(eventSourceIndicator);
|
|
544
|
-
variantNode.querySelector("a").onclick = () => {
|
|
545
|
-
parentEventSourceClient.connect();
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
const disableAutoreloadSetting = () => {
|
|
550
|
-
document.querySelector(".settings-autoreload").setAttribute("data-disabled", "true");
|
|
551
|
-
document.querySelector(".settings-autoreload").setAttribute("title", `Autoreload not available: disabled by server`);
|
|
552
|
-
document.querySelector("#toggle-autoreload").disabled = true;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
const createHorizontalBreakpoint = breakpointValue => {
|
|
556
|
-
return createBreakpoint(windowWidthMeasure, breakpointValue);
|
|
557
|
-
};
|
|
558
|
-
const createMeasure = ({
|
|
559
|
-
compute,
|
|
560
|
-
register
|
|
561
|
-
}) => {
|
|
562
|
-
let currentValue = compute();
|
|
563
|
-
const get = () => compute();
|
|
564
|
-
const changed = createSignal();
|
|
565
|
-
let unregister = () => {};
|
|
566
|
-
if (register) {
|
|
567
|
-
unregister = register(() => {
|
|
568
|
-
const value = compute();
|
|
569
|
-
if (value !== currentValue) {
|
|
570
|
-
const previousValue = value;
|
|
571
|
-
currentValue = value;
|
|
572
|
-
changed.notify(value, previousValue);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
return {
|
|
577
|
-
get,
|
|
578
|
-
changed,
|
|
579
|
-
unregister
|
|
580
|
-
};
|
|
581
|
-
};
|
|
582
|
-
const createSignal = () => {
|
|
583
|
-
const callbackArray = [];
|
|
584
|
-
const listen = callback => {
|
|
585
|
-
callbackArray.push(callback);
|
|
586
|
-
return () => {
|
|
587
|
-
const index = callbackArray.indexOf(callback);
|
|
588
|
-
if (index > -1) {
|
|
589
|
-
callbackArray.splice(index, 1);
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
};
|
|
593
|
-
const notify = (...args) => {
|
|
594
|
-
callbackArray.slice().forEach(callback => {
|
|
595
|
-
callback(...args);
|
|
596
|
-
});
|
|
597
|
-
};
|
|
598
|
-
return {
|
|
599
|
-
listen,
|
|
600
|
-
notify
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
const windowWidthMeasure = createMeasure({
|
|
604
|
-
name: "window-width",
|
|
605
|
-
compute: () => window.innerWidth,
|
|
606
|
-
register: onchange => {
|
|
607
|
-
window.addEventListener("resize", onchange);
|
|
608
|
-
window.addEventListener("orientationchange", onchange);
|
|
609
|
-
return () => {
|
|
610
|
-
window.removeEventListener("resize", onchange);
|
|
611
|
-
window.removeEventListener("orientationchange", onchange);
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
const createBreakpoint = (measure, breakpointValue) => {
|
|
616
|
-
const getBreakpointState = () => {
|
|
617
|
-
const value = measure.get();
|
|
618
|
-
if (value < breakpointValue) {
|
|
619
|
-
return "below";
|
|
620
|
-
}
|
|
621
|
-
if (value > breakpointValue) {
|
|
622
|
-
return "above";
|
|
623
|
-
}
|
|
624
|
-
return "equals";
|
|
625
|
-
};
|
|
626
|
-
let currentBreakpointState = getBreakpointState();
|
|
627
|
-
const isAbove = () => {
|
|
628
|
-
return measure.get() > breakpointValue;
|
|
629
|
-
};
|
|
630
|
-
const isBelow = () => {
|
|
631
|
-
return measure.get() < breakpointValue;
|
|
632
|
-
};
|
|
633
|
-
const breakpointChanged = createSignal();
|
|
634
|
-
measure.changed.listen(() => {
|
|
635
|
-
const breakpointState = getBreakpointState();
|
|
636
|
-
if (breakpointState !== currentBreakpointState) {
|
|
637
|
-
const breakpointStatePrevious = currentBreakpointState;
|
|
638
|
-
currentBreakpointState = breakpointState;
|
|
639
|
-
breakpointChanged.notify(breakpointState, breakpointStatePrevious);
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
return {
|
|
643
|
-
isAbove,
|
|
644
|
-
isBelow,
|
|
645
|
-
changed: breakpointChanged
|
|
646
|
-
};
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
// const windowScrollTop = createMeasure({
|
|
650
|
-
// name: "window-scroll-top",
|
|
651
|
-
// compute: () => window.scrollTop,
|
|
652
|
-
// register: (onchange) => {
|
|
653
|
-
// window.addEventListener("scroll", onchange)
|
|
654
|
-
// return () => {
|
|
655
|
-
// window.removeEventListener("scroll", onchange)
|
|
656
|
-
// }
|
|
657
|
-
// },
|
|
658
|
-
// })
|
|
659
|
-
|
|
660
|
-
const WINDOW_SMALL_WIDTH = 420;
|
|
661
|
-
const makeToolbarResponsive = () => {
|
|
662
|
-
// apply responsive design on toolbar icons if needed + add listener on resize screen
|
|
663
|
-
// ideally we should listen breakpoint once, for now restore toolbar
|
|
664
|
-
const overflowMenuBreakpoint = createHorizontalBreakpoint(WINDOW_SMALL_WIDTH);
|
|
665
|
-
const handleOverflowMenuBreakpoint = () => {
|
|
666
|
-
responsiveToolbar(overflowMenuBreakpoint);
|
|
667
|
-
};
|
|
668
|
-
handleOverflowMenuBreakpoint();
|
|
669
|
-
overflowMenuBreakpoint.changed.listen(handleOverflowMenuBreakpoint);
|
|
670
|
-
|
|
671
|
-
// overflow menu
|
|
672
|
-
document.querySelector("#overflow-menu-button").onclick = () => toggleOverflowMenu();
|
|
673
|
-
};
|
|
674
|
-
const responsiveToolbar = overflowMenuBreakpoint => {
|
|
675
|
-
// close all tooltips in case opened
|
|
676
|
-
hideTooltip(document.querySelector("#eventsource-indicator"));
|
|
677
|
-
hideTooltip(document.querySelector("#execution-indicator"));
|
|
678
|
-
// close settings box in case opened
|
|
679
|
-
deactivateToolbarSection(document.querySelector("#settings"));
|
|
680
|
-
if (overflowMenuBreakpoint.isBelow()) {
|
|
681
|
-
enableOverflow();
|
|
682
|
-
} else {
|
|
683
|
-
disableOverflow();
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
let moves = [];
|
|
687
|
-
const enableOverflow = () => {
|
|
688
|
-
// move elements from toolbar to overflow menu
|
|
689
|
-
const responsiveToolbarElements = document.querySelectorAll("[data-responsive-toolbar-element]");
|
|
690
|
-
const overflowMenu = document.querySelector("#overflow-menu");
|
|
691
|
-
|
|
692
|
-
// keep a placeholder element to know where to move them back
|
|
693
|
-
moves = Array.from(responsiveToolbarElements).map(element => {
|
|
694
|
-
const placeholder = document.createElement("div");
|
|
695
|
-
placeholder.style.display = "none";
|
|
696
|
-
placeholder.setAttribute("data-placeholder", "");
|
|
697
|
-
element.parentNode.replaceChild(placeholder, element);
|
|
698
|
-
overflowMenu.appendChild(element);
|
|
699
|
-
return {
|
|
700
|
-
element,
|
|
701
|
-
placeholder
|
|
702
|
-
};
|
|
703
|
-
});
|
|
704
|
-
document.querySelector("#toolbar").setAttribute("data-overflow-menu-enabled", "");
|
|
705
|
-
removeForceHideElement(document.querySelector("#overflow-menu-button"));
|
|
706
|
-
};
|
|
707
|
-
const disableOverflow = () => {
|
|
708
|
-
// close overflow menu in case it's open & unselect toggleOverflowMenu button in case it's selected
|
|
709
|
-
hideOverflowMenu();
|
|
710
|
-
deactivateToolbarSection(document.querySelector("#overflow-menu"));
|
|
711
|
-
moves.forEach(({
|
|
712
|
-
element,
|
|
713
|
-
placeholder
|
|
714
|
-
}) => {
|
|
715
|
-
placeholder.parentNode.replaceChild(element, placeholder);
|
|
716
|
-
});
|
|
717
|
-
moves = [];
|
|
718
|
-
document.querySelector("#toolbar").removeAttribute("data-overflow-menu-enabled");
|
|
719
|
-
forceHideElement(document.querySelector("#overflow-menu-button"));
|
|
720
|
-
};
|
|
721
|
-
const toggleOverflowMenu = () => {
|
|
722
|
-
if (overflowMenuIsVisible()) {
|
|
723
|
-
hideOverflowMenu();
|
|
724
|
-
} else {
|
|
725
|
-
showOverflowMenu();
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
const overflowMenuIsVisible = () => {
|
|
729
|
-
const toolbar = document.querySelector("#toolbar");
|
|
730
|
-
return toolbar.hasAttribute("data-overflow-menu-visible");
|
|
731
|
-
};
|
|
732
|
-
const showOverflowMenu = () => {
|
|
733
|
-
const toolbar = document.querySelector("#toolbar");
|
|
734
|
-
document.querySelector("#overflow-menu").setAttribute("data-animate", "");
|
|
735
|
-
toolbar.setAttribute("data-overflow-menu-visible", "");
|
|
736
|
-
};
|
|
737
|
-
const hideOverflowMenu = () => {
|
|
738
|
-
const toolbar = document.querySelector("#toolbar");
|
|
739
|
-
toolbar.removeAttribute("data-overflow-menu-visible");
|
|
740
|
-
document.querySelector("#overflow-menu").removeAttribute("data-animate");
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
const toolbarVisibilityPreference = createPreference("toolbar");
|
|
744
|
-
const renderToolbar = async () => {
|
|
745
|
-
const toolbarOverlay = document.querySelector("#toolbar-overlay");
|
|
746
|
-
toolbarOverlay.onclick = () => {
|
|
747
|
-
hideAllTooltip();
|
|
748
|
-
hideSettings();
|
|
749
|
-
};
|
|
750
|
-
const toolbarVisible = toolbarVisibilityPreference.has() ? toolbarVisibilityPreference.get() : true;
|
|
751
|
-
if (toolbarVisible) {
|
|
752
|
-
showToolbar({
|
|
753
|
-
animate: false
|
|
754
|
-
});
|
|
755
|
-
} else {
|
|
756
|
-
hideToolbar({
|
|
757
|
-
animate: false
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
setLinkHrefForParentWindow(document.querySelector(".toolbar-icon-wrapper"), "/");
|
|
761
|
-
renderToolbarNotification();
|
|
762
|
-
makeToolbarResponsive();
|
|
763
|
-
renderToolbarSettings();
|
|
764
|
-
renderToolbarAnimation();
|
|
765
|
-
renderToolbarTheme();
|
|
766
|
-
renderExecutionInToolbar();
|
|
767
|
-
// this might become active but we need to detect this somehow
|
|
768
|
-
deactivateToolbarSection(document.querySelector("#file-list-link"));
|
|
769
|
-
initToolbarEventSource();
|
|
770
|
-
|
|
771
|
-
// if user click enter or space quickly while closing toolbar
|
|
772
|
-
// it will cancel the closing
|
|
773
|
-
// that's why I used toggleToolbar and not hideToolbar
|
|
774
|
-
document.querySelector("#button-close-toolbar").onclick = () => toogleToolbar();
|
|
775
|
-
};
|
|
776
|
-
const toogleToolbar = () => {
|
|
777
|
-
if (toolbarIsVisible()) {
|
|
778
|
-
hideToolbar();
|
|
779
|
-
} else {
|
|
780
|
-
showToolbar();
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
const toolbarIsVisible = () => document.documentElement.hasAttribute("data-toolbar-visible");
|
|
784
|
-
let hideToolbar = () => {
|
|
785
|
-
// toolbar hidden by default, nothing to do to hide it by default
|
|
786
|
-
sendEventToParent("toolbar-visibility-change", false);
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
// (by the way it might be cool to have the toolbar auto show when)
|
|
790
|
-
// it has something to say (being disconnected from server)
|
|
791
|
-
const showToolbar = ({
|
|
792
|
-
animate = true
|
|
793
|
-
} = {}) => {
|
|
794
|
-
toolbarVisibilityPreference.set(true);
|
|
795
|
-
if (animate) {
|
|
796
|
-
document.documentElement.setAttribute("data-toolbar-animation", "");
|
|
797
|
-
} else {
|
|
798
|
-
document.documentElement.removeAttribute("data-toolbar-animation");
|
|
799
|
-
}
|
|
800
|
-
document.documentElement.setAttribute("data-toolbar-visible", "");
|
|
801
|
-
sendEventToParent("toolbar-visibility-change", true);
|
|
802
|
-
const toolbarIframe = getToolbarIframe();
|
|
803
|
-
const toolbarIframeParent = toolbarIframe.parentNode;
|
|
804
|
-
const parentWindow = window.parent;
|
|
805
|
-
const parentDocumentElement = parentWindow.document.compatMode === "CSS1Compat" ? parentWindow.document.documentElement : parentWindow.document.body;
|
|
806
|
-
const scrollYMax = parentDocumentElement.scrollHeight - parentWindow.innerHeight;
|
|
807
|
-
const scrollY = parentDocumentElement.scrollTop;
|
|
808
|
-
const scrollYRemaining = scrollYMax - scrollY;
|
|
809
|
-
setStyles(toolbarIframeParent, {
|
|
810
|
-
"transition-property": "padding-bottom",
|
|
811
|
-
"transition-duration": "300ms"
|
|
812
|
-
});
|
|
813
|
-
// maybe we should use js animation here because we would not conflict with css
|
|
814
|
-
const restoreToolbarIframeParentStyles = setStyles(toolbarIframeParent, {
|
|
815
|
-
"scroll-padding-bottom": "40px",
|
|
816
|
-
// same here we should add 40px
|
|
817
|
-
"padding-bottom": "40px" // if there is already one we should add 40px
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
const restoreToolbarIframeStyles = setStyles(toolbarIframe, {
|
|
821
|
-
height: "40px",
|
|
822
|
-
visibility: "visible"
|
|
823
|
-
});
|
|
824
|
-
if (scrollYRemaining < 40 && scrollYMax > 0) {
|
|
825
|
-
const scrollEnd = scrollY + 40;
|
|
826
|
-
startJavaScriptAnimation({
|
|
827
|
-
duration: 300,
|
|
828
|
-
onProgress: ({
|
|
829
|
-
progress
|
|
830
|
-
}) => {
|
|
831
|
-
const value = scrollY + (scrollEnd - scrollY) * progress;
|
|
832
|
-
parentDocumentElement.scrollTop = value;
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
hideToolbar = () => {
|
|
837
|
-
restoreToolbarIframeParentStyles();
|
|
838
|
-
restoreToolbarIframeStyles();
|
|
839
|
-
hideTooltip(document.querySelector("#eventsource-indicator"));
|
|
840
|
-
hideTooltip(document.querySelector("#execution-indicator"));
|
|
841
|
-
toolbarVisibilityPreference.set(false);
|
|
842
|
-
if (animate) {
|
|
843
|
-
document.documentElement.setAttribute("data-toolbar-animation", "");
|
|
844
|
-
} else {
|
|
845
|
-
document.documentElement.removeAttribute("data-toolbar-animation");
|
|
846
|
-
}
|
|
847
|
-
document.documentElement.removeAttribute("data-toolbar-visible");
|
|
848
|
-
sendEventToParent("toolbar-visibility-change", false);
|
|
849
|
-
};
|
|
850
|
-
};
|
|
851
|
-
const addExternalCommandCallback = (command, callback) => {
|
|
852
|
-
const messageEventCallback = messageEvent => {
|
|
853
|
-
const {
|
|
854
|
-
data
|
|
855
|
-
} = messageEvent;
|
|
856
|
-
if (typeof data !== "object") {
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
const {
|
|
860
|
-
__jsenv__
|
|
861
|
-
} = data;
|
|
862
|
-
if (!__jsenv__) {
|
|
863
|
-
return;
|
|
864
|
-
}
|
|
865
|
-
if (__jsenv__.command !== command) {
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
callback(...__jsenv__.args);
|
|
869
|
-
};
|
|
870
|
-
window.addEventListener("message", messageEventCallback);
|
|
871
|
-
return () => {
|
|
872
|
-
window.removeEventListener("message", messageEventCallback);
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
const sendEventToParent = (name, data) => {
|
|
876
|
-
window.parent.postMessage({
|
|
877
|
-
__jsenv__: {
|
|
878
|
-
event: name,
|
|
879
|
-
data
|
|
880
|
-
}
|
|
881
|
-
}, "*");
|
|
882
|
-
};
|
|
883
|
-
window.toolbar = {
|
|
884
|
-
show: showToolbar,
|
|
885
|
-
hide: () => hideToolbar()
|
|
886
|
-
};
|
|
887
|
-
|
|
888
|
-
// const { currentScript } = document
|
|
889
|
-
addExternalCommandCallback("renderToolbar", ({
|
|
890
|
-
logs
|
|
891
|
-
}) => {
|
|
892
|
-
renderToolbar();
|
|
893
|
-
});
|
|
894
|
-
addExternalCommandCallback("showToolbar", () => {
|
|
895
|
-
showToolbar();
|
|
896
|
-
});
|
|
897
|
-
addExternalCommandCallback("hideToolbar", () => {
|
|
898
|
-
hideToolbar();
|
|
899
|
-
});
|
|
900
|
-
sendEventToParent("toolbar_ready");
|