@inkandswitch/patchwork-pkg-base 0.0.38 → 0.0.39
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/package.json +1 -1
- package/packages/drafts/dist/assets/{DraftListProvider-D3dHIGmO.js → DraftListProvider-D41q9O5B.js} +3 -2
- package/packages/drafts/dist/assets/{DraftListProvider-D3dHIGmO.js.map → DraftListProvider-D41q9O5B.js.map} +1 -1
- package/packages/drafts/dist/assets/{DraftOverlayProvider-Cae4SJD7.js → DraftOverlayProvider-B0Mtq1UF.js} +3 -2
- package/packages/drafts/dist/assets/{DraftOverlayProvider-Cae4SJD7.js.map → DraftOverlayProvider-B0Mtq1UF.js.map} +1 -1
- package/packages/drafts/dist/assets/{index-DAqs20jZ.js → index-FKZtof6Z.js} +6 -4
- package/packages/drafts/dist/assets/index-FKZtof6Z.js.map +1 -0
- package/packages/drafts/dist/assets/{main-9LQJEnZS.js → main-Cp8VsNHh.js} +22 -1197
- package/packages/drafts/dist/assets/main-Cp8VsNHh.js.map +1 -0
- package/packages/drafts/dist/index.js +5 -5
- package/packages/drafts/package.json +11 -11
- package/packages/sync-indicator/dist/assets/SyncIndicator-DxVkpuKE.js.map +1 -1
- package/packages/tldraw4/dist/tool.js +2 -2
- package/packages/tldraw4/dist/tool.js.map +1 -1
- package/packages/tldraw5/dist/tool.js +2 -2
- package/packages/tldraw5/dist/tool.js.map +1 -1
- package/packages/drafts/dist/assets/index-DAqs20jZ.js.map +0 -1
- package/packages/drafts/dist/assets/main-9LQJEnZS.js.map +0 -1
|
@@ -563,12 +563,13 @@
|
|
|
563
563
|
}
|
|
564
564
|
})();
|
|
565
565
|
import { insert, createComponent, effect, setAttribute, memo, template, addEventListener, use, setStyleProperty, delegateEvents, render } from "solid-js/web";
|
|
566
|
-
import { createContext, createSignal, createEffect, onCleanup,
|
|
567
|
-
import { createStore,
|
|
566
|
+
import { createContext, createSignal, createEffect, onCleanup, onMount, createMemo, Show, For } from "solid-js";
|
|
567
|
+
import { createStore, reconcile } from "solid-js/store";
|
|
568
568
|
import { decodeHeads, encodeHeads } from "@automerge/automerge-repo/slim";
|
|
569
569
|
import * as Automerge from "@automerge/automerge/slim";
|
|
570
570
|
import { getRegistry, isLoadedPlugin } from "@inkandswitch/patchwork-plugins";
|
|
571
|
-
import { s as subscribe$1 } from "./index-
|
|
571
|
+
import { s as subscribe$1 } from "./index-FKZtof6Z.js";
|
|
572
|
+
import "@automerge/automerge-repo";
|
|
572
573
|
function getDefaultExportFromCjs(x) {
|
|
573
574
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
574
575
|
}
|
|
@@ -1062,1198 +1063,6 @@ function createDocSignal(handle) {
|
|
|
1062
1063
|
});
|
|
1063
1064
|
return signal;
|
|
1064
1065
|
}
|
|
1065
|
-
const STATE = /* @__PURE__ */ Symbol.for("_am_meta");
|
|
1066
|
-
const TRACE = /* @__PURE__ */ Symbol.for("_am_trace");
|
|
1067
|
-
const OBJECT_ID = /* @__PURE__ */ Symbol.for("_am_objectId");
|
|
1068
|
-
const IS_PROXY = /* @__PURE__ */ Symbol.for("_am_isProxy");
|
|
1069
|
-
const CLEAR_CACHE = /* @__PURE__ */ Symbol.for("_am_clearCache");
|
|
1070
|
-
const UINT = /* @__PURE__ */ Symbol.for("_am_uint");
|
|
1071
|
-
const INT = /* @__PURE__ */ Symbol.for("_am_int");
|
|
1072
|
-
const F64 = /* @__PURE__ */ Symbol.for("_am_f64");
|
|
1073
|
-
const COUNTER = /* @__PURE__ */ Symbol.for("_am_counter");
|
|
1074
|
-
const IMMUTABLE_STRING = /* @__PURE__ */ Symbol.for("_am_immutableString");
|
|
1075
|
-
class Counter {
|
|
1076
|
-
constructor(value) {
|
|
1077
|
-
this.value = value || 0;
|
|
1078
|
-
Reflect.defineProperty(this, COUNTER, { value: true });
|
|
1079
|
-
}
|
|
1080
|
-
/**
|
|
1081
|
-
* A peculiar JavaScript language feature from its early days: if the object
|
|
1082
|
-
* `x` has a `valueOf()` method that returns a number, you can use numerical
|
|
1083
|
-
* operators on the object `x` directly, such as `x + 1` or `x < 4`.
|
|
1084
|
-
* This method is also called when coercing a value to a string by
|
|
1085
|
-
* concatenating it with another string, as in `x + ''`.
|
|
1086
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf
|
|
1087
|
-
*/
|
|
1088
|
-
valueOf() {
|
|
1089
|
-
return this.value;
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Returns the counter value as a decimal string. If `x` is a counter object,
|
|
1093
|
-
* this method is called e.g. when you do `['value: ', x].join('')` or when
|
|
1094
|
-
* you use string interpolation: `value: ${x}`.
|
|
1095
|
-
*/
|
|
1096
|
-
toString() {
|
|
1097
|
-
return this.valueOf().toString();
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Returns the counter value, so that a JSON serialization of an Automerge
|
|
1101
|
-
* document represents the counter simply as an integer.
|
|
1102
|
-
*/
|
|
1103
|
-
toJSON() {
|
|
1104
|
-
return this.value;
|
|
1105
|
-
}
|
|
1106
|
-
/**
|
|
1107
|
-
* Increases the value of the counter by `delta`. If `delta` is not given,
|
|
1108
|
-
* increases the value of the counter by 1.
|
|
1109
|
-
*
|
|
1110
|
-
* Will throw an error if used outside of a change callback.
|
|
1111
|
-
*/
|
|
1112
|
-
increment(_delta) {
|
|
1113
|
-
throw new Error("Counters should not be incremented outside of a change callback");
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Decreases the value of the counter by `delta`. If `delta` is not given,
|
|
1117
|
-
* decreases the value of the counter by 1.
|
|
1118
|
-
*
|
|
1119
|
-
* Will throw an error if used outside of a change callback.
|
|
1120
|
-
*/
|
|
1121
|
-
decrement(_delta) {
|
|
1122
|
-
throw new Error("Counters should not be decremented outside of a change callback");
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
class WriteableCounter extends Counter {
|
|
1126
|
-
constructor(value, context, path, objectId, key) {
|
|
1127
|
-
super(value);
|
|
1128
|
-
this.context = context;
|
|
1129
|
-
this.path = path;
|
|
1130
|
-
this.objectId = objectId;
|
|
1131
|
-
this.key = key;
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Increases the value of the counter by `delta`. If `delta` is not given,
|
|
1135
|
-
* increases the value of the counter by 1.
|
|
1136
|
-
*/
|
|
1137
|
-
increment(delta) {
|
|
1138
|
-
delta = typeof delta === "number" ? delta : 1;
|
|
1139
|
-
this.context.increment(this.objectId, this.key, delta);
|
|
1140
|
-
this.value += delta;
|
|
1141
|
-
return this.value;
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Decreases the value of the counter by `delta`. If `delta` is not given,
|
|
1145
|
-
* decreases the value of the counter by 1.
|
|
1146
|
-
*/
|
|
1147
|
-
decrement(delta) {
|
|
1148
|
-
return this.increment(typeof delta === "number" ? -delta : -1);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
function getWriteableCounter(value, context, path, objectId, key) {
|
|
1152
|
-
return new WriteableCounter(value, context, path, objectId, key);
|
|
1153
|
-
}
|
|
1154
|
-
var _a;
|
|
1155
|
-
class ImmutableString {
|
|
1156
|
-
constructor(val) {
|
|
1157
|
-
this[_a] = true;
|
|
1158
|
-
this.val = val;
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Returns the content of the ImmutableString object as a simple string
|
|
1162
|
-
*/
|
|
1163
|
-
toString() {
|
|
1164
|
-
return this.val;
|
|
1165
|
-
}
|
|
1166
|
-
toJSON() {
|
|
1167
|
-
return this.val;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
_a = IMMUTABLE_STRING;
|
|
1171
|
-
function parseListIndex(key) {
|
|
1172
|
-
if (typeof key === "string" && /^[0-9]+$/.test(key))
|
|
1173
|
-
key = parseInt(key, 10);
|
|
1174
|
-
if (typeof key !== "number") {
|
|
1175
|
-
return key;
|
|
1176
|
-
}
|
|
1177
|
-
if (key < 0 || isNaN(key) || key === Infinity || key === -Infinity) {
|
|
1178
|
-
throw new RangeError("A list index must be positive, but you passed " + key);
|
|
1179
|
-
}
|
|
1180
|
-
return key;
|
|
1181
|
-
}
|
|
1182
|
-
function valueAt(target, prop) {
|
|
1183
|
-
const { context, objectId, path } = target;
|
|
1184
|
-
const value = context.getWithType(objectId, prop);
|
|
1185
|
-
if (value === null) {
|
|
1186
|
-
return;
|
|
1187
|
-
}
|
|
1188
|
-
const datatype = value[0];
|
|
1189
|
-
const val = value[1];
|
|
1190
|
-
switch (datatype) {
|
|
1191
|
-
case void 0:
|
|
1192
|
-
return;
|
|
1193
|
-
case "map":
|
|
1194
|
-
return mapProxy(context, val, [...path, prop]);
|
|
1195
|
-
case "list":
|
|
1196
|
-
return listProxy(context, val, [...path, prop]);
|
|
1197
|
-
case "text":
|
|
1198
|
-
return context.text(val);
|
|
1199
|
-
case "str":
|
|
1200
|
-
return new ImmutableString(val);
|
|
1201
|
-
case "uint":
|
|
1202
|
-
return val;
|
|
1203
|
-
case "int":
|
|
1204
|
-
return val;
|
|
1205
|
-
case "f64":
|
|
1206
|
-
return val;
|
|
1207
|
-
case "boolean":
|
|
1208
|
-
return val;
|
|
1209
|
-
case "null":
|
|
1210
|
-
return null;
|
|
1211
|
-
case "bytes":
|
|
1212
|
-
return val;
|
|
1213
|
-
case "timestamp":
|
|
1214
|
-
return val;
|
|
1215
|
-
case "counter": {
|
|
1216
|
-
const counter = getWriteableCounter(val, context, path, objectId, prop);
|
|
1217
|
-
return counter;
|
|
1218
|
-
}
|
|
1219
|
-
default:
|
|
1220
|
-
throw RangeError(`datatype ${datatype} unimplemented`);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
function import_value(value, path, context) {
|
|
1224
|
-
const type = typeof value;
|
|
1225
|
-
switch (type) {
|
|
1226
|
-
case "object":
|
|
1227
|
-
if (value == null) {
|
|
1228
|
-
return [null, "null"];
|
|
1229
|
-
} else if (value[UINT]) {
|
|
1230
|
-
return [value.value, "uint"];
|
|
1231
|
-
} else if (value[INT]) {
|
|
1232
|
-
return [value.value, "int"];
|
|
1233
|
-
} else if (value[F64]) {
|
|
1234
|
-
return [value.value, "f64"];
|
|
1235
|
-
} else if (value[COUNTER]) {
|
|
1236
|
-
return [value.value, "counter"];
|
|
1237
|
-
} else if (value instanceof Date) {
|
|
1238
|
-
return [value.getTime(), "timestamp"];
|
|
1239
|
-
} else if (isImmutableString(value)) {
|
|
1240
|
-
return [value.toString(), "str"];
|
|
1241
|
-
} else if (value instanceof Uint8Array) {
|
|
1242
|
-
return [value, "bytes"];
|
|
1243
|
-
} else if (value instanceof Array) {
|
|
1244
|
-
return [value, "list"];
|
|
1245
|
-
} else if (Object.prototype.toString.call(value) === "[object Object]") {
|
|
1246
|
-
return [value, "map"];
|
|
1247
|
-
} else if (isSameDocument(value, context)) {
|
|
1248
|
-
throw new RangeError("Cannot create a reference to an existing document object");
|
|
1249
|
-
} else {
|
|
1250
|
-
throw new RangeError(`Cannot assign unknown object: ${value}`);
|
|
1251
|
-
}
|
|
1252
|
-
case "boolean":
|
|
1253
|
-
return [value, "boolean"];
|
|
1254
|
-
case "number":
|
|
1255
|
-
if (Number.isInteger(value)) {
|
|
1256
|
-
return [value, "int"];
|
|
1257
|
-
} else {
|
|
1258
|
-
return [value, "f64"];
|
|
1259
|
-
}
|
|
1260
|
-
case "string":
|
|
1261
|
-
return [value, "text"];
|
|
1262
|
-
case "undefined":
|
|
1263
|
-
throw new RangeError([
|
|
1264
|
-
`Cannot assign undefined value at ${printPath(path)}, `,
|
|
1265
|
-
"because `undefined` is not a valid JSON data type. ",
|
|
1266
|
-
"You might consider setting the property's value to `null`, ",
|
|
1267
|
-
"or using `delete` to remove it altogether."
|
|
1268
|
-
].join(""));
|
|
1269
|
-
default:
|
|
1270
|
-
throw new RangeError([
|
|
1271
|
-
`Cannot assign ${type} value at ${printPath(path)}. `,
|
|
1272
|
-
`All JSON primitive datatypes (object, array, string, number, boolean, null) `,
|
|
1273
|
-
`are supported in an Automerge document; ${type} values are not. `
|
|
1274
|
-
].join(""));
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
function isSameDocument(val, context) {
|
|
1278
|
-
var _b, _c;
|
|
1279
|
-
if (val instanceof Date) {
|
|
1280
|
-
return false;
|
|
1281
|
-
}
|
|
1282
|
-
if (val && ((_c = (_b = val[STATE]) === null || _b === void 0 ? void 0 : _b.handle) === null || _c === void 0 ? void 0 : _c.__wbg_ptr) === context.__wbg_ptr) {
|
|
1283
|
-
return true;
|
|
1284
|
-
}
|
|
1285
|
-
return false;
|
|
1286
|
-
}
|
|
1287
|
-
const MapHandler = {
|
|
1288
|
-
get(target, key) {
|
|
1289
|
-
const { context, objectId, cache: cache2 } = target;
|
|
1290
|
-
if (key === Symbol.toStringTag) {
|
|
1291
|
-
return target[Symbol.toStringTag];
|
|
1292
|
-
}
|
|
1293
|
-
if (key === OBJECT_ID)
|
|
1294
|
-
return objectId;
|
|
1295
|
-
if (key === IS_PROXY)
|
|
1296
|
-
return true;
|
|
1297
|
-
if (key === TRACE)
|
|
1298
|
-
return target.trace;
|
|
1299
|
-
if (key === STATE)
|
|
1300
|
-
return { handle: context };
|
|
1301
|
-
if (!cache2[key]) {
|
|
1302
|
-
cache2[key] = valueAt(target, key);
|
|
1303
|
-
}
|
|
1304
|
-
return cache2[key];
|
|
1305
|
-
},
|
|
1306
|
-
set(target, key, val) {
|
|
1307
|
-
const { context, objectId, path } = target;
|
|
1308
|
-
target.cache = {};
|
|
1309
|
-
if (isSameDocument(val, context)) {
|
|
1310
|
-
throw new RangeError("Cannot create a reference to an existing document object");
|
|
1311
|
-
}
|
|
1312
|
-
if (key === TRACE) {
|
|
1313
|
-
target.trace = val;
|
|
1314
|
-
return true;
|
|
1315
|
-
}
|
|
1316
|
-
if (key === CLEAR_CACHE) {
|
|
1317
|
-
return true;
|
|
1318
|
-
}
|
|
1319
|
-
const [value, datatype] = import_value(val, [...path, key], context);
|
|
1320
|
-
switch (datatype) {
|
|
1321
|
-
case "list": {
|
|
1322
|
-
const list = context.putObject(objectId, key, []);
|
|
1323
|
-
const proxyList = listProxy(context, list, [...path, key]);
|
|
1324
|
-
for (let i = 0; i < value.length; i++) {
|
|
1325
|
-
proxyList[i] = value[i];
|
|
1326
|
-
}
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
case "text": {
|
|
1330
|
-
context.putObject(objectId, key, value);
|
|
1331
|
-
break;
|
|
1332
|
-
}
|
|
1333
|
-
case "map": {
|
|
1334
|
-
const map = context.putObject(objectId, key, {});
|
|
1335
|
-
const proxyMap = mapProxy(context, map, [...path, key]);
|
|
1336
|
-
for (const key2 in value) {
|
|
1337
|
-
proxyMap[key2] = value[key2];
|
|
1338
|
-
}
|
|
1339
|
-
break;
|
|
1340
|
-
}
|
|
1341
|
-
default:
|
|
1342
|
-
context.put(objectId, key, value, datatype);
|
|
1343
|
-
}
|
|
1344
|
-
return true;
|
|
1345
|
-
},
|
|
1346
|
-
deleteProperty(target, key) {
|
|
1347
|
-
const { context, objectId } = target;
|
|
1348
|
-
target.cache = {};
|
|
1349
|
-
context.delete(objectId, key);
|
|
1350
|
-
return true;
|
|
1351
|
-
},
|
|
1352
|
-
has(target, key) {
|
|
1353
|
-
const value = this.get(target, key);
|
|
1354
|
-
return value !== void 0;
|
|
1355
|
-
},
|
|
1356
|
-
getOwnPropertyDescriptor(target, key) {
|
|
1357
|
-
const value = this.get(target, key);
|
|
1358
|
-
if (typeof value !== "undefined") {
|
|
1359
|
-
return {
|
|
1360
|
-
configurable: true,
|
|
1361
|
-
enumerable: true,
|
|
1362
|
-
value
|
|
1363
|
-
};
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
ownKeys(target) {
|
|
1367
|
-
const { context, objectId } = target;
|
|
1368
|
-
const keys = context.keys(objectId);
|
|
1369
|
-
return [...new Set(keys)];
|
|
1370
|
-
}
|
|
1371
|
-
};
|
|
1372
|
-
const ListHandler = {
|
|
1373
|
-
get(target, index) {
|
|
1374
|
-
const { context, objectId } = target;
|
|
1375
|
-
index = parseListIndex(index);
|
|
1376
|
-
if (index === Symbol.hasInstance) {
|
|
1377
|
-
return (instance) => {
|
|
1378
|
-
return Array.isArray(instance);
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
if (index === Symbol.toStringTag) {
|
|
1382
|
-
return target[Symbol.toStringTag];
|
|
1383
|
-
}
|
|
1384
|
-
if (index === OBJECT_ID)
|
|
1385
|
-
return objectId;
|
|
1386
|
-
if (index === IS_PROXY)
|
|
1387
|
-
return true;
|
|
1388
|
-
if (index === TRACE)
|
|
1389
|
-
return target.trace;
|
|
1390
|
-
if (index === STATE)
|
|
1391
|
-
return { handle: context };
|
|
1392
|
-
if (index === "length")
|
|
1393
|
-
return context.length(objectId);
|
|
1394
|
-
if (typeof index === "number") {
|
|
1395
|
-
return valueAt(target, index);
|
|
1396
|
-
} else {
|
|
1397
|
-
return listMethods(target)[index];
|
|
1398
|
-
}
|
|
1399
|
-
},
|
|
1400
|
-
set(target, index, val) {
|
|
1401
|
-
const { context, objectId, path } = target;
|
|
1402
|
-
index = parseListIndex(index);
|
|
1403
|
-
if (isSameDocument(val, context)) {
|
|
1404
|
-
throw new RangeError("Cannot create a reference to an existing document object");
|
|
1405
|
-
}
|
|
1406
|
-
if (index === CLEAR_CACHE) {
|
|
1407
|
-
return true;
|
|
1408
|
-
}
|
|
1409
|
-
if (index === TRACE) {
|
|
1410
|
-
target.trace = val;
|
|
1411
|
-
return true;
|
|
1412
|
-
}
|
|
1413
|
-
if (typeof index == "string") {
|
|
1414
|
-
throw new RangeError("list index must be a number");
|
|
1415
|
-
}
|
|
1416
|
-
const [value, datatype] = import_value(val, [...path, index], context);
|
|
1417
|
-
switch (datatype) {
|
|
1418
|
-
case "list": {
|
|
1419
|
-
let list;
|
|
1420
|
-
if (index >= context.length(objectId)) {
|
|
1421
|
-
list = context.insertObject(objectId, index, []);
|
|
1422
|
-
} else {
|
|
1423
|
-
list = context.putObject(objectId, index, []);
|
|
1424
|
-
}
|
|
1425
|
-
const proxyList = listProxy(context, list, [...path, index]);
|
|
1426
|
-
proxyList.splice(0, 0, ...value);
|
|
1427
|
-
break;
|
|
1428
|
-
}
|
|
1429
|
-
case "text": {
|
|
1430
|
-
if (index >= context.length(objectId)) {
|
|
1431
|
-
context.insertObject(objectId, index, value);
|
|
1432
|
-
} else {
|
|
1433
|
-
context.putObject(objectId, index, value);
|
|
1434
|
-
}
|
|
1435
|
-
break;
|
|
1436
|
-
}
|
|
1437
|
-
case "map": {
|
|
1438
|
-
let map;
|
|
1439
|
-
if (index >= context.length(objectId)) {
|
|
1440
|
-
map = context.insertObject(objectId, index, {});
|
|
1441
|
-
} else {
|
|
1442
|
-
map = context.putObject(objectId, index, {});
|
|
1443
|
-
}
|
|
1444
|
-
const proxyMap = mapProxy(context, map, [...path, index]);
|
|
1445
|
-
for (const key in value) {
|
|
1446
|
-
proxyMap[key] = value[key];
|
|
1447
|
-
}
|
|
1448
|
-
break;
|
|
1449
|
-
}
|
|
1450
|
-
default:
|
|
1451
|
-
if (index >= context.length(objectId)) {
|
|
1452
|
-
context.insert(objectId, index, value, datatype);
|
|
1453
|
-
} else {
|
|
1454
|
-
context.put(objectId, index, value, datatype);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return true;
|
|
1458
|
-
},
|
|
1459
|
-
deleteProperty(target, index) {
|
|
1460
|
-
const { context, objectId } = target;
|
|
1461
|
-
index = parseListIndex(index);
|
|
1462
|
-
const elem = context.get(objectId, index);
|
|
1463
|
-
if (elem != null && elem[0] == "counter") {
|
|
1464
|
-
throw new TypeError("Unsupported operation: deleting a counter from a list");
|
|
1465
|
-
}
|
|
1466
|
-
context.delete(objectId, index);
|
|
1467
|
-
return true;
|
|
1468
|
-
},
|
|
1469
|
-
has(target, index) {
|
|
1470
|
-
const { context, objectId } = target;
|
|
1471
|
-
index = parseListIndex(index);
|
|
1472
|
-
if (typeof index === "number") {
|
|
1473
|
-
return index < context.length(objectId);
|
|
1474
|
-
}
|
|
1475
|
-
return index === "length";
|
|
1476
|
-
},
|
|
1477
|
-
getOwnPropertyDescriptor(target, index) {
|
|
1478
|
-
const { context, objectId } = target;
|
|
1479
|
-
if (index === "length")
|
|
1480
|
-
return { writable: true, value: context.length(objectId) };
|
|
1481
|
-
if (index === OBJECT_ID)
|
|
1482
|
-
return { configurable: false, enumerable: false, value: objectId };
|
|
1483
|
-
index = parseListIndex(index);
|
|
1484
|
-
const value = valueAt(target, index);
|
|
1485
|
-
return { configurable: true, enumerable: true, value };
|
|
1486
|
-
},
|
|
1487
|
-
getPrototypeOf(target) {
|
|
1488
|
-
return Object.getPrototypeOf(target);
|
|
1489
|
-
},
|
|
1490
|
-
ownKeys() {
|
|
1491
|
-
const keys = [];
|
|
1492
|
-
keys.push("length");
|
|
1493
|
-
return keys;
|
|
1494
|
-
}
|
|
1495
|
-
};
|
|
1496
|
-
Object.assign({}, ListHandler, {
|
|
1497
|
-
get(target, index) {
|
|
1498
|
-
const { context, objectId } = target;
|
|
1499
|
-
index = parseListIndex(index);
|
|
1500
|
-
if (index === Symbol.hasInstance) {
|
|
1501
|
-
return (instance) => {
|
|
1502
|
-
return Array.isArray(instance);
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
if (index === Symbol.toStringTag) {
|
|
1506
|
-
return target[Symbol.toStringTag];
|
|
1507
|
-
}
|
|
1508
|
-
if (index === OBJECT_ID)
|
|
1509
|
-
return objectId;
|
|
1510
|
-
if (index === IS_PROXY)
|
|
1511
|
-
return true;
|
|
1512
|
-
if (index === TRACE)
|
|
1513
|
-
return target.trace;
|
|
1514
|
-
if (index === STATE)
|
|
1515
|
-
return { handle: context };
|
|
1516
|
-
if (index === "length")
|
|
1517
|
-
return context.length(objectId);
|
|
1518
|
-
if (typeof index === "number") {
|
|
1519
|
-
return valueAt(target, index);
|
|
1520
|
-
} else {
|
|
1521
|
-
return textMethods(target)[index] || listMethods(target)[index];
|
|
1522
|
-
}
|
|
1523
|
-
},
|
|
1524
|
-
getPrototypeOf() {
|
|
1525
|
-
return Object.getPrototypeOf(new Text());
|
|
1526
|
-
}
|
|
1527
|
-
});
|
|
1528
|
-
function mapProxy(context, objectId, path) {
|
|
1529
|
-
const target = {
|
|
1530
|
-
context,
|
|
1531
|
-
objectId,
|
|
1532
|
-
path: path || [],
|
|
1533
|
-
cache: {}
|
|
1534
|
-
};
|
|
1535
|
-
const proxied = {};
|
|
1536
|
-
Object.assign(proxied, target);
|
|
1537
|
-
const result = new Proxy(proxied, MapHandler);
|
|
1538
|
-
return result;
|
|
1539
|
-
}
|
|
1540
|
-
function listProxy(context, objectId, path) {
|
|
1541
|
-
const target = {
|
|
1542
|
-
context,
|
|
1543
|
-
objectId,
|
|
1544
|
-
path: path || [],
|
|
1545
|
-
cache: {}
|
|
1546
|
-
};
|
|
1547
|
-
const proxied = [];
|
|
1548
|
-
Object.assign(proxied, target);
|
|
1549
|
-
return new Proxy(proxied, ListHandler);
|
|
1550
|
-
}
|
|
1551
|
-
function listMethods(target) {
|
|
1552
|
-
const { context, objectId, path } = target;
|
|
1553
|
-
const methods = {
|
|
1554
|
-
at(index) {
|
|
1555
|
-
return valueAt(target, index);
|
|
1556
|
-
},
|
|
1557
|
-
deleteAt(index, numDelete) {
|
|
1558
|
-
if (typeof numDelete === "number") {
|
|
1559
|
-
context.splice(objectId, index, numDelete);
|
|
1560
|
-
} else {
|
|
1561
|
-
context.delete(objectId, index);
|
|
1562
|
-
}
|
|
1563
|
-
return this;
|
|
1564
|
-
},
|
|
1565
|
-
fill(val, start, end) {
|
|
1566
|
-
const [value, datatype] = import_value(val, [...path, start], context);
|
|
1567
|
-
const length = context.length(objectId);
|
|
1568
|
-
start = parseListIndex(start || 0);
|
|
1569
|
-
end = parseListIndex(end || length);
|
|
1570
|
-
for (let i = start; i < Math.min(end, length); i++) {
|
|
1571
|
-
if (datatype === "list" || datatype === "map") {
|
|
1572
|
-
context.putObject(objectId, i, value);
|
|
1573
|
-
} else if (datatype === "text") {
|
|
1574
|
-
context.putObject(objectId, i, value);
|
|
1575
|
-
} else {
|
|
1576
|
-
context.put(objectId, i, value, datatype);
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
return this;
|
|
1580
|
-
},
|
|
1581
|
-
indexOf(searchElement, start = 0) {
|
|
1582
|
-
const length = context.length(objectId);
|
|
1583
|
-
for (let i = start; i < length; i++) {
|
|
1584
|
-
const valueWithType = context.getWithType(objectId, i);
|
|
1585
|
-
if (!valueWithType) {
|
|
1586
|
-
continue;
|
|
1587
|
-
}
|
|
1588
|
-
const [valType, value] = valueWithType;
|
|
1589
|
-
const isObject2 = ["map", "list", "text"].includes(valType);
|
|
1590
|
-
if (!isObject2) {
|
|
1591
|
-
if (value === searchElement) {
|
|
1592
|
-
return i;
|
|
1593
|
-
} else {
|
|
1594
|
-
continue;
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
if (valType === "text" && typeof searchElement === "string") {
|
|
1598
|
-
if (searchElement === valueAt(target, i)) {
|
|
1599
|
-
return i;
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
if (searchElement[OBJECT_ID] === value) {
|
|
1603
|
-
return i;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
return -1;
|
|
1607
|
-
},
|
|
1608
|
-
insertAt(index, ...values) {
|
|
1609
|
-
this.splice(index, 0, ...values);
|
|
1610
|
-
return this;
|
|
1611
|
-
},
|
|
1612
|
-
pop() {
|
|
1613
|
-
const length = context.length(objectId);
|
|
1614
|
-
if (length == 0) {
|
|
1615
|
-
return void 0;
|
|
1616
|
-
}
|
|
1617
|
-
const last = valueAt(target, length - 1);
|
|
1618
|
-
context.delete(objectId, length - 1);
|
|
1619
|
-
return last;
|
|
1620
|
-
},
|
|
1621
|
-
push(...values) {
|
|
1622
|
-
const len = context.length(objectId);
|
|
1623
|
-
this.splice(len, 0, ...values);
|
|
1624
|
-
return context.length(objectId);
|
|
1625
|
-
},
|
|
1626
|
-
shift() {
|
|
1627
|
-
if (context.length(objectId) == 0)
|
|
1628
|
-
return;
|
|
1629
|
-
const first = valueAt(target, 0);
|
|
1630
|
-
context.delete(objectId, 0);
|
|
1631
|
-
return first;
|
|
1632
|
-
},
|
|
1633
|
-
splice(index, del, ...vals) {
|
|
1634
|
-
index = parseListIndex(index);
|
|
1635
|
-
if (typeof del !== "number") {
|
|
1636
|
-
del = context.length(objectId) - index;
|
|
1637
|
-
}
|
|
1638
|
-
del = parseListIndex(del);
|
|
1639
|
-
for (const val of vals) {
|
|
1640
|
-
if (isSameDocument(val, context)) {
|
|
1641
|
-
throw new RangeError("Cannot create a reference to an existing document object");
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
const result = [];
|
|
1645
|
-
for (let i = 0; i < del; i++) {
|
|
1646
|
-
const value = valueAt(target, index);
|
|
1647
|
-
if (value !== void 0) {
|
|
1648
|
-
result.push(value);
|
|
1649
|
-
}
|
|
1650
|
-
context.delete(objectId, index);
|
|
1651
|
-
}
|
|
1652
|
-
const values = vals.map((val, index2) => {
|
|
1653
|
-
try {
|
|
1654
|
-
return import_value(val, [...path], context);
|
|
1655
|
-
} catch (e) {
|
|
1656
|
-
if (e instanceof RangeError) {
|
|
1657
|
-
throw new RangeError(`${e.message} (at index ${index2} in the input)`);
|
|
1658
|
-
} else {
|
|
1659
|
-
throw e;
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
});
|
|
1663
|
-
for (const [value, datatype] of values) {
|
|
1664
|
-
switch (datatype) {
|
|
1665
|
-
case "list": {
|
|
1666
|
-
const list = context.insertObject(objectId, index, []);
|
|
1667
|
-
const proxyList = listProxy(context, list, [...path, index]);
|
|
1668
|
-
proxyList.splice(0, 0, ...value);
|
|
1669
|
-
break;
|
|
1670
|
-
}
|
|
1671
|
-
case "text": {
|
|
1672
|
-
context.insertObject(objectId, index, value);
|
|
1673
|
-
break;
|
|
1674
|
-
}
|
|
1675
|
-
case "map": {
|
|
1676
|
-
const map = context.insertObject(objectId, index, {});
|
|
1677
|
-
const proxyMap = mapProxy(context, map, [...path, index]);
|
|
1678
|
-
for (const key in value) {
|
|
1679
|
-
proxyMap[key] = value[key];
|
|
1680
|
-
}
|
|
1681
|
-
break;
|
|
1682
|
-
}
|
|
1683
|
-
default:
|
|
1684
|
-
context.insert(objectId, index, value, datatype);
|
|
1685
|
-
}
|
|
1686
|
-
index += 1;
|
|
1687
|
-
}
|
|
1688
|
-
return result;
|
|
1689
|
-
},
|
|
1690
|
-
unshift(...values) {
|
|
1691
|
-
this.splice(0, 0, ...values);
|
|
1692
|
-
return context.length(objectId);
|
|
1693
|
-
},
|
|
1694
|
-
entries() {
|
|
1695
|
-
let i = 0;
|
|
1696
|
-
const iterator = {
|
|
1697
|
-
next: () => {
|
|
1698
|
-
const value = valueAt(target, i);
|
|
1699
|
-
if (value === void 0) {
|
|
1700
|
-
return { value: void 0, done: true };
|
|
1701
|
-
} else {
|
|
1702
|
-
return { value: [i++, value], done: false };
|
|
1703
|
-
}
|
|
1704
|
-
},
|
|
1705
|
-
[Symbol.iterator]() {
|
|
1706
|
-
return this;
|
|
1707
|
-
}
|
|
1708
|
-
};
|
|
1709
|
-
return iterator;
|
|
1710
|
-
},
|
|
1711
|
-
keys() {
|
|
1712
|
-
let i = 0;
|
|
1713
|
-
const len = context.length(objectId);
|
|
1714
|
-
const iterator = {
|
|
1715
|
-
next: () => {
|
|
1716
|
-
if (i < len) {
|
|
1717
|
-
return { value: i++, done: false };
|
|
1718
|
-
}
|
|
1719
|
-
return { value: void 0, done: true };
|
|
1720
|
-
},
|
|
1721
|
-
[Symbol.iterator]() {
|
|
1722
|
-
return this;
|
|
1723
|
-
}
|
|
1724
|
-
};
|
|
1725
|
-
return iterator;
|
|
1726
|
-
},
|
|
1727
|
-
values() {
|
|
1728
|
-
let i = 0;
|
|
1729
|
-
const iterator = {
|
|
1730
|
-
next: () => {
|
|
1731
|
-
const value = valueAt(target, i++);
|
|
1732
|
-
if (value === void 0) {
|
|
1733
|
-
return { value: void 0, done: true };
|
|
1734
|
-
} else {
|
|
1735
|
-
return { value, done: false };
|
|
1736
|
-
}
|
|
1737
|
-
},
|
|
1738
|
-
[Symbol.iterator]() {
|
|
1739
|
-
return this;
|
|
1740
|
-
}
|
|
1741
|
-
};
|
|
1742
|
-
return iterator;
|
|
1743
|
-
},
|
|
1744
|
-
toArray() {
|
|
1745
|
-
const list = [];
|
|
1746
|
-
let value;
|
|
1747
|
-
do {
|
|
1748
|
-
value = valueAt(target, list.length);
|
|
1749
|
-
if (value !== void 0) {
|
|
1750
|
-
list.push(value);
|
|
1751
|
-
}
|
|
1752
|
-
} while (value !== void 0);
|
|
1753
|
-
return list;
|
|
1754
|
-
},
|
|
1755
|
-
map(f) {
|
|
1756
|
-
return this.toArray().map(f);
|
|
1757
|
-
},
|
|
1758
|
-
toString() {
|
|
1759
|
-
return this.toArray().toString();
|
|
1760
|
-
},
|
|
1761
|
-
toLocaleString() {
|
|
1762
|
-
return this.toArray().toLocaleString();
|
|
1763
|
-
},
|
|
1764
|
-
forEach(f) {
|
|
1765
|
-
return this.toArray().forEach(f);
|
|
1766
|
-
},
|
|
1767
|
-
// todo: real concat function is different
|
|
1768
|
-
concat(other) {
|
|
1769
|
-
return this.toArray().concat(other);
|
|
1770
|
-
},
|
|
1771
|
-
every(f) {
|
|
1772
|
-
return this.toArray().every(f);
|
|
1773
|
-
},
|
|
1774
|
-
filter(f) {
|
|
1775
|
-
return this.toArray().filter(f);
|
|
1776
|
-
},
|
|
1777
|
-
find(f) {
|
|
1778
|
-
let index = 0;
|
|
1779
|
-
for (const v of this) {
|
|
1780
|
-
if (f(v, index)) {
|
|
1781
|
-
return v;
|
|
1782
|
-
}
|
|
1783
|
-
index += 1;
|
|
1784
|
-
}
|
|
1785
|
-
},
|
|
1786
|
-
findIndex(f) {
|
|
1787
|
-
let index = 0;
|
|
1788
|
-
for (const v of this) {
|
|
1789
|
-
if (f(v, index)) {
|
|
1790
|
-
return index;
|
|
1791
|
-
}
|
|
1792
|
-
index += 1;
|
|
1793
|
-
}
|
|
1794
|
-
return -1;
|
|
1795
|
-
},
|
|
1796
|
-
includes(elem) {
|
|
1797
|
-
return this.find((e) => e === elem) !== void 0;
|
|
1798
|
-
},
|
|
1799
|
-
join(sep) {
|
|
1800
|
-
return this.toArray().join(sep);
|
|
1801
|
-
},
|
|
1802
|
-
reduce(f, initialValue) {
|
|
1803
|
-
return this.toArray().reduce(f, initialValue);
|
|
1804
|
-
},
|
|
1805
|
-
reduceRight(f, initialValue) {
|
|
1806
|
-
return this.toArray().reduceRight(f, initialValue);
|
|
1807
|
-
},
|
|
1808
|
-
lastIndexOf(search, fromIndex = Infinity) {
|
|
1809
|
-
return this.toArray().lastIndexOf(search, fromIndex);
|
|
1810
|
-
},
|
|
1811
|
-
slice(index, num) {
|
|
1812
|
-
return this.toArray().slice(index, num);
|
|
1813
|
-
},
|
|
1814
|
-
some(f) {
|
|
1815
|
-
let index = 0;
|
|
1816
|
-
for (const v of this) {
|
|
1817
|
-
if (f(v, index)) {
|
|
1818
|
-
return true;
|
|
1819
|
-
}
|
|
1820
|
-
index += 1;
|
|
1821
|
-
}
|
|
1822
|
-
return false;
|
|
1823
|
-
},
|
|
1824
|
-
[Symbol.iterator]: function* () {
|
|
1825
|
-
let i = 0;
|
|
1826
|
-
let value = valueAt(target, i);
|
|
1827
|
-
while (value !== void 0) {
|
|
1828
|
-
yield value;
|
|
1829
|
-
i += 1;
|
|
1830
|
-
value = valueAt(target, i);
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
return methods;
|
|
1835
|
-
}
|
|
1836
|
-
function textMethods(target) {
|
|
1837
|
-
const { context, objectId } = target;
|
|
1838
|
-
const methods = {
|
|
1839
|
-
set(index, value) {
|
|
1840
|
-
return this[index] = value;
|
|
1841
|
-
},
|
|
1842
|
-
get(index) {
|
|
1843
|
-
return this[index];
|
|
1844
|
-
},
|
|
1845
|
-
toString() {
|
|
1846
|
-
return context.text(objectId).replace(//g, "");
|
|
1847
|
-
},
|
|
1848
|
-
toSpans() {
|
|
1849
|
-
const spans = [];
|
|
1850
|
-
let chars = "";
|
|
1851
|
-
const length = context.length(objectId);
|
|
1852
|
-
for (let i = 0; i < length; i++) {
|
|
1853
|
-
const value = this[i];
|
|
1854
|
-
if (typeof value === "string") {
|
|
1855
|
-
chars += value;
|
|
1856
|
-
} else {
|
|
1857
|
-
if (chars.length > 0) {
|
|
1858
|
-
spans.push(chars);
|
|
1859
|
-
chars = "";
|
|
1860
|
-
}
|
|
1861
|
-
spans.push(value);
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
if (chars.length > 0) {
|
|
1865
|
-
spans.push(chars);
|
|
1866
|
-
}
|
|
1867
|
-
return spans;
|
|
1868
|
-
},
|
|
1869
|
-
toJSON() {
|
|
1870
|
-
return this.toString();
|
|
1871
|
-
},
|
|
1872
|
-
indexOf(o, start = 0) {
|
|
1873
|
-
const text = context.text(objectId);
|
|
1874
|
-
return text.indexOf(o, start);
|
|
1875
|
-
},
|
|
1876
|
-
insertAt(index, ...values) {
|
|
1877
|
-
if (values.every((v) => typeof v === "string")) {
|
|
1878
|
-
context.splice(objectId, index, 0, values.join(""));
|
|
1879
|
-
} else {
|
|
1880
|
-
listMethods(target).insertAt(index, ...values);
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
};
|
|
1884
|
-
return methods;
|
|
1885
|
-
}
|
|
1886
|
-
function printPath(path) {
|
|
1887
|
-
const jsonPointerComponents = path.map((component) => {
|
|
1888
|
-
if (typeof component === "number") {
|
|
1889
|
-
return component.toString();
|
|
1890
|
-
} else if (typeof component === "string") {
|
|
1891
|
-
return component.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
1892
|
-
}
|
|
1893
|
-
});
|
|
1894
|
-
if (path.length === 0) {
|
|
1895
|
-
return "";
|
|
1896
|
-
} else {
|
|
1897
|
-
return "/" + jsonPointerComponents.join("/");
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
function isImmutableString(obj) {
|
|
1901
|
-
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, IMMUTABLE_STRING);
|
|
1902
|
-
}
|
|
1903
|
-
function isCounter(obj) {
|
|
1904
|
-
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, COUNTER);
|
|
1905
|
-
}
|
|
1906
|
-
let wasm;
|
|
1907
|
-
const cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
|
|
1908
|
-
throw Error("TextEncoder not available");
|
|
1909
|
-
} };
|
|
1910
|
-
typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
|
|
1911
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
1912
|
-
} : function(arg, view) {
|
|
1913
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
1914
|
-
view.set(buf);
|
|
1915
|
-
return {
|
|
1916
|
-
read: arg.length,
|
|
1917
|
-
written: buf.length
|
|
1918
|
-
};
|
|
1919
|
-
};
|
|
1920
|
-
const cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
|
|
1921
|
-
throw Error("TextDecoder not available");
|
|
1922
|
-
} };
|
|
1923
|
-
if (typeof TextDecoder !== "undefined") {
|
|
1924
|
-
cachedTextDecoder.decode();
|
|
1925
|
-
}
|
|
1926
|
-
typeof FinalizationRegistry === "undefined" ? {} : new FinalizationRegistry((ptr) => wasm.__wbg_automerge_free(ptr >>> 0, 1));
|
|
1927
|
-
typeof FinalizationRegistry === "undefined" ? {} : new FinalizationRegistry((ptr) => wasm.__wbg_syncstate_free(ptr >>> 0, 1));
|
|
1928
|
-
function _state(doc, checkroot = true) {
|
|
1929
|
-
if (typeof doc !== "object") {
|
|
1930
|
-
throw new RangeError("must be the document root");
|
|
1931
|
-
}
|
|
1932
|
-
const state = Reflect.get(doc, STATE);
|
|
1933
|
-
if (state === void 0 || state == null || checkroot && _obj(doc) !== "_root") {
|
|
1934
|
-
throw new RangeError("must be the document root");
|
|
1935
|
-
}
|
|
1936
|
-
return state;
|
|
1937
|
-
}
|
|
1938
|
-
function _clear_cache(doc) {
|
|
1939
|
-
Reflect.set(doc, CLEAR_CACHE, true);
|
|
1940
|
-
}
|
|
1941
|
-
function _obj(doc) {
|
|
1942
|
-
if (!(typeof doc === "object") || doc === null) {
|
|
1943
|
-
return null;
|
|
1944
|
-
}
|
|
1945
|
-
return Reflect.get(doc, OBJECT_ID);
|
|
1946
|
-
}
|
|
1947
|
-
function _is_proxy(doc) {
|
|
1948
|
-
return !!Reflect.get(doc, IS_PROXY);
|
|
1949
|
-
}
|
|
1950
|
-
function applyPatch(doc, patch) {
|
|
1951
|
-
let path = resolvePath(doc, patch.path);
|
|
1952
|
-
if (patch.action === "put") {
|
|
1953
|
-
applyPutPatch(doc, path, patch);
|
|
1954
|
-
} else if (patch.action === "insert") {
|
|
1955
|
-
applyInsertPatch(doc, path, patch);
|
|
1956
|
-
} else if (patch.action === "del") {
|
|
1957
|
-
applyDelPatch(doc, path, patch);
|
|
1958
|
-
} else if (patch.action === "splice") {
|
|
1959
|
-
applySplicePatch(doc, path, patch);
|
|
1960
|
-
} else if (patch.action === "inc") {
|
|
1961
|
-
applyIncPatch(doc, path, patch);
|
|
1962
|
-
} else if (patch.action === "mark") {
|
|
1963
|
-
applyMarkPatch(doc, path, patch);
|
|
1964
|
-
} else if (patch.action === "unmark") {
|
|
1965
|
-
applyUnmarkPatch(doc, path, patch);
|
|
1966
|
-
} else if (patch.action === "conflict") ;
|
|
1967
|
-
else {
|
|
1968
|
-
throw new RangeError(`unsupported patch: ${patch}`);
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
function applyPutPatch(doc, path, patch) {
|
|
1972
|
-
let { obj: parent, prop } = pathElemAt(path, -1);
|
|
1973
|
-
parent[prop] = patch.value;
|
|
1974
|
-
}
|
|
1975
|
-
function applyInsertPatch(doc, path, patch) {
|
|
1976
|
-
let { obj: parent, prop } = pathElemAt(path, -1);
|
|
1977
|
-
if (!Array.isArray(parent)) {
|
|
1978
|
-
throw new RangeError(`target is not an array for patch`);
|
|
1979
|
-
}
|
|
1980
|
-
if (!(typeof prop === "number")) {
|
|
1981
|
-
throw new RangeError(`index is not a number for patch`);
|
|
1982
|
-
}
|
|
1983
|
-
parent.splice(prop, 0, ...patch.values);
|
|
1984
|
-
}
|
|
1985
|
-
function applyDelPatch(doc, path, patch) {
|
|
1986
|
-
let { obj: parent, prop, parentPath } = pathElemAt(path, -1);
|
|
1987
|
-
if (!(typeof prop === "number")) {
|
|
1988
|
-
throw new RangeError(`index is not a number for patch`);
|
|
1989
|
-
}
|
|
1990
|
-
if (Array.isArray(parent)) {
|
|
1991
|
-
parent.splice(prop, patch.length || 1);
|
|
1992
|
-
} else if (typeof parent === "string") {
|
|
1993
|
-
if (isAutomerge(doc)) {
|
|
1994
|
-
splice(doc, parentPath, prop, patch.length || 1);
|
|
1995
|
-
} else {
|
|
1996
|
-
let { obj: grandParent, prop: grandParentProp } = pathElemAt(path, -2);
|
|
1997
|
-
if (typeof prop !== "number") {
|
|
1998
|
-
throw new RangeError(`index is not a number for patch`);
|
|
1999
|
-
}
|
|
2000
|
-
let target = grandParent[grandParentProp];
|
|
2001
|
-
if (target == null || typeof target !== "string") {
|
|
2002
|
-
throw new RangeError(`target is not a string for patch`);
|
|
2003
|
-
}
|
|
2004
|
-
let newString = target.slice(0, prop) + target.slice(prop + (patch.length || 1));
|
|
2005
|
-
grandParent[grandParentProp] = newString;
|
|
2006
|
-
}
|
|
2007
|
-
} else {
|
|
2008
|
-
throw new RangeError(`target is not an array or string for patch`);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
function applySplicePatch(doc, path, patch) {
|
|
2012
|
-
if (isAutomerge(doc)) {
|
|
2013
|
-
let { obj: parent, prop, parentPath } = pathElemAt(path, -1);
|
|
2014
|
-
if (!(typeof prop === "number")) {
|
|
2015
|
-
throw new RangeError(`index is not a number for patch`);
|
|
2016
|
-
}
|
|
2017
|
-
splice(doc, parentPath, prop, 0, patch.value);
|
|
2018
|
-
} else {
|
|
2019
|
-
let { obj: parent, prop } = pathElemAt(path, -1);
|
|
2020
|
-
let { obj: grandParent, prop: grandParentProp } = pathElemAt(path, -2);
|
|
2021
|
-
if (typeof prop !== "number") {
|
|
2022
|
-
throw new RangeError(`index is not a number for patch`);
|
|
2023
|
-
}
|
|
2024
|
-
let target = grandParent[grandParentProp];
|
|
2025
|
-
if (target == null || typeof target !== "string") {
|
|
2026
|
-
throw new RangeError(`target is not a string for patch`);
|
|
2027
|
-
}
|
|
2028
|
-
let newString = target.slice(0, prop) + patch.value + target.slice(prop);
|
|
2029
|
-
grandParent[grandParentProp] = newString;
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
function applyIncPatch(doc, path, patch) {
|
|
2033
|
-
let { obj: parent, prop } = pathElemAt(path, -1);
|
|
2034
|
-
const counter = parent[prop];
|
|
2035
|
-
if (isAutomerge(doc)) {
|
|
2036
|
-
if (!isCounter(counter)) {
|
|
2037
|
-
throw new RangeError(`target is not a counter for patch`);
|
|
2038
|
-
}
|
|
2039
|
-
counter.increment(patch.value);
|
|
2040
|
-
} else {
|
|
2041
|
-
if (!(typeof counter === "number")) {
|
|
2042
|
-
throw new RangeError(`target is not a number for patch`);
|
|
2043
|
-
}
|
|
2044
|
-
parent[prop] = counter + patch.value;
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
function applyMarkPatch(doc, path, patch) {
|
|
2048
|
-
let { obj: parent, prop } = pathElemAt(path, -1);
|
|
2049
|
-
if (!isAutomerge(doc)) {
|
|
2050
|
-
return;
|
|
2051
|
-
}
|
|
2052
|
-
for (const markSpec of patch.marks) {
|
|
2053
|
-
mark(
|
|
2054
|
-
doc,
|
|
2055
|
-
patch.path,
|
|
2056
|
-
// TODO: add mark expansion to patches. This will require emitting
|
|
2057
|
-
// the expand values in patches.
|
|
2058
|
-
{ start: markSpec.start, end: markSpec.end, expand: "none" },
|
|
2059
|
-
markSpec.name,
|
|
2060
|
-
markSpec.value
|
|
2061
|
-
);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
function applyUnmarkPatch(doc, path, patch) {
|
|
2065
|
-
if (!isAutomerge(doc)) {
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
unmark(doc, patch.path, { start: patch.start, end: patch.end, expand: "none" }, patch.name);
|
|
2069
|
-
}
|
|
2070
|
-
function applyPatches(doc, patches) {
|
|
2071
|
-
for (const patch of patches) {
|
|
2072
|
-
applyPatch(doc, patch);
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
function resolvePath(doc, path) {
|
|
2076
|
-
const result = [];
|
|
2077
|
-
let current = doc;
|
|
2078
|
-
let currentPath = [];
|
|
2079
|
-
for (const [index, prop] of path.entries()) {
|
|
2080
|
-
result.push({ obj: current, prop, parentPath: currentPath.slice() });
|
|
2081
|
-
currentPath.push(prop);
|
|
2082
|
-
if (index !== path.length - 1) {
|
|
2083
|
-
if (current == null || typeof current != "object") {
|
|
2084
|
-
throw new Error(`Invalid path: ${path}`);
|
|
2085
|
-
}
|
|
2086
|
-
current = current[prop];
|
|
2087
|
-
} else {
|
|
2088
|
-
break;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
return result;
|
|
2092
|
-
}
|
|
2093
|
-
function pathElemAt(resolved, index) {
|
|
2094
|
-
let result = resolved.at(index);
|
|
2095
|
-
if (result == void 0) {
|
|
2096
|
-
throw new Error("invalid path");
|
|
2097
|
-
}
|
|
2098
|
-
return result;
|
|
2099
|
-
}
|
|
2100
|
-
function cursorToIndex(state, value, index) {
|
|
2101
|
-
if (typeof index == "string") {
|
|
2102
|
-
if (/^-?[0-9]+@[0-9a-zA-Z]+$|^[se]$/.test(index)) {
|
|
2103
|
-
return state.handle.getCursorPosition(value, index);
|
|
2104
|
-
} else {
|
|
2105
|
-
throw new RangeError("index must be a number or cursor");
|
|
2106
|
-
}
|
|
2107
|
-
} else {
|
|
2108
|
-
return index;
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
function getObjectId(doc, prop) {
|
|
2112
|
-
{
|
|
2113
|
-
return _obj(doc);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
function diff(doc, before, after) {
|
|
2117
|
-
checkHeads(before, "before");
|
|
2118
|
-
checkHeads(after, "after");
|
|
2119
|
-
const state = _state(doc);
|
|
2120
|
-
if (state.mostRecentPatch && equals(state.mostRecentPatch.before, before) && equals(state.mostRecentPatch.after, after)) {
|
|
2121
|
-
return state.mostRecentPatch.patches;
|
|
2122
|
-
}
|
|
2123
|
-
return state.handle.diff(before, after);
|
|
2124
|
-
}
|
|
2125
|
-
function checkHeads(heads, fieldname) {
|
|
2126
|
-
if (!Array.isArray(heads)) {
|
|
2127
|
-
throw new Error(`${fieldname} must be an array`);
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
function equals(val1, val2) {
|
|
2131
|
-
if (!isObject(val1) || !isObject(val2))
|
|
2132
|
-
return val1 === val2;
|
|
2133
|
-
const keys1 = Object.keys(val1).sort(), keys2 = Object.keys(val2).sort();
|
|
2134
|
-
if (keys1.length !== keys2.length)
|
|
2135
|
-
return false;
|
|
2136
|
-
for (let i = 0; i < keys1.length; i++) {
|
|
2137
|
-
if (keys1[i] !== keys2[i])
|
|
2138
|
-
return false;
|
|
2139
|
-
if (!equals(val1[keys1[i]], val2[keys2[i]]))
|
|
2140
|
-
return false;
|
|
2141
|
-
}
|
|
2142
|
-
return true;
|
|
2143
|
-
}
|
|
2144
|
-
function getHeads(doc) {
|
|
2145
|
-
const state = _state(doc);
|
|
2146
|
-
return state.heads || state.handle.getHeads();
|
|
2147
|
-
}
|
|
2148
|
-
function isAutomerge(doc) {
|
|
2149
|
-
if (typeof doc == "object" && doc !== null) {
|
|
2150
|
-
return getObjectId(doc) === "_root" && !!Reflect.get(doc, STATE);
|
|
2151
|
-
} else {
|
|
2152
|
-
return false;
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
function isObject(obj) {
|
|
2156
|
-
return typeof obj === "object" && obj !== null;
|
|
2157
|
-
}
|
|
2158
|
-
function splice(doc, path, index, del, newText) {
|
|
2159
|
-
const objPath = absoluteObjPath(doc, path, "splice");
|
|
2160
|
-
if (!_is_proxy(doc)) {
|
|
2161
|
-
throw new RangeError("object cannot be modified outside of a change block");
|
|
2162
|
-
}
|
|
2163
|
-
const state = _state(doc, false);
|
|
2164
|
-
_clear_cache(doc);
|
|
2165
|
-
index = cursorToIndex(state, objPath, index);
|
|
2166
|
-
try {
|
|
2167
|
-
return state.handle.splice(objPath, index, del, newText);
|
|
2168
|
-
} catch (e) {
|
|
2169
|
-
throw new RangeError(`Cannot splice: ${e}`);
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
function mark(doc, path, range, name, value) {
|
|
2173
|
-
const objPath = absoluteObjPath(doc, path, "mark");
|
|
2174
|
-
if (!_is_proxy(doc)) {
|
|
2175
|
-
throw new RangeError("object cannot be modified outside of a change block");
|
|
2176
|
-
}
|
|
2177
|
-
const state = _state(doc, false);
|
|
2178
|
-
try {
|
|
2179
|
-
return state.handle.mark(objPath, range, name, value);
|
|
2180
|
-
} catch (e) {
|
|
2181
|
-
throw new RangeError(`Cannot mark: ${e}`);
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
function unmark(doc, path, range, name) {
|
|
2185
|
-
const objPath = absoluteObjPath(doc, path, "unmark");
|
|
2186
|
-
if (!_is_proxy(doc)) {
|
|
2187
|
-
throw new RangeError("object cannot be modified outside of a change block");
|
|
2188
|
-
}
|
|
2189
|
-
const state = _state(doc, false);
|
|
2190
|
-
try {
|
|
2191
|
-
return state.handle.unmark(objPath, range, name);
|
|
2192
|
-
} catch (e) {
|
|
2193
|
-
throw new RangeError(`Cannot unmark: ${e}`);
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
function absoluteObjPath(doc, path, functionName) {
|
|
2197
|
-
path = path.slice();
|
|
2198
|
-
const objectId = _obj(doc);
|
|
2199
|
-
if (!objectId) {
|
|
2200
|
-
throw new RangeError(`invalid object for ${functionName}`);
|
|
2201
|
-
}
|
|
2202
|
-
path.unshift(objectId);
|
|
2203
|
-
return path.join("/");
|
|
2204
|
-
}
|
|
2205
|
-
function autoproduce(payload) {
|
|
2206
|
-
return (doc) => applyPatches(doc, payload.patches);
|
|
2207
|
-
}
|
|
2208
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
2209
|
-
function initial(handle) {
|
|
2210
|
-
const template2 = {};
|
|
2211
|
-
applyPatches(template2, diff(handle.doc(), [], getHeads(handle.doc())));
|
|
2212
|
-
return template2;
|
|
2213
|
-
}
|
|
2214
|
-
function makeDocumentProjection(handle) {
|
|
2215
|
-
onCleanup(() => {
|
|
2216
|
-
const item = cache.get(handle);
|
|
2217
|
-
if (!item) return;
|
|
2218
|
-
if (!item.refs--) {
|
|
2219
|
-
item.cleanup();
|
|
2220
|
-
}
|
|
2221
|
-
});
|
|
2222
|
-
if (cache.has(handle)) {
|
|
2223
|
-
const item = cache.get(handle);
|
|
2224
|
-
item.refs++;
|
|
2225
|
-
return item.store;
|
|
2226
|
-
}
|
|
2227
|
-
const [doc, set] = createStore(initial(handle));
|
|
2228
|
-
cache.set(handle, {
|
|
2229
|
-
refs: 0,
|
|
2230
|
-
store: doc,
|
|
2231
|
-
cleanup() {
|
|
2232
|
-
handle.off("change", patch);
|
|
2233
|
-
handle.off("delete", ondelete);
|
|
2234
|
-
cache.delete(handle);
|
|
2235
|
-
}
|
|
2236
|
-
});
|
|
2237
|
-
function patch(payload) {
|
|
2238
|
-
set(produce(autoproduce(payload)));
|
|
2239
|
-
}
|
|
2240
|
-
function ondelete() {
|
|
2241
|
-
set(reconcile({}));
|
|
2242
|
-
}
|
|
2243
|
-
handle.on("change", patch);
|
|
2244
|
-
handle.on("delete", ondelete);
|
|
2245
|
-
return doc;
|
|
2246
|
-
}
|
|
2247
|
-
function createDocumentProjection(handle) {
|
|
2248
|
-
const projection = createMemo(() => {
|
|
2249
|
-
const unwrappedHandle = typeof handle == "function" ? handle() : handle;
|
|
2250
|
-
return unwrappedHandle && makeDocumentProjection(unwrappedHandle);
|
|
2251
|
-
});
|
|
2252
|
-
return projection;
|
|
2253
|
-
}
|
|
2254
|
-
createContext(
|
|
2255
|
-
null
|
|
2256
|
-
);
|
|
2257
1066
|
function resolveElement(source) {
|
|
2258
1067
|
return typeof source === "function" ? source() : source;
|
|
2259
1068
|
}
|
|
@@ -2292,7 +1101,23 @@ function subscribeDoc(element, selector) {
|
|
|
2292
1101
|
unsubscribe();
|
|
2293
1102
|
});
|
|
2294
1103
|
});
|
|
2295
|
-
const
|
|
1104
|
+
const [store, setStore] = createStore({});
|
|
1105
|
+
const [ready, setReady] = createSignal(false);
|
|
1106
|
+
createEffect(() => {
|
|
1107
|
+
const h = handle();
|
|
1108
|
+
if (!h) {
|
|
1109
|
+
setReady(false);
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
const sync = () => {
|
|
1113
|
+
setStore(reconcile(h.doc() ?? {}));
|
|
1114
|
+
setReady(true);
|
|
1115
|
+
};
|
|
1116
|
+
sync();
|
|
1117
|
+
h.on("change", sync);
|
|
1118
|
+
onCleanup(() => h.off("change", sync));
|
|
1119
|
+
});
|
|
1120
|
+
const doc = () => ready() ? store : void 0;
|
|
2296
1121
|
return [doc, handle];
|
|
2297
1122
|
}
|
|
2298
1123
|
var _tmpl$ = /* @__PURE__ */ template(`<span class=drafts-hint>Drafts aren't supported for folders yet.`), _tmpl$2 = /* @__PURE__ */ template(`<div class="drafts-actions drafts-actions--top"><button class="drafts-btn drafts-btn--primary">New draft`), _tmpl$3 = /* @__PURE__ */ template(`<div class=drafts-list>`), _tmpl$4 = /* @__PURE__ */ template(`<div class=drafts-dropzone>Drop to fork a new draft from this version`), _tmpl$5 = /* @__PURE__ */ template(`<button class="drafts-btn drafts-btn--warning"title="Merge this draft into Main">Merge into Main`), _tmpl$6 = /* @__PURE__ */ template(`<div class=drafts-actions>`), _tmpl$7 = /* @__PURE__ */ template(`<div class=drafts-panel><div class=drafts-version>v0.0.18`), _tmpl$8 = /* @__PURE__ */ template(`<div class=drafts-empty>No document selected.`), _tmpl$9 = /* @__PURE__ */ template(`<span class=draft-badge>current`), _tmpl$0 = /* @__PURE__ */ template(`<div class=draft-card><div class=draft-card-header title="Main version (host document)"><div class=draft-card-title>`), _tmpl$1 = /* @__PURE__ */ template(`<div class=draft-card><div class=draft-card-header title="Open draft"><div class=draft-card-title>`), _tmpl$10 = /* @__PURE__ */ template(`<button type=button class=draft-card-return title="Return to the latest version">Return to latest`), _tmpl$11 = /* @__PURE__ */ template(`<input class=draft-name-input>`), _tmpl$12 = /* @__PURE__ */ template(`<span class=draft-name title="Double-click to rename">`), _tmpl$13 = /* @__PURE__ */ template(`<div class=draft-scrubber-token><div class=draft-scrubber-line></div><div class=draft-scrubber-edge title="Drag to scrub through history"></div><div class=draft-scrubber-dot title="Drag to scrub through history">`), _tmpl$14 = /* @__PURE__ */ template(`<div class=draft-changes-body><div class=draft-scrubber></div><div class=draft-changes-rows>`), _tmpl$15 = /* @__PURE__ */ template(`<div class=draft-card-changes>`), _tmpl$16 = /* @__PURE__ */ template(`<div class=draft-changes-empty>No changes yet.`), _tmpl$17 = /* @__PURE__ */ template(`<div class=draft-scrubber-sticker title="Drag out to fork a new draft from this version"><span class=draft-sticker-time></span><span class=draft-sticker-title></span><span class=draft-sticker-spacer>`), _tmpl$18 = /* @__PURE__ */ template(`<button type=button class=draft-group-row title="View the draft as of this group — drag out to fork a draft from it"><span class=draft-group-time></span><span class=draft-group-spacer>`), _tmpl$19 = /* @__PURE__ */ template(`<div class="draft-avatar draft-avatar--extra">+`), _tmpl$20 = /* @__PURE__ */ template(`<div class=draft-avatars>`), _tmpl$21 = /* @__PURE__ */ template(`<div class=draft-avatar>`), _tmpl$22 = /* @__PURE__ */ template(`<span class="draft-count draft-count--add">+`), _tmpl$23 = /* @__PURE__ */ template(`<span class="draft-count draft-count--del">-`), _tmpl$24 = /* @__PURE__ */ template(`<span class=draft-counts>`);
|
|
@@ -3503,4 +2328,4 @@ const renderDraftsSidebar = (_handle, element) => {
|
|
|
3503
2328
|
export {
|
|
3504
2329
|
renderDraftsSidebar
|
|
3505
2330
|
};
|
|
3506
|
-
//# sourceMappingURL=main-
|
|
2331
|
+
//# sourceMappingURL=main-Cp8VsNHh.js.map
|