dce-reactkit 3.8.7 → 3.9.0-beta-loading-modal.1

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.
Files changed (39) hide show
  1. package/dist/cjs/index.js +254 -386
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/Modal/ModalProps.d.ts +2 -0
  4. package/dist/cjs/types/index.d.ts +1 -3
  5. package/dist/cjs/types/types/ReactKitErrorCode.d.ts +1 -4
  6. package/dist/esm/index.js +256 -386
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/types/components/Modal/ModalProps.d.ts +2 -0
  9. package/dist/esm/types/index.d.ts +1 -3
  10. package/dist/esm/types/types/ReactKitErrorCode.d.ts +1 -4
  11. package/dist/index.d.ts +46 -83
  12. package/package.json +1 -2
  13. package/src/components/Modal/ModalProps.ts +4 -0
  14. package/src/components/Modal/index.tsx +49 -21
  15. package/src/components/MultiSwitch.tsx +1 -1
  16. package/src/index.ts +0 -4
  17. package/src/types/ReactKitErrorCode.tsx +1 -6
  18. package/dist/cjs/types/components/Dropdown.d.ts +0 -32
  19. package/dist/cjs/types/helpers/validators/ChicagoTitleCase.d.ts +0 -9
  20. package/dist/cjs/types/helpers/validators/validURL.d.ts +0 -8
  21. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -22
  22. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  23. package/dist/cjs/types/types/DropdownItemType.d.ts +0 -6
  24. package/dist/esm/types/components/Dropdown.d.ts +0 -32
  25. package/dist/esm/types/helpers/validators/ChicagoTitleCase.d.ts +0 -9
  26. package/dist/esm/types/helpers/validators/validURL.d.ts +0 -8
  27. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/index.d.ts +0 -22
  28. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -33
  29. package/dist/esm/types/types/DropdownItemType.d.ts +0 -6
  30. package/src/components/Dropdown.tsx +0 -317
  31. package/src/helpers/validators/ChicagoTitleCase.test.ts +0 -85
  32. package/src/helpers/validators/ChicagoTitleCase.ts +0 -32
  33. package/src/helpers/validators/findURL.test.ts +0 -83
  34. package/src/helpers/validators/findURL.ts +0 -43
  35. package/src/helpers/validators/validURL.test.ts +0 -90
  36. package/src/helpers/validators/validURL.ts +0 -18
  37. package/src/helpers/visitEndpointOnAnotherServer/index.ts +0 -90
  38. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +0 -164
  39. package/src/types/DropdownItemType.ts +0 -11
