@poolse/react-ui 2.19.0 → 2.20.0
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/CHANGELOG.md +30 -0
- package/dist/index.cjs +101 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +101 -55
- package/dist/index.js.map +1 -1
- package/dist/styles.css +134 -43
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1632,6 +1632,27 @@ function formatBytes(n) {
|
|
|
1632
1632
|
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
1633
1633
|
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
1634
1634
|
}
|
|
1635
|
+
|
|
1636
|
+
// src/bubbleText.ts
|
|
1637
|
+
function hasMarkdown(body) {
|
|
1638
|
+
return /[*_~`#>|\\]|\[.*\]|^\s*(?:[-+]|\d+[.)])\s|https?:\/\/|www\./ms.test(body);
|
|
1639
|
+
}
|
|
1640
|
+
function emojiOnlyCount(body) {
|
|
1641
|
+
const text = body.trim();
|
|
1642
|
+
if (!text || text.length > 32) return 0;
|
|
1643
|
+
try {
|
|
1644
|
+
const unit = "(?:\\p{Regional_Indicator}{2}|\\p{Extended_Pictographic})[\\u{1F3FB}-\\u{1F3FF}]?\\uFE0F?(?:\\u200D\\p{Extended_Pictographic}[\\u{1F3FB}-\\u{1F3FF}]?\\uFE0F?)*";
|
|
1645
|
+
const whole = new RegExp(`^(?:${unit}){1,3}$`, "u");
|
|
1646
|
+
if (!whole.test(text)) return 0;
|
|
1647
|
+
const each = new RegExp(unit, "gu");
|
|
1648
|
+
return (text.match(each) ?? []).length;
|
|
1649
|
+
} catch {
|
|
1650
|
+
return 0;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
function emojiFontSize(count) {
|
|
1654
|
+
return count === 1 ? 44 : count === 2 ? 38 : 32;
|
|
1655
|
+
}
|
|
1635
1656
|
function MessageBubble({
|
|
1636
1657
|
message,
|
|
1637
1658
|
currentUserId,
|
|
@@ -1663,6 +1684,9 @@ function MessageBubble({
|
|
|
1663
1684
|
const hasAnyAttachment = imageAttachments.length > 0 || fileAttachments.length > 0;
|
|
1664
1685
|
const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
|
|
1665
1686
|
const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
|
|
1687
|
+
const jumboCount = hasVisibleBody && !hasAnyAttachment && !message.quoted_message_id ? emojiOnlyCount(rawBody) : 0;
|
|
1688
|
+
const trimToggleVisible = shouldTrim || expanded && rawBody.length > maxBodyLength + TRIM_BUFFER;
|
|
1689
|
+
const inlineMeta = hasVisibleBody && jumboCount === 0 && !trimToggleVisible && (!markdown || !hasMarkdown(displayBody));
|
|
1666
1690
|
const className = [
|
|
1667
1691
|
"poolse-message",
|
|
1668
1692
|
isSelf ? "poolse-message--self" : "poolse-message--other",
|
|
@@ -1672,7 +1696,8 @@ function MessageBubble({
|
|
|
1672
1696
|
// Tells the CSS to round the image mosaic's bottom corners to
|
|
1673
1697
|
// match the bubble's outer corner when nothing follows the media.
|
|
1674
1698
|
hasAnyAttachment ? "poolse-message--has-media" : "",
|
|
1675
|
-
metaOverlay ? "poolse-message--media-only" : ""
|
|
1699
|
+
metaOverlay ? "poolse-message--media-only" : "",
|
|
1700
|
+
jumboCount > 0 ? "poolse-message--jumbo" : ""
|
|
1676
1701
|
].filter(Boolean).join(" ");
|
|
1677
1702
|
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
1678
1703
|
hour: "2-digit",
|
|
@@ -1694,62 +1719,83 @@ function MessageBubble({
|
|
|
1694
1719
|
showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
1695
1720
|
imageAttachments.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images: imageAttachments }),
|
|
1696
1721
|
fileAttachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
{
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
"
|
|
1712
|
-
{
|
|
1713
|
-
type: "button",
|
|
1714
|
-
className: "poolse-message__read-more",
|
|
1715
|
-
onClick: (e) => {
|
|
1716
|
-
e.stopPropagation();
|
|
1717
|
-
setExpanded(true);
|
|
1718
|
-
},
|
|
1719
|
-
children: "Read more"
|
|
1720
|
-
}
|
|
1721
|
-
),
|
|
1722
|
-
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsx(
|
|
1723
|
-
"button",
|
|
1722
|
+
(() => {
|
|
1723
|
+
const metaContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1724
|
+
/* @__PURE__ */ jsx("span", { children: time }),
|
|
1725
|
+
message.edited_at && !message.deleted_at ? /* @__PURE__ */ jsx("span", { children: "\xB7 edited" }) : null,
|
|
1726
|
+
isSelf && readState ? /* @__PURE__ */ jsx(
|
|
1727
|
+
PoolseIcon,
|
|
1728
|
+
{
|
|
1729
|
+
name: readState === "read" ? "check-double" : "check",
|
|
1730
|
+
size: 14,
|
|
1731
|
+
label: readState === "read" ? "Read" : "Sent"
|
|
1732
|
+
}
|
|
1733
|
+
) : null
|
|
1734
|
+
] });
|
|
1735
|
+
const body = message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "Message deleted" }) : hasVisibleBody ? /* @__PURE__ */ jsxs(
|
|
1736
|
+
"div",
|
|
1724
1737
|
{
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1738
|
+
className: markdown && !inlineMeta && jumboCount === 0 ? "poolse-message__body poolse-message__body--md" : "poolse-message__body",
|
|
1739
|
+
children: [
|
|
1740
|
+
jumboCount > 0 ? /* @__PURE__ */ jsx(
|
|
1741
|
+
"span",
|
|
1742
|
+
{
|
|
1743
|
+
className: "poolse-message__body--jumbo",
|
|
1744
|
+
style: { fontSize: emojiFontSize(jumboCount) },
|
|
1745
|
+
children: displayBody
|
|
1746
|
+
}
|
|
1747
|
+
) : markdown && !inlineMeta ? /* @__PURE__ */ jsx(
|
|
1748
|
+
ReactMarkdown,
|
|
1749
|
+
{
|
|
1750
|
+
remarkPlugins: [remarkGfm],
|
|
1751
|
+
components: {
|
|
1752
|
+
// Force links to a new tab + no opener — chat content
|
|
1753
|
+
// is user-supplied so security defaults matter.
|
|
1754
|
+
a: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
|
|
1755
|
+
},
|
|
1756
|
+
children: displayBody
|
|
1757
|
+
}
|
|
1758
|
+
) : /* @__PURE__ */ jsx("span", { children: displayBody }),
|
|
1759
|
+
inlineMeta && // Invisible twin of the meta, inline after the text: it
|
|
1760
|
+
// reserves exactly the meta's footprint on the last
|
|
1761
|
+
// line, so the absolutely-positioned real meta never
|
|
1762
|
+
// overlaps a glyph — and when the line is full, the
|
|
1763
|
+
// reservation wraps and the meta drops a line, flush
|
|
1764
|
+
// right. The WhatsApp trick.
|
|
1765
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-message__meta poolse-message__meta--spacer", "aria-hidden": true, children: metaContent }),
|
|
1766
|
+
shouldTrim && /* @__PURE__ */ jsx(
|
|
1767
|
+
"button",
|
|
1768
|
+
{
|
|
1769
|
+
type: "button",
|
|
1770
|
+
className: "poolse-message__read-more",
|
|
1771
|
+
onClick: (e) => {
|
|
1772
|
+
e.stopPropagation();
|
|
1773
|
+
setExpanded(true);
|
|
1774
|
+
},
|
|
1775
|
+
children: "Read more"
|
|
1776
|
+
}
|
|
1777
|
+
),
|
|
1778
|
+
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsx(
|
|
1779
|
+
"button",
|
|
1780
|
+
{
|
|
1781
|
+
type: "button",
|
|
1782
|
+
className: "poolse-message__read-more",
|
|
1783
|
+
onClick: (e) => {
|
|
1784
|
+
e.stopPropagation();
|
|
1785
|
+
setExpanded(false);
|
|
1786
|
+
},
|
|
1787
|
+
children: "Show less"
|
|
1788
|
+
}
|
|
1789
|
+
)
|
|
1790
|
+
]
|
|
1732
1791
|
}
|
|
1733
|
-
)
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
/* @__PURE__ */ jsx("span", { children: time }),
|
|
1741
|
-
message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
|
|
1742
|
-
isSelf && readState ? /* @__PURE__ */ jsx(
|
|
1743
|
-
PoolseIcon,
|
|
1744
|
-
{
|
|
1745
|
-
name: readState === "read" ? "check-double" : "check",
|
|
1746
|
-
size: 14,
|
|
1747
|
-
label: readState === "read" ? "Read" : "Sent"
|
|
1748
|
-
}
|
|
1749
|
-
) : null
|
|
1750
|
-
]
|
|
1751
|
-
}
|
|
1752
|
-
)
|
|
1792
|
+
) : null;
|
|
1793
|
+
const metaClass = metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : inlineMeta ? "poolse-message__meta poolse-message__meta--inline" : "poolse-message__meta poolse-message__meta--block";
|
|
1794
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1795
|
+
body,
|
|
1796
|
+
/* @__PURE__ */ jsx("span", { className: metaClass, children: metaContent })
|
|
1797
|
+
] });
|
|
1798
|
+
})()
|
|
1753
1799
|
] });
|
|
1754
1800
|
}
|
|
1755
1801
|
function isImageContentType(ct) {
|