@carlonicora/nextjs-jsonapi 6.24.0 → 6.26.0

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 (250) hide show
  1. package/dist/{BlockNoteEditor-MONT74RQ.js → BlockNoteEditor-JHXDOCS5.js} +28 -25
  2. package/dist/BlockNoteEditor-JHXDOCS5.js.map +1 -0
  3. package/dist/{BlockNoteEditor-ENDOVTAW.mjs → BlockNoteEditor-RVDSB6TF.mjs} +13 -10
  4. package/dist/{BlockNoteEditor-ENDOVTAW.mjs.map → BlockNoteEditor-RVDSB6TF.mjs.map} +1 -1
  5. package/dist/{BlockNoteViewer-2TJZ6JET.mjs → BlockNoteViewer-76CKL6W5.mjs} +8 -6
  6. package/dist/{BlockNoteViewer-2TJZ6JET.mjs.map → BlockNoteViewer-76CKL6W5.mjs.map} +1 -1
  7. package/dist/{BlockNoteViewer-K2HBF3IP.js → BlockNoteViewer-B25WKYQP.js} +9 -7
  8. package/dist/BlockNoteViewer-B25WKYQP.js.map +1 -0
  9. package/dist/JsonApiRequest-OKNQZLS6.js +26 -0
  10. package/dist/{JsonApiRequest-KC6DOHKT.js.map → JsonApiRequest-OKNQZLS6.js.map} +1 -1
  11. package/dist/{JsonApiRequest-ADLBJ5RX.mjs → JsonApiRequest-WNPDS356.mjs} +2 -2
  12. package/dist/billing/index.js +504 -517
  13. package/dist/billing/index.js.map +1 -1
  14. package/dist/billing/index.mjs +20 -33
  15. package/dist/billing/index.mjs.map +1 -1
  16. package/dist/{chunk-VNUT2D27.mjs → chunk-2PWYG2WJ.mjs} +2 -2
  17. package/dist/{chunk-W4ML6D2X.mjs → chunk-3U7YJ73T.mjs} +7 -7
  18. package/dist/{chunk-BQ2WAG4K.js → chunk-3VNDFKT7.js} +19 -19
  19. package/dist/{chunk-BQ2WAG4K.js.map → chunk-3VNDFKT7.js.map} +1 -1
  20. package/dist/{chunk-BE6UMM5X.mjs → chunk-47HNJQ7U.mjs} +3 -3
  21. package/dist/chunk-5T2AQMQ2.mjs +90 -0
  22. package/dist/chunk-5T2AQMQ2.mjs.map +1 -0
  23. package/dist/{chunk-A5M3MORY.js → chunk-5WM72MLE.js} +3 -3
  24. package/dist/{chunk-A5M3MORY.js.map → chunk-5WM72MLE.js.map} +1 -1
  25. package/dist/{chunk-OZADFYE7.mjs → chunk-64REWDSK.mjs} +308 -241
  26. package/dist/chunk-64REWDSK.mjs.map +1 -0
  27. package/dist/{chunk-S7SPAC6X.mjs → chunk-73NKUBMP.mjs} +3 -3
  28. package/dist/chunk-743M4TIB.mjs +76 -0
  29. package/dist/chunk-743M4TIB.mjs.map +1 -0
  30. package/dist/{chunk-HN7L6RRW.js → chunk-77JC2UCF.js} +903 -955
  31. package/dist/chunk-77JC2UCF.js.map +1 -0
  32. package/dist/{chunk-7OIWOPM5.mjs → chunk-7MGXQIEP.mjs} +4 -3
  33. package/dist/chunk-7MGXQIEP.mjs.map +1 -0
  34. package/dist/{chunk-YTDGYI62.mjs → chunk-DWPHHUMV.mjs} +3 -3
  35. package/dist/{chunk-SO3YUCL6.js → chunk-F3EVYBMA.js} +6 -5
  36. package/dist/chunk-F3EVYBMA.js.map +1 -0
  37. package/dist/{chunk-53SD4YRF.js → chunk-FBHUUPRV.js} +5 -5
  38. package/dist/{chunk-53SD4YRF.js.map → chunk-FBHUUPRV.js.map} +1 -1
  39. package/dist/{chunk-T6G2F2BK.mjs → chunk-FJUKLVVX.mjs} +16 -68
  40. package/dist/chunk-FJUKLVVX.mjs.map +1 -0
  41. package/dist/chunk-HROKKUBQ.js +156 -0
  42. package/dist/chunk-HROKKUBQ.js.map +1 -0
  43. package/dist/{chunk-BDWV4KYR.js → chunk-JE6QWCNE.js} +1386 -1319
  44. package/dist/chunk-JE6QWCNE.js.map +1 -0
  45. package/dist/{chunk-RCOKQ3R4.js → chunk-LNO2JLU3.js} +2 -2
  46. package/dist/{chunk-RCOKQ3R4.js.map → chunk-LNO2JLU3.js.map} +1 -1
  47. package/dist/{chunk-TMV7TL7O.mjs → chunk-M7YK5CCE.mjs} +8 -6
  48. package/dist/{chunk-TMV7TL7O.mjs.map → chunk-M7YK5CCE.mjs.map} +1 -1
  49. package/dist/{chunk-GMMDXINC.js → chunk-N3NQS7X6.js} +12 -12
  50. package/dist/{chunk-GMMDXINC.js.map → chunk-N3NQS7X6.js.map} +1 -1
  51. package/dist/chunk-NP3AFULU.js +76 -0
  52. package/dist/chunk-NP3AFULU.js.map +1 -0
  53. package/dist/{chunk-TNTCLVUR.js → chunk-ONU4WCDG.js} +17 -15
  54. package/dist/chunk-ONU4WCDG.js.map +1 -0
  55. package/dist/{chunk-YSE2Z4RB.js → chunk-PQQFOONG.js} +12 -12
  56. package/dist/{chunk-YSE2Z4RB.js.map → chunk-PQQFOONG.js.map} +1 -1
  57. package/dist/chunk-RW6XZGZG.mjs +156 -0
  58. package/dist/chunk-RW6XZGZG.mjs.map +1 -0
  59. package/dist/chunk-SYMI4IDW.js +90 -0
  60. package/dist/chunk-SYMI4IDW.js.map +1 -0
  61. package/dist/{chunk-N2BFT7KI.mjs → chunk-W7U6O3OE.mjs} +2 -71
  62. package/dist/chunk-W7U6O3OE.mjs.map +1 -0
  63. package/dist/{chunk-YMCL3JXZ.mjs → chunk-YPBIPE2B.mjs} +2 -2
  64. package/dist/{chunk-P7L6OFX5.js → chunk-Z6T2575A.js} +12 -81
  65. package/dist/chunk-Z6T2575A.js.map +1 -0
  66. package/dist/client/index.js +13 -10
  67. package/dist/client/index.js.map +1 -1
  68. package/dist/client/index.mjs +17 -14
  69. package/dist/components/forms/DatePickerPopover.d.ts.map +1 -1
  70. package/dist/components/forms/DateRangeSelector.d.ts.map +1 -1
  71. package/dist/components/forms/FormDate.d.ts.map +1 -1
  72. package/dist/components/forms/FormDateTime.d.ts.map +1 -1
  73. package/dist/components/forms/time-cycle.d.ts +14 -0
  74. package/dist/components/forms/time-cycle.d.ts.map +1 -0
  75. package/dist/components/index.js +11 -8
  76. package/dist/components/index.js.map +1 -1
  77. package/dist/components/index.mjs +10 -7
  78. package/dist/components/tables/cells/cell.date.d.ts.map +1 -1
  79. package/dist/components/tables/cells/cell.dateTime.d.ts.map +1 -1
  80. package/dist/contexts/DateLocaleContext.d.ts +56 -0
  81. package/dist/contexts/DateLocaleContext.d.ts.map +1 -0
  82. package/dist/contexts/index.d.ts +1 -0
  83. package/dist/contexts/index.d.ts.map +1 -1
  84. package/dist/contexts/index.js +24 -8
  85. package/dist/contexts/index.js.map +1 -1
  86. package/dist/contexts/index.mjs +23 -7
  87. package/dist/core/index.js +17 -6
  88. package/dist/core/index.js.map +1 -1
  89. package/dist/core/index.mjs +19 -8
  90. package/dist/date-locale/index.d.ts +2 -0
  91. package/dist/date-locale/index.d.ts.map +1 -0
  92. package/dist/date-locale/index.js +21 -0
  93. package/dist/date-locale/index.js.map +1 -0
  94. package/dist/date-locale/index.mjs +21 -0
  95. package/dist/email-automations/index.js +131 -123
  96. package/dist/email-automations/index.js.map +1 -1
  97. package/dist/email-automations/index.mjs +23 -15
  98. package/dist/email-automations/index.mjs.map +1 -1
  99. package/dist/features/account-deletion/components/AccountDeletionAdminTrigger.d.ts.map +1 -1
  100. package/dist/features/analytics/components/AnalyticsJourneyContainer.d.ts.map +1 -1
  101. package/dist/features/analytics/components/AnalyticsSessionsTable.d.ts.map +1 -1
  102. package/dist/features/analytics/index.js +154 -147
  103. package/dist/features/analytics/index.js.map +1 -1
  104. package/dist/features/analytics/index.mjs +32 -25
  105. package/dist/features/analytics/index.mjs.map +1 -1
  106. package/dist/features/analytics/server.js +11 -9
  107. package/dist/features/analytics/server.js.map +1 -1
  108. package/dist/features/analytics/server.mjs +9 -7
  109. package/dist/features/analytics/server.mjs.map +1 -1
  110. package/dist/features/billing/components/utils/date.d.ts +3 -3
  111. package/dist/features/billing/components/utils/format-options.d.ts +6 -4
  112. package/dist/features/billing/components/utils/format-options.d.ts.map +1 -1
  113. package/dist/features/billing/components/utils/useBillingFormatOptions.d.ts +5 -1
  114. package/dist/features/billing/components/utils/useBillingFormatOptions.d.ts.map +1 -1
  115. package/dist/features/billing/stripe-usage/components/details/UsageSummaryCard.d.ts.map +1 -1
  116. package/dist/features/billing/stripe-usage/components/lists/UsageHistoryTable.d.ts.map +1 -1
  117. package/dist/features/blog/components/admin/BlogTranslationStatus.d.ts.map +1 -1
  118. package/dist/features/blog/components/public/BlogPostMeta.d.ts.map +1 -1
  119. package/dist/features/blog/hooks/useBlogPostTableStructure.d.ts.map +1 -1
  120. package/dist/features/blog/index.js +168 -162
  121. package/dist/features/blog/index.js.map +1 -1
  122. package/dist/features/blog/index.mjs +25 -19
  123. package/dist/features/blog/index.mjs.map +1 -1
  124. package/dist/features/blog/server.js +29 -27
  125. package/dist/features/blog/server.js.map +1 -1
  126. package/dist/features/blog/server.mjs +8 -6
  127. package/dist/features/blog/server.mjs.map +1 -1
  128. package/dist/features/email-automation/hooks/useEmailAutomationEnrollmentTableStructure.d.ts.map +1 -1
  129. package/dist/features/handbook/components/parts/HandbookIndexStatus.d.ts.map +1 -1
  130. package/dist/features/help/components/HelpArticleBody.d.ts.map +1 -1
  131. package/dist/features/help/index.js +48 -43
  132. package/dist/features/help/index.js.map +1 -1
  133. package/dist/features/help/index.mjs +15 -10
  134. package/dist/features/help/index.mjs.map +1 -1
  135. package/dist/features/notification/components/notifications/Notification.d.ts +2 -1
  136. package/dist/features/notification/components/notifications/Notification.d.ts.map +1 -1
  137. package/dist/features/notification/contexts/NotificationContext.d.ts.map +1 -1
  138. package/dist/features/notification/hooks/useNotificationTableStructure.d.ts.map +1 -1
  139. package/dist/features/oauth/components/OAuthClientCard.d.ts.map +1 -1
  140. package/dist/features/oauth/components/OAuthClientDetail.d.ts.map +1 -1
  141. package/dist/features/tokenusage/index.js +133 -130
  142. package/dist/features/tokenusage/index.js.map +1 -1
  143. package/dist/features/tokenusage/index.mjs +10 -7
  144. package/dist/features/tokenusage/index.mjs.map +1 -1
  145. package/dist/features/tokenusage/lib/formatters.d.ts +6 -3
  146. package/dist/features/tokenusage/lib/formatters.d.ts.map +1 -1
  147. package/dist/index.js +19 -7
  148. package/dist/index.js.map +1 -1
  149. package/dist/index.mjs +23 -11
  150. package/dist/local-transport-AT4TE264.js +15 -0
  151. package/dist/{local-transport-MJPOKPTU.js.map → local-transport-AT4TE264.js.map} +1 -1
  152. package/dist/{local-transport-RVD4FZGA.mjs → local-transport-KWEUZ4GX.mjs} +5 -5
  153. package/dist/offline/index.js +56 -54
  154. package/dist/offline/index.js.map +1 -1
  155. package/dist/offline/index.mjs +23 -21
  156. package/dist/offline/index.mjs.map +1 -1
  157. package/dist/{request-4AWGPIGH.mjs → request-6GAIWWTG.mjs} +2 -2
  158. package/dist/{request-H5FZBZA2.js → request-BWO4Y434.js} +3 -3
  159. package/dist/{request-H5FZBZA2.js.map → request-BWO4Y434.js.map} +1 -1
  160. package/dist/server/ServerSession.d.ts +2 -0
  161. package/dist/server/ServerSession.d.ts.map +1 -1
  162. package/dist/server/index.js +10 -8
  163. package/dist/server/index.js.map +1 -1
  164. package/dist/server/index.mjs +9 -7
  165. package/dist/utils/date-formatter.d.ts +45 -4
  166. package/dist/utils/date-formatter.d.ts.map +1 -1
  167. package/dist/utils/index.d.ts +1 -1
  168. package/dist/utils/index.d.ts.map +1 -1
  169. package/dist/utils/toast.d.ts +2 -0
  170. package/dist/utils/toast.d.ts.map +1 -1
  171. package/dist/write-through-KNRI5L4V.mjs +15 -0
  172. package/dist/write-through-KNRI5L4V.mjs.map +1 -0
  173. package/dist/write-through-MYHQ6GJU.js +15 -0
  174. package/dist/{write-through-HE2QSOVI.js.map → write-through-MYHQ6GJU.js.map} +1 -1
  175. package/messages/en.json +1 -0
  176. package/messages/it.json +1 -0
  177. package/package.json +6 -1
  178. package/src/components/forms/DatePickerPopover.tsx +5 -3
  179. package/src/components/forms/DateRangeSelector.tsx +9 -7
  180. package/src/components/forms/FormDate.tsx +5 -3
  181. package/src/components/forms/FormDateTime.tsx +75 -39
  182. package/src/components/forms/__tests__/time-cycle.spec.ts +37 -0
  183. package/src/components/forms/time-cycle.ts +27 -0
  184. package/src/components/tables/cells/cell.date.tsx +3 -5
  185. package/src/components/tables/cells/cell.dateTime.tsx +3 -7
  186. package/src/contexts/DateLocaleContext.tsx +106 -0
  187. package/src/contexts/__tests__/DateLocaleContext.spec.tsx +175 -0
  188. package/src/contexts/index.ts +1 -0
  189. package/src/date-locale/index.ts +12 -0
  190. package/src/features/account-deletion/components/AccountDeletionAdminTrigger.tsx +3 -4
  191. package/src/features/analytics/components/AnalyticsJourneyContainer.tsx +8 -8
  192. package/src/features/analytics/components/AnalyticsSessionsTable.tsx +4 -6
  193. package/src/features/auth/components/two-factor/PasskeyList.tsx +3 -3
  194. package/src/features/auth/components/two-factor/TotpAuthenticatorList.tsx +3 -3
  195. package/src/features/billing/components/utils/__tests__/billing-formatters.spec.ts +14 -6
  196. package/src/features/billing/components/utils/date.ts +5 -5
  197. package/src/features/billing/components/utils/format-options.ts +6 -4
  198. package/src/features/billing/components/utils/useBillingFormatOptions.ts +8 -2
  199. package/src/features/billing/stripe-usage/components/details/UsageSummaryCard.tsx +4 -12
  200. package/src/features/billing/stripe-usage/components/lists/UsageHistoryTable.tsx +4 -17
  201. package/src/features/blog/components/admin/BlogTranslationStatus.tsx +3 -2
  202. package/src/features/blog/components/public/BlogPostMeta.tsx +5 -4
  203. package/src/features/blog/components/public/__tests__/BlogList.spec.tsx +1 -2
  204. package/src/features/blog/components/public/__tests__/BlogPostView.spec.tsx +2 -3
  205. package/src/features/blog/hooks/useBlogPostTableStructure.tsx +4 -8
  206. package/src/features/email-automation/hooks/useEmailAutomationEnrollmentTableStructure.tsx +11 -5
  207. package/src/features/email-blast/components/containers/EmailBlastContainer.tsx +3 -3
  208. package/src/features/email-blast/hooks/useEmailBlastTableStructure.tsx +4 -4
  209. package/src/features/handbook/components/parts/HandbookIndexStatus.tsx +4 -3
  210. package/src/features/help/components/HelpArticleBody.tsx +4 -3
  211. package/src/features/notification/components/notifications/Notification.tsx +38 -7
  212. package/src/features/notification/contexts/NotificationContext.tsx +6 -3
  213. package/src/features/notification/hooks/useNotificationTableStructure.tsx +6 -5
  214. package/src/features/oauth/components/OAuthClientCard.tsx +8 -5
  215. package/src/features/oauth/components/OAuthClientDetail.tsx +3 -6
  216. package/src/features/tokenusage/lib/__tests__/formatters.spec.ts +19 -0
  217. package/src/features/tokenusage/lib/formatters.ts +11 -6
  218. package/src/features/waitlist/hooks/useWaitlistTableStructure.tsx +5 -5
  219. package/src/server/ServerSession.ts +3 -0
  220. package/src/server/__tests__/ServerSession.read.spec.ts +18 -1
  221. package/src/utils/__tests__/date-formatter.spec.ts +134 -10
  222. package/src/utils/__tests__/toast.spec.ts +39 -0
  223. package/src/utils/date-formatter.ts +200 -44
  224. package/src/utils/index.ts +11 -1
  225. package/src/utils/toast.ts +2 -0
  226. package/dist/BlockNoteEditor-MONT74RQ.js.map +0 -1
  227. package/dist/BlockNoteViewer-K2HBF3IP.js.map +0 -1
  228. package/dist/JsonApiRequest-KC6DOHKT.js +0 -26
  229. package/dist/chunk-7OIWOPM5.mjs.map +0 -1
  230. package/dist/chunk-BDWV4KYR.js.map +0 -1
  231. package/dist/chunk-HN7L6RRW.js.map +0 -1
  232. package/dist/chunk-N2BFT7KI.mjs.map +0 -1
  233. package/dist/chunk-OZADFYE7.mjs.map +0 -1
  234. package/dist/chunk-P7L6OFX5.js.map +0 -1
  235. package/dist/chunk-SO3YUCL6.js.map +0 -1
  236. package/dist/chunk-T6G2F2BK.mjs.map +0 -1
  237. package/dist/chunk-TNTCLVUR.js.map +0 -1
  238. package/dist/local-transport-MJPOKPTU.js +0 -15
  239. package/dist/write-through-7I3LA2WN.mjs +0 -15
  240. package/dist/write-through-HE2QSOVI.js +0 -15
  241. /package/dist/{JsonApiRequest-ADLBJ5RX.mjs.map → JsonApiRequest-WNPDS356.mjs.map} +0 -0
  242. /package/dist/{chunk-VNUT2D27.mjs.map → chunk-2PWYG2WJ.mjs.map} +0 -0
  243. /package/dist/{chunk-W4ML6D2X.mjs.map → chunk-3U7YJ73T.mjs.map} +0 -0
  244. /package/dist/{chunk-BE6UMM5X.mjs.map → chunk-47HNJQ7U.mjs.map} +0 -0
  245. /package/dist/{chunk-S7SPAC6X.mjs.map → chunk-73NKUBMP.mjs.map} +0 -0
  246. /package/dist/{chunk-YTDGYI62.mjs.map → chunk-DWPHHUMV.mjs.map} +0 -0
  247. /package/dist/{chunk-YMCL3JXZ.mjs.map → chunk-YPBIPE2B.mjs.map} +0 -0
  248. /package/dist/{local-transport-RVD4FZGA.mjs.map → date-locale/index.mjs.map} +0 -0
  249. /package/dist/{request-4AWGPIGH.mjs.map → local-transport-KWEUZ4GX.mjs.map} +0 -0
  250. /package/dist/{write-through-7I3LA2WN.mjs.map → request-6GAIWWTG.mjs.map} +0 -0
