Skip to content

Commit 18dcefb

Browse files
committed
move browser-only rrdom features to the new vdom package
1 parent 058c457 commit 18dcefb

28 files changed

+255
-67
lines changed

.vscode/rrweb-monorepo.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"name": "rrdom (package)",
99
"path": "../packages/rrdom"
1010
},
11+
{
12+
"name": "vdom (package)",
13+
"path": "../packages/vdom"
14+
},
1115
{
1216
"name": "rrweb (package)",
1317
"path": "../packages/rrweb"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"packages/rrweb",
1919
"packages/rrweb-snapshot",
2020
"packages/rrweb-player",
21-
"packages/rrdom"
21+
"packages/rrdom",
22+
"packages/vdom"
2223
],
2324
"devDependencies": {
2425
"@typescript-eslint/eslint-plugin": "^5.25.0",

packages/rrdom/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343
"rollup-plugin-terser": "^7.0.2",
4444
"rollup-plugin-typescript2": "^0.31.2",
4545
"rollup-plugin-web-worker-loader": "^1.6.1",
46-
"rrweb-snapshot": "^1.1.14",
4746
"ts-jest": "^27.1.3",
4847
"typescript": "^4.6.2"
4948
},
5049
"dependencies": {
5150
"cssom": "^0.5.0",
5251
"cssstyle": "^2.3.0",
53-
"nwsapi": "^2.2.0"
52+
"nwsapi": "^2.2.0",
53+
"rrweb-snapshot": "^1.1.14",
54+
"vdom": "^0.1.2"
5455
}
5556
}

packages/rrdom/rollup.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ const baseConfigs = [
3232
name: 'RRDocument',
3333
path: 'document-nodejs',
3434
},
35-
{
36-
input: './src/virtual-dom.ts',
37-
name: 'RRDocument',
38-
path: 'virtual-dom',
39-
},
4035
];
4136

4237
let configs = [];

packages/rrdom/src/document-nodejs.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ClassList,
1414
IRRDocument,
1515
CSSStyleDeclaration,
16-
} from './document';
16+
} from 'vdom';
1717
const nwsapi = require('nwsapi');
1818
const cssom = require('cssom');
1919
const cssstyle = require('cssstyle');
@@ -53,22 +53,27 @@ export class RRDocument
5353
return this._nwsapi;
5454
}
5555

56+
// @ts-ignore
5657
get documentElement(): RRElement | null {
5758
return super.documentElement as RRElement | null;
5859
}
5960

61+
// @ts-ignore
6062
get body(): RRElement | null {
6163
return super.body as RRElement | null;
6264
}
6365

66+
// @ts-ignore
6467
get head() {
6568
return super.head as RRElement | null;
6669
}
6770

71+
// @ts-ignore
6872
get implementation(): RRDocument {
6973
return this;
7074
}
7175

76+
// @ts-ignore
7277
get firstElementChild(): RRElement | null {
7378
return this.documentElement;
7479
}
@@ -198,6 +203,7 @@ export class RRElement extends BaseRRElementImpl(RRNode) {
198203
});
199204
}
200205

206+
// @ts-ignore
201207
get style() {
202208
return (this._style as unknown) as CSSStyleDeclaration;
203209
}

packages/rrdom/test/document-nodejs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
RRStyleElement,
1717
RRText,
1818
} from '../src/document-nodejs';
19-
import { buildFromDom } from '../src/virtual-dom';
19+
import { buildFromDom } from 'vdom';
2020

