Skip to content

Commit 02bcc65

Browse files
committed
fix: update loro-crdt to v1.10.2
1 parent 1bc1e98 commit 02bcc65

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

examples/stories/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build-storybook": "storybook build"
1313
},
1414
"dependencies": {
15-
"loro-crdt": "^1.10.0",
15+
"loro-crdt": "^1.10.2",
1616
"loro-prosemirror": "workspace:*",
1717
"prosemirror-commands": "^1.7.1",
1818
"prosemirror-example-setup": "^1.2.3",
@@ -54,4 +54,4 @@
5454
"vite-plugin-top-level-await": "^1.6.0",
5555
"vite-plugin-wasm": "^3.5.0"
5656
}
57-
}
57+
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"src"
3939
],
4040
"peerDependencies": {
41-
"loro-crdt": "^1.10.0",
41+
"loro-crdt": "^1.10.2",
4242
"prosemirror-model": "^1.18.1",
4343
"prosemirror-state": "^1.4.1",
4444
"prosemirror-view": "^1.28.0"
@@ -50,7 +50,7 @@
5050
"chromatic": "^11.5.3",
5151
"eslint": "^8.57.0",
5252
"lib0": "^0.2.93",
53-
"loro-crdt": "^1.10.0",
53+
"loro-crdt": "^1.10.2",
5454
"prettier": "^3.2.5",
5555
"prosemirror-model": "^1.18.1",
5656
"prosemirror-state": "^1.4.1",
@@ -62,4 +62,4 @@
6262
"vite": "^5.2.7",
6363
"vitest": "^1.4.0"
6464
}
65-
}
65+
}

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export function createNodeFromLoroObj(
146146
try {
147147
const marks = [];
148148
for (const [markName, mark] of Object.entries(delta.attributes ?? {})) {
149-
marks.push(schema.mark(markName, mark));
149+
const markAttrs = valueToAttrs(mark);
150+
marks.push(schema.mark(markName, markAttrs ?? undefined));
150151
}
151152
retval.push(schema.text(delta.insert, marks));
152153
} catch (e) {
@@ -251,6 +252,20 @@ function nodeMarksToAttributes(marks: readonly Mark[]): {
251252
return pattrs;
252253
}
253254

255+
function valueToAttrs(
256+
value: Value | Attrs | null | undefined,
257+
): Attrs | null {
258+
if (
259+
value != null &&
260+
typeof value === "object" &&
261+
!Array.isArray(value) &&
262+
!(value instanceof Uint8Array)
263+
) {
264+
return value as Attrs;
265+
}
266+
return null;
267+
}
268+
254269
function eqLoroTextNodes(obj: LoroText, nodes: Node[]) {
255270
const delta = obj.toDelta();
256271
return (
@@ -259,9 +274,10 @@ function eqLoroTextNodes(obj: LoroText, nodes: Node[]) {
259274
(delta, i) =>
260275
delta.insert === nodes[i].text &&
261276
Object.keys(delta.attributes || {}).length === nodes[i].marks.length &&
262-
nodes[i].marks.every((mark) =>
263-
eqAttrs((delta.attributes || {})[mark.type.name], mark.attrs),
264-
),
277+
nodes[i].marks.every((mark) => {
278+
const attrs = valueToAttrs((delta.attributes || {})[mark.type.name]);
279+
return attrs != null && eqAttrs(attrs, mark.attrs);
280+
}),
265281
)
266282
);
267283
}

0 commit comments

Comments
 (0)