add visit function for snapshot
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
import snapshot, { serializeNodeWithId, transformAttribute } from './snapshot';
|
import snapshot, {
|
||||||
|
serializeNodeWithId,
|
||||||
|
transformAttribute,
|
||||||
|
visit,
|
||||||
|
} from './snapshot';
|
||||||
import rebuild, { buildNodeWithSN, addHoverClass } from './rebuild';
|
import rebuild, { buildNodeWithSN, addHoverClass } from './rebuild';
|
||||||
export * from './types';
|
export * from './types';
|
||||||
|
|
||||||
@@ -9,4 +13,5 @@ export {
|
|||||||
buildNodeWithSN,
|
buildNodeWithSN,
|
||||||
addHoverClass,
|
addHoverClass,
|
||||||
transformAttribute,
|
transformAttribute,
|
||||||
|
visit,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -425,4 +425,21 @@ function snapshot(
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function visit(
|
||||||
|
node: serializedNodeWithId,
|
||||||
|
onVisit: (node: serializedNodeWithId) => unknown,
|
||||||
|
) {
|
||||||
|
function walk(current: serializedNodeWithId) {
|
||||||
|
onVisit(current);
|
||||||
|
if (
|
||||||
|
current.type === NodeType.Document ||
|
||||||
|
current.type === NodeType.Element
|
||||||
|
) {
|
||||||
|
current.childNodes.forEach(walk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
walk(node);
|
||||||
|
}
|
||||||
|
|
||||||
export default snapshot;
|
export default snapshot;
|
||||||
|
|||||||
Reference in New Issue
Block a user