@liveblocks/core 1.8.1 → 1.8.3-oss1
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/index.d.mts +170 -34
- package/dist/index.d.ts +170 -34
- package/dist/index.js +465 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +416 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "1.8.
|
|
9
|
+
var PKG_VERSION = "1.8.3-oss1";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1744,6 +1744,359 @@ function errorIf(condition, message) {
|
|
|
1744
1744
|
}
|
|
1745
1745
|
}
|
|
1746
1746
|
|
|
1747
|
+
// src/comments/comment-body.ts
|
|
1748
|
+
function isCommentBodyParagraph(element) {
|
|
1749
|
+
return "type" in element && element.type === "mention";
|
|
1750
|
+
}
|
|
1751
|
+
function isCommentBodyText(element) {
|
|
1752
|
+
return "text" in element && typeof element.text === "string";
|
|
1753
|
+
}
|
|
1754
|
+
function isCommentBodyMention(element) {
|
|
1755
|
+
return "type" in element && element.type === "mention";
|
|
1756
|
+
}
|
|
1757
|
+
function isCommentBodyLink(element) {
|
|
1758
|
+
return "type" in element && element.type === "link";
|
|
1759
|
+
}
|
|
1760
|
+
var commentBodyElementsGuards = {
|
|
1761
|
+
paragraph: isCommentBodyParagraph,
|
|
1762
|
+
text: isCommentBodyText,
|
|
1763
|
+
link: isCommentBodyLink,
|
|
1764
|
+
mention: isCommentBodyMention
|
|
1765
|
+
};
|
|
1766
|
+
var commentBodyElementsTypes = {
|
|
1767
|
+
paragraph: "block",
|
|
1768
|
+
text: "inline",
|
|
1769
|
+
link: "inline",
|
|
1770
|
+
mention: "inline"
|
|
1771
|
+
};
|
|
1772
|
+
function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
|
|
1773
|
+
if (!body || !_optionalChain([body, 'optionalAccess', _44 => _44.content])) {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
|
|
1777
|
+
const type = element ? commentBodyElementsTypes[element] : "all";
|
|
1778
|
+
const guard = element ? commentBodyElementsGuards[element] : () => true;
|
|
1779
|
+
const visitor = typeof elementOrVisitor === "function" ? elementOrVisitor : possiblyVisitor;
|
|
1780
|
+
for (const block of body.content) {
|
|
1781
|
+
if (type === "all" || type === "block") {
|
|
1782
|
+
if (guard(block)) {
|
|
1783
|
+
_optionalChain([visitor, 'optionalCall', _45 => _45(block)]);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
if (type === "all" || type === "inline") {
|
|
1787
|
+
for (const inline of block.children) {
|
|
1788
|
+
if (guard(inline)) {
|
|
1789
|
+
_optionalChain([visitor, 'optionalCall', _46 => _46(inline)]);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
function getMentionedIdsFromCommentBody(body) {
|
|
1796
|
+
const mentionedIds = /* @__PURE__ */ new Set();
|
|
1797
|
+
traverseCommentBody(
|
|
1798
|
+
body,
|
|
1799
|
+
"mention",
|
|
1800
|
+
(mention) => mentionedIds.add(mention.id)
|
|
1801
|
+
);
|
|
1802
|
+
return Array.from(mentionedIds);
|
|
1803
|
+
}
|
|
1804
|
+
async function resolveUsersInCommentBody(body, resolveUsers) {
|
|
1805
|
+
const resolvedUsers = /* @__PURE__ */ new Map();
|
|
1806
|
+
if (!resolveUsers) {
|
|
1807
|
+
return resolvedUsers;
|
|
1808
|
+
}
|
|
1809
|
+
const userIds = getMentionedIdsFromCommentBody(body);
|
|
1810
|
+
const users = await resolveUsers({
|
|
1811
|
+
userIds
|
|
1812
|
+
});
|
|
1813
|
+
for (const [index, userId] of userIds.entries()) {
|
|
1814
|
+
const user = _optionalChain([users, 'optionalAccess', _47 => _47[index]]);
|
|
1815
|
+
if (user) {
|
|
1816
|
+
resolvedUsers.set(userId, user);
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
return resolvedUsers;
|
|
1820
|
+
}
|
|
1821
|
+
var htmlEscapables = {
|
|
1822
|
+
"&": "&",
|
|
1823
|
+
"<": "<",
|
|
1824
|
+
">": ">",
|
|
1825
|
+
'"': """,
|
|
1826
|
+
"'": "'"
|
|
1827
|
+
};
|
|
1828
|
+
var htmlEscapablesRegex = new RegExp(
|
|
1829
|
+
Object.keys(htmlEscapables).map((entity) => `\\${entity}`).join("|"),
|
|
1830
|
+
"g"
|
|
1831
|
+
);
|
|
1832
|
+
function htmlSafe(value) {
|
|
1833
|
+
return new HtmlSafeString([String(value)], []);
|
|
1834
|
+
}
|
|
1835
|
+
function joinHtml(strings) {
|
|
1836
|
+
if (strings.length <= 0) {
|
|
1837
|
+
return new HtmlSafeString([""], []);
|
|
1838
|
+
}
|
|
1839
|
+
return new HtmlSafeString(
|
|
1840
|
+
["", ...Array(strings.length - 1).fill(""), ""],
|
|
1841
|
+
strings
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
function escapeHtml(value) {
|
|
1845
|
+
if (value instanceof HtmlSafeString) {
|
|
1846
|
+
return value.toString();
|
|
1847
|
+
}
|
|
1848
|
+
if (Array.isArray(value)) {
|
|
1849
|
+
return joinHtml(value).toString();
|
|
1850
|
+
}
|
|
1851
|
+
return String(value).replace(
|
|
1852
|
+
htmlEscapablesRegex,
|
|
1853
|
+
(character) => htmlEscapables[character]
|
|
1854
|
+
);
|
|
1855
|
+
}
|
|
1856
|
+
var HtmlSafeString = class {
|
|
1857
|
+
constructor(strings, values) {
|
|
1858
|
+
this._strings = strings;
|
|
1859
|
+
this._values = values;
|
|
1860
|
+
}
|
|
1861
|
+
toString() {
|
|
1862
|
+
return this._strings.reduce((result, str, i) => {
|
|
1863
|
+
return result + escapeHtml(nn(this._values[i - 1])) + str;
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
function html(strings, ...values) {
|
|
1868
|
+
return new HtmlSafeString(strings, values);
|
|
1869
|
+
}
|
|
1870
|
+
var markdownEscapables = {
|
|
1871
|
+
_: "\\_",
|
|
1872
|
+
"*": "\\*",
|
|
1873
|
+
"#": "\\#",
|
|
1874
|
+
"`": "\\`",
|
|
1875
|
+
"~": "\\~",
|
|
1876
|
+
"!": "\\!",
|
|
1877
|
+
"|": "\\|",
|
|
1878
|
+
"(": "\\(",
|
|
1879
|
+
")": "\\)",
|
|
1880
|
+
"{": "\\{",
|
|
1881
|
+
"}": "\\}",
|
|
1882
|
+
"[": "\\[",
|
|
1883
|
+
"]": "\\]"
|
|
1884
|
+
};
|
|
1885
|
+
var markdownEscapablesRegex = new RegExp(
|
|
1886
|
+
Object.keys(markdownEscapables).map((entity) => `\\${entity}`).join("|"),
|
|
1887
|
+
"g"
|
|
1888
|
+
);
|
|
1889
|
+
function joinMarkdown(strings) {
|
|
1890
|
+
if (strings.length <= 0) {
|
|
1891
|
+
return new MarkdownSafeString([""], []);
|
|
1892
|
+
}
|
|
1893
|
+
return new MarkdownSafeString(
|
|
1894
|
+
["", ...Array(strings.length - 1).fill(""), ""],
|
|
1895
|
+
strings
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
function escapeMarkdown(value) {
|
|
1899
|
+
if (value instanceof MarkdownSafeString) {
|
|
1900
|
+
return value.toString();
|
|
1901
|
+
}
|
|
1902
|
+
if (Array.isArray(value)) {
|
|
1903
|
+
return joinMarkdown(value).toString();
|
|
1904
|
+
}
|
|
1905
|
+
return String(value).replace(
|
|
1906
|
+
markdownEscapablesRegex,
|
|
1907
|
+
(character) => markdownEscapables[character]
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
var MarkdownSafeString = class {
|
|
1911
|
+
constructor(strings, values) {
|
|
1912
|
+
this._strings = strings;
|
|
1913
|
+
this._values = values;
|
|
1914
|
+
}
|
|
1915
|
+
toString() {
|
|
1916
|
+
return this._strings.reduce((result, str, i) => {
|
|
1917
|
+
return result + escapeMarkdown(nn(this._values[i - 1])) + str;
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
function markdown(strings, ...values) {
|
|
1922
|
+
return new MarkdownSafeString(strings, values);
|
|
1923
|
+
}
|
|
1924
|
+
function toAbsoluteUrl(url) {
|
|
1925
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
1926
|
+
return url;
|
|
1927
|
+
} else if (url.startsWith("www.")) {
|
|
1928
|
+
return "https://" + url;
|
|
1929
|
+
}
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
var stringifyCommentBodyPlainElements = {
|
|
1933
|
+
paragraph: ({ children }) => children,
|
|
1934
|
+
text: ({ element }) => element.text,
|
|
1935
|
+
link: ({ element }) => element.url,
|
|
1936
|
+
mention: ({ element, user }) => {
|
|
1937
|
+
return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _48 => _48.name]), () => ( element.id))}`;
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
var stringifyCommentBodyHtmlElements = {
|
|
1941
|
+
paragraph: ({ children }) => {
|
|
1942
|
+
return children ? html`<p>${htmlSafe(children)}</p>` : children;
|
|
1943
|
+
},
|
|
1944
|
+
text: ({ element }) => {
|
|
1945
|
+
let children = element.text;
|
|
1946
|
+
if (!children) {
|
|
1947
|
+
return children;
|
|
1948
|
+
}
|
|
1949
|
+
if (element.bold) {
|
|
1950
|
+
children = html`<strong>${children}</strong>`;
|
|
1951
|
+
}
|
|
1952
|
+
if (element.italic) {
|
|
1953
|
+
children = html`<em>${children}</em>`;
|
|
1954
|
+
}
|
|
1955
|
+
if (element.strikethrough) {
|
|
1956
|
+
children = html`<s>${children}</s>`;
|
|
1957
|
+
}
|
|
1958
|
+
if (element.code) {
|
|
1959
|
+
children = html`<code>${children}</code>`;
|
|
1960
|
+
}
|
|
1961
|
+
return children;
|
|
1962
|
+
},
|
|
1963
|
+
link: ({ element, href }) => {
|
|
1964
|
+
return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.url}</a>`;
|
|
1965
|
+
},
|
|
1966
|
+
mention: ({ element, user }) => {
|
|
1967
|
+
return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _49 => _49.name]), () => ( element.id))}</span>`;
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
var stringifyCommentBodyMarkdownElements = {
|
|
1971
|
+
paragraph: ({ children }) => {
|
|
1972
|
+
return children;
|
|
1973
|
+
},
|
|
1974
|
+
text: ({ element }) => {
|
|
1975
|
+
let children = element.text;
|
|
1976
|
+
if (!children) {
|
|
1977
|
+
return children;
|
|
1978
|
+
}
|
|
1979
|
+
if (element.bold) {
|
|
1980
|
+
children = markdown`**${children}**`;
|
|
1981
|
+
}
|
|
1982
|
+
if (element.italic) {
|
|
1983
|
+
children = markdown`_${children}_`;
|
|
1984
|
+
}
|
|
1985
|
+
if (element.strikethrough) {
|
|
1986
|
+
children = markdown`~~${children}~~`;
|
|
1987
|
+
}
|
|
1988
|
+
if (element.code) {
|
|
1989
|
+
children = markdown`\`${children}\``;
|
|
1990
|
+
}
|
|
1991
|
+
return children;
|
|
1992
|
+
},
|
|
1993
|
+
link: ({ element, href }) => {
|
|
1994
|
+
return markdown`[${element.url}](${href})`;
|
|
1995
|
+
},
|
|
1996
|
+
mention: ({ element, user }) => {
|
|
1997
|
+
return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _50 => _50.name]), () => ( element.id))}`;
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
async function stringifyCommentBody(body, options) {
|
|
2001
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.format]), () => ( "plain"));
|
|
2002
|
+
const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
|
|
2003
|
+
const elements = {
|
|
2004
|
+
...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
|
|
2005
|
+
..._optionalChain([options, 'optionalAccess', _53 => _53.elements])
|
|
2006
|
+
};
|
|
2007
|
+
const resolvedUsers = await resolveUsersInCommentBody(
|
|
2008
|
+
body,
|
|
2009
|
+
_optionalChain([options, 'optionalAccess', _54 => _54.resolveUsers])
|
|
2010
|
+
);
|
|
2011
|
+
const blocks = body.content.flatMap((block, blockIndex) => {
|
|
2012
|
+
switch (block.type) {
|
|
2013
|
+
case "paragraph": {
|
|
2014
|
+
const inlines = block.children.flatMap((inline, inlineIndex) => {
|
|
2015
|
+
if (isCommentBodyMention(inline)) {
|
|
2016
|
+
return inline.id ? [
|
|
2017
|
+
elements.mention(
|
|
2018
|
+
{
|
|
2019
|
+
element: inline,
|
|
2020
|
+
user: resolvedUsers.get(inline.id)
|
|
2021
|
+
},
|
|
2022
|
+
inlineIndex
|
|
2023
|
+
)
|
|
2024
|
+
] : [];
|
|
2025
|
+
}
|
|
2026
|
+
if (isCommentBodyLink(inline)) {
|
|
2027
|
+
return [
|
|
2028
|
+
elements.link(
|
|
2029
|
+
{
|
|
2030
|
+
element: inline,
|
|
2031
|
+
href: _nullishCoalesce(toAbsoluteUrl(inline.url), () => ( inline.url))
|
|
2032
|
+
},
|
|
2033
|
+
inlineIndex
|
|
2034
|
+
)
|
|
2035
|
+
];
|
|
2036
|
+
}
|
|
2037
|
+
if (isCommentBodyText(inline)) {
|
|
2038
|
+
return [elements.text({ element: inline }, inlineIndex)];
|
|
2039
|
+
}
|
|
2040
|
+
return [];
|
|
2041
|
+
});
|
|
2042
|
+
return [
|
|
2043
|
+
elements.paragraph(
|
|
2044
|
+
{ element: block, children: inlines.join("") },
|
|
2045
|
+
blockIndex
|
|
2046
|
+
)
|
|
2047
|
+
];
|
|
2048
|
+
}
|
|
2049
|
+
default:
|
|
2050
|
+
return [];
|
|
2051
|
+
}
|
|
2052
|
+
});
|
|
2053
|
+
return blocks.join(separator);
|
|
2054
|
+
}
|
|
2055
|
+
function convertToCommentData(data) {
|
|
2056
|
+
const editedAt = data.editedAt ? new Date(data.editedAt) : void 0;
|
|
2057
|
+
const createdAt = new Date(data.createdAt);
|
|
2058
|
+
const reactions = data.reactions.map((reaction) => ({
|
|
2059
|
+
...reaction,
|
|
2060
|
+
createdAt: new Date(reaction.createdAt)
|
|
2061
|
+
}));
|
|
2062
|
+
if (data.body) {
|
|
2063
|
+
return {
|
|
2064
|
+
...data,
|
|
2065
|
+
reactions,
|
|
2066
|
+
createdAt,
|
|
2067
|
+
editedAt
|
|
2068
|
+
};
|
|
2069
|
+
} else {
|
|
2070
|
+
const deletedAt = new Date(data.deletedAt);
|
|
2071
|
+
return {
|
|
2072
|
+
...data,
|
|
2073
|
+
reactions,
|
|
2074
|
+
createdAt,
|
|
2075
|
+
editedAt,
|
|
2076
|
+
deletedAt
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function convertToThreadData(data) {
|
|
2081
|
+
const updatedAt = data.updatedAt ? new Date(data.updatedAt) : void 0;
|
|
2082
|
+
const createdAt = new Date(data.createdAt);
|
|
2083
|
+
const comments = data.comments.map(
|
|
2084
|
+
(comment) => convertToCommentData(comment)
|
|
2085
|
+
);
|
|
2086
|
+
return {
|
|
2087
|
+
...data,
|
|
2088
|
+
createdAt,
|
|
2089
|
+
updatedAt,
|
|
2090
|
+
comments
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
function convertToCommentUserReaction(data) {
|
|
2094
|
+
return {
|
|
2095
|
+
...data,
|
|
2096
|
+
createdAt: new Date(data.createdAt)
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
|
|
1747
2100
|
// src/comments/index.ts
|
|
1748
2101
|
function getAuthBearerHeaderFromAuthValue(authValue) {
|
|
1749
2102
|
if (authValue.type === "public") {
|
|
@@ -1796,7 +2149,7 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1796
2149
|
return await fetch(url, {
|
|
1797
2150
|
...options,
|
|
1798
2151
|
headers: {
|
|
1799
|
-
..._optionalChain([options, 'optionalAccess',
|
|
2152
|
+
..._optionalChain([options, 'optionalAccess', _55 => _55.headers]),
|
|
1800
2153
|
Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
|
|
1801
2154
|
}
|
|
1802
2155
|
});
|
|
@@ -1805,39 +2158,43 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1805
2158
|
const response = await fetchApi(roomId, "/threads");
|
|
1806
2159
|
if (response.ok) {
|
|
1807
2160
|
const json = await response.json();
|
|
1808
|
-
return json.data;
|
|
2161
|
+
return json.data.map((thread) => convertToThreadData(thread));
|
|
1809
2162
|
} else if (response.status === 404) {
|
|
1810
2163
|
return [];
|
|
1811
2164
|
} else {
|
|
1812
2165
|
throw new Error("There was an error while getting threads.");
|
|
1813
2166
|
}
|
|
1814
2167
|
}
|
|
1815
|
-
function createThread({
|
|
2168
|
+
async function createThread({
|
|
1816
2169
|
metadata,
|
|
1817
2170
|
body,
|
|
1818
2171
|
commentId,
|
|
1819
2172
|
threadId
|
|
1820
2173
|
}) {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
id: threadId,
|
|
1828
|
-
comment: {
|
|
1829
|
-
id: commentId,
|
|
1830
|
-
body
|
|
2174
|
+
const thread = await fetchJson(
|
|
2175
|
+
"/threads",
|
|
2176
|
+
{
|
|
2177
|
+
method: "POST",
|
|
2178
|
+
headers: {
|
|
2179
|
+
"Content-Type": "application/json"
|
|
1831
2180
|
},
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
2181
|
+
body: JSON.stringify({
|
|
2182
|
+
id: threadId,
|
|
2183
|
+
comment: {
|
|
2184
|
+
id: commentId,
|
|
2185
|
+
body
|
|
2186
|
+
},
|
|
2187
|
+
metadata
|
|
2188
|
+
})
|
|
2189
|
+
}
|
|
2190
|
+
);
|
|
2191
|
+
return convertToThreadData(thread);
|
|
1835
2192
|
}
|
|
1836
|
-
function editThreadMetadata({
|
|
2193
|
+
async function editThreadMetadata({
|
|
1837
2194
|
metadata,
|
|
1838
2195
|
threadId
|
|
1839
2196
|
}) {
|
|
1840
|
-
return fetchJson(
|
|
2197
|
+
return await fetchJson(
|
|
1841
2198
|
`/threads/${encodeURIComponent(threadId)}/metadata`,
|
|
1842
2199
|
{
|
|
1843
2200
|
method: "POST",
|
|
@@ -1848,12 +2205,12 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1848
2205
|
}
|
|
1849
2206
|
);
|
|
1850
2207
|
}
|
|
1851
|
-
function createComment({
|
|
2208
|
+
async function createComment({
|
|
1852
2209
|
threadId,
|
|
1853
2210
|
commentId,
|
|
1854
2211
|
body
|
|
1855
2212
|
}) {
|
|
1856
|
-
|
|
2213
|
+
const comment = await fetchJson(
|
|
1857
2214
|
`/threads/${encodeURIComponent(threadId)}/comments`,
|
|
1858
2215
|
{
|
|
1859
2216
|
method: "POST",
|
|
@@ -1866,13 +2223,14 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1866
2223
|
})
|
|
1867
2224
|
}
|
|
1868
2225
|
);
|
|
2226
|
+
return convertToCommentData(comment);
|
|
1869
2227
|
}
|
|
1870
|
-
function editComment({
|
|
2228
|
+
async function editComment({
|
|
1871
2229
|
threadId,
|
|
1872
2230
|
commentId,
|
|
1873
2231
|
body
|
|
1874
2232
|
}) {
|
|
1875
|
-
|
|
2233
|
+
const comment = await fetchJson(
|
|
1876
2234
|
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
1877
2235
|
commentId
|
|
1878
2236
|
)}`,
|
|
@@ -1886,6 +2244,7 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1886
2244
|
})
|
|
1887
2245
|
}
|
|
1888
2246
|
);
|
|
2247
|
+
return convertToCommentData(comment);
|
|
1889
2248
|
}
|
|
1890
2249
|
async function deleteComment({
|
|
1891
2250
|
threadId,
|
|
@@ -1900,12 +2259,12 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1900
2259
|
}
|
|
1901
2260
|
);
|
|
1902
2261
|
}
|
|
1903
|
-
function addReaction({
|
|
2262
|
+
async function addReaction({
|
|
1904
2263
|
threadId,
|
|
1905
2264
|
commentId,
|
|
1906
2265
|
emoji
|
|
1907
2266
|
}) {
|
|
1908
|
-
|
|
2267
|
+
const reaction = await fetchJson(
|
|
1909
2268
|
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
1910
2269
|
commentId
|
|
1911
2270
|
)}/reactions`,
|
|
@@ -1917,13 +2276,14 @@ function createCommentsApi(roomId, getAuthValue, config) {
|
|
|
1917
2276
|
body: JSON.stringify({ emoji })
|
|
1918
2277
|
}
|
|
1919
2278
|
);
|
|
2279
|
+
return convertToCommentUserReaction(reaction);
|
|
1920
2280
|
}
|
|
1921
|
-
function removeReaction({
|
|
2281
|
+
async function removeReaction({
|
|
1922
2282
|
threadId,
|
|
1923
2283
|
commentId,
|
|
1924
2284
|
emoji
|
|
1925
2285
|
}) {
|
|
1926
|
-
|
|
2286
|
+
await fetchJson(
|
|
1927
2287
|
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
1928
2288
|
commentId
|
|
1929
2289
|
)}/reactions/${encodeURIComponent(emoji)}`,
|
|
@@ -2084,6 +2444,14 @@ var OpCode = /* @__PURE__ */ ((OpCode2) => {
|
|
|
2084
2444
|
OpCode2[OpCode2["CREATE_REGISTER"] = 8] = "CREATE_REGISTER";
|
|
2085
2445
|
return OpCode2;
|
|
2086
2446
|
})(OpCode || {});
|
|
2447
|
+
function ackOp(opId) {
|
|
2448
|
+
return {
|
|
2449
|
+
type: 5 /* DELETE_CRDT */,
|
|
2450
|
+
id: "ACK",
|
|
2451
|
+
// (H)ACK
|
|
2452
|
+
opId
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2087
2455
|
function isAckOp(op) {
|
|
2088
2456
|
return op.type === 5 /* DELETE_CRDT */ && op.id === "ACK";
|
|
2089
2457
|
}
|
|
@@ -2309,7 +2677,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2309
2677
|
return [
|
|
2310
2678
|
{
|
|
2311
2679
|
type: 8 /* CREATE_REGISTER */,
|
|
2312
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2680
|
+
opId: _optionalChain([pool, 'optionalAccess', _56 => _56.generateOpId, 'call', _57 => _57()]),
|
|
2313
2681
|
id: this._id,
|
|
2314
2682
|
parentId,
|
|
2315
2683
|
parentKey,
|
|
@@ -2411,7 +2779,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2411
2779
|
const ops = [];
|
|
2412
2780
|
const op = {
|
|
2413
2781
|
id: this._id,
|
|
2414
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2782
|
+
opId: _optionalChain([pool, 'optionalAccess', _58 => _58.generateOpId, 'call', _59 => _59()]),
|
|
2415
2783
|
type: 2 /* CREATE_LIST */,
|
|
2416
2784
|
parentId,
|
|
2417
2785
|
parentKey
|
|
@@ -2688,7 +3056,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2688
3056
|
_applyInsertUndoRedo(op) {
|
|
2689
3057
|
const { id, parentKey: key } = op;
|
|
2690
3058
|
const child = creationOpToLiveNode(op);
|
|
2691
|
-
if (_optionalChain([this, 'access',
|
|
3059
|
+
if (_optionalChain([this, 'access', _60 => _60._pool, 'optionalAccess', _61 => _61.getNode, 'call', _62 => _62(id)]) !== void 0) {
|
|
2692
3060
|
return { modified: false };
|
|
2693
3061
|
}
|
|
2694
3062
|
child._attach(id, nn(this._pool));
|
|
@@ -2696,8 +3064,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2696
3064
|
const existingItemIndex = this._indexOfPosition(key);
|
|
2697
3065
|
let newKey = key;
|
|
2698
3066
|
if (existingItemIndex !== -1) {
|
|
2699
|
-
const before2 = _optionalChain([this, 'access',
|
|
2700
|
-
const after2 = _optionalChain([this, 'access',
|
|
3067
|
+
const before2 = _optionalChain([this, 'access', _63 => _63._items, 'access', _64 => _64[existingItemIndex], 'optionalAccess', _65 => _65._parentPos]);
|
|
3068
|
+
const after2 = _optionalChain([this, 'access', _66 => _66._items, 'access', _67 => _67[existingItemIndex + 1], 'optionalAccess', _68 => _68._parentPos]);
|
|
2701
3069
|
newKey = makePosition(before2, after2);
|
|
2702
3070
|
child._setParentLink(this, newKey);
|
|
2703
3071
|
}
|
|
@@ -2712,7 +3080,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2712
3080
|
_applySetUndoRedo(op) {
|
|
2713
3081
|
const { id, parentKey: key } = op;
|
|
2714
3082
|
const child = creationOpToLiveNode(op);
|
|
2715
|
-
if (_optionalChain([this, 'access',
|
|
3083
|
+
if (_optionalChain([this, 'access', _69 => _69._pool, 'optionalAccess', _70 => _70.getNode, 'call', _71 => _71(id)]) !== void 0) {
|
|
2716
3084
|
return { modified: false };
|
|
2717
3085
|
}
|
|
2718
3086
|
this._unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -2834,7 +3202,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2834
3202
|
} else {
|
|
2835
3203
|
this._items[existingItemIndex]._setParentLink(
|
|
2836
3204
|
this,
|
|
2837
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
3205
|
+
makePosition(newKey, _optionalChain([this, 'access', _72 => _72._items, 'access', _73 => _73[existingItemIndex + 1], 'optionalAccess', _74 => _74._parentPos]))
|
|
2838
3206
|
);
|
|
2839
3207
|
const previousIndex = this._items.indexOf(child);
|
|
2840
3208
|
child._setParentLink(this, newKey);
|
|
@@ -2860,7 +3228,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2860
3228
|
if (existingItemIndex !== -1) {
|
|
2861
3229
|
this._items[existingItemIndex]._setParentLink(
|
|
2862
3230
|
this,
|
|
2863
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
3231
|
+
makePosition(newKey, _optionalChain([this, 'access', _75 => _75._items, 'access', _76 => _76[existingItemIndex + 1], 'optionalAccess', _77 => _77._parentPos]))
|
|
2864
3232
|
);
|
|
2865
3233
|
}
|
|
2866
3234
|
child._setParentLink(this, newKey);
|
|
@@ -2879,7 +3247,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2879
3247
|
if (existingItemIndex !== -1) {
|
|
2880
3248
|
this._items[existingItemIndex]._setParentLink(
|
|
2881
3249
|
this,
|
|
2882
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
3250
|
+
makePosition(newKey, _optionalChain([this, 'access', _78 => _78._items, 'access', _79 => _79[existingItemIndex + 1], 'optionalAccess', _80 => _80._parentPos]))
|
|
2883
3251
|
);
|
|
2884
3252
|
}
|
|
2885
3253
|
child._setParentLink(this, newKey);
|
|
@@ -2907,7 +3275,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2907
3275
|
if (existingItemIndex !== -1) {
|
|
2908
3276
|
this._items[existingItemIndex]._setParentLink(
|
|
2909
3277
|
this,
|
|
2910
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
3278
|
+
makePosition(newKey, _optionalChain([this, 'access', _81 => _81._items, 'access', _82 => _82[existingItemIndex + 1], 'optionalAccess', _83 => _83._parentPos]))
|
|
2911
3279
|
);
|
|
2912
3280
|
}
|
|
2913
3281
|
child._setParentLink(this, newKey);
|
|
@@ -2965,7 +3333,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2965
3333
|
* @param element The element to add to the end of the LiveList.
|
|
2966
3334
|
*/
|
|
2967
3335
|
push(element) {
|
|
2968
|
-
_optionalChain([this, 'access',
|
|
3336
|
+
_optionalChain([this, 'access', _84 => _84._pool, 'optionalAccess', _85 => _85.assertStorageIsWritable, 'call', _86 => _86()]);
|
|
2969
3337
|
return this.insert(element, this.length);
|
|
2970
3338
|
}
|
|
2971
3339
|
/**
|
|
@@ -2974,7 +3342,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2974
3342
|
* @param index The index at which you want to insert the element.
|
|
2975
3343
|
*/
|
|
2976
3344
|
insert(element, index) {
|
|
2977
|
-
_optionalChain([this, 'access',
|
|
3345
|
+
_optionalChain([this, 'access', _87 => _87._pool, 'optionalAccess', _88 => _88.assertStorageIsWritable, 'call', _89 => _89()]);
|
|
2978
3346
|
if (index < 0 || index > this._items.length) {
|
|
2979
3347
|
throw new Error(
|
|
2980
3348
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
|
|
@@ -3004,7 +3372,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3004
3372
|
* @param targetIndex The index where the element should be after moving.
|
|
3005
3373
|
*/
|
|
3006
3374
|
move(index, targetIndex) {
|
|
3007
|
-
_optionalChain([this, 'access',
|
|
3375
|
+
_optionalChain([this, 'access', _90 => _90._pool, 'optionalAccess', _91 => _91.assertStorageIsWritable, 'call', _92 => _92()]);
|
|
3008
3376
|
if (targetIndex < 0) {
|
|
3009
3377
|
throw new Error("targetIndex cannot be less than 0");
|
|
3010
3378
|
}
|
|
@@ -3062,10 +3430,10 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3062
3430
|
* @param index The index of the element to delete
|
|
3063
3431
|
*/
|
|
3064
3432
|
delete(index) {
|
|
3065
|
-
_optionalChain([this, 'access',
|
|
3433
|
+
_optionalChain([this, 'access', _93 => _93._pool, 'optionalAccess', _94 => _94.assertStorageIsWritable, 'call', _95 => _95()]);
|
|
3066
3434
|
if (index < 0 || index >= this._items.length) {
|
|
3067
3435
|
throw new Error(
|
|
3068
|
-
`Cannot delete list item at index "
|
|
3436
|
+
`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
3069
3437
|
);
|
|
3070
3438
|
}
|
|
3071
3439
|
const item = this._items[index];
|
|
@@ -3095,7 +3463,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3095
3463
|
}
|
|
3096
3464
|
}
|
|
3097
3465
|
clear() {
|
|
3098
|
-
_optionalChain([this, 'access',
|
|
3466
|
+
_optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.assertStorageIsWritable, 'call', _98 => _98()]);
|
|
3099
3467
|
if (this._pool) {
|
|
3100
3468
|
const ops = [];
|
|
3101
3469
|
const reverseOps = [];
|
|
@@ -3129,7 +3497,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3129
3497
|
}
|
|
3130
3498
|
}
|
|
3131
3499
|
set(index, item) {
|
|
3132
|
-
_optionalChain([this, 'access',
|
|
3500
|
+
_optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
|
|
3133
3501
|
if (index < 0 || index >= this._items.length) {
|
|
3134
3502
|
throw new Error(
|
|
3135
3503
|
`Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -3277,7 +3645,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3277
3645
|
_shiftItemPosition(index, key) {
|
|
3278
3646
|
const shiftedPosition = makePosition(
|
|
3279
3647
|
key,
|
|
3280
|
-
this._items.length > index + 1 ? _optionalChain([this, 'access',
|
|
3648
|
+
this._items.length > index + 1 ? _optionalChain([this, 'access', _102 => _102._items, 'access', _103 => _103[index + 1], 'optionalAccess', _104 => _104._parentPos]) : void 0
|
|
3281
3649
|
);
|
|
3282
3650
|
this._items[index]._setParentLink(this, shiftedPosition);
|
|
3283
3651
|
}
|
|
@@ -3406,7 +3774,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3406
3774
|
const ops = [];
|
|
3407
3775
|
const op = {
|
|
3408
3776
|
id: this._id,
|
|
3409
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
3777
|
+
opId: _optionalChain([pool, 'optionalAccess', _105 => _105.generateOpId, 'call', _106 => _106()]),
|
|
3410
3778
|
type: 7 /* CREATE_MAP */,
|
|
3411
3779
|
parentId,
|
|
3412
3780
|
parentKey
|
|
@@ -3553,7 +3921,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3553
3921
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
3554
3922
|
*/
|
|
3555
3923
|
set(key, value) {
|
|
3556
|
-
_optionalChain([this, 'access',
|
|
3924
|
+
_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.assertStorageIsWritable, 'call', _109 => _109()]);
|
|
3557
3925
|
const oldValue = this._map.get(key);
|
|
3558
3926
|
if (oldValue) {
|
|
3559
3927
|
oldValue._detach();
|
|
@@ -3599,7 +3967,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3599
3967
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
3600
3968
|
*/
|
|
3601
3969
|
delete(key) {
|
|
3602
|
-
_optionalChain([this, 'access',
|
|
3970
|
+
_optionalChain([this, 'access', _110 => _110._pool, 'optionalAccess', _111 => _111.assertStorageIsWritable, 'call', _112 => _112()]);
|
|
3603
3971
|
const item = this._map.get(key);
|
|
3604
3972
|
if (item === void 0) {
|
|
3605
3973
|
return false;
|
|
@@ -3778,7 +4146,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3778
4146
|
if (this._id === void 0) {
|
|
3779
4147
|
throw new Error("Cannot serialize item is not attached");
|
|
3780
4148
|
}
|
|
3781
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
4149
|
+
const opId = _optionalChain([pool, 'optionalAccess', _113 => _113.generateOpId, 'call', _114 => _114()]);
|
|
3782
4150
|
const ops = [];
|
|
3783
4151
|
const op = {
|
|
3784
4152
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -4056,7 +4424,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4056
4424
|
* @param value The value of the property to add
|
|
4057
4425
|
*/
|
|
4058
4426
|
set(key, value) {
|
|
4059
|
-
_optionalChain([this, 'access',
|
|
4427
|
+
_optionalChain([this, 'access', _115 => _115._pool, 'optionalAccess', _116 => _116.assertStorageIsWritable, 'call', _117 => _117()]);
|
|
4060
4428
|
this.update({ [key]: value });
|
|
4061
4429
|
}
|
|
4062
4430
|
/**
|
|
@@ -4071,7 +4439,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4071
4439
|
* @param key The key of the property to delete
|
|
4072
4440
|
*/
|
|
4073
4441
|
delete(key) {
|
|
4074
|
-
_optionalChain([this, 'access',
|
|
4442
|
+
_optionalChain([this, 'access', _118 => _118._pool, 'optionalAccess', _119 => _119.assertStorageIsWritable, 'call', _120 => _120()]);
|
|
4075
4443
|
const keyAsString = key;
|
|
4076
4444
|
const oldValue = this._map.get(keyAsString);
|
|
4077
4445
|
if (oldValue === void 0) {
|
|
@@ -4124,7 +4492,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4124
4492
|
* @param patch The object used to overrides properties
|
|
4125
4493
|
*/
|
|
4126
4494
|
update(patch) {
|
|
4127
|
-
_optionalChain([this, 'access',
|
|
4495
|
+
_optionalChain([this, 'access', _121 => _121._pool, 'optionalAccess', _122 => _122.assertStorageIsWritable, 'call', _123 => _123()]);
|
|
4128
4496
|
if (this._pool === void 0 || this._id === void 0) {
|
|
4129
4497
|
for (const key in patch) {
|
|
4130
4498
|
const newValue = patch[key];
|
|
@@ -4768,15 +5136,15 @@ function installBackgroundTabSpy() {
|
|
|
4768
5136
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
4769
5137
|
const inBackgroundSince = { current: null };
|
|
4770
5138
|
function onVisibilityChange() {
|
|
4771
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
5139
|
+
if (_optionalChain([doc, 'optionalAccess', _124 => _124.visibilityState]) === "hidden") {
|
|
4772
5140
|
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
4773
5141
|
} else {
|
|
4774
5142
|
inBackgroundSince.current = null;
|
|
4775
5143
|
}
|
|
4776
5144
|
}
|
|
4777
|
-
_optionalChain([doc, 'optionalAccess',
|
|
5145
|
+
_optionalChain([doc, 'optionalAccess', _125 => _125.addEventListener, 'call', _126 => _126("visibilitychange", onVisibilityChange)]);
|
|
4778
5146
|
const unsub = () => {
|
|
4779
|
-
_optionalChain([doc, 'optionalAccess',
|
|
5147
|
+
_optionalChain([doc, 'optionalAccess', _127 => _127.removeEventListener, 'call', _128 => _128("visibilitychange", onVisibilityChange)]);
|
|
4780
5148
|
};
|
|
4781
5149
|
return [inBackgroundSince, unsub];
|
|
4782
5150
|
}
|
|
@@ -4965,7 +5333,7 @@ function createRoom(options, config) {
|
|
|
4965
5333
|
}
|
|
4966
5334
|
},
|
|
4967
5335
|
assertStorageIsWritable: () => {
|
|
4968
|
-
const scopes = _optionalChain([context, 'access',
|
|
5336
|
+
const scopes = _optionalChain([context, 'access', _129 => _129.dynamicSessionInfo, 'access', _130 => _130.current, 'optionalAccess', _131 => _131.scopes]);
|
|
4969
5337
|
if (scopes === void 0) {
|
|
4970
5338
|
return;
|
|
4971
5339
|
}
|
|
@@ -4995,12 +5363,16 @@ function createRoom(options, config) {
|
|
|
4995
5363
|
ydoc: makeEventSource(),
|
|
4996
5364
|
comments: makeEventSource()
|
|
4997
5365
|
};
|
|
4998
|
-
async function
|
|
5366
|
+
async function httpPostToRoom(endpoint, body) {
|
|
5367
|
+
if (!managedSocket.authValue) {
|
|
5368
|
+
throw new Error("Not authorized");
|
|
5369
|
+
}
|
|
5370
|
+
const authTokenOrPublicApiKey = managedSocket.authValue.type === "public" ? managedSocket.authValue.publicApiKey : managedSocket.authValue.token.raw;
|
|
4999
5371
|
const url = new URL(
|
|
5000
|
-
`/v2/c/rooms/${encodeURIComponent(roomId)}
|
|
5372
|
+
`/v2/c/rooms/${encodeURIComponent(config.roomId)}${endpoint}`,
|
|
5001
5373
|
config.baseUrl
|
|
5002
5374
|
).toString();
|
|
5003
|
-
const fetcher = _optionalChain([config, 'access',
|
|
5375
|
+
const fetcher = _optionalChain([config, 'access', _132 => _132.polyfills, 'optionalAccess', _133 => _133.fetch]) || /* istanbul ignore next */
|
|
5004
5376
|
fetch;
|
|
5005
5377
|
return fetcher(url, {
|
|
5006
5378
|
method: "POST",
|
|
@@ -5008,25 +5380,22 @@ function createRoom(options, config) {
|
|
|
5008
5380
|
"Content-Type": "application/json",
|
|
5009
5381
|
Authorization: `Bearer ${authTokenOrPublicApiKey}`
|
|
5010
5382
|
},
|
|
5011
|
-
body: JSON.stringify(
|
|
5383
|
+
body: JSON.stringify(body)
|
|
5012
5384
|
});
|
|
5013
5385
|
}
|
|
5014
5386
|
function sendMessages(messages) {
|
|
5015
5387
|
const serializedPayload = JSON.stringify(messages);
|
|
5016
|
-
const nonce = _optionalChain([context, 'access',
|
|
5017
|
-
if (config.unstable_fallbackToHTTP &&
|
|
5388
|
+
const nonce = _optionalChain([context, 'access', _134 => _134.dynamicSessionInfo, 'access', _135 => _135.current, 'optionalAccess', _136 => _136.nonce]);
|
|
5389
|
+
if (config.unstable_fallbackToHTTP && nonce) {
|
|
5018
5390
|
const size = new TextEncoder().encode(serializedPayload).length;
|
|
5019
5391
|
if (size > MAX_SOCKET_MESSAGE_SIZE) {
|
|
5020
|
-
void
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
).then((resp) => {
|
|
5026
|
-
if (!resp.ok && resp.status === 403) {
|
|
5027
|
-
managedSocket.reconnect();
|
|
5392
|
+
void httpPostToRoom("/send-message", { nonce, messages }).then(
|
|
5393
|
+
(resp) => {
|
|
5394
|
+
if (!resp.ok && resp.status === 403) {
|
|
5395
|
+
managedSocket.reconnect();
|
|
5396
|
+
}
|
|
5028
5397
|
}
|
|
5029
|
-
|
|
5398
|
+
);
|
|
5030
5399
|
warn(
|
|
5031
5400
|
"Message was too large for websockets and sent over HTTP instead"
|
|
5032
5401
|
);
|
|
@@ -5278,7 +5647,7 @@ function createRoom(options, config) {
|
|
|
5278
5647
|
}
|
|
5279
5648
|
context.myPresence.patch(patch);
|
|
5280
5649
|
if (context.activeBatch) {
|
|
5281
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5650
|
+
if (_optionalChain([options2, 'optionalAccess', _137 => _137.addToHistory])) {
|
|
5282
5651
|
context.activeBatch.reverseOps.unshift({
|
|
5283
5652
|
type: "presence",
|
|
5284
5653
|
data: oldValues
|
|
@@ -5288,7 +5657,7 @@ function createRoom(options, config) {
|
|
|
5288
5657
|
} else {
|
|
5289
5658
|
flushNowOrSoon();
|
|
5290
5659
|
batchUpdates(() => {
|
|
5291
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5660
|
+
if (_optionalChain([options2, 'optionalAccess', _138 => _138.addToHistory])) {
|
|
5292
5661
|
addToUndoStack(
|
|
5293
5662
|
[{ type: "presence", data: oldValues }],
|
|
5294
5663
|
doNotBatchUpdates
|
|
@@ -5468,7 +5837,7 @@ function createRoom(options, config) {
|
|
|
5468
5837
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
5469
5838
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
5470
5839
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
5471
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
5840
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _139 => _139()]);
|
|
5472
5841
|
notifyStorageStatus();
|
|
5473
5842
|
eventHub.storageDidLoad.notify();
|
|
5474
5843
|
break;
|
|
@@ -5491,7 +5860,7 @@ function createRoom(options, config) {
|
|
|
5491
5860
|
if (process.env.NODE_ENV !== "production") {
|
|
5492
5861
|
const traces = /* @__PURE__ */ new Set();
|
|
5493
5862
|
for (const opId of message.opIds) {
|
|
5494
|
-
const trace = _optionalChain([context, 'access',
|
|
5863
|
+
const trace = _optionalChain([context, 'access', _140 => _140.opStackTraces, 'optionalAccess', _141 => _141.get, 'call', _142 => _142(opId)]);
|
|
5495
5864
|
if (trace) {
|
|
5496
5865
|
traces.add(trace);
|
|
5497
5866
|
}
|
|
@@ -5539,7 +5908,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5539
5908
|
}
|
|
5540
5909
|
const now = Date.now();
|
|
5541
5910
|
const elapsedMillis = now - context.buffer.lastFlushedAt;
|
|
5542
|
-
if (elapsedMillis
|
|
5911
|
+
if (elapsedMillis >= config.throttleDelay) {
|
|
5543
5912
|
const messagesToFlush = serializeBuffer();
|
|
5544
5913
|
if (messagesToFlush.length === 0) {
|
|
5545
5914
|
return;
|
|
@@ -5804,7 +6173,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5804
6173
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
5805
6174
|
__internal: {
|
|
5806
6175
|
get presenceBuffer() {
|
|
5807
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
6176
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _143 => _143.buffer, 'access', _144 => _144.presenceUpdates, 'optionalAccess', _145 => _145.data]), () => ( null)));
|
|
5808
6177
|
},
|
|
5809
6178
|
// prettier-ignore
|
|
5810
6179
|
get undoStack() {
|
|
@@ -5946,7 +6315,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5946
6315
|
}
|
|
5947
6316
|
if (isLiveNode(first)) {
|
|
5948
6317
|
const node = first;
|
|
5949
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6318
|
+
if (_optionalChain([options, 'optionalAccess', _146 => _146.isDeep])) {
|
|
5950
6319
|
const storageCallback = second;
|
|
5951
6320
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
5952
6321
|
} else {
|
|
@@ -6071,12 +6440,12 @@ function createClient(options) {
|
|
|
6071
6440
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
6072
6441
|
roomId,
|
|
6073
6442
|
baseUrl,
|
|
6074
|
-
_optionalChain([clientOptions, 'access',
|
|
6443
|
+
_optionalChain([clientOptions, 'access', _147 => _147.polyfills, 'optionalAccess', _148 => _148.WebSocket])
|
|
6075
6444
|
),
|
|
6076
6445
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
6077
6446
|
})),
|
|
6078
6447
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
6079
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
6448
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _149 => _149.unstable_batchedUpdates]),
|
|
6080
6449
|
baseUrl,
|
|
6081
6450
|
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
|
|
6082
6451
|
}
|
|
@@ -6091,7 +6460,7 @@ function createClient(options) {
|
|
|
6091
6460
|
const shouldConnect = _nullishCoalesce(_nullishCoalesce(options2.autoConnect, () => ( options2.shouldInitiallyConnect)), () => ( true));
|
|
6092
6461
|
if (shouldConnect) {
|
|
6093
6462
|
if (typeof atob === "undefined") {
|
|
6094
|
-
if (_optionalChain([clientOptions, 'access',
|
|
6463
|
+
if (_optionalChain([clientOptions, 'access', _150 => _150.polyfills, 'optionalAccess', _151 => _151.atob]) === void 0) {
|
|
6095
6464
|
throw new Error(
|
|
6096
6465
|
"You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
|
|
6097
6466
|
);
|
|
@@ -6107,11 +6476,11 @@ function createClient(options) {
|
|
|
6107
6476
|
return room;
|
|
6108
6477
|
}
|
|
6109
6478
|
function getRoom(roomId) {
|
|
6110
|
-
const room = _optionalChain([roomsById, 'access',
|
|
6479
|
+
const room = _optionalChain([roomsById, 'access', _152 => _152.get, 'call', _153 => _153(roomId), 'optionalAccess', _154 => _154.room]);
|
|
6111
6480
|
return room ? room : null;
|
|
6112
6481
|
}
|
|
6113
6482
|
function forceLeave(roomId) {
|
|
6114
|
-
const unsubs = _nullishCoalesce(_optionalChain([roomsById, 'access',
|
|
6483
|
+
const unsubs = _nullishCoalesce(_optionalChain([roomsById, 'access', _155 => _155.get, 'call', _156 => _156(roomId), 'optionalAccess', _157 => _157.unsubs]), () => ( /* @__PURE__ */ new Set()));
|
|
6115
6484
|
for (const unsub of unsubs) {
|
|
6116
6485
|
unsub();
|
|
6117
6486
|
}
|
|
@@ -6392,12 +6761,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6392
6761
|
}
|
|
6393
6762
|
const newState = Object.assign({}, state);
|
|
6394
6763
|
for (const key in update.updates) {
|
|
6395
|
-
if (_optionalChain([update, 'access',
|
|
6764
|
+
if (_optionalChain([update, 'access', _158 => _158.updates, 'access', _159 => _159[key], 'optionalAccess', _160 => _160.type]) === "update") {
|
|
6396
6765
|
const val = update.node.get(key);
|
|
6397
6766
|
if (val !== void 0) {
|
|
6398
6767
|
newState[key] = lsonToJson(val);
|
|
6399
6768
|
}
|
|
6400
|
-
} else if (_optionalChain([update, 'access',
|
|
6769
|
+
} else if (_optionalChain([update, 'access', _161 => _161.updates, 'access', _162 => _162[key], 'optionalAccess', _163 => _163.type]) === "delete") {
|
|
6401
6770
|
delete newState[key];
|
|
6402
6771
|
}
|
|
6403
6772
|
}
|
|
@@ -6458,12 +6827,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6458
6827
|
}
|
|
6459
6828
|
const newState = Object.assign({}, state);
|
|
6460
6829
|
for (const key in update.updates) {
|
|
6461
|
-
if (_optionalChain([update, 'access',
|
|
6830
|
+
if (_optionalChain([update, 'access', _164 => _164.updates, 'access', _165 => _165[key], 'optionalAccess', _166 => _166.type]) === "update") {
|
|
6462
6831
|
const value = update.node.get(key);
|
|
6463
6832
|
if (value !== void 0) {
|
|
6464
6833
|
newState[key] = lsonToJson(value);
|
|
6465
6834
|
}
|
|
6466
|
-
} else if (_optionalChain([update, 'access',
|
|
6835
|
+
} else if (_optionalChain([update, 'access', _167 => _167.updates, 'access', _168 => _168[key], 'optionalAccess', _169 => _169.type]) === "delete") {
|
|
6467
6836
|
delete newState[key];
|
|
6468
6837
|
}
|
|
6469
6838
|
}
|
|
@@ -6553,7 +6922,7 @@ function createCacheItem(key, asyncFunction, options) {
|
|
|
6553
6922
|
let previousState = { isLoading: false };
|
|
6554
6923
|
const eventSource2 = makeEventSource();
|
|
6555
6924
|
function notify() {
|
|
6556
|
-
const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6925
|
+
const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _170 => _170.isStateEqual]), () => ( isShallowEqual));
|
|
6557
6926
|
if (!isEqual(previousState, state)) {
|
|
6558
6927
|
previousState = state;
|
|
6559
6928
|
eventSource2.notify(state);
|
|
@@ -6621,7 +6990,7 @@ function createAsyncCache(asyncFunction, options) {
|
|
|
6621
6990
|
return create(key).get();
|
|
6622
6991
|
}
|
|
6623
6992
|
function getState(key) {
|
|
6624
|
-
return _optionalChain([cache, 'access',
|
|
6993
|
+
return _optionalChain([cache, 'access', _171 => _171.get, 'call', _172 => _172(key), 'optionalAccess', _173 => _173.getState, 'call', _174 => _174()]);
|
|
6625
6994
|
}
|
|
6626
6995
|
function revalidate(key) {
|
|
6627
6996
|
return create(key).revalidate();
|
|
@@ -6801,5 +7170,11 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
6801
7170
|
|
|
6802
7171
|
|
|
6803
7172
|
|
|
6804
|
-
|
|
7173
|
+
|
|
7174
|
+
|
|
7175
|
+
|
|
7176
|
+
|
|
7177
|
+
|
|
7178
|
+
|
|
7179
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.cloneLson = cloneLson; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToThreadData = convertToThreadData; exports.createAsyncCache = createAsyncCache; exports.createClient = createClient; exports.createCommentsApi = createCommentsApi; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.shallow = shallow; exports.stringify = stringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
|
6805
7180
|
//# sourceMappingURL=index.js.map
|