Skip to content

Commit

Permalink
fix: use default prop
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Jul 19, 2024
1 parent e9d9ac7 commit 5b55e8e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ export function genId(): number {
return _id++;
}

function makeBlockSelector(
blockClass: string | null,
blockSelector: string | RegExp | null,
): string | RegExp | null {
if (!blockClass && !blockSelector) return null;

if (typeof blockClass === 'string' && blockClass.length > 0) {
if (!blockSelector) return `.${blockClass}`;
if (typeof blockSelector === 'string')
return `.${blockClass},${blockSelector}`;
return new RegExp(`(${blockClass}|${blockSelector.source})`);
}
if (typeof blockSelector === 'string' && blockSelector.length > 0) {
if (!blockClass) return blockSelector;
return new RegExp(`(${blockClass}|${blockSelector})`);
}
if (!!blockSelector && typeof blockSelector === 'object') {
if (!blockClass) return blockSelector;
return new RegExp(`(${blockClass}|${blockSelector.source})`);
}

return null;
}

function getValidTagName(element: HTMLElement): Lowercase<string> {
if (element instanceof HTMLFormElement) {
return 'form';
Expand Down Expand Up @@ -1237,6 +1261,7 @@ function snapshot(
n: Document,
options?: {
mirror?: Mirror;
blockClass?: string | null;
blockSelector?: string | RegExp | null;
maskTextClass?: string | RegExp;
maskTextSelector?: string | null;
Expand Down Expand Up @@ -1265,6 +1290,7 @@ function snapshot(
): serializedNodeWithId | null {
const {
mirror = new Mirror(),
blockClass = 'rr-block',
blockSelector = null,
maskTextClass = 'rr-mask',
maskTextSelector = null,
Expand All @@ -1284,6 +1310,7 @@ function snapshot(
stylesheetLoadTimeout,
keepIframeSrcFn = () => false,
} = options || {};

const maskInputOptions: MaskInputOptions =
maskAllInputs === true
? {
Expand Down Expand Up @@ -1330,7 +1357,7 @@ function snapshot(
return serializeNodeWithId(n, {
doc: n,
mirror,
blockSelector,
blockSelector: makeBlockSelector(blockClass, blockSelector),
maskTextClass,
maskTextSelector,
skipChild: false,
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export function isBlocked(
blockSelector: string | RegExp | null,
checkAncestors: boolean,
): boolean {
console.log(node, 'blockSelector', blockSelector);
if (!blockSelector) return false;

const el = closestElementOfNode(node);
Expand Down

0 comments on commit 5b55e8e

Please sign in to comment.