fix #62 accept RegExp type block class config
This commit is contained in:
@@ -58,7 +58,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/smoothscroll-polyfill": "^0.3.0",
|
"@types/smoothscroll-polyfill": "^0.3.0",
|
||||||
"mitt": "^1.1.3",
|
"mitt": "^1.1.3",
|
||||||
"rrweb-snapshot": "^0.7.6",
|
"rrweb-snapshot": "^0.7.8",
|
||||||
"smoothscroll-polyfill": "^0.4.3"
|
"smoothscroll-polyfill": "^0.4.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
hookResetter,
|
hookResetter,
|
||||||
textCursor,
|
textCursor,
|
||||||
attributeCursor,
|
attributeCursor,
|
||||||
|
blockClass,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { deepDelete, isParentRemoved, isParentDropped } from './collection';
|
import { deepDelete, isParentRemoved, isParentDropped } from './collection';
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ import { deepDelete, isParentRemoved, isParentDropped } from './collection';
|
|||||||
*/
|
*/
|
||||||
function initMutationObserver(
|
function initMutationObserver(
|
||||||
cb: mutationCallBack,
|
cb: mutationCallBack,
|
||||||
blockClass: string,
|
blockClass: blockClass,
|
||||||
): MutationObserver {
|
): MutationObserver {
|
||||||
const observer = new MutationObserver(mutations => {
|
const observer = new MutationObserver(mutations => {
|
||||||
const texts: textCursor[] = [];
|
const texts: textCursor[] = [];
|
||||||
@@ -242,7 +243,7 @@ function initMousemoveObserver(cb: mousemoveCallBack): listenerHandler {
|
|||||||
|
|
||||||
function initMouseInteractionObserver(
|
function initMouseInteractionObserver(
|
||||||
cb: mouseInteractionCallBack,
|
cb: mouseInteractionCallBack,
|
||||||
blockClass: string,
|
blockClass: blockClass,
|
||||||
): listenerHandler {
|
): listenerHandler {
|
||||||
const handlers: listenerHandler[] = [];
|
const handlers: listenerHandler[] = [];
|
||||||
const getHandler = (eventKey: keyof typeof MouseInteractions) => {
|
const getHandler = (eventKey: keyof typeof MouseInteractions) => {
|
||||||
@@ -274,7 +275,7 @@ function initMouseInteractionObserver(
|
|||||||
|
|
||||||
function initScrollObserver(
|
function initScrollObserver(
|
||||||
cb: scrollCallback,
|
cb: scrollCallback,
|
||||||
blockClass: string,
|
blockClass: blockClass,
|
||||||
): listenerHandler {
|
): listenerHandler {
|
||||||
const updatePosition = throttle<UIEvent>(evt => {
|
const updatePosition = throttle<UIEvent>(evt => {
|
||||||
if (!evt.target || isBlocked(evt.target as Node, blockClass)) {
|
if (!evt.target || isBlocked(evt.target as Node, blockClass)) {
|
||||||
@@ -317,7 +318,7 @@ const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
|
|||||||
const lastInputValueMap: WeakMap<EventTarget, inputValue> = new WeakMap();
|
const lastInputValueMap: WeakMap<EventTarget, inputValue> = new WeakMap();
|
||||||
function initInputObserver(
|
function initInputObserver(
|
||||||
cb: inputCallback,
|
cb: inputCallback,
|
||||||
blockClass: string,
|
blockClass: blockClass,
|
||||||
ignoreClass: string,
|
ignoreClass: string,
|
||||||
): listenerHandler {
|
): listenerHandler {
|
||||||
function eventHandler(event: Event) {
|
function eventHandler(event: Event) {
|
||||||
|
|||||||
@@ -98,11 +98,13 @@ export type eventWithTime = event & {
|
|||||||
delay?: number;
|
delay?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type blockClass = string | RegExp;
|
||||||
|
|
||||||
export type recordOptions = {
|
export type recordOptions = {
|
||||||
emit?: (e: eventWithTime, isCheckout?: boolean) => void;
|
emit?: (e: eventWithTime, isCheckout?: boolean) => void;
|
||||||
checkoutEveryNth?: number;
|
checkoutEveryNth?: number;
|
||||||
checkoutEveryNms?: number;
|
checkoutEveryNms?: number;
|
||||||
blockClass?: string;
|
blockClass?: blockClass;
|
||||||
ignoreClass?: string;
|
ignoreClass?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@ export type observerParam = {
|
|||||||
scrollCb: scrollCallback;
|
scrollCb: scrollCallback;
|
||||||
viewportResizeCb: viewportResizeCallback;
|
viewportResizeCb: viewportResizeCallback;
|
||||||
inputCb: inputCallback;
|
inputCb: inputCallback;
|
||||||
blockClass: string;
|
blockClass: blockClass;
|
||||||
ignoreClass: string;
|
ignoreClass: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
18
src/utils.ts
18
src/utils.ts
@@ -3,6 +3,7 @@ import {
|
|||||||
throttleOptions,
|
throttleOptions,
|
||||||
listenerHandler,
|
listenerHandler,
|
||||||
hookResetter,
|
hookResetter,
|
||||||
|
blockClass,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { INode } from 'rrweb-snapshot';
|
import { INode } from 'rrweb-snapshot';
|
||||||
|
|
||||||
@@ -113,15 +114,22 @@ export function getWindowWidth(): number {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isBlocked(node: Node | null, blockClass: string): boolean {
|
export function isBlocked(node: Node | null, blockClass: blockClass): boolean {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (node.nodeType === node.ELEMENT_NODE) {
|
if (node.nodeType === node.ELEMENT_NODE) {
|
||||||
return (
|
let needBlock = false;
|
||||||
(node as HTMLElement).classList.contains(blockClass) ||
|
if (typeof blockClass === 'string') {
|
||||||
isBlocked(node.parentNode, blockClass)
|
needBlock = (node as HTMLElement).classList.contains(blockClass);
|
||||||
);
|
} else {
|
||||||
|
(node as HTMLElement).classList.forEach(className => {
|
||||||
|
if (blockClass.test(className)) {
|
||||||
|
needBlock = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return needBlock || isBlocked(node.parentNode, blockClass);
|
||||||
}
|
}
|
||||||
return isBlocked(node.parentNode, blockClass);
|
return isBlocked(node.parentNode, blockClass);
|
||||||
}
|
}
|
||||||
|
|||||||
5
typings/types.d.ts
vendored
5
typings/types.d.ts
vendored
@@ -70,11 +70,12 @@ export declare type eventWithTime = event & {
|
|||||||
timestamp: number;
|
timestamp: number;
|
||||||
delay?: number;
|
delay?: number;
|
||||||
};
|
};
|
||||||
|
export declare type blockClass = string | RegExp;
|
||||||
export declare type recordOptions = {
|
export declare type recordOptions = {
|
||||||
emit?: (e: eventWithTime, isCheckout?: boolean) => void;
|
emit?: (e: eventWithTime, isCheckout?: boolean) => void;
|
||||||
checkoutEveryNth?: number;
|
checkoutEveryNth?: number;
|
||||||
checkoutEveryNms?: number;
|
checkoutEveryNms?: number;
|
||||||
blockClass?: string;
|
blockClass?: blockClass;
|
||||||
ignoreClass?: string;
|
ignoreClass?: string;
|
||||||
};
|
};
|
||||||
export declare type observerParam = {
|
export declare type observerParam = {
|
||||||
@@ -84,7 +85,7 @@ export declare type observerParam = {
|
|||||||
scrollCb: scrollCallback;
|
scrollCb: scrollCallback;
|
||||||
viewportResizeCb: viewportResizeCallback;
|
viewportResizeCb: viewportResizeCallback;
|
||||||
inputCb: inputCallback;
|
inputCb: inputCallback;
|
||||||
blockClass: string;
|
blockClass: blockClass;
|
||||||
ignoreClass: string;
|
ignoreClass: string;
|
||||||
};
|
};
|
||||||
export declare type textCursor = {
|
export declare type textCursor = {
|
||||||
|
|||||||
4
typings/utils.d.ts
vendored
4
typings/utils.d.ts
vendored
@@ -1,4 +1,4 @@
|
|||||||
import { Mirror, throttleOptions, listenerHandler, hookResetter } from './types';
|
import { Mirror, throttleOptions, listenerHandler, hookResetter, blockClass } from './types';
|
||||||
import { INode } from 'rrweb-snapshot';
|
import { INode } from 'rrweb-snapshot';
|
||||||
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler;
|
export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler;
|
||||||
export declare const mirror: Mirror;
|
export declare const mirror: Mirror;
|
||||||
@@ -6,5 +6,5 @@ export declare function throttle<T>(func: (arg: T) => void, wait: number, option
|
|||||||
export declare function hookSetter<T>(target: T, key: string | number | symbol, d: PropertyDescriptor): hookResetter;
|
export declare function hookSetter<T>(target: T, key: string | number | symbol, d: PropertyDescriptor): hookResetter;
|
||||||
export declare function getWindowHeight(): number;
|
export declare function getWindowHeight(): number;
|
||||||
export declare function getWindowWidth(): number;
|
export declare function getWindowWidth(): number;
|
||||||
export declare function isBlocked(node: Node | null, blockClass: string): boolean;
|
export declare function isBlocked(node: Node | null, blockClass: blockClass): boolean;
|
||||||
export declare function isAncestorRemoved(target: INode): boolean;
|
export declare function isAncestorRemoved(target: INode): boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user