Skip to content

Commit 72e23b8

Browse files
committed
Avoid circular dependencies and import un-bundled rrdom
1 parent 85d600a commit 72e23b8

File tree

10 files changed

+57
-60
lines changed

10 files changed

+57
-60
lines changed

packages/rrdom/rollup.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import resolve from '@rollup/plugin-node-resolve';
22
import commonjs from '@rollup/plugin-commonjs';
33
import esbuild, { minify } from 'rollup-plugin-esbuild';
4-
54
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
65
import pkg from './package.json';
76

packages/rrdom/src/diff.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
IRRText,
1616
Mirror,
1717
} from './document';
18+
import { StyleRuleType, VirtualStyleRules } from './types';
1819
import type {
1920
RRCanvasElement,
2021
RRElement,
@@ -418,38 +419,6 @@ export function getNestedRule(
418419
}
419420
}
420421

421-
export enum StyleRuleType {
422-
Insert,
423-
Remove,
424-
Snapshot,
425-
SetProperty,
426-
RemoveProperty,
427-
}
428-
type InsertRule = {
429-
cssText: string;
430-
type: StyleRuleType.Insert;
431-
index?: number | number[];
432-
};
433-
type RemoveRule = {
434-
type: StyleRuleType.Remove;
435-
index: number | number[];
436-
};
437-
type SetPropertyRule = {
438-
type: StyleRuleType.SetProperty;
439-
index: number[];
440-
property: string;
441-
value: string | null;
442-
priority: string | undefined;
443-
};
444-
type RemovePropertyRule = {
445-
type: StyleRuleType.RemoveProperty;
446-
index: number[];
447-
property: string;
448-
};
449-
450-
export type VirtualStyleRules = Array<
451-
InsertRule | RemoveRule | SetPropertyRule | RemovePropertyRule
452-
>;
453422

454423
export function getPositionsAndIndex(nestedIndex: number[]) {
455424
const positions = [...nestedIndex];

packages/rrdom/src/types.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export enum StyleRuleType {
2+
Insert,
3+
Remove,
4+
Snapshot,
5+
SetProperty,
6+
RemoveProperty,
7+
}
8+
9+
type InsertRule = {
10+
cssText: string;
11+
type: StyleRuleType.Insert;
12+
index?: number | number[];
13+
};
14+
type RemoveRule = {
15+
type: StyleRuleType.Remove;
16+
index: number | number[];
17+
};
18+
type SetPropertyRule = {
19+
type: StyleRuleType.SetProperty;
20+
index: number[];
21+
property: string;
22+
value: string | null;
23+
priority: string | undefined;
24+
};
25+
type RemovePropertyRule = {
26+
type: StyleRuleType.RemoveProperty;
27+
index: number[];
28+
property: string;
29+
};
30+
31+
export type VirtualStyleRules = Array<
32+
InsertRule | RemoveRule | SetPropertyRule | RemovePropertyRule
33+
>;

packages/rrdom/src/virtual-dom.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
createMirror,
2727
Mirror,
2828
} from './document';
29-
import type { VirtualStyleRules } from './diff';
29+
import type { VirtualStyleRules } from './types';
3030

3131
export class RRDocument extends BaseRRDocumentImpl(RRNode) {
3232
public mirror: Mirror = createMirror();
@@ -318,4 +318,3 @@ export function buildFromDom(
318318
}
319319

320320
export { RRNode };
321-
export { diff, createOrGetNode, StyleRuleType } from './diff';

packages/rrweb/src/replay/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ import {
1515
RRIFrameElement,
1616
RRMediaElement,
1717
RRCanvasElement,
18-
StyleRuleType,
19-
VirtualStyleRules,
20-
createOrGetNode,
2118
buildFromNode,
2219
buildFromDom,
23-
diff,
24-
} from 'rrdom/es/virtual-dom';
25-
import type { Mirror as RRDOMMirror } from 'rrdom/es/document';
20+
} from 'rrdom/src/virtual-dom';
21+
import type { Mirror as RRDOMMirror } from 'rrdom/src/document';
22+
import type { VirtualStyleRules } from 'rrdom/src/types';
23+
import { StyleRuleType } from 'rrdom/src/types';
24+
import { createOrGetNode, diff } from 'rrdom/src/diff';
2625
import * as mittProxy from 'mitt';
2726
import { polyfill as smoothscrollPolyfill } from './smoothscroll';
2827
import { Timer } from './timer';
@@ -73,7 +72,7 @@ import getInjectStyleRules from './styles/inject-style';
7372
import './styles/style.css';
7473
import canvasMutation from './canvas';
7574
import { deserializeArg } from './canvas/deserialize-args';
76-
import type { ReplayerHandler } from 'rrdom/es/diff';
75+
import type { ReplayerHandler } from 'rrdom/src/diff';
7776

7877
const SKIP_TIME_THRESHOLD = 10 * 1000;
7978
const SKIP_TIME_INTERVAL = 5 * 1000;
@@ -125,7 +124,7 @@ export class Replayer {
125124
private nextUserInteractionEvent: eventWithTime | null;
126125

127126
// tslint:disable-next-line: variable-name
128-
private legacy_missingNodeRetryMap: missingNodeMap = {};
127+
private legacy_missingNodeRetryMap: missingNodeMap<Node | RRNode> = {};
129128

130129
// The replayer uses the cache to speed up replay and scrubbing.
131130
private cache: BuildCache = createCache();
@@ -1413,7 +1412,7 @@ export class Replayer {
14131412
});
14141413

