ag-common 0.0.211 → 0.0.216
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/array.d.ts +1 -1
- package/dist/common/helpers/array.js +16 -4
- package/dist/ui/components/Button/index.d.ts +5 -3
- package/dist/ui/components/HeadersRaw/index.d.ts +5 -4
- package/dist/ui/components/Icon/index.d.ts +3 -4
- package/dist/ui/components/Prompt/Dialog.d.ts +7 -0
- package/dist/ui/components/Prompt/Dialog.js +25 -0
- package/dist/ui/components/Prompt/Modal.d.ts +11 -0
- package/dist/ui/components/Prompt/Modal.js +96 -0
- package/dist/ui/components/Prompt/index.d.ts +2 -6
- package/dist/ui/components/Prompt/index.js +4 -97
- package/dist/ui/components/Search/Base.js +1 -1
- package/dist/ui/components/Search/types.d.ts +1 -1
- package/dist/ui/components/Sidebar/index.js +1 -1
- package/dist/ui/components/Toast/index.d.ts +2 -3
- package/dist/ui/helpers/callOpenApi/direct.d.ts +1 -1
- package/dist/ui/helpers/callOpenApi/direct.js +35 -21
- package/dist/ui/helpers/cookie/set.js +1 -1
- package/dist/ui/helpers/dom.d.ts +6 -0
- package/dist/ui/helpers/dom.js +15 -1
- package/package.json +5 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const arrayToObject: <TIn, Indexer extends string | number, TOut>(arr: TIn[], keyF: (a: TIn) => Indexer, valueF: (a: TIn) => TOut) => { [a in Indexer]: TOut; };
|
|
2
2
|
export declare const flat: <T>(arr: T[][]) => T[];
|
|
3
3
|
export declare const take: <T>(array: T[], num: number) => {
|
|
4
4
|
part: T[];
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.distinct = exports.distinctBy = exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.distinct = exports.distinctBy = exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.arrayToObject = void 0;
|
|
4
|
+
const arrayToObject = (
|
|
5
|
+
/**
|
|
6
|
+
* array items
|
|
7
|
+
*/
|
|
8
|
+
arr,
|
|
9
|
+
/**
|
|
10
|
+
* from an array item, get the indexer
|
|
11
|
+
*/
|
|
12
|
+
keyF,
|
|
13
|
+
/**
|
|
14
|
+
* from an array item, return the new value
|
|
15
|
+
*/
|
|
16
|
+
valueF) => {
|
|
5
17
|
const ret = {};
|
|
6
18
|
if (!arr || !keyF) {
|
|
7
19
|
return ret;
|
|
8
20
|
}
|
|
9
21
|
arr.forEach((v) => {
|
|
10
22
|
const k = keyF(v);
|
|
11
|
-
ret[k] = v;
|
|
23
|
+
ret[k] = valueF(v);
|
|
12
24
|
});
|
|
13
25
|
return ret;
|
|
14
26
|
};
|
|
15
|
-
exports.
|
|
27
|
+
exports.arrayToObject = arrayToObject;
|
|
16
28
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
29
|
// @ts-ignore
|
|
18
30
|
const flat = (arr) => [].concat(...arr);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { KeyboardEventHandler, MouseEventHandler } from 'react';
|
|
2
2
|
export declare const ButtonBase: import("styled-components").FlattenSimpleInterpolation;
|
|
3
|
-
export
|
|
3
|
+
export interface IButton {
|
|
4
4
|
title?: string;
|
|
5
5
|
invert?: boolean;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
className?: string;
|
|
8
8
|
onClick?: MouseEventHandler<HTMLButtonElement>;
|
|
9
9
|
onKeyPress?: KeyboardEventHandler<HTMLButtonElement>;
|
|
10
|
-
|
|
10
|
+
children: string | JSX.Element;
|
|
11
|
+
}
|
|
12
|
+
export declare const Button: (props: IButton) => JSX.Element;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export
|
|
3
|
-
title?: string
|
|
4
|
-
image?: string
|
|
2
|
+
export interface IHeadersRaw {
|
|
3
|
+
title?: string;
|
|
4
|
+
image?: string;
|
|
5
5
|
SiteShort: string;
|
|
6
6
|
FullSiteUrl: string;
|
|
7
7
|
siteDesc: string;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
export declare const HeadersRaw: ({ title, image, SiteShort, FullSiteUrl, siteDesc, }: IHeadersRaw) => JSX.Element[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface
|
|
2
|
+
export interface IIconProps {
|
|
3
3
|
disabled?: boolean;
|
|
4
4
|
fill?: string;
|
|
5
5
|
outline?: string;
|
|
@@ -16,6 +16,5 @@ interface IIcon {
|
|
|
16
16
|
tabIndex?: number;
|
|
17
17
|
className?: string;
|
|
18
18
|
}
|
|
19
|
-
export declare const IconF: import("styled-components").StyledComponent<"span", any,
|
|
20
|
-
export declare const Icon: (pr:
|
|
21
|
-
export {};
|
|
19
|
+
export declare const IconF: import("styled-components").StyledComponent<"span", any, IIconProps, never>;
|
|
20
|
+
export declare const Icon: (pr: IIconProps) => JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PromptDialog = void 0;
|
|
16
|
+
const Modal_1 = require("./Modal");
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
19
|
+
const PromptDialog = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
return new Promise((res) => {
|
|
21
|
+
const wrapper = document.body.appendChild(document.createElement('div'));
|
|
22
|
+
react_dom_1.default.render(react_1.default.createElement(Modal_1.PromptModal, Object.assign({}, p, { res: res, wrapper: wrapper })), wrapper);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
exports.PromptDialog = PromptDialog;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const PromptModal: ({ wrapper, res, bottomText, topText, okText, cancelText, defaultValue, placeholder, }: {
|
|
3
|
+
defaultValue?: string | undefined;
|
|
4
|
+
placeholder?: string | undefined;
|
|
5
|
+
res: (v: string | undefined) => void;
|
|
6
|
+
wrapper: HTMLDivElement;
|
|
7
|
+
topText?: string | undefined;
|
|
8
|
+
bottomText: string;
|
|
9
|
+
okText?: string | undefined;
|
|
10
|
+
cancelText?: string | undefined;
|
|
11
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.PromptModal = void 0;
|
|
30
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
31
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
32
|
+
const Button_1 = require("../Button");
|
|
33
|
+
const FlexColumn_1 = require("../FlexColumn");
|
|
34
|
+
const FlexRow_1 = require("../FlexRow");
|
|
35
|
+
const Modal_1 = require("../Modal");
|
|
36
|
+
const TextEdit_1 = require("../TextEdit");
|
|
37
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
38
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const Base = styled_components_1.default.div `
|
|
41
|
+
width: 95vw;
|
|
42
|
+
max-width: 30rem;
|
|
43
|
+
height: 50vh;
|
|
44
|
+
max-height: 15rem;
|
|
45
|
+
padding: 1rem;
|
|
46
|
+
`;
|
|
47
|
+
const Content = (0, styled_components_1.default)(FlexColumn_1.FlexColumn) `
|
|
48
|
+
height: 100%;
|
|
49
|
+
`;
|
|
50
|
+
const TopText = styled_components_1.default.div `
|
|
51
|
+
font-weight: bold;
|
|
52
|
+
border-bottom: solid 1px #ccc;
|
|
53
|
+
padding-bottom: 0.25rem;
|
|
54
|
+
font-size: 1.5rem;
|
|
55
|
+
margin-bottom: 1rem;
|
|
56
|
+
`;
|
|
57
|
+
const BottomText = styled_components_1.default.div `
|
|
58
|
+
padding-bottom: 0.25rem;
|
|
59
|
+
font-size: 1.1rem;
|
|
60
|
+
`;
|
|
61
|
+
const Bottom = (0, styled_components_1.default)(FlexRow_1.FlexRow) `
|
|
62
|
+
margin-top: auto;
|
|
63
|
+
justify-content: flex-end;
|
|
64
|
+
> button:first-child {
|
|
65
|
+
margin-right: 1rem;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelText = 'Cancel', defaultValue, placeholder, }) => {
|
|
69
|
+
const [text, setText] = (0, react_1.useState)(defaultValue || '');
|
|
70
|
+
const ret = (v) => {
|
|
71
|
+
try {
|
|
72
|
+
res(v);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
react_dom_1.default.unmountComponentAtNode(wrapper);
|
|
76
|
+
wrapper.remove();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return (react_1.default.createElement(Modal_1.Modal, { position: "center", topPosition: "center", open: true, setOpen: () => ret(undefined), showCloseButton: false, closeOnClickOutside: false },
|
|
80
|
+
react_1.default.createElement(Base, null,
|
|
81
|
+
react_1.default.createElement(Content, null,
|
|
82
|
+
topText && react_1.default.createElement(TopText, null, topText),
|
|
83
|
+
react_1.default.createElement(BottomText, null, bottomText),
|
|
84
|
+
react_1.default.createElement(TextEdit_1.TextEdit, { defaultValue: text, onSubmit: (c, enter) => {
|
|
85
|
+
if (enter) {
|
|
86
|
+
ret(c);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
setText(c);
|
|
90
|
+
}
|
|
91
|
+
}, placeholder: placeholder, defaultEditing: { focus: true }, singleLine: true, noGrow: true }),
|
|
92
|
+
react_1.default.createElement(Bottom, { noGrow: true },
|
|
93
|
+
react_1.default.createElement(Button_1.Button, { onClick: () => ret(text) }, okText),
|
|
94
|
+
react_1.default.createElement(Button_1.Button, { invert: true, onClick: () => ret(undefined) }, cancelText))))));
|
|
95
|
+
};
|
|
96
|
+
exports.PromptModal = PromptModal;
|
|
@@ -10,102 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
15
|
};
|
|
37
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports
|
|
39
|
-
|
|
40
|
-
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
41
|
-
const Button_1 = require("../Button");
|
|
42
|
-
const FlexColumn_1 = require("../FlexColumn");
|
|
43
|
-
const FlexRow_1 = require("../FlexRow");
|
|
44
|
-
const Modal_1 = require("../Modal");
|
|
45
|
-
const TextEdit_1 = require("../TextEdit");
|
|
46
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
47
|
-
const react_dom_1 = __importDefault(require("react-dom"));
|
|
48
|
-
const react_1 = __importStar(require("react"));
|
|
49
|
-
const Base = styled_components_1.default.div `
|
|
50
|
-
width: 95vw;
|
|
51
|
-
max-width: 30rem;
|
|
52
|
-
height: 50vh;
|
|
53
|
-
max-height: 15rem;
|
|
54
|
-
padding: 1rem;
|
|
55
|
-
`;
|
|
56
|
-
const Content = (0, styled_components_1.default)(FlexColumn_1.FlexColumn) `
|
|
57
|
-
height: 100%;
|
|
58
|
-
`;
|
|
59
|
-
const TopText = styled_components_1.default.div `
|
|
60
|
-
font-weight: bold;
|
|
61
|
-
border-bottom: solid 1px #ccc;
|
|
62
|
-
padding-bottom: 0.25rem;
|
|
63
|
-
font-size: 1.5rem;
|
|
64
|
-
margin-bottom: 1rem;
|
|
65
|
-
`;
|
|
66
|
-
const BottomText = styled_components_1.default.div `
|
|
67
|
-
padding-bottom: 0.25rem;
|
|
68
|
-
font-size: 1.1rem;
|
|
69
|
-
`;
|
|
70
|
-
const Bottom = (0, styled_components_1.default)(FlexRow_1.FlexRow) `
|
|
71
|
-
margin-top: auto;
|
|
72
|
-
justify-content: flex-end;
|
|
73
|
-
> button:first-child {
|
|
74
|
-
margin-right: 1rem;
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelText = 'Cancel', defaultValue, placeholder, }) => {
|
|
78
|
-
const [text, setText] = (0, react_1.useState)(defaultValue || '');
|
|
79
|
-
const ret = (v) => {
|
|
80
|
-
try {
|
|
81
|
-
res(v);
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
react_dom_1.default.unmountComponentAtNode(wrapper);
|
|
85
|
-
wrapper.remove();
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return (react_1.default.createElement(Modal_1.Modal, { position: "center", topPosition: "center", open: true, setOpen: () => ret(undefined), showCloseButton: false, closeOnClickOutside: false },
|
|
89
|
-
react_1.default.createElement(Base, null,
|
|
90
|
-
react_1.default.createElement(Content, null,
|
|
91
|
-
topText && react_1.default.createElement(TopText, null, topText),
|
|
92
|
-
react_1.default.createElement(BottomText, null, bottomText),
|
|
93
|
-
react_1.default.createElement(TextEdit_1.TextEdit, { defaultValue: text, onSubmit: (c, enter) => {
|
|
94
|
-
if (enter) {
|
|
95
|
-
ret(c);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
setText(c);
|
|
99
|
-
}
|
|
100
|
-
}, placeholder: placeholder, defaultEditing: { focus: true }, singleLine: true, noGrow: true }),
|
|
101
|
-
react_1.default.createElement(Bottom, { noGrow: true },
|
|
102
|
-
react_1.default.createElement(Button_1.Button, { onClick: () => ret(text) }, okText),
|
|
103
|
-
react_1.default.createElement(Button_1.Button, { invert: true, onClick: () => ret(undefined) }, cancelText))))));
|
|
104
|
-
};
|
|
105
|
-
const prompt = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
-
return new Promise((res) => {
|
|
107
|
-
const wrapper = document.body.appendChild(document.createElement('div'));
|
|
108
|
-
react_dom_1.default.render(react_1.default.createElement(PromptModal, Object.assign({}, p, { res: res, wrapper: wrapper })), wrapper);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
exports.prompt = prompt;
|
|
17
|
+
__exportStar(require("./Dialog"), exports);
|
|
18
|
+
__exportStar(require("./Modal"), exports);
|
|
@@ -97,6 +97,6 @@ const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeTe
|
|
|
97
97
|
onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange(v);
|
|
98
98
|
}, { key: 'pagesearch', time: 200 }), defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, MagnifyIconSvg), noGrow: true, allowUndo: false, onEscape: () => resWrap(undefined), onClickOutsideWithNoValue: null }),
|
|
99
99
|
react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
|
|
100
|
-
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length }, filteredItems.map((i) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i)))))));
|
|
100
|
+
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length }, filteredItems.map((i, index) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i, index)))))));
|
|
101
101
|
};
|
|
102
102
|
exports.SearchBase = SearchBase;
|
|
@@ -5,7 +5,7 @@ export interface ISearchDialog<T> {
|
|
|
5
5
|
/**
|
|
6
6
|
* method run to render each filtered item
|
|
7
7
|
*/
|
|
8
|
-
renderItem: (searchText: string, item: T) => JSX.Element | string;
|
|
8
|
+
renderItem: (searchText: string, item: T, index: number) => JSX.Element | string;
|
|
9
9
|
/**
|
|
10
10
|
* all potential items
|
|
11
11
|
*/
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ToastPosition } from 'react-hot-toast';
|
|
3
|
-
interface
|
|
3
|
+
export interface IToastOptions {
|
|
4
4
|
appearance: 'error' | 'success';
|
|
5
5
|
autoClose?: number;
|
|
6
6
|
}
|
|
7
|
-
export declare const addToast: (m: string, options?:
|
|
7
|
+
export declare const addToast: (m: string, options?: IToastOptions | undefined) => void;
|
|
8
8
|
export declare const ToastProvider: ({ position }: {
|
|
9
9
|
position: ToastPosition;
|
|
10
10
|
}) => JSX.Element;
|
|
11
|
-
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ICallOpenApi } from './types';
|
|
2
2
|
import { AxiosWrapperLite } from '../jwt';
|
|
3
|
-
export declare const callOpenApi: <T, TDefaultApi>(
|
|
3
|
+
export declare const callOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapperLite<T>>;
|
|
@@ -13,8 +13,33 @@ exports.callOpenApi = void 0;
|
|
|
13
13
|
const cookie_1 = require("../cookie");
|
|
14
14
|
const sleep_1 = require("../../../common/helpers/sleep");
|
|
15
15
|
const array_1 = require("../../../common/helpers/array");
|
|
16
|
-
|
|
17
|
-
var _a, _b
|
|
16
|
+
function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let idToken;
|
|
20
|
+
//if override supplied will only use that and not refresh
|
|
21
|
+
if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
|
|
22
|
+
idToken = overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
idToken = (0, cookie_1.getCookieString)({
|
|
26
|
+
name: 'id_token',
|
|
27
|
+
defaultValue: '',
|
|
28
|
+
});
|
|
29
|
+
//if we have a cookie token, can try to refresh
|
|
30
|
+
if (idToken) {
|
|
31
|
+
const updated = yield refreshToken();
|
|
32
|
+
if ((_a = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
33
|
+
idToken = (_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return idToken;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
42
|
+
const { func, apiUrl, logout, newDefaultApi, headers } = p;
|
|
18
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
44
|
let error;
|
|
20
45
|
let data = undefined;
|
|
@@ -22,20 +47,9 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
22
47
|
basePath: apiUrl,
|
|
23
48
|
baseOptions: { headers: Object.assign({ authorization: '' }, (headers || {})) },
|
|
24
49
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else {
|
|
29
|
-
const isAuthed = !!(0, cookie_1.getCookieString)({
|
|
30
|
-
name: 'id_token',
|
|
31
|
-
defaultValue: '',
|
|
32
|
-
});
|
|
33
|
-
if (isAuthed) {
|
|
34
|
-
const updated = yield refreshToken();
|
|
35
|
-
if ((_a = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
36
|
-
config.baseOptions.headers.authorization = `Bearer ${(_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token}`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
50
|
+
const idToken = yield getIdTokenAuthHeader(p);
|
|
51
|
+
if (idToken) {
|
|
52
|
+
config.baseOptions.headers.authorization = `Bearer ${idToken}`;
|
|
39
53
|
}
|
|
40
54
|
const cl = newDefaultApi(config);
|
|
41
55
|
let errorCount = 0;
|
|
@@ -54,13 +68,13 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
54
68
|
catch (e) {
|
|
55
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
70
|
const ae = e;
|
|
57
|
-
const status = (
|
|
71
|
+
const status = (_a = ae.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
58
72
|
const errorMessage = [
|
|
59
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
(
|
|
61
|
-
(
|
|
62
|
-
(
|
|
63
|
-
(
|
|
74
|
+
(_d = (_c = (_b = ae.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '',
|
|
75
|
+
(_g = (_f = (_e = ae.response) === null || _e === void 0 ? void 0 : _e.statusText) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : '',
|
|
76
|
+
(_k = (_j = (_h = ae.response) === null || _h === void 0 ? void 0 : _h.status) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _k !== void 0 ? _k : '',
|
|
77
|
+
(_m = (_l = ae.message) === null || _l === void 0 ? void 0 : _l.toString()) !== null && _m !== void 0 ? _m : '',
|
|
64
78
|
]
|
|
65
79
|
.filter(array_1.notEmpty)
|
|
66
80
|
.sort((a, b) => (a.length < b.length ? -1 : 1))
|
|
@@ -17,7 +17,7 @@ function setCookieRaw({ name, value, expiryDays = 1, }) {
|
|
|
17
17
|
const d = new Date();
|
|
18
18
|
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
19
19
|
const expires = `expires=${!value || expiryDays < 0 ? const_1.expireDate : d.toUTCString()}`;
|
|
20
|
-
document.cookie = `${name}=${!value ? '' : value};${expires};path
|
|
20
|
+
document.cookie = `${name}=${!value ? '' : value};${expires};path=/; SameSite=Strict; Secure`;
|
|
21
21
|
}
|
|
22
22
|
function wipeCookies(name) {
|
|
23
23
|
if (typeof window === 'undefined') {
|
package/dist/ui/helpers/dom.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export declare const domContains: (e: DOMRect | undefined, x: number, y: number) => boolean;
|
|
2
2
|
export declare const convertRemToPixels: (rem: number) => number;
|
|
3
|
+
/**
|
|
4
|
+
* can use to nested wrap styledcomponent components, but persist data- attributes
|
|
5
|
+
* @param p
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const filterDataProps: (p: any) => Record<string, string>;
|
package/dist/ui/helpers/dom.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertRemToPixels = exports.domContains = void 0;
|
|
3
|
+
exports.filterDataProps = exports.convertRemToPixels = exports.domContains = void 0;
|
|
4
|
+
const array_1 = require("../../common/helpers/array");
|
|
4
5
|
const domContains = (e, x, y) => {
|
|
5
6
|
if (!e) {
|
|
6
7
|
return false;
|
|
@@ -16,3 +17,16 @@ const convertRemToPixels = (rem) => {
|
|
|
16
17
|
return rem * parseFloat(fontSize);
|
|
17
18
|
};
|
|
18
19
|
exports.convertRemToPixels = convertRemToPixels;
|
|
20
|
+
/**
|
|
21
|
+
* can use to nested wrap styledcomponent components, but persist data- attributes
|
|
22
|
+
* @param p
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const filterDataProps = (p) => {
|
|
27
|
+
const x = Object.entries(p)
|
|
28
|
+
.filter((r) => r[0].startsWith('data-'))
|
|
29
|
+
.map((r) => r);
|
|
30
|
+
return (0, array_1.arrayToObject)(x, (s) => s[0], (s) => s[1]);
|
|
31
|
+
};
|
|
32
|
+
exports.filterDataProps = filterDataProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.216",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"packageManager": "yarn@3.2.0",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"format": "npx eslint --ext .ts,.tsx ./src --fix",
|
|
12
|
-
"build": "rimraf dist && yarn lint && tsc
|
|
12
|
+
"build": "rimraf dist && yarn lint && tsc",
|
|
13
13
|
"lint": "npx eslint --ext .ts,.tsx ./src",
|
|
14
14
|
"start": "cross-env BROWSER=none start-storybook -p 6006",
|
|
15
15
|
"build-storybook": "build-storybook -o docs --quiet"
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/core": "7.17.8",
|
|
34
|
-
"@mdx-js/react": "1.6.22",
|
|
35
34
|
"@storybook/addon-actions": "6.4.20",
|
|
36
35
|
"@storybook/addon-docs": "6.4.20",
|
|
37
36
|
"@storybook/addon-essentials": "6.4.20",
|
|
38
37
|
"@storybook/addon-interactions": "6.4.20",
|
|
39
38
|
"@storybook/addon-links": "6.4.20",
|
|
39
|
+
"@storybook/addons": "^6.4.20",
|
|
40
40
|
"@storybook/react": "6.4.20",
|
|
41
|
-
"@storybook/
|
|
41
|
+
"@storybook/theming": "^6.4.20",
|
|
42
42
|
"@types/jsonwebtoken": "8.5.8",
|
|
43
43
|
"@types/node": "17.0.23",
|
|
44
44
|
"@types/react": "17.0.43",
|
|
@@ -46,21 +46,17 @@
|
|
|
46
46
|
"@types/styled-components": "5.1.24",
|
|
47
47
|
"@typescript-eslint/eslint-plugin": "5.18.0",
|
|
48
48
|
"@typescript-eslint/parser": "5.18.0",
|
|
49
|
-
"babel-loader": "8.2.4",
|
|
50
49
|
"cross-env": "7.0.3",
|
|
51
50
|
"eslint": "8.12.0",
|
|
52
51
|
"eslint-config-airbnb-typescript": "16.2.0",
|
|
53
52
|
"eslint-config-prettier": "8.5.0",
|
|
54
|
-
"eslint-config-react-app": "7.0.0",
|
|
55
53
|
"eslint-plugin-import": "2.25.4",
|
|
56
54
|
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
57
55
|
"eslint-plugin-prettier": "4.0.0",
|
|
58
56
|
"eslint-plugin-react": "7.29.4",
|
|
59
57
|
"eslint-plugin-react-hooks": "4.4.0",
|
|
60
58
|
"prettier": "2.6.2",
|
|
61
|
-
"rimraf": "3.0.2"
|
|
62
|
-
"storybook": "6.4.20",
|
|
63
|
-
"typescript-styled-plugin": "0.18.2"
|
|
59
|
+
"rimraf": "3.0.2"
|
|
64
60
|
},
|
|
65
61
|
"files": [
|
|
66
62
|
"dist/**/*",
|