export serializeNodeWithId so rrweb could serialize newly added nodes
This commit is contained in:
5
index.d.ts
vendored
5
index.d.ts
vendored
@@ -3,3 +3,8 @@ export * from './src/types';
|
||||
|
||||
export function snapshot(n: Document): [serializedNodeWithId | null, idNodeMap];
|
||||
export function rebuild(n: serializedNodeWithId): Node | null;
|
||||
export function serializeNodeWithId(
|
||||
n: Node,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
): serializedNodeWithId | null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import snapshot from './snapshot';
|
||||
import snapshot, { serializeNodeWithId } from './snapshot';
|
||||
import rebuild from './rebuild';
|
||||
export * from './types';
|
||||
|
||||
export { snapshot, rebuild };
|
||||
export { snapshot, serializeNodeWithId, rebuild };
|
||||
|
||||
@@ -117,9 +117,10 @@ function serializeNode(n: Node, doc: Document): serializedNode | false {
|
||||
}
|
||||
}
|
||||
|
||||
function serializeNodeWithId(
|
||||
export function serializeNodeWithId(
|
||||
n: Node,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
): serializedNodeWithId | null {
|
||||
const _serializedNode = serializeNode(n, doc);
|
||||
if (!_serializedNode) {
|
||||
@@ -127,9 +128,12 @@ function serializeNodeWithId(
|
||||
console.warn(n, 'not serialized');
|
||||
return null;
|
||||
}
|
||||
return Object.assign(_serializedNode, {
|
||||
const serializedNode = Object.assign(_serializedNode, {
|
||||
id: genId(),
|
||||
});
|
||||
(n as INode).__sn = serializedNode;
|
||||
map[serializedNode.id] = n as INode;
|
||||
return serializedNode;
|
||||
}
|
||||
|
||||
function _snapshot(
|
||||
@@ -137,12 +141,10 @@ function _snapshot(
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
): serializedNodeWithId | null {
|
||||
const serializedNode = serializeNodeWithId(n, doc);
|
||||
const serializedNode = serializeNodeWithId(n, doc, map);
|
||||
if (!serializedNode) {
|
||||
return null;
|
||||
}
|
||||
(n as INode).__sn = serializedNode;
|
||||
map[serializedNode.id] = n as INode;
|
||||
if (
|
||||
serializedNode.type === NodeType.Document ||
|
||||
serializedNode.type === NodeType.Element
|
||||
|
||||
Reference in New Issue
Block a user