@@ -0,0 +1,156 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
4
+
5
+ // src/utils/date-formatter.ts
6
+ var formatLocalDate = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (d) => {
7
+ const year = d.getFullYear();
8
+ const month = String(d.getMonth() + 1).padStart(2, "0");
9
+ const day = String(d.getDate()).padStart(2, "0");
10
+ return `${year}-${month}-${day}`;
11
+ }, "formatLocalDate");
12
+ var NUMERIC_DATE = { day: "2-digit", month: "2-digit", year: "numeric" };
13
+ var DATE_STYLE_OPTIONS = {
14
+ date: NUMERIC_DATE,
15
+ dateMedium: { dateStyle: "medium" },
16
+ dateLong: { dateStyle: "long" },
17
+ dateTime: { ...NUMERIC_DATE, hour: "numeric", minute: "2-digit" },
18
+ dateTimeMedium: { dateStyle: "medium", timeStyle: "short" },
19
+ dateTimeLong: { day: "numeric", month: "long", year: "numeric", hour: "numeric", minute: "2-digit" },
20
+ dateTimeSeconds: { ...NUMERIC_DATE, hour: "numeric", minute: "2-digit", second: "2-digit" },
21
+ time: { hour: "numeric", minute: "2-digit" },
22
+ weekdayDateTime: { weekday: "short", day: "numeric", month: "short", hour: "numeric", minute: "2-digit" },
23
+ weekdayDay: { weekday: "short", day: "numeric", month: "long", year: "numeric" },
24
+ monthYear: { month: "short", year: "numeric" },
25
+ monthYearLong: { month: "long", year: "numeric" },
26
+ month: { month: "short" },
27
+ monthLong: { month: "long" },
28
+ dayMonth: { day: "numeric", month: "short" },
29
+ weekday: { weekday: "short" },
30
+ weekdayLong: { weekday: "long" }
31
+ };
32
+ var PUBLIC_STYLE_MAP = {
33
+ date: "dateMedium",
34
+ dateTime: "dateTimeMedium",
35
+ dateTimeSeconds: "dateTimeMedium"
36
+ };
37
+ var formatterCache = /* @__PURE__ */ new Map();
38
+ var cachedDateTimeFormat = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (locale, key, options, timeZone) => {
39
+ const cacheKey = `${locale}|${key}|${_nullishCoalesce(timeZone, () => ( ""))}`;
40
+ let formatter = formatterCache.get(cacheKey);
41
+ if (!formatter) {
42
+ formatter = new Intl.DateTimeFormat(locale, timeZone ? { ...options, timeZone } : options);
43
+ formatterCache.set(cacheKey, formatter);
44
+ }
45
+ return formatter;
46
+ }, "cachedDateTimeFormat");
47
+ var relativeCache = /* @__PURE__ */ new Map();
48
+ var cachedRelativeTimeFormat = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (locale) => {
49
+ let formatter = relativeCache.get(locale);
50
+ if (!formatter) {
51
+ formatter = new Intl.RelativeTimeFormat(locale, { numeric: "always" });
52
+ relativeCache.set(locale, formatter);
53
+ }
54
+ return formatter;
55
+ }, "cachedRelativeTimeFormat");
56
+ var toValidDate = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (date) => {
57
+ if (date === void 0 || date === null) return void 0;
58
+ const value = date instanceof Date ? date : new Date(date);
59
+ return Number.isNaN(value.getTime()) ? void 0 : value;
60
+ }, "toValidDate");
61
+ var languageOf = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (tag) => tag.split("-")[0].toLowerCase(), "languageOf");
62
+ var MAX_ACCEPT_LANGUAGE_ENTRIES = 50;
63
+ function resolveDateLocale(params) {
64
+ const { appLocale, acceptLanguage } = params;
65
+ if (!acceptLanguage) return appLocale;
66
+ const appLanguage = languageOf(appLocale);
67
+ const entries = [];
68
+ const parts = acceptLanguage.split(",");
69
+ for (let index = 0; index < parts.length && entries.length < MAX_ACCEPT_LANGUAGE_ENTRIES; index++) {
70
+ const [rawTag, ...rawParams] = parts[index].split(";");
71
+ const tag = rawTag.trim();
72
+ if (!tag || tag === "*") continue;
73
+ let quality = 1;
74
+ const qualityParam = rawParams.map((param) => param.trim()).find((param) => param.startsWith("q="));
75
+ if (qualityParam !== void 0) {
76
+ const raw = qualityParam.slice(2);
77
+ quality = /^\d+(\.\d+)?$/.test(raw) ? Number(raw) : NaN;
78
+ }
79
+ if (!(quality > 0)) continue;
80
+ if (languageOf(tag) !== appLanguage) continue;
81
+ entries.push({ tag, quality, index });
82
+ }
83
+ entries.sort((a, b) => b.quality - a.quality || a.index - b.index);
84
+ for (const entry of entries) {
85
+ try {
86
+ const [supported] = Intl.DateTimeFormat.supportedLocalesOf([entry.tag]);
87
+ if (supported && languageOf(supported) === appLanguage) return supported;
88
+ } catch (e) {
89
+ }
90
+ }
91
+ return appLocale;
92
+ }
93
+ _chunk7QVYU63Ejs.__name.call(void 0, resolveDateLocale, "resolveDateLocale");
94
+ function formatDateStyle(params) {
95
+ const value = toValidDate(params.date);
96
+ if (!value) return "";
97
+ const style = params.isPublic && PUBLIC_STYLE_MAP[params.style] || params.style;
98
+ return cachedDateTimeFormat(params.locale, style, DATE_STYLE_OPTIONS[style], params.timeZone).format(value);
99
+ }
100
+ _chunk7QVYU63Ejs.__name.call(void 0, formatDateStyle, "formatDateStyle");
101
+ function formatRelativeDate(params) {
102
+ const value = toValidDate(params.date);
103
+ if (!value) return "";
104
+ const now = _nullishCoalesce(params.now, () => ( /* @__PURE__ */ new Date()));
105
+ const diff = now.getTime() - value.getTime();
106
+ const sign = diff < 0 ? 1 : -1;
107
+ const seconds = Math.floor(Math.abs(diff) / 1e3);
108
+ const minutes = Math.floor(seconds / 60);
109
+ const hours = Math.floor(minutes / 60);
110
+ const days = Math.floor(hours / 24);
111
+ const relative = cachedRelativeTimeFormat(params.locale);
112
+ if (days > 0) return relative.format(sign * days, "day");
113
+ if (hours > 0) return relative.format(sign * hours, "hour");
114
+ if (minutes > 0) return relative.format(sign * minutes, "minute");
115
+ return relative.format(sign * seconds, "second");
116
+ }
117
+ _chunk7QVYU63Ejs.__name.call(void 0, formatRelativeDate, "formatRelativeDate");
118
+ function usesTwelveHourClock(locale) {
119
+ const hourCycle = cachedDateTimeFormat(locale, "__hourCycle", { hour: "numeric" }).resolvedOptions().hourCycle;
120
+ return hourCycle === "h11" || hourCycle === "h12";
121
+ }
122
+ _chunk7QVYU63Ejs.__name.call(void 0, usesTwelveHourClock, "usesTwelveHourClock");
123
+ var dateFormatLocale = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (appLocale) => _nullishCoalesce(appLocale, () => ( "en")), "dateFormatLocale");
124
+ var LEGACY_DATE_OPTIONS = { year: "numeric", month: "2-digit", day: "2-digit" };
125
+ var LEGACY_TIME_OPTIONS = { hour: "2-digit", minute: "2-digit" };
126
+ var formatDate = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (eventDate, formatOption, locale = "en-GB", now) => {
127
+ const reference = _nullishCoalesce(now, () => ( /* @__PURE__ */ new Date()));
128
+ const diff = reference.getTime() - eventDate.getTime();
129
+ if (formatOption === "default") {
130
+ if (diff < 24 * 60 * 60 * 1e3) formatOption = "timeSince";
131
+ else formatOption = "dateTime";
132
+ }
133
+ switch (formatOption) {
134
+ case "timeSince":
135
+ return formatRelativeDate({ date: eventDate, locale, now: reference });
136
+ case "date":
137
+ return cachedDateTimeFormat(locale, "__legacyDate", LEGACY_DATE_OPTIONS).format(eventDate);
138
+ case "time":
139
+ return cachedDateTimeFormat(locale, "__legacyTime", LEGACY_TIME_OPTIONS).format(eventDate);
140
+ case "dateTime":
141
+ return `${cachedDateTimeFormat(locale, "__legacyDate", LEGACY_DATE_OPTIONS).format(eventDate)} ${cachedDateTimeFormat(locale, "__legacyTime", LEGACY_TIME_OPTIONS).format(eventDate)}`;
142
+ default:
143
+ throw new Error("Invalid format option");
144
+ }
145
+ }, "formatDate");
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ exports.formatLocalDate = formatLocalDate; exports.resolveDateLocale = resolveDateLocale; exports.formatDateStyle = formatDateStyle; exports.formatRelativeDate = formatRelativeDate; exports.usesTwelveHourClock = usesTwelveHourClock; exports.dateFormatLocale = dateFormatLocale; exports.formatDate = formatDate;
156
+ //# sourceMappingURL=chunk-HROKKUBQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-HROKKUBQ.js","../src/utils/date-formatter.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACSO,IAAM,gBAAA,kBAAkB,qCAAA,CAAC,CAAA,EAAA,GAAoB;AAClD,EAAA,MAAM,KAAA,EAAO,CAAA,CAAE,WAAA,CAAY,CAAA;AAC3B,EAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS,EAAA,EAAI,CAAC,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAA;AACtD,EAAA,MAAM,IAAA,EAAM,MAAA,CAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAA;AAC/C,EAAA,OAAO,CAAA,EAAA;AAJsB;AA0BzB;AAMO;AACL,EAAA;AACN,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACQ,EAAA;AACR,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACO,EAAA;AACP,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAGa;AACL,EAAA;AACN,EAAA;AACA,EAAA;AACF;AAEM;AAGA;AAME,EAAA;AACF,EAAA;AACC,EAAA;AACH,IAAA;AACA,IAAA;AACF,EAAA;AACO,EAAA;AAZoB;AAevB;AAEA;AACA,EAAA;AACC,EAAA;AACH,IAAA;AACA,IAAA;AACF,EAAA;AACO,EAAA;AANwB;AAS3B;AACA,EAAA;AACE,EAAA;AACC,EAAA;AAHW;AAMd;AAEA;AAUU;AACN,EAAA;AACH,EAAA;AAEC,EAAA;AACA,EAAA;AAEA,EAAA;AACN,EAAA;AACQ,IAAA;AACA,IAAA;AACD,IAAA;AAED,IAAA;AACE,IAAA;AACF,IAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACM,IAAA;AACF,IAAA;AAEJ,IAAA;AACF,EAAA;AAEQ,EAAA;AAER,EAAA;AACM,IAAA;AACF,MAAA;AACI,MAAA;AACN,IAAA;AAEA,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AArCgB;AA2CA;AAOR,EAAA;AACD,EAAA;AACC,EAAA;AACC,EAAA;AACT;AAXgB;AAcA;AACR,EAAA;AACD,EAAA;AACC,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACF,EAAA;AACA,EAAA;AACA,EAAA;AACG,EAAA;AACT;AAhBgB;AAmBA;AACR,EAAA;AACC,EAAA;AACT;AAHgB;AAMH;AAEP;AACA;AAQO;AAML,EAAA;AACA,EAAA;AAEF,EAAA;AACE,IAAA;AACC,IAAA;AACP,EAAA;AAEQ,EAAA;AACD,IAAA;AACH,MAAA;AACG,IAAA;AACH,MAAA;AACG,IAAA;AACH,MAAA;AACG,IAAA;AACH,MAAA;AACF,IAAA;AACE,MAAA;AACJ,EAAA;AAzBwB;ADnEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-HROKKUBQ.js","sourcesContent":[null,"type FormatOption = \"date\" | \"time\" | \"dateTime\" | \"timeSince\" | \"default\";\n\n/**\n * Format a `Date` as `YYYY-MM-DD` using the value's local-time components.\n *\n * Use for JSON:API attributes whose backend field type is `\"date\"` (calendar\n * date with no time component). `JSON.stringify(new Date(...))` would call\n * `.toISOString()`, which UTC-shifts and can lose a day west of UTC; this\n * helper avoids that by emitting the local-date components verbatim.\n *\n * For `\"datetime\"` fields use `.toISOString()` instead — those represent an\n * instant in time and the UTC shift is correct.\n */\nexport const formatLocalDate = (d: Date): string => {\n const year = d.getFullYear();\n const month = String(d.getMonth() + 1).padStart(2, \"0\");\n const day = String(d.getDate()).padStart(2, \"0\");\n return `${year}-${month}-${day}`;\n};\n\nexport type DateFormatStyle =\n | \"date\"\n | \"dateMedium\"\n | \"dateLong\"\n | \"dateTime\"\n | \"dateTimeMedium\"\n | \"dateTimeLong\"\n | \"dateTimeSeconds\"\n | \"time\"\n | \"weekdayDateTime\"\n | \"weekdayDay\"\n | \"monthYear\"\n | \"monthYearLong\"\n | \"month\"\n | \"monthLong\"\n | \"dayMonth\"\n | \"weekday\"\n | \"weekdayLong\";\n\nconst NUMERIC_DATE: Intl.DateTimeFormatOptions = { day: \"2-digit\", month: \"2-digit\", year: \"numeric\" };\n\n/**\n * The option set behind each named style. No style pins `hour12` / `hourCycle`:\n * the clock (12 or 24 hours) follows the locale.\n */\nexport const DATE_STYLE_OPTIONS: Record<DateFormatStyle, Intl.DateTimeFormatOptions> = {\n date: NUMERIC_DATE,\n dateMedium: { dateStyle: \"medium\" },\n dateLong: { dateStyle: \"long\" },\n dateTime: { ...NUMERIC_DATE, hour: \"numeric\", minute: \"2-digit\" },\n dateTimeMedium: { dateStyle: \"medium\", timeStyle: \"short\" },\n dateTimeLong: { day: \"numeric\", month: \"long\", year: \"numeric\", hour: \"numeric\", minute: \"2-digit\" },\n dateTimeSeconds: { ...NUMERIC_DATE, hour: \"numeric\", minute: \"2-digit\", second: \"2-digit\" },\n time: { hour: \"numeric\", minute: \"2-digit\" },\n weekdayDateTime: { weekday: \"short\", day: \"numeric\", month: \"short\", hour: \"numeric\", minute: \"2-digit\" },\n weekdayDay: { weekday: \"short\", day: \"numeric\", month: \"long\", year: \"numeric\" },\n monthYear: { month: \"short\", year: \"numeric\" },\n monthYearLong: { month: \"long\", year: \"numeric\" },\n month: { month: \"short\" },\n monthLong: { month: \"long\" },\n dayMonth: { day: \"numeric\", month: \"short\" },\n weekday: { weekday: \"short\" },\n weekdayLong: { weekday: \"long\" },\n};\n\n/** Public pages never show an all-numeric date: the month is spelled out. */\nexport const PUBLIC_STYLE_MAP: Partial<Record<DateFormatStyle, DateFormatStyle>> = {\n date: \"dateMedium\",\n dateTime: \"dateTimeMedium\",\n dateTimeSeconds: \"dateTimeMedium\",\n};\n\nconst formatterCache = new Map<string, Intl.DateTimeFormat>();\n\n/** One cached `Intl.DateTimeFormat` per locale + option-set key + time zone. */\nconst cachedDateTimeFormat = (\n locale: string,\n key: string,\n options: Intl.DateTimeFormatOptions,\n timeZone?: string,\n): Intl.DateTimeFormat => {\n const cacheKey = `${locale}|${key}|${timeZone ?? \"\"}`;\n let formatter = formatterCache.get(cacheKey);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, timeZone ? { ...options, timeZone } : options);\n formatterCache.set(cacheKey, formatter);\n }\n return formatter;\n};\n\nconst relativeCache = new Map<string, Intl.RelativeTimeFormat>();\n\nconst cachedRelativeTimeFormat = (locale: string): Intl.RelativeTimeFormat => {\n let formatter = relativeCache.get(locale);\n if (!formatter) {\n formatter = new Intl.RelativeTimeFormat(locale, { numeric: \"always\" });\n relativeCache.set(locale, formatter);\n }\n return formatter;\n};\n\nconst toValidDate = (date: Date | string | undefined): Date | undefined => {\n if (date === undefined || date === null) return undefined;\n const value = date instanceof Date ? date : new Date(date);\n return Number.isNaN(value.getTime()) ? undefined : value;\n};\n\nconst languageOf = (tag: string): string => tag.split(\"-\")[0].toLowerCase();\n\nconst MAX_ACCEPT_LANGUAGE_ENTRIES = 50;\n\n/**\n * The locale every real-world date is formatted in.\n *\n * The first `Accept-Language` entry (quality order) whose language equals the\n * app language's and that `Intl` supports; otherwise the app language. A\n * malformed entry (`*`, an unparseable or zero quality, an unknown tag) is\n * skipped, never thrown on.\n */\nexport function resolveDateLocale(params: { appLocale: string; acceptLanguage?: string }): string {\n const { appLocale, acceptLanguage } = params;\n if (!acceptLanguage) return appLocale;\n\n const appLanguage = languageOf(appLocale);\n const entries: { tag: string; quality: number; index: number }[] = [];\n\n const parts = acceptLanguage.split(\",\");\n for (let index = 0; index < parts.length && entries.length < MAX_ACCEPT_LANGUAGE_ENTRIES; index++) {\n const [rawTag, ...rawParams] = parts[index].split(\";\");\n const tag = rawTag.trim();\n if (!tag || tag === \"*\") continue;\n\n let quality = 1;\n const qualityParam = rawParams.map((param) => param.trim()).find((param) => param.startsWith(\"q=\"));\n if (qualityParam !== undefined) {\n const raw = qualityParam.slice(2);\n quality = /^\\d+(\\.\\d+)?$/.test(raw) ? Number(raw) : NaN;\n }\n if (!(quality > 0)) continue;\n if (languageOf(tag) !== appLanguage) continue;\n\n entries.push({ tag, quality, index });\n }\n\n entries.sort((a, b) => b.quality - a.quality || a.index - b.index);\n\n for (const entry of entries) {\n try {\n const [supported] = Intl.DateTimeFormat.supportedLocalesOf([entry.tag]);\n if (supported && languageOf(supported) === appLanguage) return supported;\n } catch {\n // An invalid language tag: skip it.\n }\n }\n\n return appLocale;\n}\n\n/**\n * Formats a date in a named style. Returns \"\" for `undefined` or a value that\n * does not parse. `isPublic` swaps the all-numeric styles for month-as-word.\n */\nexport function formatDateStyle(params: {\n date: Date | string | undefined;\n style: DateFormatStyle;\n locale: string;\n timeZone?: string;\n isPublic?: boolean;\n}): string {\n const value = toValidDate(params.date);\n if (!value) return \"\";\n const style = (params.isPublic && PUBLIC_STYLE_MAP[params.style]) || params.style;\n return cachedDateTimeFormat(params.locale, style, DATE_STYLE_OPTIONS[style], params.timeZone).format(value);\n}\n\n/** \"3 hours ago\" / \"3 ore fa\", always numeric (\"1 day ago\", never \"yesterday\"). */\nexport function formatRelativeDate(params: { date: Date | string; locale: string; now?: Date }): string {\n const value = toValidDate(params.date);\n if (!value) return \"\";\n const now = params.now ?? new Date();\n const diff = now.getTime() - value.getTime();\n const sign = diff < 0 ? 1 : -1;\n const seconds = Math.floor(Math.abs(diff) / 1000);\n const minutes = Math.floor(seconds / 60);\n const hours = Math.floor(minutes / 60);\n const days = Math.floor(hours / 24);\n\n const relative = cachedRelativeTimeFormat(params.locale);\n if (days > 0) return relative.format(sign * days, \"day\");\n if (hours > 0) return relative.format(sign * hours, \"hour\");\n if (minutes > 0) return relative.format(sign * minutes, \"minute\");\n return relative.format(sign * seconds, \"second\");\n}\n\n/** True when the locale's clock is 12-hour (hour cycle h11 / h12). */\nexport function usesTwelveHourClock(locale: string): boolean {\n const hourCycle = cachedDateTimeFormat(locale, \"__hourCycle\", { hour: \"numeric\" }).resolvedOptions().hourCycle;\n return hourCycle === \"h11\" || hourCycle === \"h12\";\n}\n\n/** The locale to format dates in for an app locale: the app locale itself, English when missing. */\nexport const dateFormatLocale = (appLocale?: string): string => appLocale ?? \"en\";\n\nconst LEGACY_DATE_OPTIONS: Intl.DateTimeFormatOptions = { year: \"numeric\", month: \"2-digit\", day: \"2-digit\" };\nconst LEGACY_TIME_OPTIONS: Intl.DateTimeFormatOptions = { hour: \"2-digit\", minute: \"2-digit\" };\n\n/**\n * @deprecated Use `formatDateStyle` (or `useDateFormatter().format`) and\n * `formatRelativeDate` (or `useDateFormatter().relative`). Kept for other nja\n * apps: same default locale and the same \"date\" / \"time\" / \"dateTime\" output.\n * Pass `now` from render code; the `new Date()` fallback is for legacy callers.\n */\nexport const formatDate = (\n eventDate: Date,\n formatOption: FormatOption,\n locale: string = \"en-GB\",\n now?: Date,\n): string => {\n const reference = now ?? new Date();\n const diff = reference.getTime() - eventDate.getTime();\n\n if (formatOption === \"default\") {\n if (diff < 24 * 60 * 60 * 1000) formatOption = \"timeSince\";\n else formatOption = \"dateTime\";\n }\n\n switch (formatOption) {\n case \"timeSince\":\n return formatRelativeDate({ date: eventDate, locale, now: reference });\n case \"date\":\n return cachedDateTimeFormat(locale, \"__legacyDate\", LEGACY_DATE_OPTIONS).format(eventDate);\n case \"time\":\n return cachedDateTimeFormat(locale, \"__legacyTime\", LEGACY_TIME_OPTIONS).format(eventDate);\n case \"dateTime\":\n return `${cachedDateTimeFormat(locale, \"__legacyDate\", LEGACY_DATE_OPTIONS).format(eventDate)} ${cachedDateTimeFormat(locale, \"__legacyTime\", LEGACY_TIME_OPTIONS).format(eventDate)}`;\n default:\n throw new Error(\"Invalid format option\");\n }\n};\n\nexport type { FormatOption };\n"]}