@streamscloud/kit 0.93.5 → 0.93.7

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.
@@ -16,6 +16,8 @@ export declare class DateHelper {
16
16
  static formatDateRange(startDate: LikeDate, endDate: LikeDate, locale: string): string;
17
17
  static dateRangeDescriptionString(startDate: LikeDate, endDate: LikeDate | null | undefined, locale: string): string;
18
18
  static toDefaultDateTimeRepresentation: (val: LikeDate, locale: string, alwaysIncludeYear?: boolean) => string;
19
+ /** `01.dec · 11:30`, with a two-digit year for past years: `01.dec.25 · 11:30`. */
20
+ static toCompactDateTimeRepresentation: (val: LikeDate, locale: string, showTime?: boolean) => string;
19
21
  static addYears(dateToModify: LikeDate, yearsToAdd: number, resetTime?: boolean): Date;
20
22
  static startOfLastWeek(): string;
21
23
  static endOfLastWeek(): string;
@@ -151,6 +151,27 @@ export class DateHelper {
151
151
  const time = `${formatNumber(dateTime.getHours())}:${formatNumber(dateTime.getMinutes())}`;
152
152
  return `${date}. ${monthName}${year} - ${time}`;
153
153
  };
154
+ /** `01.dec · 11:30`, with a two-digit year for past years: `01.dec.25 · 11:30`. */
155
+ static toCompactDateTimeRepresentation = (val, locale, showTime = true) => {
156
+ const dateTime = DateHelper.toDate(val);
157
+ const parts = new Intl.DateTimeFormat(locale, {
158
+ day: '2-digit',
159
+ month: 'short',
160
+ year: '2-digit',
161
+ hour: '2-digit',
162
+ minute: '2-digit',
163
+ hourCycle: 'h23'
164
+ }).formatToParts(dateTime);
165
+ const getPart = (type) => parts.find((part) => part.type === type)?.value ?? '';
166
+ // Norwegian short months carry their own trailing dot ("nov."), which would double the separator.
167
+ const month = getPart('month').replace(/\.$/, '').toLocaleLowerCase(locale);
168
+ const dateSegments = [getPart('day'), month];
169
+ if (dateTime.getFullYear() !== new Date().getFullYear()) {
170
+ dateSegments.push(getPart('year'));
171
+ }
172
+ const date = dateSegments.join('.');
173
+ return showTime ? `${date} · ${getPart('hour')}:${getPart('minute')}` : date;
174
+ };
154
175
  static addYears(dateToModify, yearsToAdd, resetTime = true) {
155
176
  const date = new Date(dateToModify);
156
177
  date.setFullYear(date.getFullYear() + yearsToAdd);
@@ -5,7 +5,7 @@
5
5
  const { value, segments, variant = 'tray', size = 'md', fullWidth = false, compare, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, on } = $props();
6
6
  const formFieldLabel = getFormFieldLabel();
7
7
  const segmentIdPrefix = $props.id();
8
- const segmentEls = [];
8
+ const segmentEls = $state([]);
9
9
  const isActive = (segment) => (compare ? compare(value, segment.value) : value === segment.value);
10
10
  const tabStopIndex = $derived.by(() => {
11
11
  const activeIndex = segments.findIndex((segment) => !segment.disabled && isActive(segment));
@@ -1,12 +1,9 @@
1
- <script lang="ts" generics="T extends {id: string}">import { DateHelper } from '../../../core/utils';
1
+ <script lang="ts" generics="T extends {id: string}">import { AppLocale } from '../../../core/locale';
2
+ import { DateHelper } from '../../../core/utils';
2
3
  import { ImageRound } from '../../image';
4
+ import { TimeAgo } from '../../time-ago';
3
5
  import { Tooltip } from '../../tooltip';
4
6
  let { item, column } = $props();
5
- const fmt = (d, options) => new Intl.DateTimeFormat(undefined, options).format(d);
6
- const timeFormat = { hour: '2-digit', minute: '2-digit', hour12: false };
7
- const dateFormat = { day: '2-digit' };
8
- const monthFormat = { month: 'short' };
9
- const yearFormat = { year: '2-digit' };
10
7
  const getValueForColumn = (column, item) => (column.valueFactory ? column.valueFactory(item) : item[column.id])?.toString();
11
8
  const getDateValueForColumn = (column, item) => {
12
9
  const value = getValueForColumn(column, item);
@@ -15,6 +12,7 @@ const getDateValueForColumn = (column, item) => {
15
12
  const dateTime = $derived(getDateValueForColumn(column, item));
16
13
  const by = $derived(column.byValueFactory ? column.byValueFactory(item) : null);
17
14
  const underline = $derived(column.underline ?? 'hover');
15
+ const showTime = $derived(column.showTime ?? true);
18
16
  const getHref = (by) => {
19
17
  return column.hrefFactory ? column.hrefFactory(by) : null;
20
18
  };
@@ -46,13 +44,11 @@ const navigateToUser = (event, by) => {
46
44
  </span>
47
45
  {/if}
48
46
  <span class="table-by-cell__date">
49
- {fmt(dateTime, dateFormat)}.
50
- <span class="table-by-cell__month">{fmt(dateTime, monthFormat)}</span>
51
- {#if dateTime.getFullYear() !== new Date().getFullYear()}
52
- .{fmt(dateTime, yearFormat)}
47
+ {#if column.dateDisplay === 'absolute'}
48
+ {DateHelper.toCompactDateTimeRepresentation(dateTime, column.locale ?? AppLocale.current, showTime)}
49
+ {:else}
50
+ <TimeAgo date={dateTime} autoUpdate={column.autoUpdate ?? false} showTime={showTime} locale={column.locale} absoluteFormat="compact" />
53
51
  {/if}
54
- <span>&nbsp;&middot;&nbsp;</span>
55
- {fmt(dateTime, timeFormat)}
56
52
  </span>
57
53
  {:else if by}
58
54
  {@const href = getHref(by)}
@@ -99,9 +95,6 @@ const navigateToUser = (event, by) => {
99
95
  justify-content: center;
100
96
  height: 100%;
101
97
  }
102
- .table-by-cell__month {
103
- text-transform: lowercase;
104
- }
105
98
  .table-by-cell__by {
106
99
  display: flex;
107
100
  align-items: center;
@@ -1,3 +1,4 @@
1
+ import type { AppLocaleValue } from '../../core/locale';
1
2
  import type { Repository } from '../../core/repository';
2
3
  import type { BadgeShape, BadgeVariant } from '../badge';
3
4
  import type { ButtonSize, ButtonVariant } from '../button';
@@ -77,6 +78,14 @@ export interface ITableByColumn<T> extends ITableColumn<T> {
77
78
  }) => void) | null;
78
79
  /** When the person-name link shows its underline: only on hover, permanently, or not at all. @default 'hover' */
79
80
  underline?: 'hover' | 'always' | 'never';
81
+ /** Relative "5 minutes ago" text, or the absolute "04.nov · 14:32" form. @default 'relative' */
82
+ dateDisplay?: 'relative' | 'absolute';
83
+ /** Re-render the relative text on a timer as time passes. Relative display only. */
84
+ autoUpdate?: boolean;
85
+ /** Include the time of day in the date. @default true */
86
+ showTime?: boolean;
87
+ /** Falls back to the global `AppLocale` when not set. */
88
+ locale?: AppLocaleValue | null;
80
89
  }
81
90
  export interface ITableButtonColumn<T> extends ITableColumn<T> {
82
91
  type: 'button';
@@ -1,14 +1,20 @@
1
1
  <script lang="ts">import { DateFormatOptions, DateHelper } from '../../core/utils/date-helper';
2
2
  import { TimeAgoLocalization } from './time-ago-localization';
3
- let { date = null, thresholdMinutes = 60 * 24 * 2 /* 2 days */ } = $props();
4
- const localization = new TimeAgoLocalization();
3
+ let { date = null, thresholdMinutes = 60 * 24 * 2 /* 2 days */, autoUpdate = true, showTime = true, locale = null, absoluteFormat = 'phrase' } = $props();
4
+ const localization = new TimeAgoLocalization(() => locale);
5
5
  let timeSpan = $state.raw(null);
6
6
  let timeoutId;
7
7
  const setRelativeTime = (d) => {
8
8
  disableTimeout();
9
9
  const dateVal = d ? DateHelper.toDate(d) : new Date();
10
+ const formatTime = () => dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat);
10
11
  const setupAbsDate = () => {
11
- timeSpan = localization.at(dateVal.toLocaleString(localization.locale, dateVal.getFullYear() === new Date().getFullYear() ? DateFormatOptions.dateFormatWithoutYear : DateFormatOptions.dateFormat), dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat));
12
+ if (absoluteFormat === 'compact') {
13
+ timeSpan = DateHelper.toCompactDateTimeRepresentation(dateVal, localization.locale, showTime);
14
+ return;
15
+ }
16
+ const formattedDate = dateVal.toLocaleString(localization.locale, dateVal.getFullYear() === new Date().getFullYear() ? DateFormatOptions.dateFormatWithoutYear : DateFormatOptions.dateFormat);
17
+ timeSpan = showTime ? localization.at(formattedDate, formatTime()) : formattedDate;
12
18
  };
13
19
  const diffSeconds = (+new Date() - +dateVal) / 1000;
14
20
  if (diffSeconds > thresholdMinutes * 60) {
@@ -40,13 +46,15 @@ const setRelativeTime = (d) => {
40
46
  refreshIntervalSec = 3600;
41
47
  }
42
48
  else if (diffSeconds < secsIn2Days) {
43
- timeSpan = localization.yesterday(dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat));
49
+ timeSpan = showTime ? localization.yesterdayAt(formatTime()) : localization.yesterday;
44
50
  refreshIntervalSec = 3600;
45
51
  }
46
52
  else {
47
53
  return setupAbsDate();
48
54
  }
49
- timeoutId = setTimeout(() => setRelativeTime(d), refreshIntervalSec * 1000);
55
+ if (autoUpdate) {
56
+ timeoutId = setTimeout(() => setRelativeTime(d), refreshIntervalSec * 1000);
57
+ }
50
58
  };
51
59
  $effect(() => {
52
60
  setRelativeTime(date);
@@ -69,7 +77,7 @@ const disableTimeout = () => {
69
77
 
70
78
  <!--
71
79
  @component
72
- Displays a human-readable relative time string (e.g. "5 minutes ago") that auto-updates on a self-scheduled
80
+ Displays a human-readable relative time string (e.g. "5 minutes ago") that can auto-update on a self-scheduled
73
81
  timer. Falls back to an absolute date/time after `thresholdMinutes`.
74
82
 
75
83
  Inherits typography from the parent — pass `font-size` / `color` through CSS on a surrounding element to
@@ -1,11 +1,20 @@
1
+ import type { AppLocaleValue } from '../../core/locale';
1
2
  type Props = {
2
3
  /** Date to display relative to now */
3
4
  date: Date | string | null;
4
5
  /** Minutes after which absolute date format is used @default 2880 */
5
6
  thresholdMinutes?: number;
7
+ /** Re-render the relative text on a timer as time passes. @default true */
8
+ autoUpdate?: boolean;
9
+ /** Include the time of day in the absolute and "yesterday" forms. @default true */
10
+ showTime?: boolean;
11
+ /** Falls back to the global `AppLocale` when not set. */
12
+ locale?: AppLocaleValue | null;
13
+ /** Form of the date past `thresholdMinutes`: `'phrase'` — "Dec 01 at 11:30", `'compact'` — "01.dec · 11:30", the table `by` column's form. @default 'phrase' */
14
+ absoluteFormat?: 'phrase' | 'compact';
6
15
  };
7
16
  /**
8
- * Displays a human-readable relative time string (e.g. "5 minutes ago") that auto-updates on a self-scheduled
17
+ * Displays a human-readable relative time string (e.g. "5 minutes ago") that can auto-update on a self-scheduled
9
18
  * timer. Falls back to an absolute date/time after `thresholdMinutes`.
10
19
  *
11
20
  * Inherits typography from the parent — pass `font-size` / `color` through CSS on a surrounding element to
@@ -1,10 +1,14 @@
1
+ import { type AppLocaleValue } from '../../core/locale';
1
2
  export declare class TimeAgoLocalization {
3
+ #private;
4
+ constructor(locale?: () => AppLocaleValue | null | undefined);
2
5
  get locale(): string;
3
6
  get aMinuteAgo(): string;
4
7
  get anHourAgo(): string;
5
8
  get justNow(): string;
6
- get at(): (date: string, time: string) => string;
7
- get hoursAgo(): (hours: number) => string;
8
- get minutesAgo(): (minutes: number) => string;
9
- get yesterday(): (time: string) => string;
9
+ get yesterday(): string;
10
+ at: (date: string, time: string) => string;
11
+ hoursAgo: (hours: number) => string;
12
+ minutesAgo: (minutes: number) => string;
13
+ yesterdayAt: (time: string) => string;
10
14
  }
@@ -1,29 +1,39 @@
1
1
  import { AppLocale } from '../../core/locale';
2
2
  export class TimeAgoLocalization {
3
+ #locale;
4
+ constructor(locale = () => undefined) {
5
+ this.#locale = locale;
6
+ }
3
7
  get locale() {
4
- return loc.locale[AppLocale.current];
8
+ return loc.locale[this.#current];
5
9
  }
6
10
  get aMinuteAgo() {
7
- return loc.aMinuteAgo[AppLocale.current];
11
+ return loc.aMinuteAgo[this.#current];
8
12
  }
9
13
  get anHourAgo() {
10
- return loc.anHourAgo[AppLocale.current];
14
+ return loc.anHourAgo[this.#current];
11
15
  }
12
16
  get justNow() {
13
- return loc.justNow[AppLocale.current];
14
- }
15
- get at() {
16
- return loc.at[AppLocale.current];
17
- }
18
- get hoursAgo() {
19
- return loc.hoursAgo[AppLocale.current];
20
- }
21
- get minutesAgo() {
22
- return loc.minutesAgo[AppLocale.current];
17
+ return loc.justNow[this.#current];
23
18
  }
24
19
  get yesterday() {
25
- return loc.yesterday[AppLocale.current];
20
+ return loc.yesterday[this.#current];
26
21
  }
22
+ get #current() {
23
+ return this.#locale() ?? AppLocale.current;
24
+ }
25
+ at = (date, time) => {
26
+ return loc.at[this.#current](date, time);
27
+ };
28
+ hoursAgo = (hours) => {
29
+ return loc.hoursAgo[this.#current](hours);
30
+ };
31
+ minutesAgo = (minutes) => {
32
+ return loc.minutesAgo[this.#current](minutes);
33
+ };
34
+ yesterdayAt = (time) => {
35
+ return loc.yesterdayAt[this.#current](time);
36
+ };
27
37
  }
28
38
  const loc = {
29
39
  locale: {
@@ -42,6 +52,10 @@ const loc = {
42
52
  en: 'just now',
43
53
  no: 'nettopp nå'
44
54
  },
55
+ yesterday: {
56
+ en: 'yesterday',
57
+ no: 'i går'
58
+ },
45
59
  at: {
46
60
  en: (date, time) => `${date} at ${time}`,
47
61
  no: (date, time) => `${date} kl. ${time}`
@@ -54,8 +68,8 @@ const loc = {
54
68
  en: (minutes) => `${minutes} minutes ago`,
55
69
  no: (minutes) => `${minutes} minutter siden`
56
70
  },
57
- yesterday: {
58
- en: (time) => `Yesterday at ${time}`,
59
- no: (time) => `I går kl. ${time}`
71
+ yesterdayAt: {
72
+ en: (time) => `yesterday at ${time}`,
73
+ no: (time) => `i går kl. ${time}`
60
74
  }
61
75
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.93.5",
3
+ "version": "0.93.7",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",