@lukaskj/xmonkey 2.1.1 → 2.2.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/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +29 -0
- package/dist/styles/_xmonkey-wrapper.scss +17 -4
- package/dist/types.d.ts +1 -1
- package/dist/utils/get-storage-key-id-from-string.d.ts +1 -0
- package/dist/utils/get-storage-key-id-from-string.js +3 -0
- package/dist/x-monkey-window-component.js +6 -3
- package/package.json +5 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useCallback, useState, useEffect } from "preact/hooks";
|
|
2
|
+
export function useLocalStorage(key, defaultValue) {
|
|
3
|
+
return useStorage(key, defaultValue, window.localStorage);
|
|
4
|
+
}
|
|
5
|
+
export function useSessionStorage(key, defaultValue) {
|
|
6
|
+
return useStorage(key, defaultValue, window.sessionStorage);
|
|
7
|
+
}
|
|
8
|
+
function useStorage(key, defaultValue, storageObject) {
|
|
9
|
+
const [value, setValue] = useState(() => {
|
|
10
|
+
const jsonValue = storageObject.getItem(key);
|
|
11
|
+
if (jsonValue != null)
|
|
12
|
+
return JSON.parse(jsonValue);
|
|
13
|
+
if (typeof defaultValue === "function") {
|
|
14
|
+
return defaultValue();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return storageObject.removeItem(key);
|
|
23
|
+
storageObject.setItem(key, JSON.stringify(value));
|
|
24
|
+
}, [key, value, storageObject]);
|
|
25
|
+
const remove = useCallback(() => {
|
|
26
|
+
setValue(undefined);
|
|
27
|
+
}, []);
|
|
28
|
+
return [value, setValue, remove];
|
|
29
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
##{vars.$xmonkey-wrapper} {
|
|
5
5
|
min-width: 200px;
|
|
6
|
+
width: 200px;
|
|
6
7
|
position: absolute;
|
|
7
8
|
top: 10px;
|
|
8
9
|
left: 10px;
|
|
@@ -38,12 +39,24 @@
|
|
|
38
39
|
margin-right: 2px;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
transition:
|
|
43
|
+
height 100ms ease-in-out,
|
|
44
|
+
width 100ms ease-in-out,
|
|
45
|
+
min-width 100ms ease-in-out,
|
|
46
|
+
min-height 100ms ease-in-out,
|
|
47
|
+
max-height 100ms ease-in-out,
|
|
48
|
+
max-width 100ms ease-in-out;
|
|
49
|
+
|
|
50
|
+
&:has(.minim) {
|
|
51
|
+
min-height: 15px !important;
|
|
52
|
+
min-width: 15px !important;
|
|
53
|
+
width: 15px !important;
|
|
54
|
+
height: 15px !important;
|
|
55
|
+
overflow: hidden !important;
|
|
56
|
+
}
|
|
57
|
+
|
|
41
58
|
.#{vars.$xmonkey-container} {
|
|
42
59
|
max-height: 1000px;
|
|
43
|
-
transition: max-height 70ms;
|
|
44
|
-
&:has(.b-collapsed) {
|
|
45
|
-
max-height: 15px;
|
|
46
|
-
}
|
|
47
60
|
&:has(.#{vars.$xmonkey-header}) {
|
|
48
61
|
margin-top: 0;
|
|
49
62
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getStorageKeyIdFromString(data: string): string;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useSessionStorage } from "./hooks";
|
|
3
|
+
import { useMemo } from "preact/hooks";
|
|
4
|
+
import { getStorageKeyIdFromString } from "./utils/get-storage-key-id-from-string";
|
|
3
5
|
export function XMonkeyWindowComponent(props) {
|
|
4
|
-
const
|
|
6
|
+
const storageKey = useMemo(() => getStorageKeyIdFromString(props.title), [props.title]);
|
|
7
|
+
const [minimized, setMinimized] = useSessionStorage(storageKey, false);
|
|
5
8
|
function toggleMinimize() {
|
|
6
9
|
setMinimized(!minimized);
|
|
7
10
|
}
|
|
8
|
-
return (_jsxs("div", { className:
|
|
11
|
+
return (_jsxs("div", { className: `xmwr_c d-f fd-c ai-c jc-sb` + (minimized ? " minim" : ""), children: [_jsxs("div", { className: "xmwr-h w-100 m0 d-f fd-r jc-c bg-primary noselect", children: [_jsx("div", { className: "xmwr-title m0", children: props.title }), _jsx(MinimizeButton, { toggleMinimize: toggleMinimize, minimized: minimized })] }), _jsx("div", { className: "xmwr-b w-100 d-f jc-c", children: props.children })] }));
|
|
9
12
|
}
|
|
10
13
|
function MinimizeButton({ minimized, toggleMinimize }) {
|
|
11
14
|
const minimizeChar = minimized ? "+" : "-";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lukaskj/xmonkey",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"author": "lukaskj",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"scripts": {
|
|
@@ -79,6 +79,10 @@
|
|
|
79
79
|
"./ui-script": {
|
|
80
80
|
"types": "./dist/ui-script/index.d.ts",
|
|
81
81
|
"import": "./dist/ui-script/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./hooks": {
|
|
84
|
+
"types": "./dist/hooks/index.d.ts",
|
|
85
|
+
"import": "./dist/hooks/index.js"
|
|
82
86
|
}
|
|
83
87
|
},
|
|
84
88
|
"main": "dist/index.js",
|