@oneblink/apps-react 4.1.0-beta.7 → 4.1.0-beta.8

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 (177) hide show
  1. package/README.md +2 -8
  2. package/dist/OneBlinkAutoSaveForm.d.ts +25 -5
  3. package/dist/OneBlinkAutoSaveForm.js +12 -0
  4. package/dist/OneBlinkAutoSaveForm.js.map +1 -1
  5. package/dist/OneBlinkForm.d.ts +558 -8
  6. package/dist/OneBlinkForm.js +546 -0
  7. package/dist/OneBlinkForm.js.map +1 -1
  8. package/dist/OneBlinkFormBase.d.ts +53 -8
  9. package/dist/OneBlinkFormBase.js +49 -25
  10. package/dist/OneBlinkFormBase.js.map +1 -1
  11. package/dist/OneBlinkReadOnlyForm.d.ts +83 -6
  12. package/dist/OneBlinkReadOnlyForm.js +80 -1
  13. package/dist/OneBlinkReadOnlyForm.js.map +1 -1
  14. package/dist/PaymentReceipt.d.ts +59 -0
  15. package/dist/PaymentReceipt.js +61 -6
  16. package/dist/PaymentReceipt.js.map +1 -1
  17. package/dist/components/formStore/FormStoreTableProvider.js +23 -1
  18. package/dist/components/formStore/FormStoreTableProvider.js.map +1 -1
  19. package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.d.ts +5 -0
  20. package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js +5 -0
  21. package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js.map +1 -1
  22. package/dist/components/formStore/OneBlinkFormStoreColumnsButton.d.ts +5 -0
  23. package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js +5 -0
  24. package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js.map +1 -1
  25. package/dist/components/formStore/OneBlinkFormStoreDownloadButton.d.ts +5 -0
  26. package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js +5 -0
  27. package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js.map +1 -1
  28. package/dist/components/formStore/OneBlinkFormStoreProvider.d.ts +5 -0
  29. package/dist/components/formStore/OneBlinkFormStoreProvider.js +5 -0
  30. package/dist/components/formStore/OneBlinkFormStoreProvider.js.map +1 -1
  31. package/dist/components/formStore/OneBlinkFormStoreRefreshButton.d.ts +5 -0
  32. package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js +5 -0
  33. package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js.map +1 -1
  34. package/dist/components/formStore/OneBlinkFormStoreTable.d.ts +4 -0
  35. package/dist/components/formStore/OneBlinkFormStoreTable.js +4 -0
  36. package/dist/components/formStore/OneBlinkFormStoreTable.js.map +1 -1
  37. package/dist/components/formStore/table/ColumnFilters.js.map +1 -1
  38. package/dist/components/pickers/V4CompatibleDatePicker.d.ts +5 -0
  39. package/dist/components/pickers/V4CompatibleDatePicker.js +5 -0
  40. package/dist/components/pickers/V4CompatibleDatePicker.js.map +1 -1
  41. package/dist/components/pickers/V4CompatibleDateTimePicker.d.ts +5 -0
  42. package/dist/components/pickers/V4CompatibleDateTimePicker.js +5 -0
  43. package/dist/components/pickers/V4CompatibleDateTimePicker.js.map +1 -1
  44. package/dist/components/pickers/V4CompatibleTimePicker.d.ts +5 -0
  45. package/dist/components/pickers/V4CompatibleTimePicker.js +5 -0
  46. package/dist/components/pickers/V4CompatibleTimePicker.js.map +1 -1
  47. package/dist/components/renderer/LookupButton.d.ts +3 -1
  48. package/dist/components/renderer/LookupButton.js +7 -5
  49. package/dist/components/renderer/LookupButton.js.map +1 -1
  50. package/dist/components/renderer/LookupNotification.js +60 -15
  51. package/dist/components/renderer/LookupNotification.js.map +1 -1
  52. package/dist/components/renderer/OneBlinkFormElements.d.ts +3 -3
  53. package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
  54. package/dist/components/renderer/PageFormElements.d.ts +3 -3
  55. package/dist/components/renderer/PageFormElements.js.map +1 -1
  56. package/dist/components/renderer/ProgressBar.d.ts +7 -3
  57. package/dist/components/renderer/ProgressBar.js +5 -0
  58. package/dist/components/renderer/ProgressBar.js.map +1 -1
  59. package/dist/form-elements/FormElementABN.js +1 -1
  60. package/dist/form-elements/FormElementABN.js.map +1 -1
  61. package/dist/form-elements/FormElementBSB.js +1 -1
  62. package/dist/form-elements/FormElementBSB.js.map +1 -1
  63. package/dist/form-elements/FormElementBarcodeScanner.js +3 -3
  64. package/dist/form-elements/FormElementBarcodeScanner.js.map +1 -1
  65. package/dist/form-elements/FormElementCalculation.js.map +1 -1
  66. package/dist/form-elements/FormElementCheckBoxes.js +1 -1
  67. package/dist/form-elements/FormElementCheckBoxes.js.map +1 -1
  68. package/dist/form-elements/FormElementDate.js +1 -1
  69. package/dist/form-elements/FormElementDate.js.map +1 -1
  70. package/dist/form-elements/FormElementDateTime.js +1 -1
  71. package/dist/form-elements/FormElementDateTime.js.map +1 -1
  72. package/dist/form-elements/FormElementEmail.js +1 -1
  73. package/dist/form-elements/FormElementEmail.js.map +1 -1
  74. package/dist/form-elements/FormElementForm.d.ts +4 -4
  75. package/dist/form-elements/FormElementForm.js.map +1 -1
  76. package/dist/form-elements/FormElementNumber.js +1 -1
  77. package/dist/form-elements/FormElementNumber.js.map +1 -1
  78. package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
  79. package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
  80. package/dist/form-elements/FormElementSelect.js +1 -1
  81. package/dist/form-elements/FormElementSelect.js.map +1 -1
  82. package/dist/form-elements/FormElementSummary.js.map +1 -1
  83. package/dist/form-elements/FormElementTelephone.js +1 -1
  84. package/dist/form-elements/FormElementTelephone.js.map +1 -1
  85. package/dist/form-elements/FormElementText.js +1 -1
  86. package/dist/form-elements/FormElementText.js.map +1 -1
  87. package/dist/form-elements/FormElementTextarea.js +1 -1
  88. package/dist/form-elements/FormElementTextarea.js.map +1 -1
  89. package/dist/form-elements/FormElementTime.js +1 -1
  90. package/dist/form-elements/FormElementTime.js.map +1 -1
  91. package/dist/hooks/useAuth.d.ts +81 -6
  92. package/dist/hooks/useAuth.js +54 -0
  93. package/dist/hooks/useAuth.js.map +1 -1
  94. package/dist/hooks/useBooleanState.d.ts +42 -5
  95. package/dist/hooks/useBooleanState.js +36 -0
  96. package/dist/hooks/useBooleanState.js.map +1 -1
  97. package/dist/hooks/useClickOutsideElement.d.ts +40 -0
  98. package/dist/hooks/useClickOutsideElement.js +40 -0
  99. package/dist/hooks/useClickOutsideElement.js.map +1 -1
  100. package/dist/hooks/useConditionalLogic.d.ts +2 -3
  101. package/dist/hooks/useConditionalLogic.js.map +1 -1
  102. package/dist/hooks/useDrafts.d.ts +82 -0
  103. package/dist/hooks/useDrafts.js +204 -0
  104. package/dist/hooks/useDrafts.js.map +1 -0
  105. package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +18 -5
  106. package/dist/hooks/useFormSubmissionAutoSaveState.js +10 -0
  107. package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
  108. package/dist/hooks/useFormSubmissionModelContext.d.ts +4 -4
  109. package/dist/hooks/useFormSubmissionModelContext.js.map +1 -1
  110. package/dist/hooks/useFormSubmissionState.d.ts +45 -5
  111. package/dist/hooks/useFormSubmissionState.js +37 -0
  112. package/dist/hooks/useFormSubmissionState.js.map +1 -1
  113. package/dist/hooks/useFormValidation.d.ts +3 -3
  114. package/dist/hooks/useFormValidation.js.map +1 -1
  115. package/dist/hooks/useInjectPages.d.ts +2 -3
  116. package/dist/hooks/useInjectPages.js.map +1 -1
  117. package/dist/hooks/useIsMounted.d.ts +20 -0
  118. package/dist/hooks/useIsMounted.js +19 -0
  119. package/dist/hooks/useIsMounted.js.map +1 -1
  120. package/dist/hooks/useIsOffline.d.ts +54 -0
  121. package/dist/hooks/useIsOffline.js +54 -0
  122. package/dist/hooks/useIsOffline.js.map +1 -1
  123. package/dist/hooks/useLoadDataState.d.ts +46 -3
  124. package/dist/hooks/useLoadDataState.js +41 -0
  125. package/dist/hooks/useLoadDataState.js.map +1 -1
  126. package/dist/hooks/useLogin.d.ts +400 -13
  127. package/dist/hooks/useLogin.js +300 -0
  128. package/dist/hooks/useLogin.js.map +1 -1
  129. package/dist/hooks/useLookupNotification.d.ts +11 -4
  130. package/dist/hooks/useLookupNotification.js +42 -3
  131. package/dist/hooks/useLookupNotification.js.map +1 -1
  132. package/dist/hooks/useLookups.d.ts +3 -3
  133. package/dist/hooks/useLookups.js.map +1 -1
  134. package/dist/hooks/useNullableState.d.ts +46 -1
  135. package/dist/hooks/useNullableState.js +42 -1
  136. package/dist/hooks/useNullableState.js.map +1 -1
  137. package/dist/hooks/usePendingSubmissions.d.ts +103 -0
  138. package/dist/hooks/usePendingSubmissions.js +195 -0
  139. package/dist/hooks/usePendingSubmissions.js.map +1 -0
  140. package/dist/hooks/useReplaceableText.js +2 -1
  141. package/dist/hooks/useReplaceableText.js.map +1 -1
  142. package/dist/hooks/useSignUp.d.ts +5 -0
  143. package/dist/hooks/useSignUp.js +5 -0
  144. package/dist/hooks/useSignUp.js.map +1 -1
  145. package/dist/index.d.ts +7 -4
  146. package/dist/index.js +5 -2
  147. package/dist/index.js.map +1 -1
  148. package/dist/services/checkBsbsAreInvalid.d.ts +2 -3
  149. package/dist/services/checkBsbsAreInvalid.js.map +1 -1
  150. package/dist/services/checkIfAttachmentsExist.d.ts +2 -3
  151. package/dist/services/checkIfAttachmentsExist.js.map +1 -1
  152. package/dist/services/checkIfBsbsAreValidating.d.ts +2 -3
  153. package/dist/services/checkIfBsbsAreValidating.js.map +1 -1
  154. package/dist/services/cleanFormSubmissionModel.d.ts +4 -4
  155. package/dist/services/cleanFormSubmissionModel.js +2 -1
  156. package/dist/services/cleanFormSubmissionModel.js.map +1 -1
  157. package/dist/services/form-validation.d.ts +3 -3
  158. package/dist/services/form-validation.js.map +1 -1
  159. package/dist/services/generate-default-data.d.ts +2 -3
  160. package/dist/services/generate-default-data.js +3 -1
  161. package/dist/services/generate-default-data.js.map +1 -1
  162. package/dist/services/generateFreshdeskDependentFieldElements.js.map +1 -1
  163. package/dist/services/getDateRangeConfiguration.d.ts +2 -3
  164. package/dist/services/getDateRangeConfiguration.js.map +1 -1
  165. package/dist/services/getRepeatableSetEntriesConfiguration.d.ts +2 -3
  166. package/dist/services/getRepeatableSetEntriesConfiguration.js.map +1 -1
  167. package/dist/styles/receipt.scss +1 -1
  168. package/dist/styles/repeatable-set.scss +2 -2
  169. package/dist/typedoc.d.ts +2 -0
  170. package/dist/typedoc.js +3 -0
  171. package/dist/typedoc.js.map +1 -0
  172. package/dist/types/form.d.ts +5 -6
  173. package/dist/types/form.js.map +1 -1
  174. package/package.json +10 -4
  175. package/dist/services/determineIsInfoPage.d.ts +0 -2
  176. package/dist/services/determineIsInfoPage.js +0 -17
  177. package/dist/services/determineIsInfoPage.js.map +0 -1