14151414
// tslint:disable-next-line: variable-name
1416-
const legacy_missingNodeMap: missingNodeMap = {
1415+
const legacy_missingNodeMap: missingNodeMap<Node | RRNode> = {
14171416
...this.legacy_missingNodeRetryMap,
14181417
};
14191418
const queue: addedNodeMutation[] = [];
@@ -1733,7 +1732,7 @@ export class Replayer {
17331732
}
17341733

17351734
private legacy_resolveMissingNode(
1736-
map: missingNodeMap,
1735+
map: missingNodeMap<Node | RRNode>,
17371736
parent: Node | RRNode,
17381737
target: Node | RRNode,
17391738
targetMutation: addedNodeMutation,
@@ -1742,7 +1741,7 @@ export class Replayer {
17421741
const previousInMap = previousId && map[previousId];
17431742
const nextInMap = nextId && map[nextId];
17441743
if (previousInMap) {
1745-
const { node, mutation } = previousInMap as missingNode;
1744+
const { node, mutation } = previousInMap as missingNode<Node | RRNode>;
17461745
parent.insertBefore(node as Node & RRNode, target as Node & RRNode);
17471746
delete map[mutation.node.id];
17481747
delete this.legacy_missingNodeRetryMap[mutation.node.id];
@@ -1751,7 +1750,7 @@ export class Replayer {
17511750
}
17521751
}
17531752
if (nextInMap) {
1754-
const { node, mutation } = nextInMap as missingNode;
1753+
const { node, mutation } = nextInMap as missingNode<Node | RRNode>;
17551754
parent.insertBefore(
17561755
node as Node & RRNode,
17571756
target.nextSibling as Node & RRNode,

packages/rrweb/src/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { PackFn, UnpackFn } from './packer/base';
1111
import type { IframeManager } from './record/iframe-manager';
1212
import type { ShadowDomManager } from './record/shadow-dom-manager';
1313
import type { Replayer } from './replay';
14-
import type { RRNode } from 'rrdom/es/virtual-dom';
1514
import type { CanvasManager } from './record/observers/canvas/canvas-manager';
1615

1716
export enum EventType {
@@ -669,12 +668,12 @@ export type playerMetaData = {
669668
totalTime: number;
670669
};
671670

672-
export type missingNode = {
673-
node: Node | RRNode;
671+
export type missingNode<TNode> = {
672+
node: TNode;
674673
mutation: addedNodeMutation;
675674
};
676-
export type missingNodeMap = {
677-
[id: number]: missingNode;
675+
export type missingNodeMap<TNode> = {
676+
[id: number]: missingNode<TNode>;
678677
};
679678

680679
export type actionWithDelay = {

packages/rrweb/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from './types';
1111
import type { IMirror, Mirror } from 'rrweb-snapshot';
1212
import { isShadowRoot, IGNORED_NODE } from 'rrweb-snapshot';
13-
import type { RRNode, RRIFrameElement } from 'rrdom/es/virtual-dom';
13+
import type { RRNode, RRIFrameElement } from 'rrdom/src/virtual-dom';
1414

1515
export function on(
1616
type: string,

packages/rrweb/typings/replay/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Mirror } from 'rrweb-snapshot';
2-
import { RRDocument } from 'rrdom/es/virtual-dom';
2+
import { RRDocument } from 'rrdom/src/virtual-dom';
33
import { Timer } from './timer';
44
import { createPlayerService, createSpeedService } from './machine';
55
import { eventWithTime, playerConfig, playerMetaData, Handler } from '../types';

packages/rrweb/typings/types.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { PackFn, UnpackFn } from './packer/base';
33
import type { IframeManager } from './record/iframe-manager';
44
import type { ShadowDomManager } from './record/shadow-dom-manager';
55
import type { Replayer } from './replay';
6-
import type { RRNode } from 'rrdom/es/virtual-dom';
76
import type { CanvasManager } from './record/observers/canvas/canvas-manager';
87
export declare enum EventType {
98
DomContentLoaded = 0,
@@ -477,12 +476,12 @@ export declare type playerMetaData = {
477476
endTime: number;
478477
totalTime: number;
479478
};
480-
export declare type missingNode = {
481-
node: Node | RRNode;
479+
export declare type missingNode<TNode> = {
480+
node: TNode;
482481
mutation: addedNodeMutation;
483482
};
484-
export declare type missingNodeMap = {
485-
[id: number]: missingNode;
483+
export declare type missingNodeMap<TNode> = {
484+
[id: number]: missingNode<TNode>;
486485
};
487486
export declare type actionWithDelay = {
488487
doAction: () => void;

packages/rrweb/typings/utils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { throttleOptions, listenerHandler, hookResetter, blockClass, addedNodeMutation, DocumentDimension, IWindow, DeprecatedMirror } from './types';
22
import type { IMirror, Mirror } from 'rrweb-snapshot';
3-
import type { RRNode, RRIFrameElement } from 'rrdom/es/virtual-dom';
3+
import type { RRNode, RRIFrameElement } from 'rrdom/src/virtual-dom';
44
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | IWindow): listenerHandler;
55
export declare let _mirror: DeprecatedMirror;
66
export declare function throttle<T>(func: (arg: T) => void, wait: number, options?: throttleOptions): (arg: T) => void;

0 commit comments

Comments
 (0)