dce-reactkit 3.5.12 → 3.5.14

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,18 @@
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
9
+ * propagation
10
+ * @param [opts.inheritColor] if true, inherit text color for links
11
+ * @returns the processed text
12
+ */
13
+ declare const makeLinksClickable: (text: string, opts?: {
14
+ newTab?: boolean;
15
+ preventPropagation?: boolean;
16
+ inheritColor?: boolean;
17
+ }) => React.ReactNode;
18
+ 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,23 @@ 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
1383
+ * propagation
1384
+ * @param [opts.inheritColor] if true, inherit text color for links
1385
+ * @returns the processed text
1386
+ */
1387
+ declare const makeLinksClickable: (text: string, opts?: {
1388
+ newTab?: boolean;
1389
+ preventPropagation?: boolean;
1390
+ inheritColor?: boolean;
1391
+ }) => React.ReactNode;
1392
+
1375
1393
  /**
1376
1394
  * List of error codes built into the react kit
1377
1395
  * @author Gabe Abrams
@@ -1422,4 +1440,4 @@ declare const LogBuiltInMetadata: {
1422
1440
  };
1423
1441
  };
1424
1442
 
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 };
1443
+ 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.14",
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,100 @@
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
14
+ * propagation
15
+ * @param [opts.inheritColor] if true, inherit text color for links
16
+ * @returns the processed text
17
+ */
18
+ const makeLinksClickable = (
19
+ text: string,
20
+ opts?: {
21
+ newTab?: boolean,
22
+ preventPropagation?: boolean,
23
+ inheritColor?: boolean,
24
+ },
25
+ ): React.ReactNode => {
26
+ // Search text for links
27
+ let matches = urlRegex.exec(text);
28
+
29
+ // If no matches, just return the text
30
+ if (!matches) {
31
+ return text;
32
+ }
33
+
34
+ // Check if using new tab
35
+ const newTab = opts?.newTab;
36
+
37
+ // Next element key
38
+ let nextKey = 0;
39
+
40
+ // Process each link
41
+ const elements: React.ReactNode[] = [];
42
+ let lastIndex = 0;
43
+ while (matches) {
44
+ // Get the link
45
+ const link = matches[0];
46
+
47
+ // Get the index of the link
48
+ const { index } = matches;
49
+
50
+ // Add the text before the link
51
+ elements.push(
52
+ <span key={nextKey += 1}>
53
+ {text.substring(lastIndex, index)}
54
+ </span>,
55
+ );
56
+
57
+ // Add the link
58
+ elements.push(
59
+ <a
60
+ key={nextKey += 1}
61
+ href={link}
62
+ target={newTab ? '_blank' : undefined}
63
+ rel={newTab ? 'noopener noreferrer' : undefined}
64
+ style={{
65
+ textDecoration: 'underline',
66
+ color: opts?.inheritColor ? 'inherit' : undefined,
67
+ }}
68
+ onClick={(e) => {
69
+ // Prevent propagation if requested
70
+ if (opts?.preventPropagation) {
71
+ e.stopPropagation();
72
+ }
73
+ }}
74
+ >
75
+ {link}
76
+ </a>,
77
+ );
78
+
79
+ // Update the last index
80
+ lastIndex = index + link.length;
81
+
82
+ // Get the next match
83
+ matches = urlRegex.exec(text);
84
+ }
85
+
86
+ // Add the last bit of text
87
+ const remainingText = text.substring(lastIndex);
88
+ if (remainingText && remainingText.length > 0) {
89
+ elements.push(
90
+ <span key={nextKey += 1}>
91
+ {remainingText}
92
+ </span>,
93
+ );
94
+ }
95
+
96
+ // Return the elements
97
+ return elements;
98
+ };
99
+
100
+ 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,