init the repo and integrate rrweb-snapshot
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.vscode
|
||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
build
|
||||||
4
.prettierrc
Normal file
4
.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
29
package.json
Normal file
29
package.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "rrweb",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "record and replay the web",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+ssh://git@github.com/rrweb-io/rrweb.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"rrweb"
|
||||||
|
],
|
||||||
|
"author": "yanzhen@smartx.com",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/rrweb-io/rrweb/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/rrweb-io/rrweb#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"tslint": "^4.5.1",
|
||||||
|
"typescript": "^3.1.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"rrweb-snapshot": "file:../snapshot"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/index.ts
Normal file
3
src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import record from './record';
|
||||||
|
|
||||||
|
export { record };
|
||||||
35
src/record.ts
Normal file
35
src/record.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { snapshot } from 'rrweb-snapshot';
|
||||||
|
import { EventType, event } from './types';
|
||||||
|
|
||||||
|
function on(
|
||||||
|
type: string,
|
||||||
|
fn: EventListenerOrEventListenerObject,
|
||||||
|
target = document,
|
||||||
|
) {
|
||||||
|
target.addEventListener(type, fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createEvent(type: EventType, data: any): event {
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
data,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function emit(e: event) {}
|
||||||
|
|
||||||
|
function record() {
|
||||||
|
on('DOMContentLoaded', () => {
|
||||||
|
emit(
|
||||||
|
createEvent(EventType.DomContentLoaded, { href: window.location.href }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
on('load', () => {
|
||||||
|
emit(createEvent(EventType.Load, null));
|
||||||
|
const node = snapshot(document);
|
||||||
|
emit(createEvent(EventType.FullSnapshot, { node }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default record;
|
||||||
12
src/types.ts
Normal file
12
src/types.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export enum EventType {
|
||||||
|
DomContentLoaded,
|
||||||
|
Load,
|
||||||
|
FullSnapshot,
|
||||||
|
IncrementalSnapshot,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type event = {
|
||||||
|
type: EventType;
|
||||||
|
timestamp: number;
|
||||||
|
data: any;
|
||||||
|
};
|
||||||
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"preserveConstEnums": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"rootDir": "src",
|
||||||
|
"outDir": "build",
|
||||||
|
"lib": ["es6", "dom"]
|
||||||
|
},
|
||||||
|
"compileOnSave": true,
|
||||||
|
"exclude": ["test"],
|
||||||
|
"include": ["src", "index.d.ts"]
|
||||||
|
}
|
||||||
21
tslint.json
Normal file
21
tslint.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"defaultSeverity": "error",
|
||||||
|
"extends": ["tslint:recommended"],
|
||||||
|
"jsRules": {},
|
||||||
|
"rules": {
|
||||||
|
"no-any": true,
|
||||||
|
"quotemark": [true, "single"],
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"no-unused-variable": true,
|
||||||
|
"object-literal-key-quotes": false,
|
||||||
|
"variable-name": [
|
||||||
|
true,
|
||||||
|
"ban-keywords",
|
||||||
|
"check-format",
|
||||||
|
"allow-leading-underscore"
|
||||||
|
],
|
||||||
|
"arrow-parens": false
|
||||||
|
},
|
||||||
|
"rulesDirectory": []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user