@webiny/app-admin 6.4.12-beta.2 → 6.4.12-beta.4
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/hooks/useHotkeys.js +3 -1
- package/hooks/useHotkeys.js.map +1 -1
- package/package.json +19 -19
package/hooks/useHotkeys.js
CHANGED
|
@@ -44,6 +44,8 @@ function useHotkeys(props) {
|
|
|
44
44
|
const { disabled, zIndex, keys } = props;
|
|
45
45
|
const prevPropsRef = useRef();
|
|
46
46
|
const firstRenderRef = useRef(true);
|
|
47
|
+
const propsRef = useRef(props);
|
|
48
|
+
propsRef.current = props;
|
|
47
49
|
useEffect(function() {
|
|
48
50
|
if (firstRenderRef.current || prevPropsRef.current?.disabled !== disabled) {
|
|
49
51
|
firstRenderRef.current = false;
|
|
@@ -57,7 +59,7 @@ function useHotkeys(props) {
|
|
|
57
59
|
});
|
|
58
60
|
useEffect(function() {
|
|
59
61
|
return function() {
|
|
60
|
-
if (!disabled) unregisterZIndex(
|
|
62
|
+
if (!propsRef.current.disabled) unregisterZIndex(propsRef.current);
|
|
61
63
|
};
|
|
62
64
|
}, []);
|
|
63
65
|
}
|
package/hooks/useHotkeys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks/useHotkeys.js","sources":["../../src/hooks/useHotkeys.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport isHotkey from \"is-hotkey\";\n\ntype HookProps = {\n disabled?: boolean;\n zIndex: number;\n keys?: { [key: string]: (e: KeyboardEvent) => void };\n};\n\ntype State = {\n listenerAttached: boolean;\n zIndex: null | number;\n handlers: { [zIndex: number]: { [key: string]: (e: KeyboardEvent) => void } };\n};\n\nconst state: State = {\n listenerAttached: false,\n zIndex: null,\n handlers: {}\n};\n\nfunction triggerHotkeys(e: KeyboardEvent) {\n if (state.zIndex === null) {\n return;\n }\n\n const keys = state.handlers[state.zIndex];\n for (const key in keys) {\n if (isHotkey(key, e)) {\n keys[key](e);\n break;\n }\n }\n}\n\nfunction registerZIndex({ zIndex, keys }: HookProps) {\n if (state.zIndex === null || state.zIndex < zIndex) {\n state.zIndex = zIndex;\n }\n\n if (!state.handlers[zIndex]) {\n state.handlers[zIndex] = {};\n }\n\n if (!keys || Object.keys(keys).length === 0) {\n return;\n }\n\n for (const key in keys) {\n if (key in state.handlers[zIndex]) {\n throw Error(`Shortcut \"${key}\" already registered on zIndex ${zIndex}.`);\n }\n state.handlers[zIndex][key] = keys[key];\n }\n\n if (!state.listenerAttached) {\n document.body.addEventListener(\"keydown\", triggerHotkeys);\n state.listenerAttached = true;\n }\n}\n\nfunction unregisterZIndex({ zIndex, keys }: HookProps) {\n if (state.handlers && state.handlers[zIndex]) {\n for (const key in keys) {\n delete state.handlers[zIndex][key];\n }\n\n if (Object.keys(state.handlers[zIndex]).length === 0) {\n delete state.handlers[zIndex];\n }\n }\n\n if (Object.keys(state.handlers).length > 0) {\n state.zIndex = Math.max(...Object.keys(state.handlers).map(Number));\n } else {\n state.zIndex = null;\n\n if (state.listenerAttached) {\n document.body.removeEventListener(\"keydown\", triggerHotkeys);\n state.listenerAttached = false;\n }\n }\n}\n\nexport function useHotkeys(props: HookProps) {\n const { disabled, zIndex, keys } = props;\n\n const prevPropsRef = useRef<HookProps | undefined>();\n const firstRenderRef = useRef(true);\n\n useEffect(function () {\n if (firstRenderRef.current || prevPropsRef.current?.disabled !== disabled) {\n firstRenderRef.current = false;\n if (disabled) {\n unregisterZIndex(props);\n } else {\n registerZIndex(props);\n }\n }\n\n if (!disabled && typeof keys === \"object\") {\n Object.assign(state.handlers[zIndex], keys);\n }\n prevPropsRef.current = { ...props };\n });\n\n useEffect(function () {\n return function () {\n if (!disabled) {\n unregisterZIndex(
|
|
1
|
+
{"version":3,"file":"hooks/useHotkeys.js","sources":["../../src/hooks/useHotkeys.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport isHotkey from \"is-hotkey\";\n\ntype HookProps = {\n disabled?: boolean;\n zIndex: number;\n keys?: { [key: string]: (e: KeyboardEvent) => void };\n};\n\ntype State = {\n listenerAttached: boolean;\n zIndex: null | number;\n handlers: { [zIndex: number]: { [key: string]: (e: KeyboardEvent) => void } };\n};\n\nconst state: State = {\n listenerAttached: false,\n zIndex: null,\n handlers: {}\n};\n\nfunction triggerHotkeys(e: KeyboardEvent) {\n if (state.zIndex === null) {\n return;\n }\n\n const keys = state.handlers[state.zIndex];\n for (const key in keys) {\n if (isHotkey(key, e)) {\n keys[key](e);\n break;\n }\n }\n}\n\nfunction registerZIndex({ zIndex, keys }: HookProps) {\n if (state.zIndex === null || state.zIndex < zIndex) {\n state.zIndex = zIndex;\n }\n\n if (!state.handlers[zIndex]) {\n state.handlers[zIndex] = {};\n }\n\n if (!keys || Object.keys(keys).length === 0) {\n return;\n }\n\n for (const key in keys) {\n if (key in state.handlers[zIndex]) {\n throw Error(`Shortcut \"${key}\" already registered on zIndex ${zIndex}.`);\n }\n state.handlers[zIndex][key] = keys[key];\n }\n\n if (!state.listenerAttached) {\n document.body.addEventListener(\"keydown\", triggerHotkeys);\n state.listenerAttached = true;\n }\n}\n\nfunction unregisterZIndex({ zIndex, keys }: HookProps) {\n if (state.handlers && state.handlers[zIndex]) {\n for (const key in keys) {\n delete state.handlers[zIndex][key];\n }\n\n if (Object.keys(state.handlers[zIndex]).length === 0) {\n delete state.handlers[zIndex];\n }\n }\n\n if (Object.keys(state.handlers).length > 0) {\n state.zIndex = Math.max(...Object.keys(state.handlers).map(Number));\n } else {\n state.zIndex = null;\n\n if (state.listenerAttached) {\n document.body.removeEventListener(\"keydown\", triggerHotkeys);\n state.listenerAttached = false;\n }\n }\n}\n\nexport function useHotkeys(props: HookProps) {\n const { disabled, zIndex, keys } = props;\n\n const prevPropsRef = useRef<HookProps | undefined>();\n const firstRenderRef = useRef(true);\n\n // The unmount cleanup below runs once, so it must not close over the props of the first\n // render. Without this, a component unmounted while its shortcuts are registered (for\n // example, an open drawer navigating away) would leak them into the shared registry, and\n // the next component to register the same shortcut would throw.\n const propsRef = useRef(props);\n propsRef.current = props;\n\n useEffect(function () {\n if (firstRenderRef.current || prevPropsRef.current?.disabled !== disabled) {\n firstRenderRef.current = false;\n if (disabled) {\n unregisterZIndex(props);\n } else {\n registerZIndex(props);\n }\n }\n\n if (!disabled && typeof keys === \"object\") {\n Object.assign(state.handlers[zIndex], keys);\n }\n prevPropsRef.current = { ...props };\n });\n\n useEffect(function () {\n return function () {\n if (!propsRef.current.disabled) {\n unregisterZIndex(propsRef.current);\n }\n };\n }, []);\n}\n"],"names":["state","triggerHotkeys","e","keys","key","isHotkey","registerZIndex","zIndex","Object","Error","document","unregisterZIndex","Math","Number","useHotkeys","props","disabled","prevPropsRef","useRef","firstRenderRef","propsRef","useEffect"],"mappings":";;AAeA,MAAMA,QAAe;IACjB,kBAAkB;IAClB,QAAQ;IACR,UAAU,CAAC;AACf;AAEA,SAASC,eAAeC,CAAgB;IACpC,IAAIF,AAAiB,SAAjBA,MAAM,MAAM,EACZ;IAGJ,MAAMG,OAAOH,MAAM,QAAQ,CAACA,MAAM,MAAM,CAAC;IACzC,IAAK,MAAMI,OAAOD,KACd,IAAIE,UAASD,KAAKF,IAAI;QAClBC,IAAI,CAACC,IAAI,CAACF;QACV;IACJ;AAER;AAEA,SAASI,eAAe,EAAEC,MAAM,EAAEJ,IAAI,EAAa;IAC/C,IAAIH,AAAiB,SAAjBA,MAAM,MAAM,IAAaA,MAAM,MAAM,GAAGO,QACxCP,MAAM,MAAM,GAAGO;IAGnB,IAAI,CAACP,MAAM,QAAQ,CAACO,OAAO,EACvBP,MAAM,QAAQ,CAACO,OAAO,GAAG,CAAC;IAG9B,IAAI,CAACJ,QAAQK,AAA6B,MAA7BA,OAAO,IAAI,CAACL,MAAM,MAAM,EACjC;IAGJ,IAAK,MAAMC,OAAOD,KAAM;QACpB,IAAIC,OAAOJ,MAAM,QAAQ,CAACO,OAAO,EAC7B,MAAME,MAAM,CAAC,UAAU,EAAEL,IA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;QAEvB;QAEA,IAAI,CAACC,YAAY,AAAgB,YAAhB,OAAOb,MACpBK,OAAO,MAAM,CAACR,MAAM,QAAQ,CAACO,OAAO,EAAEJ;QAE1Cc,aAAa,OAAO,GAAG;YAAE,GAAGF,KAAK;QAAC;IACtC;IAEAM,UAAU;QACN,OAAO;YACH,IAAI,CAACD,SAAS,OAAO,CAAC,QAAQ,EAC1BT,iBAAiBS,SAAS,OAAO;QAEzC;IACJ,GAAG,EAAE;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-admin",
|
|
3
|
-
"version": "6.4.12-beta.
|
|
3
|
+
"version": "6.4.12-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,24 +25,24 @@
|
|
|
25
25
|
"@lexical/utils": "0.46.0",
|
|
26
26
|
"@svgr/webpack": "8.1.0",
|
|
27
27
|
"@types/react": "18.3.31",
|
|
28
|
-
"@webiny/admin-ui": "6.4.12-beta.
|
|
29
|
-
"@webiny/app": "6.4.12-beta.
|
|
28
|
+
"@webiny/admin-ui": "6.4.12-beta.4",
|
|
29
|
+
"@webiny/app": "6.4.12-beta.4",
|
|
30
30
|
"@webiny/di": "1.1.0",
|
|
31
|
-
"@webiny/feature": "6.4.12-beta.
|
|
32
|
-
"@webiny/form": "6.4.12-beta.
|
|
33
|
-
"@webiny/icons": "6.4.12-beta.
|
|
34
|
-
"@webiny/lexical-converter": "6.4.12-beta.
|
|
35
|
-
"@webiny/lexical-editor": "6.4.12-beta.
|
|
36
|
-
"@webiny/lexical-nodes": "6.4.12-beta.
|
|
37
|
-
"@webiny/lexical-theme": "6.4.12-beta.
|
|
38
|
-
"@webiny/plugins": "6.4.12-beta.
|
|
39
|
-
"@webiny/react-composition": "6.4.12-beta.
|
|
40
|
-
"@webiny/react-properties": "6.4.12-beta.
|
|
41
|
-
"@webiny/sdk": "6.4.12-beta.
|
|
42
|
-
"@webiny/telemetry": "6.4.12-beta.
|
|
43
|
-
"@webiny/utils": "6.4.12-beta.
|
|
44
|
-
"@webiny/validation": "6.4.12-beta.
|
|
45
|
-
"@webiny/wcp": "6.4.12-beta.
|
|
31
|
+
"@webiny/feature": "6.4.12-beta.4",
|
|
32
|
+
"@webiny/form": "6.4.12-beta.4",
|
|
33
|
+
"@webiny/icons": "6.4.12-beta.4",
|
|
34
|
+
"@webiny/lexical-converter": "6.4.12-beta.4",
|
|
35
|
+
"@webiny/lexical-editor": "6.4.12-beta.4",
|
|
36
|
+
"@webiny/lexical-nodes": "6.4.12-beta.4",
|
|
37
|
+
"@webiny/lexical-theme": "6.4.12-beta.4",
|
|
38
|
+
"@webiny/plugins": "6.4.12-beta.4",
|
|
39
|
+
"@webiny/react-composition": "6.4.12-beta.4",
|
|
40
|
+
"@webiny/react-properties": "6.4.12-beta.4",
|
|
41
|
+
"@webiny/sdk": "6.4.12-beta.4",
|
|
42
|
+
"@webiny/telemetry": "6.4.12-beta.4",
|
|
43
|
+
"@webiny/utils": "6.4.12-beta.4",
|
|
44
|
+
"@webiny/validation": "6.4.12-beta.4",
|
|
45
|
+
"@webiny/wcp": "6.4.12-beta.4",
|
|
46
46
|
"apollo-cache": "1.3.5",
|
|
47
47
|
"apollo-client": "2.6.10",
|
|
48
48
|
"apollo-link": "1.2.14",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@types/react-transition-group": "4.4.12",
|
|
82
82
|
"@types/store": "2.0.5",
|
|
83
83
|
"@types/tinycolor2": "1.4.6",
|
|
84
|
-
"@webiny/build-tools": "6.4.12-beta.
|
|
84
|
+
"@webiny/build-tools": "6.4.12-beta.4",
|
|
85
85
|
"rimraf": "6.1.3",
|
|
86
86
|
"typescript": "6.0.3",
|
|
87
87
|
"vitest": "5.0.1"
|