2121
describe('RRDocument for nodejs environment', () => {
2222
describe('RRDocument API', () => {
@@ -542,6 +542,6 @@ describe('RRDocument for nodejs environment', () => {
542542
});
543543

544544
function getHtml(fileName: string) {
545-
const filePath = path.resolve(__dirname, `./html/${fileName}`);
545+
const filePath = path.resolve(__dirname, `../../vdom/test/html/${fileName}`);
546546
return fs.readFileSync(filePath, 'utf8');
547547
}

packages/rrweb/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ module.exports = {
55
testMatch: ['**/**.test.ts'],
66
moduleNameMapper: {
77
'\\.css$': 'identity-obj-proxy',
8-
'rrdom/es/(.*)': 'rrdom/lib/$1',
98
},
109
};

packages/rrweb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"base64-arraybuffer": "^1.0.1",
8080
"fflate": "^0.4.4",
8181
"mitt": "^1.1.3",
82-
"rrdom": "^0.1.2",
82+
"vdom": "^0.1.2",
8383
"rrweb-snapshot": "^1.1.14"
8484
}
8585
}

packages/rrweb/src/replay/index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
buildFromDom,
1616
diff,
1717
getDefaultSN,
18-
} from 'rrdom/es/virtual-dom';
18+
} from 'vdom';
1919
import type {
20-
RRNode,
20+
BaseRRNode as RRNode,
2121
RRElement,
2222
RRStyleElement,
2323
RRIFrameElement,
@@ -26,7 +26,7 @@ import type {
2626
ReplayerHandler,
2727
Mirror as RRDOMMirror,
2828
VirtualStyleRules,
29-
} from 'rrdom/es/virtual-dom';
29+
} from 'vdom';
3030
import * as mittProxy from 'mitt';
3131
import { polyfill as smoothscrollPolyfill } from './smoothscroll';
3232
import { Timer } from './timer';
@@ -731,7 +731,7 @@ export class Replayer {
731731
);
732732
}
733733
if (this.usingVirtualDom) {
734-
const styleEl = this.virtualDom.createElement('style') ;
734+
const styleEl = this.virtualDom.createElement('style');
735735
this.virtualDom.mirror.add(
736736
styleEl,
737737
getDefaultSN(styleEl, this.virtualDom.unserializedId),
@@ -752,10 +752,7 @@ export class Replayer {
752752
head as HTMLHeadElement,
753753
);
754754
for (let idx = 0; idx < injectStylesRules.length; idx++) {
755-
(styleEl.sheet! ).insertRule(
756-
injectStylesRules[idx],
757-
idx,
758-
);
755+
styleEl.sheet!.insertRule(injectStylesRules[idx], idx);
759756
}
760757
}
761758
}
@@ -1210,7 +1207,7 @@ export class Replayer {
12101207
if (!target) {
12111208
return this.debugNodeNotFound(d, d.id);
12121209
}
1213-
const styleSheet = ((target ) as HTMLStyleElement).sheet!;
1210+
const styleSheet = (target as HTMLStyleElement).sheet!;
12141211
d.adds?.forEach(({ rule, index: nestedIndex }) => {
12151212
try {
12161213
if (Array.isArray(nestedIndex)) {
@@ -1692,7 +1689,7 @@ export class Replayer {
16921689
}
16931690
}
16941691
} else if (attributeName === 'style') {
1695-
const styleValues = value ;
1692+
const styleValues = value;
16961693
const targetEl = target as HTMLElement | RRElement;
16971694
for (const s in styleValues) {
16981695
if (styleValues[s] === false) {
@@ -1772,7 +1769,7 @@ export class Replayer {
17721769
const previousInMap = previousId && map[previousId];
17731770
const nextInMap = nextId && map[nextId];
17741771
if (previousInMap) {
1775-
const { node, mutation } = previousInMap ;
1772+
const { node, mutation } = previousInMap;
17761773
parent.insertBefore(node as Node & RRNode, target as Node & RRNode);
17771774
delete map[mutation.node.id];
17781775
delete this.legacy_missingNodeRetryMap[mutation.node.id];
@@ -1781,7 +1778,7 @@ export class Replayer {
17811778
}
17821779
}
17831780
if (nextInMap) {
1784-
const { node, mutation } = nextInMap ;
1781+
const { node, mutation } = nextInMap;
17851782
parent.insertBefore(
17861783
node as Node & RRNode,
17871784
target.nextSibling as Node & RRNode,

packages/rrweb/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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';
14+
import type { BaseRRNode } from 'vdom';
1515
import type { CanvasManager } from './record/observers/canvas/canvas-manager';
1616

1717
export enum EventType {
@@ -670,7 +670,7 @@ export type playerMetaData = {
670670
};
671671

672672
export type missingNode = {
673-
node: Node | RRNode;
673+
node: Node | BaseRRNode;
674674
mutation: addedNodeMutation;
675675
};
676676
export type missingNodeMap = {

0 commit comments

Comments
 (0)