@darajs/ui-utils 1.0.0-a.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 (58) hide show
  1. package/LICENSE +201 -0
  2. package/dist/clipboard-utils.d.ts +26 -0
  3. package/dist/clipboard-utils.d.ts.map +1 -0
  4. package/dist/clipboard-utils.js +67 -0
  5. package/dist/clipboard-utils.js.map +1 -0
  6. package/dist/constants.d.ts +35 -0
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/constants.js +37 -0
  9. package/dist/constants.js.map +1 -0
  10. package/dist/get-status-color.d.ts +32 -0
  11. package/dist/get-status-color.d.ts.map +1 -0
  12. package/dist/get-status-color.js +34 -0
  13. package/dist/get-status-color.js.map +1 -0
  14. package/dist/index.d.ts +30 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +30 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/path-utils.d.ts +23 -0
  19. package/dist/path-utils.d.ts.map +1 -0
  20. package/dist/path-utils.js +29 -0
  21. package/dist/path-utils.js.map +1 -0
  22. package/dist/request-utils.d.ts +83 -0
  23. package/dist/request-utils.d.ts.map +1 -0
  24. package/dist/request-utils.js +161 -0
  25. package/dist/request-utils.js.map +1 -0
  26. package/dist/rx-utils.d.ts +9 -0
  27. package/dist/rx-utils.d.ts.map +1 -0
  28. package/dist/rx-utils.js +33 -0
  29. package/dist/rx-utils.js.map +1 -0
  30. package/dist/use-d3-axis.d.ts +45 -0
  31. package/dist/use-d3-axis.d.ts.map +1 -0
  32. package/dist/use-d3-axis.js +84 -0
  33. package/dist/use-d3-axis.js.map +1 -0
  34. package/dist/use-deep-compare.d.ts +13 -0
  35. package/dist/use-deep-compare.d.ts.map +1 -0
  36. package/dist/use-deep-compare.js +37 -0
  37. package/dist/use-deep-compare.js.map +1 -0
  38. package/dist/use-dimensions.d.ts +22 -0
  39. package/dist/use-dimensions.d.ts.map +1 -0
  40. package/dist/use-dimensions.js +47 -0
  41. package/dist/use-dimensions.js.map +1 -0
  42. package/dist/use-intersection-observer.d.ts +30 -0
  43. package/dist/use-intersection-observer.d.ts.map +1 -0
  44. package/dist/use-intersection-observer.js +48 -0
  45. package/dist/use-intersection-observer.js.map +1 -0
  46. package/dist/use-on-click-outside.d.ts +9 -0
  47. package/dist/use-on-click-outside.d.ts.map +1 -0
  48. package/dist/use-on-click-outside.js +42 -0
  49. package/dist/use-on-click-outside.js.map +1 -0
  50. package/dist/use-throttle.d.ts +25 -0
  51. package/dist/use-throttle.d.ts.map +1 -0
  52. package/dist/use-throttle.js +48 -0
  53. package/dist/use-throttle.js.map +1 -0
  54. package/dist/use-update-effect.d.ts +26 -0
  55. package/dist/use-update-effect.d.ts.map +1 -0
  56. package/dist/use-update-effect.js +35 -0
  57. package/dist/use-update-effect.js.map +1 -0
  58. package/package.json +54 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Copyright 2023 Impulse Innovations Limited
