@monkvision/common 4.0.0

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 (183) hide show
  1. package/LICENSE +32 -0
  2. package/README/APP_UTILS.md +52 -0
  3. package/README/HOOKS.md +242 -0
  4. package/README/INTERNATIONALIZATION.md +89 -0
  5. package/README/STATE_MANAGEMENT.md +125 -0
  6. package/README/THEMING.md +70 -0
  7. package/README/UTILITIES.md +254 -0
  8. package/README.md +23 -0
  9. package/lib/PreventExit/hooks.d.ts +15 -0
  10. package/lib/PreventExit/hooks.js +27 -0
  11. package/lib/PreventExit/hooks.js.map +1 -0
  12. package/lib/PreventExit/index.d.ts +1 -0
  13. package/lib/PreventExit/index.js +18 -0
  14. package/lib/PreventExit/index.js.map +1 -0
  15. package/lib/PreventExit/store.d.ts +23 -0
  16. package/lib/PreventExit/store.js +41 -0
  17. package/lib/PreventExit/store.js.map +1 -0
  18. package/lib/apps/analytics.d.ts +2 -0
  19. package/lib/apps/analytics.js +16 -0
  20. package/lib/apps/analytics.js.map +1 -0
  21. package/lib/apps/appState.d.ts +61 -0
  22. package/lib/apps/appState.js +11 -0
  23. package/lib/apps/appState.js.map +1 -0
  24. package/lib/apps/appStateProvider.d.ts +64 -0
  25. package/lib/apps/appStateProvider.js +116 -0
  26. package/lib/apps/appStateProvider.js.map +1 -0
  27. package/lib/apps/index.d.ts +3 -0
  28. package/lib/apps/index.js +20 -0
  29. package/lib/apps/index.js.map +1 -0
  30. package/lib/apps/monitoring.d.ts +2 -0
  31. package/lib/apps/monitoring.js +25 -0
  32. package/lib/apps/monitoring.js.map +1 -0
  33. package/lib/apps/searchParams.d.ts +60 -0
  34. package/lib/apps/searchParams.js +81 -0
  35. package/lib/apps/searchParams.js.map +1 -0
  36. package/lib/hooks/index.d.ts +12 -0
  37. package/lib/hooks/index.js +29 -0
  38. package/lib/hooks/index.js.map +1 -0
  39. package/lib/hooks/useAsyncEffect.d.ts +7 -0
  40. package/lib/hooks/useAsyncEffect.js +37 -0
  41. package/lib/hooks/useAsyncEffect.js.map +1 -0
  42. package/lib/hooks/useAsyncInterval.d.ts +7 -0
  43. package/lib/hooks/useAsyncInterval.js +54 -0
  44. package/lib/hooks/useAsyncInterval.js.map +1 -0
  45. package/lib/hooks/useInteractiveStatus.d.ts +52 -0
  46. package/lib/hooks/useInteractiveStatus.js +70 -0
  47. package/lib/hooks/useInteractiveStatus.js.map +1 -0
  48. package/lib/hooks/useInterval.d.ts +5 -0
  49. package/lib/hooks/useInterval.js +27 -0
  50. package/lib/hooks/useInterval.js.map +1 -0
  51. package/lib/hooks/useLoadingState.d.ts +33 -0
  52. package/lib/hooks/useLoadingState.js +36 -0
  53. package/lib/hooks/useLoadingState.js.map +1 -0
  54. package/lib/hooks/useObjectMemo.d.ts +12 -0
  55. package/lib/hooks/useObjectMemo.js +20 -0
  56. package/lib/hooks/useObjectMemo.js.map +1 -0
  57. package/lib/hooks/useObjectTranslation.d.ts +15 -0
  58. package/lib/hooks/useObjectTranslation.js +19 -0
  59. package/lib/hooks/useObjectTranslation.js.map +1 -0
  60. package/lib/hooks/useQueue.d.ts +152 -0
  61. package/lib/hooks/useQueue.js +194 -0
  62. package/lib/hooks/useQueue.js.map +1 -0
  63. package/lib/hooks/useResponsiveStyle.d.ts +28 -0
  64. package/lib/hooks/useResponsiveStyle.js +64 -0
  65. package/lib/hooks/useResponsiveStyle.js.map +1 -0
  66. package/lib/hooks/useSearchParams.d.ts +4 -0
  67. package/lib/hooks/useSearchParams.js +12 -0
  68. package/lib/hooks/useSearchParams.js.map +1 -0
  69. package/lib/hooks/useSightLabel.d.ts +21 -0
  70. package/lib/hooks/useSightLabel.js +19 -0
  71. package/lib/hooks/useSightLabel.js.map +1 -0
  72. package/lib/hooks/useWindowDimensions.d.ts +15 -0
  73. package/lib/hooks/useWindowDimensions.js +27 -0
  74. package/lib/hooks/useWindowDimensions.js.map +1 -0
  75. package/lib/i18n/index.d.ts +2 -0
  76. package/lib/i18n/index.js +19 -0
  77. package/lib/i18n/index.js.map +1 -0
  78. package/lib/i18n/translations/image.d.ts +22 -0
  79. package/lib/i18n/translations/image.js +408 -0
  80. package/lib/i18n/translations/image.js.map +1 -0
  81. package/lib/i18n/translations/index.d.ts +2 -0
  82. package/lib/i18n/translations/index.js +19 -0
  83. package/lib/i18n/translations/index.js.map +1 -0
  84. package/lib/i18n/translations/vehicleParts.d.ts +5 -0
  85. package/lib/i18n/translations/vehicleParts.js +461 -0
  86. package/lib/i18n/translations/vehicleParts.js.map +1 -0
  87. package/lib/i18n/utils.d.ts +45 -0
  88. package/lib/i18n/utils.js +86 -0
  89. package/lib/i18n/utils.js.map +1 -0
  90. package/lib/index.d.ts +7 -0
  91. package/lib/index.js +24 -0
  92. package/lib/index.js.map +1 -0
  93. package/lib/state/actions/createdOneImage.d.ts +44 -0
  94. package/lib/state/actions/createdOneImage.js +52 -0
  95. package/lib/state/actions/createdOneImage.js.map +1 -0
  96. package/lib/state/actions/gotOneInspection.d.ts +24 -0
  97. package/lib/state/actions/gotOneInspection.js +55 -0
  98. package/lib/state/actions/gotOneInspection.js.map +1 -0
  99. package/lib/state/actions/index.d.ts +6 -0
  100. package/lib/state/actions/index.js +23 -0
  101. package/lib/state/actions/index.js.map +1 -0
  102. package/lib/state/actions/monkAction.d.ts +34 -0
  103. package/lib/state/actions/monkAction.js +30 -0
  104. package/lib/state/actions/monkAction.js.map +1 -0
  105. package/lib/state/actions/resetState.d.ts +20 -0
  106. package/lib/state/actions/resetState.js +21 -0
  107. package/lib/state/actions/resetState.js.map +1 -0
  108. package/lib/state/actions/updatedManyTasks.d.ts +32 -0
  109. package/lib/state/actions/updatedManyTasks.js +47 -0
  110. package/lib/state/actions/updatedManyTasks.js.map +1 -0
  111. package/lib/state/actions/updatedVehicle.d.ts +38 -0
  112. package/lib/state/actions/updatedVehicle.js +50 -0
  113. package/lib/state/actions/updatedVehicle.js.map +1 -0
  114. package/lib/state/context.d.ts +21 -0
  115. package/lib/state/context.js +10 -0
  116. package/lib/state/context.js.map +1 -0
  117. package/lib/state/hooks.d.ts +8 -0
  118. package/lib/state/hooks.js +20 -0
  119. package/lib/state/hooks.js.map +1 -0
  120. package/lib/state/index.d.ts +6 -0
  121. package/lib/state/index.js +23 -0
  122. package/lib/state/index.js.map +1 -0
  123. package/lib/state/provider.d.ts +19 -0
  124. package/lib/state/provider.js +40 -0
  125. package/lib/state/provider.js.map +1 -0
  126. package/lib/state/reducer.d.ts +6 -0
  127. package/lib/state/reducer.js +24 -0
  128. package/lib/state/reducer.js.map +1 -0
  129. package/lib/state/state.d.ts +50 -0
  130. package/lib/state/state.js +22 -0
  131. package/lib/state/state.js.map +1 -0
  132. package/lib/theme/context.d.ts +5 -0
  133. package/lib/theme/context.js +10 -0
  134. package/lib/theme/context.js.map +1 -0
  135. package/lib/theme/default/index.d.ts +1 -0
  136. package/lib/theme/default/index.js +18 -0
  137. package/lib/theme/default/index.js.map +1 -0
  138. package/lib/theme/default/palette.d.ts +2 -0
  139. package/lib/theme/default/palette.js +69 -0
  140. package/lib/theme/default/palette.js.map +1 -0
  141. package/lib/theme/hooks.d.ts +5 -0
  142. package/lib/theme/hooks.js +13 -0
  143. package/lib/theme/hooks.js.map +1 -0
  144. package/lib/theme/index.d.ts +5 -0
  145. package/lib/theme/index.js +22 -0
  146. package/lib/theme/index.js.map +1 -0
  147. package/lib/theme/provider.d.ts +16 -0
  148. package/lib/theme/provider.js +29 -0
  149. package/lib/theme/provider.js.map +1 -0
  150. package/lib/theme/theme.d.ts +17 -0
  151. package/lib/theme/theme.js +54 -0
  152. package/lib/theme/theme.js.map +1 -0
  153. package/lib/utils/array.utils.d.ts +26 -0
  154. package/lib/utils/array.utils.js +75 -0
  155. package/lib/utils/array.utils.js.map +1 -0
  156. package/lib/utils/browser.utils.d.ts +4 -0
  157. package/lib/utils/browser.utils.js +16 -0
  158. package/lib/utils/browser.utils.js.map +1 -0
  159. package/lib/utils/color.utils.d.ts +51 -0
  160. package/lib/utils/color.utils.js +155 -0
  161. package/lib/utils/color.utils.js.map +1 -0
  162. package/lib/utils/env.utils.d.ts +5 -0
  163. package/lib/utils/env.utils.js +16 -0
  164. package/lib/utils/env.utils.js.map +1 -0
  165. package/lib/utils/index.d.ts +9 -0
  166. package/lib/utils/index.js +26 -0
  167. package/lib/utils/index.js.map +1 -0
  168. package/lib/utils/mimetype.utils.d.ts +14 -0
  169. package/lib/utils/mimetype.utils.js +69 -0
  170. package/lib/utils/mimetype.utils.js.map +1 -0
  171. package/lib/utils/promise.utils.d.ts +4 -0
  172. package/lib/utils/promise.utils.js +13 -0
  173. package/lib/utils/promise.utils.js.map +1 -0
  174. package/lib/utils/state.utils.d.ts +9 -0
  175. package/lib/utils/state.utils.js +35 -0
  176. package/lib/utils/state.utils.js.map +1 -0
  177. package/lib/utils/string.utils.d.ts +22 -0
  178. package/lib/utils/string.utils.js +48 -0
  179. package/lib/utils/string.utils.js.map +1 -0
  180. package/lib/utils/zlib.utils.d.ts +8 -0
  181. package/lib/utils/zlib.utils.js +30 -0
  182. package/lib/utils/zlib.utils.js.map +1 -0
  183. package/package.json +97 -0
