@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.
- package/README.md +3 -0
- package/dist/js/toolbar_core.js +17 -17
- package/dist/js/toolbar_injector.js +1 -46
- package/dist/jsenv_plugin_toolbar.js +1 -3
- package/package.json +2 -2
- package/src/client/core/animation_actions.js +5 -5
- package/src/client/core/animation_effects.js +6 -6
- package/src/client/core/animation_signals.js +4 -4
- package/src/client/core/changes_actions.js +5 -5
- package/src/client/core/changes_signals.js +2 -2
- package/src/client/core/execution_actions.js +16 -16
- package/src/client/core/execution_effects.js +10 -10
- package/src/client/core/execution_signals.js +6 -6
- package/src/client/core/notification_actions.js +31 -31
- package/src/client/core/notification_context.js +2 -1
- package/src/client/core/notification_effects.js +6 -6
- package/src/client/core/notification_signals.js +5 -5
- package/src/client/core/parent_window_actions.js +18 -18
- package/src/client/core/parent_window_context.js +5 -5
- package/src/client/core/parent_window_effects.js +9 -9
- package/src/client/core/parent_window_signals.js +17 -17
- package/src/client/core/server_actions.js +5 -5
- package/src/client/core/server_effects.js +6 -6
- package/src/client/core/server_signals.js +7 -7
- package/src/client/core/settings_actions.js +5 -5
- package/src/client/core/settings_signals.js +2 -2
- package/src/client/core/theme_actions.js +5 -5
- package/src/client/core/theme_effects.js +5 -5
- package/src/client/core/theme_signals.js +4 -4
- package/src/client/core/toolbar_logger.js +8 -8
- package/src/client/core/toolbar_open_actions.js +5 -5
- package/src/client/core/toolbar_open_effects.js +4 -4
- package/src/client/core/toolbar_open_signals.js +4 -4
- package/src/client/core/toolbar_state_context.js +1 -1
- package/src/client/core/toolbar_state_effects.js +7 -7
- package/src/client/core/toolbar_state_signals.js +11 -11
- package/src/client/core/tooltip_actions.js +5 -5
- package/src/client/toolbar_core.js +8 -8
- package/src/client/toolbar_injector.js +97 -97
- package/src/client/ui/changes_indicator/changes_indicator.js +33 -33
- package/src/client/ui/document_execution_indicator/document_execution_indicator.js +28 -28
- package/src/client/ui/document_index_link/document_index_link.js +3 -3
- package/src/client/ui/server_indicator/server_indicator.js +30 -30
- package/src/client/ui/toolbar_close_button/toolbar_close_button.js +6 -6
- package/src/client/ui/toolbar_menu_overflow/toolbar_menu_overflow.js +50 -50
- package/src/client/ui/toolbar_opening/toolbar_opening.js +35 -35
- package/src/client/ui/toolbar_overlay/toolbar_overlay.js +36 -36
- package/src/client/ui/toolbar_settings/toolbar_animation_setting.js +13 -13
- package/src/client/ui/toolbar_settings/toolbar_autoreload_setting.js +19 -19
- package/src/client/ui/toolbar_settings/toolbar_notification_setting.js +47 -47
- package/src/client/ui/toolbar_settings/toolbar_settings.js +29 -29
- package/src/client/ui/toolbar_settings/toolbar_theme_setting.js +8 -8
- package/src/client/ui/toolbar_ui.js +19 -19
- package/src/client/ui/util/animation.js +116 -116
- package/src/client/ui/util/dom.js +29 -29
- package/src/client/ui/util/fetch_using_xhr.js +184 -184
- package/src/client/ui/util/fetching.js +6 -6
- package/src/client/ui/util/iframe_to_parent_href.js +6 -6
- package/src/client/ui/util/responsive.js +48 -48
- package/src/client/ui/util/util.js +13 -13
- package/src/client/ui/variant.js +27 -27
- package/src/jsenv_plugin_toolbar.js +17 -17
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
export const createHorizontalBreakpoint = (breakpointValue) => {
|
|
2
|
-
return createBreakpoint(windowWidthMeasure, breakpointValue)
|
|
3
|
-
}
|
|
2
|
+
return createBreakpoint(windowWidthMeasure, breakpointValue);
|
|
3
|
+
};
|
|
4
4
|
|
|
5
5
|
const createMeasure = ({ compute, register }) => {
|
|
6
|
-
let currentValue = compute()
|
|
6
|
+
let currentValue = compute();
|
|
7
7
|
|
|
8
|
-
const get = () => compute()
|
|
8
|
+
const get = () => compute();
|
|
9
9
|
|
|
10
|
-
const changed = createSignal()
|
|
10
|
+
const changed = createSignal();
|
|
11
11
|
|
|
12
|
-
let unregister = () => {}
|
|
12
|
+
let unregister = () => {};
|
|
13
13
|
if (register) {
|
|
14
14
|
unregister = register(() => {
|
|
15
|
-
const value = compute()
|
|
15
|
+
const value = compute();
|
|
16
16
|
if (value !== currentValue) {
|
|
17
|
-
const previousValue = value
|
|
18
|
-
currentValue = value
|
|
19
|
-
changed.notify(value, previousValue)
|
|
17
|
+
const previousValue = value;
|
|
18
|
+
currentValue = value;
|
|
19
|
+
changed.notify(value, previousValue);
|
|
20
20
|
}
|
|
21
|
-
})
|
|
21
|
+
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
return { get, changed, unregister }
|
|
25
|
-
}
|
|
24
|
+
return { get, changed, unregister };
|
|
25
|
+
};
|
|
26
26
|
|
|
27
27
|
const createSignal = () => {
|
|
28
|
-
const callbackArray = []
|
|
28
|
+
const callbackArray = [];
|
|
29
29
|
|
|
30
30
|
const listen = (callback) => {
|
|
31
|
-
callbackArray.push(callback)
|
|
31
|
+
callbackArray.push(callback);
|
|
32
32
|
return () => {
|
|
33
|
-
const index = callbackArray.indexOf(callback)
|
|
33
|
+
const index = callbackArray.indexOf(callback);
|
|
34
34
|
if (index > -1) {
|
|
35
|
-
callbackArray.splice(index, 1)
|
|
35
|
+
callbackArray.splice(index, 1);
|
|
36
36
|
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
const notify = (...args) => {
|
|
41
41
|
callbackArray.slice().forEach((callback) => {
|
|
42
|
-
callback(...args)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
42
|
+
callback(...args);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
45
|
|
|
46
|
-
return { listen, notify }
|
|
47
|
-
}
|
|
46
|
+
return { listen, notify };
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
const windowWidthMeasure = createMeasure({
|
|
50
50
|
name: "window-width",
|
|
51
51
|
compute: () => window.innerWidth,
|
|
52
52
|
register: (onchange) => {
|
|
53
|
-
window.addEventListener("resize", onchange)
|
|
54
|
-
window.addEventListener("orientationchange", onchange)
|
|
53
|
+
window.addEventListener("resize", onchange);
|
|
54
|
+
window.addEventListener("orientationchange", onchange);
|
|
55
55
|
return () => {
|
|
56
|
-
window.removeEventListener("resize", onchange)
|
|
57
|
-
window.removeEventListener("orientationchange", onchange)
|
|
58
|
-
}
|
|
56
|
+
window.removeEventListener("resize", onchange);
|
|
57
|
+
window.removeEventListener("orientationchange", onchange);
|
|
58
|
+
};
|
|
59
59
|
},
|
|
60
|
-
})
|
|
60
|
+
});
|
|
61
61
|
|
|
62
62
|
const createBreakpoint = (measure, breakpointValue) => {
|
|
63
63
|
const getBreakpointState = () => {
|
|
64
|
-
const value = measure.get()
|
|
64
|
+
const value = measure.get();
|
|
65
65
|
|
|
66
66
|
if (value < breakpointValue) {
|
|
67
|
-
return "below"
|
|
67
|
+
return "below";
|
|
68
68
|
}
|
|
69
69
|
if (value > breakpointValue) {
|
|
70
|
-
return "above"
|
|
70
|
+
return "above";
|
|
71
71
|
}
|
|
72
|
-
return "equals"
|
|
73
|
-
}
|
|
72
|
+
return "equals";
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
let currentBreakpointState = getBreakpointState()
|
|
75
|
+
let currentBreakpointState = getBreakpointState();
|
|
76
76
|
|
|
77
77
|
const isAbove = () => {
|
|
78
|
-
return measure.get() > breakpointValue
|
|
79
|
-
}
|
|
78
|
+
return measure.get() > breakpointValue;
|
|
79
|
+
};
|
|
80
80
|
|
|
81
81
|
const isBelow = () => {
|
|
82
|
-
return measure.get() < breakpointValue
|
|
83
|
-
}
|
|
82
|
+
return measure.get() < breakpointValue;
|
|
83
|
+
};
|
|
84
84
|
|
|
85
|
-
const breakpointChanged = createSignal()
|
|
85
|
+
const breakpointChanged = createSignal();
|
|
86
86
|
|
|
87
87
|
measure.changed.listen(() => {
|
|
88
|
-
const breakpointState = getBreakpointState()
|
|
88
|
+
const breakpointState = getBreakpointState();
|
|
89
89
|
if (breakpointState !== currentBreakpointState) {
|
|
90
|
-
const breakpointStatePrevious = currentBreakpointState
|
|
91
|
-
currentBreakpointState = breakpointState
|
|
92
|
-
breakpointChanged.notify(breakpointState, breakpointStatePrevious)
|
|
90
|
+
const breakpointStatePrevious = currentBreakpointState;
|
|
91
|
+
currentBreakpointState = breakpointState;
|
|
92
|
+
breakpointChanged.notify(breakpointState, breakpointStatePrevious);
|
|
93
93
|
}
|
|
94
|
-
})
|
|
94
|
+
});
|
|
95
95
|
|
|
96
96
|
return {
|
|
97
97
|
isAbove,
|
|
98
98
|
isBelow,
|
|
99
99
|
changed: breakpointChanged,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
102
|
|
|
103
103
|
// const windowScrollTop = createMeasure({
|
|
104
104
|
// name: "window-scroll-top",
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export const createPromiseAndHooks = () => {
|
|
2
|
-
let resolve
|
|
3
|
-
let reject
|
|
2
|
+
let resolve;
|
|
3
|
+
let reject;
|
|
4
4
|
const promise = new Promise((res, rej) => {
|
|
5
|
-
resolve = res
|
|
6
|
-
reject = rej
|
|
7
|
-
})
|
|
8
|
-
promise.resolve = resolve
|
|
9
|
-
promise.reject = reject
|
|
10
|
-
return promise
|
|
11
|
-
}
|
|
5
|
+
resolve = res;
|
|
6
|
+
reject = rej;
|
|
7
|
+
});
|
|
8
|
+
promise.resolve = resolve;
|
|
9
|
+
promise.reject = reject;
|
|
10
|
+
return promise;
|
|
11
|
+
};
|
|
12
12
|
|
|
13
13
|
export const moveElement = (element, from, to) => {
|
|
14
|
-
to.appendChild(element)
|
|
15
|
-
}
|
|
14
|
+
to.appendChild(element);
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
export const replaceElement = (elementToReplace, otherElement) => {
|
|
18
|
-
elementToReplace.parentNode.replaceChild(otherElement, elementToReplace)
|
|
19
|
-
}
|
|
18
|
+
elementToReplace.parentNode.replaceChild(otherElement, elementToReplace);
|
|
19
|
+
};
|
package/src/client/ui/variant.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
export const enableVariant = (rootNode, variables) => {
|
|
2
2
|
const nodesNotMatching = Array.from(
|
|
3
3
|
rootNode.querySelectorAll(`[${attributeIndicatingACondition}]`),
|
|
4
|
-
)
|
|
4
|
+
);
|
|
5
5
|
nodesNotMatching.forEach((nodeNotMatching) => {
|
|
6
6
|
const conditionAttributeValue = nodeNotMatching.getAttribute(
|
|
7
7
|
attributeIndicatingACondition,
|
|
8
|
-
)
|
|
9
|
-
const matches = testCondition(conditionAttributeValue, variables)
|
|
8
|
+
);
|
|
9
|
+
const matches = testCondition(conditionAttributeValue, variables);
|
|
10
10
|
if (matches) {
|
|
11
11
|
renameAttribute(
|
|
12
12
|
nodeNotMatching,
|
|
13
13
|
attributeIndicatingACondition,
|
|
14
14
|
attributeIndicatingAMatch,
|
|
15
|
-
)
|
|
15
|
+
);
|
|
16
16
|
}
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
|
|
19
19
|
const nodesMatching = Array.from(
|
|
20
20
|
rootNode.querySelectorAll(`[${attributeIndicatingAMatch}]`),
|
|
21
|
-
)
|
|
21
|
+
);
|
|
22
22
|
nodesMatching.forEach((nodeMatching) => {
|
|
23
23
|
const conditionAttributeValue = nodeMatching.getAttribute(
|
|
24
24
|
attributeIndicatingAMatch,
|
|
25
|
-
)
|
|
26
|
-
const matches = testCondition(conditionAttributeValue, variables)
|
|
25
|
+
);
|
|
26
|
+
const matches = testCondition(conditionAttributeValue, variables);
|
|
27
27
|
if (!matches) {
|
|
28
28
|
renameAttribute(
|
|
29
29
|
nodeMatching,
|
|
30
30
|
attributeIndicatingAMatch,
|
|
31
31
|
attributeIndicatingACondition,
|
|
32
|
-
)
|
|
32
|
+
);
|
|
33
33
|
}
|
|
34
|
-
})
|
|
35
|
-
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
36
|
|
|
37
37
|
const testCondition = (conditionAttributeValue, variables) => {
|
|
38
|
-
const condition = parseCondition(conditionAttributeValue)
|
|
38
|
+
const condition = parseCondition(conditionAttributeValue);
|
|
39
39
|
return Object.keys(variables).some((key) => {
|
|
40
40
|
if (condition.key !== key) {
|
|
41
|
-
return false
|
|
41
|
+
return false;
|
|
42
42
|
}
|
|
43
43
|
// the condition do not specify a value, any value is ok
|
|
44
44
|
if (condition.value === undefined) {
|
|
45
|
-
return true
|
|
45
|
+
return true;
|
|
46
46
|
}
|
|
47
47
|
if (condition.value === variables[key]) {
|
|
48
|
-
return true
|
|
48
|
+
return true;
|
|
49
49
|
}
|
|
50
|
-
return false
|
|
51
|
-
})
|
|
52
|
-
}
|
|
50
|
+
return false;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
53
|
|
|
54
54
|
const parseCondition = (conditionAttributeValue) => {
|
|
55
|
-
const colonIndex = conditionAttributeValue.indexOf(":")
|
|
55
|
+
const colonIndex = conditionAttributeValue.indexOf(":");
|
|
56
56
|
if (colonIndex === -1) {
|
|
57
57
|
return {
|
|
58
58
|
key: conditionAttributeValue,
|
|
59
59
|
value: undefined,
|
|
60
|
-
}
|
|
60
|
+
};
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
63
63
|
key: conditionAttributeValue.slice(0, colonIndex),
|
|
64
64
|
value: conditionAttributeValue.slice(colonIndex + 1),
|
|
65
|
-
}
|
|
66
|
-
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
67
|
|
|
68
|
-
const attributeIndicatingACondition = `data-when
|
|
69
|
-
const attributeIndicatingAMatch = `data-when-active
|
|
68
|
+
const attributeIndicatingACondition = `data-when`;
|
|
69
|
+
const attributeIndicatingAMatch = `data-when-active`;
|
|
70
70
|
|
|
71
71
|
const renameAttribute = (node, name, newName) => {
|
|
72
|
-
node.setAttribute(newName, node.getAttribute(name))
|
|
73
|
-
node.removeAttribute(name)
|
|
74
|
-
}
|
|
72
|
+
node.setAttribute(newName, node.getAttribute(name));
|
|
73
|
+
node.removeAttribute(name);
|
|
74
|
+
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
stringifyHtmlAst,
|
|
4
4
|
injectHtmlNodeAsEarlyAsPossible,
|
|
5
5
|
createHtmlNode,
|
|
6
|
-
} from "@jsenv/ast"
|
|
6
|
+
} from "@jsenv/ast";
|
|
7
7
|
|
|
8
8
|
export const jsenvPluginToolbar = ({
|
|
9
9
|
logLevel = "warn",
|
|
@@ -16,11 +16,11 @@ export const jsenvPluginToolbar = ({
|
|
|
16
16
|
const toolbarInjectorClientFileUrl = new URL(
|
|
17
17
|
"./client/toolbar_injector.js",
|
|
18
18
|
import.meta.url,
|
|
19
|
-
).href
|
|
19
|
+
).href;
|
|
20
20
|
const toolbarHtmlClientFileUrl = new URL(
|
|
21
21
|
"./client/toolbar.html",
|
|
22
22
|
import.meta.url,
|
|
23
|
-
).href
|
|
23
|
+
).href;
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
26
|
name: "jsenv:toolbar",
|
|
@@ -28,20 +28,20 @@ export const jsenvPluginToolbar = ({
|
|
|
28
28
|
transformUrlContent: {
|
|
29
29
|
html: (urlInfo, context) => {
|
|
30
30
|
if (urlInfo.url.startsWith(toolbarHtmlClientFileUrl)) {
|
|
31
|
-
urlInfo.data.isJsenvToolbar = true
|
|
32
|
-
return null
|
|
31
|
+
urlInfo.data.isJsenvToolbar = true;
|
|
32
|
+
return null;
|
|
33
33
|
}
|
|
34
|
-
const htmlAst = parseHtmlString(urlInfo.content)
|
|
34
|
+
const htmlAst = parseHtmlString(urlInfo.content);
|
|
35
35
|
const [toolbarInjectorReference] = context.referenceUtils.inject({
|
|
36
36
|
type: "js_import",
|
|
37
37
|
expectedType: "js_module",
|
|
38
38
|
specifier: toolbarInjectorClientFileUrl,
|
|
39
|
-
})
|
|
39
|
+
});
|
|
40
40
|
const [toolbarClientFileReference] = context.referenceUtils.inject({
|
|
41
41
|
type: "iframe_src",
|
|
42
42
|
expectedType: "html",
|
|
43
43
|
specifier: toolbarHtmlClientFileUrl,
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
injectHtmlNodeAsEarlyAsPossible(
|
|
46
46
|
htmlAst,
|
|
47
47
|
createHtmlNode({
|
|
@@ -59,15 +59,15 @@ export const jsenvPluginToolbar = ({
|
|
|
59
59
|
}),
|
|
60
60
|
}),
|
|
61
61
|
"jsenv:toolbar",
|
|
62
|
-
)
|
|
63
|
-
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
62
|
+
);
|
|
63
|
+
const htmlModified = stringifyHtmlAst(htmlAst);
|
|
64
64
|
return {
|
|
65
65
|
content: htmlModified,
|
|
66
|
-
}
|
|
66
|
+
};
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
|
-
}
|
|
70
|
-
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
71
|
|
|
72
72
|
const generateCodeToInjectToolbar = ({
|
|
73
73
|
toolbarInjectorReference,
|
|
@@ -79,7 +79,7 @@ const generateCodeToInjectToolbar = ({
|
|
|
79
79
|
animationsEnabled,
|
|
80
80
|
notificationsEnabled,
|
|
81
81
|
}) => {
|
|
82
|
-
const from = toolbarInjectorReference.generatedSpecifier
|
|
82
|
+
const from = toolbarInjectorReference.generatedSpecifier;
|
|
83
83
|
const paramsSource = JSON.stringify(
|
|
84
84
|
{
|
|
85
85
|
toolbarUrl: toolbarClientFileReference.generatedSpecifier,
|
|
@@ -92,9 +92,9 @@ const generateCodeToInjectToolbar = ({
|
|
|
92
92
|
},
|
|
93
93
|
null,
|
|
94
94
|
" ",
|
|
95
|
-
)
|
|
95
|
+
);
|
|
96
96
|
|
|
97
97
|
return `import { injectToolbar } from ${from}
|
|
98
98
|
|
|
99
|
-
injectToolbar(${paramsSource})
|
|
100
|
-
}
|
|
99
|
+
injectToolbar(${paramsSource});`;
|
|
100
|
+
};
|