@liveblocks/react-ui 3.5.2 → 3.5.3
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/_private/index.d.cts +4 -0
- package/dist/_private/index.d.ts +4 -0
- package/dist/components/Thread.cjs.map +1 -1
- package/dist/components/Thread.js.map +1 -1
- package/dist/components/internal/AiChatAssistantMessage.cjs +29 -9
- package/dist/components/internal/AiChatAssistantMessage.cjs.map +1 -1
- package/dist/components/internal/AiChatAssistantMessage.js +30 -10
- package/dist/components/internal/AiChatAssistantMessage.js.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/overrides.cjs +42 -1
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.js +42 -1
- package/dist/overrides.js.map +1 -1
- package/dist/primitives/AiMessage/index.cjs +7 -1
- package/dist/primitives/AiMessage/index.cjs.map +1 -1
- package/dist/primitives/AiMessage/index.js +7 -1
- package/dist/primitives/AiMessage/index.js.map +1 -1
- package/dist/primitives/AiMessage/tool-invocation.cjs.map +1 -1
- package/dist/primitives/AiMessage/tool-invocation.js.map +1 -1
- package/dist/primitives/Duration.cjs +195 -0
- package/dist/primitives/Duration.cjs.map +1 -0
- package/dist/primitives/Duration.js +192 -0
- package/dist/primitives/Duration.js.map +1 -0
- package/dist/primitives/Timestamp.cjs +4 -3
- package/dist/primitives/Timestamp.cjs.map +1 -1
- package/dist/primitives/Timestamp.js +4 -4
- package/dist/primitives/Timestamp.js.map +1 -1
- package/dist/primitives/index.cjs +2 -0
- package/dist/primitives/index.cjs.map +1 -1
- package/dist/primitives/index.d.cts +59 -4
- package/dist/primitives/index.d.ts +59 -4
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/src/styles/index.css +20 -2
- package/styles.css +1 -1
- package/styles.css.map +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
4
|
+
import { forwardRef, useMemo } from 'react';
|
|
5
|
+
import { numberFormat } from '../utils/intl.js';
|
|
6
|
+
import { useInterval } from '../utils/use-interval.js';
|
|
7
|
+
import { useRerender } from '../utils/use-rerender.js';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const RENDER_INTERVAL = 0.5 * 1e3;
|
|
11
|
+
const DURATION_NAME = "Duration";
|
|
12
|
+
function getDurationParts(duration) {
|
|
13
|
+
let remaining = Math.max(duration, 0);
|
|
14
|
+
const milliseconds = remaining % 1e3;
|
|
15
|
+
remaining = Math.floor(remaining / 1e3);
|
|
16
|
+
const seconds = remaining % 60;
|
|
17
|
+
remaining = Math.floor(remaining / 60);
|
|
18
|
+
const minutes = remaining % 60;
|
|
19
|
+
remaining = Math.floor(remaining / 60);
|
|
20
|
+
const hours = remaining % 24;
|
|
21
|
+
remaining = Math.floor(remaining / 24);
|
|
22
|
+
const days = remaining % 7;
|
|
23
|
+
const weeks = Math.floor(remaining / 7);
|
|
24
|
+
return { weeks, days, hours, minutes, seconds, milliseconds };
|
|
25
|
+
}
|
|
26
|
+
const durationPartsToNumberFormatOptions = {
|
|
27
|
+
weeks: "week",
|
|
28
|
+
days: "day",
|
|
29
|
+
hours: "hour",
|
|
30
|
+
minutes: "minute",
|
|
31
|
+
seconds: "second",
|
|
32
|
+
milliseconds: "millisecond"
|
|
33
|
+
};
|
|
34
|
+
function formatShortDuration(duration, locale) {
|
|
35
|
+
let resolvedLocale;
|
|
36
|
+
if (locale) {
|
|
37
|
+
resolvedLocale = locale;
|
|
38
|
+
} else {
|
|
39
|
+
const formatter = numberFormat();
|
|
40
|
+
resolvedLocale = formatter.resolvedOptions().locale;
|
|
41
|
+
}
|
|
42
|
+
const parts = getDurationParts(duration);
|
|
43
|
+
const formattedParts = [];
|
|
44
|
+
for (const [unit, value] of Object.entries(parts)) {
|
|
45
|
+
if (value === 0 || unit === "milliseconds") {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const formatter = numberFormat(resolvedLocale, {
|
|
49
|
+
style: "unit",
|
|
50
|
+
unit: durationPartsToNumberFormatOptions[unit],
|
|
51
|
+
unitDisplay: "narrow"
|
|
52
|
+
});
|
|
53
|
+
formattedParts.push(formatter.format(value));
|
|
54
|
+
}
|
|
55
|
+
if (!formattedParts.length) {
|
|
56
|
+
formattedParts.push(
|
|
57
|
+
numberFormat(resolvedLocale, {
|
|
58
|
+
style: "unit",
|
|
59
|
+
unit: "second",
|
|
60
|
+
unitDisplay: "narrow"
|
|
61
|
+
}).format(0)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return formattedParts.join(" ");
|
|
65
|
+
}
|
|
66
|
+
function formatVerboseDuration(duration, locale) {
|
|
67
|
+
let resolvedLocale;
|
|
68
|
+
if (locale) {
|
|
69
|
+
resolvedLocale = locale;
|
|
70
|
+
} else {
|
|
71
|
+
const formatter = numberFormat();
|
|
72
|
+
resolvedLocale = formatter.resolvedOptions().locale;
|
|
73
|
+
}
|
|
74
|
+
const parts = getDurationParts(duration);
|
|
75
|
+
const formattedParts = [];
|
|
76
|
+
for (const [unit, value] of Object.entries(parts)) {
|
|
77
|
+
if (value === 0 || unit === "milliseconds") {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const formatter = numberFormat(resolvedLocale, {
|
|
81
|
+
style: "unit",
|
|
82
|
+
unit: durationPartsToNumberFormatOptions[unit],
|
|
83
|
+
unitDisplay: "long"
|
|
84
|
+
});
|
|
85
|
+
formattedParts.push(formatter.format(value));
|
|
86
|
+
}
|
|
87
|
+
if (!formattedParts.length) {
|
|
88
|
+
formattedParts.push(
|
|
89
|
+
numberFormat(resolvedLocale, {
|
|
90
|
+
style: "unit",
|
|
91
|
+
unit: "second",
|
|
92
|
+
unitDisplay: "long"
|
|
93
|
+
}).format(0)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return formattedParts.join(" ");
|
|
97
|
+
}
|
|
98
|
+
function formatIso8601Duration(duration) {
|
|
99
|
+
const normalizedDuration = Math.max(duration, 0);
|
|
100
|
+
if (normalizedDuration === 0) {
|
|
101
|
+
return "PT0S";
|
|
102
|
+
}
|
|
103
|
+
const { weeks, days, hours, minutes, seconds, milliseconds } = getDurationParts(normalizedDuration);
|
|
104
|
+
let isoDuration = "P";
|
|
105
|
+
if (weeks > 0) {
|
|
106
|
+
isoDuration += `${weeks}W`;
|
|
107
|
+
}
|
|
108
|
+
if (days > 0) {
|
|
109
|
+
isoDuration += `${days}D`;
|
|
110
|
+
}
|
|
111
|
+
if (hours > 0 || minutes > 0 || seconds > 0 || milliseconds > 0) {
|
|
112
|
+
isoDuration += "T";
|
|
113
|
+
if (hours > 0) {
|
|
114
|
+
isoDuration += `${hours}H`;
|
|
115
|
+
}
|
|
116
|
+
if (minutes > 0) {
|
|
117
|
+
isoDuration += `${minutes}M`;
|
|
118
|
+
}
|
|
119
|
+
if (seconds > 0 || milliseconds > 0) {
|
|
120
|
+
if (milliseconds > 0) {
|
|
121
|
+
isoDuration += `${seconds}.${milliseconds.toString().padStart(3, "0").replace(/0+$/, "")}S`;
|
|
122
|
+
} else {
|
|
123
|
+
isoDuration += `${seconds}S`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return isoDuration;
|
|
128
|
+
}
|
|
129
|
+
function getDateTime(date) {
|
|
130
|
+
if (date instanceof Date) {
|
|
131
|
+
return date.getTime();
|
|
132
|
+
}
|
|
133
|
+
return new Date(date).getTime();
|
|
134
|
+
}
|
|
135
|
+
function getDuration(from, to) {
|
|
136
|
+
return getDateTime(to) - getDateTime(from);
|
|
137
|
+
}
|
|
138
|
+
const Duration = forwardRef(
|
|
139
|
+
({
|
|
140
|
+
duration,
|
|
141
|
+
from,
|
|
142
|
+
to,
|
|
143
|
+
locale,
|
|
144
|
+
dateTime,
|
|
145
|
+
title: renderTitle = formatVerboseDuration,
|
|
146
|
+
children: renderChildren = formatShortDuration,
|
|
147
|
+
interval = RENDER_INTERVAL,
|
|
148
|
+
asChild,
|
|
149
|
+
...props
|
|
150
|
+
}, forwardedRef) => {
|
|
151
|
+
const Component = asChild ? Slot : "time";
|
|
152
|
+
const [rerender, key] = useRerender();
|
|
153
|
+
const resolvedDuration = useMemo(() => {
|
|
154
|
+
if (duration !== void 0) {
|
|
155
|
+
return duration;
|
|
156
|
+
}
|
|
157
|
+
if (from !== void 0) {
|
|
158
|
+
return getDuration(from, to ?? Date.now());
|
|
159
|
+
}
|
|
160
|
+
return 0;
|
|
161
|
+
}, [duration, from, to, key]);
|
|
162
|
+
const normalizedDuration = useMemo(
|
|
163
|
+
() => formatIso8601Duration(resolvedDuration),
|
|
164
|
+
[resolvedDuration]
|
|
165
|
+
);
|
|
166
|
+
const title = useMemo(
|
|
167
|
+
() => typeof renderTitle === "function" ? renderTitle(resolvedDuration, locale) : renderTitle,
|
|
168
|
+
[renderTitle, resolvedDuration, locale]
|
|
169
|
+
);
|
|
170
|
+
const children = useMemo(
|
|
171
|
+
() => typeof renderChildren === "function" ? renderChildren(resolvedDuration, locale) : renderChildren,
|
|
172
|
+
[renderChildren, resolvedDuration, locale]
|
|
173
|
+
);
|
|
174
|
+
useInterval(
|
|
175
|
+
rerender,
|
|
176
|
+
from !== void 0 && to === void 0 ? interval : false
|
|
177
|
+
);
|
|
178
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
179
|
+
...props,
|
|
180
|
+
ref: forwardedRef,
|
|
181
|
+
dateTime: dateTime ?? normalizedDuration,
|
|
182
|
+
title,
|
|
183
|
+
children
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
if (process.env.NODE_ENV !== "production") {
|
|
188
|
+
Duration.displayName = DURATION_NAME;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { Duration, formatIso8601Duration };
|
|
192
|
+
//# sourceMappingURL=Duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Duration.js","sources":["../../src/primitives/Duration.tsx"],"sourcesContent":["\"use client\";\n\nimport type { Relax } from \"@liveblocks/core\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { forwardRef, type ReactNode, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { numberFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst RENDER_INTERVAL = 0.5 * 1000; // 0.5 second\n\nconst DURATION_NAME = \"Duration\";\n\nexport type DurationProps = Omit<\n ComponentPropsWithSlot<\"time\">,\n \"children\" | \"title\"\n> &\n Relax<\n | {\n /**\n * The duration in milliseconds.\n * If provided, `from` and `to` will be ignored.\n */\n duration: number;\n }\n | {\n /**\n * The date at which the duration starts.\n * If provided, `duration` will be ignored.\n * If provided without `to` it means that the duration is in progress,\n * and the component will re-render at an interval, customizable with\n * the `interval` prop.\n */\n from: Date | string | number;\n\n /**\n * The date at which the duration ends.\n * If `from` is provided without `to`, `Date.now()` will be used.\n */\n to?: Date | string | number;\n }\n > & {\n /**\n * A function to format the displayed duration.\n */\n children?: (duration: number, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((duration: number, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render if\n * `from` is provided without `to`, meaning that the duration is in progress.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the duration.\n */\n locale?: string;\n };\n\ninterface DurationParts {\n weeks: number;\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n milliseconds: number;\n}\n\nfunction getDurationParts(duration: number): DurationParts {\n let remaining = Math.max(duration, 0);\n\n const milliseconds = remaining % 1000;\n remaining = Math.floor(remaining / 1000);\n\n const seconds = remaining % 60;\n remaining = Math.floor(remaining / 60);\n\n const minutes = remaining % 60;\n remaining = Math.floor(remaining / 60);\n\n const hours = remaining % 24;\n remaining = Math.floor(remaining / 24);\n\n const days = remaining % 7;\n const weeks = Math.floor(remaining / 7);\n\n return { weeks, days, hours, minutes, seconds, milliseconds };\n}\n\nconst durationPartsToNumberFormatOptions: Record<\n keyof DurationParts,\n Intl.NumberFormatOptions[\"unit\"]\n> = {\n weeks: \"week\",\n days: \"day\",\n hours: \"hour\",\n minutes: \"minute\",\n seconds: \"second\",\n milliseconds: \"millisecond\",\n};\n\n/**\n * Formats a duration in a short format.\n * TODO: Use `Intl.DurationFormat` when it's better supported.\n */\nfunction formatShortDuration(duration: number, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = numberFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const parts = getDurationParts(duration);\n const formattedParts: string[] = [];\n\n for (const [unit, value] of Object.entries(parts) as [\n keyof DurationParts,\n number,\n ][]) {\n if (value === 0 || unit === \"milliseconds\") {\n continue;\n }\n\n const formatter = numberFormat(resolvedLocale, {\n style: \"unit\",\n unit: durationPartsToNumberFormatOptions[unit],\n unitDisplay: \"narrow\",\n });\n\n formattedParts.push(formatter.format(value));\n }\n\n if (!formattedParts.length) {\n formattedParts.push(\n numberFormat(resolvedLocale, {\n style: \"unit\",\n unit: \"second\",\n unitDisplay: \"narrow\",\n }).format(0)\n );\n }\n\n return formattedParts.join(\" \");\n}\n\n/**\n * Formats a duration in a longer format.\n * TODO: Use `Intl.DurationFormat` when it's better supported.\n */\nfunction formatVerboseDuration(duration: number, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = numberFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const parts = getDurationParts(duration);\n const formattedParts: string[] = [];\n\n for (const [unit, value] of Object.entries(parts) as [\n keyof DurationParts,\n number,\n ][]) {\n if (value === 0 || unit === \"milliseconds\") {\n continue;\n }\n\n const formatter = numberFormat(resolvedLocale, {\n style: \"unit\",\n unit: durationPartsToNumberFormatOptions[unit],\n unitDisplay: \"long\",\n });\n\n formattedParts.push(formatter.format(value));\n }\n\n if (!formattedParts.length) {\n formattedParts.push(\n numberFormat(resolvedLocale, {\n style: \"unit\",\n unit: \"second\",\n unitDisplay: \"long\",\n }).format(0)\n );\n }\n\n return formattedParts.join(\" \");\n}\n\n/**\n * Formats a duration as ISO 8601.\n * TODO: Use `Temporal.Duration` when it's better supported.\n */\nexport function formatIso8601Duration(duration: number) {\n const normalizedDuration = Math.max(duration, 0);\n\n if (normalizedDuration === 0) {\n return \"PT0S\";\n }\n\n const { weeks, days, hours, minutes, seconds, milliseconds } =\n getDurationParts(normalizedDuration);\n\n let isoDuration = \"P\";\n\n // 1. Weeks\n if (weeks > 0) {\n isoDuration += `${weeks}W`;\n }\n\n // 2. Days\n if (days > 0) {\n isoDuration += `${days}D`;\n }\n\n if (hours > 0 || minutes > 0 || seconds > 0 || milliseconds > 0) {\n isoDuration += \"T\";\n\n // 3. Hours\n if (hours > 0) {\n isoDuration += `${hours}H`;\n }\n\n // 4. Minutes\n if (minutes > 0) {\n isoDuration += `${minutes}M`;\n }\n\n // 5. Seconds and milliseconds\n if (seconds > 0 || milliseconds > 0) {\n if (milliseconds > 0) {\n isoDuration += `${seconds}.${milliseconds.toString().padStart(3, \"0\").replace(/0+$/, \"\")}S`;\n } else {\n isoDuration += `${seconds}S`;\n }\n }\n }\n\n return isoDuration;\n}\n\n/**\n * Converts a Date or Date-like value to a timestamp in milliseconds.\n */\nfunction getDateTime(date: Date | string | number) {\n if (date instanceof Date) {\n return date.getTime();\n }\n\n return new Date(date).getTime();\n}\n\n/**\n * Get a duration between two Date or Date-like values.\n */\nfunction getDuration(from: Date | string | number, to: Date | string | number) {\n return getDateTime(to) - getDateTime(from);\n}\n\n/**\n * Displays a formatted duration, and automatically re-renders to if the\n * duration is in progress.\n *\n * @example\n * <Duration duration={3 * 60 * 1000} />\n *\n * @example\n * <Duration from={fiveHoursAgoDate} />\n *\n * @example\n * <Duration from={fiveHoursAgoDate} to={oneHourAgoDate} />\n */\nexport const Duration = forwardRef<HTMLTimeElement, DurationProps>(\n (\n {\n duration,\n from,\n to,\n locale,\n dateTime,\n title: renderTitle = formatVerboseDuration,\n children: renderChildren = formatShortDuration,\n interval = RENDER_INTERVAL,\n asChild,\n ...props\n },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"time\";\n const [rerender, key] = useRerender();\n const resolvedDuration = useMemo(() => {\n if (duration !== undefined) {\n return duration;\n }\n\n if (from !== undefined) {\n return getDuration(from, to ?? Date.now());\n }\n\n return 0;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [duration, from, to, key]);\n const normalizedDuration = useMemo(\n () => formatIso8601Duration(resolvedDuration),\n [resolvedDuration]\n );\n const title = useMemo(\n () =>\n typeof renderTitle === \"function\"\n ? renderTitle(resolvedDuration, locale)\n : renderTitle,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderTitle, resolvedDuration, locale]\n );\n const children = useMemo(\n () =>\n typeof renderChildren === \"function\"\n ? renderChildren(resolvedDuration, locale)\n : renderChildren,\n\n [renderChildren, resolvedDuration, locale]\n );\n\n // Only re-render if the duration is in progress.\n useInterval(\n rerender,\n from !== undefined && to === undefined ? interval : false\n );\n\n return (\n <Component\n {...props}\n ref={forwardedRef}\n dateTime={dateTime ?? normalizedDuration}\n title={title}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Duration.displayName = DURATION_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;;AAWA;AAEA;AA+DA;AACE;AAEA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACF;AAEA;AAGI;AACK;AACD;AACC;AACE;AACA;AAEX;AAMA;AACE;AAEA;AACE;AAAiB;AAEjB;AAEA;AAA6C;AAG/C;AACA;AAEA;AAIE;AACE;AAAA;AAGF;AAA+C;AACtC;AACkC;AAC5B;AAGf;AAA2C;AAG7C;AACE;AAAe;AACgB;AACpB;AACD;AACO;AACJ;AACb;AAGF;AACF;AAMA;AACE;AAEA;AACE;AAAiB;AAEjB;AAEA;AAA6C;AAG/C;AACA;AAEA;AAIE;AACE;AAAA;AAGF;AAA+C;AACtC;AACkC;AAC5B;AAGf;AAA2C;AAG7C;AACE;AAAe;AACgB;AACpB;AACD;AACO;AACJ;AACb;AAGF;AACF;AAMO;AACL;AAEA;AACE;AAAO;AAGT;AAGA;AAGA;AACE;AAAkB;AAIpB;AACE;AAAkB;AAGpB;AACE;AAGA;AACE;AAAkB;AAIpB;AACE;AAAkB;AAIpB;AACE;AACE;AAAuF;AAEvF;AAAkB;AACpB;AACF;AAGF;AACF;AAKA;AACE;AACE;AAAoB;AAGtB;AACF;AAKA;AACE;AACF;AAeO;AAAiB;AAEpB;AACE;AACA;AACA;AACA;AACA;AACqB;AACM;AAChB;AACX;AACG;AAIL;AACA;AACA;AACE;AACE;AAAO;AAGT;AACE;AAAyC;AAG3C;AAAO;AAGT;AAA2B;AACmB;AAC3B;AAEnB;AAAc;AAIN;AAEgC;AAExC;AAAiB;AAIT;AAEmC;AAI3C;AAAA;AACE;AACoD;AAGtD;AACG;AACK;AACC;AACiB;AACtB;AAEC;AACH;AAGN;AAEA;AACE;AACF;;"}
|
|
@@ -78,7 +78,7 @@ function formatRelativeDate(date, locale) {
|
|
|
78
78
|
return capitalize.capitalize(formatter.format(Math.round(difference), "years"));
|
|
79
79
|
}
|
|
80
80
|
function formatDynamicDate(date, locale) {
|
|
81
|
-
return date.getTime()
|
|
81
|
+
return Math.abs(date.getTime() - Date.now()) <= DYNAMIC_DATE_THRESHOLD ? formatRelativeDate(date, locale) : formatShortDate(date, locale);
|
|
82
82
|
}
|
|
83
83
|
const Timestamp = react.forwardRef(
|
|
84
84
|
({
|
|
@@ -100,11 +100,11 @@ const Timestamp = react.forwardRef(
|
|
|
100
100
|
);
|
|
101
101
|
const title = react.useMemo(
|
|
102
102
|
() => typeof renderTitle === "function" ? renderTitle(parsedDate, locale) : renderTitle,
|
|
103
|
-
[renderTitle, parsedDate, key]
|
|
103
|
+
[renderTitle, parsedDate, locale, key]
|
|
104
104
|
);
|
|
105
105
|
const children = react.useMemo(
|
|
106
106
|
() => typeof renderChildren === "function" ? renderChildren(parsedDate, locale) : renderChildren,
|
|
107
|
-
[renderChildren, parsedDate, key]
|
|
107
|
+
[renderChildren, parsedDate, locale, key]
|
|
108
108
|
);
|
|
109
109
|
useInterval.useInterval(rerender, interval);
|
|
110
110
|
return /* @__PURE__ */ jsxRuntime.jsx(Component, {
|
|
@@ -121,4 +121,5 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
exports.Timestamp = Timestamp;
|
|
124
|
+
exports.formatRelativeDate = formatRelativeDate;
|
|
124
125
|
//# sourceMappingURL=Timestamp.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timestamp.cjs","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\
|
|
1
|
+
{"version":3,"file":"Timestamp.cjs","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\nexport function formatRelativeDate(date: Date, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = relativeTimeFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const isBrokenWhenNarrow = localesWithBrokenNarrowRelativeFormatting.some(\n (locale) =>\n resolvedLocale === locale || resolvedLocale.startsWith(`${locale}-`)\n );\n\n const formatter = relativeTimeFormat(resolvedLocale, {\n style: isBrokenWhenNarrow ? \"short\" : \"narrow\",\n numeric: \"auto\",\n });\n\n let difference = (date.getTime() - Date.now()) / 1000;\n\n if (\n difference > -relativeUnits.seconds &&\n difference < relativeUnits.seconds\n ) {\n return formatter.format(0, \"seconds\");\n }\n\n for (const [unit, length] of Object.entries(relativeUnits)) {\n if (Math.abs(difference) < length) {\n return formatter.format(\n Math.round(difference),\n unit as Intl.RelativeTimeFormatUnit\n );\n }\n\n difference /= length;\n }\n\n return capitalize(formatter.format(Math.round(difference), \"years\"));\n}\n\n/**\n * Formats a date relatively if it's recent or soon,\n * otherwise absolutely with only the day and month.\n */\nfunction formatDynamicDate(date: Date, locale?: string) {\n return Math.abs(date.getTime() - Date.now()) <= DYNAMIC_DATE_THRESHOLD\n ? formatRelativeDate(date, locale)\n : formatShortDate(date, locale);\n}\n\n/**\n * Displays a formatted date, and automatically re-renders to support relative\n * formatting. Defaults to relative formatting for nearby dates and a short\n * absolute formatting for more distant ones.\n *\n * @example\n * <Timestamp date={new Date()} />\n *\n * @example\n * <Timestamp date={new Date()} title={(date) => date.toISOString()} interval={false}>\n * {(date) => date.toLocaleDateString()}\n * </Timestamp>\n */\nexport const Timestamp = forwardRef<HTMLTimeElement, TimestampProps>(\n (\n {\n date,\n locale,\n children: renderChildren = formatDynamicDate,\n title: renderTitle = formatVerboseDate,\n dateTime,\n interval = RENDER_INTERVAL,\n asChild,\n ...props\n },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"time\";\n const [rerender, key] = useRerender();\n const parsedDate = useMemo(() => new Date(date), [date]);\n const normalizedDate = useMemo(\n () => parsedDate.toISOString(),\n [parsedDate]\n );\n const title = useMemo(\n () =>\n typeof renderTitle === \"function\"\n ? renderTitle(parsedDate, locale)\n : renderTitle,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderTitle, parsedDate, locale, key]\n );\n const children = useMemo(\n () =>\n typeof renderChildren === \"function\"\n ? renderChildren(parsedDate, locale)\n : renderChildren,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderChildren, parsedDate, locale, key]\n );\n\n useInterval(rerender, interval);\n\n return (\n <Component\n {...props}\n ref={forwardedRef}\n dateTime={dateTime ?? normalizedDate}\n title={title}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Timestamp.displayName = TIMESTAMP_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAYA;AACA;AAEA;AA+BA;AAAsB;AACX;AACA;AACF;AACD;AACC;AAET;AAKA;AACE;AAAyC;AACjC;AACC;AACF;AACC;AACE;AAGV;AACF;AAKA;AACE;AAAyC;AAChC;AACF;AAGP;AACF;AAGA;AAAkD;AAChD;AACA;AACA;AACA;AACA;AACA;AAEF;AAKgB;AACd;AAEA;AACE;AAAiB;AAEjB;AAEA;AAA6C;AAG/C;AAAqE;AAEE;AAGvE;AAAqD;AACb;AAC7B;AAGX;AAEA;AAIE;AAAoC;AAGtC;AACE;AACE;AAAiB;AACM;AACrB;AACF;AAGF;AAAc;AAGhB;AACF;AAMA;AACE;AAGF;AAeO;AAAkB;AAErB;AACE;AACA;AAC2B;AACN;AACrB;AACW;AACX;AACG;AAIL;AACA;AACA;AACA;AAAuB;AACQ;AAClB;AAEb;AAAc;AAIN;AAE+B;AAEvC;AAAiB;AAIT;AAEkC;AAG1C;AAEA;AACG;AACK;AACC;AACiB;AACtB;AAEC;AACH;AAGN;AAEA;AACE;AACF;;;"}
|
|
@@ -76,7 +76,7 @@ function formatRelativeDate(date, locale) {
|
|
|
76
76
|
return capitalize(formatter.format(Math.round(difference), "years"));
|
|
77
77
|
}
|
|
78
78
|
function formatDynamicDate(date, locale) {
|
|
79
|
-
return date.getTime()
|
|
79
|
+
return Math.abs(date.getTime() - Date.now()) <= DYNAMIC_DATE_THRESHOLD ? formatRelativeDate(date, locale) : formatShortDate(date, locale);
|
|
80
80
|
}
|
|
81
81
|
const Timestamp = forwardRef(
|
|
82
82
|
({
|
|
@@ -98,11 +98,11 @@ const Timestamp = forwardRef(
|
|
|
98
98
|
);
|
|
99
99
|
const title = useMemo(
|
|
100
100
|
() => typeof renderTitle === "function" ? renderTitle(parsedDate, locale) : renderTitle,
|
|
101
|
-
[renderTitle, parsedDate, key]
|
|
101
|
+
[renderTitle, parsedDate, locale, key]
|
|
102
102
|
);
|
|
103
103
|
const children = useMemo(
|
|
104
104
|
() => typeof renderChildren === "function" ? renderChildren(parsedDate, locale) : renderChildren,
|
|
105
|
-
[renderChildren, parsedDate, key]
|
|
105
|
+
[renderChildren, parsedDate, locale, key]
|
|
106
106
|
);
|
|
107
107
|
useInterval(rerender, interval);
|
|
108
108
|
return /* @__PURE__ */ jsx(Component, {
|
|
@@ -118,5 +118,5 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
118
118
|
Timestamp.displayName = TIMESTAMP_NAME;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export { Timestamp };
|
|
121
|
+
export { Timestamp, formatRelativeDate };
|
|
122
122
|
//# sourceMappingURL=Timestamp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timestamp.js","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\
|
|
1
|
+
{"version":3,"file":"Timestamp.js","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\nexport function formatRelativeDate(date: Date, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = relativeTimeFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const isBrokenWhenNarrow = localesWithBrokenNarrowRelativeFormatting.some(\n (locale) =>\n resolvedLocale === locale || resolvedLocale.startsWith(`${locale}-`)\n );\n\n const formatter = relativeTimeFormat(resolvedLocale, {\n style: isBrokenWhenNarrow ? \"short\" : \"narrow\",\n numeric: \"auto\",\n });\n\n let difference = (date.getTime() - Date.now()) / 1000;\n\n if (\n difference > -relativeUnits.seconds &&\n difference < relativeUnits.seconds\n ) {\n return formatter.format(0, \"seconds\");\n }\n\n for (const [unit, length] of Object.entries(relativeUnits)) {\n if (Math.abs(difference) < length) {\n return formatter.format(\n Math.round(difference),\n unit as Intl.RelativeTimeFormatUnit\n );\n }\n\n difference /= length;\n }\n\n return capitalize(formatter.format(Math.round(difference), \"years\"));\n}\n\n/**\n * Formats a date relatively if it's recent or soon,\n * otherwise absolutely with only the day and month.\n */\nfunction formatDynamicDate(date: Date, locale?: string) {\n return Math.abs(date.getTime() - Date.now()) <= DYNAMIC_DATE_THRESHOLD\n ? formatRelativeDate(date, locale)\n : formatShortDate(date, locale);\n}\n\n/**\n * Displays a formatted date, and automatically re-renders to support relative\n * formatting. Defaults to relative formatting for nearby dates and a short\n * absolute formatting for more distant ones.\n *\n * @example\n * <Timestamp date={new Date()} />\n *\n * @example\n * <Timestamp date={new Date()} title={(date) => date.toISOString()} interval={false}>\n * {(date) => date.toLocaleDateString()}\n * </Timestamp>\n */\nexport const Timestamp = forwardRef<HTMLTimeElement, TimestampProps>(\n (\n {\n date,\n locale,\n children: renderChildren = formatDynamicDate,\n title: renderTitle = formatVerboseDate,\n dateTime,\n interval = RENDER_INTERVAL,\n asChild,\n ...props\n },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"time\";\n const [rerender, key] = useRerender();\n const parsedDate = useMemo(() => new Date(date), [date]);\n const normalizedDate = useMemo(\n () => parsedDate.toISOString(),\n [parsedDate]\n );\n const title = useMemo(\n () =>\n typeof renderTitle === \"function\"\n ? renderTitle(parsedDate, locale)\n : renderTitle,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderTitle, parsedDate, locale, key]\n );\n const children = useMemo(\n () =>\n typeof renderChildren === \"function\"\n ? renderChildren(parsedDate, locale)\n : renderChildren,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderChildren, parsedDate, locale, key]\n );\n\n useInterval(rerender, interval);\n\n return (\n <Component\n {...props}\n ref={forwardedRef}\n dateTime={dateTime ?? normalizedDate}\n title={title}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Timestamp.displayName = TIMESTAMP_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAYA;AACA;AAEA;AA+BA;AAAsB;AACX;AACA;AACF;AACD;AACC;AAET;AAKA;AACE;AAAyC;AACjC;AACC;AACF;AACC;AACE;AAGV;AACF;AAKA;AACE;AAAyC;AAChC;AACF;AAGP;AACF;AAGA;AAAkD;AAChD;AACA;AACA;AACA;AACA;AACA;AAEF;AAKgB;AACd;AAEA;AACE;AAAiB;AAEjB;AAEA;AAA6C;AAG/C;AAAqE;AAEE;AAGvE;AAAqD;AACb;AAC7B;AAGX;AAEA;AAIE;AAAoC;AAGtC;AACE;AACE;AAAiB;AACM;AACrB;AACF;AAGF;AAAc;AAGhB;AACF;AAMA;AACE;AAGF;AAeO;AAAkB;AAErB;AACE;AACA;AAC2B;AACN;AACrB;AACW;AACX;AACG;AAIL;AACA;AACA;AACA;AAAuB;AACQ;AAClB;AAEb;AAAc;AAIN;AAE+B;AAEvC;AAAiB;AAIT;AAEkC;AAG1C;AAEA;AACG;AACK;AACC;AACiB;AACtB;AAEC;AACH;AAGN;AAEA;AACE;AACF;;"}
|
|
@@ -4,6 +4,7 @@ var index = require('./Comment/index.cjs');
|
|
|
4
4
|
var index$1 = require('./Composer/index.cjs');
|
|
5
5
|
var contexts = require('./Composer/contexts.cjs');
|
|
6
6
|
var utils = require('./Composer/utils.cjs');
|
|
7
|
+
var Duration = require('./Duration.cjs');
|
|
7
8
|
var FileSize = require('./FileSize.cjs');
|
|
8
9
|
var Timestamp = require('./Timestamp.cjs');
|
|
9
10
|
|
|
@@ -13,6 +14,7 @@ exports.Comment = index;
|
|
|
13
14
|
exports.Composer = index$1;
|
|
14
15
|
exports.useComposer = contexts.useComposer;
|
|
15
16
|
exports.AttachmentTooLargeError = utils.AttachmentTooLargeError;
|
|
17
|
+
exports.Duration = Duration.Duration;
|
|
16
18
|
exports.FileSize = FileSize.FileSize;
|
|
17
19
|
exports.Timestamp = Timestamp.Timestamp;
|
|
18
20
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ElementType, ComponentPropsWithoutRef, ReactNode, ComponentType, FormEvent } from 'react';
|
|
3
|
-
import { MentionData, CommentBody as CommentBody$1, CommentAttachment, CommentMixedAttachment } from '@liveblocks/core';
|
|
3
|
+
import { MentionData, CommentBody as CommentBody$1, CommentAttachment, CommentMixedAttachment, Relax } from '@liveblocks/core';
|
|
4
4
|
|
|
5
5
|
type Direction = "ltr" | "rtl";
|
|
6
6
|
type SlotProp = {
|
|
@@ -445,6 +445,61 @@ declare class AttachmentTooLargeError extends Error {
|
|
|
445
445
|
constructor(message: string, origin?: "client" | "server");
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
type DurationProps = Omit<ComponentPropsWithSlot<"time">, "children" | "title"> & Relax<{
|
|
449
|
+
/**
|
|
450
|
+
* The duration in milliseconds.
|
|
451
|
+
* If provided, `from` and `to` will be ignored.
|
|
452
|
+
*/
|
|
453
|
+
duration: number;
|
|
454
|
+
} | {
|
|
455
|
+
/**
|
|
456
|
+
* The date at which the duration starts.
|
|
457
|
+
* If provided, `duration` will be ignored.
|
|
458
|
+
* If provided without `to` it means that the duration is in progress,
|
|
459
|
+
* and the component will re-render at an interval, customizable with
|
|
460
|
+
* the `interval` prop.
|
|
461
|
+
*/
|
|
462
|
+
from: Date | string | number;
|
|
463
|
+
/**
|
|
464
|
+
* The date at which the duration ends.
|
|
465
|
+
* If `from` is provided without `to`, `Date.now()` will be used.
|
|
466
|
+
*/
|
|
467
|
+
to?: Date | string | number;
|
|
468
|
+
}> & {
|
|
469
|
+
/**
|
|
470
|
+
* A function to format the displayed duration.
|
|
471
|
+
*/
|
|
472
|
+
children?: (duration: number, locale?: string) => ReactNode;
|
|
473
|
+
/**
|
|
474
|
+
* The `title` attribute's value or a function to format it.
|
|
475
|
+
*/
|
|
476
|
+
title?: string | ((duration: number, locale?: string) => string);
|
|
477
|
+
/**
|
|
478
|
+
* The interval in milliseconds at which the component will re-render if
|
|
479
|
+
* `from` is provided without `to`, meaning that the duration is in progress.
|
|
480
|
+
* Can be set to `false` to disable re-rendering.
|
|
481
|
+
*/
|
|
482
|
+
interval?: number | false;
|
|
483
|
+
/**
|
|
484
|
+
* The locale used when formatting the duration.
|
|
485
|
+
*/
|
|
486
|
+
locale?: string;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Displays a formatted duration, and automatically re-renders to if the
|
|
490
|
+
* duration is in progress.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* <Duration duration={3 * 60 * 1000} />
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* <Duration from={fiveHoursAgoDate} />
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* <Duration from={fiveHoursAgoDate} to={oneHourAgoDate} />
|
|
500
|
+
*/
|
|
501
|
+
declare const Duration: react.ForwardRefExoticComponent<DurationProps & react.RefAttributes<HTMLTimeElement>>;
|
|
502
|
+
|
|
448
503
|
interface FileSizeProps extends Omit<ComponentPropsWithSlot<"span">, "children"> {
|
|
449
504
|
/**
|
|
450
505
|
* The file size to display.
|
|
@@ -492,8 +547,8 @@ interface TimestampProps extends Omit<ComponentPropsWithSlot<"time">, "children"
|
|
|
492
547
|
}
|
|
493
548
|
/**
|
|
494
549
|
* Displays a formatted date, and automatically re-renders to support relative
|
|
495
|
-
* formatting. Defaults to relative formatting for
|
|
496
|
-
* absolute formatting for
|
|
550
|
+
* formatting. Defaults to relative formatting for nearby dates and a short
|
|
551
|
+
* absolute formatting for more distant ones.
|
|
497
552
|
*
|
|
498
553
|
* @example
|
|
499
554
|
* <Timestamp date={new Date()} />
|
|
@@ -505,4 +560,4 @@ interface TimestampProps extends Omit<ComponentPropsWithSlot<"time">, "children"
|
|
|
505
560
|
*/
|
|
506
561
|
declare const Timestamp: react.ForwardRefExoticComponent<TimestampProps & react.RefAttributes<HTMLTimeElement>>;
|
|
507
562
|
|
|
508
|
-
export { AiComposerSubmitMessage, AttachmentTooLargeError, index$1 as Comment, CommentBodyComponents, CommentBodyLinkProps, CommentBodyMentionProps, CommentBodyProps, CommentLinkProps, CommentMentionProps, index as Composer, ComposerAttachFilesProps, ComposerAttachmentsDropAreaProps, ComposerBodyMark, ComposerBodyMarks, ComposerContext, ComposerEditorComponents, ComposerEditorFloatingToolbarProps, ComposerEditorLinkProps, ComposerEditorMentionProps, ComposerEditorMentionSuggestionsProps, ComposerEditorProps, ComposerFloatingToolbarProps, ComposerFormProps, ComposerLinkProps, ComposerMarkToggleProps, ComposerMentionProps, ComposerSubmitComment, ComposerSubmitProps, ComposerSuggestionsListItemProps, ComposerSuggestionsListProps, FileSize, FileSizeProps, Timestamp, TimestampProps, useComposer };
|
|
563
|
+
export { AiComposerSubmitMessage, AttachmentTooLargeError, index$1 as Comment, CommentBodyComponents, CommentBodyLinkProps, CommentBodyMentionProps, CommentBodyProps, CommentLinkProps, CommentMentionProps, index as Composer, ComposerAttachFilesProps, ComposerAttachmentsDropAreaProps, ComposerBodyMark, ComposerBodyMarks, ComposerContext, ComposerEditorComponents, ComposerEditorFloatingToolbarProps, ComposerEditorLinkProps, ComposerEditorMentionProps, ComposerEditorMentionSuggestionsProps, ComposerEditorProps, ComposerFloatingToolbarProps, ComposerFormProps, ComposerLinkProps, ComposerMarkToggleProps, ComposerMentionProps, ComposerSubmitComment, ComposerSubmitProps, ComposerSuggestionsListItemProps, ComposerSuggestionsListProps, Duration, DurationProps, FileSize, FileSizeProps, Timestamp, TimestampProps, useComposer };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ElementType, ComponentPropsWithoutRef, ReactNode, ComponentType, FormEvent } from 'react';
|
|
3
|
-
import { MentionData, CommentBody as CommentBody$1, CommentAttachment, CommentMixedAttachment } from '@liveblocks/core';
|
|
3
|
+
import { MentionData, CommentBody as CommentBody$1, CommentAttachment, CommentMixedAttachment, Relax } from '@liveblocks/core';
|
|
4
4
|
|
|
5
5
|
type Direction = "ltr" | "rtl";
|
|
6
6
|
type SlotProp = {
|
|
@@ -445,6 +445,61 @@ declare class AttachmentTooLargeError extends Error {
|
|
|
445
445
|
constructor(message: string, origin?: "client" | "server");
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
type DurationProps = Omit<ComponentPropsWithSlot<"time">, "children" | "title"> & Relax<{
|
|
449
|
+
/**
|
|
450
|
+
* The duration in milliseconds.
|
|
451
|
+
* If provided, `from` and `to` will be ignored.
|
|
452
|
+
*/
|
|
453
|
+
duration: number;
|
|
454
|
+
} | {
|
|
455
|
+
/**
|
|
456
|
+
* The date at which the duration starts.
|
|
457
|
+
* If provided, `duration` will be ignored.
|
|
458
|
+
* If provided without `to` it means that the duration is in progress,
|
|
459
|
+
* and the component will re-render at an interval, customizable with
|
|
460
|
+
* the `interval` prop.
|
|
461
|
+
*/
|
|
462
|
+
from: Date | string | number;
|
|
463
|
+
/**
|
|
464
|
+
* The date at which the duration ends.
|
|
465
|
+
* If `from` is provided without `to`, `Date.now()` will be used.
|
|
466
|
+
*/
|
|
467
|
+
to?: Date | string | number;
|
|
468
|
+
}> & {
|
|
469
|
+
/**
|
|
470
|
+
* A function to format the displayed duration.
|
|
471
|
+
*/
|
|
472
|
+
children?: (duration: number, locale?: string) => ReactNode;
|
|
473
|
+
/**
|
|
474
|
+
* The `title` attribute's value or a function to format it.
|
|
475
|
+
*/
|
|
476
|
+
title?: string | ((duration: number, locale?: string) => string);
|
|
477
|
+
/**
|
|
478
|
+
* The interval in milliseconds at which the component will re-render if
|
|
479
|
+
* `from` is provided without `to`, meaning that the duration is in progress.
|
|
480
|
+
* Can be set to `false` to disable re-rendering.
|
|
481
|
+
*/
|
|
482
|
+
interval?: number | false;
|
|
483
|
+
/**
|
|
484
|
+
* The locale used when formatting the duration.
|
|
485
|
+
*/
|
|
486
|
+
locale?: string;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Displays a formatted duration, and automatically re-renders to if the
|
|
490
|
+
* duration is in progress.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* <Duration duration={3 * 60 * 1000} />
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* <Duration from={fiveHoursAgoDate} />
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* <Duration from={fiveHoursAgoDate} to={oneHourAgoDate} />
|
|
500
|
+
*/
|
|
501
|
+
declare const Duration: react.ForwardRefExoticComponent<DurationProps & react.RefAttributes<HTMLTimeElement>>;
|
|
502
|
+
|
|
448
503
|
interface FileSizeProps extends Omit<ComponentPropsWithSlot<"span">, "children"> {
|
|
449
504
|
/**
|
|
450
505
|
* The file size to display.
|
|
@@ -492,8 +547,8 @@ interface TimestampProps extends Omit<ComponentPropsWithSlot<"time">, "children"
|
|
|
492
547
|
}
|
|
493
548
|
/**
|
|
494
549
|
* Displays a formatted date, and automatically re-renders to support relative
|
|
495
|
-
* formatting. Defaults to relative formatting for
|
|
496
|
-
* absolute formatting for
|
|
550
|
+
* formatting. Defaults to relative formatting for nearby dates and a short
|
|
551
|
+
* absolute formatting for more distant ones.
|
|
497
552
|
*
|
|
498
553
|
* @example
|
|
499
554
|
* <Timestamp date={new Date()} />
|
|
@@ -505,4 +560,4 @@ interface TimestampProps extends Omit<ComponentPropsWithSlot<"time">, "children"
|
|
|
505
560
|
*/
|
|
506
561
|
declare const Timestamp: react.ForwardRefExoticComponent<TimestampProps & react.RefAttributes<HTMLTimeElement>>;
|
|
507
562
|
|
|
508
|
-
export { AiComposerSubmitMessage, AttachmentTooLargeError, index$1 as Comment, CommentBodyComponents, CommentBodyLinkProps, CommentBodyMentionProps, CommentBodyProps, CommentLinkProps, CommentMentionProps, index as Composer, ComposerAttachFilesProps, ComposerAttachmentsDropAreaProps, ComposerBodyMark, ComposerBodyMarks, ComposerContext, ComposerEditorComponents, ComposerEditorFloatingToolbarProps, ComposerEditorLinkProps, ComposerEditorMentionProps, ComposerEditorMentionSuggestionsProps, ComposerEditorProps, ComposerFloatingToolbarProps, ComposerFormProps, ComposerLinkProps, ComposerMarkToggleProps, ComposerMentionProps, ComposerSubmitComment, ComposerSubmitProps, ComposerSuggestionsListItemProps, ComposerSuggestionsListProps, FileSize, FileSizeProps, Timestamp, TimestampProps, useComposer };
|
|
563
|
+
export { AiComposerSubmitMessage, AttachmentTooLargeError, index$1 as Comment, CommentBodyComponents, CommentBodyLinkProps, CommentBodyMentionProps, CommentBodyProps, CommentLinkProps, CommentMentionProps, index as Composer, ComposerAttachFilesProps, ComposerAttachmentsDropAreaProps, ComposerBodyMark, ComposerBodyMarks, ComposerContext, ComposerEditorComponents, ComposerEditorFloatingToolbarProps, ComposerEditorLinkProps, ComposerEditorMentionProps, ComposerEditorMentionSuggestionsProps, ComposerEditorProps, ComposerFloatingToolbarProps, ComposerFormProps, ComposerLinkProps, ComposerMarkToggleProps, ComposerMentionProps, ComposerSubmitComment, ComposerSubmitProps, ComposerSuggestionsListItemProps, ComposerSuggestionsListProps, Duration, DurationProps, FileSize, FileSizeProps, Timestamp, TimestampProps, useComposer };
|
package/dist/primitives/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as index$1 from './Composer/index.js';
|
|
|
4
4
|
export { index$1 as Composer };
|
|
5
5
|
export { useComposer } from './Composer/contexts.js';
|
|
6
6
|
export { AttachmentTooLargeError } from './Composer/utils.js';
|
|
7
|
+
export { Duration } from './Duration.js';
|
|
7
8
|
export { FileSize } from './FileSize.js';
|
|
8
9
|
export { Timestamp } from './Timestamp.js';
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/version.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const PKG_NAME = "@liveblocks/react-ui";
|
|
4
|
-
const PKG_VERSION = typeof "3.5.
|
|
4
|
+
const PKG_VERSION = typeof "3.5.3" === "string" && "3.5.3";
|
|
5
5
|
const PKG_FORMAT = typeof "cjs" === "string" && "cjs";
|
|
6
6
|
|
|
7
7
|
exports.PKG_FORMAT = PKG_FORMAT;
|
package/dist/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const PKG_NAME = "@liveblocks/react-ui";
|
|
2
|
-
const PKG_VERSION = typeof "3.5.
|
|
2
|
+
const PKG_VERSION = typeof "3.5.3" === "string" && "3.5.3";
|
|
3
3
|
const PKG_FORMAT = typeof "esm" === "string" && "esm";
|
|
4
4
|
|
|
5
5
|
export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react-ui",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@floating-ui/react-dom": "^2.1.2",
|
|
79
|
-
"@liveblocks/client": "3.5.
|
|
80
|
-
"@liveblocks/core": "3.5.
|
|
81
|
-
"@liveblocks/react": "3.5.
|
|
79
|
+
"@liveblocks/client": "3.5.3",
|
|
80
|
+
"@liveblocks/core": "3.5.3",
|
|
81
|
+
"@liveblocks/react": "3.5.3",
|
|
82
82
|
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
|
83
83
|
"@radix-ui/react-popover": "^1.1.2",
|
|
84
84
|
"@radix-ui/react-slot": "^1.1.0",
|
package/src/styles/index.css
CHANGED
|
@@ -2811,7 +2811,14 @@
|
|
|
2811
2811
|
animation: lb-animation-shimmer-text 2s cubic-bezier(0.1, 0, 0.9, 1) infinite;
|
|
2812
2812
|
}
|
|
2813
2813
|
|
|
2814
|
-
.lb-ai-chat-message-thinking
|
|
2814
|
+
.lb-ai-chat-message-thinking,
|
|
2815
|
+
.lb-ai-chat-message-retrieval,
|
|
2816
|
+
.lb-ai-chat-message-reasoning {
|
|
2817
|
+
margin-block-end: calc(0.75 * var(--lb-spacing));
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
.lb-ai-chat-message-thinking,
|
|
2821
|
+
.lb-ai-chat-message-retrieval {
|
|
2815
2822
|
inline-size: fit-content;
|
|
2816
2823
|
max-inline-size: 100%;
|
|
2817
2824
|
color: var(--lb-foreground-tertiary);
|
|
@@ -2824,7 +2831,6 @@
|
|
|
2824
2831
|
|
|
2825
2832
|
.lb-ai-chat-message-reasoning {
|
|
2826
2833
|
position: relative;
|
|
2827
|
-
margin-block-end: calc(0.75 * var(--lb-spacing));
|
|
2828
2834
|
|
|
2829
2835
|
&::after {
|
|
2830
2836
|
content: "";
|
|
@@ -2875,6 +2881,18 @@
|
|
|
2875
2881
|
}
|
|
2876
2882
|
}
|
|
2877
2883
|
|
|
2884
|
+
.lb-ai-chat-message-retrieval-query {
|
|
2885
|
+
font-weight: 500;
|
|
2886
|
+
|
|
2887
|
+
&::before {
|
|
2888
|
+
content: "“";
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
&::after {
|
|
2892
|
+
content: "”";
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2878
2896
|
.lb-ai-tool {
|
|
2879
2897
|
position: relative;
|
|
2880
2898
|
|