dce-reactkit 3.0.0 → 3.0.3

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 (166) hide show
  1. package/README.md +1 -546
  2. package/dist/cjs/index.js +1826 -0
  3. package/dist/cjs/index.js.map +1 -0
  4. package/{lib/esm → dist/cjs}/types/components/AppWrapper.d.ts +29 -4
  5. package/dist/cjs/types/components/ButtonInputGroup.d.ts +12 -0
  6. package/dist/cjs/types/components/CheckboxButton.d.ts +20 -0
  7. package/dist/cjs/types/components/Drawer.d.ts +10 -0
  8. package/{lib/cjs/lib → dist/cjs/types}/components/ErrorBox.d.ts +0 -0
  9. package/{lib/cjs/lib → dist/cjs/types}/components/LoadingSpinner.d.ts +0 -0
  10. package/{lib/cjs/lib → dist/cjs/types}/components/Modal.d.ts +0 -0
  11. package/dist/cjs/types/components/RadioButton.d.ts +20 -0
  12. package/dist/cjs/types/components/SimpleDateChooser.d.ts +22 -0
  13. package/{lib/esm/lib → dist/cjs/types}/components/TabBox.d.ts +1 -0
  14. package/{lib/cjs/lib → dist/cjs/types}/errors/ErrorWithCode.d.ts +0 -0
  15. package/{lib/cjs/lib → dist/cjs/types}/helpers/abbreviate.d.ts +0 -0
  16. package/{lib/cjs/lib → dist/cjs/types}/helpers/avg.d.ts +0 -0
  17. package/{lib/cjs/lib → dist/cjs/types}/helpers/ceilToNumDecimals.d.ts +0 -0
  18. package/{lib/cjs/lib → dist/cjs/types}/helpers/floorToNumDecimals.d.ts +0 -0
  19. package/{lib/cjs/lib → dist/cjs/types}/helpers/forceNumIntoBounds.d.ts +0 -0
  20. package/dist/cjs/types/helpers/genRouteHandler.d.ts +32 -0
  21. package/dist/cjs/types/helpers/getOrdinal.d.ts +8 -0
  22. package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +17 -0
  23. package/{lib/cjs/lib → dist/cjs/types}/helpers/handleError.d.ts +5 -1
  24. package/{lib/cjs/lib → dist/cjs/types}/helpers/handleSuccess.d.ts +0 -0
  25. package/{lib/cjs/lib → dist/cjs/types}/helpers/padDecimalZeros.d.ts +0 -0
  26. package/{lib/cjs/lib → dist/cjs/types}/helpers/padZerosLeft.d.ts +0 -0
  27. package/{lib/cjs/lib → dist/cjs/types}/helpers/roundToNumDecimals.d.ts +0 -0
  28. package/{lib/cjs/lib → dist/cjs/types}/helpers/sum.d.ts +0 -0
  29. package/{lib/cjs/lib → dist/cjs/types}/helpers/visitServerEndpoint.d.ts +0 -0
  30. package/{lib/cjs/lib → dist/cjs/types}/helpers/waitMs.d.ts +0 -0
  31. package/{lib/cjs/lib → dist/cjs/types}/index.d.ts +14 -6
  32. package/dist/cjs/types/server/initServer.d.ts +21 -0
  33. package/{lib/cjs/lib → dist/cjs/types}/types/ModalButtonType.d.ts +0 -0
  34. package/{lib/cjs/lib → dist/cjs/types}/types/ModalSize.d.ts +0 -0
  35. package/{lib/cjs/lib → dist/cjs/types}/types/ModalType.d.ts +0 -0
  36. package/{lib → dist}/cjs/types/types/ParamType.d.ts +1 -1
  37. package/{lib → dist}/cjs/types/types/ReactKitErrorCode.d.ts +3 -1
  38. package/{lib/cjs/lib → dist/cjs/types}/types/Variant.d.ts +0 -0
  39. package/dist/esm/index.js +1782 -0
  40. package/dist/esm/index.js.map +1 -0
  41. package/{lib/cjs → dist/esm}/types/components/AppWrapper.d.ts +29 -4
  42. package/dist/esm/types/components/ButtonInputGroup.d.ts +12 -0
  43. package/dist/esm/types/components/CheckboxButton.d.ts +20 -0
  44. package/dist/esm/types/components/Drawer.d.ts +10 -0
  45. package/{lib/cjs → dist/esm}/types/components/ErrorBox.d.ts +0 -0
  46. package/{lib/cjs → dist/esm}/types/components/LoadingSpinner.d.ts +0 -0
  47. package/{lib/cjs → dist/esm}/types/components/Modal.d.ts +0 -0
  48. package/dist/esm/types/components/RadioButton.d.ts +20 -0
  49. package/dist/esm/types/components/SimpleDateChooser.d.ts +22 -0
  50. package/{lib/cjs/lib → dist/esm/types}/components/TabBox.d.ts +1 -0
  51. package/{lib/cjs → dist/esm}/types/errors/ErrorWithCode.d.ts +0 -0
  52. package/{lib/cjs → dist/esm}/types/helpers/abbreviate.d.ts +0 -0
  53. package/{lib/cjs → dist/esm}/types/helpers/avg.d.ts +0 -0
  54. package/{lib/cjs → dist/esm}/types/helpers/ceilToNumDecimals.d.ts +0 -0
  55. package/{lib/cjs → dist/esm}/types/helpers/floorToNumDecimals.d.ts +0 -0
  56. package/{lib/cjs → dist/esm}/types/helpers/forceNumIntoBounds.d.ts +0 -0
  57. package/dist/esm/types/helpers/genRouteHandler.d.ts +32 -0
  58. package/dist/esm/types/helpers/getOrdinal.d.ts +8 -0
  59. package/dist/esm/types/helpers/getTimeInfoInET.d.ts +17 -0
  60. package/{lib/cjs → dist/esm}/types/helpers/handleError.d.ts +5 -1
  61. package/{lib/cjs → dist/esm}/types/helpers/handleSuccess.d.ts +0 -0
  62. package/{lib/cjs → dist/esm}/types/helpers/padDecimalZeros.d.ts +0 -0
  63. package/{lib/cjs → dist/esm}/types/helpers/padZerosLeft.d.ts +0 -0
  64. package/{lib/cjs → dist/esm}/types/helpers/roundToNumDecimals.d.ts +0 -0
  65. package/{lib/cjs → dist/esm}/types/helpers/sum.d.ts +0 -0
  66. package/{lib/cjs → dist/esm}/types/helpers/visitServerEndpoint.d.ts +0 -0
  67. package/{lib/cjs → dist/esm}/types/helpers/waitMs.d.ts +0 -0
  68. package/{lib/esm/lib → dist/esm/types}/index.d.ts +14 -6
  69. package/dist/esm/types/server/initServer.d.ts +21 -0
  70. package/{lib/cjs → dist/esm}/types/types/ModalButtonType.d.ts +0 -0
  71. package/{lib/cjs → dist/esm}/types/types/ModalSize.d.ts +0 -0
  72. package/{lib/cjs → dist/esm}/types/types/ModalType.d.ts +0 -0
  73. package/{lib/esm/lib → dist/esm/types}/types/ParamType.d.ts +1 -1
  74. package/{lib/esm/lib → dist/esm/types}/types/ReactKitErrorCode.d.ts +3 -1
  75. package/{lib/cjs → dist/esm}/types/types/Variant.d.ts +0 -0
  76. package/dist/index.d.ts +505 -0
  77. package/package.json +18 -29
  78. package/rollup.config.js +14 -13
  79. package/src/components/AppWrapper.tsx +85 -18
  80. package/src/components/ButtonInputGroup.tsx +89 -0
  81. package/src/components/CheckboxButton.tsx +100 -0
  82. package/src/components/Drawer.tsx +76 -0
  83. package/src/components/ErrorBox.tsx +4 -4
  84. package/src/components/LoadingSpinner.tsx +3 -3
  85. package/src/components/Modal.tsx +214 -97
  86. package/src/components/RadioButton.tsx +102 -0
  87. package/src/components/SimpleDateChooser.tsx +222 -0
  88. package/src/components/TabBox.tsx +65 -58
  89. package/src/helpers/genRouteHandler.ts +329 -0
  90. package/src/helpers/getOrdinal.tsx +13 -0
  91. package/src/helpers/getTimeInfoInET.tsx +56 -0
  92. package/src/helpers/handleError.ts +65 -0
  93. package/src/helpers/handleSuccess.ts +18 -0
  94. package/src/helpers/visitServerEndpoint.tsx +110 -0
  95. package/src/index.ts +29 -0
  96. package/src/server/initServer.ts +53 -0
  97. package/src/types/ParamType.ts +18 -0
  98. package/src/types/ReactKitErrorCode.tsx +3 -1
  99. package/tsconfig.json +9 -7
  100. package/lib/cjs/index.js +0 -2
  101. package/lib/cjs/index.js.map +0 -1
  102. package/lib/cjs/lib/components/AppWrapper.d.ts +0 -35
  103. package/lib/cjs/lib/helpers/parseRequest.d.ts +0 -21
  104. package/lib/cjs/lib/types/ParamType.d.ts +0 -17
  105. package/lib/cjs/lib/types/ReactKitErrorCode.d.ts +0 -13
  106. package/lib/cjs/types/components/TabBox.d.ts +0 -11
  107. package/lib/cjs/types/helpers/alert.d.ts +0 -2
  108. package/lib/cjs/types/helpers/confirm.d.ts +0 -2
  109. package/lib/cjs/types/helpers/parseRequest.d.ts +0 -21
  110. package/lib/cjs/types/helpers/showFatalError.d.ts +0 -2
  111. package/lib/cjs/types/index.d.ts +0 -22
  112. package/lib/esm/index.js +0 -16
  113. package/lib/esm/index.js.map +0 -1
  114. package/lib/esm/lib/components/AppWrapper.d.ts +0 -35
  115. package/lib/esm/lib/components/ErrorBox.d.ts +0 -12
  116. package/lib/esm/lib/components/LoadingSpinner.d.ts +0 -7
  117. package/lib/esm/lib/components/Modal.d.ts +0 -40
  118. package/lib/esm/lib/errors/ErrorWithCode.d.ts +0 -9
  119. package/lib/esm/lib/helpers/abbreviate.d.ts +0 -10
  120. package/lib/esm/lib/helpers/avg.d.ts +0 -8
  121. package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +0 -9
  122. package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +0 -9
  123. package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +0 -10
  124. package/lib/esm/lib/helpers/handleError.d.ts +0 -14
  125. package/lib/esm/lib/helpers/handleSuccess.d.ts +0 -8
  126. package/lib/esm/lib/helpers/padDecimalZeros.d.ts +0 -10
  127. package/lib/esm/lib/helpers/padZerosLeft.d.ts +0 -9
  128. package/lib/esm/lib/helpers/parseRequest.d.ts +0 -21
  129. package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +0 -9
  130. package/lib/esm/lib/helpers/sum.d.ts +0 -8
  131. package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +0 -23
  132. package/lib/esm/lib/helpers/waitMs.d.ts +0 -7
  133. package/lib/esm/lib/types/ModalButtonType.d.ts +0 -17
  134. package/lib/esm/lib/types/ModalSize.d.ts +0 -11
  135. package/lib/esm/lib/types/ModalType.d.ts +0 -16
  136. package/lib/esm/lib/types/Variant.d.ts +0 -15
  137. package/lib/esm/types/components/ErrorBox.d.ts +0 -12
  138. package/lib/esm/types/components/LoadingSpinner.d.ts +0 -7
  139. package/lib/esm/types/components/Modal.d.ts +0 -40
  140. package/lib/esm/types/components/TabBox.d.ts +0 -11
  141. package/lib/esm/types/errors/ErrorWithCode.d.ts +0 -9
  142. package/lib/esm/types/helpers/abbreviate.d.ts +0 -10
  143. package/lib/esm/types/helpers/alert.d.ts +0 -2
  144. package/lib/esm/types/helpers/avg.d.ts +0 -8
  145. package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +0 -9
  146. package/lib/esm/types/helpers/confirm.d.ts +0 -2
  147. package/lib/esm/types/helpers/floorToNumDecimals.d.ts +0 -9
  148. package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +0 -10
  149. package/lib/esm/types/helpers/handleError.d.ts +0 -14
  150. package/lib/esm/types/helpers/handleSuccess.d.ts +0 -8
  151. package/lib/esm/types/helpers/padDecimalZeros.d.ts +0 -10
  152. package/lib/esm/types/helpers/padZerosLeft.d.ts +0 -9
  153. package/lib/esm/types/helpers/parseRequest.d.ts +0 -21
  154. package/lib/esm/types/helpers/roundToNumDecimals.d.ts +0 -9
  155. package/lib/esm/types/helpers/showFatalError.d.ts +0 -2
  156. package/lib/esm/types/helpers/sum.d.ts +0 -8
  157. package/lib/esm/types/helpers/visitServerEndpoint.d.ts +0 -23
  158. package/lib/esm/types/helpers/waitMs.d.ts +0 -7
  159. package/lib/esm/types/index.d.ts +0 -22
  160. package/lib/esm/types/types/ModalButtonType.d.ts +0 -17
  161. package/lib/esm/types/types/ModalSize.d.ts +0 -11
  162. package/lib/esm/types/types/ModalType.d.ts +0 -16
  163. package/lib/esm/types/types/ParamType.d.ts +0 -17
  164. package/lib/esm/types/types/ReactKitErrorCode.d.ts +0 -13
  165. package/lib/esm/types/types/Variant.d.ts +0 -15
  166. package/lib/index.d.ts +0 -274
