feat: Added support maskInputFn with HTMLElement (#1188)

This commit is contained in:
Ben White
2023-04-15 09:31:39 +02:00
committed by GitHub
parent 944615d999
commit bc84246f78
11 changed files with 917 additions and 9 deletions

View File

@@ -685,6 +685,7 @@ function serializeElementNode(
) {
const type = getInputType(n);
attributes.value = maskInputValue({
element: n,
type,
tagName,
value,

View File

@@ -154,7 +154,7 @@ export type DataURLOptions = Partial<{
}>;
export type MaskTextFn = (text: string) => string;
export type MaskInputFn = (text: string) => string;
export type MaskInputFn = (text: string, element: HTMLElement) => string;
export type KeepIframeSrcFn = (src: string) => boolean;

View File

@@ -154,12 +154,14 @@ export function createMirror(): Mirror {
}
export function maskInputValue({
element,
maskInputOptions,
tagName,
type,
value,
maskInputFn,
}: {
element: HTMLElement;
maskInputOptions: MaskInputOptions;
tagName: string;
type: string | null;
@@ -174,7 +176,7 @@ export function maskInputValue({
(actualType && maskInputOptions[actualType as keyof MaskInputOptions])
) {
if (maskInputFn) {
text = maskInputFn(text);
text = maskInputFn(text, element);
} else {
text = '*'.repeat(text.length);
}