@lifesg/web-frontend-engine 1.0.0-alpha.3 → 1.0.0-alpha.5
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/README.md +2 -1
- package/chunks/heic2any.3b8e0e2e.js +2 -0
- package/chunks/heic2any.3b8e0e2e.js.map +1 -0
- package/chunks/index.a9be1bad.js +2 -0
- package/chunks/index.a9be1bad.js.map +1 -0
- package/chunks/index.cb84bb25.js +813 -0
- package/chunks/index.cb84bb25.js.map +1 -0
- package/chunks/index.f3b64f06.js +10 -0
- package/chunks/index.f3b64f06.js.map +1 -0
- package/cjs/chunks/heic2any.8d6aeb48.js +2 -0
- package/cjs/chunks/heic2any.8d6aeb48.js.map +1 -0
- package/cjs/chunks/index.3a31dd0d.js +813 -0
- package/cjs/chunks/index.3a31dd0d.js.map +1 -0
- package/cjs/chunks/index.42475725.js +2 -0
- package/cjs/chunks/index.42475725.js.map +1 -0
- package/cjs/chunks/index.4da6edf0.js +10 -0
- package/cjs/chunks/index.4da6edf0.js.map +1 -0
- package/cjs/index.js +1 -281
- package/cjs/index.js.map +1 -1
- package/components/custom/filter/filter/filter.d.ts +2 -0
- package/components/custom/filter/filter/types.d.ts +14 -0
- package/components/custom/filter/filter-checkbox/filter-checkbox.d.ts +3 -0
- package/components/custom/filter/filter-checkbox/types.d.ts +12 -0
- package/components/custom/filter/filter-item/filter-item.d.ts +3 -0
- package/components/custom/filter/filter-item/types.d.ts +8 -0
- package/components/custom/filter/index.d.ts +3 -0
- package/components/custom/index.d.ts +1 -0
- package/components/elements/alert/alert.d.ts +1 -2
- package/components/elements/section/section.d.ts +1 -2
- package/components/elements/sections/sections.d.ts +1 -2
- package/components/elements/text/data.d.ts +12 -12
- package/components/elements/text/text.d.ts +1 -2
- package/components/elements/wrapper/conditional-renderer.d.ts +4 -2
- package/components/elements/wrapper/types.d.ts +3 -1
- package/components/fields/checkbox-group/checkbox-group.d.ts +1 -2
- package/components/fields/checkbox-group/checkbox-group.styles.d.ts +3 -2
- package/components/fields/checkbox-group/types.d.ts +13 -1
- package/components/fields/chips/chips.d.ts +1 -2
- package/components/fields/chips/types.d.ts +1 -0
- package/components/fields/contact-field/contact-field.d.ts +1 -2
- package/components/fields/contact-field/data.d.ts +4 -214
- package/components/fields/contact-field/types.d.ts +8 -7
- package/components/fields/date-field/date-field.d.ts +1 -2
- package/components/fields/image-upload/image-context/image-context.d.ts +14 -0
- package/components/fields/image-upload/image-context/index.d.ts +1 -0
- package/components/fields/image-upload/image-input/file-item/file-item.d.ts +11 -0
- package/components/fields/image-upload/image-input/file-item/file-item.styles.d.ts +16 -0
- package/components/fields/image-upload/image-input/file-item/index.d.ts +1 -0
- package/components/fields/image-upload/image-input/image-input.d.ts +17 -0
- package/components/fields/image-upload/image-input/image-input.styles.d.ts +8 -0
- package/components/fields/image-upload/image-input/index.d.ts +1 -0
- package/components/fields/image-upload/image-manager/image-manager.d.ts +22 -0
- package/components/fields/image-upload/image-manager/index.d.ts +2 -0
- package/components/fields/image-upload/image-review/image-editor/image-editor.d.ts +3 -0
- package/components/fields/image-upload/image-review/image-editor/image-editor.styles.d.ts +4 -0
- package/components/fields/image-upload/image-review/image-editor/index.d.ts +3 -0
- package/components/fields/image-upload/image-review/image-editor/types.d.ts +16 -0
- package/components/fields/image-upload/image-review/image-error/image-error.d.ts +8 -0
- package/components/fields/image-upload/image-review/image-error/image-error.styles.d.ts +7 -0
- package/components/fields/image-upload/image-review/image-error/index.d.ts +1 -0
- package/components/fields/image-upload/image-review/image-prompts/image-prompts.d.ts +11 -0
- package/components/fields/image-upload/image-review/image-prompts/index.d.ts +1 -0
- package/components/fields/image-upload/image-review/image-review.d.ts +15 -0
- package/components/fields/image-upload/image-review/image-review.styles.d.ts +31 -0
- package/components/fields/image-upload/image-review/image-thumbnails/image-thumbnails.d.ts +11 -0
- package/components/fields/image-upload/image-review/image-thumbnails/image-thumbnails.styles.d.ts +14 -0
- package/components/fields/image-upload/image-review/image-thumbnails/index.d.ts +1 -0
- package/components/fields/image-upload/image-review/index.d.ts +1 -0
- package/components/fields/image-upload/image-upload-helper.d.ts +10 -0
- package/components/fields/image-upload/image-upload.d.ts +4 -0
- package/components/fields/image-upload/index.d.ts +2 -0
- package/components/fields/image-upload/types.d.ts +65 -0
- package/components/fields/index.d.ts +3 -0
- package/components/fields/multi-select/multi-select.d.ts +1 -2
- package/components/fields/radio-button/radio-button.d.ts +1 -2
- package/components/fields/radio-button/radio-button.styles.d.ts +4 -2
- package/components/fields/radio-button/types.d.ts +12 -0
- package/components/fields/reset-button/index.d.ts +2 -0
- package/components/fields/reset-button/reset-button.d.ts +3 -0
- package/components/fields/reset-button/types.d.ts +6 -0
- package/components/fields/select/select.d.ts +1 -2
- package/components/fields/submit-button/submit-button.d.ts +1 -2
- package/components/fields/text-field/text-field.d.ts +1 -2
- package/components/fields/text-field/types.d.ts +8 -0
- package/components/fields/textarea/textarea.d.ts +1 -2
- package/components/fields/textarea/textarea.styles.d.ts +1 -1
- package/components/fields/time-field/time-field.d.ts +1 -2
- package/components/fields/unit-number-field/index.d.ts +2 -0
- package/components/fields/unit-number-field/types.d.ts +7 -0
- package/components/fields/unit-number-field/unit-number-field.d.ts +3 -0
- package/components/frontend-engine/event/context-provider.d.ts +14 -0
- package/components/frontend-engine/event/index.d.ts +1 -0
- package/components/frontend-engine/types.d.ts +46 -20
- package/components/frontend-engine/yup/context-provider.d.ts +1 -1
- package/components/frontend-engine/yup/types.d.ts +2 -1
- package/components/shared/chip/chip.d.ts +1 -1
- package/components/shared/drag-upload/drag-upload.d.ts +3 -0
- package/components/shared/drag-upload/drag-upload.styles.d.ts +4 -0
- package/components/shared/drag-upload/index.d.ts +2 -0
- package/components/shared/drag-upload/types.d.ts +15 -0
- package/components/shared/error-messages.d.ts +29 -3
- package/components/shared/index.d.ts +2 -0
- package/components/shared/prompt/index.d.ts +2 -0
- package/components/shared/prompt/prompt.d.ts +2 -0
- package/components/shared/prompt/prompt.styles.d.ts +15 -0
- package/components/shared/prompt/types.d.ts +16 -0
- package/components/shared/sanitize/sanitize.d.ts +1 -1
- package/index.js +1 -281
- package/index.js.map +1 -1
- package/package.json +8 -2
- package/utils/api-client/api-client.d.ts +65 -0
- package/utils/api-client/index.d.ts +1 -0
- package/utils/file-helper.d.ts +43 -0
- package/utils/hooks/index.d.ts +1 -0
- package/utils/hooks/use-field-event.d.ts +9 -0
- package/utils/hooks/use-previous.d.ts +4 -1
- package/utils/image-helper.d.ts +34 -0
- package/utils/index.d.ts +4 -0
- package/utils/window-helper.d.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifesg/web-frontend-engine",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "A frontend engine for LifeSG React apps",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -23,16 +23,22 @@
|
|
|
23
23
|
"@js-joda/core": "^5.4.2",
|
|
24
24
|
"@js-joda/locale_en-us": "^4.8.6",
|
|
25
25
|
"@js-joda/timezone": "^2.15.0",
|
|
26
|
+
"axios": "^1.2.2",
|
|
26
27
|
"country-code-lookup": "^0.0.20",
|
|
28
|
+
"fabric": "^5.2.4",
|
|
29
|
+
"file-type": "^16.5.4",
|
|
30
|
+
"heic2any": "^0.0.3",
|
|
27
31
|
"libphonenumber-js": "^1.10.14",
|
|
28
32
|
"lodash": "^4.17.21",
|
|
33
|
+
"react-dropzone": "^14.2.3",
|
|
29
34
|
"react-hook-form": "^7.34.2",
|
|
30
35
|
"sanitize-html": "^2.8.1",
|
|
31
36
|
"use-deep-compare-effect": "^1.8.1",
|
|
32
37
|
"yup": "^0.32.11"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
35
|
-
"@lifesg/react-design-system": "
|
|
40
|
+
"@lifesg/react-design-system": "v1.1.0-canary.1",
|
|
41
|
+
"@lifesg/react-icons": "^1.2.0",
|
|
36
42
|
"react": "^17.0.2 || ^18.0.0",
|
|
37
43
|
"react-dom": "^17.0.2 || ^18.0.0",
|
|
38
44
|
"styled-components": "^5.3.5"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
export declare class AxiosApiClient {
|
|
3
|
+
private _client;
|
|
4
|
+
constructor(
|
|
5
|
+
/** the base url of the api. We suggest each api to have it's own client */
|
|
6
|
+
baseURL: string,
|
|
7
|
+
/** the api timeout duration. Default 15000ms */
|
|
8
|
+
timeout?: number,
|
|
9
|
+
/**
|
|
10
|
+
* Default:
|
|
11
|
+
* "Content-Type": "application/json",
|
|
12
|
+
* "Accept": "application/json",
|
|
13
|
+
*/
|
|
14
|
+
headers?: {
|
|
15
|
+
"Content-Type": string;
|
|
16
|
+
Accept: string;
|
|
17
|
+
},
|
|
18
|
+
/** Specify if cross-site Access-Control requests should be
|
|
19
|
+
* made using credentials such as cookies, authorization headers
|
|
20
|
+
* or TLS client certificates
|
|
21
|
+
*/
|
|
22
|
+
withCredentials?: boolean, config?: AxiosRequestConfig);
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param path the path of the endpoint
|
|
26
|
+
* @param config AxiosRequestConfig. For simple usage with params, just wrap it in an object (e.g. { params })
|
|
27
|
+
*/
|
|
28
|
+
get<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets response along with the full schema
|
|
31
|
+
* @param path the path of the endpoint
|
|
32
|
+
* @param config AxiosRequestConfig. For simple usage with params, just wrap it in an object (e.g. { params })
|
|
33
|
+
*/
|
|
34
|
+
getFull<T>(path: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param path the path of the endpoint
|
|
38
|
+
* @param payload the data of the POST request
|
|
39
|
+
* @param config AxiosRequestConfig
|
|
40
|
+
*/
|
|
41
|
+
post<T>(path: string, payload?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param path the path of the endpoint
|
|
45
|
+
* @param payload the data of the PUT request
|
|
46
|
+
* @param config AxiosRequestConfig
|
|
47
|
+
*/
|
|
48
|
+
put<T>(path: string, payload?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param path the path of the endpoint
|
|
52
|
+
* @param payload the data of the PATCH request
|
|
53
|
+
* @param config AxiosRequestConfig
|
|
54
|
+
*/
|
|
55
|
+
patch<T>(path: string, payload?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param path the path of the endpoint
|
|
59
|
+
* @param config AxiosRequestConfig
|
|
60
|
+
*/
|
|
61
|
+
delete<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
|
|
62
|
+
getClient(): AxiosInstance;
|
|
63
|
+
private _handleSuccess;
|
|
64
|
+
private _handleError;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api-client";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare namespace FileHelper {
|
|
2
|
+
/**
|
|
3
|
+
* truncate file name according to wrapping element width
|
|
4
|
+
*/
|
|
5
|
+
const truncateFileName: (fileName: string, widthOfElement: number) => string;
|
|
6
|
+
/**
|
|
7
|
+
* formats bytes to bigger units
|
|
8
|
+
*/
|
|
9
|
+
const bytesToSize: (bytes: number) => string;
|
|
10
|
+
/**
|
|
11
|
+
* converts file/blob to dataURL
|
|
12
|
+
*/
|
|
13
|
+
const fileToDataUrl: (file: File | Blob) => Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* converts dataURL to blob
|
|
16
|
+
*/
|
|
17
|
+
const dataUrlToBlob: (dataUrl: string) => Promise<Blob>;
|
|
18
|
+
/**
|
|
19
|
+
* estimate filesize from base64 string
|
|
20
|
+
* https://stackoverflow.com/questions/53228948/how-to-get-image-file-size-from-base-64-string-in-javascript#answer-53229045
|
|
21
|
+
*/
|
|
22
|
+
const getFilesizeFromBase64: (base64: string) => number;
|
|
23
|
+
/**
|
|
24
|
+
* convert array of file extensions to a proper sentence
|
|
25
|
+
* convert to uppercase
|
|
26
|
+
* joins array with comma
|
|
27
|
+
* add `or` before last extension
|
|
28
|
+
* lists both .JPG and .JPEG
|
|
29
|
+
*/
|
|
30
|
+
const extensionsToSentence: (list: string[]) => string;
|
|
31
|
+
/**
|
|
32
|
+
* converts file extension to mime type
|
|
33
|
+
*/
|
|
34
|
+
const fileExtensionToMimeType: (ext: string) => string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* reliably derive mime type by checking magic number of the buffer
|
|
37
|
+
*/
|
|
38
|
+
const getMimeType: (blob: Blob | File) => Promise<import("file-type/core").MimeType>;
|
|
39
|
+
/**
|
|
40
|
+
* ensure file name is unique against a list of file names
|
|
41
|
+
*/
|
|
42
|
+
const deduplicateFileName: (fileNameList: string[], index: number, fileName: string, originalFilename?: string, counter?: number) => string;
|
|
43
|
+
}
|
package/utils/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook that interacts with the event context provider
|
|
3
|
+
* use this hook to add/dispatch/remove event listeners
|
|
4
|
+
*/
|
|
5
|
+
export declare const useFieldEvent: () => {
|
|
6
|
+
addFieldEventListener: (type: string, id: string, listener: (ev: Event) => unknown, options?: boolean | AddEventListenerOptions) => void;
|
|
7
|
+
dispatchFieldEvent: (type: string, id: string, detail?: any) => boolean;
|
|
8
|
+
removeFieldEventListener: (type: string, id: string, listener: (ev: Event) => unknown, options?: boolean | EventListenerOptions) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare namespace ImageHelper {
|
|
2
|
+
/**
|
|
3
|
+
* convert image type
|
|
4
|
+
*/
|
|
5
|
+
const convertBlob: (blob: File | Blob, outputMimeType?: string) => Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* converts dataURL to HTMLImageElement
|
|
8
|
+
*/
|
|
9
|
+
const dataUrlToImage: (dataURL: string) => Promise<HTMLImageElement>;
|
|
10
|
+
/**
|
|
11
|
+
* converts blob to HTMLImageElement
|
|
12
|
+
*/
|
|
13
|
+
const blobToImage: (blob: Blob) => Promise<HTMLImageElement>;
|
|
14
|
+
/**
|
|
15
|
+
* resamples image by rendering it on canvas
|
|
16
|
+
*/
|
|
17
|
+
const resampleImage: (image: HTMLImageElement, options: {
|
|
18
|
+
scale: number;
|
|
19
|
+
quality?: number;
|
|
20
|
+
type?: string;
|
|
21
|
+
}) => Promise<Blob>;
|
|
22
|
+
/**
|
|
23
|
+
* rescursively attempt to compress image till the desired filesize
|
|
24
|
+
*
|
|
25
|
+
* fileSize is in kb
|
|
26
|
+
* optional `maxAttempts` to limit the attempts, if file size still exceeds at the end of it, return the best compressed image
|
|
27
|
+
*/
|
|
28
|
+
const compressImage: (file: File | Blob, options: {
|
|
29
|
+
quality?: number;
|
|
30
|
+
fileSize: number;
|
|
31
|
+
attempts?: number;
|
|
32
|
+
maxAttempts?: number;
|
|
33
|
+
}) => any;
|
|
34
|
+
}
|
package/utils/index.d.ts
CHANGED