@jsenv/navi 0.26.38 → 0.26.39

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.
@@ -31424,31 +31424,54 @@ const formatTime = (date, locale) => {
31424
31424
  /**
31425
31425
  * Formats a date relative to now: "il y a 3 jours", "dans 2 heures", etc.
31426
31426
  */
31427
- const formatTimeAgo = (date, locale, { now = new Date() } = {}) => {
31427
+ const formatTimeAgo = (
31428
+ date,
31429
+ locale,
31430
+ { now = new Date(), prefix } = {},
31431
+ ) => {
31428
31432
  const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
31429
31433
  const nowMs = now instanceof Date ? now.getTime() : now;
31430
31434
  const diff = date.getTime() - nowMs;
31431
31435
  const absDiff = Math.abs(diff);
31432
31436
 
31437
+ let value;
31438
+ let unit;
31433
31439
  if (absDiff < MINUTE) {
31434
- return rtf.format(Math.round(diff / 1000), "second");
31435
- }
31436
- if (absDiff < HOUR) {
31437
- return rtf.format(Math.round(diff / MINUTE), "minute");
31438
- }
31439
- if (absDiff < DAY) {
31440
- return rtf.format(Math.round(diff / HOUR), "hour");
31441
- }
31442
- if (absDiff < 7 * DAY) {
31443
- return rtf.format(Math.round(diff / DAY), "day");
31444
- }
31445
- if (absDiff < 30 * DAY) {
31446
- return rtf.format(Math.round(diff / (7 * DAY)), "week");
31440
+ value = Math.round(diff / 1000);
31441
+ unit = "second";
31442
+ } else if (absDiff < HOUR) {
31443
+ value = Math.round(diff / MINUTE);
31444
+ unit = "minute";
31445
+ } else if (absDiff < DAY) {
31446
+ value = Math.round(diff / HOUR);
31447
+ unit = "hour";
31448
+ } else if (absDiff < 7 * DAY) {
31449
+ value = Math.round(diff / DAY);
31450
+ unit = "day";
31451
+ } else if (absDiff < 30 * DAY) {
31452
+ value = Math.round(diff / (7 * DAY));
31453
+ unit = "week";
31454
+ } else if (absDiff < YEAR) {
31455
+ value = Math.round(diff / (30 * DAY));
31456
+ unit = "month";
31457
+ } else {
31458
+ value = Math.round(diff / YEAR);
31459
+ unit = "year";
31447
31460
  }
31448
- if (absDiff < YEAR) {
31449
- return rtf.format(Math.round(diff / (30 * DAY)), "month");
31461
+
31462
+ if (!prefix || value >= 0) {
31463
+ return rtf.format(value, unit);
31450
31464
  }
31451
- return rtf.format(Math.round(diff / YEAR), "year");
31465
+ // Drop the leading past-tense literal ("il y a ", "ago ") and prepend the custom prefix.
31466
+ // Slicing from the "integer" part keeps: integer + unit, drops the prefix.
31467
+ const parts = rtf.formatToParts(value, unit);
31468
+ const integerIndex = parts.findIndex((p) => p.type === "integer");
31469
+ const withoutPrefix = parts
31470
+ .slice(integerIndex)
31471
+ .map((p) => p.value)
31472
+ .join("")
31473
+ .trim();
31474
+ return `${prefix} ${withoutPrefix}`;
31452
31475
  };
31453
31476
 
31454
31477
  /**
@@ -31472,11 +31495,11 @@ const formatTimeAgo = (date, locale, { now = new Date() } = {}) => {
31472
31495
  * // ended 2 hours ago
31473
31496
  * formatDuration(Date.now() - 3 * 3_600_000, 3_600_000, "fr") // "il y a 2 heures"
31474
31497
  */
31475
- const formatDuration = (
31498
+ const formatTimeRelative = (
31476
31499
  start,
31477
31500
  durationMs = 0,
31478
31501
  locale,
31479
- { now = new Date() } = {},
31502
+ { now = new Date(), prefix } = {},
31480
31503
  ) => {
31481
31504
  const startMs = start instanceof Date ? start.getTime() : Number(start);
31482
31505
  const endMs = startMs + durationMs;
@@ -31487,7 +31510,7 @@ const formatDuration = (
31487
31510
  }
31488
31511
  if (nowMs >= endMs) {
31489
31512
  const refDate = endMs > startMs ? new Date(endMs) : new Date(startMs);
31490
- return formatTimeAgo(refDate, locale, { now });
31513
+ return formatTimeAgo(refDate, locale, { now, prefix });
31491
31514
  }
31492
31515
 
31493
31516
  const diff = startMs - nowMs;
@@ -31612,7 +31635,8 @@ const toLocalDayKey = (date) => {
31612
31635
  const Time = ({
31613
31636
  children,
31614
31637
  type = "day",
31615
- duration = 0,
31638
+ eventDuration = 0,
31639
+ prefix,
31616
31640
  locale,
31617
31641
  ...props
31618
31642
  }) => {
@@ -31620,11 +31644,15 @@ const Time = ({
31620
31644
  const lang = locale || langSignal.value;
31621
31645
  let text;
31622
31646
  let dateTimeAttr;
31623
- if (type === "duration") {
31624
- text = date ? formatDuration(date, duration, lang) : children === undefined ? "–" : String(children);
31647
+ if (type === "relative") {
31648
+ text = date ? formatTimeRelative(date, eventDuration, lang, {
31649
+ prefix
31650
+ }) : children === undefined ? "–" : String(children);
31625
31651
  dateTimeAttr = date ? date.toISOString() : undefined;
31626
31652
  } else {
31627
- text = date ? formatDate(date, type, lang) : children === undefined ? "–" : String(children);
31653
+ text = date ? formatDate(date, type, lang, {
31654
+ prefix
31655
+ }) : children === undefined ? "–" : String(children);
31628
31656
  dateTimeAttr = date ? toDateTimeAttr(date, type) : undefined;
31629
31657
  }
31630
31658
  return jsx(Text, {
@@ -31677,7 +31705,7 @@ const toDateTimeAttr = (date, type) => {
31677
31705
  const mm = String(date.getMonth() + 1).padStart(2, "0");
31678
31706
  return `${yyyy}-${mm}`;
31679
31707
  }
31680
- if (type === "datetime" || type === "relative") {
31708
+ if (type === "datetime" || type === "ago" || type === "relative") {
31681
31709
  return date.toISOString();
31682
31710
  }
31683
31711
  // day
@@ -31686,7 +31714,9 @@ const toDateTimeAttr = (date, type) => {
31686
31714
  const dd = String(date.getDate()).padStart(2, "0");
31687
31715
  return `${yyyy}-${mm}-${dd}`;
31688
31716
  };
31689
- const formatDate = (date, type, locale) => {
31717
+ const formatDate = (date, type, locale, {
31718
+ prefix
31719
+ } = {}) => {
31690
31720
  if (type === "day") {
31691
31721
  return formatDay(date, locale);
31692
31722
  }
@@ -31699,8 +31729,10 @@ const formatDate = (date, type, locale) => {
31699
31729
  if (type === "time") {
31700
31730
  return formatTime(date, locale);
31701
31731
  }
31702
- if (type === "relative") {
31703
- return formatTimeAgo(date, locale);
31732
+ if (type === "ago") {
31733
+ return formatTimeAgo(date, locale, {
31734
+ prefix
31735
+ });
31704
31736
  }
31705
31737
  return String(date);
31706
31738
  };
@@ -39714,5 +39746,5 @@ const UserSvg = () => jsx("svg", {
39714
39746
  })
39715
39747
  });
39716
39748
 
39717
- export { ActionRenderer, ActiveKeyboardShortcuts, Address, Badge, BadgeCount, Box, Button, ButtonCopyToClipboard, Caption, CheckSvg, Checkbox, CheckboxList, CloseSvg, Code, Col, Colgroup, ConstructionSvg, Details, Dialog, DialogLayout, Editable, ErrorBoundary, ErrorBoundaryContext, ExclamationSvg, EyeClosedSvg, EyeSvg, Field, Form, Group, Head, HeartSvg, HomeSvg, Icon, Image, Input, Interpolate, Label, Link, LinkAnchorSvg, LinkBlankTargetSvg, LinkCurrentSvg, List, ListItem, ListItemFooter, ListItemGroup, ListItemHeader, Loading, LoadingDotsSvg, LoadingIndicator, LoadingIndicatorFluid, MessageBox, Meter, Nav, NaviDebug, Paragraph, Picker, Popover, Quantity, Radio, RadioList, Route, RowNumberCol, RowNumberTableCell, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, SidePanel, StarSvg, SummaryMarker, Svg, Table, TableCell, Tbody, Text, Thead, Time, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, actionRunEffect, addCustomMessage, anyMatchingRouteSignal, applySearch, arraySignalMembership, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSearch, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, ensureDocumentStartViewTransition, filterTableSelection, formatDatetime, formatDay, formatDuration, formatMonth, formatNumber, formatTime, formatTimeAgo, getNowHours, installCustomConstraintValidation, interpolateText, isCellSelected, isColumnSelected, isRowSelected, isToday, langSignal, localStorageSignal, moveArrayItemByIndex, navBack, navForward, navTo, naviI18n, openCallout, rawUrlPart, reload, removeCustomMessage, requestListClose, requestListOpen, rerunActions, resource, route, routeAction, setBaseUrl, setupRoutes, stateSignal, stopLoad, stringifyTableSelectionValue, swapArrayItemByIndex, syncOwnedResourceToSignals, syncResourceToSignals, updateActions, useActionStatus, useArraySignalMembership, useAsyncData, useCalloutRequestClose, useCancelPrevious, useCellGridFromRows, useConstraintValidityState, useDependenciesDiff, useDisplayedLayoutEffect, useDocumentResource, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useNavState, useOrderedColumns, useRouteStatus, useRunOnMount, useSearchText, useSelectRequestClose, useSelectableElement, useSelectionController, useSidePanelClose, useSignalSync, useStateArray, useTitleLevel, useUrlSearchParam, valueInLocalStorage, windowWidthSignal };
39749
+ export { ActionRenderer, ActiveKeyboardShortcuts, Address, Badge, BadgeCount, Box, Button, ButtonCopyToClipboard, Caption, CheckSvg, Checkbox, CheckboxList, CloseSvg, Code, Col, Colgroup, ConstructionSvg, Details, Dialog, DialogLayout, Editable, ErrorBoundary, ErrorBoundaryContext, ExclamationSvg, EyeClosedSvg, EyeSvg, Field, Form, Group, Head, HeartSvg, HomeSvg, Icon, Image, Input, Interpolate, Label, Link, LinkAnchorSvg, LinkBlankTargetSvg, LinkCurrentSvg, List, ListItem, ListItemFooter, ListItemGroup, ListItemHeader, Loading, LoadingDotsSvg, LoadingIndicator, LoadingIndicatorFluid, MessageBox, Meter, Nav, NaviDebug, Paragraph, Picker, Popover, Quantity, Radio, RadioList, Route, RowNumberCol, RowNumberTableCell, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, SidePanel, StarSvg, SummaryMarker, Svg, Table, TableCell, Tbody, Text, Thead, Time, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, actionRunEffect, addCustomMessage, anyMatchingRouteSignal, applySearch, arraySignalMembership, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSearch, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, ensureDocumentStartViewTransition, filterTableSelection, formatDatetime, formatDay, formatMonth, formatNumber, formatTime, formatTimeAgo, formatTimeRelative, getNowHours, installCustomConstraintValidation, interpolateText, isCellSelected, isColumnSelected, isRowSelected, isToday, langSignal, localStorageSignal, moveArrayItemByIndex, navBack, navForward, navTo, naviI18n, openCallout, rawUrlPart, reload, removeCustomMessage, requestListClose, requestListOpen, rerunActions, resource, route, routeAction, setBaseUrl, setupRoutes, stateSignal, stopLoad, stringifyTableSelectionValue, swapArrayItemByIndex, syncOwnedResourceToSignals, syncResourceToSignals, updateActions, useActionStatus, useArraySignalMembership, useAsyncData, useCalloutRequestClose, useCancelPrevious, useCellGridFromRows, useConstraintValidityState, useDependenciesDiff, useDisplayedLayoutEffect, useDocumentResource, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useNavState, useOrderedColumns, useRouteStatus, useRunOnMount, useSearchText, useSelectRequestClose, useSelectableElement, useSelectionController, useSidePanelClose, useSignalSync, useStateArray, useTitleLevel, useUrlSearchParam, valueInLocalStorage, windowWidthSignal };
39718
39750
  //# sourceMappingURL=jsenv_navi.js.map