@liveblocks/core 3.20.0-exp2 → 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 +29 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -14
- package/dist/index.d.ts +11 -14
- package/dist/index.js +29 -30
- 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,9 +8703,9 @@ function applyTextOperationsToSegments(segments, ops) {
|
|
|
8703
8703
|
}
|
|
8704
8704
|
return next;
|
|
8705
8705
|
}
|
|
8706
|
-
function applyLiveTextOperations(
|
|
8707
|
-
return
|
|
8708
|
-
applyTextOperationsToSegments(
|
|
8706
|
+
function applyLiveTextOperations(data, ops) {
|
|
8707
|
+
return segmentsToData(
|
|
8708
|
+
applyTextOperationsToSegments(dataToSegments(data), ops)
|
|
8709
8709
|
);
|
|
8710
8710
|
}
|
|
8711
8711
|
function invertTextOperations(segments, ops) {
|
|
@@ -8759,9 +8759,9 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8759
8759
|
#segments;
|
|
8760
8760
|
#version;
|
|
8761
8761
|
#pendingOps;
|
|
8762
|
-
constructor(
|
|
8762
|
+
constructor(textOrData = "", version = 0) {
|
|
8763
8763
|
super();
|
|
8764
|
-
this.#segments = typeof
|
|
8764
|
+
this.#segments = typeof textOrData === "string" ? textOrData.length === 0 ? [] : [{ text: textOrData }] : dataToSegments(textOrData);
|
|
8765
8765
|
this.#version = version;
|
|
8766
8766
|
this.#pendingOps = /* @__PURE__ */ new Map();
|
|
8767
8767
|
}
|
|
@@ -8788,7 +8788,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8788
8788
|
id: this._id,
|
|
8789
8789
|
parentId,
|
|
8790
8790
|
parentKey,
|
|
8791
|
-
data: this.
|
|
8791
|
+
data: this.toJSON(),
|
|
8792
8792
|
version: this.#version
|
|
8793
8793
|
}
|
|
8794
8794
|
];
|
|
@@ -8802,7 +8802,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8802
8802
|
type: CrdtType.TEXT,
|
|
8803
8803
|
parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
|
|
8804
8804
|
parentKey: this.parent.key,
|
|
8805
|
-
data: this.
|
|
8805
|
+
data: this.toJSON(),
|
|
8806
8806
|
version: this.#version
|
|
8807
8807
|
};
|
|
8808
8808
|
}
|
|
@@ -8993,15 +8993,12 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
8993
8993
|
toString() {
|
|
8994
8994
|
return this.#segments.map((segment) => segment.text).join("");
|
|
8995
8995
|
}
|
|
8996
|
-
toDelta() {
|
|
8997
|
-
return segmentsToDelta(this.#segments);
|
|
8998
|
-
}
|
|
8999
8996
|
toJSON() {
|
|
9000
8997
|
return super.toJSON();
|
|
9001
8998
|
}
|
|
9002
8999
|
/** @internal */
|
|
9003
9000
|
_toJSON() {
|
|
9004
|
-
return this
|
|
9001
|
+
return segmentsToData(this.#segments);
|
|
9005
9002
|
}
|
|
9006
9003
|
/** @internal */
|
|
9007
9004
|
_toTreeNode(key) {
|
|
@@ -9020,7 +9017,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
|
|
|
9020
9017
|
};
|
|
9021
9018
|
}
|
|
9022
9019
|
clone() {
|
|
9023
|
-
return new _LiveText(this.
|
|
9020
|
+
return new _LiveText(this.toJSON(), this.#version);
|
|
9024
9021
|
}
|
|
9025
9022
|
};
|
|
9026
9023
|
|
|
@@ -9224,22 +9221,24 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
9224
9221
|
type: "delete",
|
|
9225
9222
|
index: 0,
|
|
9226
9223
|
length: currentCrdt.type === CrdtType.TEXT ? currentCrdt.data.reduce(
|
|
9227
|
-
(sum,
|
|
9224
|
+
(sum, segment) => sum + segment[0].length,
|
|
9228
9225
|
0
|
|
9229
9226
|
) : 0
|
|
9230
9227
|
},
|
|
9231
|
-
...crdt.data.map(
|
|
9232
|
-
|
|
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 ? {
|
|
9233
9232
|
type: "insert",
|
|
9234
|
-
index:
|
|
9235
|
-
text
|
|
9233
|
+
index: insertIndex,
|
|
9234
|
+
text
|
|
9236
9235
|
} : {
|
|
9237
9236
|
type: "insert",
|
|
9238
|
-
index:
|
|
9239
|
-
text
|
|
9240
|
-
attributes
|
|
9241
|
-
}
|
|
9242
|
-
)
|
|
9237
|
+
index: insertIndex,
|
|
9238
|
+
text,
|
|
9239
|
+
attributes
|
|
9240
|
+
};
|
|
9241
|
+
})
|
|
9243
9242
|
]
|
|
9244
9243
|
});
|
|
9245
9244
|
}
|
|
@@ -12848,7 +12847,7 @@ function toPlainLson(lson) {
|
|
|
12848
12847
|
} else if (lson instanceof LiveText) {
|
|
12849
12848
|
return {
|
|
12850
12849
|
liveblocksType: "LiveText",
|
|
12851
|
-
data: lson.
|
|
12850
|
+
data: lson.toJSON(),
|
|
12852
12851
|
version: lson.version
|
|
12853
12852
|
};
|
|
12854
12853
|
} else {
|