@pega/custom-dx-components 0.0.1 → 0.23.2

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 (234) hide show
  1. package/.vscode/extensions.json +1 -1
  2. package/README.md +6 -189
  3. package/package.json +34 -32
  4. package/src/auth.js +608 -0
  5. package/src/cli.js +42 -0
  6. package/src/constants.js +125 -8
  7. package/src/tasks/authenticate/helper.js +91 -8
  8. package/src/tasks/authenticate/index.js +169 -49
  9. package/src/tasks/build/helper.js +122 -0
  10. package/src/tasks/build/index.js +54 -0
  11. package/src/tasks/build-all/helper.js +70 -0
  12. package/src/tasks/build-all/index.js +79 -0
  13. package/src/tasks/{publish/bundle → bundle}/builder/index.js +49 -5
  14. package/src/tasks/{publish/bundle → bundle}/builder/webpack.config.js +5 -3
  15. package/src/tasks/{publish/bundle → bundle}/index.js +2 -2
  16. package/src/tasks/create/index.js +87 -64
  17. package/src/tasks/create/templates/Constellation/Field/Boolean/Boolean.js.mustache +38 -0
  18. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +26 -0
  19. package/src/tasks/create/templates/Constellation/Field/Boolean/config.json.mustache +146 -0
  20. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +61 -0
  21. package/src/tasks/create/templates/Constellation/Field/Boolean/event-utils.js.mustache +18 -0
  22. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +170 -0
  23. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +21 -0
  24. package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -0
  25. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +61 -0
  26. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +41 -0
  27. package/src/tasks/create/templates/Constellation/Field/Date/config.json.mustache +196 -0
  28. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +439 -0
  29. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +73 -0
  30. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +256 -0
  31. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +23 -0
  32. package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -0
  33. package/src/tasks/create/templates/Constellation/Field/Date/suggestions-handler.js +10 -0
  34. package/src/tasks/create/templates/Constellation/Field/DateTime/config.json.mustache +257 -0
  35. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +92 -0
  36. package/src/tasks/create/templates/Constellation/Field/DateTime/date-utils.js.mustache +287 -0
  37. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +328 -0
  38. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +73 -0
  39. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +254 -0
  40. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +23 -0
  41. package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -0
  42. package/src/tasks/create/templates/Constellation/Field/DateTime/suggestions-handler.js +10 -0
  43. package/src/tasks/create/templates/Constellation/Field/Decimal/config.json.mustache +279 -0
  44. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +49 -0
  45. package/src/tasks/create/templates/Constellation/Field/Decimal/event-utils.js.mustache +18 -0
  46. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +273 -0
  47. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +21 -0
  48. package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -0
  49. package/src/tasks/create/templates/Constellation/Field/Decimal/suggestions-handler.js +10 -0
  50. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/config.json.mustache +292 -0
  51. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +53 -0
  52. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/event-utils.js.mustache +18 -0
  53. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +299 -0
  54. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +23 -0
  55. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -0
  56. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/suggestions-handler.js +10 -0
  57. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/config.json.mustache +94 -0
  58. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +49 -0
  59. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/event-utils.js.mustache +18 -0
  60. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +281 -0
  61. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +21 -0
  62. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -0
  63. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/suggestions-handler.js +10 -0
  64. package/src/tasks/create/templates/Constellation/Field/Integer/config.json.mustache +348 -0
  65. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +49 -0
  66. package/src/tasks/create/templates/Constellation/Field/Integer/event-utils.js.mustache +18 -0
  67. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +336 -0
  68. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +21 -0
  69. package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -0
  70. package/src/tasks/create/templates/Constellation/Field/Integer/suggestions-handler.js +10 -0
  71. package/src/tasks/create/templates/Constellation/Field/Picklist/config.json.mustache +115 -0
  72. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +78 -0
  73. package/src/tasks/create/templates/Constellation/Field/Picklist/event-utils.js.mustache +18 -0
  74. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +351 -0
  75. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +67 -0
  76. package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -0
  77. package/src/tasks/create/templates/Constellation/Field/Picklist/suggestions-handler.js +10 -0
  78. package/src/tasks/create/{template → templates/Constellation/Field/Text}/config.json.mustache +15 -5
  79. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +51 -0
  80. package/src/tasks/create/{template → templates/Constellation/Field/Text}/index.jsx.mustache +5 -0
  81. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +13 -0
  82. package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -0
  83. package/src/tasks/create/templates/Constellation/Field/Text-Email/config.json.mustache +112 -0
  84. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +48 -0
  85. package/src/tasks/create/templates/Constellation/Field/Text-Email/event-utils.js.mustache +18 -0
  86. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +231 -0
  87. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +22 -0
  88. package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -0
  89. package/src/tasks/create/templates/Constellation/Field/Text-Email/suggestions-handler.js +10 -0
  90. package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.jsx +26 -0
  91. package/src/tasks/create/templates/Constellation/Field/Text-Input/config.json.mustache +112 -0
  92. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +48 -0
  93. package/src/tasks/create/templates/Constellation/Field/Text-Input/event-utils.js.mustache +18 -0
  94. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +239 -0
  95. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +21 -0
  96. package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -0
  97. package/src/tasks/create/templates/Constellation/Field/Text-Input/suggestions-handler.js +10 -0
  98. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/config.json.mustache +112 -0
  99. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +48 -0
  100. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/event-utils.js.mustache +18 -0
  101. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +231 -0
  102. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +20 -0
  103. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -0
  104. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/suggestions-handler.js +10 -0
  105. package/src/tasks/create/templates/Constellation/Field/Text-Phone/config.json.mustache +124 -0
  106. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +46 -0
  107. package/src/tasks/create/templates/Constellation/Field/Text-Phone/event-utils.js.mustache +18 -0
  108. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +267 -0
  109. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +37 -0
  110. package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -0
  111. package/src/tasks/create/templates/Constellation/Field/Text-Phone/suggestions-handler.js +10 -0
  112. package/src/tasks/create/templates/Constellation/Field/Text-URL/config.json.mustache +238 -0
  113. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +46 -0
  114. package/src/tasks/create/templates/Constellation/Field/Text-URL/event-utils.js.mustache +18 -0
  115. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +232 -0
  116. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +22 -0
  117. package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -0
  118. package/src/tasks/create/templates/Constellation/Field/Text-URL/suggestions-handler.js +10 -0
  119. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.jsx.mustache +173 -0
  120. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/config.json.mustache +186 -0
  121. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/demo.stories.jsx.mustache +57 -0
  122. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/index.jsx.mustache +213 -0
  123. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/mock.stories.js.mustache +20 -0
  124. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/styles.js.mustache +7 -0
  125. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/suggestions-handler.js +10 -0
  126. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/time-of-day.js.mustache +287 -0
  127. package/src/tasks/create/templates/Constellation/Template/DETAILS/OneColumnDetails.svg +22 -0
  128. package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +26 -0
  129. package/src/tasks/create/templates/Constellation/Template/DETAILS/config.json.mustache +36 -0
  130. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +132 -0
  131. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +86 -0
  132. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +189 -0
  133. package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -0
  134. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +152 -0
  135. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +26 -0
  136. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
  137. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/config.json.mustache +43 -0
  138. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +136 -0
  139. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +86 -0
  140. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +230 -0
  141. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -0
  142. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +155 -0
  143. package/src/tasks/create/templates/Constellation/Template/FORM/DefaultForm.svg +29 -0
  144. package/src/tasks/create/templates/Constellation/Template/FORM/config.json.mustache +46 -0
  145. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +169 -0
  146. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +45 -0
  147. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +137 -0
  148. package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -0
  149. package/src/tasks/create/templates/Constellation/Template/FORM-region/TwoColumn.svg +38 -0
  150. package/src/tasks/create/templates/Constellation/Template/FORM-region/config.json.mustache +28 -0
  151. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +178 -0
  152. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +48 -0
  153. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +143 -0
  154. package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -0
  155. package/src/tasks/create/templates/Constellation/Template/PAGE/GetNextWork.jsx.mustache +35 -0
  156. package/src/tasks/create/templates/Constellation/Template/PAGE/OneColumnPage.svg +36 -0
  157. package/src/tasks/create/templates/Constellation/Template/PAGE/config.json.mustache +33 -0
  158. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +102 -0
  159. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +70 -0
  160. package/src/tasks/create/templates/Constellation/Template/PAGE/localizations.json.mustache +4 -0
  161. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +94 -0
  162. package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -0
  163. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +229 -0
  164. package/src/tasks/create/templates/Constellation/Widget/CASE/OneColumnPage.svg +36 -0
  165. package/src/tasks/create/templates/Constellation/Widget/CASE/config.json.mustache +24 -0
  166. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +78 -0
  167. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +76 -0
  168. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +390 -0
  169. package/src/tasks/create/{template → templates/Constellation/Widget/CASE}/styles.js.mustache +1 -1
  170. package/src/tasks/create/templates/Constellation/Widget/PAGE/OneColumnPage.svg +36 -0
  171. package/src/tasks/create/templates/Constellation/Widget/PAGE/config.json.mustache +60 -0
  172. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +30 -0
  173. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +48 -0
  174. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +23 -0
  175. package/src/tasks/{init/template/src/components/Organization_Library_VideoPlayer/styles.js → create/templates/Constellation/Widget/PAGE/styles.js.mustache} +3 -1
  176. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.jsx.mustache +75 -0
  177. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
  178. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Operator.jsx.mustache +240 -0
  179. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/config.json.mustache +67 -0
  180. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +68 -0
  181. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +110 -0
  182. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +51 -0
  183. package/src/tasks/{init/template/src/components/Organization_Library_MediaURL/MediaURL.styles.ts → create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache} +3 -1
  184. package/src/tasks/create-all/index.js +398 -0
  185. package/src/tasks/delete/helper.js +6 -4
  186. package/src/tasks/delete/index.js +4 -0
  187. package/src/tasks/delete-all/helper.js +153 -0
  188. package/src/tasks/delete-all/index.js +49 -0
  189. package/src/tasks/generate-ai/aiPrompt.txt.mustache +23 -0
  190. package/src/tasks/generate-ai/aiPromptDavinci.txt.mustache +14 -0
  191. package/src/tasks/generate-ai/helper.js +357 -0
  192. package/src/tasks/generate-ai/index.js +34 -0
  193. package/src/tasks/index.js +7 -0
  194. package/src/tasks/init/index.js +9 -3
  195. package/src/tasks/init/template/.eslintignore +8 -0
  196. package/src/tasks/init/template/.eslintrc.json +186 -5
  197. package/src/tasks/init/template/.vscode/extensions.json +1 -1
  198. package/src/tasks/init/template/README.md +80 -61
  199. package/src/tasks/init/template/keys/DX-ComponentDev.zip +0 -0
  200. package/src/tasks/init/template/keys/dxcb.crt +32 -0
  201. package/src/tasks/init/template/keys/dxcb.key +51 -0
  202. package/src/tasks/init/template/package.json.mustache +44 -21
  203. package/src/tasks/init/template/src/components/_components.md +1 -0
  204. package/src/tasks/init/template/tasks.config.json +19 -5
  205. package/src/tasks/init/template/templateNPMRC.txt +8 -0
  206. package/src/tasks/linter/index.js +46 -0
  207. package/src/tasks/list/helper.js +19 -6
  208. package/src/tasks/list/index.js +4 -0
  209. package/src/tasks/publish/helper.js +13 -4
  210. package/src/tasks/publish/index.js +14 -1
  211. package/src/tasks/publish-all/helper.js +154 -0
  212. package/src/tasks/publish-all/index.js +95 -0
  213. package/src/tasks/rename/index.js +314 -0
  214. package/src/tasks/validator/index.js +291 -18
  215. package/src/util.js +372 -6
  216. package/src/tasks/create/template/demo.stories.jsx.mustache +0 -44
  217. package/src/tasks/init/template/src/components/MBTAList/MBTAList.stories.tsx +0 -10
  218. package/src/tasks/init/template/src/components/MBTAList/MBTAList.tsx +0 -122
  219. package/src/tasks/init/template/src/components/MBTAList/icons/accessible.icon.tsx +0 -14
  220. package/src/tasks/init/template/src/components/MBTAList/icons/bus.icon.tsx +0 -13
  221. package/src/tasks/init/template/src/components/MBTAList/icons/mbta.icon.tsx +0 -10
  222. package/src/tasks/init/template/src/components/MBTAList/icons/subway.icon.tsx +0 -14
  223. package/src/tasks/init/template/src/components/MBTAList/index.ts +0 -2
  224. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURL.stories.tsx +0 -19
  225. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURL.types.ts +0 -10
  226. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURLDisplay.tsx +0 -25
  227. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURLInput.tsx +0 -24
  228. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/config.json +0 -13
  229. package/src/tasks/init/template/src/components/Organization_Library_MediaURL/index.ts +0 -2
  230. package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/config.json +0 -44
  231. package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/demo.stories.jsx +0 -40
  232. package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/index.jsx +0 -42
  233. /package/src/tasks/{publish/bundle → bundle}/builder/modules.js +0 -0
  234. /package/src/tasks/{publish/bundle → bundle}/builder/paths.js +0 -0
