allow skip child when serialize node and rebuild node
This commit is contained in:
2
index.d.ts
vendored
2
index.d.ts
vendored
@@ -10,10 +10,12 @@ export function serializeNodeWithId(
|
||||
n: Node,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
skipChild?: boolean,
|
||||
): serializedNodeWithId | null;
|
||||
export function resetId(): void;
|
||||
export function buildNodeWithSN(
|
||||
n: serializedNodeWithId,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
skipChild?: boolean,
|
||||
): INode | null;
|
||||
|
||||
@@ -166,6 +166,7 @@ export function buildNodeWithSN(
|
||||
n: serializedNodeWithId,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
skipChild = false,
|
||||
): INode | null {
|
||||
let node = buildNode(n, doc);
|
||||
if (!node) {
|
||||
@@ -179,7 +180,10 @@ export function buildNodeWithSN(
|
||||
|
||||
(node as INode).__sn = n;
|
||||
map[n.id] = node as INode;
|
||||
if (n.type === NodeType.Document || n.type === NodeType.Element) {
|
||||
if (
|
||||
(n.type === NodeType.Document || n.type === NodeType.Element) &&
|
||||
!skipChild
|
||||
) {
|
||||
for (const childN of n.childNodes) {
|
||||
const childNode = buildNodeWithSN(childN, doc, map);
|
||||
if (!childNode) {
|
||||
|
||||
@@ -175,6 +175,7 @@ export function serializeNodeWithId(
|
||||
n: Node,
|
||||
doc: Document,
|
||||
map: idNodeMap,
|
||||
skipChild = false,
|
||||
): serializedNodeWithId | null {
|
||||
const _serializedNode = serializeNode(n, doc);
|
||||
if (!_serializedNode) {
|
||||
@@ -188,8 +189,9 @@ export function serializeNodeWithId(
|
||||
(n as INode).__sn = serializedNode;
|
||||
map[serializedNode.id] = n as INode;
|
||||
if (
|
||||
serializedNode.type === NodeType.Document ||
|
||||
serializedNode.type === NodeType.Element
|
||||
(serializedNode.type === NodeType.Document ||
|
||||
serializedNode.type === NodeType.Element) &&
|
||||
!skipChild
|
||||
) {
|
||||
for (const childN of Array.from(n.childNodes)) {
|
||||
const serializedChildNode = serializeNodeWithId(childN, doc, map);
|
||||
|
||||
Reference in New Issue
Block a user