@lifesg/web-frontend-engine 1.0.0-alpha.4 → 1.0.0-alpha.6

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 (88) hide show
  1. package/README.md +2 -1
  2. package/chunks/heic2any.22ec65b5.js +2 -0
  3. package/chunks/heic2any.22ec65b5.js.map +1 -0
  4. package/chunks/index.391c739c.js +2 -0
  5. package/chunks/index.391c739c.js.map +1 -0
  6. package/chunks/index.5f3e1c55.js +10 -0
  7. package/chunks/index.5f3e1c55.js.map +1 -0
  8. package/chunks/index.e4d9a916.js +815 -0
  9. package/chunks/index.e4d9a916.js.map +1 -0
  10. package/cjs/chunks/heic2any.cdea5d8b.js +2 -0
  11. package/cjs/chunks/heic2any.cdea5d8b.js.map +1 -0
  12. package/cjs/chunks/index.3812af57.js +10 -0
  13. package/cjs/chunks/index.3812af57.js.map +1 -0
  14. package/cjs/chunks/index.b78c824f.js +2 -0
  15. package/cjs/chunks/index.b78c824f.js.map +1 -0
  16. package/cjs/chunks/index.eba4a3bb.js +815 -0
  17. package/cjs/chunks/index.eba4a3bb.js.map +1 -0
  18. package/cjs/index.js +1 -285
  19. package/cjs/index.js.map +1 -1
  20. package/components/fields/checkbox-group/checkbox-group.styles.d.ts +1 -1
  21. package/components/fields/image-upload/image-context/image-context.d.ts +14 -0
  22. package/components/fields/image-upload/image-context/index.d.ts +1 -0
  23. package/components/fields/image-upload/image-input/file-item/file-item.d.ts +11 -0
  24. package/components/fields/image-upload/image-input/file-item/file-item.styles.d.ts +16 -0
  25. package/components/fields/image-upload/image-input/file-item/index.d.ts +1 -0
  26. package/components/fields/image-upload/image-input/image-input.d.ts +17 -0
  27. package/components/fields/image-upload/image-input/image-input.styles.d.ts +8 -0
  28. package/components/fields/image-upload/image-input/index.d.ts +1 -0
  29. package/components/fields/image-upload/image-manager/image-manager.d.ts +22 -0
  30. package/components/fields/image-upload/image-manager/index.d.ts +2 -0
  31. package/components/fields/image-upload/image-review/image-editor/image-editor.d.ts +3 -0
  32. package/components/fields/image-upload/image-review/image-editor/image-editor.styles.d.ts +4 -0
  33. package/components/fields/image-upload/image-review/image-editor/index.d.ts +3 -0
  34. package/components/fields/image-upload/image-review/image-editor/types.d.ts +16 -0
  35. package/components/fields/image-upload/image-review/image-error/image-error.d.ts +8 -0
  36. package/components/fields/image-upload/image-review/image-error/image-error.styles.d.ts +7 -0
  37. package/components/fields/image-upload/image-review/image-error/index.d.ts +1 -0
  38. package/components/fields/image-upload/image-review/image-prompts/image-prompts.d.ts +11 -0
  39. package/components/fields/image-upload/image-review/image-prompts/index.d.ts +1 -0
  40. package/components/fields/image-upload/image-review/image-review.d.ts +15 -0
  41. package/components/fields/image-upload/image-review/image-review.styles.d.ts +31 -0
  42. package/components/fields/image-upload/image-review/image-thumbnails/image-thumbnails.d.ts +11 -0
  43. package/components/fields/image-upload/image-review/image-thumbnails/image-thumbnails.styles.d.ts +14 -0
  44. package/components/fields/image-upload/image-review/image-thumbnails/index.d.ts +1 -0
  45. package/components/fields/image-upload/image-review/index.d.ts +1 -0
  46. package/components/fields/image-upload/image-upload-helper.d.ts +10 -0
  47. package/components/fields/image-upload/image-upload.d.ts +4 -0
  48. package/components/fields/image-upload/index.d.ts +2 -0
  49. package/components/fields/image-upload/types.d.ts +65 -0
  50. package/components/fields/index.d.ts +4 -1
  51. package/components/fields/radio-button/radio-button.styles.d.ts +4 -3
  52. package/components/fields/radio-button/types.d.ts +5 -2
  53. package/components/fields/range-select/index.d.ts +2 -0
  54. package/components/fields/range-select/range-select.d.ts +3 -0
  55. package/components/fields/range-select/types.d.ts +8 -0
  56. package/components/fields/reset-button/types.d.ts +1 -0
  57. package/components/fields/switch/index.d.ts +2 -0
  58. package/components/fields/switch/switch.d.ts +3 -0
  59. package/components/fields/switch/switch.styles.d.ts +1 -0
  60. package/components/fields/switch/types.d.ts +9 -0
  61. package/components/fields/text-field/types.d.ts +8 -0
  62. package/components/fields/textarea/textarea.styles.d.ts +1 -1
  63. package/components/frontend-engine/event/context-provider.d.ts +14 -0
  64. package/components/frontend-engine/event/index.d.ts +1 -0
  65. package/components/frontend-engine/types.d.ts +27 -19
  66. package/components/frontend-engine/yup/types.d.ts +2 -1
  67. package/components/shared/drag-upload/drag-upload.d.ts +3 -0
  68. package/components/shared/drag-upload/drag-upload.styles.d.ts +4 -0
  69. package/components/shared/drag-upload/index.d.ts +2 -0
  70. package/components/shared/drag-upload/types.d.ts +15 -0
  71. package/components/shared/error-messages.d.ts +28 -4
  72. package/components/shared/index.d.ts +2 -0
  73. package/components/shared/prompt/index.d.ts +2 -0
  74. package/components/shared/prompt/prompt.d.ts +2 -0
  75. package/components/shared/prompt/prompt.styles.d.ts +13 -0
  76. package/components/shared/prompt/types.d.ts +16 -0
  77. package/index.js +1 -285
  78. package/index.js.map +1 -1
  79. package/package.json +8 -2
  80. package/utils/api-client/api-client.d.ts +65 -0
  81. package/utils/api-client/index.d.ts +1 -0
  82. package/utils/file-helper.d.ts +39 -0
  83. package/utils/hooks/index.d.ts +1 -0
  84. package/utils/hooks/use-field-event.d.ts +9 -0
  85. package/utils/hooks/use-previous.d.ts +4 -1
  86. package/utils/image-helper.d.ts +34 -0
  87. package/utils/index.d.ts +4 -0
  88. 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.4",
