@liveblocks/core 3.20.0-exp1 → 3.20.0-exp3
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.cjs +30 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -17
- package/dist/index.d.ts +14 -17
- package/dist/index.js +30 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
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 = "3.20.0-
|
|
9
|
+
var PKG_VERSION = "3.20.0-exp3";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -8486,17 +8486,17 @@ function normalizeSegments(segments) {
|
|
|
8486
8486
|
}
|
|
8487
8487
|
return normalized;
|
|
8488
8488
|
}
|
|
8489
|
-
function
|
|
8489
|
+
function dataToSegments(data) {
|
|
8490
8490
|
return normalizeSegments(
|
|
8491
|
-
|
|
8492
|
-
text
|
|
8493
|
-
attributes
|
|
8491
|
+
data.map(([text, attributes]) => ({
|
|
8492
|
+
text,
|
|
8493
|
+
attributes
|
|
8494
8494
|
}))
|
|
8495
8495
|
);
|
|
8496
8496
|
}
|
|
8497
|
-
function
|
|
8497
|
+
function segmentsToData(segments) {
|
|
8498
8498
|
return segments.map(
|
|
8499
|
-
(segment) => segment.attributes === void 0 ?
|
|
8499
|
+
(segment) => segment.attributes === void 0 ? [segment.text] : [segment.text, { ...segment.attributes }]
|
|
8500
8500
|
);
|
|
8501
8501
|
}
|
|
8502
8502
|
function textLength(segments) {
|
|
@@ -8703,8 +8703,10 @@ function applyTextOperationsToSegments(segments, ops) {
|
|
|
8703
8703
|
}
|
|
8704
8704
|
return next;
|
|
8705
8705
|
}
|
|
8706
|
-
function applyLiveTextOperations(
|
|
8707
|
-
return
|
|
8706
|
+
function applyLiveTextOperations(data, ops) {
|
|
8707
|
+
return segmentsToData(
|
|
8708
|
+
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8709
|
+
);
|
|
8708
8710
|
}
|
|
8709
8711
|
function invertTextOperations(segments, ops) {
|
|
8710
8712
|
let shadow = [...segments];
|
|
@@ -8757,9 +8759,9 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8757
8759
|
#segments;
|
|
8758
8760
|
#version;
|
|
8759
8761
|
#pendingOps;
|
|
8760
|
-
constructor(
|
|
8762
|
+
constructor(textOrData = "", version = 0) {
|
|
8761
8763
|
super();
|
|
8762
|
-
this.#segments = typeof
|
|
8764
|
+
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8763
8765
|
this.#version = version;
|
|
8764
8766
|
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8765
8767
|
}
|
|
@@ -8786,7 +8788,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8786
8788
|
id: this._id,
|
|
8787
8789
|
parentId,
|
|
8788
8790
|
parentKey,
|
|
8789
|
-
data: this.
|
|
8791
|
+
data: this.toJSON(),
|
|
8790
8792
|
version: this.#version
|
|
8791
8793
|
}
|
|
8792
8794
|
];
|
|
@@ -8800,7 +8802,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8800
8802
|
type: CrdtType.TEXT,
|
|
8801
8803
|
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8802
8804
|
parentKey: this.parent.key,
|
|
8803
|
-
data: this.
|
|
8805
|
+
data: this.toJSON(),
|
|
8804
8806
|
version: this.#version
|
|
8805
8807
|
};
|
|
8806
8808
|
}
|
|
@@ -8991,15 +8993,12 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8991
8993
|
toString() {
|
|
8992
8994
|
return this.#segments.map((segment) => segment.text).join("");
|
|
8993
8995
|
}
|
|
8994
|
-
toDelta() {
|
|
8995
|
-
return segmentsToDelta(this.#segments);
|
|
8996
|
-
}
|
|
8997
8996
|
toJSON() {
|
|
8998
8997
|
return super.toJSON();
|
|
8999
8998
|
}
|
|
9000
8999
|
/** @internal */
|
|
9001
9000
|
_toJSON() {
|
|
9002
|
-
return this
|
|
9001
|
+
return segmentsToData(this.#segments);
|
|
9003
9002
|
}
|
|
9004
9003
|
/** @internal */
|
|
9005
9004
|
_toTreeNode(key) {
|
|
@@ -9018,7 +9017,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9018
9017
|
};
|
|
9019
9018
|
}
|
|
9020
9019
|
clone() {
|
|
9021
|
-
return new _LiveText(this.
|
|
9020
|
+
return new _LiveText(this.toJSON(), this.#version);
|
|
9022
9021
|
}
|
|
9023
9022
|
};
|
|
9024
9023
|
|
|
@@ -9222,22 +9221,24 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9222
9221
|
type: "delete",
|
|
9223
9222
|
index: 0,
|
|
9224
9223
|
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9225
|
-
(sum,
|
|
9224
|
+
(sum, segment) => sum + segment[0].length,
|
|
9226
9225
|
0
|
|
9227
9226
|
) : 0
|
|
9228
9227
|
},
|
|
9229
|
-
...crdt.data.map(
|
|
9230
|
-
|
|
9228
|
+
...crdt.data.map((segment, index, items) => {
|
|
9229
|
+
const [text, attributes] = segment;
|
|
9230
|
+
const insertIndex = items.slice(0, index).reduce((sum, item) => sum + item[0].length, 0);
|
|
9231
|
+
return attributes === void 0 ? {
|
|
9231
9232
|
type: "insert",
|
|
9232
|
-
index:
|
|
9233
|
-
text
|
|
9233
|
+
index: insertIndex,
|
|
9234
|
+
text
|
|
9234
9235
|
} : {
|
|
9235
9236
|
type: "insert",
|
|
9236
|
-
index:
|
|
9237
|
-
text
|
|
9238
|
-
attributes
|
|
9239
|
-
}
|
|
9240
|
-
)
|
|
9237
|
+
index: insertIndex,
|
|
9238
|
+
text,
|
|
9239
|
+
attributes
|
|
9240
|
+
};
|
|
9241
|
+
})
|
|
9241
9242
|
]
|
|
9242
9243
|
});
|
|
9243
9244
|
}
|
|
@@ -12846,7 +12847,7 @@ function toPlainLson(lson) {
|
|
|
12846
12847
|
} else if (lson instanceof LiveText) {
|
|
12847
12848
|
return {
|
|
12848
12849
|
liveblocksType: "LiveText",
|
|
12849
|
-
data: lson.
|
|
12850
|
+
data: lson.toJSON(),
|
|
12850
12851
|
version: lson.version
|
|
12851
12852
|
};
|
|
12852
12853
|
} else {
|