@liveblocks/client 0.18.3 → 0.18.5
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.ts +15 -0
- package/dist/index.js +15 -0
- package/{index.mjs → dist/index.mjs} +0 -0
- package/package.json +28 -16
- package/.built-by-link-script +0 -1
- package/LICENSE +0 -201
- package/chunk-UV2F4F4R.js +0 -2457
- package/index-2601cea5.d.ts +0 -869
- package/index.d.ts +0 -54
- package/index.js +0 -1622
- package/internal.d.ts +0 -445
- package/internal.js +0 -370
- package/internal.mjs +0 -33
package/internal.js
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _chunkUV2F4F4Rjs = require('./chunk-UV2F4F4R.js');
|
|
39
|
-
|
|
40
|
-
// src/immutable.ts
|
|
41
|
-
function lsonObjectToJson(obj) {
|
|
42
|
-
const result = {};
|
|
43
|
-
for (const key in obj) {
|
|
44
|
-
const val = obj[key];
|
|
45
|
-
if (val !== void 0) {
|
|
46
|
-
result[key] = lsonToJson(val);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
function liveObjectToJson(liveObject) {
|
|
52
|
-
return lsonObjectToJson(liveObject.toObject());
|
|
53
|
-
}
|
|
54
|
-
function liveMapToJson(map) {
|
|
55
|
-
const result = {};
|
|
56
|
-
for (const [key, value] of map.entries()) {
|
|
57
|
-
result[key] = lsonToJson(value);
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
function lsonListToJson(value) {
|
|
62
|
-
return value.map(lsonToJson);
|
|
63
|
-
}
|
|
64
|
-
function liveListToJson(value) {
|
|
65
|
-
return lsonListToJson(value.toArray());
|
|
66
|
-
}
|
|
67
|
-
function lsonToJson(value) {
|
|
68
|
-
if (value instanceof _chunkUV2F4F4Rjs.LiveObject) {
|
|
69
|
-
return liveObjectToJson(value);
|
|
70
|
-
} else if (value instanceof _chunkUV2F4F4Rjs.LiveList) {
|
|
71
|
-
return liveListToJson(value);
|
|
72
|
-
} else if (value instanceof _chunkUV2F4F4Rjs.LiveMap) {
|
|
73
|
-
return liveMapToJson(value);
|
|
74
|
-
} else if (value instanceof _chunkUV2F4F4Rjs.LiveRegister) {
|
|
75
|
-
return value.data;
|
|
76
|
-
}
|
|
77
|
-
if (Array.isArray(value)) {
|
|
78
|
-
return lsonListToJson(value);
|
|
79
|
-
} else if (_chunkUV2F4F4Rjs.isPlainObject.call(void 0, value)) {
|
|
80
|
-
return lsonObjectToJson(value);
|
|
81
|
-
}
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
function deepLiveify(value) {
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
return new (0, _chunkUV2F4F4Rjs.LiveList)(value.map(deepLiveify));
|
|
87
|
-
} else if (_chunkUV2F4F4Rjs.isPlainObject.call(void 0, value)) {
|
|
88
|
-
const init = {};
|
|
89
|
-
for (const key in value) {
|
|
90
|
-
const val = value[key];
|
|
91
|
-
if (val === void 0) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
init[key] = deepLiveify(val);
|
|
95
|
-
}
|
|
96
|
-
return new (0, _chunkUV2F4F4Rjs.LiveObject)(init);
|
|
97
|
-
} else {
|
|
98
|
-
return value;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function patchLiveList(liveList, prev, next) {
|
|
102
|
-
let i = 0;
|
|
103
|
-
let prevEnd = prev.length - 1;
|
|
104
|
-
let nextEnd = next.length - 1;
|
|
105
|
-
let prevNode = prev[0];
|
|
106
|
-
let nextNode = next[0];
|
|
107
|
-
outer: {
|
|
108
|
-
while (prevNode === nextNode) {
|
|
109
|
-
++i;
|
|
110
|
-
if (i > prevEnd || i > nextEnd) {
|
|
111
|
-
break outer;
|
|
112
|
-
}
|
|
113
|
-
prevNode = prev[i];
|
|
114
|
-
nextNode = next[i];
|
|
115
|
-
}
|
|
116
|
-
prevNode = prev[prevEnd];
|
|
117
|
-
nextNode = next[nextEnd];
|
|
118
|
-
while (prevNode === nextNode) {
|
|
119
|
-
prevEnd--;
|
|
120
|
-
nextEnd--;
|
|
121
|
-
if (i > prevEnd || i > nextEnd) {
|
|
122
|
-
break outer;
|
|
123
|
-
}
|
|
124
|
-
prevNode = prev[prevEnd];
|
|
125
|
-
nextNode = next[nextEnd];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (i > prevEnd) {
|
|
129
|
-
if (i <= nextEnd) {
|
|
130
|
-
while (i <= nextEnd) {
|
|
131
|
-
liveList.insert(deepLiveify(next[i]), i);
|
|
132
|
-
i++;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
} else if (i > nextEnd) {
|
|
136
|
-
let localI = i;
|
|
137
|
-
while (localI <= prevEnd) {
|
|
138
|
-
liveList.delete(i);
|
|
139
|
-
localI++;
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
while (i <= prevEnd && i <= nextEnd) {
|
|
143
|
-
prevNode = prev[i];
|
|
144
|
-
nextNode = next[i];
|
|
145
|
-
const liveListNode = liveList.get(i);
|
|
146
|
-
if (_chunkUV2F4F4Rjs.isLiveObject.call(void 0, liveListNode) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, prevNode) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, nextNode)) {
|
|
147
|
-
patchLiveObject(liveListNode, prevNode, nextNode);
|
|
148
|
-
} else {
|
|
149
|
-
liveList.set(i, deepLiveify(nextNode));
|
|
150
|
-
}
|
|
151
|
-
i++;
|
|
152
|
-
}
|
|
153
|
-
while (i <= nextEnd) {
|
|
154
|
-
liveList.insert(deepLiveify(next[i]), i);
|
|
155
|
-
i++;
|
|
156
|
-
}
|
|
157
|
-
let localI = i;
|
|
158
|
-
while (localI <= prevEnd) {
|
|
159
|
-
liveList.delete(i);
|
|
160
|
-
localI++;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function patchLiveObjectKey(liveObject, key, prev, next) {
|
|
165
|
-
if (process.env.NODE_ENV !== "production") {
|
|
166
|
-
const nonSerializableValue = _chunkUV2F4F4Rjs.findNonSerializableValue.call(void 0, next);
|
|
167
|
-
if (nonSerializableValue) {
|
|
168
|
-
console.error(
|
|
169
|
-
`New state path: '${nonSerializableValue.path}' value: '${nonSerializableValue.value}' is not serializable.
|
|
170
|
-
Only serializable value can be synced with Liveblocks.`
|
|
171
|
-
);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const value = liveObject.get(key);
|
|
176
|
-
if (next === void 0) {
|
|
177
|
-
liveObject.delete(key);
|
|
178
|
-
} else if (value === void 0) {
|
|
179
|
-
liveObject.set(key, deepLiveify(next));
|
|
180
|
-
} else if (prev === next) {
|
|
181
|
-
return;
|
|
182
|
-
} else if (_chunkUV2F4F4Rjs.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) {
|
|
183
|
-
patchLiveList(value, prev, next);
|
|
184
|
-
} else if (_chunkUV2F4F4Rjs.isLiveObject.call(void 0, value) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, prev) && _chunkUV2F4F4Rjs.isPlainObject.call(void 0, next)) {
|
|
185
|
-
patchLiveObject(value, prev, next);
|
|
186
|
-
} else {
|
|
187
|
-
liveObject.set(key, deepLiveify(next));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function patchLiveObject(root, prev, next) {
|
|
191
|
-
const updates = {};
|
|
192
|
-
for (const key in next) {
|
|
193
|
-
patchLiveObjectKey(root, key, prev[key], next[key]);
|
|
194
|
-
}
|
|
195
|
-
for (const key in prev) {
|
|
196
|
-
if (next[key] === void 0) {
|
|
197
|
-
root.delete(key);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (Object.keys(updates).length > 0) {
|
|
201
|
-
root.update(updates);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function getParentsPath(node) {
|
|
205
|
-
const path = [];
|
|
206
|
-
while (node.parent.type === "HasParent") {
|
|
207
|
-
if (_chunkUV2F4F4Rjs.isLiveList.call(void 0, node.parent.node)) {
|
|
208
|
-
path.push(node.parent.node._indexOfPosition(node.parent.key));
|
|
209
|
-
} else {
|
|
210
|
-
path.push(node.parent.key);
|
|
211
|
-
}
|
|
212
|
-
node = node.parent.node;
|
|
213
|
-
}
|
|
214
|
-
return path;
|
|
215
|
-
}
|
|
216
|
-
function legacy_patchImmutableObject(state, updates) {
|
|
217
|
-
return updates.reduce(
|
|
218
|
-
(state2, update) => legacy_patchImmutableObjectWithUpdate(state2, update),
|
|
219
|
-
state
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
function legacy_patchImmutableObjectWithUpdate(state, update) {
|
|
223
|
-
const path = getParentsPath(update.node);
|
|
224
|
-
return legacy_patchImmutableNode(state, path, update);
|
|
225
|
-
}
|
|
226
|
-
function legacy_patchImmutableNode(state, path, update) {
|
|
227
|
-
var _a, _b, _c, _d;
|
|
228
|
-
const pathItem = path.pop();
|
|
229
|
-
if (pathItem === void 0) {
|
|
230
|
-
switch (update.type) {
|
|
231
|
-
case "LiveObject": {
|
|
232
|
-
if (state === null || typeof state !== "object" || Array.isArray(state)) {
|
|
233
|
-
throw new Error(
|
|
234
|
-
"Internal: received update on LiveObject but state was not an object"
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
const newState = Object.assign({}, state);
|
|
238
|
-
for (const key in update.updates) {
|
|
239
|
-
if (((_a = update.updates[key]) == null ? void 0 : _a.type) === "update") {
|
|
240
|
-
const val = update.node.get(key);
|
|
241
|
-
if (val !== void 0) {
|
|
242
|
-
newState[key] = lsonToJson(val);
|
|
243
|
-
}
|
|
244
|
-
} else if (((_b = update.updates[key]) == null ? void 0 : _b.type) === "delete") {
|
|
245
|
-
delete newState[key];
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return newState;
|
|
249
|
-
}
|
|
250
|
-
case "LiveList": {
|
|
251
|
-
if (!Array.isArray(state)) {
|
|
252
|
-
throw new Error(
|
|
253
|
-
"Internal: received update on LiveList but state was not an array"
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
let newState = state.map((x) => x);
|
|
257
|
-
for (const listUpdate of update.updates) {
|
|
258
|
-
if (listUpdate.type === "set") {
|
|
259
|
-
newState = newState.map(
|
|
260
|
-
(item, index) => index === listUpdate.index ? lsonToJson(listUpdate.item) : item
|
|
261
|
-
);
|
|
262
|
-
} else if (listUpdate.type === "insert") {
|
|
263
|
-
if (listUpdate.index === newState.length) {
|
|
264
|
-
newState.push(lsonToJson(listUpdate.item));
|
|
265
|
-
} else {
|
|
266
|
-
newState = [
|
|
267
|
-
...newState.slice(0, listUpdate.index),
|
|
268
|
-
lsonToJson(listUpdate.item),
|
|
269
|
-
...newState.slice(listUpdate.index)
|
|
270
|
-
];
|
|
271
|
-
}
|
|
272
|
-
} else if (listUpdate.type === "delete") {
|
|
273
|
-
newState.splice(listUpdate.index, 1);
|
|
274
|
-
} else if (listUpdate.type === "move") {
|
|
275
|
-
if (listUpdate.previousIndex > listUpdate.index) {
|
|
276
|
-
newState = [
|
|
277
|
-
...newState.slice(0, listUpdate.index),
|
|
278
|
-
lsonToJson(listUpdate.item),
|
|
279
|
-
...newState.slice(listUpdate.index, listUpdate.previousIndex),
|
|
280
|
-
...newState.slice(listUpdate.previousIndex + 1)
|
|
281
|
-
];
|
|
282
|
-
} else {
|
|
283
|
-
newState = [
|
|
284
|
-
...newState.slice(0, listUpdate.previousIndex),
|
|
285
|
-
...newState.slice(
|
|
286
|
-
listUpdate.previousIndex + 1,
|
|
287
|
-
listUpdate.index + 1
|
|
288
|
-
),
|
|
289
|
-
lsonToJson(listUpdate.item),
|
|
290
|
-
...newState.slice(listUpdate.index + 1)
|
|
291
|
-
];
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return newState;
|
|
296
|
-
}
|
|
297
|
-
case "LiveMap": {
|
|
298
|
-
if (state === null || typeof state !== "object" || Array.isArray(state)) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
"Internal: received update on LiveMap but state was not an object"
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
const newState = Object.assign({}, state);
|
|
304
|
-
for (const key in update.updates) {
|
|
305
|
-
if (((_c = update.updates[key]) == null ? void 0 : _c.type) === "update") {
|
|
306
|
-
const value = update.node.get(key);
|
|
307
|
-
if (value !== void 0) {
|
|
308
|
-
newState[key] = lsonToJson(value);
|
|
309
|
-
}
|
|
310
|
-
} else if (((_d = update.updates[key]) == null ? void 0 : _d.type) === "delete") {
|
|
311
|
-
delete newState[key];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return newState;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (Array.isArray(state)) {
|
|
319
|
-
const newArray = [...state];
|
|
320
|
-
newArray[pathItem] = legacy_patchImmutableNode(
|
|
321
|
-
state[pathItem],
|
|
322
|
-
path,
|
|
323
|
-
update
|
|
324
|
-
);
|
|
325
|
-
return newArray;
|
|
326
|
-
} else if (state !== null && typeof state === "object") {
|
|
327
|
-
const node = state[pathItem];
|
|
328
|
-
if (node === void 0) {
|
|
329
|
-
return state;
|
|
330
|
-
} else {
|
|
331
|
-
return _chunkUV2F4F4Rjs.__spreadProps.call(void 0, _chunkUV2F4F4Rjs.__spreadValues.call(void 0, {}, state), {
|
|
332
|
-
[pathItem]: legacy_patchImmutableNode(node, path, update)
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
return state;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
exports.ClientMsgCode = _chunkUV2F4F4Rjs.ClientMsgCode; exports.CrdtType = _chunkUV2F4F4Rjs.CrdtType; exports.OpCode = _chunkUV2F4F4Rjs.OpCode; exports.ServerMsgCode = _chunkUV2F4F4Rjs.ServerMsgCode; exports.WebsocketCloseCodes = _chunkUV2F4F4Rjs.WebsocketCloseCodes; exports.asArrayWithLegacyMethods = _chunkUV2F4F4Rjs.asArrayWithLegacyMethods; exports.assertNever = _chunkUV2F4F4Rjs.assertNever; exports.b64decode = _chunkUV2F4F4Rjs.b64decode; exports.comparePosition = _chunkUV2F4F4Rjs.comparePosition; exports.deprecate = _chunkUV2F4F4Rjs.deprecate; exports.deprecateIf = _chunkUV2F4F4Rjs.deprecateIf; exports.errorIf = _chunkUV2F4F4Rjs.errorIf; exports.freeze = _chunkUV2F4F4Rjs.freeze; exports.isAppOnlyAuthToken = _chunkUV2F4F4Rjs.isAppOnlyAuthToken; exports.isAuthToken = _chunkUV2F4F4Rjs.isAuthToken; exports.isChildCrdt = _chunkUV2F4F4Rjs.isChildCrdt; exports.isJsonArray = _chunkUV2F4F4Rjs.isJsonArray; exports.isJsonObject = _chunkUV2F4F4Rjs.isJsonObject; exports.isJsonScalar = _chunkUV2F4F4Rjs.isJsonScalar; exports.isPlainObject = _chunkUV2F4F4Rjs.isPlainObject; exports.isRoomAuthToken = _chunkUV2F4F4Rjs.isRoomAuthToken; exports.isRootCrdt = _chunkUV2F4F4Rjs.isRootCrdt; exports.isScope = _chunkUV2F4F4Rjs.isScope; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = _chunkUV2F4F4Rjs.makePosition; exports.nn = _chunkUV2F4F4Rjs.nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.throwUsageError = _chunkUV2F4F4Rjs.throwUsageError; exports.tryParseJson = _chunkUV2F4F4Rjs.tryParseJson;
|
package/internal.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import mod from "./internal.js";
|
|
2
|
-
|
|
3
|
-
export default mod;
|
|
4
|
-
export const ClientMsgCode = mod.ClientMsgCode;
|
|
5
|
-
export const CrdtType = mod.CrdtType;
|
|
6
|
-
export const OpCode = mod.OpCode;
|
|
7
|
-
export const ServerMsgCode = mod.ServerMsgCode;
|
|
8
|
-
export const WebsocketCloseCodes = mod.WebsocketCloseCodes;
|
|
9
|
-
export const asArrayWithLegacyMethods = mod.asArrayWithLegacyMethods;
|
|
10
|
-
export const assertNever = mod.assertNever;
|
|
11
|
-
export const b64decode = mod.b64decode;
|
|
12
|
-
export const comparePosition = mod.comparePosition;
|
|
13
|
-
export const deprecate = mod.deprecate;
|
|
14
|
-
export const deprecateIf = mod.deprecateIf;
|
|
15
|
-
export const errorIf = mod.errorIf;
|
|
16
|
-
export const freeze = mod.freeze;
|
|
17
|
-
export const isAppOnlyAuthToken = mod.isAppOnlyAuthToken;
|
|
18
|
-
export const isAuthToken = mod.isAuthToken;
|
|
19
|
-
export const isChildCrdt = mod.isChildCrdt;
|
|
20
|
-
export const isJsonArray = mod.isJsonArray;
|
|
21
|
-
export const isJsonObject = mod.isJsonObject;
|
|
22
|
-
export const isJsonScalar = mod.isJsonScalar;
|
|
23
|
-
export const isPlainObject = mod.isPlainObject;
|
|
24
|
-
export const isRoomAuthToken = mod.isRoomAuthToken;
|
|
25
|
-
export const isRootCrdt = mod.isRootCrdt;
|
|
26
|
-
export const isScope = mod.isScope;
|
|
27
|
-
export const legacy_patchImmutableObject = mod.legacy_patchImmutableObject;
|
|
28
|
-
export const lsonToJson = mod.lsonToJson;
|
|
29
|
-
export const makePosition = mod.makePosition;
|
|
30
|
-
export const nn = mod.nn;
|
|
31
|
-
export const patchLiveObjectKey = mod.patchLiveObjectKey;
|
|
32
|
-
export const throwUsageError = mod.throwUsageError;
|
|
33
|
-
export const tryParseJson = mod.tryParseJson;
|