3
+ "version": "1.0.0-alpha.6",
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": "^1.0.2",
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,39 @@
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
+ * converts file/blob to dataURL
8
+ */
9
+ const fileToDataUrl: (file: File | Blob) => Promise<string>;
10
+ /**
11
+ * converts dataURL to blob
12
+ */
13
+ const dataUrlToBlob: (dataUrl: string) => Promise<Blob>;
14
+ /**
15
+ * estimate filesize from base64 string
16
+ * https://stackoverflow.com/questions/53228948/how-to-get-image-file-size-from-base-64-string-in-javascript#answer-53229045
17
+ */
18
+ const getFilesizeFromBase64: (base64: string) => number;
19
+ /**
20
+ * convert array of file extensions to a proper sentence
21
+ * convert to uppercase
22
+ * joins array with comma
23
+ * add `or` before last extension
24
+ * lists both .JPG and .JPEG
25
+ */
26
+ const extensionsToSentence: (list: string[]) => string;
27
+ /**
28
+ * converts file extension to mime type
29
+ */
30
+ const fileExtensionToMimeType: (ext: string) => string | undefined;
31
+ /**
32
+ * reliably derive mime type by checking magic number of the buffer
33
+ */
34
+ const getMimeType: (blob: Blob | File) => Promise<import("file-type/core").MimeType>;
35
+ /**
36
+ * ensure file name is unique against a list of file names
37
+ */
38
+ const deduplicateFileName: (fileNameList: string[], index: number, fileName: string, originalFilename?: string, counter?: number) => string;
39
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./use-field-event";
1
2
  export * from "./use-previous";
2
3
  export * from "./use-validation-config";
3
4
  export * from "./use-validation-schema";
@@ -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
+ };
@@ -1 +1,4 @@
1
- export declare const usePrevious: (value: any) => undefined;
1
+ /**
2
+ * tracks the previous value
3
+ */
4
+ export declare const usePrevious: <T = unknown>(value: T) => T;
@@ -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
@@ -1,3 +1,7 @@
1
+ export * from "./api-client";
1
2
  export * from "./date-time-helper";
3
+ export * from "./file-helper";
4
+ export * from "./image-helper";
2
5
  export * from "./object-helper";
3
6
  export * from "./test-helper";
7
+ export * from "./window-helper";
@@ -0,0 +1,3 @@
1
+ export declare namespace WindowHelper {
2
+ const isMobileView: () => boolean;
3
+ }