lib0 1.0.0-rc.10 → 1.0.0-rc.12
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 +3 -3
- package/src/delta/delta.js +49 -17
- package/types/delta/delta.d.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lib0",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -270,8 +270,8 @@
|
|
|
270
270
|
}
|
|
271
271
|
},
|
|
272
272
|
"devDependencies": {
|
|
273
|
-
"@types/node": "^
|
|
274
|
-
"c8": "^
|
|
273
|
+
"@types/node": "^25.5.2",
|
|
274
|
+
"c8": "^11.0.0",
|
|
275
275
|
"dpdm": "^4.0.1",
|
|
276
276
|
"standard": "^17.1.0",
|
|
277
277
|
"typescript": "^5.9.3"
|
package/src/delta/delta.js
CHANGED
|
@@ -180,7 +180,12 @@ export class TextOp extends list.ListNode {
|
|
|
180
180
|
* @param {TextOp} other
|
|
181
181
|
*/
|
|
182
182
|
[equalityTrait.EqualityTraitSymbol] (other) {
|
|
183
|
-
return $textOp.check(other) &&
|
|
183
|
+
return $textOp.check(other) &&
|
|
184
|
+
fun.equalityDeep(this.insert, other.insert) &&
|
|
185
|
+
(
|
|
186
|
+
(object.isEmpty(this.format) && object.isEmpty(other.format)) || fun.equalityDeep(this.format, other.format)
|
|
187
|
+
) &&
|
|
188
|
+
fun.equalityDeep(this.attribution, other.attribution)
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
/**
|
|
@@ -297,7 +302,12 @@ export class InsertOp extends list.ListNode {
|
|
|
297
302
|
* @param {InsertOp<ArrayContent>} other
|
|
298
303
|
*/
|
|
299
304
|
[equalityTrait.EqualityTraitSymbol] (other) {
|
|
300
|
-
return $insertOp.check(other) &&
|
|
305
|
+
return $insertOp.check(other) &&
|
|
306
|
+
fun.equalityDeep(this.insert, other.insert) &&
|
|
307
|
+
(
|
|
308
|
+
(object.isEmpty(this.format) && object.isEmpty(other.format)) || fun.equalityDeep(this.format, other.format)
|
|
309
|
+
) &&
|
|
310
|
+
fun.equalityDeep(this.attribution, other.attribution)
|
|
301
311
|
}
|
|
302
312
|
|
|
303
313
|
/**
|
|
@@ -454,7 +464,12 @@ export class RetainOp extends list.ListNode {
|
|
|
454
464
|
* @param {RetainOp} other
|
|
455
465
|
*/
|
|
456
466
|
[equalityTrait.EqualityTraitSymbol] (other) {
|
|
457
|
-
return $retainOp.check(other) &&
|
|
467
|
+
return $retainOp.check(other) &&
|
|
468
|
+
this.retain === other.retain &&
|
|
469
|
+
(
|
|
470
|
+
(object.isEmpty(this.format) && object.isEmpty(other.format)) || fun.equalityDeep(this.format, other.format)
|
|
471
|
+
) &&
|
|
472
|
+
fun.equalityDeep(this.attribution, other.attribution)
|
|
458
473
|
}
|
|
459
474
|
|
|
460
475
|
clone (start = 0, end = this.retain) {
|
|
@@ -554,7 +569,12 @@ export class ModifyOp extends list.ListNode {
|
|
|
554
569
|
* @param {ModifyOp<any>} other
|
|
555
570
|
*/
|
|
556
571
|
[equalityTrait.EqualityTraitSymbol] (other) {
|
|
557
|
-
return $modifyOp.check(other) &&
|
|
572
|
+
return $modifyOp.check(other) &&
|
|
573
|
+
this.value[equalityTrait.EqualityTraitSymbol](other.value) &&
|
|
574
|
+
(
|
|
575
|
+
(object.isEmpty(this.format) && object.isEmpty(other.format)) || fun.equalityDeep(this.format, other.format)
|
|
576
|
+
) &&
|
|
577
|
+
fun.equalityDeep(this.attribution, other.attribution)
|
|
558
578
|
}
|
|
559
579
|
|
|
560
580
|
/**
|
|
@@ -1244,6 +1264,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1244
1264
|
*/
|
|
1245
1265
|
constructor (name, $schema) {
|
|
1246
1266
|
super(name, $schema)
|
|
1267
|
+
// @todo rename to usedFormats !!
|
|
1247
1268
|
/**
|
|
1248
1269
|
* @type {FormattingAttributes?}
|
|
1249
1270
|
*/
|
|
@@ -1324,8 +1345,8 @@ export class DeltaBuilder extends Delta {
|
|
|
1324
1345
|
*/
|
|
1325
1346
|
insert (insert, formatting = null, attribution = null) {
|
|
1326
1347
|
modDeltaCheck(this)
|
|
1327
|
-
const mergedAttributes =
|
|
1328
|
-
const mergedAttribution =
|
|
1348
|
+
const mergedAttributes = mergeFormats(this.usedAttributes, formatting)
|
|
1349
|
+
const mergedAttribution = mergeAttributions(this.usedAttribution, attribution)
|
|
1329
1350
|
/**
|
|
1330
1351
|
* @param {TextOp | InsertOp<any>} lastOp
|
|
1331
1352
|
*/
|
|
@@ -1335,7 +1356,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1335
1356
|
if ($textOp.check(end) && checkMergedEquals(end)) {
|
|
1336
1357
|
end._updateInsert(end.insert + insert)
|
|
1337
1358
|
} else if (insert.length > 0) {
|
|
1338
|
-
list.pushEnd(this.children, new TextOp(insert, object.isEmpty(mergedAttributes) ? null : mergedAttributes,
|
|
1359
|
+
list.pushEnd(this.children, new TextOp(insert, object.isEmpty(mergedAttributes) ? null : mergedAttributes, mergedAttribution))
|
|
1339
1360
|
}
|
|
1340
1361
|
this.childCnt += insert.length
|
|
1341
1362
|
} else if (arr.isArray(insert)) {
|
|
@@ -1344,7 +1365,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1344
1365
|
end.insert.push(...insert)
|
|
1345
1366
|
end._fingerprint = null
|
|
1346
1367
|
} else if (insert.length > 0) {
|
|
1347
|
-
list.pushEnd(this.children, new InsertOp(insert.slice() /* ensures that we don't reuse an existing array */, object.isEmpty(mergedAttributes) ? null : mergedAttributes,
|
|
1368
|
+
list.pushEnd(this.children, new InsertOp(insert.slice() /* ensures that we don't reuse an existing array */, object.isEmpty(mergedAttributes) ? null : mergedAttributes, mergedAttribution))
|
|
1348
1369
|
}
|
|
1349
1370
|
this.childCnt += insert.length
|
|
1350
1371
|
}
|
|
@@ -1360,9 +1381,9 @@ export class DeltaBuilder extends Delta {
|
|
|
1360
1381
|
*/
|
|
1361
1382
|
modify (modify, formatting = null, attribution = null) {
|
|
1362
1383
|
modDeltaCheck(this)
|
|
1363
|
-
const mergedAttributes =
|
|
1364
|
-
const mergedAttribution =
|
|
1365
|
-
list.pushEnd(this.children, new ModifyOp(modify, object.isEmpty(mergedAttributes) ? null : mergedAttributes,
|
|
1384
|
+
const mergedAttributes = mergeFormats(this.usedAttributes, formatting)
|
|
1385
|
+
const mergedAttribution = mergeAttributions(this.usedAttribution, attribution)
|
|
1386
|
+
list.pushEnd(this.children, new ModifyOp(modify, object.isEmpty(mergedAttributes) ? null : mergedAttributes, mergedAttribution))
|
|
1366
1387
|
this.childCnt += 1
|
|
1367
1388
|
return /** @type {any} */ (this)
|
|
1368
1389
|
}
|
|
@@ -1374,14 +1395,14 @@ export class DeltaBuilder extends Delta {
|
|
|
1374
1395
|
*/
|
|
1375
1396
|
retain (len, format = null, attribution = null) {
|
|
1376
1397
|
modDeltaCheck(this)
|
|
1377
|
-
const mergedFormats =
|
|
1378
|
-
const mergedAttribution =
|
|
1398
|
+
const mergedFormats = mergeFormats(this.usedAttributes, format)
|
|
1399
|
+
const mergedAttribution = mergeAttributions(this.usedAttribution, attribution)
|
|
1379
1400
|
const lastOp = /** @type {RetainOp|InsertOp<any>} */ (this.children.end)
|
|
1380
1401
|
if ($retainOp.check(lastOp) && fun.equalityDeep(mergedFormats, lastOp.format) && fun.equalityDeep(mergedAttribution, lastOp.attribution)) {
|
|
1381
1402
|
// @ts-ignore
|
|
1382
1403
|
lastOp.retain += len
|
|
1383
1404
|
} else if (len > 0) {
|
|
1384
|
-
list.pushEnd(this.children, new RetainOp(len, mergedFormats, mergedAttribution))
|
|
1405
|
+
list.pushEnd(this.children, new RetainOp(len, object.isEmpty(mergedFormats) ? null : mergedFormats, mergedAttribution))
|
|
1385
1406
|
}
|
|
1386
1407
|
this.childCnt += len
|
|
1387
1408
|
return this
|
|
@@ -1419,7 +1440,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1419
1440
|
modDeltaCheck(this)
|
|
1420
1441
|
// @ts-ignore
|
|
1421
1442
|
this.attrs[key] /** @type {any} */ =
|
|
1422
|
-
(new SetAttrOp(/** @type {any} */ (key), val, prevValue,
|
|
1443
|
+
(new SetAttrOp(/** @type {any} */ (key), val, prevValue, mergeAttributions(this.usedAttribution, attribution)))
|
|
1423
1444
|
return /** @type {any} */ (this)
|
|
1424
1445
|
}
|
|
1425
1446
|
|
|
@@ -1454,7 +1475,7 @@ export class DeltaBuilder extends Delta {
|
|
|
1454
1475
|
modDeltaCheck(this)
|
|
1455
1476
|
// @ts-ignore
|
|
1456
1477
|
this.attrs[key] /** @type {any} */ =
|
|
1457
|
-
(new DeleteAttrOp(/** @type {any} */ (key), prevValue,
|
|
1478
|
+
(new DeleteAttrOp(/** @type {any} */ (key), prevValue, mergeAttributions(this.usedAttribution, attribution)))
|
|
1458
1479
|
return /** @type {any} */ (this)
|
|
1459
1480
|
}
|
|
1460
1481
|
|
|
@@ -2038,7 +2059,18 @@ export const $deltaBuilderAny = /** @type {s.Schema<DeltaBuilderAny>} */ (/* @__
|
|
|
2038
2059
|
* @param {T | null} a
|
|
2039
2060
|
* @param {T | null} b
|
|
2040
2061
|
*/
|
|
2041
|
-
export const
|
|
2062
|
+
export const mergeAttributions = (a, b) => a == null
|
|
2063
|
+
? b
|
|
2064
|
+
: (b == null ? a : object.assign({}, a, b))
|
|
2065
|
+
|
|
2066
|
+
/**
|
|
2067
|
+
* Helper function to merge formats. The latter input "wins".
|
|
2068
|
+
*
|
|
2069
|
+
* @template {{ [key: string]: any }} T
|
|
2070
|
+
* @param {T | null} a
|
|
2071
|
+
* @param {T | null} b
|
|
2072
|
+
*/
|
|
2073
|
+
export const mergeFormats = (a, b) => object.isEmpty(a)
|
|
2042
2074
|
? (object.isEmpty(b) ? null : b)
|
|
2043
2075
|
: (object.isEmpty(b) ? a : object.assign({}, a, b))
|
|
2044
2076
|
|
package/types/delta/delta.d.ts
CHANGED
|
@@ -750,7 +750,10 @@ export function $delta<DeltaConf extends ReadableDeltaConf = {}>({ name, attrs,
|
|
|
750
750
|
export const $$delta: s.Schema<$Delta<DeltaConf>>;
|
|
751
751
|
export const $deltaAny: s.Schema<Delta<any>>;
|
|
752
752
|
export const $deltaBuilderAny: s.Schema<DeltaBuilderAny>;
|
|
753
|
-
export function
|
|
753
|
+
export function mergeAttributions<T extends {
|
|
754
|
+
[key: string]: any;
|
|
755
|
+
}>(a: T | null, b: T | null): T | null;
|
|
756
|
+
export function mergeFormats<T extends {
|
|
754
757
|
[key: string]: any;
|
|
755
758
|
}>(a: T | null, b: T | null): T | null;
|
|
756
759
|
export function mergeDeltas<D extends DeltaAny | null>(a: D, b: D): D;
|