ag-common 0.0.129 → 0.0.134
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/common/helpers/string.d.ts +1 -0
- package/dist/common/helpers/string.js +3 -1
- package/dist/ui/components/Modal/index.js +3 -3
- package/dist/ui/components/Prompt/index.js +2 -2
- package/dist/ui/components/Sidebar/index.js +3 -5
- package/dist/ui/components/TextEdit/TextEdit.d.ts +8 -1
- package/dist/ui/components/TextEdit/TextEdit.js +5 -4
- package/dist/ui/components/TextEdit/common.js +1 -1
- package/dist/ui/components/index.d.ts +0 -1
- package/dist/ui/components/index.js +0 -1
- package/dist/ui/helpers/callOpenApi/cached.js +6 -1
- package/dist/ui/helpers/callOpenApi/direct.js +5 -1
- package/dist/ui/helpers/cookie.d.ts +55 -11
- package/dist/ui/helpers/cookie.js +103 -58
- package/package.json +3 -3
- package/dist/ui/components/TextInput/index.d.ts +0 -11
- package/dist/ui/components/TextInput/index.js +0 -53
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeStringify = exports.containsInsensitive = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
|
|
3
|
+
exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
4
|
const toBase64 = (str) => Buffer.from(str).toString('base64');
|
|
5
5
|
exports.toBase64 = toBase64;
|
|
6
6
|
const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
|
|
@@ -140,3 +140,5 @@ const safeStringify = (obj, indent = 2) => {
|
|
|
140
140
|
return retVal;
|
|
141
141
|
};
|
|
142
142
|
exports.safeStringify = safeStringify;
|
|
143
|
+
const chunkString = (str, length) => str.match(new RegExp(`.{1,${length}}`, 'g'));
|
|
144
|
+
exports.chunkString = chunkString;
|
|
@@ -34,7 +34,7 @@ const FixedBackground = styled_components_1.default.div `
|
|
|
34
34
|
width: 100%;
|
|
35
35
|
height: 100%;
|
|
36
36
|
background-color: rgba(0, 0, 0, 0.5);
|
|
37
|
-
z-index:
|
|
37
|
+
z-index: 2;
|
|
38
38
|
display: flex;
|
|
39
39
|
justify-content: center;
|
|
40
40
|
align-items: center;
|
|
@@ -80,8 +80,8 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'bott
|
|
|
80
80
|
if (!open) {
|
|
81
81
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
82
82
|
}
|
|
83
|
-
return (react_1.default.createElement(FixedBackground,
|
|
84
|
-
react_1.default.createElement(ModalBase, { "data-position": position, "data-topposition": topPosition, ref: ref },
|
|
83
|
+
return (react_1.default.createElement(FixedBackground, null,
|
|
84
|
+
react_1.default.createElement(ModalBase, { "data-position": position, "data-topposition": topPosition, ref: ref, className: className },
|
|
85
85
|
showCloseButton && react_1.default.createElement(CloseStyled, { onClick: () => setOpen(false) }),
|
|
86
86
|
children)));
|
|
87
87
|
};
|
|
@@ -41,7 +41,7 @@ const Button_1 = require("../Button");
|
|
|
41
41
|
const FlexColumn_1 = require("../FlexColumn");
|
|
42
42
|
const FlexRow_1 = require("../FlexRow");
|
|
43
43
|
const Modal_1 = require("../Modal");
|
|
44
|
-
const
|
|
44
|
+
const TextEdit_1 = require("../TextEdit");
|
|
45
45
|
const Base = styled_components_1.default.div `
|
|
46
46
|
width: 95vw;
|
|
47
47
|
max-width: 30rem;
|
|
@@ -85,7 +85,7 @@ const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelT
|
|
|
85
85
|
react_1.default.createElement(Content, null,
|
|
86
86
|
topText && react_1.default.createElement(TopText, null, topText),
|
|
87
87
|
react_1.default.createElement(BottomText, null, bottomText),
|
|
88
|
-
react_1.default.createElement(
|
|
88
|
+
react_1.default.createElement(TextEdit_1.TextEdit, { defaultValue: text, onSubmit: (c) => setText(c), placeholder: placeholder, defaultEditing: { focus: true }, singleLine: true, noGrow: true }),
|
|
89
89
|
react_1.default.createElement(Bottom, { noGrow: true },
|
|
90
90
|
react_1.default.createElement(Button_1.Button, { onClick: () => ret(text) }, okText),
|
|
91
91
|
react_1.default.createElement(Button_1.Button, { invert: true, onClick: () => ret(undefined) }, cancelText))))));
|
|
@@ -92,13 +92,11 @@ const ChevronStyled = (0, styled_components_1.default)(Chevron_1.Chevron) `
|
|
|
92
92
|
}
|
|
93
93
|
`;
|
|
94
94
|
const Sidebar = ({ children, className, key = 'sidebar', cookieDocument, }) => {
|
|
95
|
-
const [
|
|
96
|
-
key,
|
|
97
|
-
defaultValue:
|
|
95
|
+
const [open, setOpen] = (0, cookie_1.useCookieBoolean)({
|
|
96
|
+
name: key,
|
|
97
|
+
defaultValue: false,
|
|
98
98
|
cookieDocument: cookieDocument,
|
|
99
99
|
});
|
|
100
|
-
const open = openRaw === 'true';
|
|
101
|
-
const setOpen = (o) => setOpenRaw(o.toString());
|
|
102
100
|
return (react_1.default.createElement(Base, { className: className, "data-open": open, onClick: () => !open && setOpen(true), "data-hover": true },
|
|
103
101
|
react_1.default.createElement(Hamburger, { "data-open": open, onClick: () => setOpen(!open), "data-hover": true },
|
|
104
102
|
react_1.default.createElement(ChevronStyled, { point: open ? 'right' : 'left', width: "100%" })),
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { StyledComponent } from 'styled-components';
|
|
3
3
|
export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const TextEdit: ({ defaultValue, defaultEditing, onSubmit, disableEdit, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine, }: {
|
|
4
|
+
export declare const TextEdit: ({ defaultValue, defaultEditing, onSubmit, disableEdit, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine, noGrow, }: {
|
|
5
|
+
/**
|
|
6
|
+
* forces single row input style. will also enable 'Enter' to auto submit
|
|
7
|
+
*/
|
|
5
8
|
singleLine?: boolean | undefined;
|
|
6
9
|
className?: string | undefined;
|
|
7
10
|
defaultValue: string;
|
|
@@ -17,4 +20,8 @@ export declare const TextEdit: ({ defaultValue, defaultEditing, onSubmit, disabl
|
|
|
17
20
|
onEditingChange?: ((editing: boolean) => void) | undefined;
|
|
18
21
|
onClickOutsideWithNoValue?: (() => void) | undefined;
|
|
19
22
|
onClickNotEditing?: (() => void) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* if true, will not grow. default false
|
|
25
|
+
*/
|
|
26
|
+
noGrow?: boolean | undefined;
|
|
20
27
|
}) => JSX.Element;
|
|
@@ -63,12 +63,13 @@ const Right = styled_components_1.default.div `
|
|
|
63
63
|
`;
|
|
64
64
|
const Icon = styled_components_1.default.div `
|
|
65
65
|
width: 1.5rem;
|
|
66
|
+
display: flex;
|
|
66
67
|
cursor: pointer;
|
|
67
68
|
&:hover {
|
|
68
69
|
filter: saturate(3);
|
|
69
70
|
}
|
|
70
71
|
`;
|
|
71
|
-
const TextEdit = ({ defaultValue, defaultEditing, onSubmit, disableEdit = false, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine = false, }) => {
|
|
72
|
+
const TextEdit = ({ defaultValue, defaultEditing, onSubmit, disableEdit = false, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine = false, noGrow = false, }) => {
|
|
72
73
|
const ref = (0, react_1.useRef)(null);
|
|
73
74
|
const taref = (0, react_1.useRef)(null);
|
|
74
75
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
@@ -106,7 +107,7 @@ const TextEdit = ({ defaultValue, defaultEditing, onSubmit, disableEdit = false,
|
|
|
106
107
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
108
|
}, [defaultEditing]);
|
|
108
109
|
if (!editing || disableEdit) {
|
|
109
|
-
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false' }),
|
|
110
|
+
return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false', "data-nogrow": noGrow }),
|
|
110
111
|
react_1.default.createElement(exports.ValueReadonly, { "data-type": "text" }, value),
|
|
111
112
|
react_1.default.createElement(Right, null, !disableEdit && (react_1.default.createElement(Icon, { style: common_1.iconRight, onClick: (e) => {
|
|
112
113
|
e.stopPropagation();
|
|
@@ -122,9 +123,9 @@ const TextEdit = ({ defaultValue, defaultEditing, onSubmit, disableEdit = false,
|
|
|
122
123
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
124
|
ValueTextBox
|
|
124
125
|
: ValueTextArea;
|
|
125
|
-
return (react_1.default.createElement(ValueBoxEdit, Object.assign({ "data-editing": "true"
|
|
126
|
+
return (react_1.default.createElement(ValueBoxEdit, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "true",
|
|
126
127
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
-
ref: ref, tabIndex: editing ? 0 : undefined,
|
|
128
|
+
ref: ref, tabIndex: editing ? 0 : undefined, "data-nogrow": noGrow }),
|
|
128
129
|
react_1.default.createElement(Comp, { "data-editing": "true", "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => setValue(v.currentTarget.value), placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => singleLine && e.code.endsWith('Enter') && onSubmit(value) && false }),
|
|
129
130
|
react_1.default.createElement(Right, null,
|
|
130
131
|
valueChange && (react_1.default.createElement(Icon, { style: common_1.iconLeft, onClick: () => valueChange && onSubmit(value) },
|
|
@@ -30,6 +30,5 @@ __exportStar(require("./RowOrColumn"), exports);
|
|
|
30
30
|
__exportStar(require("./Sidebar"), exports);
|
|
31
31
|
__exportStar(require("./Table"), exports);
|
|
32
32
|
__exportStar(require("./TextEdit"), exports);
|
|
33
|
-
__exportStar(require("./TextInput"), exports);
|
|
34
33
|
__exportStar(require("./Toast"), exports);
|
|
35
34
|
__exportStar(require("./UserImage"), exports);
|
|
@@ -19,7 +19,12 @@ const direct_1 = require("./direct");
|
|
|
19
19
|
const string_1 = require("../../../common/helpers/string");
|
|
20
20
|
let callOpenApiCache;
|
|
21
21
|
function getCacheKey({ cacheKey, overrideAuth, }) {
|
|
22
|
-
const authkeyPrefix = (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) ||
|
|
22
|
+
const authkeyPrefix = (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) ||
|
|
23
|
+
(0, cookie_1.getCookieWrapper)({
|
|
24
|
+
name: 'id_token',
|
|
25
|
+
defaultValue: '',
|
|
26
|
+
parse: (s) => s,
|
|
27
|
+
});
|
|
23
28
|
let cacheKeyRet;
|
|
24
29
|
if (cacheKey) {
|
|
25
30
|
const pref = !authkeyPrefix ? '' : (0, string_1.toBase64)(authkeyPrefix);
|
|
@@ -26,7 +26,11 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
26
26
|
config.baseOptions.headers.authorization = `Bearer ${overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token}`;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
const isAuthed = !!(0, cookie_1.getCookieWrapper)({
|
|
29
|
+
const isAuthed = !!(0, cookie_1.getCookieWrapper)({
|
|
30
|
+
name: 'id_token',
|
|
31
|
+
defaultValue: '',
|
|
32
|
+
parse: (s) => s,
|
|
33
|
+
});
|
|
30
34
|
if (isAuthed) {
|
|
31
35
|
const updated = yield refreshToken();
|
|
32
36
|
if ((_a = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
@@ -1,18 +1,62 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare function wipeCookies(name: string): void;
|
|
2
|
+
/**
|
|
3
|
+
* json+b64 incoming. chunk. write chunks
|
|
4
|
+
* @param p
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function setCookieWrapper<T>(p: {
|
|
8
|
+
value: T;
|
|
9
|
+
name: string;
|
|
10
|
+
cookieDocument?: string;
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
12
|
+
* required for objects. defaults to JSON.stringify
|
|
7
13
|
*/
|
|
14
|
+
stringify?: (s: T) => string;
|
|
15
|
+
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* read chunks. json parse+unb64
|
|
18
|
+
* @param param0
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCookieWrapper<T>({ name, cookieDocument, defaultValue, parse: parseRaw, }: {
|
|
22
|
+
defaultValue: T;
|
|
23
|
+
name: string;
|
|
8
24
|
cookieDocument?: string;
|
|
9
|
-
|
|
25
|
+
/**
|
|
26
|
+
* required for objects. defaults to JSON.parse
|
|
27
|
+
*/
|
|
28
|
+
parse?: (s: string) => T;
|
|
10
29
|
}): T;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
declare type Dispatch<A> = (value: A) => void;
|
|
31
|
+
declare type SetStateAction<S> = S | ((prevState: S) => S);
|
|
32
|
+
declare type ReturnType<T> = [T, Dispatch<SetStateAction<T>>];
|
|
33
|
+
declare type TParse<T> = (s: string | null | undefined) => T;
|
|
34
|
+
export declare function useCookie<T>(p: {
|
|
35
|
+
defaultValue: T;
|
|
36
|
+
name: string;
|
|
37
|
+
cookieDocument?: string;
|
|
14
38
|
/**
|
|
15
|
-
*
|
|
39
|
+
* required for objects. defaults to JSON.parse
|
|
16
40
|
*/
|
|
41
|
+
parse?: TParse<T>;
|
|
42
|
+
/**
|
|
43
|
+
* required for objects. defaults to JSON.stringify
|
|
44
|
+
*/
|
|
45
|
+
stringify?: (v: T) => string;
|
|
46
|
+
}): ReturnType<T>;
|
|
47
|
+
export declare const useCookieString: (p: {
|
|
48
|
+
defaultValue: string;
|
|
49
|
+
name: string;
|
|
50
|
+
cookieDocument?: string;
|
|
51
|
+
}) => ReturnType<string>;
|
|
52
|
+
export declare const useCookieNumber: (p: {
|
|
53
|
+
defaultValue: number | undefined;
|
|
54
|
+
name: string;
|
|
55
|
+
cookieDocument?: string;
|
|
56
|
+
}) => ReturnType<number | undefined>;
|
|
57
|
+
export declare const useCookieBoolean: (p: {
|
|
58
|
+
defaultValue: boolean;
|
|
59
|
+
name: string;
|
|
17
60
|
cookieDocument?: string;
|
|
18
|
-
})
|
|
61
|
+
}) => ReturnType<boolean>;
|
|
62
|
+
export {};
|
|
@@ -1,62 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCookie = exports.getCookieWrapper = exports.
|
|
3
|
+
exports.useCookieBoolean = exports.useCookieNumber = exports.useCookieString = exports.useCookie = exports.getCookieWrapper = exports.setCookieWrapper = exports.wipeCookies = void 0;
|
|
4
4
|
/* eslint-disable guard-for-in */
|
|
5
5
|
/* eslint-disable no-restricted-syntax */
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
+
const log_1 = require("../../common/helpers/log");
|
|
7
8
|
const string_1 = require("../../common/helpers/string");
|
|
8
9
|
const expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
|
|
9
10
|
const maxCookieLen = 4000;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* expiryDays <0 will delete
|
|
13
|
+
* @param param0
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function setCookieRaw({ name, value, expiryDays = 1, }) {
|
|
12
17
|
if (typeof window === undefined) {
|
|
13
18
|
return;
|
|
14
19
|
}
|
|
15
20
|
const d = new Date();
|
|
16
|
-
d.setTime(d.getTime() +
|
|
17
|
-
const expires = `expires=${!
|
|
18
|
-
document.cookie = `${
|
|
21
|
+
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
22
|
+
const expires = `expires=${!value || expiryDays < 0 ? expireDate : d.toUTCString()}`;
|
|
23
|
+
document.cookie = `${name}=${!value ? '' : value};${expires};path=/`;
|
|
19
24
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
25
|
+
function getCookieRaw({ name, cookieDocument, }) {
|
|
26
|
+
const nameeq = `${name}=`;
|
|
22
27
|
const ca1 = cookieDocument || (typeof window !== 'undefined' && document.cookie);
|
|
23
28
|
if (!ca1 || !(ca1 === null || ca1 === void 0 ? void 0 : ca1.trim())) {
|
|
24
29
|
return undefined;
|
|
25
30
|
}
|
|
26
31
|
const ca = ca1.split(';').map((t) => t.trim());
|
|
27
32
|
for (const c of ca) {
|
|
28
|
-
if (c.indexOf(
|
|
29
|
-
|
|
33
|
+
if (c.indexOf(nameeq) === 0) {
|
|
34
|
+
const raw = c.substr(nameeq.length, c.length);
|
|
35
|
+
return raw;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
return undefined;
|
|
33
39
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
setCookie(cname + index, null, -1);
|
|
38
|
-
index += 1;
|
|
39
|
-
}
|
|
40
|
-
if (!raw) {
|
|
40
|
+
function wipeCookies(name) {
|
|
41
|
+
if (typeof window === 'undefined') {
|
|
42
|
+
(0, log_1.warn)('cant wipe cookies on server');
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
const str = (0, string_1.toBase64)(JSON.stringify(raw));
|
|
44
|
-
let chunks = [str];
|
|
45
|
-
if (str.length > maxCookieLen) {
|
|
46
|
-
chunks = chunkString(str, maxCookieLen);
|
|
47
|
-
}
|
|
48
|
-
for (const index1 in chunks) {
|
|
49
|
-
const chunk = chunks[index1];
|
|
50
|
-
setCookie(cname + index1, chunk, exdays);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.setCookieWrapper = setCookieWrapper;
|
|
54
|
-
function wipeCookies(cname) {
|
|
55
45
|
let currentCount = 0;
|
|
56
46
|
// eslint-disable-next-line no-constant-condition
|
|
57
47
|
while (true) {
|
|
58
|
-
if (
|
|
59
|
-
|
|
48
|
+
if (getCookieRaw({
|
|
49
|
+
name: name + currentCount,
|
|
50
|
+
cookieDocument: '',
|
|
51
|
+
})) {
|
|
52
|
+
setCookieRaw({ name: name + currentCount, value: '', expiryDays: -1 });
|
|
60
53
|
currentCount += 1;
|
|
61
54
|
}
|
|
62
55
|
else {
|
|
@@ -65,46 +58,98 @@ function wipeCookies(cname) {
|
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
60
|
exports.wipeCookies = wipeCookies;
|
|
68
|
-
|
|
61
|
+
/**
|
|
62
|
+
* json+b64 incoming. chunk. write chunks
|
|
63
|
+
* @param p
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
function setCookieWrapper(p) {
|
|
67
|
+
const stringify = (s) => {
|
|
68
|
+
if (p.stringify) {
|
|
69
|
+
return p.stringify(s);
|
|
70
|
+
}
|
|
71
|
+
return JSON.stringify(s);
|
|
72
|
+
};
|
|
73
|
+
wipeCookies(p.name);
|
|
74
|
+
if (!p.value) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const str = (0, string_1.toBase64)(stringify(p.value));
|
|
78
|
+
const chunks = (0, string_1.chunkString)(str, maxCookieLen);
|
|
79
|
+
for (const index1 in chunks) {
|
|
80
|
+
const chunk = chunks[index1];
|
|
81
|
+
setCookieRaw(Object.assign(Object.assign({}, p), { name: p.name + index1, value: chunk }));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.setCookieWrapper = setCookieWrapper;
|
|
85
|
+
/**
|
|
86
|
+
* read chunks. json parse+unb64
|
|
87
|
+
* @param param0
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
function getCookieWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
|
|
91
|
+
const parse = (s) => {
|
|
92
|
+
if (!s) {
|
|
93
|
+
return defaultValue;
|
|
94
|
+
}
|
|
95
|
+
if (parseRaw) {
|
|
96
|
+
return parseRaw(s);
|
|
97
|
+
}
|
|
98
|
+
return JSON.parse(s);
|
|
99
|
+
};
|
|
69
100
|
let raw = '';
|
|
70
101
|
let currentCount = 0;
|
|
71
102
|
// eslint-disable-next-line no-constant-condition
|
|
72
103
|
while (true) {
|
|
73
|
-
const newv =
|
|
74
|
-
|
|
104
|
+
const newv = getCookieRaw({
|
|
105
|
+
name: name + currentCount,
|
|
75
106
|
cookieDocument,
|
|
76
107
|
});
|
|
77
108
|
if (!newv) {
|
|
78
|
-
|
|
79
|
-
if (defaultValue) {
|
|
80
|
-
setCookie(cname, defaultValue);
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
-
return defaultValue;
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
return JSON.parse((0, string_1.fromBase64)(raw));
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
wipeCookies(cname);
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
109
|
+
break;
|
|
93
110
|
}
|
|
94
111
|
raw += newv;
|
|
95
112
|
currentCount += 1;
|
|
96
113
|
}
|
|
114
|
+
try {
|
|
115
|
+
return parse((0, string_1.fromBase64)(raw));
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
(0, log_1.warn)('cookie error:', e);
|
|
119
|
+
wipeCookies(name);
|
|
120
|
+
return defaultValue;
|
|
121
|
+
}
|
|
97
122
|
}
|
|
98
123
|
exports.getCookieWrapper = getCookieWrapper;
|
|
99
124
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
function useCookie(
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
125
|
+
function useCookie(p) {
|
|
126
|
+
const parse = (s) => {
|
|
127
|
+
if (!s) {
|
|
128
|
+
return p.defaultValue;
|
|
129
|
+
}
|
|
130
|
+
if (p.parse) {
|
|
131
|
+
return p.parse(s);
|
|
132
|
+
}
|
|
133
|
+
return JSON.parse(s);
|
|
134
|
+
};
|
|
135
|
+
const stringify = (s) => {
|
|
136
|
+
if (p.stringify) {
|
|
137
|
+
return p.stringify(s);
|
|
138
|
+
}
|
|
139
|
+
return JSON.stringify(s);
|
|
140
|
+
};
|
|
141
|
+
const [cookie, setCookie] = (0, react_1.useState)(getCookieWrapper(Object.assign(Object.assign({}, p), { parse })) || p.defaultValue);
|
|
142
|
+
const setState = (valueRaw) => {
|
|
143
|
+
const value = (valueRaw instanceof Function ? valueRaw(cookie) : valueRaw);
|
|
144
|
+
setCookieWrapper(Object.assign(Object.assign({}, p), { stringify, value }));
|
|
145
|
+
setCookie(value);
|
|
146
|
+
};
|
|
147
|
+
return [cookie, setState];
|
|
109
148
|
}
|
|
110
149
|
exports.useCookie = useCookie;
|
|
150
|
+
const useCookieString = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s || '', stringify: (s) => s }));
|
|
151
|
+
exports.useCookieString = useCookieString;
|
|
152
|
+
const useCookieNumber = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => (!s ? undefined : Number.parseFloat(s)), stringify: (s) => (!s ? '' : s.toString()) }));
|
|
153
|
+
exports.useCookieNumber = useCookieNumber;
|
|
154
|
+
const useCookieBoolean = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s === 'true', stringify: (s) => s.toString() }));
|
|
155
|
+
exports.useCookieBoolean = useCookieBoolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.134",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"aws-cdk-lib": "2.x",
|
|
17
|
-
"aws-sdk": "2.
|
|
17
|
+
"aws-sdk": "2.1072.0",
|
|
18
18
|
"axios": "0.25.0",
|
|
19
19
|
"constructs": "10.x",
|
|
20
20
|
"jsonwebtoken": "8.5.1",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jsonwebtoken": "8.5.8",
|
|
32
|
-
"@types/node": "17.0.
|
|
32
|
+
"@types/node": "17.0.17",
|
|
33
33
|
"@types/react": "17.0.39",
|
|
34
34
|
"@types/react-dom": "17.0.11",
|
|
35
35
|
"@types/styled-components": "5.1.22",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare const TextInput: ({ placeholder, value, onChange, onKeyPress, label, disabled, className, focus, }: {
|
|
3
|
-
focus?: boolean | undefined;
|
|
4
|
-
className?: string | undefined;
|
|
5
|
-
disabled?: boolean | undefined;
|
|
6
|
-
label?: string | JSX.Element | undefined;
|
|
7
|
-
placeholder?: string | undefined;
|
|
8
|
-
value: string;
|
|
9
|
-
onChange: (value: string) => void;
|
|
10
|
-
onKeyPress?: ((event: React.KeyboardEvent<HTMLInputElement>) => void) | undefined;
|
|
11
|
-
}) => JSX.Element;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.TextInput = void 0;
|
|
26
|
-
const react_1 = __importStar(require("react"));
|
|
27
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
28
|
-
const math_1 = require("../../../common/helpers/math");
|
|
29
|
-
const colours_1 = require("../../styles/colours");
|
|
30
|
-
const Base = styled_components_1.default.input `
|
|
31
|
-
font-size: 1.2rem;
|
|
32
|
-
border: solid 1px ${colours_1.colours.lightCharcoal};
|
|
33
|
-
border-radius: 0.5rem;
|
|
34
|
-
padding: 0.5rem;
|
|
35
|
-
width: calc(100% - 1.5rem);
|
|
36
|
-
&:disabled {
|
|
37
|
-
background-color: ${colours_1.colours.darker};
|
|
38
|
-
cursor: not-allowed;
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
const TextInput = ({ placeholder, value, onChange, onKeyPress, label, disabled = false, className, focus, }) => {
|
|
42
|
-
const [id] = (0, react_1.useState)((0, math_1.getRandomInt)(1000).toString());
|
|
43
|
-
const tiref = (0, react_1.useRef)(null);
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
45
|
-
if (focus && (tiref === null || tiref === void 0 ? void 0 : tiref.current)) {
|
|
46
|
-
tiref.current.focus();
|
|
47
|
-
}
|
|
48
|
-
}, [focus]);
|
|
49
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
50
|
-
id && label ? react_1.default.createElement("label", { htmlFor: id }, label) : '',
|
|
51
|
-
react_1.default.createElement(Base, { ref: tiref, className: className, disabled: disabled, id: id, placeholder: placeholder, required: true, value: value, onChange: (e) => onChange(e.target.value), onKeyPress: (e) => onKeyPress && onKeyPress(e) })));
|
|
52
|
-
};
|
|
53
|
-
exports.TextInput = TextInput;
|