ag-common 0.0.660 → 0.0.662
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/ui/components/MinSidebar/index.js +1 -4
- package/dist/ui/components/Modal/Modal.js +9 -0
- package/dist/ui/components/Sidebar/index.js +1 -4
- package/dist/ui/helpers/routes.d.ts +4 -21
- package/dist/ui/helpers/routes.js +13 -11
- package/dist/ui/helpers/useOnClickOutside.d.ts +2 -4
- package/dist/ui/helpers/useOnClickOutside.js +22 -9
- package/package.json +1 -1
|
@@ -66,10 +66,7 @@ const ChevronStyled = (0, styled_1.default)(Chevron_1.Chevron) `
|
|
|
66
66
|
const MinSidebar = ({ chevronColour, children, className, style, }) => {
|
|
67
67
|
const ref = (0, react_1.useRef)(null);
|
|
68
68
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
69
|
-
(0, helpers_1.useOnClickOutside)({ ref }, () => {
|
|
70
|
-
if (!open || window.innerWidth > media_1.smallScreenPx) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
69
|
+
(0, helpers_1.useOnClickOutside)({ ref, disabled: () => !open || window.innerWidth > media_1.smallScreenPx }, () => {
|
|
73
70
|
setOpen(false);
|
|
74
71
|
});
|
|
75
72
|
return (react_1.default.createElement(Base, { style: style, "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), ref: ref },
|
|
@@ -84,6 +84,15 @@ const CloseStyled = (0, styled_1.default)(Close_1.Close) `
|
|
|
84
84
|
z-index: 1;
|
|
85
85
|
`;
|
|
86
86
|
const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top', showCloseButton = true, closeOnMoveMouseOutside = false, className, closeOnClickOutside = true, }) => {
|
|
87
|
+
(0, react_1.useEffect)(() => {
|
|
88
|
+
const originalStyle = window.getComputedStyle(document.body).overflow || '';
|
|
89
|
+
if (open) {
|
|
90
|
+
document.body.style.overflow = 'hidden';
|
|
91
|
+
}
|
|
92
|
+
return () => {
|
|
93
|
+
document.body.style.overflow = originalStyle;
|
|
94
|
+
};
|
|
95
|
+
}, [open]);
|
|
87
96
|
const [bounced, setBounced] = (0, react_1.useState)(false);
|
|
88
97
|
const ref = (0, react_1.useRef)(null);
|
|
89
98
|
(0, useOnClickOutside_1.useOnClickOutside)({
|
|
@@ -168,10 +168,7 @@ const ChevronStyled = (0, styled_1.default)(Chevron_1.Chevron) `
|
|
|
168
168
|
const Sidebar = ({ children, className, mode = 'defaultClosed', }) => {
|
|
169
169
|
const ref = (0, react_2.useRef)(null);
|
|
170
170
|
const [open, setOpen] = (0, react_2.useState)(mode === 'defaultClosed' ? false : null);
|
|
171
|
-
(0, helpers_1.useOnClickOutside)({ ref }, () => {
|
|
172
|
-
if (!open || window.innerWidth > media_1.smallScreenPx) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
171
|
+
(0, helpers_1.useOnClickOutside)({ ref, disabled: () => !open || window.innerWidth > media_1.smallScreenPx }, () => {
|
|
175
172
|
setOpen(false);
|
|
176
173
|
});
|
|
177
174
|
return (react_2.default.createElement(Base, { "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), "data-hover": true, ref: ref },
|
|
@@ -38,28 +38,18 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
38
38
|
cookieDocument: string | undefined;
|
|
39
39
|
}
|
|
40
40
|
export declare const getRenderLanguage: (host?: string | null) => TLang;
|
|
41
|
+
export declare const getClientReqHref: () => IRequestCommon;
|
|
41
42
|
/**
|
|
42
43
|
* get parsed url. use on client/SSR. defaults to window location if possible
|
|
43
44
|
* @param param0
|
|
44
45
|
* @returns
|
|
45
46
|
*/
|
|
46
|
-
export declare const getClientOrServerReqHref: ({ url, query,
|
|
47
|
+
export declare const getClientOrServerReqHref: ({ url, query, userAgent, }: {
|
|
47
48
|
url?: URLLite | undefined;
|
|
48
49
|
query?: Record<string, string> | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* if true, wont use window location. default false
|
|
51
|
-
*/
|
|
52
|
-
forceServer?: boolean | undefined;
|
|
53
50
|
/** will use navigator if possible */
|
|
54
51
|
userAgent?: string | undefined;
|
|
55
|
-
}) =>
|
|
56
|
-
url: URLLite;
|
|
57
|
-
query: {
|
|
58
|
-
[x: string]: string;
|
|
59
|
-
};
|
|
60
|
-
userAgent: string;
|
|
61
|
-
lang: TLang;
|
|
62
|
-
};
|
|
52
|
+
}) => IRequestCommon;
|
|
63
53
|
/**
|
|
64
54
|
* get server side parsed url
|
|
65
55
|
* @param param0 * @returns
|
|
@@ -81,11 +71,4 @@ export declare const getServerReq: ({ pathname, query, headers, }: {
|
|
|
81
71
|
* eg ctx.query
|
|
82
72
|
*/
|
|
83
73
|
query: Record<string, string | string[] | undefined>;
|
|
84
|
-
}) =>
|
|
85
|
-
url: URLLite;
|
|
86
|
-
query: {
|
|
87
|
-
[x: string]: string;
|
|
88
|
-
};
|
|
89
|
-
userAgent: string;
|
|
90
|
-
lang: TLang;
|
|
91
|
-
};
|
|
74
|
+
}) => IRequestCommon;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServerReq = exports.getClientOrServerReqHref = exports.getRenderLanguage = void 0;
|
|
3
|
+
exports.getServerReq = exports.getClientOrServerReqHref = exports.getClientReqHref = exports.getRenderLanguage = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
4
5
|
const i18n_1 = require("../../common/helpers/i18n");
|
|
5
6
|
const object_1 = require("../../common/helpers/object");
|
|
6
7
|
const object_2 = require("../../common/helpers/string/object");
|
|
@@ -30,27 +31,29 @@ const getRenderLanguage = (host) => {
|
|
|
30
31
|
return 'en';
|
|
31
32
|
};
|
|
32
33
|
exports.getRenderLanguage = getRenderLanguage;
|
|
34
|
+
const getClientReqHref = () => {
|
|
35
|
+
const nu = new URL(window.location.href);
|
|
36
|
+
const url = (0, url_1.stripUrl)(nu);
|
|
37
|
+
const query = (0, object_2.stringToObject)((0, common_1.trimSide)(url.search, true, '?') || '', '=', '&');
|
|
38
|
+
const userAgent = navigator.userAgent;
|
|
39
|
+
return { url, query, userAgent, lang: (0, exports.getRenderLanguage)(url.host) };
|
|
40
|
+
};
|
|
41
|
+
exports.getClientReqHref = getClientReqHref;
|
|
33
42
|
/**
|
|
34
43
|
* get parsed url. use on client/SSR. defaults to window location if possible
|
|
35
44
|
* @param param0
|
|
36
45
|
* @returns
|
|
37
46
|
*/
|
|
38
|
-
const getClientOrServerReqHref = ({ url, query,
|
|
47
|
+
const getClientOrServerReqHref = ({ url, query, userAgent, }) => {
|
|
39
48
|
if (typeof window !== 'undefined') {
|
|
40
|
-
|
|
41
|
-
const nu = new URL(window.location.href);
|
|
42
|
-
url = (0, url_1.stripUrl)(nu);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (typeof navigator !== 'undefined') {
|
|
46
|
-
userAgent = navigator.userAgent;
|
|
49
|
+
return (0, exports.getClientReqHref)();
|
|
47
50
|
}
|
|
48
51
|
if (!url) {
|
|
49
52
|
throw new Error('no href');
|
|
50
53
|
}
|
|
51
54
|
return {
|
|
52
55
|
url,
|
|
53
|
-
query: Object.assign(Object.assign({}, query), (0, object_2.stringToObject)(url.search || '', '=', '&')),
|
|
56
|
+
query: Object.assign(Object.assign({}, query), (0, object_2.stringToObject)((0, common_1.trimSide)(url.search, true, '?') || '', '=', '&')),
|
|
54
57
|
userAgent: userAgent !== null && userAgent !== void 0 ? userAgent : '?',
|
|
55
58
|
lang: (0, exports.getRenderLanguage)(url.host),
|
|
56
59
|
};
|
|
@@ -70,7 +73,6 @@ const getServerReq = ({ pathname, query, headers, }) => {
|
|
|
70
73
|
const ret = (0, exports.getClientOrServerReqHref)({
|
|
71
74
|
url: !href ? undefined : new URL(href),
|
|
72
75
|
query: parsedQuery,
|
|
73
|
-
forceServer: true,
|
|
74
76
|
userAgent: (_a = headers['user-agent']) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
|
|
75
77
|
});
|
|
76
78
|
return ret;
|
|
@@ -2,10 +2,8 @@ import type { RefObject } from 'react';
|
|
|
2
2
|
type Event = MouseEvent | TouchEvent;
|
|
3
3
|
export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(p: {
|
|
4
4
|
ref: RefObject<T>;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
disabled?: boolean;
|
|
5
|
+
/** can either be a boolean, or a callback */
|
|
6
|
+
disabled?: boolean | (() => boolean);
|
|
9
7
|
/** if true, will also consider moving mouse outside div. default false */
|
|
10
8
|
moveMouseOutside?: boolean;
|
|
11
9
|
}, handler: (event: Event) => void): void;
|
|
@@ -6,21 +6,34 @@ const react_1 = require("react");
|
|
|
6
6
|
const dom_1 = require("./dom");
|
|
7
7
|
function useOnClickOutside(p, handler) {
|
|
8
8
|
(0, react_1.useEffect)(() => {
|
|
9
|
-
if (p.disabled || typeof window === 'undefined') {
|
|
10
|
-
return () => {
|
|
11
|
-
//
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
9
|
const listener = (event) => {
|
|
15
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const disabled = !p.disabled || typeof p.disabled === 'boolean'
|
|
12
|
+
? (_a = p.disabled) !== null && _a !== void 0 ? _a : false
|
|
13
|
+
: p.disabled();
|
|
14
|
+
if (disabled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
16
17
|
//
|
|
17
18
|
const isRightMB = (0, dom_1.isRightClick)(event);
|
|
18
19
|
if (isRightMB) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
const el = (
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const el = (_b = p.ref) === null || _b === void 0 ? void 0 : _b.current;
|
|
23
|
+
if (!el) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
//walk dom tree to see if nodes match
|
|
27
|
+
let n = event.target;
|
|
28
|
+
let found = false;
|
|
29
|
+
while (n) {
|
|
30
|
+
if (n.isEqualNode(el)) {
|
|
31
|
+
found = true;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
n = n.parentNode;
|
|
35
|
+
}
|
|
36
|
+
if (found) {
|
|
24
37
|
return;
|
|
25
38
|
}
|
|
26
39
|
handler(event);
|
package/package.json
CHANGED