ag-common 0.0.141 → 0.0.145
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.
|
@@ -39,6 +39,9 @@ function trimSide(str, fromStart = true, ...params) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.trimSide = trimSide;
|
|
41
41
|
function trim(str, ...params) {
|
|
42
|
+
if (!str) {
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
42
45
|
str = trimSide(str, true, ...params);
|
|
43
46
|
str = trimSide(str, false, ...params);
|
|
44
47
|
return str;
|
|
@@ -149,9 +152,14 @@ exports.chunkString = chunkString;
|
|
|
149
152
|
*/
|
|
150
153
|
function stringToObject(raw, splitKeyValue, splitKeys) {
|
|
151
154
|
const ret = {};
|
|
155
|
+
if (!stringToObject) {
|
|
156
|
+
return ret;
|
|
157
|
+
}
|
|
152
158
|
raw.split(splitKeys).forEach((set) => {
|
|
153
159
|
const [k, v] = set.split(splitKeyValue);
|
|
154
|
-
|
|
160
|
+
if (k) {
|
|
161
|
+
ret[k] = v;
|
|
162
|
+
}
|
|
155
163
|
});
|
|
156
164
|
return ret;
|
|
157
165
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, children, shadow, }: {
|
|
2
|
+
export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, children, shadow, maxHeight, }: {
|
|
3
3
|
options: T[];
|
|
4
4
|
value?: T;
|
|
5
5
|
onChange: (v: T, index: number) => void;
|
|
@@ -11,4 +11,8 @@ export declare function DropdownList<T>({ options, value, onChange, placeholder,
|
|
|
11
11
|
* colour of dropdown shadow. default #555
|
|
12
12
|
*/
|
|
13
13
|
shadow?: string;
|
|
14
|
+
/**
|
|
15
|
+
* max height of items list. default 50vh
|
|
16
|
+
*/
|
|
17
|
+
maxHeight?: string;
|
|
14
18
|
}): JSX.Element;
|
|
@@ -45,6 +45,12 @@ const SItems = styled_components_1.default.div `
|
|
|
45
45
|
cursor: default;
|
|
46
46
|
width: 100%;
|
|
47
47
|
max-width: 95vw;
|
|
48
|
+
${({ maxHeight }) => maxHeight &&
|
|
49
|
+
(0, styled_components_1.css) `
|
|
50
|
+
max-height: ${maxHeight};
|
|
51
|
+
`}
|
|
52
|
+
|
|
53
|
+
overflow-y: scroll;
|
|
48
54
|
${({ open }) => open &&
|
|
49
55
|
(0, styled_components_1.css) `
|
|
50
56
|
display: flex;
|
|
@@ -82,7 +88,7 @@ const SItem = styled_components_1.default.div `
|
|
|
82
88
|
background-color: rgba(0, 0, 0, 0.2);
|
|
83
89
|
}
|
|
84
90
|
`;
|
|
85
|
-
function DropdownList({ options, value, onChange, placeholder, className, renderF, children, shadow = '#555', }) {
|
|
91
|
+
function DropdownList({ options, value, onChange, placeholder, className, renderF, children, shadow = '#555', maxHeight = '50vh', }) {
|
|
86
92
|
var _a, _b;
|
|
87
93
|
const ref = (0, react_1.useRef)(null);
|
|
88
94
|
const [state, setState] = (0, react_1.useState)(value);
|
|
@@ -124,7 +130,7 @@ function DropdownList({ options, value, onChange, placeholder, className, render
|
|
|
124
130
|
e.preventDefault();
|
|
125
131
|
setOpen(!open);
|
|
126
132
|
} },
|
|
127
|
-
react_1.default.createElement(SItems, { open: open, style: style, shadow: shadow }, open &&
|
|
133
|
+
react_1.default.createElement(SItems, { open: open, style: style, shadow: shadow, maxHeight: maxHeight }, open &&
|
|
128
134
|
options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: (e) => {
|
|
129
135
|
if (s !== state) {
|
|
130
136
|
onChange(s, i);
|
|
@@ -62,3 +62,15 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
62
62
|
*/
|
|
63
63
|
cookieDocument: string | undefined;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* get parsed url. will use window if possible
|
|
67
|
+
* @param param0
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
export declare const getClientOrServerReqHref: ({ href }: {
|
|
71
|
+
href?: string | undefined;
|
|
72
|
+
}) => LocationSubset;
|
|
73
|
+
export declare const getServerReq: ({ host, pathname, }: {
|
|
74
|
+
pathname: string;
|
|
75
|
+
host: string;
|
|
76
|
+
}) => LocationSubset;
|
|
@@ -1,2 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getServerReq = exports.getClientOrServerReqHref = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const string_1 = require("../../common/helpers/string");
|
|
6
|
+
const calculateServerHref = ({ host, pathname, }) => {
|
|
7
|
+
if (!host) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
let href = '';
|
|
11
|
+
if (host.includes('localhost')) {
|
|
12
|
+
href += 'http://';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
href += 'https://';
|
|
16
|
+
}
|
|
17
|
+
href += host + pathname;
|
|
18
|
+
return decodeURIComponent(href);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* get parsed url. will use window if possible
|
|
22
|
+
* @param param0
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
const getClientOrServerReqHref = ({ href }) => {
|
|
26
|
+
if (typeof window !== 'undefined') {
|
|
27
|
+
href = window.location.href;
|
|
28
|
+
}
|
|
29
|
+
if (!href) {
|
|
30
|
+
throw new Error('no href');
|
|
31
|
+
}
|
|
32
|
+
const parsed = (0, url_1.parse)(href);
|
|
33
|
+
const ret = {
|
|
34
|
+
hash: parsed.hash || '',
|
|
35
|
+
host: parsed.host || '',
|
|
36
|
+
origin: `${parsed.protocol}//${parsed.host}`,
|
|
37
|
+
href: `${parsed.protocol}//${parsed.host}${parsed.path}${parsed.hash || ''}`,
|
|
38
|
+
path: `${parsed.path}${parsed.hash || ''}`,
|
|
39
|
+
pathname: parsed.pathname || '',
|
|
40
|
+
protocol: parsed.protocol || '',
|
|
41
|
+
query: (0, string_1.stringToObject)(parsed.query || '', '=', '&'),
|
|
42
|
+
};
|
|
43
|
+
return ret;
|
|
44
|
+
};
|
|
45
|
+
exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
46
|
+
const getServerReq = ({ host, pathname, }) => {
|
|
47
|
+
const href = calculateServerHref({
|
|
48
|
+
host,
|
|
49
|
+
pathname,
|
|
50
|
+
});
|
|
51
|
+
return (0, exports.getClientOrServerReqHref)({ href });
|
|
52
|
+
};
|
|
53
|
+
exports.getServerReq = getServerReq;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.145",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/styled-components": "5.1.22",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
37
37
|
"@typescript-eslint/parser": "5.11.0",
|
|
38
|
-
"eslint": "8.
|
|
38
|
+
"eslint": "8.9.0",
|
|
39
39
|
"eslint-config-airbnb-typescript": "16.1.0",
|
|
40
40
|
"eslint-config-prettier": "8.3.0",
|
|
41
41
|
"eslint-config-react-app": "7.0.0",
|