@linktr.ee/messaging-react 3.30.0-rc-1785753549 → 3.30.0-rc-1785813043
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/{Card-zNT8CDXp.cjs → Card-BNdM_HTl.cjs} +2 -2
- package/dist/{Card-zNT8CDXp.cjs.map → Card-BNdM_HTl.cjs.map} +1 -1
- package/dist/{Card-C3wgZsLR.js → Card-DF7MA6LU.js} +2 -2
- package/dist/{Card-C3wgZsLR.js.map → Card-DF7MA6LU.js.map} +1 -1
- package/dist/{index-BOT7kzSo.js → index-D6MaA3Za.js} +1675 -1704
- package/dist/{index-BOT7kzSo.js.map → index-D6MaA3Za.js.map} +1 -1
- package/dist/{index-CpruqPcW.cjs → index-DeVx_Ewa.cjs} +3 -3
- package/dist/{index-CpruqPcW.cjs.map → index-DeVx_Ewa.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/components/CustomLinkPreviewList/CustomLinkPreviewList.test.tsx +0 -15
- package/src/components/CustomLinkPreviewList/index.tsx +26 -24
- package/src/components/CustomMessageInput/CustomMessageInput.stories.tsx +2 -50
- package/src/components/CustomMessageInput/CustomMessageInput.test.tsx +2 -160
- package/src/components/CustomMessageInput/index.tsx +16 -134
- package/src/utils/formatRelativeTime.test.ts +29 -27
- package/src/utils/formatRelativeTime.ts +14 -10
|
@@ -68,59 +68,61 @@ describe('formatRelativeTime', () => {
|
|
|
68
68
|
mockDate('2024-01-15T12:00:00Z')
|
|
69
69
|
const date = new Date('2024-01-13T12:00:00Z')
|
|
70
70
|
expect(formatRelativeTime(date)).not.toBe('Yesterday')
|
|
71
|
-
expect(formatRelativeTime(date)).toBe('2d')
|
|
72
71
|
})
|
|
73
72
|
})
|
|
74
73
|
|
|
75
|
-
describe('
|
|
76
|
-
|
|
74
|
+
describe('2-6 days ago (short weekday)', () => {
|
|
75
|
+
// The weekday branch uses the runtime locale
|
|
76
|
+
// (toLocaleDateString(undefined, …)), so assertions avoid fixed
|
|
77
|
+
// strings that would depend on the test runner's ambient ICU locale.
|
|
78
|
+
// A short weekday name is purely alphabetic with no digits.
|
|
79
|
+
const weekdayPattern = /^\p{L}+$/u
|
|
80
|
+
|
|
81
|
+
it('should return a short weekday name for messages 2 days ago', () => {
|
|
77
82
|
mockDate('2024-01-15T12:00:00Z')
|
|
78
|
-
const date = new Date('2024-01-13T12:00:00Z')
|
|
79
|
-
|
|
83
|
+
const date = new Date('2024-01-13T12:00:00Z') // Saturday
|
|
84
|
+
const result = formatRelativeTime(date)
|
|
85
|
+
expect(result).toMatch(weekdayPattern)
|
|
86
|
+
expect(result).toBe(date.toLocaleDateString(undefined, { weekday: 'short' }))
|
|
80
87
|
})
|
|
81
88
|
|
|
82
|
-
it('should return
|
|
89
|
+
it('should return a short weekday name for messages 6 days ago (boundary before dates)', () => {
|
|
83
90
|
mockDate('2024-01-15T12:00:00Z')
|
|
84
|
-
const date = new Date('2024-01-09T12:00:00Z')
|
|
85
|
-
|
|
91
|
+
const date = new Date('2024-01-09T12:00:00Z') // Tuesday
|
|
92
|
+
const result = formatRelativeTime(date)
|
|
93
|
+
expect(result).toMatch(weekdayPattern)
|
|
94
|
+
expect(result).toBe(date.toLocaleDateString(undefined, { weekday: 'short' }))
|
|
86
95
|
})
|
|
87
96
|
})
|
|
88
97
|
|
|
89
|
-
describe('
|
|
90
|
-
it('should return
|
|
98
|
+
describe('7+ days ago, same year (month and day)', () => {
|
|
99
|
+
it('should return month + day without year for messages 7 days ago', () => {
|
|
91
100
|
mockDate('2024-01-15T12:00:00Z')
|
|
92
101
|
const date = new Date('2024-01-08T12:00:00Z')
|
|
93
|
-
|
|
102
|
+
const result = formatRelativeTime(date)
|
|
103
|
+
expect(result).toMatch(/\p{L}/u) // spelled-out month
|
|
104
|
+
expect(result).toMatch(/\b8\b/) // day
|
|
105
|
+
expect(result).not.toMatch(/2024|24/) // no year
|
|
94
106
|
})
|
|
95
|
-
})
|
|
96
107
|
|
|
97
|
-
|
|
98
|
-
// The absolute-date branch intentionally uses the runtime locale
|
|
99
|
-
// (toLocaleDateString(undefined, …)), so assertions avoid a fixed
|
|
100
|
-
// string that would depend on the test runner's ambient ICU locale.
|
|
101
|
-
// Instead we assert the locale-independent behaviour: a spelled-out
|
|
102
|
-
// month (alphabetic) rather than the old all-numeric M/D/YY, plus the
|
|
103
|
-
// day and 2-digit year in any order.
|
|
104
|
-
const numericDatePattern = /^\d{1,2}\/\d{1,2}\/\d{2}$/
|
|
105
|
-
|
|
106
|
-
it('should return a spelled-month date for messages more than 4 weeks ago', () => {
|
|
108
|
+
it('should return month + day without year for messages more than 4 weeks ago in the same year', () => {
|
|
107
109
|
mockDate('2024-02-15T12:00:00Z')
|
|
108
110
|
const date = new Date('2024-01-01T12:00:00Z')
|
|
109
111
|
const result = formatRelativeTime(date)
|
|
110
|
-
expect(result).not.toMatch(numericDatePattern)
|
|
111
112
|
expect(result).toMatch(/\p{L}/u) // spelled-out month
|
|
112
113
|
expect(result).toMatch(/\b1\b/) // day
|
|
113
|
-
expect(result).toMatch(/24/) //
|
|
114
|
+
expect(result).not.toMatch(/2024|24/) // no year
|
|
114
115
|
})
|
|
116
|
+
})
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
describe('Previous years (month, day and year)', () => {
|
|
119
|
+
it('should include the full year for messages from a previous year', () => {
|
|
117
120
|
mockDate('2024-01-15T12:00:00Z')
|
|
118
121
|
const date = new Date('2023-12-01T12:00:00Z')
|
|
119
122
|
const result = formatRelativeTime(date)
|
|
120
|
-
expect(result).not.toMatch(numericDatePattern)
|
|
121
123
|
expect(result).toMatch(/\p{L}/u) // spelled-out month
|
|
122
124
|
expect(result).toMatch(/\b1\b/) // day
|
|
123
|
-
expect(result).toMatch(/
|
|
125
|
+
expect(result).toMatch(/2023/) // full year
|
|
124
126
|
})
|
|
125
127
|
})
|
|
126
128
|
|
|
@@ -15,7 +15,9 @@ const getDaysDifference = (date1: Date, date2: Date): number => {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Format a date - shows time for today, relative time for older messages
|
|
18
|
-
* (e.g., "Just now", "2:08 PM" for today, "Yesterday" for yesterday,
|
|
18
|
+
* (e.g., "Just now", "2:08 PM" for today, "Yesterday" for yesterday,
|
|
19
|
+
* "Mon" for 2-6 days ago, "Jul 14" for older dates this year,
|
|
20
|
+
* "Jul 14, 2025" for previous years)
|
|
19
21
|
*/
|
|
20
22
|
export const formatRelativeTime = (date: Date): string => {
|
|
21
23
|
const now = new Date()
|
|
@@ -43,21 +45,23 @@ export const formatRelativeTime = (date: Date): string => {
|
|
|
43
45
|
return 'Yesterday'
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
//
|
|
48
|
+
// 2-6 days ago - show short weekday name (e.g., "Mon")
|
|
47
49
|
if (daysDiff < 7) {
|
|
48
|
-
return
|
|
50
|
+
return date.toLocaleDateString(undefined, { weekday: 'short' })
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
//
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// 7+ days ago, same year - show month and day (e.g., "Jul 14")
|
|
54
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
55
|
+
return date.toLocaleDateString(undefined, {
|
|
56
|
+
month: 'short',
|
|
57
|
+
day: 'numeric',
|
|
58
|
+
})
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
//
|
|
61
|
+
// Previous years - include the year (e.g., "Jul 14, 2025")
|
|
58
62
|
return date.toLocaleDateString(undefined, {
|
|
59
|
-
day: 'numeric',
|
|
60
63
|
month: 'short',
|
|
61
|
-
|
|
64
|
+
day: 'numeric',
|
|
65
|
+
year: 'numeric',
|
|
62
66
|
})
|
|
63
67
|
}
|