@@ -1,6 +1,60 @@
1
1
  import * as React from 'react';
2
+ /**
3
+ * @param type
4
+ * @param listener
5
+ * @group Hooks
6
+ */
2
7
  export declare const useNetworkChangeEffect: (type: 'online' | 'offline', listener: () => unknown) => void;
8
+ /**
9
+ * IsOfflineContextProvider is a React Component that provides the `isOffline`
10
+ * state for components further down your component tree to consume. It should
11
+ * be used to wrap the components requiring the state.
12
+ *
13
+ * - **This component is required in your component tree to be able to consume the
14
+ * [`useIsOffline`](./useIsOffline.html) hook.**
15
+ *
16
+ * ### Usage
17
+ *
18
+ * ```jsx
19
+ * import { IsOfflineContextProvider } from '@oneblink/apps-react'
20
+ *
21
+ * const TopLevelComponent = () => {
22
+ * return (
23
+ * <IsOfflineContextProvider>
24
+ * <div>
25
+ * <ComponentThatRequiresOfflineState />
26
+ * </div>
27
+ * </IsOfflineContextProvider>
28
+ * )
29
+ * }
30
+ *
31
+ * export default TopLevelComponent
32
+ * ```
33
+ *
34
+ * @param props
35
+ * @returns
36
+ * @group Components
37
+ */
3
38
  export declare function IsOfflineContextProvider({ children, }: {
4
39
  children: React.ReactNode;
5
40
  }): JSX.Element;