@@ -0,0 +1,505 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+
4
+ /**
5
+ * A wrapper for the entire React app that adds global functionality like
6
+ * handling for fatal error messages, adds bootstrap support
7
+ * @author Gabe Abrams
8
+ */
9
+
10
+ declare type Props$8 = {
11
+ children: React.ReactNode;
12
+ sendRequest: SendRequestFunction;
13
+ dark?: boolean;
14
+ sessionExpiredMessage?: string;
15
+ };
16
+ declare type SendRequestFunction = (opts: {
17
+ path: string;
18
+ method: ('GET' | 'POST' | 'DELETE' | 'PUT');
19
+ params?: {
20
+ [x: string]: any;
21
+ } | undefined;
22
+ headers?: {
23
+ [x: string]: any;
24
+ } | undefined;
25
+ numRetries?: number | undefined;
26
+ }) => Promise<{
27
+ body: any;
28
+ status: number;
29
+ headers: {
30
+ [x: string]: any;
31
+ };
32
+ }>;
33
+ /**
34
+ * Show an alert modal with an "Okay" button
35
+ * @author Gabe Abrams
36
+ * @param title the title text to display at the top of the alert
37
+ * @param text the text to display in the alert
38
+ */
39
+ declare const alert: (title: string, text: string) => Promise<undefined>;
40
+ /**
41
+ * Show a confirmation modal with an "Okay" and a "Cancel" button
42
+ * @author Gabe Abrams
43
+ * @param title the title text to display at the top of the alert
44
+ * @param text the text to display in the alert
45
+ * @returns true if the user confirmed
46
+ */
47
+ declare const confirm: (title: string, text: string) => Promise<boolean>;
48
+ /**
49
+ * Show a fatal error message
50
+ * @author Gabe Abrams
51
+ * @param error the error to show
52
+ * @param [errorTitle] title of the error box
53
+ */
54
+ declare const showFatalError: (error: any, errorTitle?: string) => undefined;
55
+ declare const AppWrapper: React.FC<Props$8>;
56
+
57
+ /**
58
+ * Loading spinner/indicator
59
+ * @author Gabe Abrams
60
+ */
61
+ declare const LoadingSpinner: () => JSX.Element;
62
+
63
+ /**
64
+ * Displays an error
65
+ * @author Gabe Abrams
66
+ */
67
+
68
+ declare type Props$7 = {
69
+ error: any;
70
+ title?: string;
71
+ onClose?: () => void;
72
+ };
73
+ declare const ErrorBox: React.FC<Props$7>;
74
+
75
+ /**
76
+ * Bootstrap variants
77
+ * @author Gabe Abrams
78
+ */
79
+ declare enum Variant {
80
+ Primary = "primary",
81
+ Secondary = "secondary",
82
+ Success = "success",
83
+ Warning = "warning",
84
+ Info = "info",
85
+ Danger = "danger",
86
+ Light = "light",
87
+ Dark = "dark"
88
+ }
89
+
90
+ /**
91
+ * Types of buttons in the modal
92
+ * @author Gabe Abrams
93
+ */
94
+ declare enum ModalButtonType {
95
+ Okay = "okay",
96
+ Cancel = "cancel",
97
+ Yes = "yes",
98
+ No = "no",
99
+ Abandon = "abandon",
100
+ GoBack = "goBack",
101
+ Continue = "continue",
102
+ ImSure = "imSure",
103
+ Delete = "delete",
104
+ Confirm = "confirm"
105
+ }
106
+
107
+ /**
108
+ * Modal sizes
109
+ * @author Gabe Abrams
110
+ */
111
+ declare enum ModalSize {
112
+ Small = "sm",
113
+ Medium = "md",
114
+ Large = "lg",
115
+ ExtraLarge = "xl"
116
+ }
117
+
118
+ /**
119
+ * Types of modals
120
+ * @author Gabe Abrams
121
+ */
122
+ declare enum ModalType {
123
+ Okay = "okay",
124
+ OkayCancel = "okay-cancel",
125
+ YesNo = "yes-no",
126
+ YesNoCancel = "yes-no-cancel",
127
+ AbandonGoBack = "abandon-goBack",
128
+ ImSureCancel = "imSure-cancel",
129
+ DeleteCancel = "delete-cancel",
130
+ ConfirmCancel = "confirm-cancel",
131
+ NoButtons = "-"
132
+ }
133
+
134
+ /**
135
+ * A generic popup modal
136
+ * @author Gabe Abrams
137
+ */
138
+
139
+ declare type Props$6 = {
140
+ type?: ModalType;
141
+ size?: ModalSize;
142
+ title?: React.ReactNode;
143
+ children?: React.ReactNode;
144
+ onClose?: (type: ModalButtonType) => void;
145
+ dontAllowBackdropExit?: boolean;
146
+ okayLabel?: string;
147
+ okayVariant?: Variant;
148
+ cancelLabel?: string;
149
+ cancelVariant?: Variant;
150
+ yesLabel?: string;
151
+ yesVariant?: Variant;
152
+ noLabel?: string;
153
+ noVariant?: Variant;
154
+ abandonLabel?: string;
155
+ abandonVariant?: Variant;
156
+ goBackLabel?: string;
157
+ goBackVariant?: Variant;
158
+ continueLabel?: string;
159
+ continueVariant?: Variant;
160
+ imSureLabel?: string;
161
+ imSureVariant?: Variant;
162
+ deleteLabel?: string;
163
+ deleteVariant?: Variant;
164
+ confirmLabel?: string;
165
+ confirmVariant?: Variant;
166
+ onTopOfOtherModals?: boolean;
167
+ };
168
+ declare const Modal: React.FC<Props$6>;
169
+
170
+ /**
171
+ * A box with a tab on the top that holds buttons and other content
172
+ * @author Gabe Abrams
173
+ */
174
+
175
+ declare type Props$5 = {
176
+ title: React.ReactNode;
177
+ children: React.ReactNode;
178
+ noBottomPadding?: boolean;
179
+ };
180
+ declare const TabBox: React.FC<Props$5>;
181
+
182
+ /**
183
+ * A radio selection button
184
+ * @author Gabe Abrams
185
+ */
186
+
187
+ declare type Props$4 = {
188
+ text: string;
189
+ onSelected: () => void;
190
+ ariaLabel: string;
191
+ title?: string;
192
+ selected?: boolean;
193
+ id?: string;
194
+ noMarginOnRight?: boolean;
195
+ selectedVariant?: Variant;
196
+ unselectedVariant?: Variant;
197
+ small?: boolean;
198
+ };
199
+ declare const RadioButton: React.FC<Props$4>;
200
+
201
+ /**
202
+ * A checkbox button
203
+ * @author Gabe Abrams
204
+ */
205
+
206
+ declare type Props$3 = {
207
+ text: string;
208
+ onChanged: (checked: boolean) => void;
209
+ ariaLabel: string;
210
+ title?: string;
211
+ checked?: boolean;
212
+ id?: string;
213
+ noMarginOnRight?: boolean;
214
+ checkedVariant?: Variant;
215
+ uncheckedVariant?: Variant;
216
+ small?: boolean;
217
+ };
218
+ declare const CheckboxButton: React.FC<Props$3>;
219
+
220
+ /**
221
+ * Input group with a title and space for buttons
222
+ * @author Gabe Abrams
223
+ */
224
+
225
+ declare type Props$2 = {
226
+ label: string;
227
+ minLabelWidth?: string;
228
+ children: React.ReactNode;
229
+ };
230
+ declare const ButtonInputGroup: React.FC<Props$2>;
231
+
232
+ /**
233
+ * A very simple, lightweight date chooser
234
+ * @author Gabe Abrams
235
+ */
236
+
237
+ declare type Props$1 = {
238
+ ariaLabel: string;
239
+ name: string;
240
+ month: number;
241
+ day: number;
242
+ year: number;
243
+ /**
244
+ * Handler for when date changes
245
+ * @param month new 1-indexed month number
246
+ * @param day new 1-indexed day number
247
+ * @param year new full year number
248
+ */
249
+ onChange: (month: number, day: number, year: number) => void;
250
+ numMonthsToShow?: number;
251
+ };
252
+ declare const SimpleDateChooser: React.FC<Props$1>;
253
+
254
+ /**
255
+ * Drawer container
256
+ * @author Gabe Abrams
257
+ */
258
+
259
+ declare type Props = {
260
+ children: React.ReactNode;
261
+ };
262
+ declare const Drawer: React.FC<Props>;
263
+
264
+ /**
265
+ * An error with a code
266
+ * @author Gabe Abrams
267
+ */
268
+ declare class ErrorWithCode extends Error {
269
+ code: string;
270
+ constructor(message: string, code: string);
271
+ }
272
+
273
+ /**
274
+ * Shorten text so it fits into a certain number of chars
275
+ * @author Gabe Abrams
276
+ * @param text the text to abbreviate
277
+ * @param maxChars the maximum number of chars to include
278
+ * @returns abbreviated text with length no greater than maxChars
279
+ * (including ellipses if applicable)
280
+ */
281
+ declare const abbreviate: (text: string, maxChars: number) => string;
282
+
283
+ /**
284
+ * Get the average of a set of numbers
285
+ * @author Gabe Abrams
286
+ * @param nums the numbers to average
287
+ * @returns average value or 0 if no numbers
288
+ */
289
+ declare const avg: (nums: number[]) => number;
290
+
291
+ /**
292
+ * Round a number (ceiling) to a certain number of decimals
293
+ * @author Gabe Abrams
294
+ * @param num the number to round
295
+ * @param numDecimals the number of decimals to round to
296
+ * @returns rounded number
297
+ */
298
+ declare const ceilToNumDecimals: (num: number, numDecimals: number) => number;
299
+
300
+ /**
301
+ * Round a number (floor) to a certain number of decimals
302
+ * @author Gabe Abrams
303
+ * @param num the number to round
304
+ * @param numDecimals the number of decimals to round to
305
+ * @returns rounded number
306
+ */
307
+ declare const floorToNumDecimals: (num: number, numDecimals: number) => number;
308
+
309
+ /**
310
+ * Force a number to stay within specific bounds
311
+ * @author Gabe Abrams
312
+ * @param num the number to move into the bounds
313
+ * @param min the minimum number in the bound
314
+ * @param max the maximum number in the bound
315
+ * @returns bounded number
316
+ */
317
+ declare const forceNumIntoBounds: (num: number, min: number, max: number) => number;
318
+
319
+ /**
320
+ * Pad a number's decimal with zeros on the right
321
+ * (e.g. 5.2 becomes 5.20 with 2 digit padding)
322
+ * @author Gabe Abrams
323
+ * @param num the number to pad
324
+ * @param numDigits the minimum number of digits after the decimal
325
+ * @returns padded number
326
+ */
327
+ declare const padDecimalZeros: (num: number, numDigits: number) => string;
328
+
329
+ /**
330
+ * Pad a number with zeros on the left (e.g. 5 becomes 05 with 2 digit padding)
331
+ * @author Gabe Abrams
332
+ * @param num the number to pad
333
+ * @param numDigits the minimum number of digits before the decimal
334
+ * @returns padded number
335
+ */
336
+ declare const padZerosLeft: (num: number, numDigits: number) => string;
337
+
338
+ /**
339
+ * Round a number to a certain number of decimals
340
+ * @author Gabe Abrams
341
+ * @param num the number to round
342
+ * @param numDecimals the number of decimals to round to
343
+ * @returns rounded number
344
+ */
345
+ declare const roundToNumDecimals: (num: number, numDecimals: number) => number;
346
+
347
+ /**
348
+ * Sum the numbers in an array
349
+ * @author Gabe Abrams
350
+ * @param nums the numbers to sum
351
+ * @returns the sum of the numbers
352
+ */
353
+ declare const sum: (nums: number[]) => number;
354
+
355
+ /**
356
+ * Wait for a certain number of ms
357
+ * @author Gabe Abrams
358
+ * @param ms number of ms to wait
359
+ */
360
+ declare const waitMs: (ms?: number) => Promise<unknown>;
361
+
362
+ /**
363
+ * Visit an endpoint on the server [for client only]
364
+ * @author Gabe Abrams
365
+ * @param opts object containing all arguments
366
+ * @param opts.path - the path of the server endpoint
367
+ * @param [opts.method=GET] - the method of the endpoint
368
+ * @param [opts.params] - query/body parameters to include
369
+ * @returns response from server
370
+ */
371
+ declare const visitServerEndpoint: (opts: {
372
+ path: string;
373
+ method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
374
+ params?: {
375
+ [x: string]: any;
376
+ } | undefined;
377
+ }) => Promise<any>;
378
+
379
+ /**
380
+ * Server-side API param types
381
+ * @author Gabe Abrams
382
+ */
383
+ declare enum ParamType {
384
+ Boolean = "boolean",
385
+ BooleanOptional = "boolean-optional",
386
+ Float = "float",
387
+ FloatOptional = "float-optional",
388
+ Int = "int",
389
+ IntOptional = "int-optional",
390
+ JSON = "json",
391
+ JSONOptional = "json-optional",
392
+ String = "string",
393
+ StringOptional = "string-optional"
394
+ }
395
+
396
+ /**
397
+ * Handle an error and respond to the client
398
+ * @author Gabe Abrams
399
+ * @param res express response
400
+ * @param error error info
401
+ * @param opts.err the error to send to the client
402
+ * or the error message
403
+ * @param [opts.code] an error code (only used if err.code is not
404
+ * included)
405
+ * @param [opts.status=500] the https status code to use
406
+ * defined)
407
+ */
408
+ declare const handleError: (res: any, error: ({
409
+ message: any;
410
+ code?: string;
411
+ status?: number;
412
+ } | Error | string | any)) => undefined;
413
+
414
+ /**
415
+ * Send successful API response
416
+ * @author Gabe Abrams
417
+ * @param res express response
418
+ * @param body the body of the response to send to the client
419
+ */
420
+ declare const handleSuccess: (res: any, body: any) => undefined;
421
+
422
+ /**
423
+ * Generate an express API route handler
424
+ * @author Gabe Abrams
425
+ * @param opts object containing all arguments
426
+ * @param opts.paramTypes map containing the types for each parameter that is
427
+ * included in the request (map: param name => type)
428
+ * @param opts.handler function that processes the request
429
+ * @returns express route handler that takes the following arguments:
430
+ * params (map: param name => value), handleSuccess (function for handling
431
+ * successful requests), handleError (function for handling failed requests),
432
+ * req (express request object), res (express response object),
433
+ * next (express next function)
434
+ */
435
+ declare const genRouteHandler: (opts: {
436
+ paramTypes?: {
437
+ [k: string]: ParamType;
438
+ } | undefined;
439
+ handler: (opts: {
440
+ params: {
441
+ [k: string]: any;
442
+ };
443
+ handleSuccess: (body: any) => void;
444
+ handleError: (error: any) => void;
445
+ req: any;
446
+ res: any;
447
+ next: () => void;
448
+ }) => void;
449
+ }) => (req: any, res: any, next: () => void) => Promise<undefined>;
450
+
451
+ declare type GetLaunchInfoFunction = (req: any) => {
452
+ launched: boolean;
453
+ launchInfo?: any;
454
+ };
455
+ /**
456
+ * Prepare dce-reactkit to run on the server
457
+ * @author Gabe Abrams
458
+ * @param opts object containing all arguments
459
+ * @param opts.getLaunchInfo CACCL LTI's get launch info function
460
+ */
461
+ declare const initServer: (opts: {
462
+ getLaunchInfo: GetLaunchInfoFunction;
463
+ }) => void;
464
+
465
+ /**
466
+ * Get a number's ordinal
467
+ * @author Gabe Abrams
468
+ * @param num the number being analyzed
469
+ * @returns ordinal
470
+ */
471
+ declare const getOrdinal: (num: number) => string;
472
+
473
+ /**
474
+ * Get current time info in US Boston Eastern Time, independent of machine
475
+ * timezone
476
+ * @author Gabe Abrams
477
+ * @param {Date} [date=now] the date to get info on
478
+ * @returns object with timestamp (ms since epoch) and numbers
479
+ * corresponding to ET time values for year, month, day, hour, minute
480
+ */
481
+ declare const getTimeInfoInET: (date?: Date | undefined) => {
482
+ timestamp: number;
483
+ year: number;
484
+ month: number;
485
+ day: number;
486
+ hour: number;
487
+ minute: number;
488
+ };
489
+
490
+ /**
491
+ * List of error codes built into the react kit
492
+ * @author Gabe Abrams
493
+ */
494
+ declare enum ReactKitErrorCode {
495
+ NoResponse = "DRK1",
496
+ NoCode = "DRK2",
497
+ SessionExpired = "DRK3",
498
+ MissingParameter = "DRK4",
499
+ InvalidParameter = "DRK5",
500
+ WrongCourse = "DRK6",
501
+ NoCACCLSendRequestFunction = "DRK7",
502
+ NoCACCLGetLaunchInfoFunction = "DRK8"
503
+ }
504
+
505
+ export { AppWrapper, ButtonInputGroup, CheckboxButton, Drawer, ErrorBox, ErrorWithCode, LoadingSpinner, Modal, ModalButtonType, ModalSize, ModalType, ParamType, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, Variant, abbreviate, alert, avg, ceilToNumDecimals, confirm, floorToNumDecimals, forceNumIntoBounds, genRouteHandler, getOrdinal, getTimeInfoInET, handleError, handleSuccess, initServer, padDecimalZeros, padZerosLeft, roundToNumDecimals, showFatalError, sum, visitServerEndpoint, waitMs };
package/package.json CHANGED
@@ -1,59 +1,48 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.0.0",
4
- "main": "lib/cjs/index.js",
5
- "module": "lib/esm/index.js",
6
- "types": "lib/index.d.ts",
3
+ "version": "3.0.3",
4
+ "description": "Shared components for Harvard DCE apps",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/index.d.ts",
7
8
  "scripts": {
8
- "build": "rollup -c"
9
+ "build": "rm -rf dist && rollup -c"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
12
- "url": "git+https://github.com/harvard-edtech/dce-reactkit"
13
+ "url": "git+https://github.com/harvard-edtech/dce-reactkit.git"
13
14
  },
