ag-common 0.0.20 → 0.0.24
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/api/helpers/dynamo.d.ts +2 -2
- package/dist/api/helpers/validateOpenApi.js +6 -0
- package/dist/api/types/aws.d.ts +100 -0
- package/dist/api/{types.js → types/aws.js} +0 -0
- package/dist/api/{types.d.ts → types/index.d.ts} +2 -30
- package/dist/api/types/index.js +13 -0
- package/dist/common/helpers/async.d.ts +13 -0
- package/dist/common/helpers/async.js +41 -0
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +1 -0
- package/dist/common/helpers/log.d.ts +1 -1
- package/dist/common/helpers/log.js +24 -47
- package/dist/common/helpers/string.d.ts +7 -0
- package/dist/common/helpers/string.js +35 -1
- package/dist/ui/components/DropdownList/index.js +14 -2
- package/dist/ui/helpers/callOpenApi.js +2 -5
- package/dist/ui/helpers/dom.d.ts +1 -0
- package/dist/ui/helpers/dom.js +3 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DocumentClient
|
|
2
|
-
import { IQueryDynamo } from '../types';
|
|
1
|
+
import { DocumentClient } from 'aws-sdk/clients/dynamodb';
|
|
2
|
+
import { IQueryDynamo, Key } from '../types';
|
|
3
3
|
export declare let dynamoDb: DocumentClient;
|
|
4
4
|
export declare const setDynamo: (region: string) => void;
|
|
5
5
|
export declare const putDynamo: <T>(item: T, tableName: string) => Promise<{
|
|
@@ -46,6 +46,12 @@ const getOperation = ({ path, method, resource, schema, }) => {
|
|
|
46
46
|
function validateOpenApi({ event, next, authorized, schema, COGNITO_USER_POOL_ID, }) {
|
|
47
47
|
var _a, _b, _c, _d, _e;
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!schema) {
|
|
50
|
+
throw new Error('schema undefined!');
|
|
51
|
+
}
|
|
52
|
+
if (!COGNITO_USER_POOL_ID) {
|
|
53
|
+
throw new Error('COGNITO_USER_POOL_ID undefined');
|
|
54
|
+
}
|
|
49
55
|
const request = {
|
|
50
56
|
method: event.httpMethod,
|
|
51
57
|
path: event.path,
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export interface APIGatewayProxyResult {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
headers?: {
|
|
4
|
+
[header: string]: boolean | number | string;
|
|
5
|
+
} | undefined;
|
|
6
|
+
multiValueHeaders?: {
|
|
7
|
+
[header: string]: Array<boolean | number | string>;
|
|
8
|
+
} | undefined;
|
|
9
|
+
body: string;
|
|
10
|
+
isBase64Encoded?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface APIGatewayEvent {
|
|
13
|
+
body: string | null;
|
|
14
|
+
headers: Record<string, string | undefined>;
|
|
15
|
+
httpMethod: string;
|
|
16
|
+
queryStringParameters: Record<string, string> | null;
|
|
17
|
+
pathParameters: Record<string, string> | null;
|
|
18
|
+
resource: string;
|
|
19
|
+
path: string;
|
|
20
|
+
requestContext: {
|
|
21
|
+
connectionId: string;
|
|
22
|
+
domainName: string;
|
|
23
|
+
identity: {
|
|
24
|
+
userAgent: string;
|
|
25
|
+
sourceIp: string;
|
|
26
|
+
};
|
|
27
|
+
httpMethod: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface AttributeValue {
|
|
31
|
+
B?: string | undefined;
|
|
32
|
+
BS?: string[] | undefined;
|
|
33
|
+
BOOL?: boolean | undefined;
|
|
34
|
+
L?: AttributeValue[] | undefined;
|
|
35
|
+
M?: {
|
|
36
|
+
[id: string]: AttributeValue;
|
|
37
|
+
} | undefined;
|
|
38
|
+
N?: string | undefined;
|
|
39
|
+
NS?: string[] | undefined;
|
|
40
|
+
NULL?: boolean | undefined;
|
|
41
|
+
S?: string | undefined;
|
|
42
|
+
SS?: string[] | undefined;
|
|
43
|
+
}
|
|
44
|
+
export interface AppSyncResolverEvent<TArguments, TSource = Record<string, any> | null> {
|
|
45
|
+
arguments: TArguments;
|
|
46
|
+
identity?: any;
|
|
47
|
+
source: TSource;
|
|
48
|
+
request: {
|
|
49
|
+
headers: {
|
|
50
|
+
[name: string]: string | undefined;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
info: {
|
|
54
|
+
selectionSetList: string[];
|
|
55
|
+
selectionSetGraphQL: string;
|
|
56
|
+
parentTypeName: string;
|
|
57
|
+
fieldName: string;
|
|
58
|
+
variables: {
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
prev: {
|
|
63
|
+
result: {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
} | null;
|
|
67
|
+
stash: {
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface DynamoDBStreamEvent {
|
|
72
|
+
Records: {
|
|
73
|
+
awsRegion?: string | undefined;
|
|
74
|
+
dynamodb?: {
|
|
75
|
+
ApproximateCreationDateTime?: number | undefined;
|
|
76
|
+
Keys?: {
|
|
77
|
+
[key: string]: AttributeValue;
|
|
78
|
+
} | undefined;
|
|
79
|
+
NewImage?: {
|
|
80
|
+
[key: string]: AttributeValue;
|
|
81
|
+
} | undefined;
|
|
82
|
+
OldImage?: {
|
|
83
|
+
[key: string]: AttributeValue;
|
|
84
|
+
} | undefined;
|
|
85
|
+
SequenceNumber?: string | undefined;
|
|
86
|
+
SizeBytes?: number | undefined;
|
|
87
|
+
StreamViewType?: 'KEYS_ONLY' | 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES' | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
eventID?: string | undefined;
|
|
90
|
+
eventName?: 'INSERT' | 'MODIFY' | 'REMOVE' | undefined;
|
|
91
|
+
eventSource?: string | undefined;
|
|
92
|
+
eventSourceARN?: string | undefined;
|
|
93
|
+
eventVersion?: string | undefined;
|
|
94
|
+
userIdentity?: any;
|
|
95
|
+
}[];
|
|
96
|
+
}
|
|
97
|
+
export declare type Key = {
|
|
98
|
+
[key: string]: AttributeValue;
|
|
99
|
+
};
|
|
100
|
+
export {};
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { aws_dynamodb as dynamodb } from 'aws-cdk-lib';
|
|
2
|
-
import { Key } from 'aws
|
|
2
|
+
import { Key } from './aws';
|
|
3
3
|
export interface DYNAMOKEYS {
|
|
4
4
|
type: string;
|
|
5
5
|
L1: string;
|
|
@@ -43,32 +43,4 @@ export interface IQueryDynamo {
|
|
|
43
43
|
filterValue?: string | number;
|
|
44
44
|
filterOperator?: string;
|
|
45
45
|
}
|
|
46
|
-
export
|
|
47
|
-
statusCode: number;
|
|
48
|
-
headers?: {
|
|
49
|
-
[header: string]: boolean | number | string;
|
|
50
|
-
} | undefined;
|
|
51
|
-
multiValueHeaders?: {
|
|
52
|
-
[header: string]: Array<boolean | number | string>;
|
|
53
|
-
} | undefined;
|
|
54
|
-
body: string;
|
|
55
|
-
isBase64Encoded?: boolean | undefined;
|
|
56
|
-
}
|
|
57
|
-
export interface APIGatewayEvent {
|
|
58
|
-
body: string | null;
|
|
59
|
-
headers: Record<string, string | undefined>;
|
|
60
|
-
httpMethod: string;
|
|
61
|
-
queryStringParameters: Record<string, string> | null;
|
|
62
|
-
pathParameters: Record<string, string> | null;
|
|
63
|
-
resource: string;
|
|
64
|
-
path: string;
|
|
65
|
-
requestContext: {
|
|
66
|
-
connectionId: string;
|
|
67
|
-
domainName: string;
|
|
68
|
-
identity: {
|
|
69
|
-
userAgent: string;
|
|
70
|
-
sourceIp: string;
|
|
71
|
-
};
|
|
72
|
-
httpMethod: string;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
46
|
+
export * from './aws';
|
|
@@ -0,0 +1,13 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./aws"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run async forEach over all array items
|
|
3
|
+
* @param array
|
|
4
|
+
* @param callback
|
|
5
|
+
*/
|
|
6
|
+
export declare function asyncForEach<T>(array: T[], callback: (i: T, index: number, array: T[]) => void): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* run async map over all array items
|
|
9
|
+
* @param array
|
|
10
|
+
* @param callback
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function asyncMap<T, TY>(array: T[], callback: (i: T, index: number, array: T[]) => Promise<TY>): Promise<TY[]>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.asyncMap = exports.asyncForEach = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* run async forEach over all array items
|
|
15
|
+
* @param array
|
|
16
|
+
* @param callback
|
|
17
|
+
*/
|
|
18
|
+
function asyncForEach(array, callback) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
for (let index = 0; index < array.length; index += 1) {
|
|
21
|
+
yield callback(array[index], index, array);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.asyncForEach = asyncForEach;
|
|
26
|
+
/**
|
|
27
|
+
* run async map over all array items
|
|
28
|
+
* @param array
|
|
29
|
+
* @param callback
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
function asyncMap(array, callback) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const ret = [];
|
|
35
|
+
for (let index = 0; index < array.length; index += 1) {
|
|
36
|
+
ret.push(yield callback(array[index], index, array));
|
|
37
|
+
}
|
|
38
|
+
return ret;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.asyncMap = asyncMap;
|
|
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./array"), exports);
|
|
14
|
+
__exportStar(require("./async"), exports);
|
|
14
15
|
__exportStar(require("./date"), exports);
|
|
15
16
|
__exportStar(require("./distinctBy"), exports);
|
|
16
17
|
__exportStar(require("./email"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
2
2
|
export declare const GetLogLevel: (l: TLogType) => number;
|
|
3
|
-
export declare const trace: (...args: any[]) => void;
|
|
4
3
|
export declare const debug: (...args: any[]) => void;
|
|
5
4
|
export declare const info: (...args: any[]) => void;
|
|
6
5
|
export declare const warn: (...args: any[]) => void;
|
|
6
|
+
export declare const trace: (...args: any[]) => void;
|
|
7
7
|
export declare const error: (...args: any[]) => void;
|
|
8
8
|
export declare const fatal: (...args: any[]) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fatal = exports.error = exports.
|
|
3
|
+
exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.GetLogLevel = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
|
|
@@ -11,68 +11,43 @@ function dateF() {
|
|
|
11
11
|
const str = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
|
|
12
12
|
return str;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const ret = [];
|
|
16
|
-
args.forEach((a) => {
|
|
17
|
-
a.forEach((v) => {
|
|
18
|
-
if (v !== null &&
|
|
19
|
-
typeof v !== 'undefined' &&
|
|
20
|
-
v.toString().indexOf('Error:') !== -1 &&
|
|
21
|
-
v.stack) {
|
|
22
|
-
ret.push(`${v.stack}`);
|
|
23
|
-
}
|
|
24
|
-
else if (typeof v === 'string') {
|
|
25
|
-
if (v.trim() !== 'undefined') {
|
|
26
|
-
ret.push(`${v.trim()}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (typeof v === 'object') {
|
|
30
|
-
ret.push(JSON.parse(JSON.stringify(v)));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
ret.push(v);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return ret;
|
|
38
|
-
}
|
|
39
|
-
function logprocess(type, date, args) {
|
|
14
|
+
function logprocess(type, args) {
|
|
40
15
|
var _a;
|
|
41
|
-
const msg = `[${date}] ${type} `;
|
|
42
|
-
const argsClean = args.filter(_1.notEmpty);
|
|
43
16
|
const min = (0, exports.GetLogLevel)((_a = process.env.LOG_LEVEL) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'WARN';
|
|
44
17
|
const typesLogLevel = (0, exports.GetLogLevel)(type);
|
|
45
18
|
// env ignores it
|
|
46
19
|
if (typesLogLevel < min) {
|
|
47
20
|
return;
|
|
48
21
|
}
|
|
22
|
+
////////
|
|
23
|
+
const log = [`[${dateF()}]`, type, ...args.filter(_1.notEmpty)];
|
|
49
24
|
switch (type) {
|
|
50
25
|
case 'TRACE': {
|
|
51
|
-
console.trace(
|
|
26
|
+
console.trace(...log);
|
|
52
27
|
break;
|
|
53
28
|
}
|
|
54
29
|
case 'DEBUG': {
|
|
55
|
-
console.debug(
|
|
30
|
+
console.debug(...log);
|
|
56
31
|
break;
|
|
57
32
|
}
|
|
58
33
|
case 'INFO': {
|
|
59
|
-
console.log(
|
|
34
|
+
console.log(...log);
|
|
60
35
|
break;
|
|
61
36
|
}
|
|
62
37
|
case 'WARN': {
|
|
63
|
-
console.warn(
|
|
38
|
+
console.warn(...log);
|
|
64
39
|
break;
|
|
65
40
|
}
|
|
66
41
|
case 'ERROR': {
|
|
67
|
-
console.error(
|
|
42
|
+
console.error(...log);
|
|
68
43
|
break;
|
|
69
44
|
}
|
|
70
45
|
case 'FATAL': {
|
|
71
|
-
console.error(
|
|
46
|
+
console.error(...log);
|
|
72
47
|
break;
|
|
73
48
|
}
|
|
74
49
|
default: {
|
|
75
|
-
console.log(
|
|
50
|
+
console.log(...log);
|
|
76
51
|
break;
|
|
77
52
|
}
|
|
78
53
|
}
|
|
@@ -131,23 +106,25 @@ function printStackTrace(...args) {
|
|
|
131
106
|
}
|
|
132
107
|
return callstack.join('\n');
|
|
133
108
|
}
|
|
109
|
+
const debug = (...args) => logprocess('DEBUG', args);
|
|
110
|
+
exports.debug = debug;
|
|
111
|
+
const info = (...args) => logprocess('INFO', args);
|
|
112
|
+
exports.info = info;
|
|
113
|
+
const warn = (...args) => logprocess('WARN', args);
|
|
114
|
+
exports.warn = warn;
|
|
115
|
+
//
|
|
134
116
|
const trace = (...args) => {
|
|
135
|
-
const argsNice = nicify(args);
|
|
136
117
|
args.push(printStackTrace());
|
|
137
|
-
logprocess('TRACE',
|
|
118
|
+
logprocess('TRACE', args);
|
|
138
119
|
};
|
|
139
120
|
exports.trace = trace;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const warn = (...args) => logprocess('WARN', dateF(), nicify(args));
|
|
145
|
-
exports.warn = warn;
|
|
146
|
-
const error = (...args) => logprocess('ERROR', dateF(), nicify(args));
|
|
121
|
+
const error = (...args) => {
|
|
122
|
+
args.push(printStackTrace());
|
|
123
|
+
logprocess('ERROR', args);
|
|
124
|
+
};
|
|
147
125
|
exports.error = error;
|
|
148
126
|
const fatal = (...args) => {
|
|
149
|
-
const argsNice = nicify(args);
|
|
150
127
|
args.push(printStackTrace());
|
|
151
|
-
logprocess('FATAL',
|
|
128
|
+
logprocess('FATAL', args);
|
|
152
129
|
};
|
|
153
130
|
exports.fatal = fatal;
|
|
@@ -16,3 +16,10 @@ export declare const niceUrl: (siteUrl: string) => ISite | undefined;
|
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
18
|
export declare function toTitleCase(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* remove all found params from str
|
|
21
|
+
* @param str
|
|
22
|
+
* @param params allows single chars and/or strings
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function replaceRemove(str: string, ...params: string[]): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = void 0;
|
|
3
|
+
exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = void 0;
|
|
4
4
|
const csvJSON = (csv) => {
|
|
5
5
|
const lines = csv.split('\n');
|
|
6
6
|
const result = [];
|
|
@@ -75,3 +75,37 @@ function toTitleCase(str) {
|
|
|
75
75
|
return str.replace(/\w\S*/g, (txt) => txt && txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase());
|
|
76
76
|
}
|
|
77
77
|
exports.toTitleCase = toTitleCase;
|
|
78
|
+
/**
|
|
79
|
+
* remove all found params from str
|
|
80
|
+
* @param str
|
|
81
|
+
* @param params allows single chars and/or strings
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
function replaceRemove(str, ...params) {
|
|
85
|
+
const replaceSingles = [];
|
|
86
|
+
const replaceStrings = [];
|
|
87
|
+
params.forEach((p) => {
|
|
88
|
+
if (typeof p !== 'string') {
|
|
89
|
+
throw new Error('trim only supports strings');
|
|
90
|
+
}
|
|
91
|
+
if (p.length === 1) {
|
|
92
|
+
replaceSingles.push(p);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
replaceStrings.push(p);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
let firstLength = 0;
|
|
99
|
+
let changedLength = 0;
|
|
100
|
+
let ret = str;
|
|
101
|
+
const singleRegex = `[${replaceSingles.join('')}]*`;
|
|
102
|
+
const stringRegex = `(${replaceStrings.map((s) => `(${s})`).join('|')})*`;
|
|
103
|
+
do {
|
|
104
|
+
firstLength = ret.length;
|
|
105
|
+
ret = ret.replace(new RegExp(stringRegex, 'gim'), '');
|
|
106
|
+
ret = ret.replace(new RegExp(singleRegex, 'gim'), '');
|
|
107
|
+
changedLength = ret.length;
|
|
108
|
+
} while (changedLength < firstLength);
|
|
109
|
+
return ret;
|
|
110
|
+
}
|
|
111
|
+
exports.replaceRemove = replaceRemove;
|
|
@@ -24,6 +24,7 @@ const colours_1 = require("../../styles/colours");
|
|
|
24
24
|
const react_1 = __importStar(require("react"));
|
|
25
25
|
const styled_components_1 = __importStar(require("styled-components"));
|
|
26
26
|
const Icon_1 = require("../Icon");
|
|
27
|
+
const dom_1 = require("../../helpers/dom");
|
|
27
28
|
const SBase = styled_components_1.default.div `
|
|
28
29
|
display: flex;
|
|
29
30
|
flex-flow: row;
|
|
@@ -42,7 +43,6 @@ const SItems = styled_components_1.default.div `
|
|
|
42
43
|
background-color: white;
|
|
43
44
|
cursor: default;
|
|
44
45
|
width: 100%;
|
|
45
|
-
right: 0;
|
|
46
46
|
max-width: 95vw;
|
|
47
47
|
${({ open }) => open &&
|
|
48
48
|
(0, styled_components_1.css) `
|
|
@@ -81,6 +81,7 @@ const SItem = styled_components_1.default.div `
|
|
|
81
81
|
}
|
|
82
82
|
`;
|
|
83
83
|
function DropdownList({ options, value, onChange, placeholder, className, renderF, children, }) {
|
|
84
|
+
var _a, _b;
|
|
84
85
|
const ref = (0, react_1.useRef)(null);
|
|
85
86
|
const [state, setState] = (0, react_1.useState)(value);
|
|
86
87
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
@@ -102,12 +103,23 @@ function DropdownList({ options, value, onChange, placeholder, className, render
|
|
|
102
103
|
setState(newv);
|
|
103
104
|
}, [options, value]);
|
|
104
105
|
const maxLen = Math.max(...options.map((s) => renderF(s).length));
|
|
106
|
+
const style = {
|
|
107
|
+
width: `calc(${maxLen}ch + 2rem)`,
|
|
108
|
+
};
|
|
109
|
+
const minLeft = (0, dom_1.convertRemToPixels)(2 + maxLen / 2);
|
|
110
|
+
const offsetList = (_b = (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetLeft) !== null && _b !== void 0 ? _b : 0;
|
|
111
|
+
if (offsetList < minLeft) {
|
|
112
|
+
style.left = 0;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
style.right = 0;
|
|
116
|
+
}
|
|
105
117
|
return (react_1.default.createElement(SBase, { className: className, ref: ref, title: placeholder, onClick: (e) => {
|
|
106
118
|
e.stopPropagation();
|
|
107
119
|
e.preventDefault();
|
|
108
120
|
setOpen(!open);
|
|
109
121
|
} },
|
|
110
|
-
react_1.default.createElement(SItems, { open: open, style:
|
|
122
|
+
react_1.default.createElement(SItems, { open: open, style: style }, open &&
|
|
111
123
|
options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: () => {
|
|
112
124
|
if (s !== state) {
|
|
113
125
|
onChange(s, i);
|
|
@@ -53,7 +53,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
53
53
|
((_e = ae.response) === null || _e === void 0 ? void 0 : _e.statusText) ||
|
|
54
54
|
((_f = ae.response) === null || _f === void 0 ? void 0 : _f.status) ||
|
|
55
55
|
'ERROR');
|
|
56
|
-
if (status === 403) {
|
|
56
|
+
if (status === 403 || status === 401) {
|
|
57
57
|
logout();
|
|
58
58
|
return {
|
|
59
59
|
error: ae,
|
|
@@ -76,10 +76,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
76
76
|
data,
|
|
77
77
|
error,
|
|
78
78
|
loading: false,
|
|
79
|
-
reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
const ret = func(cl);
|
|
81
|
-
return ret;
|
|
82
|
-
}),
|
|
79
|
+
reFetch: () => __awaiter(void 0, void 0, void 0, function* () { return func(cl); }),
|
|
83
80
|
url: func.toString(),
|
|
84
81
|
datetime: new Date().getTime(),
|
|
85
82
|
};
|
package/dist/ui/helpers/dom.d.ts
CHANGED
package/dist/ui/helpers/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.domContains = void 0;
|
|
3
|
+
exports.convertRemToPixels = exports.domContains = void 0;
|
|
4
4
|
const domContains = (e, x, y) => {
|
|
5
5
|
if (!e) {
|
|
6
6
|
return false;
|
|
@@ -8,3 +8,5 @@ const domContains = (e, x, y) => {
|
|
|
8
8
|
return e.x <= x && x <= e.x + e.width && e.y <= y && y <= e.y + e.height;
|
|
9
9
|
};
|
|
10
10
|
exports.domContains = domContains;
|
|
11
|
+
const convertRemToPixels = (rem) => rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
12
|
+
exports.convertRemToPixels = convertRemToPixels;
|