41
+ /**
42
+ * This function is a react hook for determining whether an application is in an
43
+ * offline state.
44
+ *
45
+ * - **This component requires
46
+ * [`<IsOfflineContextProvider/>`](./IsOfflineContextProvider.html) to be
47
+ * present in your component tree.**
48
+ *
49
+ * ## Example
50
+ *
51
+ * ```js
52
+ * import { useIsOffline } from '@oneblink/apps-react'
53
+ *
54
+ * const isOffline = useIsOffline()
55
+ * ```
56
+ *
57
+ * @returns
58
+ * @group Hooks
59
+ */
6
60
  export default function useIsOffline(): boolean;
@@ -3,6 +3,11 @@ import { offlineService } from '@oneblink/apps';
3
3
  import useBooleanState from '../hooks/useBooleanState';
4
4
  const defaultValue = offlineService.isOffline();
5
5
  const IsOfflineContext = React.createContext(defaultValue);
6
+ /**
7
+ * @param type
8
+ * @param listener
9
+ * @group Hooks
10
+ */
6
11
  export const useNetworkChangeEffect = (type, listener) => {
7
12
  React.useEffect(() => {
8
13
  // Stupid cordova seems to require that offline/online
@@ -15,12 +20,61 @@ export const useNetworkChangeEffect = (type, listener) => {
15
20
  };
16
21
  }, [type, listener]);
17
22
  };
