@jsenv/plugin-toolbar 0.1.14 → 1.0.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.
Files changed (62) hide show
  1. package/README.md +3 -0
  2. package/dist/js/toolbar_core.js +17 -17
  3. package/dist/js/toolbar_injector.js +1 -46
  4. package/dist/jsenv_plugin_toolbar.js +1 -3
  5. package/package.json +2 -2
  6. package/src/client/core/animation_actions.js +5 -5
  7. package/src/client/core/animation_effects.js +6 -6
  8. package/src/client/core/animation_signals.js +4 -4
  9. package/src/client/core/changes_actions.js +5 -5
  10. package/src/client/core/changes_signals.js +2 -2
  11. package/src/client/core/execution_actions.js +16 -16
  12. package/src/client/core/execution_effects.js +10 -10
  13. package/src/client/core/execution_signals.js +6 -6
  14. package/src/client/core/notification_actions.js +31 -31
  15. package/src/client/core/notification_context.js +2 -1
  16. package/src/client/core/notification_effects.js +6 -6
  17. package/src/client/core/notification_signals.js +5 -5
  18. package/src/client/core/parent_window_actions.js +18 -18
  19. package/src/client/core/parent_window_context.js +5 -5
  20. package/src/client/core/parent_window_effects.js +9 -9
  21. package/src/client/core/parent_window_signals.js +17 -17
  22. package/src/client/core/server_actions.js +5 -5
  23. package/src/client/core/server_effects.js +6 -6
  24. package/src/client/core/server_signals.js +7 -7
  25. package/src/client/core/settings_actions.js +5 -5
  26. package/src/client/core/settings_signals.js +2 -2
  27. package/src/client/core/theme_actions.js +5 -5
  28. package/src/client/core/theme_effects.js +5 -5
  29. package/src/client/core/theme_signals.js +4 -4
  30. package/src/client/core/toolbar_logger.js +8 -8
  31. package/src/client/core/toolbar_open_actions.js +5 -5
  32. package/src/client/core/toolbar_open_effects.js +4 -4
  33. package/src/client/core/toolbar_open_signals.js +4 -4
  34. package/src/client/core/toolbar_state_context.js +1 -1
  35. package/src/client/core/toolbar_state_effects.js +7 -7
  36. package/src/client/core/toolbar_state_signals.js +11 -11
  37. package/src/client/core/tooltip_actions.js +5 -5
  38. package/src/client/toolbar_core.js +8 -8
  39. package/src/client/toolbar_injector.js +97 -97
  40. package/src/client/ui/changes_indicator/changes_indicator.js +33 -33
  41. package/src/client/ui/document_execution_indicator/document_execution_indicator.js +28 -28
  42. package/src/client/ui/document_index_link/document_index_link.js +3 -3
  43. package/src/client/ui/server_indicator/server_indicator.js +30 -30
  44. package/src/client/ui/toolbar_close_button/toolbar_close_button.js +6 -6
  45. package/src/client/ui/toolbar_menu_overflow/toolbar_menu_overflow.js +50 -50
  46. package/src/client/ui/toolbar_opening/toolbar_opening.js +35 -35
  47. package/src/client/ui/toolbar_overlay/toolbar_overlay.js +36 -36
  48. package/src/client/ui/toolbar_settings/toolbar_animation_setting.js +13 -13
  49. package/src/client/ui/toolbar_settings/toolbar_autoreload_setting.js +19 -19
  50. package/src/client/ui/toolbar_settings/toolbar_notification_setting.js +47 -47
  51. package/src/client/ui/toolbar_settings/toolbar_settings.js +29 -29
  52. package/src/client/ui/toolbar_settings/toolbar_theme_setting.js +8 -8
  53. package/src/client/ui/toolbar_ui.js +19 -19
  54. package/src/client/ui/util/animation.js +116 -116
  55. package/src/client/ui/util/dom.js +29 -29
  56. package/src/client/ui/util/fetch_using_xhr.js +184 -184
  57. package/src/client/ui/util/fetching.js +6 -6
  58. package/src/client/ui/util/iframe_to_parent_href.js +6 -6
  59. package/src/client/ui/util/responsive.js +48 -48
  60. package/src/client/ui/util/util.js +13 -13
  61. package/src/client/ui/variant.js +27 -27
  62. package/src/jsenv_plugin_toolbar.js +17 -17
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @jsenv/plugin-toolbar [![npm package](https://img.shields.io/npm/v/@jsenv/plugin-toolbar.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/plugin-toolbar)
2
+
3
+ [Documentation](<https://github.com/jsenv/core/wiki/A)-Getting-started>) · [Changelog](./CHANGELOG.md)
@@ -1,8 +1,8 @@
1
1
  var l$2;
2
2
  l$2 = {
3
3
  __e: function (n, l, u, i) {
4
- for (var t, r, o; l = l.__;) if ((t = l.__c) && !t.__) try {
5
- if ((r = t.constructor) && null != r.getDerivedStateFromError && (t.setState(r.getDerivedStateFromError(n)), o = t.__d), null != t.componentDidCatch && (t.componentDidCatch(n, i || {}), o = t.__d), o) return t.__E = t;
4
+ for (var t, o, r; l = l.__;) if ((t = l.__c) && !t.__) try {
5
+ if ((o = t.constructor) && null != o.getDerivedStateFromError && (t.setState(o.getDerivedStateFromError(n)), r = t.__d), null != t.componentDidCatch && (t.componentDidCatch(n, i || {}), r = t.__d), r) return t.__E = t;
6
6
  } catch (l) {
7
7
  n = l;
8
8
  }
@@ -748,24 +748,24 @@ const notifyExecutionResult = (execution, previousExecution) => {
748
748
  if (previousExecution.status === "completed") {
749
749
  notify("Broken", {
750
750
  ...notificationOptions,
751
- body: `${executedFileRelativeUrl} execution now failing.`
751
+ body: "".concat(executedFileRelativeUrl, " execution now failing.")
752
752
  });
753
753
  } else {
754
754
  notify("Still failing", {
755
755
  ...notificationOptions,
756
- body: `${executedFileRelativeUrl} execution still failing.`
756
+ body: "".concat(executedFileRelativeUrl, " execution still failing.")
757
757
  });
758
758
  }
759
759
  } else {
760
760
  notify("Failing", {
761
761
  ...notificationOptions,
762
- body: `${executedFileRelativeUrl} execution failed.`
762
+ body: "".concat(executedFileRelativeUrl, " execution failed.")
763
763
  });
764
764
  }
765
765
  } else if (previousExecution && previousExecution.status === "failed") {
766
766
  notify("Fixed", {
767
767
  ...notificationOptions,
768
- body: `${executedFileRelativeUrl} execution fixed.`
768
+ body: "".concat(executedFileRelativeUrl, " execution fixed.")
769
769
  });
770
770
  }
771
771
  };
@@ -1279,7 +1279,7 @@ const renderDocumentIndexLink = () => {
1279
1279
  };
1280
1280
 
1281
1281
  const enableVariant = (rootNode, variables) => {
1282
- const nodesNotMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingACondition}]`));
1282
+ const nodesNotMatching = Array.from(rootNode.querySelectorAll("[".concat(attributeIndicatingACondition, "]")));
1283
1283
  nodesNotMatching.forEach(nodeNotMatching => {
1284
1284
  const conditionAttributeValue = nodeNotMatching.getAttribute(attributeIndicatingACondition);
1285
1285
  const matches = testCondition(conditionAttributeValue, variables);
@@ -1287,7 +1287,7 @@ const enableVariant = (rootNode, variables) => {
1287
1287
  renameAttribute(nodeNotMatching, attributeIndicatingACondition, attributeIndicatingAMatch);
1288
1288
  }
1289
1289
  });
1290
- const nodesMatching = Array.from(rootNode.querySelectorAll(`[${attributeIndicatingAMatch}]`));
1290
+ const nodesMatching = Array.from(rootNode.querySelectorAll("[".concat(attributeIndicatingAMatch, "]")));
1291
1291
  nodesMatching.forEach(nodeMatching => {
1292
1292
  const conditionAttributeValue = nodeMatching.getAttribute(attributeIndicatingAMatch);
1293
1293
  const matches = testCondition(conditionAttributeValue, variables);
@@ -1325,8 +1325,8 @@ const parseCondition = conditionAttributeValue => {
1325
1325
  value: conditionAttributeValue.slice(colonIndex + 1)
1326
1326
  };
1327
1327
  };
1328
- const attributeIndicatingACondition = `data-when`;
1329
- const attributeIndicatingAMatch = `data-when-active`;
1328
+ const attributeIndicatingACondition = "data-when";
1329
+ const attributeIndicatingAMatch = "data-when-active";
1330
1330
  const renameAttribute = (node, name, newName) => {
1331
1331
  node.setAttribute(newName, node.getAttribute(name));
1332
1332
  node.removeAttribute(name);
@@ -1379,10 +1379,10 @@ const computeText = ({
1379
1379
  endTime
1380
1380
  }) => {
1381
1381
  if (status === "completed") {
1382
- return `Execution completed in ${endTime - startTime}ms`;
1382
+ return "Execution completed in ".concat(endTime - startTime, "ms");
1383
1383
  }
1384
1384
  if (status === "failed") {
1385
- return `Execution failed in ${endTime - startTime}ms`;
1385
+ return "Execution failed in ".concat(endTime - startTime, "ms");
1386
1386
  }
1387
1387
  if (status === "running") {
1388
1388
  return "Executing...";
@@ -1468,9 +1468,9 @@ const computeTooltipText = ({
1468
1468
  }) => {
1469
1469
  const changesCount = changes.length;
1470
1470
  if (changesCount === 1) {
1471
- return `There is <a href="javascript:void(0)">1</a> change to apply`;
1471
+ return "There is <a href=\"javascript:void(0)\">1</a> change to apply";
1472
1472
  }
1473
- return `There is <a href="javascript:void(0)">${changesCount}<a> changes to apply`;
1473
+ return "There is <a href=\"javascript:void(0)\">".concat(changesCount, "<a> changes to apply");
1474
1474
  };
1475
1475
 
1476
1476
  const parentServerEvents = window.parent.__server_events__;
@@ -1546,7 +1546,7 @@ const renderToolbarAutoreloadSetting = () => {
1546
1546
  };
1547
1547
  const disableAutoreloadSetting = () => {
1548
1548
  document.querySelector(".settings_autoreload").setAttribute("data-disabled", "true");
1549
- document.querySelector(".settings_autoreload").setAttribute("title", `Autoreload not enabled on server`);
1549
+ document.querySelector(".settings_autoreload").setAttribute("title", "Autoreload not enabled on server");
1550
1550
  document.querySelector("#toggle_autoreload").disabled = true;
1551
1551
  };
1552
1552
 
@@ -1641,7 +1641,7 @@ const renderToolbarNotificationSetting = () => {
1641
1641
  const applyNotificationNotAvailableEffects = () => {
1642
1642
  const notifSetting = document.querySelector(".settings_notification");
1643
1643
  notifSetting.setAttribute("data-disabled", "true");
1644
- notifSetting.setAttribute("title", `Notification not available in the browser`);
1644
+ notifSetting.setAttribute("title", "Notification not available in the browser");
1645
1645
  notifCheckbox.disabled = true;
1646
1646
  };
1647
1647
  const applyNotificationDefaultEffects = () => {
@@ -1654,7 +1654,7 @@ const applyNotificationDeniedEffects = () => {
1654
1654
  applyNotificationNOTGrantedEffects();
1655
1655
  const notifSetting = document.querySelector(".settings_notification");
1656
1656
  notifSetting.setAttribute("data-disabled", "true");
1657
- notifSetting.setAttribute("title", `Notification denied`);
1657
+ notifSetting.setAttribute("title", "Notification denied");
1658
1658
  };
1659
1659
  const applyNotificationGrantedEffects = () => {
1660
1660
  enableVariant(document.querySelector(".notification_text"), {
@@ -80,52 +80,7 @@ const injectToolbar = async ({
80
80
  });
81
81
  });
82
82
  const div = document.createElement("div");
83
- div.innerHTML = `
84
- <div id="jsenv_toolbar_trigger" style="display:none">
85
- <svg id="jsenv_toolbar_trigger_icon">
86
- <use xlink:href="${jsenvLogoSvgUrl}#jsenv_logo"></use>
87
- </svg>
88
- <style>
89
- #jsenv_toolbar_trigger {
90
- display: block;
91
- overflow: hidden;
92
- position: fixed;
93
- z-index: 1000;
94
- bottom: -32px;
95
- right: 20px;
96
- height: 40px;
97
- width: 40px;
98
- padding: 0;
99
- margin: 0;
100
- border-radius: 5px 5px 0 0;
101
- border: 1px solid rgba(0, 0, 0, 0.33);
102
- border-bottom: none;
103
- box-shadow: 0px 0px 6px 2px rgba(0, 0, 0, 0.46);
104
- background: transparent;
105
- text-align: center;
106
- transition: 600ms;
107
- }
108
-
109
- #jsenv_toolbar_trigger:hover {
110
- cursor: pointer;
111
- }
112
-
113
- #jsenv_toolbar_trigger[data-expanded] {
114
- bottom: 0;
115
- }
116
-
117
- #jsenv_toolbar_trigger_icon {
118
- width: 35px;
119
- height: 35px;
120
- opacity: 0;
121
- transition: 600ms;
122
- }
123
-
124
- #jsenv_toolbar_trigger[data-expanded] #jsenv_toolbar_trigger_icon {
125
- opacity: 1;
126
- }
127
- </style>
128
- </div>`;
83
+ div.innerHTML = "\n<div id=\"jsenv_toolbar_trigger\" style=\"display:none\">\n <svg id=\"jsenv_toolbar_trigger_icon\">\n <use xlink:href=\"".concat(jsenvLogoSvgUrl, "#jsenv_logo\"></use>\n </svg>\n <style>\n #jsenv_toolbar_trigger {\n display: block;\n overflow: hidden;\n position: fixed;\n z-index: 1000;\n bottom: -32px;\n right: 20px;\n height: 40px;\n width: 40px;\n padding: 0;\n margin: 0;\n border-radius: 5px 5px 0 0;\n border: 1px solid rgba(0, 0, 0, 0.33);\n border-bottom: none;\n box-shadow: 0px 0px 6px 2px rgba(0, 0, 0, 0.46);\n background: transparent;\n text-align: center;\n transition: 600ms;\n }\n\n #jsenv_toolbar_trigger:hover {\n cursor: pointer;\n }\n\n #jsenv_toolbar_trigger[data-expanded] {\n bottom: 0;\n }\n\n #jsenv_toolbar_trigger_icon {\n width: 35px;\n height: 35px;\n opacity: 0;\n transition: 600ms;\n }\n\n #jsenv_toolbar_trigger[data-expanded] #jsenv_toolbar_trigger_icon {\n opacity: 1;\n }\n </style>\n</div>");
129
84
  const toolbarTrigger = div.firstElementChild;
130
85
  iframe.parentNode.appendChild(toolbarTrigger);
131
86
  let timer;
@@ -72,9 +72,7 @@ const generateCodeToInjectToolbar = ({
72
72
  animationsEnabled,
73
73
  notificationsEnabled
74
74
  }, null, " ");
75
- return `import { injectToolbar } from ${from}
76
-
77
- injectToolbar(${paramsSource});`;
75
+ return "import { injectToolbar } from ".concat(from, "\n\ninjectToolbar(").concat(paramsSource, ");");
78
76
  };
79
77
 
80
78
  export { jsenvPluginToolbar };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-toolbar",
3
- "version": "0.1.14",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "/src/"
27
27
  ],
28
28
  "dependencies": {
29
- "@jsenv/ast": "3.0.7",
29
+ "@jsenv/ast": "4.0.0",
30
30
  "@preact/signals": "1.1.3"
31
31
  },
32
32
  "scripts": {
@@ -1,8 +1,8 @@
1
- import { animationsEnabledSignal } from "./animation_signals.js"
1
+ import { animationsEnabledSignal } from "./animation_signals.js";
2
2
 
3
3
  export const enableAnimations = () => {
4
- animationsEnabledSignal.value = true
5
- }
4
+ animationsEnabledSignal.value = true;
5
+ };
6
6
  export const disableAnimations = () => {
7
- animationsEnabledSignal.value = false
8
- }
7
+ animationsEnabledSignal.value = false;
8
+ };
@@ -1,12 +1,12 @@
1
- import { effect } from "@preact/signals"
1
+ import { effect } from "@preact/signals";
2
2
 
3
- import { animationsEnabledSignal } from "./animation_signals.js"
3
+ import { animationsEnabledSignal } from "./animation_signals.js";
4
4
 
5
5
  effect(() => {
6
- const animationsEnabled = animationsEnabledSignal.value
6
+ const animationsEnabled = animationsEnabledSignal.value;
7
7
  if (animationsEnabled) {
8
- document.documentElement.removeAttribute("data-animation-disabled")
8
+ document.documentElement.removeAttribute("data-animation-disabled");
9
9
  } else {
10
- document.documentElement.setAttribute("data-animation-disabled", "")
10
+ document.documentElement.setAttribute("data-animation-disabled", "");
11
11
  }
12
- })
12
+ });
@@ -1,7 +1,7 @@
1
- import { signal } from "@preact/signals"
1
+ import { signal } from "@preact/signals";
2
2
 
3
- import { paramsFromParentWindow } from "./parent_window_context.js"
4
- import { stateFromLocalStorage } from "./toolbar_state_context.js"
3
+ import { paramsFromParentWindow } from "./parent_window_context.js";
4
+ import { stateFromLocalStorage } from "./toolbar_state_context.js";
5
5
 
6
6
  export const animationsEnabledSignal = signal(
7
7
  typeof stateFromLocalStorage.animationsEnabled === "boolean"
@@ -9,4 +9,4 @@ export const animationsEnabledSignal = signal(
9
9
  : typeof paramsFromParentWindow.animationsEnabled === "boolean"
10
10
  ? paramsFromParentWindow.animationsEnabled
11
11
  : false,
12
- )
12
+ );
@@ -1,9 +1,9 @@
1
- import { changesTooltipOpenedSignal } from "./changes_signals.js"
1
+ import { changesTooltipOpenedSignal } from "./changes_signals.js";
2
2
 
3
3
  export const openChangesToolip = () => {
4
- changesTooltipOpenedSignal.value = true
5
- }
4
+ changesTooltipOpenedSignal.value = true;
5
+ };
6
6
 
7
7
  export const closeChangesToolip = () => {
8
- changesTooltipOpenedSignal.value = false
9
- }
8
+ changesTooltipOpenedSignal.value = false;
9
+ };
@@ -1,3 +1,3 @@
1
- import { signal } from "@preact/signals"
1
+ import { signal } from "@preact/signals";
2
2
 
3
- export const changesTooltipOpenedSignal = signal(false)
3
+ export const changesTooltipOpenedSignal = signal(false);
@@ -1,50 +1,50 @@
1
- import { executionTooltipOpenedSignal } from "./execution_signals.js"
2
- import { notify } from "./notification_actions.js"
1
+ import { executionTooltipOpenedSignal } from "./execution_signals.js";
2
+ import { notify } from "./notification_actions.js";
3
3
 
4
4
  export const openExecutionTooltip = () => {
5
- executionTooltipOpenedSignal.value = true
6
- }
5
+ executionTooltipOpenedSignal.value = true;
6
+ };
7
7
 
8
8
  export const closeExecutionTooltip = () => {
9
- executionTooltipOpenedSignal.value = false
10
- }
9
+ executionTooltipOpenedSignal.value = false;
10
+ };
11
11
 
12
12
  export const notifyExecutionResult = (execution, previousExecution) => {
13
- const executedFileRelativeUrl = window.location.href
13
+ const executedFileRelativeUrl = window.location.href;
14
14
  const notificationOptions = {
15
15
  lang: "en",
16
16
  icon: getFaviconHref(),
17
17
  clickToFocus: true,
18
18
  clickToClose: true,
19
- }
19
+ };
20
20
  if (execution.status === "failed") {
21
21
  if (previousExecution) {
22
22
  if (previousExecution.status === "completed") {
23
23
  notify("Broken", {
24
24
  ...notificationOptions,
25
25
  body: `${executedFileRelativeUrl} execution now failing.`,
26
- })
26
+ });
27
27
  } else {
28
28
  notify("Still failing", {
29
29
  ...notificationOptions,
30
30
  body: `${executedFileRelativeUrl} execution still failing.`,
31
- })
31
+ });
32
32
  }
33
33
  } else {
34
34
  notify("Failing", {
35
35
  ...notificationOptions,
36
36
  body: `${executedFileRelativeUrl} execution failed.`,
37
- })
37
+ });
38
38
  }
39
39
  } else if (previousExecution && previousExecution.status === "failed") {
40
40
  notify("Fixed", {
41
41
  ...notificationOptions,
42
42
  body: `${executedFileRelativeUrl} execution fixed.`,
43
- })
43
+ });
44
44
  }
45
- }
45
+ };
46
46
 
47
47
  const getFaviconHref = () => {
48
- const link = document.querySelector('link[rel="icon"]')
49
- return link ? link.href : undefined
50
- }
48
+ const link = document.querySelector('link[rel="icon"]');
49
+ return link ? link.href : undefined;
50
+ };
@@ -1,22 +1,22 @@
1
- import { effect } from "@preact/signals"
1
+ import { effect } from "@preact/signals";
2
2
 
3
3
  import {
4
4
  executionSignal,
5
5
  previousExecutionSignal,
6
- } from "./execution_signals.js"
7
- import { notifyExecutionResult } from "./execution_actions.js"
6
+ } from "./execution_signals.js";
7
+ import { notifyExecutionResult } from "./execution_actions.js";
8
8
 
9
9
  effect(() => {
10
- const execution = executionSignal.value
10
+ const execution = executionSignal.value;
11
11
  if (execution) {
12
- sessionStorage.setItem(window.location.href, JSON.stringify(execution))
12
+ sessionStorage.setItem(window.location.href, JSON.stringify(execution));
13
13
  }
14
- })
14
+ });
15
15
 
16
16
  effect(() => {
17
- const execution = executionSignal.value
18
- const previousExecution = previousExecutionSignal.value
17
+ const execution = executionSignal.value;
18
+ const previousExecution = previousExecutionSignal.value;
19
19
  if (execution) {
20
- notifyExecutionResult(execution, previousExecution)
20
+ notifyExecutionResult(execution, previousExecution);
21
21
  }
22
- })
22
+ });
@@ -1,19 +1,19 @@
1
- import { signal } from "@preact/signals"
1
+ import { signal } from "@preact/signals";
2
2
 
3
- export const executionTooltipOpenedSignal = signal(false)
3
+ export const executionTooltipOpenedSignal = signal(false);
4
4
 
5
5
  export const executionSignal = signal({
6
6
  status: "running",
7
- })
7
+ });
8
8
 
9
9
  export const previousExecutionSignal = signal(
10
10
  sessionStorage.hasOwnProperty(window.location.href)
11
11
  ? JSON.parse(sessionStorage.getItem(window.location.href))
12
12
  : null,
13
- )
13
+ );
14
14
 
15
15
  window.parent.__supervisor__
16
16
  .getDocumentExecutionResult()
17
17
  .then(({ status, startTime, endTime }) => {
18
- executionSignal.value = { status, startTime, endTime }
19
- })
18
+ executionSignal.value = { status, startTime, endTime };
19
+ });
@@ -1,32 +1,32 @@
1
- import { notificationAPIDetected } from "./notification_context.js"
1
+ import { notificationAPIDetected } from "./notification_context.js";
2
2
  import {
3
3
  notificationsEnabledSignal,
4
4
  notificationPermissionSignal,
5
- } from "./notification_signals.js"
5
+ } from "./notification_signals.js";
6
6
 
7
7
  export const enableNotifications = () => {
8
- notificationsEnabledSignal.value = true
9
- }
8
+ notificationsEnabledSignal.value = true;
9
+ };
10
10
 
11
11
  export const disableNotifications = () => {
12
- notificationsEnabledSignal.value = false
13
- }
12
+ notificationsEnabledSignal.value = false;
13
+ };
14
14
 
15
- const arrayOfOpenedNotifications = []
15
+ const arrayOfOpenedNotifications = [];
16
16
  export const notify = notificationAPIDetected
17
17
  ? async (
18
18
  title,
19
19
  { clickToFocus = false, clickToClose = false, ...options } = {},
20
20
  ) => {
21
- const notificationsEnabled = notificationsEnabledSignal.value
21
+ const notificationsEnabled = notificationsEnabledSignal.value;
22
22
  if (!notificationsEnabled) {
23
- return null
23
+ return null;
24
24
  }
25
25
  if (Notification.permission !== "granted") {
26
- return null
26
+ return null;
27
27
  }
28
- const notification = new Notification(title, options)
29
- arrayOfOpenedNotifications.push(notification)
28
+ const notification = new Notification(title, options);
29
+ arrayOfOpenedNotifications.push(notification);
30
30
  notification.onclick = () => {
31
31
  // but if the user navigated inbetween
32
32
  // focusing window will show something else
@@ -36,36 +36,36 @@ export const notify = notificationAPIDetected
36
36
  // we could also navigauate to this file execution but
37
37
  // there is no guarantee re-executing the file would give same output
38
38
  // and it would also trigger an other notification
39
- if (clickToFocus) window.focus()
40
- if (clickToClose) notification.close()
41
- }
39
+ if (clickToFocus) window.focus();
40
+ if (clickToClose) notification.close();
41
+ };
42
42
  notification.onclose = () => {
43
- const index = arrayOfOpenedNotifications.indexOf(notification)
43
+ const index = arrayOfOpenedNotifications.indexOf(notification);
44
44
  if (index > -1) {
45
- arrayOfOpenedNotifications.splice(index, 1)
45
+ arrayOfOpenedNotifications.splice(index, 1);
46
46
  }
47
- }
48
- return notification
47
+ };
48
+ return notification;
49
49
  }
50
- : () => {}
50
+ : () => {};
51
51
 
52
52
  export const closeAllNotifications = () => {
53
53
  // slice because arrayOfOpenedNotifications can be mutated while looping
54
54
  arrayOfOpenedNotifications.slice().forEach((notification) => {
55
- notification.close()
56
- })
57
- }
55
+ notification.close();
56
+ });
57
+ };
58
58
 
59
- let requestPromise
59
+ let requestPromise;
60
60
  export const requestPermission = notificationAPIDetected
61
61
  ? async () => {
62
62
  if (requestPromise) {
63
- await requestPromise
64
- return
63
+ await requestPromise;
64
+ return;
65
65
  }
66
- requestPromise = Notification.requestPermission()
67
- await requestPromise
68
- requestPromise = undefined
69
- notificationPermissionSignal.value = Notification.permission
66
+ requestPromise = Notification.requestPermission();
67
+ await requestPromise;
68
+ requestPromise = undefined;
69
+ notificationPermissionSignal.value = Notification.permission;
70
70
  }
71
- : () => Promise.resolve()
71
+ : () => Promise.resolve();
@@ -1 +1,2 @@
1
- export const notificationAPIDetected = typeof window.Notification === "function"
1
+ export const notificationAPIDetected =
2
+ typeof window.Notification === "function";
@@ -1,11 +1,11 @@
1
- import { effect } from "@preact/signals"
1
+ import { effect } from "@preact/signals";
2
2
 
3
- import { notificationsEnabledSignal } from "./notification_signals.js"
4
- import { closeAllNotifications } from "./notification_actions.js"
3
+ import { notificationsEnabledSignal } from "./notification_signals.js";
4
+ import { closeAllNotifications } from "./notification_actions.js";
5
5
 
6
6
  effect(() => {
7
- const notificationsEnabled = notificationsEnabledSignal.value
7
+ const notificationsEnabled = notificationsEnabledSignal.value;
8
8
  if (!notificationsEnabled) {
9
- closeAllNotifications()
9
+ closeAllNotifications();
10
10
  }
11
- })
11
+ });
@@ -1,7 +1,7 @@
1
- import { signal } from "@preact/signals"
1
+ import { signal } from "@preact/signals";
2
2
 
3
- import { paramsFromParentWindow } from "./parent_window_context.js"
4
- import { stateFromLocalStorage } from "./toolbar_state_context.js"
3
+ import { paramsFromParentWindow } from "./parent_window_context.js";
4
+ import { stateFromLocalStorage } from "./toolbar_state_context.js";
5
5
 
6
6
  export const notificationsEnabledSignal = signal(
7
7
  typeof stateFromLocalStorage.notificationsEnabled === "boolean"
@@ -9,5 +9,5 @@ export const notificationsEnabledSignal = signal(
9
9
  : typeof paramsFromParentWindow.notificationsEnabled === "boolean"
10
10
  ? paramsFromParentWindow.notificationsEnabled
11
11
  : false,
12
- )
13
- export const notificationPermissionSignal = signal(Notification.permission)
12
+ );
13
+ export const notificationPermissionSignal = signal(Notification.permission);
@@ -1,4 +1,4 @@
1
- import { parentWindowReloader } from "./parent_window_context.js"
1
+ import { parentWindowReloader } from "./parent_window_context.js";
2
2
 
3
3
  export const sendEventToParent = (name, data) => {
4
4
  window.parent.postMessage(
@@ -9,35 +9,35 @@ export const sendEventToParent = (name, data) => {
9
9
  },
10
10
  },
11
11
  "*",
12
- )
13
- }
12
+ );
13
+ };
14
14
 
15
15
  export const addExternalCommandCallback = (command, callback) => {
16
16
  const messageEventCallback = (messageEvent) => {
17
- const { data } = messageEvent
17
+ const { data } = messageEvent;
18
18
  if (typeof data !== "object") {
19
- return
19
+ return;
20
20
  }
21
- const { __jsenv__ } = data
21
+ const { __jsenv__ } = data;
22
22
  if (!__jsenv__) {
23
- return
23
+ return;
24
24
  }
25
25
  if (__jsenv__.command !== command) {
26
- return
26
+ return;
27
27
  }
28
- callback(...__jsenv__.args)
29
- }
28
+ callback(...__jsenv__.args);
29
+ };
30
30
 
31
- window.addEventListener("message", messageEventCallback)
31
+ window.addEventListener("message", messageEventCallback);
32
32
  return () => {
33
- window.removeEventListener("message", messageEventCallback)
34
- }
35
- }
33
+ window.removeEventListener("message", messageEventCallback);
34
+ };
35
+ };
36
36
 
37
37
  export const enableAutoreload = () => {
38
- parentWindowReloader.autoreload.enable()
39
- }
38
+ parentWindowReloader.autoreload.enable();
39
+ };
40
40
 
41
41
  export const disableAutoreload = () => {
42
- parentWindowReloader.autoreload.disable()
43
- }
42
+ parentWindowReloader.autoreload.disable();
43
+ };
@@ -1,7 +1,7 @@
1
- export const paramsFromParentWindow = {}
2
- const searchParams = new URLSearchParams(window.location.search)
1
+ export const paramsFromParentWindow = {};
2
+ const searchParams = new URLSearchParams(window.location.search);
3
3
  searchParams.forEach((value, key) => {
4
- paramsFromParentWindow[key] = value === "" ? true : value
5
- })
4
+ paramsFromParentWindow[key] = value === "" ? true : value;
5
+ });
6
6
 
7
- export const parentWindowReloader = window.parent.__reloader__
7
+ export const parentWindowReloader = window.parent.__reloader__;