nested record iframe (#63)

* pick nested branch

* iframe snapshot

* temp: add bundle file to git

* revert ignore file

* refactor iframe impl
1. do callback one iframe is loaded, let rrweb handle the rest
2. handle iframe as normal element in rebuild

* rename hook function
This commit is contained in:
yz-yu
2021-02-07 14:00:22 +08:00
committed by GitHub
parent a3ff5e5ea8
commit 98aa732d17
11 changed files with 343 additions and 7 deletions

View File

@@ -198,13 +198,20 @@ export function buildNodeWithSN(
map: idNodeMap;
skipChild?: boolean;
hackCss: boolean;
afterAppend?: (n: INode) => unknown;
},
): INode | null {
const { doc, map, skipChild = false, hackCss = true } = options;
const { doc, map, skipChild = false, hackCss = true, afterAppend } = options;
let node = buildNode(n, { doc, hackCss });
if (!node) {
return null;
}
if (n.rootId) {
console.assert(
((map[n.rootId] as unknown) as Document) === doc,
'Target document should has the same root id.',
);
}
// use target document as root document
if (n.type === NodeType.Document) {
// close before open to make sure document was closed
@@ -215,6 +222,7 @@ export function buildNodeWithSN(
(node as INode).__sn = n;
map[n.id] = node as INode;
if (
(n.type === NodeType.Document || n.type === NodeType.Element) &&
!skipChild
@@ -225,14 +233,20 @@ export function buildNodeWithSN(
map,
skipChild: false,
hackCss,
afterAppend,
});
if (!childNode) {
console.warn('Failed to rebuild', childN);
} else {
node.appendChild(childNode);
continue;
}
node.appendChild(childNode);
if (afterAppend) {
afterAppend(childNode);
}
}
}
return node as INode;
}
@@ -274,15 +288,17 @@ function rebuild(
doc: Document;
onVisit?: (node: INode) => unknown;
hackCss?: boolean;
afterAppend?: (n: INode) => unknown;
},
): [Node | null, idNodeMap] {
const { doc, onVisit, hackCss = true } = options;
const { doc, onVisit, hackCss = true, afterAppend } = options;
const idNodeMap: idNodeMap = {};
const node = buildNodeWithSN(n, {
doc,
map: idNodeMap,
skipChild: false,
hackCss,
afterAppend,
});
visit(idNodeMap, (visitedNode) => {
if (onVisit) {