3
+ *
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { BehaviorSubject } from 'rxjs';
18
+ export interface SortingRule {
19
+ desc?: boolean;
20
+ id: string;
21
+ }
22
+ export interface FilterRule {
23
+ id: string;
24
+ value: string | Array<string>;
25
+ }
26
+ /** Standard interface for any additional request options that are required */
27
+ export interface RequestOptions {
28
+ filter?: Array<FilterRule>;
29
+ limit?: number;
30
+ searchTerm?: string;
31
+ sort?: Array<SortingRule>;
32
+ startIndex?: number;
33
+ }
34
+ /** Error class for request errors that allow them to be caught more easily */
35
+ export declare class RequestError extends Error {
36
+ requestParams: {
37
+ [k: string]: any;
38
+ };
39
+ status: number;
40
+ constructor(status: number, message: string, requestParams?: {
41
+ [k: string]: any;
42
+ });
43
+ }
44
+ /**
45
+ * Request helper for converting an options object into a valid query string
46
+ *
47
+ * @param options The request options object to convert, will handle it being undefined
48
+ */
49
+ export declare const getQueryStr: (options?: RequestOptions, extras?: {
50
+ [k: string]: string | number | boolean;
51
+ }) => string;
52
+ /**
53
+ * Request helper for checking valid response status
54
+ *
55
+ * @param res The response to check
56
+ */
57
+ export declare const isValidResponse: (res: Response) => boolean;
58
+ /**
59
+ * Request helper to check whether a response is valid and throw a Service error instance if it is not.
60
+ *
61
+ * @param res the response to check
62
+ * @param fallbackMessage a fallback error message if one is not provided
63
+ */
64
+ export declare function validateResponse(res: Response, fallbackMessage: string, requestParams?: {
65
+ [k: string]: any;
66
+ }): Promise<void>;
67
+ export declare const CHUNK_SIZE = 5000000;
68
+ /**
69
+ * An async function that loops over a file and uploads it chunk by chunk, whilst notifying the calling function of it's
70
+ * progress via an Rx stream.
71
+ *
72
+ * @param url the url to upload too
73
+ * @param file the file to upload
74
+ * @param authHeaders the authHeaders to upload with
75
+ * @param extras a dict of extras to also set on the form
76
+ * @param sub an optional subject notify the calling code of current progress
77
+ */
78
+ export declare function chunkedFileUpload(url: string, file: File, authHeaders: {
79
+ [k: string]: string;
80
+ }, extras?: {
81
+ [k: string]: string;
82
+ }, sub?: BehaviorSubject<number>): Promise<void>;
83
+ //# sourceMappingURL=request-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-utils.d.ts","sourceRoot":"","sources":["../src/request-utils.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAKvC,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,M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MAAM,CAAA;CAAE,EAChC,GAAG,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC,CA4Cf"}
@@ -0,0 +1,161 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import shortid from 'shortid';
11
+ import { HTTP_METHOD } from './constants';
12
+ /** Error class for request errors that allow them to be caught more easily */
13
+ export class RequestError extends Error {
14
+ constructor(status, message, requestParams) {
15
+ super(message);
16
+ this.name = 'ServiceError';
17
+ this.status = status;
18
+ this.requestParams = requestParams;
19
+ }
20
+ }
21
+ /**
22
+ * Request helper for converting an options object into a valid query string
23
+ *
24
+ * @param options The request options object to convert, will handle it being undefined
25
+ */
26
+ export const getQueryStr = (options, extras) => {
27
+ if (!options && !extras) {
28
+ return '';
29
+ }
30
+ let query = '?';
31
+ if (Number.isInteger(options.startIndex)) {
32
+ query += `offset=${options.startIndex}&`;
33
+ }
34
+ if (Number.isInteger(options.limit)) {
35
+ query += `limit=${options.limit}&`;
36
+ }
37
+ if (options.searchTerm) {
38
+ query += `query=${options.searchTerm}&`;
39
+ }
40
+ if (options.sort && options.sort.length > 0) {
41
+ // Handle all items in array of sorting rules
42
+ query += `order_by=${options.sort.map((sort) => `${sort.desc ? '-' : ''}${sort.id}`).join(',')}&`;
43
+ }
44
+ if (options.filter && options.filter.length > 0) {
45
+ for (const filter of options.filter) {
46
+ // Handle single filters or arrays of filter terms
47
+ if (typeof filter.value === 'string') {
48
+ query += `${filter.id}=${filter.value}&`;
49
+ }
50
+ else {
51
+ for (const val of filter.value) {
52
+ query += `${filter.id}=${val}&`;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ try {
58
+ Object.keys(extras).forEach((key) => {
59
+ query += `${key}=${String(extras[key])}&`;
60
+ });
61
+ }
62
+ catch (_a) {
63
+ // Do nothing as it was probably empty
64
+ }
65
+ return query.replace(/&$/, '');
66
+ };
67
+ /**
68
+ * Request helper for checking valid response status
69
+ *
70
+ * @param res The response to check
71
+ */
72
+ export const isValidResponse = (res) => {
73
+ return res.status >= 100 && res.status < 400;
74
+ };
75
+ /**
76
+ * Request helper to check whether a response is valid and throw a Service error instance if it is not.
77
+ *
78
+ * @param res the response to check
79
+ * @param fallbackMessage a fallback error message if one is not provided
80
+ */
81
+ export function validateResponse(res, fallbackMessage, requestParams) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!isValidResponse(res)) {
84
+ let message = fallbackMessage;
85
+ try {
86
+ const json = yield res.json();
87
+ message = (json === null || json === void 0 ? void 0 : json.message) || (json === null || json === void 0 ? void 0 : json.detail) || fallbackMessage;
88
+ }
89
+ catch (e) {
90
+ if (fallbackMessage) {
91
+ try {
92
+ message = (yield res.text()) || fallbackMessage;
93
+ }
94
+ catch (_a) {
95
+ // do nothing, use fallback message
96
+ }
97
+ }
98
+ }
99
+ throw new RequestError(res.status, message, requestParams);
100
+ }
101
+ });
102
+ }
103
+ export const CHUNK_SIZE = 5e6;
104
+ /**
105
+ * An async function that loops over a file and uploads it chunk by chunk, whilst notifying the calling function of it's
106
+ * progress via an Rx stream.
107
+ *
108
+ * @param url the url to upload too
109
+ * @param file the file to upload
110
+ * @param authHeaders the authHeaders to upload with
111
+ * @param extras a dict of extras to also set on the form
112
+ * @param sub an optional subject notify the calling code of current progress
113
+ */
114
+ export function chunkedFileUpload(url, file, authHeaders, extras, sub) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
117
+ let currentPointer = 0;
118
+ let currentChunk = 0;
119
+ const uploadId = shortid.generate();
120
+ /* eslint-disable no-await-in-loop */
121
+ // We need to process sequentially thus await in a loop
122
+ while (currentPointer < file.size) {
123
+ const fd = new FormData();
124
+ if (extras) {
125
+ for (const extra of Object.keys(extras)) {
126
+ fd.append(extra, extras[extra]);
127
+ }
128
+ }
129
+ fd.append('upload_id', uploadId);
130
+ fd.append('file_total_size', `${file.size}`);
131
+ fd.append('file_chunk_offset', `${currentPointer}`);
132
+ fd.append('file_chunk_index', `${currentChunk}`);
133
+ fd.append('file_total_chunks', `${totalChunks}`);
134
+ fd.append('file', new File([file.slice(currentPointer, currentPointer + CHUNK_SIZE)], file.name));
135
+ try {
136
+ const res = yield fetch(url, {
137
+ body: fd,
138
+ headers: Object.assign(Object.assign({}, authHeaders), { Accept: 'application/json' }),
139
+ method: HTTP_METHOD.POST,
140
+ });
141
+ yield validateResponse(res, `Failed to upload file: ${file.name}`);
142
+ if (sub) {
143
+ sub.next(Math.round(((currentChunk + 1) / totalChunks) * 100));
144
+ }
145
+ currentPointer += CHUNK_SIZE;
146
+ currentChunk += 1;
147
+ }
148
+ catch (err) {
149
+ if (sub) {
150
+ sub.error(err.message);
151
+ }
152
+ else {
153
+ throw err;
154
+ }
155
+ break;
156
+ }
157
+ }
158
+ /* eslint-enable no-await-in-loop */
159
+ });
160
+ }
161
+ //# sourceMappingURL=request-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-utils.js","sourceRoot":"","sources":["../src/request-utils.tsx"],"names":[],"mappings":";;;;;;;;;AAiBA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAqB1C,8EAA8E;AAC9E,MAAM,OAAO,YAAa,SAAQ,KAAK;IAKnC,YAAY,MAAc,EAAE,OAAe,EAAE,aAAoC;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cA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EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YACjD,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,cAAc,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAElG,IAAI;gBACA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;oBACzB,IAAI,EAAE,EAAE;oBACR,OAAO,kCAAO,WAAW,KAAE,MAAM,EAAE,kBAAkB,GAAE;oBACvD,MAAM,EAAE,WAAW,CAAC,IAAI;iBAC3B,CAAC,CAAC;gBACH,MAAM,gBAAgB,CAAC,GAAG,EAAE,0BAA0B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBACnE,IAAI,GAAG,EAAE;oBACL,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;iBAClE;gBACD,cAAc,IAAI,UAAU,CAAC;gBAC7B,YAAY,IAAI,CAAC,CAAC;aACrB;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,GAAG,EAAE;oBACL,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;iBAC1B;qBAAM;oBACH,MAAM,GAAG,CAAC;iBACb;gBACD,MAAM;aACT;SACJ;QACD,oCAAoC;IACxC,CAAC;CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Subscription } from 'rxjs';
2
+ /**
3
+ * A helper hook that wraps a subscription and makes sure that it is properly cleaned up at the end of the component
4
+ * lifecycle, returns a function that should wrap the call to subscribe
5
+ *
6
+ * @param sub the subscription to cleanup
7
+ */
8
+ export declare function useSubscription(): (sub: Subscription) => void;
9
+ //# sourceMappingURL=rx-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rx-utils.d.ts","sourceRoot":"","sources":["../src/rx-utils.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAU7D"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright 2023 Impulse Innovations Limited
3
+ *
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { useEffect, useState } from 'react';
18
+ /**
19
+ * A helper hook that wraps a subscription and makes sure that it is properly cleaned up at the end of the component
20
+ * lifecycle, returns a function that should wrap the call to subscribe
21
+ *
22
+ * @param sub the subscription to cleanup
23
+ */
24
+ export function useSubscription() {
25
+ const [subscription, setSubscription] = useState();
26
+ useEffect(() => {
27
+ if (subscription) {
28
+ return () => subscription.unsubscribe();
29
+ }
30
+ }, [subscription]);
31
+ return setSubscription;
32
+ }
33
+ //# sourceMappingURL=rx-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rx-utils.js","sourceRoot":"","sources":["../src/rx-utils.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC3B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAgB,CAAC;IAEjE,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,YAAY,EAAE;YACd,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;SAC3C;IACL,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO,eAAe,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,45 @@
1
+ export type AxisDomain = string | number | 'auto' | 'dataMin' | 'dataMax';
2
+ interface AxisProps<T> {
3
+ domain?: [T, T];
4
+ tickFormatter: (tick?: number) => string;
5
+ ticks?: Array<number>;
6
+ type: 'number' | 'category';
7
+ }
8
+ /**
9
+ * An underlying helper hook that uses d3 to create a function for getting the axis properties for an axis based
10
+ * on the pixel size of that axis. This hook should not be used directly, use one of the wrappers for it,
11
+ * e.g. useD3LinearAxis or useD3TimeAxis
12
+ *
13
+ * @param data the underlying data for the axis
14
+ * @param domain the target domain for the axis
15
+ * @param getScale a function to get the d3Scale instance with domain applied
16
+ * @param domainFormatter a function to translate the d3 domain back into a recharts domain
17
+ */
18
+ export declare function useD3Axis<T>(data: Array<T>, getScale: (data: Array<T>, domain?: [T, T]) => any, domainFormatter: (domain: [any, any]) => [T, T], domain?: [T, T]): (width?: number) => AxisProps<T>;
19
+ /**
20
+ * Hook that returns a function that generates the props for a linearly scaled axis based on the size in pixels of the
21
+ * axis
22
+ *
23
+ * @param data the underlying data for the axis
24
+ * @param domain the target domain for the axis
25
+ */
26
+ export declare function useD3LinearAxis(data: Array<number>, domain?: [number, number]): (axisSize?: number) => AxisProps<number>;
27
+ /**
28
+ * Hook that returns a function that generates the props for a time scaled axis based on the size in pixels of the
29
+ * axis
30
+ *
31
+ * @param data the underlying data for the axis
32
+ * @param domain the target domain for the axis
33
+ */
34
+ export declare function useD3TimeAxis(data: Array<Date>, domain?: [Date, Date]): (axisSize?: number) => AxisProps<Date>;
35
+ /**
36
+ * Hook that returns a function that generates the props for an ordinal (categorical) scaled axis, doesn't actually use
37
+ * the ordinal scale as it doesn't need to, but has the same returned api as the others so it can be substituted in.
38
+ *
39
+ * @param mapping a mapping dict that translates the numeric value to a label
40
+ */
41
+ export declare function useD3OrdinalAxis(mapping: {
42
+ [k: number]: string;
43
+ }): (axisSize?: number) => AxisProps<string>;
44
+ export {};
45
+ //# sourceMappingURL=use-d3-axis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-d3-axis.d.ts","sourceRoot":"","sources":["../src/use-d3-axis.tsx"],"names":[],"mappings":"AAsBA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1E,UAAU,SAAS,CAAC,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChB,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACvB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAClD,eAAe,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAC/C,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,GAChB,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAelC;AAOD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC3B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EACnB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,CAAC,CAE1C;AAOD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,SAAS,CAAC,IAAI,CAAC,CAE9G;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,CAAC,CAO3G"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Copyright 2023 Impulse Innovations Limited
3
+ *
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { scaleLinear, scaleTime } from 'd3-scale';
18
+ import { useCallback, useMemo } from 'react';
19
+ import useDeepCompare from './use-deep-compare';
20
+ /**
21
+ * An underlying helper hook that uses d3 to create a function for getting the axis properties for an axis based
22
+ * on the pixel size of that axis. This hook should not be used directly, use one of the wrappers for it,
23
+ * e.g. useD3LinearAxis or useD3TimeAxis
24
+ *
25
+ * @param data the underlying data for the axis
26
+ * @param domain the target domain for the axis
27
+ * @param getScale a function to get the d3Scale instance with domain applied
28
+ * @param domainFormatter a function to translate the d3 domain back into a recharts domain
29
+ */
30
+ export function useD3Axis(data, getScale, domainFormatter, domain) {
31
+ const valueScale = useMemo(() => getScale(data, domain), useDeepCompare([data, domain]));
32
+ return useCallback((axisSize) => {
33
+ const scale = valueScale.range([0, axisSize]).nice();
34
+ return {
35
+ domain: domainFormatter(scale.domain()),
36
+ tickFormatter: scale.tickFormat(),
37
+ ticks: scale.ticks(),
38
+ type: 'number',
39
+ };
40
+ }, [valueScale]);
41
+ }
42
+ /** Helper function for getting a linear d3Scale instance, based on data and domain */
43
+ const getLinearScale = (data, domain) => {
44
+ return scaleLinear().domain([data ? Math.min(...data) : domain[0], data ? Math.max(...data) : domain[1]]);
45
+ };
46
+ /**
47
+ * Hook that returns a function that generates the props for a linearly scaled axis based on the size in pixels of the
48
+ * axis
49
+ *
50
+ * @param data the underlying data for the axis
51
+ * @param domain the target domain for the axis
52
+ */
53
+ export function useD3LinearAxis(data, domain) {
54
+ return useD3Axis(data, getLinearScale, (dm) => dm, domain);
55
+ }
56
+ /** Helper function for getting a time d3Scale instance, based on data and domain */
57
+ const getTimeScale = (data, domain) => {
58
+ return scaleTime().domain([data ? data[0] : domain[0], data ? data[data.length - 1] : domain[1]]);
59
+ };
60
+ /**
61
+ * Hook that returns a function that generates the props for a time scaled axis based on the size in pixels of the
62
+ * axis
63
+ *
64
+ * @param data the underlying data for the axis
65
+ * @param domain the target domain for the axis
66
+ */
67
+ export function useD3TimeAxis(data, domain) {
68
+ return useD3Axis(data, getTimeScale, (dm) => dm, domain);
69
+ }
70
+ /**
71
+ * Hook that returns a function that generates the props for an ordinal (categorical) scaled axis, doesn't actually use
72
+ * the ordinal scale as it doesn't need to, but has the same returned api as the others so it can be substituted in.
73
+ *
74
+ * @param mapping a mapping dict that translates the numeric value to a label
75
+ */
76
+ export function useD3OrdinalAxis(mapping) {
77
+ return () => {
78
+ return {
79
+ tickFormatter: (tick) => mapping[tick],
80
+ type: 'category',
81
+ };
82
+ };
83
+ }
84
+ //# sourceMappingURL=use-d3-axis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-d3-axis.js","sourceRoot":"","sources":["../src/use-d3-axis.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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;AACH,MAAM,UAAU,eAAe,CAC3B,IAAmB,EACnB,MAAyB;IAEzB,OAAO,SAAS,CAAS,IAAI,EAAE,cAAc,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,oFAAoF;AACpF,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAE,MAAoB,EAA6B,EAAE;IACxF,OAAO,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAiB,EAAE,MAAqB;IAClE,OAAO,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC7D,OAAO,GAAsB,EAAE;QAC3B,OAAO;YACH,aAAa,EAAE,CAAC,IAAY,EAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YACtD,IAAI,EAAE,UAAU;SACnB,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A helper hook that allows for objects to be deeply compared rather than being compared by reference.
3
+ *
4
+ * An example usage with useEffect, where deepObject is a complex object, would be:
5
+ *
6
+ * useEffect(() => {
7
+ * doSomethingHeavy(deepObject)
8
+ * }, useDeepCompare([deepObject]))
9
+ *
10
+ * @param value - an array of values to check the equality of
11
+ */
12
+ export default function useDeepCompare<T>(value: T): T;
13
+ //# sourceMappingURL=use-deep-compare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-deep-compare.d.ts","sourceRoot":"","sources":["../src/use-deep-compare.tsx"],"names":[],"mappings":"AAmBA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAQrD"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright 2023 Impulse Innovations Limited
3
+ *
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import isEqual from 'lodash/isEqual';
18
+ import { useRef } from 'react';
19
+ /**
20
+ * A helper hook that allows for objects to be deeply compared rather than being compared by reference.
21
+ *
22
+ * An example usage with useEffect, where deepObject is a complex object, would be:
23
+ *
24
+ * useEffect(() => {
25
+ * doSomethingHeavy(deepObject)
26
+ * }, useDeepCompare([deepObject]))
27
+ *
28
+ * @param value - an array of values to check the equality of
29
+ */
30
+ export default function useDeepCompare(value) {
31
+ const ref = useRef();
32
+ if (!isEqual(value, ref.current)) {
33
+ ref.current = value;
34
+ }
35
+ return ref.current;
36
+ }
37
+ //# sourceMappingURL=use-deep-compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-deep-compare.js","sourceRoot":"","sources":["../src/use-deep-compare.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAI,KAAQ;IAC9C,MAAM,GAAG,GAAG,MAAM,EAAK,CAAC;IAExB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE;QAC9B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;KACvB;IAED,OAAO,GAAG,CAAC,OAAO,CAAC;AACvB,CAAC"}
@@ -0,0 +1,22 @@
1
+ export interface DimensionObject {
2
+ bottom: number;
3
+ height: number;
4
+ left: number;
5
+ right: number;
6
+ top: number;
7
+ width: number;
8
+ x: number;
9
+ y: number;
10
+ }
11
+ export type UseDimensionsHook<T extends HTMLElement> = [(node: T) => void, {
12
+ [k: string]: number;
13
+ }, T];
14
+ /**
15
+ * The useDimensions hook allows for a component to track the dimensions of a given element by passing the returned ref
16
+ * to it.
17
+ *
18
+ * @param liveMeasure whether to recalculate dimensions when the user scrolls or resizes the page.
19
+ */
20
+ declare function useDimensions<T extends HTMLElement>(liveMeasure?: boolean): UseDimensionsHook<T>;
21
+ export default useDimensions;
22
+ //# sourceMappingURL=use-dimensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-dimensions.d.ts","sourceRoot":"","sources":["../src/use-dimensions.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,WAAW,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,CAAC,CAAC,CAAC;AAEvG;;;;;GAKG;AACH,iBAAS,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,WAAW,UAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,CA2BtF;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright 2023 Impulse Innovations Limited
3
+ *
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { useCallback, useLayoutEffect, useState } from 'react';
18
+ /**
19
+ * The useDimensions hook allows for a component to track the dimensions of a given element by passing the returned ref
20
+ * to it.
21
+ *
22
+ * @param liveMeasure whether to recalculate dimensions when the user scrolls or resizes the page.
23
+ */
24
+ function useDimensions(liveMeasure = true) {
25
+ const [dimensions, setDimensions] = useState({});
26
+ const [node, setNode] = useState(null);
27
+ const ref = useCallback((_node) => {
28
+ setNode(_node);
29
+ }, []);
30
+ useLayoutEffect(() => {
31
+ if (node) {
32
+ const measure = () => window.requestAnimationFrame(() => setDimensions(node.getBoundingClientRect()));
33
+ measure();
34
+ if (liveMeasure) {
35
+ window.addEventListener('resize', measure);
36
+ window.addEventListener('scroll', measure);
37
+ return () => {
38
+ window.removeEventListener('resize', measure);
39
+ window.removeEventListener('scroll', measure);
40
+ };
41
+ }
42
+ }
43
+ }, [node]);
44
+ return [ref, dimensions, node];
45
+ }
46
+ export default useDimensions;
47
+ //# sourceMappingURL=use-dimensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-dimensions.js","sourceRoot":"","sources":["../src/use-dimensions.tsx"],"names":[],"mappings":"AA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
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { MutableRefObject } from 'react';
18
+ /**
19
+ * The useIntersectionObserver hook allows a component to track whether an element is intersecting with an ancestor
20
+ * element or with a top-level document's viewport.
21
+ *
22
+ * @param ref the ref to the element that is to be observed
23
+ * @param rootMargin the amount of the element that is to be intersecting for the observer's callback to be executed.
24
+ * @param threshold Either a single number or an array of numbers which indicate at what percentage of the target's
25
+ * visibility the observer's callback should be executed.
26
+ * @returns boolean indicating whether element is intersecting or not
27
+ */
28
+ declare function useIntersectionObserver<T extends Element>(ref: MutableRefObject<T>, rootMargin?: string, threshold?: number): boolean;
29
+ export default useIntersectionObserver;
30
+ //# sourceMappingURL=use-intersection-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intersection-observer.d.ts","sourceRoot":"","sources":["../src/use-intersection-observer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAuB,MAAM,OAAO,CAAC;AAE9D;;;;;;;;;GASG;AAEH,iBAAS,uBAAuB,CAAC,CAAC,SAAS,OAAO,EAC9C,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACxB,UAAU,SAAQ,EAClB,SAAS,SAAM,GAChB,OAAO,CAiBT;AAED,eAAe,uBAAuB,CAAC"}