@@ -0,0 +1,254 @@
1
+ # Utilities
2
+ This README page is aimed at providing documentation on a specific part of the `@monkvision/common` package : the
3
+ utility functions. You can refer to [this page](README.md) for more general information on the package.
4
+
5
+ This package exports various utility functions used throughout the MonkJs SDK.
6
+
7
+ # Array Utils
8
+ ### permutations
9
+ ```typescript
10
+ import { permutations } from '@monkvision/common';
11
+
12
+ console.log(permutations([1, 2, 3]));
13
+ // Output : [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
14
+ ```
15
+ Returns an array containing all the possible permutations of the given array.
16
+
17
+ ### uniq
18
+ ```typescript
19
+ import { uniq } from '@monkvision/common';
20
+
21
+ console.log(uniq([1, 1, 1, 2, 3, 3]));
22
+ // Output : [1, 2, 3]
23
+ ```
24
+ Return a copy of the given array in which all duplicates have been removed.
25
+
26
+ ### flatten
27
+ ```typescript
28
+ import { flatten } from '@monkvision/common';
29
+
30
+ console.log(flatten([ 1, [2, 3], [[4], [5, 6]]]));
31
+ // Output : [1, 2, 3, 4, 5, 6]
32
+ ```
33
+ Flatten the given array.
34
+
35
+ ### flatten
36
+ ```typescript
37
+ import { flatMap } from '@monkvision/common';
38
+
39
+ console.log(flatMap([1, 2, 3], (item: number) => [item, item + 1]));
40
+ // Output : [1, 2, 2, 3, 3, 4]
41
+ ```
42
+ JS implementation of the
43
+ [Array.prototype.flatMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
44
+ method, available on all versions of JavaScript.
45
+
46
+ ---
47
+
48
+ # Color Utils
49
+ ### getRGBAFromString
50
+ ```typescript
51
+ import { getRGBAFromString } from '@monkvision/common';
52
+
53
+ console.log(JSON.stringify(getRGBAFromString('#AF270CCC')));
54
+ // Output : {"r":175,"g":39,"b":12,"a":0.8}
55
+ ```
56
+ Returns the RGBA values of the given color. The accepted formats are :
57
+ - RGB : `rgb(167, 224, 146)`
58
+ - RGBA : `rgb(167, 224, 146, 0.03)`
59
+ - HEX : `#A7E092`
60
+ - HEX (alpha) : `#A7E09208`
61
+ - HEX (short) : `#AE9`
62
+ - HEX (short + alpha) : `#AE98`
63
+
64
+ This function is case-insensitive and ignores white spaces.
65
+
66
+ ### getHexFromRGBA
67
+ ```typescript
68
+ import { getHexFromRGBA } from '@monkvision/common';
69
+
70
+ console.log(getHexFromRGBA({ r: 111, g: 222, b: 0, a: 0.67 }));
71
+ // Output : #6FDE00AB
72
+ ```
73
+ Converts RGBA values to their hexadecimal representation.
74
+
75
+ ### shadeColor
76
+ ```typescript
77
+ import { shadeColor } from '@monkvision/common';
78
+
79
+ console.log(shadeColor('#FC72A7', 0.7));
80
+ // Output : #FFC2FFFF
81
+ ```
82
+ Apply a shade of black or white over the given color. The amount of shade to apply works as a ratio :
83
+ - use positive values like 0.08 to lighten the color by 8%
84
+ - use negative values like -0.08 to darken the color by 8%
85
+
86
+ ### changeAlpha
87
+ ```typescript
88
+ import { changeAlpha } from '@monkvision/common';
89
+
90
+ console.log(changeAlpha('#FF1234FF', 0.5));
91
+ // Output : #FF123480
92
+ ```
93
+ Returns a new color equal to the given color but with a different alpha value.
94
+
95
+ ### getInteractiveVariants
96
+ ```typescript
97
+ import { getInteractiveVariants } from '@monkvision/common';
98
+
99
+ const variants = getInteractiveVariants('#FC72A7');
100
+ /*
101
+ * variants = {
102
+ * [InteractiveStatus.DEFAULT]: '#FC72A7',
103
+ * [InteractiveStatus.HOVERED]: '#FF7BB4',
104
+ * [InteractiveStatus.ACTIVE]: '#FF80BB',
105
+ * [InteractiveStatus.DISABLED]: '#FC72A7',
106
+ * }
107
+ */
108
+ ```
109
+ Create interactive variants (hovered, active...) for the given color. You can specify as an additional parameter the
110
+ type of variation to use for the interactive colors (lighten or darken the color, default = lighten).
111
+
112
+ ---
113
+
114
+ # Environment Utils
115
+ ### getEnvOrThrow
116
+ ```typescript
117
+ import { getEnvOrThrow } from '@monkvision/common';
118
+
119
+ try {
120
+ const example = getEnvOrThrow('REACT_APP_EXAMPLE');
121
+ console.log('Env var is defined :', example);
122
+ } catch (err) {
123
+ console.log('Env var is not defined');
124
+ }
125
+ ```
126
+ Returns the value of a given environment variable. If the value does not exist, it throws an error.
127
+
128
+ ---
129
+
130
+ # Mimetype Utils
131
+ ### MIMETYPE_FILE_EXTENSIONS
132
+ ```typescript
133
+ import { MIMETYPE_FILE_EXTENSIONS } from '@monkvision/common';
134
+
135
+ console.log(MIMETYPE_FILE_EXTENSIONS['text/plain']);
136
+ // Output : ['txt']
137
+ ```
138
+ Datamap that associates mimetypes to known file extensions corresponding to this mimetype.
139
+
140
+ ### getFileExtensions
141
+ ```typescript
142
+ import { getFileExtensions } from '@monkvision/common';
143
+
144
+ console.log(getFileExtensions('image/jpeg'));
145
+ // Output : ['jpeg', 'jpg']
146
+ ```
147
+ Returns a list of file extensions known to be corresponding to the given mimetype. If no file extension is known for
148
+ this mimetype, this function will throw an error.
149
+
150
+ ### getMimetype
151
+ ```typescript
152
+ import { getMimetype } from '@monkvision/common';
153
+
154
+ console.log(getMimetype('jpg'));
155
+ // Output : 'image/jpeg'
156
+ ```
157
+ Returns the mimetype associated with the given file extension. If the file extension is unknown, this function will
158
+ throw an error.
159
+
160
+ ---
161
+
162
+ # Promise Utils
163
+ ### timeoutPromise
164
+ ```typescript
165
+ import { timeoutPromise } from '@monkvision/common';
166
+
167
+ timeoutPromise(5000).then(() => console.log('Hello!'));
168
+ // Output after 5 seconds : 'Hello!'
169
+ ```
170
+ This function creates and returns a new Promise that will resolve to void after the given amount of milliseconds.
171
+
172
+ ---
173
+
174
+ # State Utils
175
+ ### getInspectionImages
176
+ ```typescript
177
+ import { getInspectionImages } from '@monkvision/common';
178
+
179
+ console.log(getInspectionImages(inspectionId, images, filterRetakes));
180
+ // Returns an array of all the images having the given inspectionId.
181
+ ```
182
+ Utility function that extracts the images of the given inspection. Set `filterRetakes` to `false` to filter retaken
183
+ pictures.
184
+
185
+ ---
186
+
187
+ # String Utils
188
+ ### suffix
189
+ ```typescript
190
+ import { suffix } from '@monkvision/common';
191
+
192
+ console.log(suffix('my-str', { suffix1: true, suffix2: false }));
193
+ // Output : 'my-str suffix1'
194
+ ```
195
+ This function suffixes a string with the given suffixes, only if their value is `true` in the suffixes object param.
196
+
197
+ *Note : The order of the suffixes is not guaranteed.*
198
+
199
+ ### words
200
+ ```typescript
201
+ import { words } from '@monkvision/common';
202
+
203
+ console.log(words('my-str-test'));
204
+ // Output : 'my str test'
205
+ ```
206
+ Split the given string into its composing words.
207
+
208
+ ### capitalize
209
+ ```typescript
210
+ import { capitalize } from '@monkvision/common';
211
+
212
+ console.log(capitalize('my-str-test'));
213
+ // Output : 'My-str-test'
214
+ ```
215
+ Capitalizes (transforms the first character to upper case) the given string.
216
+
217
+ ### uncapitalize
218
+ ```typescript
219
+ import { uncapitalize } from '@monkvision/common';
220
+
221
+ console.log(uncapitalize('My-str-test'));
222
+ // Output : 'my-str-test'
223
+ ```
224
+ Uncapitalizes (transforms the first character to lower case) the given string.
225
+
226
+ ### toCamelCase
227
+ ```typescript
228
+ import { toCamelCase } from '@monkvision/common';
229
+
230
+ console.log(toCamelCase('My-str-test'));
231
+ // Output : 'myStrTest'
232
+ ```
233
+ Converts a string to camel case.
234
+
235
+ ---
236
+
237
+ # Zlib Utils
238
+ ### zlibCompress
239
+ ```typescript
240
+ import { zlibCompress } from '@monkvision/common';
241
+
242
+ console.log(zlibCompress('Hello World!'))
243
+ // Output : 'eJzzSM3JyVcIzy/KSVEEABxJBD4='
244
+ ```
245
+ Compresses and encodes a string in base64 using the ZLib algorithm.
246
+
247
+ ### zlibDecompress
248
+ ```typescript
249
+ import { zlibDecompress } from '@monkvision/common';
250
+
251
+ console.log(zlibDecompress('eJzzSM3JyVcIzy/KSVEEABxJBD4='))
252
+ // Output : 'Hello World!'
253
+ ```
254
+ Decompresses a string that has been encoded in base64 and compressed using the Zlib algorithm.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @monkvision/common
2
+ This package contains logic and bits of code shared accross the MonkJs project.
3
+
4
+ # Installing
5
+ To install the package, you can run the following command :
6
+
7
+ ```shell
8
+ yarn add @monkvision/common
9
+ ```
10
+
11
+ If you are using TypeScript, this package comes with its type definitions integrated, so you don't need to install
12
+ anything else!
13
+
14
+ # Detailed Documentation
15
+ This exports implements multiple functionnalities for the MonkJs SDK. If you want more details for each functionnality,
16
+ you can refer to their own README directly :
17
+
18
+ - [State Management](README/STATE_MANAGEMENT.md).
19
+ - [Theming](README/THEMING.md).
20
+ - [Internationalization](README/INTERNATIONALIZATION.md).
21
+ - [Hooks](README/APP_UTILS).
22
+ - [Utilities](README/UTILITIES.md).
23
+ - [Application Utilities](README/HOOKS).
@@ -0,0 +1,15 @@
1
+ import { PreventExitListenerResult } from './store';
2
+ /**
3
+ * Custom hook that allows preventing the user from exiting the page or navigating away.
4
+ *
5
+ * @param preventExit - A boolean value indicating whether to prevent the user from exiting the page or not.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * function MyComponent() {
10
+ * const { allowRedirect } = usePreventExit(true);
11
+ * return <div onClick={allowRedirect}>My Component</div>;
12
+ * }
13
+ * ```
14
+ */
15
+ export declare function usePreventExit(preventExit: boolean): Pick<PreventExitListenerResult, 'allowRedirect'>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePreventExit = void 0;
4
+ var react_1 = require("react");
5
+ var store_1 = require("./store");
6
+ var hooks_1 = require("../hooks");
7
+ /**
8
+ * Custom hook that allows preventing the user from exiting the page or navigating away.
9
+ *
10
+ * @param preventExit - A boolean value indicating whether to prevent the user from exiting the page or not.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * function MyComponent() {
15
+ * const { allowRedirect } = usePreventExit(true);
16
+ * return <div onClick={allowRedirect}>My Component</div>;
17
+ * }
18
+ * ```
19
+ */
20
+ function usePreventExit(preventExit) {
21
+ var _a = (0, react_1.useMemo)(store_1.createPreventExitListener, []), cleanup = _a.cleanup, setPreventExit = _a.setPreventExit, allowRedirect = _a.allowRedirect;
22
+ (0, react_1.useEffect)(function () { return setPreventExit(preventExit); }, [preventExit]);
23
+ (0, react_1.useEffect)(function () { return cleanup; }, []);
24
+ return (0, hooks_1.useObjectMemo)({ allowRedirect: allowRedirect });
25
+ }
26
+ exports.usePreventExit = usePreventExit;
27
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/PreventExit/hooks.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAC3C,iCAA+E;AAC/E,kCAAyC;AAEzC;;;;;;;;;;;;GAYG;AACH,SAAgB,cAAc,CAC5B,WAAoB;IAEd,IAAA,KAA6C,IAAA,eAAO,EAAC,iCAAyB,EAAE,EAAE,CAAC,EAAjF,OAAO,aAAA,EAAE,cAAc,oBAAA,EAAE,aAAa,mBAA2C,CAAC;IAC1F,IAAA,iBAAS,EAAC,cAAM,OAAA,cAAc,CAAC,WAAW,CAAC,EAA3B,CAA2B,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,IAAA,iBAAS,EAAC,cAAM,OAAA,OAAO,EAAP,CAAO,EAAE,EAAE,CAAC,CAAC;IAC7B,OAAO,IAAA,qBAAa,EAAC,EAAE,aAAa,eAAA,EAAE,CAAC,CAAC;AAC1C,CAAC;AAPD,wCAOC"}
@@ -0,0 +1 @@
1
+ export * from './hooks';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hooks"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/PreventExit/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Returns a listener which can used to calculate the state of prevent exit.
3
+ */
4
+ export interface PreventExitListenerResult {
5
+ /**
6
+ * Callback used to set the value indicating if direct exit of the page is currently allowed or not.
7
+ */
8
+ setPreventExit: (preventExit: boolean) => void;
9
+ /**
10
+ * Allows the user to leave the page without confirmation temporarily.
11
+ * This should be used when the developer wants to explicitly allow navigation.
12
+ */
13
+ allowRedirect: () => void;
14
+ /**
15
+ * Performs garbage collection by removing the preventExit state associated with the component.
16
+ * This should be used when the component is unmounted.
17
+ */
18
+ cleanup: () => void;
19
+ }
20
+ /**
21
+ * Creates a listener function that manages the preventExit state of a component.
22
+ */
23
+ export declare function createPreventExitListener(): PreventExitListenerResult;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPreventExitListener = void 0;
4
+ var keys = [];
5
+ var allPreventExitState = {};
6
+ function arePreventExitRemaining() {
7
+ if (keys.map(function (key) { return allPreventExitState[key]; }).every(function (i) { return i === false; })) {
8
+ window.onbeforeunload = null;
9
+ return true;
10
+ }
11
+ return false;
12
+ }
13
+ function publish(id, preventExit) {
14
+ allPreventExitState[id] = preventExit;
15
+ if (!arePreventExitRemaining()) {
16
+ window.onbeforeunload = function (e) {
17
+ e.preventDefault();
18
+ return 'prevent-exit';
19
+ };
20
+ }
21
+ }
22
+ /**
23
+ * Creates a listener function that manages the preventExit state of a component.
24
+ */
25
+ function createPreventExitListener() {
26
+ var key = Symbol('PreventExitListener');
27
+ allPreventExitState[key] = true;
28
+ keys.push(key);
29
+ return {
30
+ setPreventExit: function (preventExit) { return publish(key, preventExit); },
31
+ allowRedirect: function () {
32
+ window.onbeforeunload = null;
33
+ },
34
+ cleanup: function () {
35
+ delete allPreventExitState[key];
36
+ arePreventExitRemaining();
37
+ },
38
+ };
39
+ }
40
+ exports.createPreventExitListener = createPreventExitListener;
41
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/PreventExit/store.ts"],"names":[],"mappings":";;;AAAA,IAAM,IAAI,GAAkB,EAAE,CAAC;AAC/B,IAAM,mBAAmB,GAA4B,EAAE,CAAC;AAExD,SAAS,uBAAuB;IAC9B,IAAI,IAAI,CAAC,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,mBAAmB,CAAC,GAAG,CAAC,EAAxB,CAAwB,CAAC,CAAC,KAAK,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,KAAK,KAAK,EAAX,CAAW,CAAC,EAAE;QACzE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CAAC,EAAU,EAAE,WAAoB;IAC/C,mBAAmB,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC;IACtC,IAAI,CAAC,uBAAuB,EAAE,EAAE;QAC9B,MAAM,CAAC,cAAc,GAAG,UAAC,CAAC;YACxB,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC;KACH;AACH,CAAC;AAsBD;;GAEG;AACH,SAAgB,yBAAyB;IACvC,IAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAC1C,mBAAmB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAChC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEf,OAAO;QACL,cAAc,EAAE,UAAC,WAAW,IAAK,OAAA,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,EAAzB,CAAyB;QAC1D,aAAa,EAAE;YACb,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE;YACP,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAChC,uBAAuB,EAAE,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC;AAfD,8DAeC"}
@@ -0,0 +1,2 @@
1
+ import { MonkAppState } from './appState';
2
+ export declare function useAppStateAnalytics({ inspectionId }: Pick<MonkAppState, 'inspectionId'>): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAppStateAnalytics = void 0;
4
+ var analytics_1 = require("@monkvision/analytics");
5
+ var react_1 = require("react");
6
+ function useAppStateAnalytics(_a) {
7
+ var inspectionId = _a.inspectionId;
8
+ var setUserId = (0, analytics_1.useAnalytics)().setUserId;
9
+ (0, react_1.useEffect)(function () {
10
+ if (inspectionId) {
11
+ setUserId(inspectionId);
12
+ }
13
+ }, [inspectionId, setUserId]);
14
+ }
15
+ exports.useAppStateAnalytics = useAppStateAnalytics;
16
+ //# sourceMappingURL=analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/apps/analytics.ts"],"names":[],"mappings":";;;AAAA,mDAAqD;AACrD,+BAAkC;AAGlC,SAAgB,oBAAoB,CAAC,EAAoD;QAAlD,YAAY,kBAAA;IACzC,IAAA,SAAS,GAAK,IAAA,wBAAY,GAAE,UAAnB,CAAoB;IAErC,IAAA,iBAAS,EAAC;QACR,IAAI,YAAY,EAAE;YAChB,SAAS,CAAC,YAAY,CAAC,CAAC;SACzB;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;AAChC,CAAC;AARD,oDAQC"}
@@ -0,0 +1,61 @@
1
+ import { CaptureAppConfig, Sight, SteeringWheelPosition, VehicleType } from '@monkvision/types';
2
+ import { LoadingState } from '../hooks';
3
+ /**
4
+ * Application state usually used by Monk applications to configure and handle the current user journey.
5
+ */
6
+ export interface MonkAppState {
7
+ /**
8
+ * LoadingState indicating if the application state is loading. If it is loading it usually means that the provider
9
+ * did not have time to fetch the parameter values.
10
+ */
11
+ loading: LoadingState;
12
+ /**
13
+ * The current configuration of the application.
14
+ */
15
+ config: CaptureAppConfig;
16
+ /**
17
+ * The authentication token representing the currently logged-in user. If this param is `null`, it means the user is
18
+ * not logged in.
19
+ */
20
+ authToken: string | null;
21
+ /**
22
+ * The ID of the current inspection being handled (picture taking, report viewing...) by the application. If this
23
+ * param is `null`, it probably means that the inspection must be created by the app.
24
+ */
25
+ inspectionId: string | null;
26
+ /**
27
+ * The current vehicle type of the app. This value usually helps to choose which sights to display to the user, or
28
+ * which car 360 wireframes to use for the inspection report.
29
+ */
30
+ vehicleType: VehicleType | null;
31
+ /**
32
+ * The position of the steering wheel.
33
+ */
34
+ steeringWheel: SteeringWheelPosition | null;
35
+ /**
36
+ * Getter function used to get the current Sights based on the current VehicleType, SteeringWheel position etc.
37
+ */
38
+ getCurrentSights: () => Sight[];
39
+ /**
40
+ * Setter function used to set the current auth token.
41
+ */
42
+ setAuthToken: (value: string | null) => void;
43
+ /**
44
+ * Setter function used to set the current inspection ID.
45
+ */
46
+ setInspectionId: (value: string | null) => void;
47
+ /**
48
+ * Setter function used to set the current vehicle type.
49
+ */
50
+ setVehicleType: (value: VehicleType | null) => void;
51
+ /**
52
+ * Setter function used to set the current steering wheel position.
53
+ */
54
+ setSteeringWheel: (value: SteeringWheelPosition | null) => void;
55
+ }
56
+ /**
57
+ * React context used to store the current Monk application state.
58
+ *
59
+ * @see MonkAppState
60
+ */
61
+ export declare const MonkAppStateContext: import("react").Context<MonkAppState | null>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MonkAppStateContext = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * React context used to store the current Monk application state.
7
+ *
8
+ * @see MonkAppState
9
+ */
10
+ exports.MonkAppStateContext = (0, react_1.createContext)(null);
11
+ //# sourceMappingURL=appState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appState.js","sourceRoot":"","sources":["../../src/apps/appState.ts"],"names":[],"mappings":";;;AACA,+BAAsC;AA2DtC;;;;GAIG;AACU,QAAA,mBAAmB,GAAG,IAAA,qBAAa,EAAsB,IAAI,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { CaptureAppConfig } from '@monkvision/types';
2
+ import { PropsWithChildren } from 'react';
3
+ import { MonkAppState } from './appState';
4
+ /**
5
+ * Local storage key used within Monk web applications to store the authentication token.
6
+ */
7
+ export declare const STORAGE_KEY_AUTH_TOKEN = "@monk_authToken";
8
+ /**
9
+ * Props accepted by the MonkAppStateProvider component.
10
+ */
11
+ export type MonkAppStateProviderProps = {
12
+ /**
13
+ * The current configuration of the application.
14
+ */
15
+ config: CaptureAppConfig;
16
+ /**
17
+ * Callback called when an authentication token has successfully been fetched from either the local storage, or the
18
+ * URL search params.
19
+ */
20
+ onFetchAuthToken?: () => void;
21
+ /**
22
+ * Callback called when the language of the app must be updated because it has been specified in the URL params.
23
+ */
24
+ onFetchLanguage?: (lang: string) => void;
25
+ };
26
+ /**
27
+ * A React context provider that declares the state for the common parameters used by Monk applications. The parameters
28
+ * are described in the `MonkAppState` interface. Using options available in the App config (`config` prop), this
29
+ * component can also fetch initial values for these params directly from the URL search params and the web local
30
+ * storage.
31
+ *
32
+ * @see MonkAppState
33
+ * @see MonkAppStateProviderProps
34
+ */
35
+ export declare function MonkAppStateProvider({ config, onFetchAuthToken, onFetchLanguage, children, }: PropsWithChildren<MonkAppStateProviderProps>): JSX.Element;
36
+ /**
37
+ * Options accepted by the `useMonkAppState` hook.
38
+ */
39
+ export interface UseMonkAppStateOptions {
40
+ /**
41
+ * Boolean indicating if the `authToken` and the `inspectionId` params are required. If this value is set to `true`,
42
+ * the hook will return non-null values (even in TypeScript typings) values for the `authToken` and the `inspectionId`
43
+ * params, at the cost of throwing an error if either one of these param is `null`.
44
+ */
45
+ requireInspection?: boolean;
46
+ }
47
+ /**
48
+ * Custom hook used to get the current Monk application state (described in the `MonkAppState` interface) for the
49
+ * current `MonkAppStateContext`. This hook must be called within a child of the `MonkAppStateProvider` component.
50
+ *
51
+ * @see MonkAppState
52
+ * @see MonkAppStateContext
53
+ * @see MonkAppStateProvider
54
+ */
55
+ export declare function useMonkAppState(): MonkAppState;
56
+ export declare function useMonkAppState(o: {
57
+ requireInspection: false | undefined;
58
+ }): MonkAppState;
59
+ export declare function useMonkAppState(o: {
60
+ requireInspection: true;
61
+ }): MonkAppState & {
62
+ authToken: string;
63
+ inspectionId: string;
64
+ };