@@ -0,0 +1,287 @@
1
+ /* eslint-disable no-undef */
2
+ import dayjs from "dayjs";
3
+
4
+ const relativeTime = require("dayjs/plugin/relativeTime");
5
+
6
+ dayjs.extend(relativeTime);
7
+
8
+ const utc = require("dayjs/plugin/utc");
9
+
10
+ dayjs.extend(utc);
11
+
12
+ /**
13
+ * Return relative time in fromNow for the given datetime
14
+ * @description Convert and return the given datetime in dayJSObject
15
+ *
16
+ * @param {string} text datetime
17
+ * @returns {object} datetime as a dayjs object
18
+ */
19
+ export const getDayJSObject = (text) => {
20
+ const momObj = dayjs(text);
21
+ if (momObj.isValid()) return momObj;
22
+ const timeStamp = text;
23
+ const isDateTime = timeStamp.indexOf("GMT") !== -1;
24
+ const year = parseInt(timeStamp.substr(0, 4), 10);
25
+ const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
26
+ const day = parseInt(timeStamp.substr(6, 2), 10);
27
+
28
+ const CurrentTz = PCore.getLocaleUtils().getTimeZoneInUse();
29
+
30
+ let mom = new Date();
31
+
32
+ mom.setUTCDate(day);
33
+ mom.setUTCMonth(month);
34
+ mom.setUTCFullYear(year);
35
+
36
+ /* istanbul ignore else */
37
+ if (isDateTime) {
38
+ const hours = parseInt(timeStamp.substr(9, 2), 10);
39
+ const minutes = parseInt(timeStamp.substr(11, 2), 10);
40
+ const seconds = parseInt(timeStamp.substr(13, 2), 10);
41
+ const ms = parseInt(timeStamp.substr(16, 3), 10);
42
+ mom.setUTCHours(hours);
43
+ mom.setUTCMinutes(minutes);
44
+ mom.setUTCSeconds(seconds);
45
+ mom.setUTCMilliseconds(ms);
46
+ }
47
+
48
+ mom = dayjs(
49
+ mom.toLocaleString("en-US", {
50
+ timeZone: CurrentTz
51
+ })
52
+ );
53
+
54
+ return mom;
55
+ };
56
+
57
+ /**
58
+ * Return relative time in fromNow for the given datetime
59
+ *
60
+ * @param {string} time datetime
61
+ * @returns {object} relative time from now
62
+ */
63
+ export const getRelativeTime = (time) => {
64
+ let relativetime = "";
65
+ if (dayjs(time).isUTC()) {
66
+ relativetime = dayjs(time).fromNow();
67
+ } else {
68
+ const dayjstime = getDayJSObject(time);
69
+ relativetime = dayjs(dayjstime).fromNow();
70
+ }
71
+ return relativetime;
72
+ };
73
+
74
+ /**
75
+ * Return year for the date passed
76
+ *
77
+ * @param {string} value from which Year needs to be taken out
78
+ * @returns {number} year for the date passed
79
+ */
80
+ export const getFullYear = (value) =>
81
+ value ? new Date(value).getFullYear() : new Date().getFullYear();
82
+
83
+ /**
84
+ * Return maxDate for the date passed
85
+ *
86
+ * @param {number} nextYears next number of years
87
+ * @param {number} currentYear current year
88
+ * @param {number} yearFromValue year set on value in redux
89
+ *
90
+ * @returns {string} maxDate calculated based on inputs
91
+ */
92
+ export const getMaxDate = (nextYears, currentYear, yearFromValue) => {
93
+ if (Number.isNaN(nextYears)) {
94
+ nextYears = 20;
95
+ }
96
+ let maxYear = currentYear + nextYears;
97
+ if (yearFromValue > maxYear) {
98
+ maxYear = yearFromValue;
99
+ }
100
+ return `${maxYear}-01-01`;
101
+ };
102
+
103
+ /**
104
+ * Return minDate for the date passed
105
+ *
106
+ * @param {number} previousYears previous number of years
107
+ * @param {number} currentYear current year
108
+ * @param {number} yearFromValue year set on value in redux
109
+ *
110
+ * @returns {string} minDate calculated based on inputs
111
+ */
112
+ export const getMinDate = (previousYears, currentYear, yearFromValue) => {
113
+ if (Number.isNaN(previousYears)) {
114
+ previousYears = 100;
115
+ }
116
+ let minYear = currentYear - previousYears;
117
+ if (yearFromValue < minYear) {
118
+ minYear = yearFromValue;
119
+ }
120
+ return `${minYear}-12-31`;
121
+ };
122
+
123
+ /**
124
+ * Return clockFormat after parsing
125
+ *
126
+ * @param {number | string} clockFormat chosen by user
127
+ *
128
+ * @returns {number} clockFormat
129
+ */
130
+ export const parseClockFormat = (clockFormat) =>
131
+ typeof clockFormat === "string" ? parseInt(clockFormat, 10) : clockFormat;
132
+
133
+ /**
134
+ * Return datetime value string off to seconds
135
+ *
136
+ * @param {string} datetime in ISO format
137
+ * @param {boolean} withSeconds to specify if seconds is needed or not
138
+ *
139
+ * @returns {string} datetime after stripping of ms and seconds if selected to
140
+ */
141
+ export const correctDateTimeToSeconds = (datetime, withSeconds) => {
142
+ if (withSeconds) {
143
+ return `${datetime.substring(0, datetime.indexOf("Z"))}.000Z`;
144
+ }
145
+ return `${datetime.substring(0, datetime.lastIndexOf(":"))}:00.000Z`;
146
+ };
147
+
148
+ /**
149
+ * Return time value string off to seconds
150
+ *
151
+ * @param {string} datetime in ISO format
152
+ * @param {boolean} withSeconds to specify if seconds is needed or not
153
+ *
154
+ * @returns {string} just time after stripping of ms and seconds if selected to
155
+ */
156
+ export const timeCorrectedToSeconds = (datetime, withSeconds) => {
157
+ if (withSeconds) {
158
+ return datetime.substring(datetime.indexOf("T") + 1, datetime.indexOf("."));
159
+ }
160
+ return `${datetime.substring(
161
+ datetime.indexOf("T") + 1,
162
+ datetime.lastIndexOf(":")
163
+ )}:00`;
164
+ };
165
+
166
+ /**
167
+ * This function handles the cosmos blur handler of DateTime components
168
+ *
169
+ * @param {string | undefined} errorState for the selected datetime value
170
+ * @param {string} actualValue present in redux
171
+ * @param {string} formattedValue retrieved by trimming ISO to just Date/Time, also applying timezone if DateTime
172
+ * @param {object} actions object which has fire and blur callbacks
173
+ * @param {string} propName name of the property bound
174
+ * @param {object} pConn component's PConnect object which is useful to invoke validationApi
175
+ *
176
+ * @returns {void}
177
+ */
178
+ export const datetimeFireChangeBlurEvents = (
179
+ errorState,
180
+ actualValue,
181
+ formattedValue,
182
+ actions,
183
+ propName,
184
+ pConn
185
+ ) => {
186
+
187
+ // TODO - clean up, we should not rely on timestamp from cosmos to check InComplete validation
188
+ // above triggerFieldChange should have validated this
189
+ if (errorState) {
190
+ pConn.getValidationApi().validate(errorState);
191
+ }
192
+ // BUG-640834 In errorState presist old values avoiding store update & re-render.
193
+ else{
194
+ if (formattedValue !== actualValue) {
195
+ actions.updateFieldValue(propName, formattedValue);
196
+ }
197
+ actions.triggerFieldChange(propName, formattedValue);
198
+ }
199
+ };
200
+
201
+ /**
202
+ * Return Date format for the locale passed
203
+ *
204
+ * @param {string} locale locale string
205
+ * @param {object} options options for format string
206
+ * @returns {string} dateformat for the locale
207
+ * Example : getDateFormat("pl-PL") returns "DD.MM.YYYY"
208
+ */
209
+ export const getDateFormat = (locale, options) => {
210
+ return new Intl.DateTimeFormat(locale, options)
211
+ .formatToParts()
212
+ .map(({ type, value }) => {
213
+ switch (type) {
214
+ case "day":
215
+ return "DD";
216
+ case "month":
217
+ return "MM";
218
+ case "year":
219
+ return "YYYY";
220
+ case "hour":
221
+ return "hh";
222
+ case "minute":
223
+ return "mm";
224
+ case "second":
225
+ return "ss";
226
+ case "dayPeriod":
227
+ return "A";
228
+ case "literal":
229
+ return value;
230
+ default:
231
+ return "";
232
+ }
233
+ })
234
+ .join("");
235
+ };
236
+
237
+ /**
238
+ * Return boolean for the locale passed to specify if locale uses 12 hour format
239
+ *
240
+ * @param {string} locale locale string
241
+ * @returns {boolean} True or False for the locale
242
+ * Example : getDateFormat("pl-PL") returns false
243
+ */
244
+ export const is12HClockFormat = (locale) => {
245
+ const meridiem = new Intl.DateTimeFormat(locale, {
246
+ hour: "numeric"
247
+ })
248
+ .formatToParts()
249
+ .find(({ type }) => type === "dayPeriod");
250
+ return !!(meridiem === null || meridiem === undefined
251
+ ? undefined
252
+ : meridiem.value);
253
+ };
254
+
255
+ /**
256
+ * Return Option object for Time formatting
257
+ *
258
+ * @param {boolean} withSeconds true or false depending on seconds to be included
259
+ * @param {boolean} is12h 12 hour format
260
+ * @returns {object} options object time formatting
261
+ * Example : getTimeOptions(false, true) returns {hour: 'numeric',minute: 'numeric',hour12: true}
262
+ */
263
+ export const getTimeOptions = (withSeconds, is12h = false) => {
264
+ return {
265
+ hour: "numeric",
266
+ minute: "numeric",
267
+ ...(withSeconds && { second: "numeric" }),
268
+ hour12: is12h
269
+ };
270
+ };
271
+
272
+ /**
273
+ * Return Option object for Datetime formatting
274
+ *
275
+ * @param {boolean} withSeconds true or false depending on seconds to be included
276
+ * @param {boolean} is12h 12 hour format
277
+ * @returns {object} options object datetime formatting
278
+ * Example : getDateTimeOptions(false, true) returns {year: 'numeric',month: 'numeric',day: 'numeric',hour: 'numeric',minute: 'numeric',hour12: true}
279
+ */
280
+ export const getDateTimeOptions = (withSeconds, is12h = false) => {
281
+ return {
282
+ year: "numeric",
283
+ month: "numeric",
284
+ day: "numeric",
285
+ ...getTimeOptions(withSeconds, is12h)
286
+ };
287
+ };
@@ -0,0 +1,328 @@
1
+ /* eslint-disable no-undef */
2
+ import dayjs from 'dayjs';
3
+
4
+ const relativeTime = require('dayjs/plugin/relativeTime');
5
+ const utc = require('dayjs/plugin/utc');
6
+
7
+ dayjs.extend(relativeTime);
8
+ dayjs.extend(utc);
9
+
10
+ export const datetimedisplayformatter = (formatter) => {
11
+ const objectvalues = {};
12
+ switch (formatter) {
13
+ case "DateTime-Long": {
14
+ objectvalues.variantVal = "datetime";
15
+ objectvalues.formatVal = "long";
16
+ break;
17
+ }
18
+ case "DateTime-Short": {
19
+ objectvalues.variantVal = "date";
20
+ objectvalues.formatVal = "short";
21
+ break;
22
+ }
23
+ case "DateTime-Since": {
24
+ objectvalues.variantVal = "relative";
25
+ break;
26
+ }
27
+ case "Time-Only": {
28
+ objectvalues.variantVal = "time";
29
+ objectvalues.formatVal = "short";
30
+ break;
31
+ }
32
+ // no default
33
+ }
34
+ return objectvalues;
35
+ };
36
+
37
+ export const formatExists = (formatterVal) => {
38
+ const formatterValues = [
39
+ "DateTime-Long",
40
+ "DateTime-Short",
41
+ "DateTime-Since",
42
+ "Time-Only"
43
+ ];
44
+ let isformatter = false;
45
+ if (formatterValues.includes(formatterVal)) {
46
+ isformatter = true;
47
+ }
48
+ return isformatter;
49
+ };
50
+
51
+
52
+
53
+ /**
54
+ * Return relative time in fromNow for the given datetime
55
+ * @description Convert and return the given datetime in dayJSObject
56
+ *
57
+ * @param {string} text datetime
58
+ * @returns {object} datetime as a dayjs object
59
+ */
60
+ export const getDayJSObject = (text) => {
61
+ const momObj = dayjs(text);
62
+ if (momObj.isValid()) return momObj;
63
+ const timeStamp = text;
64
+ const isDateTime = timeStamp.indexOf("GMT") !== -1;
65
+ const year = parseInt(timeStamp.substr(0, 4), 10);
66
+ const month = parseInt(timeStamp.substr(4, 2), 10) - 1;
67
+ const day = parseInt(timeStamp.substr(6, 2), 10);
68
+
69
+ const CurrentTz = PCore.getLocaleUtils().getTimeZoneInUse();
70
+
71
+ let mom = new Date();
72
+
73
+ mom.setUTCDate(day);
74
+ mom.setUTCMonth(month);
75
+ mom.setUTCFullYear(year);
76
+
77
+ /* istanbul ignore else */
78
+ if (isDateTime) {
79
+ const hours = parseInt(timeStamp.substr(9, 2), 10);
80
+ const minutes = parseInt(timeStamp.substr(11, 2), 10);
81
+ const seconds = parseInt(timeStamp.substr(13, 2), 10);
82
+ const ms = parseInt(timeStamp.substr(16, 3), 10);
83
+ mom.setUTCHours(hours);
84
+ mom.setUTCMinutes(minutes);
85
+ mom.setUTCSeconds(seconds);
86
+ mom.setUTCMilliseconds(ms);
87
+ }
88
+
89
+ mom = dayjs(
90
+ mom.toLocaleString("en-US", {
91
+ timeZone: CurrentTz
92
+ })
93
+ );
94
+
95
+ return mom;
96
+ };
97
+
98
+ /**
99
+ * Return relative time in fromNow for the given datetime
100
+ *
101
+ * @param {string} time datetime
102
+ * @returns {object} relative time from now
103
+ */
104
+ export const getRelativeTime = (time) => {
105
+ let relativetime = "";
106
+ if (dayjs(time).isUTC()) {
107
+ relativetime = dayjs(time).fromNow();
108
+ } else {
109
+ const dayjstime = getDayJSObject(time);
110
+ relativetime = dayjs(dayjstime).fromNow();
111
+ }
112
+ return relativetime;
113
+ };
114
+
115
+ /**
116
+ * Return year for the date passed
117
+ *
118
+ * @param {string} value from which Year needs to be taken out
119
+ * @returns {number} year for the date passed
120
+ */
121
+ export const getFullYear = (value) =>
122
+ value ? new Date(value).getFullYear() : new Date().getFullYear();
123
+
124
+ /**
125
+ * Return maxDate for the date passed
126
+ *
127
+ * @param {number} nextYears next number of years
128
+ * @param {number} currentYear current year
129
+ * @param {number} yearFromValue year set on value in redux
130
+ *
131
+ * @returns {string} maxDate calculated based on inputs
132
+ */
133
+ export const getMaxDate = (nextYears, currentYear, yearFromValue) => {
134
+ if (Number.isNaN(nextYears)) {
135
+ nextYears = 20;
136
+ }
137
+ let maxYear = currentYear + nextYears;
138
+ if (yearFromValue > maxYear) {
139
+ maxYear = yearFromValue;
140
+ }
141
+ return `${maxYear}-01-01`;
142
+ };
143
+
144
+ /**
145
+ * Return minDate for the date passed
146
+ *
147
+ * @param {number} previousYears previous number of years
148
+ * @param {number} currentYear current year
149
+ * @param {number} yearFromValue year set on value in redux
150
+ *
151
+ * @returns {string} minDate calculated based on inputs
152
+ */
153
+ export const getMinDate = (previousYears, currentYear, yearFromValue) => {
154
+ if (Number.isNaN(previousYears)) {
155
+ previousYears = 100;
156
+ }
157
+ let minYear = currentYear - previousYears;
158
+ if (yearFromValue < minYear) {
159
+ minYear = yearFromValue;
160
+ }
161
+ return `${minYear}-12-31`;
162
+ };
163
+
164
+ /**
165
+ * Return clockFormat after parsing
166
+ *
167
+ * @param {number | string} clockFormat chosen by user
168
+ *
169
+ * @returns {number} clockFormat
170
+ */
171
+ export const parseClockFormat = (clockFormat) =>
172
+ typeof clockFormat === "string" ? parseInt(clockFormat, 10) : clockFormat;
173
+
174
+ /**
175
+ * Return datetime value string off to seconds
176
+ *
177
+ * @param {string} datetime in ISO format
178
+ * @param {boolean} withSeconds to specify if seconds is needed or not
179
+ *
180
+ * @returns {string} datetime after stripping of ms and seconds if selected to
181
+ */
182
+ export const correctDateTimeToSeconds = (datetime, withSeconds) => {
183
+ if (withSeconds) {
184
+ return `${datetime.substring(0, datetime.indexOf("Z"))}.000Z`;
185
+ }
186
+ return `${datetime.substring(0, datetime.lastIndexOf(":"))}:00.000Z`;
187
+ };
188
+
189
+ /**
190
+ * Return time value string off to seconds
191
+ *
192
+ * @param {string} datetime in ISO format
193
+ * @param {boolean} withSeconds to specify if seconds is needed or not
194
+ *
195
+ * @returns {string} just time after stripping of ms and seconds if selected to
196
+ */
197
+ export const timeCorrectedToSeconds = (datetime, withSeconds) => {
198
+ if (withSeconds) {
199
+ return datetime.substring(datetime.indexOf("T") + 1, datetime.indexOf("."));
200
+ }
201
+ return `${datetime.substring(
202
+ datetime.indexOf("T") + 1,
203
+ datetime.lastIndexOf(":")
204
+ )}:00`;
205
+ };
206
+
207
+ /**
208
+ * This function handles the cosmos blur handler of DateTime components
209
+ *
210
+ * @param {string | undefined} errorState for the selected datetime value
211
+ * @param {string} actualValue present in redux
212
+ * @param {string} formattedValue retrieved by trimming ISO to just Date/Time, also applying timezone if DateTime
213
+ * @param {object} actions object which has fire and blur callbacks
214
+ * @param {string} propName name of the property bound
215
+ * @param {object} pConn component's PConnect object which is useful to invoke validationApi
216
+ *
217
+ * @returns {void}
218
+ */
219
+ export const datetimeFireChangeBlurEvents = (
220
+ errorState,
221
+ actualValue,
222
+ formattedValue,
223
+ actions,
224
+ propName,
225
+ pConn
226
+ ) => {
227
+
228
+ // TODO - clean up, we should not rely on timestamp from cosmos to check InComplete validation
229
+ // above triggerFieldChange should have validated this
230
+ if (errorState) {
231
+ pConn.getValidationApi().validate(errorState);
232
+ }
233
+ // BUG-640834 In errorState presist old values avoiding store update & re-render.
234
+ else{
235
+ if (formattedValue !== actualValue) {
236
+ actions.updateFieldValue(propName, formattedValue);
237
+ }
238
+ actions.triggerFieldChange(propName, formattedValue);
239
+ }
240
+ };
241
+
242
+ /**
243
+ * Return Date format for the locale passed
244
+ *
245
+ * @param {string} locale locale string
246
+ * @param {object} options options for format string
247
+ * @returns {string} dateformat for the locale
248
+ * Example : getDateFormat("pl-PL") returns "DD.MM.YYYY"
249
+ */
250
+ export const getDateFormat = (locale, options) => {
251
+ return new Intl.DateTimeFormat(locale, options)
252
+ .formatToParts()
253
+ .map(({ type, value }) => {
254
+ switch (type) {
255
+ case "day":
256
+ return "DD";
257
+ case "month":
258
+ return "MM";
259
+ case "year":
260
+ return "YYYY";
261
+ case "hour":
262
+ return "hh";
263
+ case "minute":
264
+ return "mm";
265
+ case "second":
266
+ return "ss";
267
+ case "dayPeriod":
268
+ return "A";
269
+ case "literal":
270
+ return value;
271
+ default:
272
+ return "";
273
+ }
274
+ })
275
+ .join("");
276
+ };
277
+
278
+ /**
279
+ * Return boolean for the locale passed to specify if locale uses 12 hour format
280
+ *
281
+ * @param {string} locale locale string
282
+ * @returns {boolean} True or False for the locale
283
+ * Example : getDateFormat("pl-PL") returns false
284
+ */
285
+ export const is12HClockFormat = (locale) => {
286
+ const meridiem = new Intl.DateTimeFormat(locale, {
287
+ hour: "numeric"
288
+ })
289
+ .formatToParts()
290
+ .find(({ type }) => type === "dayPeriod");
291
+ return !!(meridiem === null || meridiem === undefined
292
+ ? undefined
293
+ : meridiem.value);
294
+ };
295
+
296
+ /**
297
+ * Return Option object for Time formatting
298
+ *
299
+ * @param {boolean} withSeconds true or false depending on seconds to be included
300
+ * @param {boolean} is12h 12 hour format
301
+ * @returns {object} options object time formatting
302
+ * Example : getTimeOptions(false, true) returns {hour: 'numeric',minute: 'numeric',hour12: true}
303
+ */
304
+ export const getTimeOptions = (withSeconds, is12h = false) => {
305
+ return {
306
+ hour: "numeric",
307
+ minute: "numeric",
308
+ ...(withSeconds && { second: "numeric" }),
309
+ hour12: is12h
310
+ };
311
+ };
312
+
313
+ /**
314
+ * Return Option object for Datetime formatting
315
+ *
316
+ * @param {boolean} withSeconds true or false depending on seconds to be included
317
+ * @param {boolean} is12h 12 hour format
318
+ * @returns {object} options object datetime formatting
319
+ * Example : getDateTimeOptions(false, true) returns {year: 'numeric',month: 'numeric',day: 'numeric',hour: 'numeric',minute: 'numeric',hour12: true}
320
+ */
321
+ export const getDateTimeOptions = (withSeconds, is12h = false) => {
322
+ return {
323
+ year: "numeric",
324
+ month: "numeric",
325
+ day: "numeric",
326
+ ...getTimeOptions(withSeconds, is12h)
327
+ };
328
+ };
@@ -0,0 +1,73 @@
1
+ import { withKnobs } from '@storybook/addon-knobs';
2
+ import { configProps, stateProps } from './mock.stories';
3
+ import {{COMPONENT_CLASS_NAME}} from './index.jsx';
4
+
5
+ export default {
6
+ title: '{{COMPONENT_CLASS_NAME}}',
7
+ decorators: [withKnobs],
8
+ component: {{COMPONENT_CLASS_NAME}}
9
+ };
10
+
11
+ if (!window.PCore) {
12
+ window.PCore = {};
13
+ }
14
+
15
+ window.PCore.getEnvironmentInfo = () => {
16
+ return {
17
+ getTimeZone: () => {
18
+ return '';
19
+ }
20
+ };
21
+ };
22
+
23
+ export const base{{COMPONENT_CLASS_NAME}} = () => {
24
+ const props = {
25
+ getPConnect: () => {
26
+ return {
27
+ getActionsApi: () => {
28
+ return {
29
+ updateFieldValue: () => {/* nothing */},
30
+ triggerFieldChange: () => {/* nothing */}
31
+ };
32
+ },
33
+ getValidationApi: () => {
34
+ return {
35
+ validate: () => {/* nothing */}
36
+ };
37
+ },
38
+ getStateProps: () => {
39
+ return stateProps;
40
+ },
41
+ getConfigProps: () => {
42
+ return configProps;
43
+ },
44
+ ignoreSuggestion: () => {/* nothing */},
45
+ acceptSuggestion: () => {/* nothing */},
46
+ clearErrorMessages: () => {/* nothing */}
47
+ };
48
+ },
49
+ value: configProps.value,
50
+ validatemessage: configProps.validatemessage,
51
+ label: configProps.label,
52
+ hideLabel: configProps.hideLabel,
53
+ helperText: configProps.helperText,
54
+ withSeconds: configProps.withSeconds,
55
+ nextYearRange: configProps.nextYearRange,
56
+ previousYearRange: configProps.previousYearRange,
57
+ showWeekNumber: configProps.showWeekNumber,
58
+ testId: configProps.testId,
59
+ additionalProps: configProps.additionalProps,
60
+ displayMode: configProps.displayMode,
61
+ variant: configProps.variant,
62
+ hasSuggestions: configProps.hasSuggestions,
63
+ disabled: configProps.disabled,
64
+ readOnly: configProps.readOnly,
65
+ required: configProps.required
66
+ };
67
+
68
+ return (
69
+ <>
70
+ <{{COMPONENT_CLASS_NAME}} {...props} />
71
+ </>
72
+ );
73
+ };