dce-reactkit 3.5.12 → 3.5.13

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.
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Get the current part of day (morning, evening, etc.)
3
3
  * @author Gabe Abrams
4
+ * @returns the part of day (morning, evening, etc.)
4
5
  */
5
6
  declare const getPartOfDay: () => string;
6
7
  export default getPartOfDay;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ /**
3
+ * Given some text, make the links clickable
4
+ * @author Gabe Abrams
5
+ * @param text the text to process
6
+ * @param [opts] options to customize behavior
7
+ * @param [opts.newTab] if true, links will open in a new tab
8
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
9
+ * and propagation
10
+ * @returns the processed text
11
+ */
12
+ declare const makeLinksClickable: (text: string, opts?: {
13
+ newTab?: boolean;
14
+ preventPropagation?: boolean;
15
+ }) => React.ReactNode;
16
+ export default makeLinksClickable;
@@ -65,6 +65,7 @@ import validateEmail from './helpers/validators/validateEmail';
65
65
  import validatePhoneNumber from './helpers/validators/validatePhoneNumber';
66
66
  import validateString from './helpers/validators/validateString';
67
67
  import idify from './helpers/idify';
68
+ import makeLinksClickable from './helpers/makeLinksClickable';
68
69
  import ModalButtonType from './types/ModalButtonType';
69
70
  import ModalSize from './types/ModalSize';
70
71
  import ModalType from './types/ModalType';
@@ -83,4 +84,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
83
84
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
84
85
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
85
86
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
86
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
87
+ export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
package/dist/index.d.ts CHANGED
@@ -1125,6 +1125,7 @@ declare const getHumanReadableDate: (dateOrTimestamp?: Date | number) => string;
1125
1125
  /**
1126
1126
  * Get the current part of day (morning, evening, etc.)
1127
1127
  * @author Gabe Abrams
1128
+ * @returns the part of day (morning, evening, etc.)
1128
1129
  */
1129
1130
  declare const getPartOfDay: () => string;
1130
1131
 
@@ -1372,6 +1373,21 @@ declare const validateString: (input: string, opts: {
1372
1373
  */
1373
1374
  declare const idify: (str: string) => string;
1374
1375
 
1376
+ /**
1377
+ * Given some text, make the links clickable
1378
+ * @author Gabe Abrams
1379
+ * @param text the text to process
1380
+ * @param [opts] options to customize behavior
1381
+ * @param [opts.newTab] if true, links will open in a new tab
1382
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
1383
+ * and propagation
1384
+ * @returns the processed text
1385
+ */
1386
+ declare const makeLinksClickable: (text: string, opts?: {
1387
+ newTab?: boolean;
1388
+ preventPropagation?: boolean;
1389
+ }) => React.ReactNode;
1390
+
1375
1391
  /**
1376
1392
  * List of error codes built into the react kit
1377
1393
  * @author Gabe Abrams
@@ -1422,4 +1438,4 @@ declare const LogBuiltInMetadata: {
1422
1438
  };
1423
1439
  };
1424
1440
 
1425
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
1441
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.5.12",
3
+ "version": "3.5.13",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Get the current part of day (morning, evening, etc.)
3
3
  * @author Gabe Abrams
4
+ * @returns the part of day (morning, evening, etc.)
4
5
  */
5
6
  const getPartOfDay = () => {
6
7
  // Setup the post-it time of day
7
8
  let partOfDay = 'day';
8
- let hours = new Date().getHours();
9
+ const hours = new Date().getHours();
9
10
  if (hours < 12) {
10
11
  partOfDay = 'morning';
11
12
  } else if (hours >= 12 && hours <= 16) {
@@ -0,0 +1,98 @@
1
+ // Import React
2
+ import React from 'react';
3
+
4
+ // Regular express that matches urls
5
+ const urlRegex = /(https?:\/\/)?([a-z0-9-]+\.)+[a-z0-9]{2,6}(:[0-9]{1,5})?(\/\S*)?/g;
6
+
7
+ /**
8
+ * Given some text, make the links clickable
9
+ * @author Gabe Abrams
10
+ * @param text the text to process
11
+ * @param [opts] options to customize behavior
12
+ * @param [opts.newTab] if true, links will open in a new tab
13
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
14
+ * and propagation
15
+ * @returns the processed text
16
+ */
17
+ const makeLinksClickable = (
18
+ text: string,
19
+ opts?: {
20
+ newTab?: boolean,
21
+ preventPropagation?: boolean,
22
+ },
23
+ ): React.ReactNode => {
24
+ // Search text for links
25
+ let matches = urlRegex.exec(text);
26
+
27
+ // If no matches, just return the text
28
+ if (!matches) {
29
+ return text;
30
+ }
31
+
32
+ // Check if using new tab
33
+ const newTab = opts?.newTab;
34
+
35
+ // Next element key
36
+ let nextKey = 0;
37
+
38
+ // Process each link
39
+ const elements: React.ReactNode[] = [];
40
+ let lastIndex = 0;
41
+ while (matches) {
42
+ // Get the link
43
+ const link = matches[0];
44
+
45
+ // Get the index of the link
46
+ const { index } = matches;
47
+
48
+ // Add the text before the link
49
+ elements.push(
50
+ <span key={nextKey += 1}>
51
+ {text.substring(lastIndex, index)}
52
+ </span>,
53
+ );
54
+
55
+ // Add the link
56
+ elements.push(
57
+ <a
58
+ key={nextKey += 1}
59
+ href={link}
60
+ target={newTab ? '_blank' : undefined}
61
+ rel={newTab ? 'noopener noreferrer' : undefined}
62
+ style={{
63
+ textDecoration: 'underline',
64
+ }}
65
+ onClick={(e) => {
66
+ // Prevent default and propagation if requested
67
+ if (opts?.preventPropagation) {
68
+ e.preventDefault();
69
+ e.stopPropagation();
70
+ }
71
+ }}
72
+ >
73
+ {link}
74
+ </a>,
75
+ );
76
+
77
+ // Update the last index
78
+ lastIndex = index + link.length;
79
+
80
+ // Get the next match
81
+ matches = urlRegex.exec(text);
82
+ }
83
+
84
+ // Add the last bit of text
85
+ const remainingText = text.substring(lastIndex);
86
+ if (remainingText && remainingText.length > 0) {
87
+ elements.push(
88
+ <span key={nextKey += 1}>
89
+ {remainingText}
90
+ </span>,
91
+ );
92
+ }
93
+
94
+ // Return the elements
95
+ return elements;
96
+ };
97
+
98
+ export default makeLinksClickable;
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ import validateEmail from './helpers/validators/validateEmail';
80
80
  import validatePhoneNumber from './helpers/validators/validatePhoneNumber';
81
81
  import validateString from './helpers/validators/validateString';
82
82
  import idify from './helpers/idify';
83
+ import makeLinksClickable from './helpers/makeLinksClickable';
83
84
 
84
85
  // Import types
85
86
  import ModalButtonType from './types/ModalButtonType';
@@ -172,6 +173,7 @@ export {
172
173
  validateString,
173
174
  getLocalTimeInfo,
174
175
  idify,
176
+ makeLinksClickable,
175
177
  // Client helpers
176
178
  initClient,
177
179
  visitServerEndpoint,