23
+ /**
24
+ * IsOfflineContextProvider is a React Component that provides the `isOffline`
25
+ * state for components further down your component tree to consume. It should
26
+ * be used to wrap the components requiring the state.
27
+ *
28
+ * - **This component is required in your component tree to be able to consume the
29
+ * [`useIsOffline`](./useIsOffline.html) hook.**
30
+ *
31
+ * ### Usage
32
+ *
33
+ * ```jsx
34
+ * import { IsOfflineContextProvider } from '@oneblink/apps-react'
35
+ *
36
+ * const TopLevelComponent = () => {
37
+ * return (
38
+ * <IsOfflineContextProvider>
39
+ * <div>
40
+ * <ComponentThatRequiresOfflineState />
41
+ * </div>
42
+ * </IsOfflineContextProvider>
43
+ * )
44
+ * }
45
+ *
46
+ * export default TopLevelComponent
47
+ * ```
48
+ *
49
+ * @param props
50
+ * @returns
51
+ * @group Components
52
+ */
18
53
  export function IsOfflineContextProvider({ children, }) {
19
54
  const [isOffline, goOffline, goOnline] = useBooleanState(defaultValue);
20
55
  useNetworkChangeEffect('online', goOnline);
21
56
  useNetworkChangeEffect('offline', goOffline);
22
57
  return (React.createElement(IsOfflineContext.Provider, { value: isOffline }, children));
23
58
  }