14
15
  "author": "Gabe Abrams <gabeabrams@gmail.com>",
15
16
  "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/harvard-edtech/dce-reactkit/issues"
19
+ },
16
20
  "homepage": "https://github.com/harvard-edtech/dce-reactkit#readme",
17
- "dependencies": {
18
- "@fortawesome/fontawesome-svg-core": "^6.1.1",
21
+ "peerDependencies": {
19
22
  "@fortawesome/free-regular-svg-icons": "^6.1.1",
20
23
  "@fortawesome/free-solid-svg-icons": "^6.1.1",
21
24
  "@fortawesome/react-fontawesome": "^0.1.18",
22
- "caccl": "^2.0.0-beta.39",
23
- "react-bootstrap": "^2.2.3",
25
+ "bootstrap": "^5.1.3",
24
26
  "react": "^18.0.0"
25
27
  },
26
28
  "devDependencies": {
27
- "@rollup/plugin-commonjs": "^21.1.0",
29
+ "@rollup/plugin-commonjs": "^22.0.0",
28
30
  "@rollup/plugin-json": "^4.1.0",
29
31
  "@rollup/plugin-node-resolve": "^13.2.1",
30
32
  "@rollup/plugin-typescript": "^8.3.2",
31
- "@types/express": "^4.17.13",
32
- "@types/react": "^18.0.5",
33
- "@typescript-eslint/eslint-plugin": "^5.18.0",
34
- "@typescript-eslint/parser": "^5.18.0",
35
- "eslint": "^8.12.0",
33
+ "@types/react": "^18.0.7",
34
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
35
+ "@typescript-eslint/parser": "^5.21.0",
36
+ "eslint": "^8.14.0",
36
37
  "eslint-config-airbnb": "^19.0.4",
37
38
  "eslint-config-airbnb-typescript": "^17.0.0",
38
39
  "eslint-plugin-import": "^2.26.0",
39
- "eslint-plugin-jest": "^26.1.3",
40
40
  "eslint-plugin-jsx-a11y": "^6.5.1",
41
41
  "eslint-plugin-react": "^7.29.4",
42
42
  "eslint-plugin-react-hooks": "^4.4.0",
43
- "react": "^18.0.0",
44
43
  "rollup": "^2.70.2",
45
44
  "rollup-plugin-dts": "^4.2.1",
46
- "rollup-plugin-peer-deps-external": "^2.2.4",
47
- "rollup-plugin-terser": "^7.0.2",
45
+ "rollup-plugin-sourcemaps": "^0.6.3",
48
46
  "typescript": "^4.6.3"
49
- },
50
- "peerDependencies": {
51
- "@fortawesome/fontawesome-svg-core": "^6.1.1",
52
- "@fortawesome/free-regular-svg-icons": "^6.1.1",
53
- "@fortawesome/free-solid-svg-icons": "^6.1.1",
54
- "@fortawesome/react-fontawesome": "^0.1.18",
55
- "caccl": "^2.0.0-beta.39",
56
- "react-bootstrap": "^2.2.3",
57
- "react": "^18.0.0"
58
47
  }
59
48
  }