@@ -1,83 +0,0 @@
1
- // Import the function to be tested
2
- // import findURLs from './findURL';
3
-
4
- // // Import constants
5
- // import { INVALID_STRING_ERRORS, INVALID_REGEX_ERROR } from './shared/constants/ERROR_MESSAGES';
6
-
7
- // /*------------------------------------------------------------------------*/
8
- // /* ---------------------------- Valid Tests --------------------------- */
9
- // /*------------------------------------------------------------------------*/
10
-
11
- // const validTests: { block: string, expected: { start: number, end: number }[] }[] = [
12
- // {
13
- // block: 'Visit http://example.com for more information.',
14
- // expected: [{ start: 6, end: 23 }],
15
- // },
16
- // {
17
- // block: 'Multiple URLs: http://one.com and http://two.com.',
18
- // expected: [
19
- // { start: 15, end: 29 },
20
- // { start: 34, end: 48 },
21
- // ],
22
- // },
23
- // {
24
- // block: 'Localhost URLs: http://localhost and http://127.0.0.1.',
25
- // expected: [
26
- // { start: 16, end: 31 },
27
- // { start: 36, end: 52 },
28
- // ],
29
- // },
30
- // {
31
- // block: 'Embedded URL: text https://embedded-url.com?query=1&value=2.',
32
- // expected: [{ start: 13, end: 51 }],
33
- // },
34
- // {
35
- // block: 'Secure site: https://secure-site.com/path?query=string#fragment',
36
- // expected: [{ start: 13, end: 58 }],
37
- // },
38
- // ];
39
-
40
- // test(
41
- // 'Returns correct start and end indices for valid URLs within a string.',
42
- // async () => {
43
- // validTests.forEach(({ block, expected }) => {
44
- // expect(findURLs(block)).toStrictEqual(expected);
45
- // });
46
- // },
47
- // );
48
-
49
- // /*------------------------------------------------------------------------*/
50
- // /* ---------------------------- Invalid Tests --------------------------- */
51
- // /*------------------------------------------------------------------------*/
52
-
53
- // const invalidTests: { block: string, expected: { start: number, end: number }[] }[] = [
54
- // {
55
- // block: 'No URL.',
56
- // expected: [],
57
- // },
58
- // {
59
- // block: 'URL format is wrong: http:/example.com and htt://example.com.',
60
- // expected: [],
61
- // },
62
- // {
63
- // block: 'Any punctuation after the URL http://example.com, should not count.',
64
- // expected: [{ start: 20, end: 37 }],
65
- // },
66
- // {
67
- // block: 'Starting punctuation ,http://example.com should not count.',
68
- // expected: [{ start: 22, end: 39 }],
69
- // },
70
- // {
71
- // block: 'Spaces in the middle http://exa mple.com is invalid.',
72
- // expected: [],
73
- // },
74
- // ];
75
-
76
- // test(
77
- // 'Returns empty array for strings without valid URLs.',
78
- // async () => {
79
- // invalidTests.forEach(({ block, expected }) => {
80
- // expect(findURLs(block)).toStrictEqual(expected);
81
- // });
82
- // },
83
- // );
@@ -1,43 +0,0 @@
1
- // /**
2
- // * This function finds URLs within a given string and returns an array of
3
- // * their locations.
4
- // * @author Leisha Bhandari
5
- // * @param block: The block of text to search for URLs
6
- // * @returns Arrays where each of them contain the start and end index of the URL
7
- // */
8
- // function findURLs(block: string): { start: number, end: number }[] {
9
- // // Expression representing the skeleton of a URL to help match and find the
10
- // // URLs within the block of text (Also takes care of Unicode characters)
11
- // const urlSkeleton = /(https?:\/\/[^\s\u0000-\u001F.,]+[^\s\u0000-\u001F.,]?(?:\?[^\s\u0000-\u001F]+)?(?:#[^\s\u0000-\u001F]+)?)/g;
12
- // const found: { start: number, end: number }[] = [];
13
- // let match: RegExpExecArray | null;
14
-
15
- // // While loop to find the URLs in the given block of texts using the URL
16
- // // skeleton
17
- // while ((match === urlSkeleton.exec(block))
18
- // && match !== null) {
19
- // // To find the beginning index of the URL
20
- // let start = match.index;
21
- // // To find the last index of the URL
22
- // let end = match.index + match[0].length;
23
-
24
- // // If statements to check whether the URL is followed by some kind of
25
- // // punctuation mark
26
- // if (block.charAt(end) === '.' || /[,;:!?"]/.test(block.charAt(end))) {
27
- // end--;
28
- // }
29
-
30
- // // While statement to make sure that the URL does not start with a
31
- // // punctuation mark
32
- // while (start > 0 && /[.,:;!?]/.test(block.charAt(start - 1))) {
33
- // start--;
34
- // }
35
-
36
- // // The object with start and end index of the URL is found and pushed to
37
- // // the found array
38
- // found.push({ start, end });
39
- // }
40
-
41
- // // Returns the array of the found URLs location
42
- // return found;
43
- // }
@@ -1,90 +0,0 @@
1
-
2
- // Import the function to be tested
3
- // import isValid from './validURL';
4
-
5
- // // Import constants
6
- // import { INVALID_STRING_ERRORS, INVALID_REGEX_ERROR } from './shared/constants/ERROR_MESSAGES';
7
-
8
- // /*------------------------------------------------------------------------*/
9
- // /* ---------------------------- Valid Tests --------------------------- */
10
- // /*------------------------------------------------------------------------*/
11
-
12
- // const validUrls: string[] = [
13
- // 'http://example.com',
14
- // 'https://example.com',
15
- // 'http://www.example.com',
16
- // 'https://www.example.com',
17
- // 'https://example.com/path',
18
- // 'http://example.com/path',
19
- // 'https://example.com?query=string',
20
- // 'http://example.com?query=string',
21
- // 'https://example.com#fragment',
22
- // 'http://example.com#fragment',
23
- // 'http://localhost',
24
- // 'https://localhost:3000',
25
- // 'http://localhost:3000',
26
- // 'http://127.0.0.1',
27
- // 'http://127.0.0.1:3000',
28
- // 'ftp://example.com/path',
29
- // 'ftp://example.com',
30
- // 'https://127.0.0.1:3000',
31
- // 'file:///C:/path/to/file'
32
- // ];
33
-
34
- // test(
35
- // 'Returns true for a given valid URL.',
36
- // async () => {
37
- // validUrls.forEach((url) => {
38
- // expect(isValid(url)).toBe(true);
39
- // });
40
- // },
41
- // );
42
-
43
- // /*------------------------------------------------------------------------*/
44
- // /* ---------------------------- Invalid Tests --------------------------- */
45
- // /*------------------------------------------------------------------------*/
46
-
47
- // const invalidUrls: string[] = [
48
- // '',
49
- // ' ',
50
- // 'example',
51
- // 'http://',
52
- // 'http://.',
53
- // 'http://..',
54
- // 'http://##/',
55
- // 'http://../',
56
- // 'http://??/',
57
- // 'http://#',
58
- // 'http://##',
59
- // '//',
60
- // '//a',
61
- // '///a',
62
- // '///',
63
- // 'http:///a',
64
- // 'http://www.foo.bar./',
65
- // 'http://foo.bar/foo(bar)baz quux',
66
- // 'http://3628126748',
67
- // 'http://.www.foo.bar/',
68
- // 'http://.www.foo.bar./',
69
- // 'http://123.123.123',
70
- // 'http://1.1.1.1.1',
71
- // 'http://example.com:99999',
72
- // 'http://example.com:80:80',
73
- // 'http://example.com::80',
74
- // 'http://example.com:-80',
75
- // 'http://-example.com',
76
- // 'http://example.com-',
77
- // 'http://example.com_',
78
- // 'http://example..com',
79
- // 'http://example.com.',
80
- // 'http://.example.com'
81
- // ];
82
-
83
- // test(
84
- // 'Returns false for a given invalid URL.',
85
- // async () => {
86
- // invalidUrls.forEach((url) => {
87
- // expect(isValid(url)).toBe(false);
88
- // });
89
- // },
90
- // );
@@ -1,18 +0,0 @@
1
- /**
2
- * This function checks if a given input string is a valid URL.
3
- * @author Leisha Bhandari
4
- * @param URL: The input string that needs checked as a URL or not.
5
- * @returns A true boolean value if the input string is a valid URL, and a false
6
- * boolean value if the input string is a invalid URL
7
- */
8
- function isValid(url: string): boolean {
9
- // Uses the input URL to create a URL object
10
- try {
11
- new URL(url);
12
- // URL constructor does not throw an error, so input URL is valid
13
- return true;
14
- } catch (err) {
15
- // URL constructor throws an error, so input URL is invalid
16
- return false;
17
- }
18
- }
@@ -1,90 +0,0 @@
1
- // Import custom error
2
- import ErrorWithCode from '../../errors/ErrorWithCode';
3
-
4
- // Import shared types
5
- import ReactKitErrorCode from '../../types/ReactKitErrorCode';
6
-
7
- // Import other helpers
8
- import sendServerToServerRequest from './sendServerToServerRequest';
9
-
10
- /**
11
- * Send a server-to-server request from this sever to another server that uses
12
- * dce-reactkit [for server only]
13
- * @author Gabe Abrams
14
- * @param opts object containing all arguments
15
- * @param opts.path - the path of the other server's endpoint
16
- * @param [opts.method=GET] - the method of the endpoint
17
- * @param [opts.params] - query/body parameters to include
18
- * @param [opts.headers] - headers to include
19
- * @returns response from server
20
- */
21
- const visitEndpointOnAnotherServer = async (
22
- opts: {
23
- path: string,
24
- method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
25
- params?: { [key in string]: any },
26
- headers?: { [k in string]: any },
27
- },
28
- ): Promise<any> => {
29
- // Remove properties with undefined values
30
- let params: { [key in string]: any } | undefined;
31
- if (opts.params) {
32
- params = Object.fromEntries(
33
- Object
34
- .entries(opts.params)
35
- .filter(([, value]) => {
36
- return value !== undefined;
37
- }),
38
- );
39
- }
40
-
41
- // Automatically JSONify arrays and objects
42
- if (params) {
43
- params = Object.fromEntries(
44
- Object
45
- .entries(params)
46
- .map(([key, value]) => {
47
- if (Array.isArray(value) || typeof value === 'object') {
48
- return [key, JSON.stringify(value)];
49
- }
50
- return [key, value];
51
- }),
52
- );
53
- }
54
-
55
- // Send the request
56
- const response = await sendServerToServerRequest({
57
- path: opts.path,
58
- method: opts.method ?? 'GET',
59
- params,
60
- });
61
-
62
- // Check for failure
63
- if (!response || !response.body) {
64
- throw new ErrorWithCode(
65
- 'We didn\'t get a response from the server. Please check your internet connection.',
66
- ReactKitErrorCode.NoResponse,
67
- );
68
- }
69
- if (!response.body.success) {
70
- // Other errors
71
- throw new ErrorWithCode(
72
- (
73
- response.body.message
74
- || 'An unknown error occurred. Please contact an admin.'
75
- ),
76
- (
77
- response.body.code
78
- || ReactKitErrorCode.NoCode
79
- ),
80
- );
81
- }
82
-
83
- // Success! Extract the body
84
- const { body } = response.body;
85
-
86
- // Return
87
- return body;
88
- };
89
-
90
- export default visitEndpointOnAnotherServer;
@@ -1,164 +0,0 @@
1
- // Import libs
2
- import qs from 'qs';
3
-
4
- // Import shared types
5
- import ReactKitErrorCode from '../../types/ReactKitErrorCode';
6
-
7
- // Import custom error
8
- import ErrorWithCode from '../../errors/ErrorWithCode';
9
-
10
- /**
11
- * Sends and retries an http request
12
- * @author Gabriel Abrams
13
- * @param opts object containing all arguments
14
- * @param opts.path path to send request to
15
- * @param [opts.host] host to send request to
16
- * @param [opts.method=GET] http method to use
17
- * @param [opts.params] body/data to include in the request
18
- * @param [opts.headers] headers to include in the request
19
- * @param [opts.sendCrossDomainCredentials=true if in development mode] if true,
20
- * send cross-domain credentials even if not in dev mode
21
- * @param [opts.responseType=JSON] expected response type
22
- * @returns { body, status, headers } on success
23
- */
24
- const sendServerToServerRequest = async (
25
- opts: {
26
- path: string,
27
- host?: string,
28
- method?: ('GET' | 'POST' | 'PUT' | 'DELETE'),
29
- params?: { [k in string]: any },
30
- headers?: { [k in string]: any },
31
- responseType?: 'Text' | 'JSON',
32
- },
33
- ): Promise<{
34
- body: any,
35
- status: number,
36
- headers: { [k in string]: any },
37
- }> => {
38
- // Process method
39
- const method: ('GET' | 'POST' | 'PUT' | 'DELETE') = (opts.method || 'GET');
40
-
41
- // Encode objects within params
42
- let params: {
43
- [k in string]: any
44
- } | undefined;
45
- if (opts.params) {
46
- params = {};
47
- Object.entries(opts.params).forEach(([key, val]) => {
48
- if (typeof val === 'object' && !Array.isArray(val)) {
49
- (params as any)[key] = JSON.stringify(val);
50
- } else {
51
- (params as any)[key] = val;
52
- }
53
- });
54
- }
55
-
56
- // Stringify parameters
57
- const stringifiedParams = qs.stringify(params || {}, {
58
- encodeValuesOnly: true,
59
- arrayFormat: 'brackets',
60
- });
61
-
62
- // Create url (include query if GET)
63
- const query = (method === 'GET' ? `?${stringifiedParams}` : '');
64
- let url;
65
- if (!opts.host) {
66
- // No host included at all. Just send to a path
67
- url = `${opts.path}${query}`;
68
- } else {
69
- url = `https://${opts.host}${opts.path}${query}`;
70
- }
71
-
72
- // Update headers
73
- const headers = opts.headers || {};
74
- let data: string | null | { [k: string]: any } | undefined = null;
75
- if (!headers['Content-Type']) {
76
- // Form encoded
77
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
78
- // Add data if applicable
79
- data = (method !== 'GET' ? stringifiedParams : null);
80
- } else {
81
- // JSON encode
82
- data = params;
83
- }
84
-
85
- // Encode data
86
- let encodedData: URLSearchParams | string | undefined;
87
- if (data) {
88
- if (headers['Content-Type'] === 'application/x-www-form-urlencoded') {
89
- encodedData = new URLSearchParams(params);
90
- } else {
91
- encodedData = JSON.stringify(data);
92
- }
93
- }
94
-
95
- // Send request
96
- try {
97
- const response = await fetch(
98
- url,
99
- {
100
- method,
101
- mode: 'cors',
102
- headers: headers ?? {},
103
- body: (
104
- (method !== 'GET' && encodedData)
105
- ? encodedData
106
- : undefined
107
- ),
108
- redirect: 'follow',
109
- },
110
- );
111
-
112
- // Get headers map
113
- const responseHeaders: {
114
- [k in string]: string
115
- } = {};
116
- response.headers.forEach((value, key) => {
117
- responseHeaders[key] = value;
118
- });
119
-
120
- // Process response based on responseType
121
- try {
122
- // Parse response
123
- let responseBody: any;
124
- if (
125
- opts.responseType
126
- && opts.responseType === 'Text'
127
- ) {
128
- // Response type is text
129
- responseBody = await response.text();
130
- } else {
131
- // Response type is JSON
132
- responseBody = await response.json();
133
- }
134
-
135
- // Return response
136
- return {
137
- body: responseBody,
138
- status: response.status,
139
- headers: responseHeaders,
140
- };
141
- } catch (err) {
142
- throw new ErrorWithCode(
143
- `Failed to parse response as ${opts.responseType}: ${(err as any)?.message}`,
144
- ReactKitErrorCode.ResponseParseError,
145
- );
146
- }
147
- } catch (err) {
148
- // Self-signed certificate error:
149
- if ((err as any)?.message?.includes('self signed certificate')) {
150
- throw new ErrorWithCode(
151
- 'We refused to send a request because the receiver has self-signed certificates.',
152
- ReactKitErrorCode.SelfSigned,
153
- );
154
- }
155
-
156
- // No tries left
157
- throw new ErrorWithCode(
158
- `We encountered an error when trying to send a network request. If this issue persists, contact an admin. Error: ${(err as any)?.message}`,
159
- ReactKitErrorCode.NotConnected,
160
- );
161
- }
162
- };
163
-
164
- export default sendServerToServerRequest;
@@ -1,11 +0,0 @@
1
- // Types of dropdown items
2
- enum DropdownItemType {
3
- // Dropdown header
4
- Header = 'Header',
5
- // Dropdown divider
6
- Divider = 'Divider',
7
- // Dropdown item
8
- Item = 'Item',
9
- }
10
-
11
- export default DropdownItemType;