59
+ /**
60
+ * This function is a react hook for determining whether an application is in an
61
+ * offline state.
62
+ *
63
+ * - **This component requires
64
+ * [`<IsOfflineContextProvider/>`](./IsOfflineContextProvider.html) to be
65
+ * present in your component tree.**
66
+ *
67
+ * ## Example
68
+ *
69
+ * ```js
70
+ * import { useIsOffline } from '@oneblink/apps-react'
71
+ *
72
+ * const isOffline = useIsOffline()
73
+ * ```
74
+ *
75
+ * @returns
76
+ * @group Hooks
77
+ */
24
78
  export default function useIsOffline() {
25
79
  return React.useContext(IsOfflineContext);
26
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useIsOffline.js","sourceRoot":"","sources":["../../src/hooks/useIsOffline.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,eAAe,MAAM,0BAA0B,CAAA;AAEtD,MAAM,YAAY,GAAG,cAAc,CAAC,SAAS,EAAE,CAAA;AAE/C,MAAM,gBAAgB,GAAG,KAAK,CAAC,aAAa,CAAU,YAAY,CAAC,CAAA;AAEnE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,IAA0B,EAC1B,QAAuB,EACvB,EAAE;IACF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,sDAAsD;QACtD,sDAAsD;QACtD,qBAAqB;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAA;QAClD,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAExC,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAC7C,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,GAGT;IACC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,eAAe,CAAC,YAAY,CAAC,CAAA;IAEtE,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC1C,sBAAsB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAE5C,OAAO,CACL,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IACxC,QAAQ,CACiB,CAC7B,CAAA;AACH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,OAAO,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["import * as React from 'react'\n\nimport { offlineService } from '@oneblink/apps'\nimport useBooleanState from '../hooks/useBooleanState'\n\nconst defaultValue = offlineService.isOffline()\n\nconst IsOfflineContext = React.createContext<boolean>(defaultValue)\n\nexport const useNetworkChangeEffect = (\n type: 'online' | 'offline',\n listener: () => unknown,\n) => {\n React.useEffect(() => {\n // Stupid cordova seems to require that offline/online\n // listeners are set on the document and browsers seem\n // to require window.\n const element = window.cordova ? document : window\n element.addEventListener(type, listener)\n\n return () => {\n element.removeEventListener(type, listener)\n }\n }, [type, listener])\n}\n\nexport function IsOfflineContextProvider({\n children,\n}: {\n children: React.ReactNode\n}) {\n const [isOffline, goOffline, goOnline] = useBooleanState(defaultValue)\n\n useNetworkChangeEffect('online', goOnline)\n useNetworkChangeEffect('offline', goOffline)\n\n return (\n <IsOfflineContext.Provider value={isOffline}>\n {children}\n </IsOfflineContext.Provider>\n )\n}\n\nexport default function useIsOffline() {\n return React.useContext(IsOfflineContext)\n}\n"]}
1
+ {"version":3,"file":"useIsOffline.js","sourceRoot":"","sources":["../../src/hooks/useIsOffline.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,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CAAC","sourcesContent":["import * as React from 'react'\n\nimport { offlineService } from '@oneblink/apps'\nimport useBooleanState from '../hooks/useBooleanState'\n\nconst defaultValue = offlineService.isOffline()\n\nconst IsOfflineContext = React.createContext<boolean>(defaultValue)\n\n/**\n * @param type\n * @param listener\n * @group Hooks\n */\nexport const useNetworkChangeEffect = (\n type: 'online' | 'offline',\n listener: () => unknown,\n) => {\n React.useEffect(() => {\n // Stupid cordova seems to require that offline/online\n // listeners are set on the document and browsers seem\n // to require window.\n const element = window.cordova ? document : window\n element.addEventListener(type, listener)\n\n return () => {\n element.removeEventListener(type, listener)\n }\n }, [type, listener])\n}\n\n/**\n * IsOfflineContextProvider is a React Component that provides the `isOffline`\n * state for components further down your component tree to consume. It should\n * be used to wrap the components requiring the state.\n *\n * - **This component is required in your component tree to be able to consume the\n * [`useIsOffline`](./useIsOffline.html) hook.**\n *\n * ### Usage\n *\n * ```jsx\n * import { IsOfflineContextProvider } from '@oneblink/apps-react'\n *\n * const TopLevelComponent = () => {\n * return (\n * <IsOfflineContextProvider>\n * <div>\n * <ComponentThatRequiresOfflineState />\n * </div>\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * export default TopLevelComponent\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function IsOfflineContextProvider({\n children,\n}: {\n children: React.ReactNode\n}) {\n const [isOffline, goOffline, goOnline] = useBooleanState(defaultValue)\n\n useNetworkChangeEffect('online', goOnline)\n useNetworkChangeEffect('offline', goOffline)\n\n return (\n <IsOfflineContext.Provider value={isOffline}>\n {children}\n </IsOfflineContext.Provider>\n )\n}\n\n/**\n * This function is a react hook for determining whether an application is in an\n * offline state.\n *\n * - **This component requires\n * [`<IsOfflineContextProvider/>`](./IsOfflineContextProvider.html) to be\n * present in your component tree.**\n *\n * ## Example\n *\n * ```js\n * import { useIsOffline } from '@oneblink/apps-react'\n *\n * const isOffline = useIsOffline()\n * ```\n *\n * @returns\n * @group Hooks\n */\nexport default function useIsOffline() {\n return React.useContext(IsOfflineContext)\n}\n"]}
@@ -1,15 +1,58 @@
1
1
  import * as React from 'react';
2
2
  export type LoadDataState<T> = {
3
3
  status: 'SUCCESS';
4
+ /** Your data. */
4
5
  result: T;
5
6
  } | {
6
7
  status: 'ERROR';
8
+ /** A JavaScript `Error` object. */
7
9
  error: Error;
8
10
  } | {
9
11
  status: 'LOADING';
10
12
  };
13
+ /**
14
+ * This function is a react hook for managing the state involved with loading
15
+ * data.
16
+ *
17
+ * ## Example
18
+ *
19
+ * ```js
20
+ * import { useLoadDataState } from '@oneblink/apps-react'
21
+ * const fetchData = async () => {
22
+ * const response = await fetch(`https://some-website.com/api?data=data`)
23
+ *
24
+ * if (!response.ok) {
25
+ * const text = await response.text()
26
+ * throw new Error(text)
27
+ * }
28
+ *
29
+ * return await response.json()
30
+ * }
31
+ *
32
+ * const MyComponent = () => {
33
+ * const [state, refresh, setResult] = useLoadDataState(fetchData)
34
+ *
35
+ * switch (state.status) {
36
+ * case 'LOADING':
37
+ * return <Loading />
38
+ * case 'ERROR':
39
+ * return <Error message={state.error} />
40
+ * case 'SUCCESS':
41
+ * // RENDER UI
42
+ * }
43
+ * }
44
+ *
45
+ * export default MyComponent
46
+ * ```
47
+ *
48
+ * @typeParam T The type of the data returned by your `onLoad` function
49
+ * @param onLoad The function that fetches your data. Should be a Promise that
50
+ * returns your data
51
+ * @returns
52
+ * @group Hooks
53
+ */
11
54
  export default function useLoadDataState<T>(onLoad: (abortSignal?: AbortSignal) => Promise<T>): [
12
- LoadDataState<T>,
13
- (abortSignal?: AbortSignal) => void,
14
- React.Dispatch<React.SetStateAction<T>>
55
+ state: LoadDataState<T>,
56
+ handleLoad: (abortSignal?: AbortSignal) => void,
57
+ setResult: React.Dispatch<React.SetStateAction<T>>
15
58
  ];
@@ -1,5 +1,46 @@
1
1
  import * as React from 'react';
2
2
  import useIsMounted from './useIsMounted';
3
+ /**
4
+ * This function is a react hook for managing the state involved with loading
5
+ * data.
6
+ *
7
+ * ## Example
8
+ *
9
+ * ```js
10
+ * import { useLoadDataState } from '@oneblink/apps-react'
11
+ * const fetchData = async () => {
12
+ * const response = await fetch(`https://some-website.com/api?data=data`)
13
+ *
14
+ * if (!response.ok) {
15
+ * const text = await response.text()
16
+ * throw new Error(text)
17
+ * }
18
+ *
19
+ * return await response.json()
20
+ * }
21
+ *
22
+ * const MyComponent = () => {
23
+ * const [state, refresh, setResult] = useLoadDataState(fetchData)
24
+ *
25
+ * switch (state.status) {
26
+ * case 'LOADING':
27
+ * return <Loading />
28
+ * case 'ERROR':
29
+ * return <Error message={state.error} />
30
+ * case 'SUCCESS':
31
+ * // RENDER UI
32
+ * }
33
+ * }
34
+ *
35
+ * export default MyComponent
36
+ * ```
37
+ *
38
+ * @typeParam T The type of the data returned by your `onLoad` function
39
+ * @param onLoad The function that fetches your data. Should be a Promise that
40
+ * returns your data
41
+ * @returns
42
+ * @group Hooks
43
+ */
3
44
  export default function useLoadDataState(onLoad) {
4
45
  const isMounted = useIsMounted();
5
46
  const [state, setState] = React.useState({
@@ -1 +1 @@
1
- {"version":3,"file":"useLoadDataState.js","sourceRoot":"","sources":["../../src/hooks/useLoadDataState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAezC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,MAAiD;IAMjD,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAmB;QACzD,MAAM,EAAE,SAAS;KAClB,CAAC,CAAA;IAEF,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAClC,KAAK,EAAE,WAAyB,EAAE,EAAE;QAClC,QAAQ,CAAC;YACP,MAAM,EAAE,SAAS;SAClB,CAAC,CAAA;QACF,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAA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AS,CAAC,CAAA;AACvC,CAAC","sourcesContent":["import * as React from 'react'\nimport useIsMounted from './useIsMounted'\n\nexport type LoadDataState<T> =\n | {\n status: 'SUCCESS'\n result: T\n }\n | {\n status: 'ERROR'\n error: Error\n }\n | {\n status: 'LOADING'\n }\n\nexport default function useLoadDataState<T>(\n onLoad: (abortSignal?: AbortSignal) => Promise<T>,\n): [\n LoadDataState<T>,\n (abortSignal?: AbortSignal) => void,\n React.Dispatch<React.SetStateAction<T>>,\n] {\n const isMounted = useIsMounted()\n const [state, setState] = React.useState<LoadDataState<T>>({\n status: 'LOADING',\n })\n\n const handleLoad = React.useCallback(\n async (abortSignal?: AbortSignal) => {\n setState({\n status: 'LOADING',\n })\n try {\n const result = await onLoad(abortSignal)\n if (isMounted.current && !abortSignal?.aborted) {\n setState({\n status: 'SUCCESS',\n result,\n })\n }\n } catch (err) {\n if (isMounted.current && !abortSignal?.aborted) {\n setState({\n status: 'ERROR',\n error: err as Error,\n })\n }\n }\n },\n [isMounted, onLoad],\n )\n\n const setResult: React.Dispatch<React.SetStateAction<T>> = React.useCallback(\n (setter) => {\n setState((currentState: LoadDataState<T>) => {\n if (currentState.status === 'SUCCESS') {\n return {\n ...currentState,\n result:\n typeof setter === 'function'\n ? // @ts-expect-error Typescript cannot tell between a generic type (T) and a function\n setter(currentState.result)\n : setter,\n }\n } else {\n return currentState\n }\n })\n },\n [],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n handleLoad(abortController.signal)\n return () => {\n abortController.abort()\n }\n }, [handleLoad])\n\n return [state, handleLoad, setResult]\n}\n"]}
1
+ {"version":3,"file":"useLoadDataState.js","sourceRoot":"","sources":["../../src/hooks/useLoadDataState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAiBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,OAAO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AM;gBACL,OAAO,YAAY,CAAA;aACpB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EACD,EAAE,CACH,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAClC,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,KAAK,EAAE,CAAA;QACzB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AACvC,CAAC","sourcesContent":["import * as React from 'react'\nimport useIsMounted from './useIsMounted'\n\nexport type LoadDataState<T> =\n | {\n status: 'SUCCESS'\n /** Your data. */\n result: T\n }\n | {\n status: 'ERROR'\n /** A JavaScript `Error` object. */\n error: Error\n }\n | {\n status: 'LOADING'\n }\n\n/**\n * This function is a react hook for managing the state involved with loading\n * data.\n *\n * ## Example\n *\n * ```js\n * import { useLoadDataState } from '@oneblink/apps-react'\n * const fetchData = async () => {\n * const response = await fetch(`https://some-website.com/api?data=data`)\n *\n * if (!response.ok) {\n * const text = await response.text()\n * throw new Error(text)\n * }\n *\n * return await response.json()\n * }\n *\n * const MyComponent = () => {\n * const [state, refresh, setResult] = useLoadDataState(fetchData)\n *\n * switch (state.status) {\n * case 'LOADING':\n * return <Loading />\n * case 'ERROR':\n * return <Error message={state.error} />\n * case 'SUCCESS':\n * // RENDER UI\n * }\n * }\n *\n * export default MyComponent\n * ```\n *\n * @typeParam T The type of the data returned by your `onLoad` function\n * @param onLoad The function that fetches your data. Should be a Promise that\n * returns your data\n * @returns\n * @group Hooks\n */\nexport default function useLoadDataState<T>(\n onLoad: (abortSignal?: AbortSignal) => Promise<T>,\n): [\n state: LoadDataState<T>,\n handleLoad: (abortSignal?: AbortSignal) => void,\n setResult: React.Dispatch<React.SetStateAction<T>>,\n] {\n const isMounted = useIsMounted()\n const [state, setState] = React.useState<LoadDataState<T>>({\n status: 'LOADING',\n })\n\n const handleLoad = React.useCallback(\n async (abortSignal?: AbortSignal) => {\n setState({\n status: 'LOADING',\n })\n try {\n const result = await onLoad(abortSignal)\n if (isMounted.current && !abortSignal?.aborted) {\n setState({\n status: 'SUCCESS',\n result,\n })\n }\n } catch (err) {\n if (isMounted.current && !abortSignal?.aborted) {\n setState({\n status: 'ERROR',\n error: err as Error,\n })\n }\n }\n },\n [isMounted, onLoad],\n )\n\n const setResult: React.Dispatch<React.SetStateAction<T>> = React.useCallback(\n (setter) => {\n setState((currentState: LoadDataState<T>) => {\n if (currentState.status === 'SUCCESS') {\n return {\n ...currentState,\n result:\n typeof setter === 'function'\n ? // @ts-expect-error Typescript cannot tell between a generic type (T) and a function\n setter(currentState.result)\n : setter,\n }\n } else {\n return currentState\n }\n })\n },\n [],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n handleLoad(abortController.signal)\n return () => {\n abortController.abort()\n }\n }, [handleLoad])\n\n return [state, handleLoad, setResult]\n}\n"]}