package/rollup.config.js CHANGED
@@ -2,9 +2,7 @@ import resolve from "@rollup/plugin-node-resolve";
2
2
  import commonjs from "@rollup/plugin-commonjs";
3
3
  import typescript from "@rollup/plugin-typescript";
4
4
  import dts from "rollup-plugin-dts";
5
- import { terser } from "rollup-plugin-terser";
6
- import peerDepsExternal from 'rollup-plugin-peer-deps-external';
7
- import json from "@rollup/plugin-json";
5
+ import sourcemaps from 'rollup-plugin-sourcemaps';
8
6
 
9
7
  const packageJson = require("./package.json");
10
8
 
@@ -24,20 +22,23 @@ export default [
24
22
  },
25
23
  ],
26
24
  plugins: [
27
- peerDepsExternal(),
28
- resolve({
29
- preferBuiltins: false,
30
- }),
25
+ resolve(),
31
26
  commonjs(),
32
27
  typescript({ tsconfig: "./tsconfig.json" }),
33
- terser(),
34
- json(),
28
+ sourcemaps(),
29
+ ],
30
+ external: [
31
+ ...Object.keys(packageJson.dependencies || {}),
32
+ ...Object.keys(packageJson.peerDependencies || {}),
35
33
  ],
36
- external: ["react", "react-dom", "styled-components"]
37
34
  },
38
35
  {
39
- input: "lib/esm/types/index.d.ts",
40
- output: [{ file: "lib/index.d.ts", format: "esm" }],
36
+ input: "dist/esm/types/index.d.ts",
37
+ output: [{ file: "dist/index.d.ts", format: "esm" }],
41
38
  plugins: [dts()],
39
+ external: [
40
+ ...Object.keys(packageJson.dependencies || {}),
41
+ ...Object.keys(packageJson.peerDependencies || {}),
42
+ ],
42
43
  },
43
- ];
44
+ ];