@flamingo-stack/openframe-frontend-core 0.0.642 → 0.0.644-2208.6318.1
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.
- package/dist/chat-protocol/index.cjs +10 -3
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.js +10 -3
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/source-metadata.d.ts +7 -1
- package/dist/chat-protocol/source-metadata.d.ts.map +1 -1
- package/dist/{chunk-FRCUUK5X.cjs → chunk-2G47VKPD.cjs} +3 -3
- package/dist/{chunk-FRCUUK5X.cjs.map → chunk-2G47VKPD.cjs.map} +1 -1
- package/dist/{chunk-ZGPJ3NVF.js → chunk-3AUBCCTI.js} +3 -3
- package/dist/{chunk-OOOOC5O5.cjs → chunk-3ENJITQA.cjs} +29 -29
- package/dist/{chunk-OOOOC5O5.cjs.map → chunk-3ENJITQA.cjs.map} +1 -1
- package/dist/{chunk-6NHLZORM.js → chunk-3ENOAHWR.js} +6 -6
- package/dist/{chunk-3IPL6G7S.js → chunk-3W563UVF.js} +40 -10
- package/dist/chunk-3W563UVF.js.map +1 -0
- package/dist/{chunk-UFBWNVZZ.js → chunk-4WIS7COJ.js} +7 -7
- package/dist/{chunk-HW7BLVQH.js → chunk-53RGBCL7.js} +4 -4
- package/dist/{chunk-S254VEDE.js → chunk-5GAWR7RX.js} +3 -3
- package/dist/{chunk-O4LL7RQV.cjs → chunk-5QRNCWHS.cjs} +199 -199
- package/dist/{chunk-O4LL7RQV.cjs.map → chunk-5QRNCWHS.cjs.map} +1 -1
- package/dist/{chunk-MJ424FEC.js → chunk-6O2XNGUE.js} +2 -2
- package/dist/{chunk-XFLJC2WR.cjs → chunk-7FI2YKEU.cjs} +59 -59
- package/dist/{chunk-XFLJC2WR.cjs.map → chunk-7FI2YKEU.cjs.map} +1 -1
- package/dist/{chunk-N5C5P2LM.cjs → chunk-CTGCWBU3.cjs} +22 -22
- package/dist/{chunk-N5C5P2LM.cjs.map → chunk-CTGCWBU3.cjs.map} +1 -1
- package/dist/{chunk-YM6L3WM5.js → chunk-DSKO3GPD.js} +3 -3
- package/dist/{chunk-2Z5FPHOL.cjs → chunk-DYJQPJBW.cjs} +20 -20
- package/dist/{chunk-2Z5FPHOL.cjs.map → chunk-DYJQPJBW.cjs.map} +1 -1
- package/dist/{chunk-POPL3W2S.js → chunk-GLGERQO7.js} +3 -3
- package/dist/{chunk-2NRLRRMR.cjs → chunk-GSC2NB5C.cjs} +108 -78
- package/dist/chunk-GSC2NB5C.cjs.map +1 -0
- package/dist/{chunk-SDGMLXIP.js → chunk-JWRMSVNZ.js} +3 -3
- package/dist/{chunk-VHB3I6F3.cjs → chunk-K6KKARAF.cjs} +173 -153
- package/dist/chunk-K6KKARAF.cjs.map +1 -0
- package/dist/{chunk-VKPTN5MT.cjs → chunk-KCO7MZ34.cjs} +6 -6
- package/dist/{chunk-VKPTN5MT.cjs.map → chunk-KCO7MZ34.cjs.map} +1 -1
- package/dist/{chunk-XWGHLSAL.js → chunk-KCS64Q7P.js} +4 -4
- package/dist/{chunk-WL3PNUNY.cjs → chunk-KSSBW5W7.cjs} +81 -81
- package/dist/{chunk-WL3PNUNY.cjs.map → chunk-KSSBW5W7.cjs.map} +1 -1
- package/dist/{chunk-M4PJVFBF.cjs → chunk-LJ5VSU2Q.cjs} +11 -11
- package/dist/{chunk-M4PJVFBF.cjs.map → chunk-LJ5VSU2Q.cjs.map} +1 -1
- package/dist/{chunk-EW3MSJOE.cjs → chunk-M7NQPYQB.cjs} +33 -33
- package/dist/{chunk-EW3MSJOE.cjs.map → chunk-M7NQPYQB.cjs.map} +1 -1
- package/dist/{chunk-YRSRP4U3.cjs → chunk-ODZ4JBFQ.cjs} +15 -15
- package/dist/{chunk-YRSRP4U3.cjs.map → chunk-ODZ4JBFQ.cjs.map} +1 -1
- package/dist/{chunk-3LXJEXPH.js → chunk-QH6KJ4OZ.js} +2 -2
- package/dist/{chunk-ORFJVMAL.js → chunk-QX3K5SXC.js} +3 -3
- package/dist/{chunk-ZAIYD3MZ.js → chunk-REAWHAOH.js} +3 -3
- package/dist/{chunk-GEIHTN6J.cjs → chunk-S7UGTAIP.cjs} +10 -10
- package/dist/{chunk-GEIHTN6J.cjs.map → chunk-S7UGTAIP.cjs.map} +1 -1
- package/dist/{chunk-3I6XHQUD.js → chunk-TN46CQSO.js} +30 -10
- package/dist/{chunk-3I6XHQUD.js.map → chunk-TN46CQSO.js.map} +1 -1
- package/dist/{chunk-YE3TFNW6.cjs → chunk-V37CP6CT.cjs} +5 -5
- package/dist/{chunk-YE3TFNW6.cjs.map → chunk-V37CP6CT.cjs.map} +1 -1
- package/dist/{chunk-SE6YRE3R.cjs → chunk-W7VZHI37.cjs} +32 -32
- package/dist/{chunk-SE6YRE3R.cjs.map → chunk-W7VZHI37.cjs.map} +1 -1
- package/dist/{chunk-6GY6DFIH.js → chunk-WTUX4SNF.js} +6 -6
- package/dist/{chunk-QY25ZP2V.cjs → chunk-YCO7DTCF.cjs} +28 -28
- package/dist/{chunk-QY25ZP2V.cjs.map → chunk-YCO7DTCF.cjs.map} +1 -1
- package/dist/{chunk-J4RZVLLQ.js → chunk-YRGIQZSU.js} +5 -5
- package/dist/{chunk-M7QROULE.js → chunk-YRWXGZLV.js} +5 -5
- package/dist/{chunk-OYI3K5R6.cjs → chunk-ZAQ6CKTU.cjs} +6 -6
- package/dist/{chunk-OYI3K5R6.cjs.map → chunk-ZAQ6CKTU.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +16 -16
- package/dist/components/case-studies/index.js +4 -4
- package/dist/components/chat/entity-cards/program-card.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +3 -3
- package/dist/components/chat/index.js +2 -2
- package/dist/components/contact/index.cjs +5 -5
- package/dist/components/contact/index.js +4 -4
- package/dist/components/docs/index.cjs +8 -8
- package/dist/components/docs/index.js +7 -7
- package/dist/components/embeds/index.cjs +5 -5
- package/dist/components/embeds/index.js +4 -4
- package/dist/components/faq/index.cjs +5 -5
- package/dist/components/faq/index.js +4 -4
- package/dist/components/features/index.cjs +4 -4
- package/dist/components/features/index.js +3 -3
- package/dist/components/help-center-pages/index.cjs +24 -24
- package/dist/components/help-center-pages/index.js +15 -15
- package/dist/components/index.cjs +53 -53
- package/dist/components/index.js +15 -15
- package/dist/components/meeting-scheduler/index.cjs +34 -34
- package/dist/components/meeting-scheduler/index.js +3 -3
- package/dist/components/navigation/index.cjs +7 -7
- package/dist/components/navigation/index.js +6 -6
- package/dist/components/onboarding-guides/index.cjs +7 -7
- package/dist/components/onboarding-guides/index.js +6 -6
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/tickets/index.cjs +8 -8
- package/dist/components/tickets/index.js +7 -7
- package/dist/components/ui/drawer.d.ts +19 -5
- package/dist/components/ui/drawer.d.ts.map +1 -1
- package/dist/components/ui/index.cjs +4 -4
- package/dist/components/ui/index.js +3 -3
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/utils/format.d.ts +39 -4
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/index.cjs +25 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +25 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/chat-protocol/__tests__/source-metadata.test.ts +49 -0
- package/src/chat-protocol/source-metadata.ts +46 -6
- package/src/components/chat/entity-cards/program-card.tsx +46 -8
- package/src/components/ui/.drawer.md +1 -0
- package/src/components/ui/__tests__/drawer-size.test.tsx +38 -0
- package/src/components/ui/drawer.tsx +44 -9
- package/src/utils/__tests__/format-program-dates.test.ts +91 -0
- package/src/utils/format.ts +79 -7
- package/src/utils/index.ts +2 -0
- package/dist/chunk-2NRLRRMR.cjs.map +0 -1
- package/dist/chunk-3IPL6G7S.js.map +0 -1
- package/dist/chunk-VHB3I6F3.cjs.map +0 -1
- /package/dist/{chunk-ZGPJ3NVF.js.map → chunk-3AUBCCTI.js.map} +0 -0
- /package/dist/{chunk-6NHLZORM.js.map → chunk-3ENOAHWR.js.map} +0 -0
- /package/dist/{chunk-UFBWNVZZ.js.map → chunk-4WIS7COJ.js.map} +0 -0
- /package/dist/{chunk-HW7BLVQH.js.map → chunk-53RGBCL7.js.map} +0 -0
- /package/dist/{chunk-S254VEDE.js.map → chunk-5GAWR7RX.js.map} +0 -0
- /package/dist/{chunk-MJ424FEC.js.map → chunk-6O2XNGUE.js.map} +0 -0
- /package/dist/{chunk-YM6L3WM5.js.map → chunk-DSKO3GPD.js.map} +0 -0
- /package/dist/{chunk-POPL3W2S.js.map → chunk-GLGERQO7.js.map} +0 -0
- /package/dist/{chunk-SDGMLXIP.js.map → chunk-JWRMSVNZ.js.map} +0 -0
- /package/dist/{chunk-XWGHLSAL.js.map → chunk-KCS64Q7P.js.map} +0 -0
- /package/dist/{chunk-3LXJEXPH.js.map → chunk-QH6KJ4OZ.js.map} +0 -0
- /package/dist/{chunk-ORFJVMAL.js.map → chunk-QX3K5SXC.js.map} +0 -0
- /package/dist/{chunk-ZAIYD3MZ.js.map → chunk-REAWHAOH.js.map} +0 -0
- /package/dist/{chunk-6GY6DFIH.js.map → chunk-WTUX4SNF.js.map} +0 -0
- /package/dist/{chunk-J4RZVLLQ.js.map → chunk-YRGIQZSU.js.map} +0 -0
- /package/dist/{chunk-M7QROULE.js.map → chunk-YRWXGZLV.js.map} +0 -0
package/package.json
CHANGED
|
@@ -117,6 +117,55 @@ describe('sourceMetadataEvent', () => {
|
|
|
117
117
|
expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// A same-origin href is the hub's NORMAL output when the owning platform is
|
|
121
|
+
// the serving platform. Dropping it left every guide chip with a name and no
|
|
122
|
+
// destination, before the consumer's own absolutiser could ever run.
|
|
123
|
+
it('keeps a root-relative external URL', () => {
|
|
124
|
+
const event = sourceMetadataEvent({
|
|
125
|
+
sources: [
|
|
126
|
+
{
|
|
127
|
+
index: 1,
|
|
128
|
+
name: 'Guide',
|
|
129
|
+
path: 'onboarding-guides/x',
|
|
130
|
+
documentType: 'onboarding_guide',
|
|
131
|
+
externalUrl: '/onboarding-guides/x',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
expect(event?.sources?.[0].externalUrl).toBe('/onboarding-guides/x');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('keeps a root-relative external URL on a grouped item', () => {
|
|
139
|
+
const event = sourceMetadataEvent({
|
|
140
|
+
sources: [
|
|
141
|
+
{
|
|
142
|
+
index: 1,
|
|
143
|
+
name: 'Guides',
|
|
144
|
+
items: [{ id: 'a', documentType: 'onboarding_guide', name: 'A', externalUrl: '/onboarding-guides/a' }],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
expect(event?.sources?.[0].items?.[0].externalUrl).toBe('/onboarding-guides/a');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('drops a protocol-relative URL, which is a third-party origin and not a path', () => {
|
|
152
|
+
const event = sourceMetadataEvent({
|
|
153
|
+
sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', externalUrl: '//evil.test/x' }],
|
|
154
|
+
});
|
|
155
|
+
expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('drops an href carrying control or zero-width characters', () => {
|
|
159
|
+
const event = sourceMetadataEvent({
|
|
160
|
+
sources: [
|
|
161
|
+
{ index: 1, name: 'A', externalUrl: '/docs/\u200bx' },
|
|
162
|
+
{ index: 2, name: 'B', externalUrl: 'https://x.test/\u0000y' },
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
expect(event?.sources?.[0]).not.toHaveProperty('externalUrl');
|
|
166
|
+
expect(event?.sources?.[1]).not.toHaveProperty('externalUrl');
|
|
167
|
+
});
|
|
168
|
+
|
|
120
169
|
it('preserves an explicit null targetPlatform, which means "no destination"', () => {
|
|
121
170
|
const event = sourceMetadataEvent({
|
|
122
171
|
sources: [{ index: 1, name: 'Doc', path: 'docs/x', documentType: 'markdown', targetPlatform: null }],
|
|
@@ -10,7 +10,13 @@
|
|
|
10
10
|
* Everything is validated, and anything that fails is DROPPED rather than
|
|
11
11
|
* repaired: this payload is assembled from a remote MCP server's tool output,
|
|
12
12
|
* so a malformed row means an upstream contract slip, and rendering a chip with
|
|
13
|
-
* a blank title or
|
|
13
|
+
* a blank title or an unsafe href is worse than rendering nothing.
|
|
14
|
+
*
|
|
15
|
+
* "Unsafe" is the operative word, and it is not a synonym for "relative".
|
|
16
|
+
* Links go through `linkUrl` (absolute https OR a root-relative path); only
|
|
17
|
+
* MEDIA urls, which have no origin to resolve against, go through `httpsUrl`.
|
|
18
|
+
* Conflating the two is what made every same-origin source chip lose its
|
|
19
|
+
* destination while keeping its name.
|
|
14
20
|
*
|
|
15
21
|
* Server-safe: no React, no browser APIs beyond `URL`.
|
|
16
22
|
*/
|
|
@@ -44,11 +50,18 @@ function nullableText(value: unknown): string | null | undefined {
|
|
|
44
50
|
return value === null ? null : text(value);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
53
|
+
/** Control, zero-width and line-separator characters — never legitimate in a
|
|
54
|
+
* URL we are about to render, and the classic way a payload smuggles one
|
|
55
|
+
* href past a reader's eye. Same set the render-time `safeHref` rejects. */
|
|
56
|
+
const UNSAFE_URL_CHARS = /[\u0000-\u001f\u007f\u200b-\u200d\u2028\u2029\ufeff]/;
|
|
57
|
+
|
|
58
|
+
/** An absolute https URL, or nothing. Plain http and non-URLs are dropped —
|
|
59
|
+
* these become MEDIA sources (`<video src>`, poster images), which have no
|
|
60
|
+
* origin to resolve against and so must be absolute. For a LINK, use
|
|
61
|
+
* `linkUrl` — a same-origin path is valid there and this would discard it. */
|
|
49
62
|
function httpsUrl(value: unknown): string | undefined {
|
|
50
63
|
const candidate = text(value);
|
|
51
|
-
if (!candidate) return undefined;
|
|
64
|
+
if (!candidate || UNSAFE_URL_CHARS.test(candidate)) return undefined;
|
|
52
65
|
try {
|
|
53
66
|
return new URL(candidate).protocol === 'https:' ? candidate : undefined;
|
|
54
67
|
} catch {
|
|
@@ -56,6 +69,33 @@ function httpsUrl(value: unknown): string | undefined {
|
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
|
|
72
|
+
/**
|
|
73
|
+
* A URL that is safe to render as a source chip's href: an absolute https URL,
|
|
74
|
+
* or a ROOT-RELATIVE path (`/onboarding-guides/foo`).
|
|
75
|
+
*
|
|
76
|
+
* Root-relative is the whole reason this exists separately from `httpsUrl`.
|
|
77
|
+
* The hub emits a relative href whenever the owning platform is the serving
|
|
78
|
+
* platform — correct for its own chat, and correct for any consumer that knows
|
|
79
|
+
* the hub origin (the dashboard absolutises hub-owned hrefs itself). Running
|
|
80
|
+
* `new URL()` with no base on such a path THROWS, so treating "not an absolute
|
|
81
|
+
* https URL" as hostile silently deleted every same-origin link before the code
|
|
82
|
+
* that would have resolved it ever ran, leaving a chip with a name and no
|
|
83
|
+
* destination.
|
|
84
|
+
*
|
|
85
|
+
* Deliberately STRICTER than the render-time `safeHref`, which also permits
|
|
86
|
+
* `http:` and `mailto:`. This payload is assembled from a remote MCP server's
|
|
87
|
+
* tool output, so the ingest guard stays fail-closed on scheme; the two differ
|
|
88
|
+
* on purpose, and only in the safe direction.
|
|
89
|
+
*/
|
|
90
|
+
function linkUrl(value: unknown): string | undefined {
|
|
91
|
+
const candidate = text(value);
|
|
92
|
+
if (!candidate || UNSAFE_URL_CHARS.test(candidate)) return undefined;
|
|
93
|
+
// Same-origin path. `//host` is protocol-relative, not a path — it would
|
|
94
|
+
// resolve to a THIRD-PARTY origin, so it is rejected with the rest.
|
|
95
|
+
if (candidate.startsWith('/')) return candidate.startsWith('//') ? undefined : candidate;
|
|
96
|
+
return httpsUrl(candidate);
|
|
97
|
+
}
|
|
98
|
+
|
|
59
99
|
/**
|
|
60
100
|
* A YouTube video id, from either a bare id or any of the watch/short/embed URL
|
|
61
101
|
* shapes. Returns the ID, never a URL — the player takes an id.
|
|
@@ -89,7 +129,7 @@ function sourceItems(value: unknown): NonNullable<ChatSource['items']> | undefin
|
|
|
89
129
|
// A grouped row without these three has nothing to render OR navigate with.
|
|
90
130
|
if (!id || !documentType || !name) return [];
|
|
91
131
|
|
|
92
|
-
const externalUrl =
|
|
132
|
+
const externalUrl = linkUrl(item.externalUrl);
|
|
93
133
|
const targetPlatform = nullableText(item.targetPlatform);
|
|
94
134
|
const path = nullableText(item.path);
|
|
95
135
|
return [
|
|
@@ -133,7 +173,7 @@ function sources(value: unknown): ChatSource[] {
|
|
|
133
173
|
|
|
134
174
|
const path = text(candidate.path);
|
|
135
175
|
const documentType = text(candidate.documentType);
|
|
136
|
-
const externalUrl =
|
|
176
|
+
const externalUrl = linkUrl(candidate.externalUrl);
|
|
137
177
|
const targetPlatform = nullableText(candidate.targetPlatform);
|
|
138
178
|
const id = text(candidate.id);
|
|
139
179
|
const sourceRepo = text(candidate.sourceRepo);
|
|
@@ -25,7 +25,12 @@ import type React from 'react';
|
|
|
25
25
|
import { useState } from 'react';
|
|
26
26
|
import Image from '../../../embed-shims/next-image';
|
|
27
27
|
import { cn } from '../../../utils/cn';
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
formatDurationCompact,
|
|
30
|
+
formatTimeWithTimezone,
|
|
31
|
+
formatDateWithTimezone,
|
|
32
|
+
formatDurationFromRange,
|
|
33
|
+
} from '../../../utils/format';
|
|
29
34
|
import { isImageMedia } from '../../../utils/media-type';
|
|
30
35
|
import { Button } from '../../ui/button/button';
|
|
31
36
|
import { ImageGalleryModal } from '../../ui/image-gallery-modal';
|
|
@@ -181,19 +186,45 @@ function getHosts(hosts: ProgramHost[] | null | undefined): Array<{ name: string
|
|
|
181
186
|
* been `in`-guarded for `start_at`. Each field is validated rather than
|
|
182
187
|
* asserted — the generic item type does not declare them.
|
|
183
188
|
*/
|
|
189
|
+
/** Read a string column off the generic item type, which does not declare it. */
|
|
190
|
+
const programStr = (value: unknown): string | null => (typeof value === 'string' && value ? value : null);
|
|
191
|
+
|
|
184
192
|
function webinarTiming(item: BaseProgramItem): {
|
|
185
193
|
startAt: string | null;
|
|
186
194
|
endAt: string | null;
|
|
187
195
|
timezone: string | null;
|
|
188
196
|
} {
|
|
189
|
-
const str = (value: unknown): string | null => (typeof value === 'string' && value ? value : null);
|
|
190
197
|
return {
|
|
191
|
-
startAt: 'start_at' in item ?
|
|
192
|
-
endAt: 'end_at' in item ?
|
|
193
|
-
timezone: 'timezone' in item ?
|
|
198
|
+
startAt: 'start_at' in item ? programStr(item.start_at) : null,
|
|
199
|
+
endAt: 'end_at' in item ? programStr(item.end_at) : null,
|
|
200
|
+
timezone: 'timezone' in item ? programStr(item.timezone) : null,
|
|
194
201
|
};
|
|
195
202
|
}
|
|
196
203
|
|
|
204
|
+
/**
|
|
205
|
+
* The instant and zone this card renders its DATE in.
|
|
206
|
+
*
|
|
207
|
+
* A card must render every part of ONE timestamp in ONE zone. The date used to
|
|
208
|
+
* come from `item.date` pinned to UTC while the time printed beside it came
|
|
209
|
+
* from `start_at` in the event's own IANA zone, so a webinar at
|
|
210
|
+
* `2026-03-20T01:18Z` / `America/New_York` read "Mar 20, 2026 · 9:18 PM" — a
|
|
211
|
+
* date and a time that never coexisted. Where the row carries a zone, the date
|
|
212
|
+
* is now derived from the SAME instant the time is, in that same zone.
|
|
213
|
+
*
|
|
214
|
+
* A row with no zone keeps the UTC pin (`formatUtc`). That pin is the React
|
|
215
|
+
* #418 hydration fix, not an oversight: do not "fix the timezone" by making it
|
|
216
|
+
* render local — that produces a different wrong answer, one that also differs
|
|
217
|
+
* between server and client.
|
|
218
|
+
*/
|
|
219
|
+
function programDateInstant(item: BaseProgramItem): { instant: string | null; timezone: string | null } {
|
|
220
|
+
const timezone = 'timezone' in item ? programStr(item.timezone) : null;
|
|
221
|
+
if (!timezone) return { instant: null, timezone: null };
|
|
222
|
+
// Prefer the scheduling instant the TIME is read from, so the two halves
|
|
223
|
+
// cannot disagree even if `item.date` carries a display override upstream.
|
|
224
|
+
const startAt = 'start_at' in item ? programStr(item.start_at) : null;
|
|
225
|
+
return { instant: startAt ?? programStr(item.date), timezone };
|
|
226
|
+
}
|
|
227
|
+
|
|
197
228
|
function MediaGallery({ images, title }: { images: ProgramMedia[]; title: string }) {
|
|
198
229
|
const [selectedImageIndex, setSelectedImageIndex] = useState<number | null>(null);
|
|
199
230
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
@@ -293,13 +324,18 @@ export function ProgramCard<T extends BaseProgramItem>({
|
|
|
293
324
|
if (typeof loc === 'string' && loc.trim().length > 0) return loc;
|
|
294
325
|
} else if (config.type === 'webinar' && 'start_at' in item) {
|
|
295
326
|
const { startAt, endAt, timezone } = webinarTiming(item);
|
|
296
|
-
|
|
327
|
+
// Compact densities join plain strings, so the zone rides inline here;
|
|
328
|
+
// the default density renders it as its own styled span instead.
|
|
329
|
+
const time = formatTimeWithTimezone(startAt, timezone, { withZoneLabel: true });
|
|
297
330
|
const dur = formatDurationFromRange(startAt, endAt);
|
|
298
331
|
return dur ? `${time} · ${dur}` : time;
|
|
299
332
|
}
|
|
300
333
|
return null;
|
|
301
334
|
};
|
|
302
|
-
const
|
|
335
|
+
const zonedDate = programDateInstant(item);
|
|
336
|
+
const compactDate = zonedDate.instant
|
|
337
|
+
? formatDateWithTimezone(zonedDate.instant, zonedDate.timezone, 'medium')
|
|
338
|
+
: formatUtc(new Date(item.date), 'MMM d, yyyy');
|
|
303
339
|
|
|
304
340
|
if (size === 'portrait') {
|
|
305
341
|
// Rail/strip density — mapped onto the shared <EntityPortraitCard> shell
|
|
@@ -378,7 +414,9 @@ export function ProgramCard<T extends BaseProgramItem>({
|
|
|
378
414
|
}
|
|
379
415
|
|
|
380
416
|
const itemDate = new Date(item.date);
|
|
381
|
-
const dateFormat =
|
|
417
|
+
const dateFormat = zonedDate.instant
|
|
418
|
+
? formatDateWithTimezone(zonedDate.instant, zonedDate.timezone, 'weekday')
|
|
419
|
+
: formatUtc(itemDate, 'EEEE d MMMM');
|
|
382
420
|
|
|
383
421
|
const defaultRenderMeta = () => {
|
|
384
422
|
if (config.type === 'podcast' && 'duration_seconds' in item && !isScheduled) {
|
|
@@ -22,6 +22,7 @@ A full-featured drawer component built on Radix UI's Dialog primitive, providing
|
|
|
22
22
|
|---|---|---|---|
|
|
23
23
|
| `side` | `"right" \| "left" \| "top" \| "bottom"` | `"right"` | Slide direction |
|
|
24
24
|
| `flush` | `boolean` | `false` | Full-bleed on mobile; floating card on desktop |
|
|
25
|
+
| `size` | `"default" \| "wide"` | `"default"` | Panel size preset; `wide` is 90% of the viewport. Use it instead of a width class. Not combinable with `resizable` (the handle owns the size; a type error) |
|
|
25
26
|
| `resizable` | `boolean` | `false` | Enables drag-to-resize handle |
|
|
26
27
|
| `minSize` | `number` | — | Minimum panel size in px |
|
|
27
28
|
| `maxSize` | `number` | — | Maximum panel size in px (clamped to viewport) |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { Drawer, DrawerContent, DrawerTitle } from '../drawer';
|
|
4
|
+
|
|
5
|
+
function panelOf(props: { side?: 'right' | 'left' | 'top' | 'bottom'; size?: 'default' | 'wide' }) {
|
|
6
|
+
render(
|
|
7
|
+
<Drawer open>
|
|
8
|
+
<DrawerContent {...props} aria-describedby={undefined}>
|
|
9
|
+
<DrawerTitle>Panel</DrawerTitle>
|
|
10
|
+
</DrawerContent>
|
|
11
|
+
</Drawer>,
|
|
12
|
+
);
|
|
13
|
+
// The title sits in the panel's own tree; the panel is the closest bg-ods-card element.
|
|
14
|
+
return screen.getByText('Panel').closest('.bg-ods-card');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('DrawerContent size', () => {
|
|
18
|
+
it('wide sets the panel to 90% of the viewport width on a side drawer', () => {
|
|
19
|
+
expect(panelOf({ side: 'right', size: 'wide' })).toHaveClass('w-[90vw]');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('wide sets the height on a top or bottom drawer', () => {
|
|
23
|
+
expect(panelOf({ side: 'bottom', size: 'wide' })).toHaveClass('h-[90vh]');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('default adds no size class', () => {
|
|
27
|
+
const panel = panelOf({ side: 'right' });
|
|
28
|
+
expect(panel).not.toHaveClass('w-[90vw]');
|
|
29
|
+
expect(panel).not.toHaveClass('h-[90vh]');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('cannot combine a size preset with the resize handle', () => {
|
|
33
|
+
// Type-level contract: a resizable panel sizes itself inline, so `wide` would be silently dropped.
|
|
34
|
+
// @ts-expect-error size="wide" and resizable are mutually exclusive
|
|
35
|
+
const props: Parameters<typeof DrawerContent>[0] = { size: 'wide', resizable: true };
|
|
36
|
+
expect(props.resizable).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -104,8 +104,19 @@ const drawerPanelVariants = cva(
|
|
|
104
104
|
false: 'gap-4 rounded-md border border-ods-border p-4',
|
|
105
105
|
true: '',
|
|
106
106
|
},
|
|
107
|
+
/** Panel size along the axis the drawer slides on. `default` leaves it to
|
|
108
|
+
* the content (or `resizable`); `wide` is the admin detail panel, 90% of
|
|
109
|
+
* the viewport. Set the size here, never with a width class. */
|
|
110
|
+
size: {
|
|
111
|
+
default: '',
|
|
112
|
+
wide: '',
|
|
113
|
+
},
|
|
107
114
|
},
|
|
108
115
|
compoundVariants: [
|
|
116
|
+
{ side: 'right', size: 'wide', class: 'w-[90vw]' },
|
|
117
|
+
{ side: 'left', size: 'wide', class: 'w-[90vw]' },
|
|
118
|
+
{ side: 'top', size: 'wide', class: 'h-[90vh]' },
|
|
119
|
+
{ side: 'bottom', size: 'wide', class: 'h-[90vh]' },
|
|
109
120
|
// flush=true → drops inner padding/gap so the consumer fully owns
|
|
110
121
|
// internal layout, BUT preserves the card chrome (rounded + border)
|
|
111
122
|
// on desktop so the panel still reads as an elevated card.
|
|
@@ -118,6 +129,7 @@ const drawerPanelVariants = cva(
|
|
|
118
129
|
defaultVariants: {
|
|
119
130
|
side: 'right',
|
|
120
131
|
flush: false,
|
|
132
|
+
size: 'default',
|
|
121
133
|
},
|
|
122
134
|
},
|
|
123
135
|
);
|
|
@@ -304,16 +316,12 @@ function DrawerResizeHandle({ side, size, minSize, maxSize, onSize, ariaLabel }:
|
|
|
304
316
|
);
|
|
305
317
|
}
|
|
306
318
|
|
|
307
|
-
interface
|
|
319
|
+
interface DrawerContentBaseProps
|
|
308
320
|
extends Omit<ComponentPropsWithoutRef<typeof DialogPrimitive.Content>, 'style'>, VariantProps<typeof drawerVariants> {
|
|
309
321
|
/** Remove outer wrapper padding and panel rounded/border/padding so the
|
|
310
322
|
* panel attaches flush to the viewport edge. Use for full-height side
|
|
311
323
|
* panels (e.g. the embedded chat). */
|
|
312
324
|
flush?: boolean;
|
|
313
|
-
/** Enable the drag-to-resize handle on the inside-facing edge. Only
|
|
314
|
-
* active for `side="left"` / `side="right"` (or `top`/`bottom`) on
|
|
315
|
-
* non-mobile viewports. */
|
|
316
|
-
resizable?: boolean;
|
|
317
325
|
/** Minimum allowed size (px) when resizable. */
|
|
318
326
|
minSize?: number;
|
|
319
327
|
/** Maximum allowed size (px) when resizable. Also clamped by viewport. */
|
|
@@ -344,11 +352,34 @@ interface DrawerContentProps
|
|
|
344
352
|
offsetHeader?: boolean;
|
|
345
353
|
}
|
|
346
354
|
|
|
355
|
+
/**
|
|
356
|
+
* The panel's size has ONE owner: a `size` preset OR the drag-to-resize handle.
|
|
357
|
+
* A resizable panel sizes itself inline, which would silently override `wide`,
|
|
358
|
+
* so the two cannot be combined (a type error, not a runtime surprise).
|
|
359
|
+
*/
|
|
360
|
+
type DrawerContentSizing =
|
|
361
|
+
| {
|
|
362
|
+
/** Panel size preset (`wide` = 90% of the viewport). Use it instead of a
|
|
363
|
+
* width/height class. */
|
|
364
|
+
size?: 'default' | 'wide';
|
|
365
|
+
resizable?: false;
|
|
366
|
+
}
|
|
367
|
+
| {
|
|
368
|
+
size?: 'default';
|
|
369
|
+
/** Enable the drag-to-resize handle on the inside-facing edge. Only
|
|
370
|
+
* active for `side="left"` / `side="right"` (or `top`/`bottom`) on
|
|
371
|
+
* non-mobile viewports. The handle owns the size, so no `size` preset. */
|
|
372
|
+
resizable: true;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
type DrawerContentProps = DrawerContentBaseProps & DrawerContentSizing;
|
|
376
|
+
|
|
347
377
|
const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, DrawerContentProps>(
|
|
348
378
|
(
|
|
349
379
|
{
|
|
350
380
|
side = 'right',
|
|
351
381
|
flush = false,
|
|
382
|
+
size = 'default',
|
|
352
383
|
resizable = false,
|
|
353
384
|
minSize = 320,
|
|
354
385
|
maxSize = 1280,
|
|
@@ -383,7 +414,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
|
|
|
383
414
|
return () => mq.removeEventListener('change', update);
|
|
384
415
|
}, [mobileBreakpoint]);
|
|
385
416
|
|
|
386
|
-
const { size, setSize } = useResizableSize({
|
|
417
|
+
const { size: resizedSize, setSize } = useResizableSize({
|
|
387
418
|
enabled: resizable,
|
|
388
419
|
isHorizontal,
|
|
389
420
|
minSize,
|
|
@@ -393,7 +424,11 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
|
|
|
393
424
|
});
|
|
394
425
|
|
|
395
426
|
const applyInlineSize = resizable && !isMobile;
|
|
396
|
-
const sizeStyle: CSSProperties = applyInlineSize
|
|
427
|
+
const sizeStyle: CSSProperties = applyInlineSize
|
|
428
|
+
? isHorizontal
|
|
429
|
+
? { width: resizedSize }
|
|
430
|
+
: { height: resizedSize }
|
|
431
|
+
: {};
|
|
397
432
|
|
|
398
433
|
return (
|
|
399
434
|
<DrawerPortal>
|
|
@@ -410,7 +445,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
|
|
|
410
445
|
{applyInlineSize ? (
|
|
411
446
|
<DrawerResizeHandle
|
|
412
447
|
side={resolvedSide}
|
|
413
|
-
size={
|
|
448
|
+
size={resizedSize}
|
|
414
449
|
minSize={minSize}
|
|
415
450
|
maxSize={maxSize}
|
|
416
451
|
onSize={setSize}
|
|
@@ -418,7 +453,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
|
|
|
418
453
|
/>
|
|
419
454
|
) : null}
|
|
420
455
|
<div
|
|
421
|
-
className={cn(drawerPanelVariants({ side, flush }), className, panelClassName)}
|
|
456
|
+
className={cn(drawerPanelVariants({ side, flush, size }), className, panelClassName)}
|
|
422
457
|
style={{ ...sizeStyle, ...panelStyle }}
|
|
423
458
|
>
|
|
424
459
|
{children}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { formatDateWithTimezone, formatDurationFromRange, formatTimeWithTimezone } from '../format';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* These three formatters render the date, time and duration of ONE event, side
|
|
7
|
+
* by side on the program card. They had no coverage at all, which is how a
|
|
8
|
+
* missing sign guard shipped: a live webinar row whose `end_at` preceded its
|
|
9
|
+
* `start_at` printed "-45m" on the card.
|
|
10
|
+
*/
|
|
11
|
+
describe('formatDurationFromRange', () => {
|
|
12
|
+
it('formats a positive range', () => {
|
|
13
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:45:00Z')).toBe('45m');
|
|
14
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T01:30:00Z')).toBe('1h 30m');
|
|
15
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T02:00:00Z')).toBe('2h');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders NOTHING when the event ends before it starts', () => {
|
|
19
|
+
// The live row that produced the bug report: e6cff6f8, end_at 45 minutes
|
|
20
|
+
// before start_at. It used to render "-45m" — and note that a -90 minute
|
|
21
|
+
// range never reached the `>= 60` branch, so it printed "-90m" rather than
|
|
22
|
+
// "-1h 30m": the output was not merely wrong, it was inconsistently wrong.
|
|
23
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-19T23:15:25Z')).toBe('');
|
|
24
|
+
expect(formatDurationFromRange('2026-03-20T02:00:00Z', '2026-03-20T00:30:00Z')).toBe('');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders nothing for a zero-length or unparseable range', () => {
|
|
28
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:00:00Z')).toBe('');
|
|
29
|
+
// Used to print the literal string "NaNm".
|
|
30
|
+
expect(formatDurationFromRange('not-a-date', '2026-03-20T00:00:00Z')).toBe('');
|
|
31
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', 'not-a-date')).toBe('');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders nothing when an endpoint is missing', () => {
|
|
35
|
+
expect(formatDurationFromRange(null, '2026-03-20T00:00:00Z')).toBe('');
|
|
36
|
+
expect(formatDurationFromRange('2026-03-20T00:00:00Z', undefined)).toBe('');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('formatDateWithTimezone / formatTimeWithTimezone agree on the zone', () => {
|
|
41
|
+
// The reported defect: the card printed the date in UTC and the time beside
|
|
42
|
+
// it in the event's own zone, so this instant read "Mar 20, 2026 · 9:18 PM"
|
|
43
|
+
// — 9:18 PM on the 20th is not when it happens, 9:18 PM on the 19th is.
|
|
44
|
+
const instant = '2026-03-20T01:18:00Z';
|
|
45
|
+
const zone = 'America/New_York';
|
|
46
|
+
|
|
47
|
+
it('puts the date on the event-local day, not the UTC day', () => {
|
|
48
|
+
expect(formatDateWithTimezone(instant, zone)).toBe('Mar 19, 2026');
|
|
49
|
+
expect(formatTimeWithTimezone(instant, zone)).toBe('9:18 PM');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renders the weekday style in the same zone', () => {
|
|
53
|
+
// Note the copy shift: the default density used to build this from the
|
|
54
|
+
// date-fns pattern 'EEEE d MMMM' ("Thursday 19 March"). Intl's en-US order
|
|
55
|
+
// is "Thursday, March 19". Preserving the old wording would mean composing
|
|
56
|
+
// the string from Intl parts by hand — re-introducing exactly the bespoke
|
|
57
|
+
// date arithmetic this change exists to remove — so the locale-correct
|
|
58
|
+
// form wins, consistent with every other formatter in this file.
|
|
59
|
+
expect(formatDateWithTimezone(instant, zone, 'weekday')).toBe('Thursday, March 19');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('falls back to UTC on both halves when no zone is given', () => {
|
|
63
|
+
expect(formatDateWithTimezone(instant, null)).toBe('Mar 20, 2026');
|
|
64
|
+
expect(formatTimeWithTimezone(instant, null)).toBe('1:18 AM');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('handles a legacy fixed-offset label consistently across both halves', () => {
|
|
68
|
+
// "EST" does NOT throw — Node resolves it as a legacy fixed UTC-5 alias, so
|
|
69
|
+
// it lands on the 19th at 8:18 PM (no DST, unlike America/New_York's EDT).
|
|
70
|
+
// What matters is that the date and the time agree about the zone.
|
|
71
|
+
expect(formatDateWithTimezone(instant, 'EST')).toBe('Mar 19, 2026');
|
|
72
|
+
expect(formatTimeWithTimezone(instant, 'EST')).toBe('8:18 PM');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('degrades BOTH halves to UTC on a genuinely invalid zone', () => {
|
|
76
|
+
// A label Intl cannot resolve DOES throw a RangeError. Both formatters must
|
|
77
|
+
// catch it the same way, or the pair disagrees about which zone it used.
|
|
78
|
+
expect(formatDateWithTimezone(instant, 'Not/AZone')).toBe('Mar 20, 2026');
|
|
79
|
+
expect(formatTimeWithTimezone(instant, 'Not/AZone')).toBe('1:18 AM');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('appends the zone label only when asked', () => {
|
|
83
|
+
expect(formatTimeWithTimezone(instant, zone, { withZoneLabel: true })).toBe('9:18 PM EDT');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('renders nothing for a missing or unparseable date', () => {
|
|
87
|
+
expect(formatDateWithTimezone(null, zone)).toBe('');
|
|
88
|
+
expect(formatDateWithTimezone('not-a-date', zone)).toBe('');
|
|
89
|
+
expect(formatTimeWithTimezone('not-a-date', zone)).toBe('');
|
|
90
|
+
});
|
|
91
|
+
});
|
package/src/utils/format.ts
CHANGED
|
@@ -273,35 +273,105 @@ export function formatDurationCompact(seconds: number | null | undefined): strin
|
|
|
273
273
|
* fixing the React #418 hydration mismatch — AND shows the true event time
|
|
274
274
|
* (4:00 PM EDT, not the 8:00 PM UTC a plain UTC pin would show, nor the
|
|
275
275
|
* viewer-local time the old unpinned call produced). Falls back to UTC when no
|
|
276
|
-
* zone is given, and tolerates
|
|
277
|
-
* The zone LABEL is rendered separately by callers
|
|
276
|
+
* zone is given, and tolerates an unresolvable label (legacy data) without throwing.
|
|
277
|
+
* The zone LABEL is rendered separately by callers that have room for their own
|
|
278
|
+
* styled span; pass `withZoneLabel` where the output is a plain joined string
|
|
279
|
+
* (the compact card densities) and the short name is appended inline — an
|
|
280
|
+
* unlabelled wall clock beside a date is readable but still ambiguous about
|
|
281
|
+
* WHICH zone it is stating.
|
|
278
282
|
*
|
|
279
|
-
* Returns: "4:00 PM"
|
|
283
|
+
* Returns: "4:00 PM", or "4:00 PM EDT" with `withZoneLabel`.
|
|
280
284
|
*/
|
|
281
|
-
export function formatTimeWithTimezone(
|
|
285
|
+
export function formatTimeWithTimezone(
|
|
286
|
+
date: Date | string | null | undefined,
|
|
287
|
+
timezone?: string | null,
|
|
288
|
+
options?: { withZoneLabel?: boolean },
|
|
289
|
+
): string {
|
|
282
290
|
if (!date) return '';
|
|
283
291
|
|
|
284
292
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
293
|
+
if (Number.isNaN(dateObj.getTime())) return '';
|
|
285
294
|
const opts: Intl.DateTimeFormatOptions = {
|
|
286
295
|
hour: 'numeric',
|
|
287
296
|
minute: '2-digit',
|
|
288
297
|
hour12: true,
|
|
289
298
|
timeZone: timezone || 'UTC',
|
|
299
|
+
...(options?.withZoneLabel ? { timeZoneName: 'short' as const } : {}),
|
|
290
300
|
};
|
|
291
301
|
try {
|
|
292
302
|
return dateObj.toLocaleTimeString('en-US', opts);
|
|
293
303
|
} catch {
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
304
|
+
// An UNRESOLVABLE `timezone` makes Intl throw a RangeError. Fall back to a
|
|
305
|
+
// UTC-pinned render so we stay deterministic (still no #418) instead of
|
|
306
|
+
// crashing. Note a bare "EST" does NOT land here: Node resolves it as a
|
|
307
|
+
// legacy fixed UTC-5 alias, which is a different wall clock from
|
|
308
|
+
// America/New_York whenever DST is in effect — a data problem, not a
|
|
309
|
+
// crash, and not one this catch can see.
|
|
297
310
|
return dateObj.toLocaleTimeString('en-US', { ...opts, timeZone: 'UTC' });
|
|
298
311
|
}
|
|
299
312
|
}
|
|
300
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Format a webinar/event DATE as the calendar day in its OWN timezone — the
|
|
316
|
+
* sibling of `formatTimeWithTimezone`, and the reason it exists.
|
|
317
|
+
*
|
|
318
|
+
* A card that prints the date in UTC and the time beside it in the event's zone
|
|
319
|
+
* can name a moment that never existed: a webinar at `2026-03-20T01:18Z` in
|
|
320
|
+
* `America/New_York` read "Mar 20, 2026 · 9:18 PM" — 9:18 PM on the 20th is not
|
|
321
|
+
* when it happens, 9:18 PM on the 19th is. Both halves of one timestamp must be
|
|
322
|
+
* rendered in ONE zone. Same UTC fallback and same non-IANA tolerance as the
|
|
323
|
+
* time formatter, so the pair can never disagree about which zone it used.
|
|
324
|
+
*
|
|
325
|
+
* `style` picks the two shapes the program cards actually render:
|
|
326
|
+
* `'medium'` → "Mar 19, 2026" (compact densities), `'weekday'` →
|
|
327
|
+
* "Thursday 19 March" (default density).
|
|
328
|
+
*
|
|
329
|
+
* Returns: "Mar 19, 2026"
|
|
330
|
+
*/
|
|
331
|
+
export type ZonedDateStyle = 'medium' | 'weekday';
|
|
332
|
+
|
|
333
|
+
const ZONED_DATE_STYLES: Record<ZonedDateStyle, Intl.DateTimeFormatOptions> = {
|
|
334
|
+
medium: { year: 'numeric', month: 'short', day: 'numeric' },
|
|
335
|
+
weekday: { weekday: 'long', day: 'numeric', month: 'long' },
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export function formatDateWithTimezone(
|
|
339
|
+
date: Date | string | null | undefined,
|
|
340
|
+
timezone?: string | null,
|
|
341
|
+
style: ZonedDateStyle = 'medium',
|
|
342
|
+
): string {
|
|
343
|
+
if (!date) return '';
|
|
344
|
+
|
|
345
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
346
|
+
if (Number.isNaN(dateObj.getTime())) return '';
|
|
347
|
+
const opts: Intl.DateTimeFormatOptions = {
|
|
348
|
+
...ZONED_DATE_STYLES[style],
|
|
349
|
+
timeZone: timezone || 'UTC',
|
|
350
|
+
};
|
|
351
|
+
try {
|
|
352
|
+
return dateObj.toLocaleDateString('en-US', opts);
|
|
353
|
+
} catch {
|
|
354
|
+
// An unresolvable `timezone` throws a RangeError — same tolerance as
|
|
355
|
+
// `formatTimeWithTimezone`, so a bad row degrades to UTC on BOTH halves
|
|
356
|
+
// rather than only one, which is the whole point of the pair.
|
|
357
|
+
return dateObj.toLocaleDateString('en-US', { ...opts, timeZone: 'UTC' });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
301
361
|
/**
|
|
302
362
|
* Calculate and format duration between two timestamps
|
|
303
363
|
* Used for webinar durations
|
|
304
364
|
* Returns: "1h 30m" or "45m"
|
|
365
|
+
*
|
|
366
|
+
* Returns `''` — the same "nothing to show" this function already returns for a
|
|
367
|
+
* missing endpoint — when the range is not a positive, real duration. An event
|
|
368
|
+
* whose `end_at` precedes its `start_at` is corrupt data, and the unguarded
|
|
369
|
+
* subtraction printed it literally: a live webinar row rendered "-45m" on the
|
|
370
|
+
* card. An unparseable timestamp printed "NaNm" the same way. A renderer shows
|
|
371
|
+
* nothing rather than an impossible value; the write path is what must reject
|
|
372
|
+
* the row. (Note the negative case never even reached the `>= 60` branch, so
|
|
373
|
+
* -90 minutes rendered as "-90m" rather than "-1h 30m" — the output was not
|
|
374
|
+
* just wrong, it was inconsistently wrong.)
|
|
305
375
|
*/
|
|
306
376
|
export function formatDurationFromRange(
|
|
307
377
|
startAt: string | Date | null | undefined,
|
|
@@ -312,7 +382,9 @@ export function formatDurationFromRange(
|
|
|
312
382
|
const start = typeof startAt === 'string' ? new Date(startAt) : startAt;
|
|
313
383
|
const end = typeof endAt === 'string' ? new Date(endAt) : endAt;
|
|
314
384
|
const durationMs = end.getTime() - start.getTime();
|
|
385
|
+
if (!Number.isFinite(durationMs) || durationMs <= 0) return '';
|
|
315
386
|
const minutes = Math.round(durationMs / 60000);
|
|
387
|
+
if (minutes <= 0) return '';
|
|
316
388
|
|
|
317
389
|
if (minutes >= 60) {
|
|
318
390
|
const hours = Math.floor(minutes / 60);
|
package/src/utils/index.ts
CHANGED