@radix-ui/react-password-toggle-field 0.1.7 → 0.1.8-rc.1784074599772
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -27
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +30 -27
- package/dist/index.mjs.map +3 -3
- package/package.json +6 -6
- package/src/password-toggle-field.tsx +20 -15
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
10
|
var __export = (target, all) => {
|
|
10
11
|
for (var name in all)
|
|
11
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -47,6 +48,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
47
48
|
// src/password-toggle-field.tsx
|
|
48
49
|
var React = __toESM(require("react"));
|
|
49
50
|
var import_react_dom = require("react-dom");
|
|
51
|
+
var import_is_development = require("@radix-ui/primitive/is-development");
|
|
50
52
|
var import_primitive = require("@radix-ui/primitive");
|
|
51
53
|
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
|
|
52
54
|
var import_react_primitive = require("@radix-ui/react-primitive");
|
|
@@ -64,7 +66,7 @@ var INITIAL_FOCUS_STATE = {
|
|
|
64
66
|
selectionStart: null,
|
|
65
67
|
selectionEnd: null
|
|
66
68
|
};
|
|
67
|
-
var PasswordToggleField = ({
|
|
69
|
+
var PasswordToggleField = /* @__PURE__ */ __name(({
|
|
68
70
|
__scopePasswordToggleField,
|
|
69
71
|
...props
|
|
70
72
|
}) => {
|
|
@@ -85,7 +87,7 @@ var PasswordToggleField = ({
|
|
|
85
87
|
} else {
|
|
86
88
|
onVisibilityChange = props.onVisibilityChange;
|
|
87
89
|
}
|
|
88
|
-
if (
|
|
90
|
+
if (import_is_development.IS_DEVELOPMENT) {
|
|
89
91
|
React.useEffect(() => {
|
|
90
92
|
if (shouldWarn) {
|
|
91
93
|
console.warn(
|
|
@@ -115,18 +117,18 @@ var PasswordToggleField = ({
|
|
|
115
117
|
children
|
|
116
118
|
}
|
|
117
119
|
);
|
|
118
|
-
};
|
|
119
|
-
PasswordToggleField.displayName = PASSWORD_TOGGLE_FIELD_NAME;
|
|
120
|
+
}, "PasswordToggleField");
|
|
120
121
|
var PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Input";
|
|
121
|
-
var PasswordToggleFieldInput = React.forwardRef(
|
|
122
|
-
|
|
122
|
+
var PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef(
|
|
123
|
+
// blank line to reduce diff noise
|
|
124
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldInput2({
|
|
123
125
|
__scopePasswordToggleField,
|
|
124
126
|
autoComplete = "current-password",
|
|
125
127
|
autoCapitalize = "off",
|
|
126
128
|
spellCheck = false,
|
|
127
129
|
id: idProp,
|
|
128
130
|
...props
|
|
129
|
-
}, forwardedRef)
|
|
131
|
+
}, forwardedRef) {
|
|
130
132
|
const { visible, inputRef, inputId, syncInputId, setVisible, focusState } = usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);
|
|
131
133
|
React.useEffect(() => {
|
|
132
134
|
syncInputId(idProp);
|
|
@@ -176,12 +178,12 @@ var PasswordToggleFieldInput = React.forwardRef(
|
|
|
176
178
|
})
|
|
177
179
|
}
|
|
178
180
|
);
|
|
179
|
-
}
|
|
181
|
+
}, "PasswordToggleFieldInput")
|
|
180
182
|
);
|
|
181
|
-
PasswordToggleFieldInput.displayName = PASSWORD_TOGGLE_FIELD_INPUT_NAME;
|
|
182
183
|
var PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Toggle";
|
|
183
|
-
var PasswordToggleFieldToggle = React.forwardRef(
|
|
184
|
-
|
|
184
|
+
var PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef(
|
|
185
|
+
// blank line to reduce diff noise
|
|
186
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldToggle2({
|
|
185
187
|
__scopePasswordToggleField,
|
|
186
188
|
onClick,
|
|
187
189
|
onPointerDown,
|
|
@@ -194,7 +196,7 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
194
196
|
"aria-hidden": ariaHidden,
|
|
195
197
|
tabIndex,
|
|
196
198
|
...props
|
|
197
|
-
}, forwardedRef)
|
|
199
|
+
}, forwardedRef) {
|
|
198
200
|
const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(
|
|
199
201
|
PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,
|
|
200
202
|
__scopePasswordToggleField
|
|
@@ -214,6 +216,7 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
214
216
|
const text = textContent ? textContent : void 0;
|
|
215
217
|
setInternalAriaLabel(text ? void 0 : DEFAULT_ARIA_LABEL);
|
|
216
218
|
}
|
|
219
|
+
__name(checkForInnerTextLabel, "checkForInnerTextLabel");
|
|
217
220
|
checkForInnerTextLabel(element.textContent);
|
|
218
221
|
const observer = new MutationObserver((entries) => {
|
|
219
222
|
let textContent;
|
|
@@ -239,11 +242,11 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
239
242
|
ariaControls ??= inputId;
|
|
240
243
|
}
|
|
241
244
|
React.useEffect(() => {
|
|
242
|
-
let cleanup = () => {
|
|
243
|
-
};
|
|
245
|
+
let cleanup = /* @__PURE__ */ __name(() => {
|
|
246
|
+
}, "cleanup");
|
|
244
247
|
const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;
|
|
245
|
-
const reset = () => focusState.current.clickTriggered = false;
|
|
246
|
-
const handlePointerUp = () => cleanup = requestIdleCallback(ownerWindow, reset);
|
|
248
|
+
const reset = /* @__PURE__ */ __name(() => focusState.current.clickTriggered = false, "reset");
|
|
249
|
+
const handlePointerUp = /* @__PURE__ */ __name(() => cleanup = requestIdleCallback(ownerWindow, reset), "handlePointerUp");
|
|
247
250
|
ownerWindow.addEventListener("pointerup", handlePointerUp);
|
|
248
251
|
return () => {
|
|
249
252
|
cleanup();
|
|
@@ -302,11 +305,10 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
302
305
|
children
|
|
303
306
|
}
|
|
304
307
|
);
|
|
305
|
-
}
|
|
308
|
+
}, "PasswordToggleFieldToggle")
|
|
306
309
|
);
|
|
307
|
-
PasswordToggleFieldToggle.displayName = PASSWORD_TOGGLE_FIELD_TOGGLE_NAME;
|
|
308
310
|
var PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Slot";
|
|
309
|
-
var PasswordToggleFieldSlot = ({
|
|
311
|
+
var PasswordToggleFieldSlot = /* @__PURE__ */ __name(({
|
|
310
312
|
__scopePasswordToggleField,
|
|
311
313
|
...props
|
|
312
314
|
}) => {
|
|
@@ -318,25 +320,24 @@ var PasswordToggleFieldSlot = ({
|
|
|
318
320
|
//
|
|
319
321
|
props.render({ visible })
|
|
320
322
|
) : visible ? props.visible : props.hidden;
|
|
321
|
-
};
|
|
322
|
-
PasswordToggleFieldSlot.displayName = PASSWORD_TOGGLE_FIELD_SLOT_NAME;
|
|
323
|
+
}, "PasswordToggleFieldSlot");
|
|
323
324
|
var PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Icon";
|
|
324
|
-
var PasswordToggleFieldIcon = React.forwardRef(
|
|
325
|
-
|
|
325
|
+
var PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef(
|
|
326
|
+
// blank line to reduce diff noise
|
|
327
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldIcon2({
|
|
326
328
|
__scopePasswordToggleField,
|
|
327
329
|
// @ts-expect-error
|
|
328
330
|
children,
|
|
329
331
|
...props
|
|
330
|
-
}, forwardedRef)
|
|
332
|
+
}, forwardedRef) {
|
|
331
333
|
const { visible } = usePasswordToggleFieldContext(
|
|
332
334
|
PASSWORD_TOGGLE_FIELD_ICON_NAME,
|
|
333
335
|
__scopePasswordToggleField
|
|
334
336
|
);
|
|
335
337
|
const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;
|
|
336
338
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.svg, { ...domProps, ref: forwardedRef, "aria-hidden": true, asChild: true, children: visible ? visibleIcon : hiddenIcon });
|
|
337
|
-
}
|
|
339
|
+
}, "PasswordToggleFieldIcon")
|
|
338
340
|
);
|
|
339
|
-
PasswordToggleFieldIcon.displayName = PASSWORD_TOGGLE_FIELD_ICON_NAME;
|
|
340
341
|
function requestIdleCallback(window2, callback, options) {
|
|
341
342
|
if (window2.requestIdleCallback) {
|
|
342
343
|
const id2 = window2.requestIdleCallback(callback, options);
|
|
@@ -346,11 +347,12 @@ function requestIdleCallback(window2, callback, options) {
|
|
|
346
347
|
}
|
|
347
348
|
const start = Date.now();
|
|
348
349
|
const id = window2.setTimeout(() => {
|
|
349
|
-
const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));
|
|
350
|
+
const timeRemaining = /* @__PURE__ */ __name(() => Math.max(0, 50 - (Date.now() - start)), "timeRemaining");
|
|
350
351
|
callback({ didTimeout: false, timeRemaining });
|
|
351
352
|
}, 1);
|
|
352
353
|
return () => {
|
|
353
354
|
window2.clearTimeout(id);
|
|
354
355
|
};
|
|
355
356
|
}
|
|
357
|
+
__name(requestIdleCallback, "requestIdleCallback");
|
|
356
358
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/password-toggle-field.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client';\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n} from './password-toggle-field';\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldIcon,\n PasswordToggleFieldSlot,\n //\n Root,\n Input,\n Toggle,\n Icon,\n Slot,\n} from './password-toggle-field';\n", "import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\nPasswordToggleField.displayName = PASSWORD_TOGGLE_FIELD_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = React.forwardRef<HTMLInputElement, PasswordToggleFieldInputProps>(\n (\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) => {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\nPasswordToggleFieldInput.displayName = PASSWORD_TOGGLE_FIELD_INPUT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n (\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) => {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\nPasswordToggleFieldToggle.displayName = PASSWORD_TOGGLE_FIELD_TOGGLE_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\nPasswordToggleFieldSlot.displayName = PASSWORD_TOGGLE_FIELD_SLOT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = React.forwardRef<SVGSVGElement, PasswordToggleFieldIconProps>(\n (\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\nPasswordToggleFieldIcon.displayName = PASSWORD_TOGGLE_FIELD_ICON_NAME;\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["window", "id"]
|
|
4
|
+
"sourcesContent": ["'use client';\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n} from './password-toggle-field';\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldIcon,\n PasswordToggleFieldSlot,\n //\n Root,\n Input,\n Toggle,\n Icon,\n Slot,\n} from './password-toggle-field';\n", "import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAA0B;AAC1B,4BAA+B;AAC/B,uBAAqC;AACrC,0CAAqC;AACrC,6BAAsD;AACtD,gCAAgC;AAChC,sBAAsB;AACtB,mCAA8B;AAC9B,oCAA+B;AAE/B,2BAAmC;AAkG/B;AAhGJ,IAAM,6BAA6B;AAqBnC,IAAM,CAAC,gCAAgC,QAAI,yCAAmB,0BAA0B;AACxF,IAAM,CAAC,6BAA6B,6BAA6B,IAC/D,iCAAkE,0BAA0B;AAgB9F,IAAM,sBAA0C;AAAA,EAC9C,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAChB;AAEA,IAAM,sBAA0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KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,GAA3C;AACtB,aAAS,EAAE,YAAY,OAAO,cAAc,CAAC;AAAA,EAC/C,GAAG,CAAC;AACJ,SAAO,MAAM;AACX,IAAAA,QAAO,aAAa,EAAE;AAAA,EACxB;AACF;AAnBS;",
|
|
6
|
+
"names": ["PasswordToggleFieldInput", "PasswordToggleFieldToggle", "PasswordToggleFieldIcon", "window", "id"]
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
2
4
|
|
|
3
5
|
// src/password-toggle-field.tsx
|
|
4
6
|
import * as React from "react";
|
|
5
7
|
import { flushSync } from "react-dom";
|
|
8
|
+
import { IS_DEVELOPMENT } from "@radix-ui/primitive/is-development";
|
|
6
9
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
7
10
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
8
11
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
@@ -20,7 +23,7 @@ var INITIAL_FOCUS_STATE = {
|
|
|
20
23
|
selectionStart: null,
|
|
21
24
|
selectionEnd: null
|
|
22
25
|
};
|
|
23
|
-
var PasswordToggleField = ({
|
|
26
|
+
var PasswordToggleField = /* @__PURE__ */ __name(({
|
|
24
27
|
__scopePasswordToggleField,
|
|
25
28
|
...props
|
|
26
29
|
}) => {
|
|
@@ -41,7 +44,7 @@ var PasswordToggleField = ({
|
|
|
41
44
|
} else {
|
|
42
45
|
onVisibilityChange = props.onVisibilityChange;
|
|
43
46
|
}
|
|
44
|
-
if (
|
|
47
|
+
if (IS_DEVELOPMENT) {
|
|
45
48
|
React.useEffect(() => {
|
|
46
49
|
if (shouldWarn) {
|
|
47
50
|
console.warn(
|
|
@@ -71,18 +74,18 @@ var PasswordToggleField = ({
|
|
|
71
74
|
children
|
|
72
75
|
}
|
|
73
76
|
);
|
|
74
|
-
};
|
|
75
|
-
PasswordToggleField.displayName = PASSWORD_TOGGLE_FIELD_NAME;
|
|
77
|
+
}, "PasswordToggleField");
|
|
76
78
|
var PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Input";
|
|
77
|
-
var PasswordToggleFieldInput = React.forwardRef(
|
|
78
|
-
|
|
79
|
+
var PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef(
|
|
80
|
+
// blank line to reduce diff noise
|
|
81
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldInput2({
|
|
79
82
|
__scopePasswordToggleField,
|
|
80
83
|
autoComplete = "current-password",
|
|
81
84
|
autoCapitalize = "off",
|
|
82
85
|
spellCheck = false,
|
|
83
86
|
id: idProp,
|
|
84
87
|
...props
|
|
85
|
-
}, forwardedRef)
|
|
88
|
+
}, forwardedRef) {
|
|
86
89
|
const { visible, inputRef, inputId, syncInputId, setVisible, focusState } = usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);
|
|
87
90
|
React.useEffect(() => {
|
|
88
91
|
syncInputId(idProp);
|
|
@@ -132,12 +135,12 @@ var PasswordToggleFieldInput = React.forwardRef(
|
|
|
132
135
|
})
|
|
133
136
|
}
|
|
134
137
|
);
|
|
135
|
-
}
|
|
138
|
+
}, "PasswordToggleFieldInput")
|
|
136
139
|
);
|
|
137
|
-
PasswordToggleFieldInput.displayName = PASSWORD_TOGGLE_FIELD_INPUT_NAME;
|
|
138
140
|
var PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Toggle";
|
|
139
|
-
var PasswordToggleFieldToggle = React.forwardRef(
|
|
140
|
-
|
|
141
|
+
var PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef(
|
|
142
|
+
// blank line to reduce diff noise
|
|
143
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldToggle2({
|
|
141
144
|
__scopePasswordToggleField,
|
|
142
145
|
onClick,
|
|
143
146
|
onPointerDown,
|
|
@@ -150,7 +153,7 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
150
153
|
"aria-hidden": ariaHidden,
|
|
151
154
|
tabIndex,
|
|
152
155
|
...props
|
|
153
|
-
}, forwardedRef)
|
|
156
|
+
}, forwardedRef) {
|
|
154
157
|
const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(
|
|
155
158
|
PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,
|
|
156
159
|
__scopePasswordToggleField
|
|
@@ -170,6 +173,7 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
170
173
|
const text = textContent ? textContent : void 0;
|
|
171
174
|
setInternalAriaLabel(text ? void 0 : DEFAULT_ARIA_LABEL);
|
|
172
175
|
}
|
|
176
|
+
__name(checkForInnerTextLabel, "checkForInnerTextLabel");
|
|
173
177
|
checkForInnerTextLabel(element.textContent);
|
|
174
178
|
const observer = new MutationObserver((entries) => {
|
|
175
179
|
let textContent;
|
|
@@ -195,11 +199,11 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
195
199
|
ariaControls ??= inputId;
|
|
196
200
|
}
|
|
197
201
|
React.useEffect(() => {
|
|
198
|
-
let cleanup = () => {
|
|
199
|
-
};
|
|
202
|
+
let cleanup = /* @__PURE__ */ __name(() => {
|
|
203
|
+
}, "cleanup");
|
|
200
204
|
const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;
|
|
201
|
-
const reset = () => focusState.current.clickTriggered = false;
|
|
202
|
-
const handlePointerUp = () => cleanup = requestIdleCallback(ownerWindow, reset);
|
|
205
|
+
const reset = /* @__PURE__ */ __name(() => focusState.current.clickTriggered = false, "reset");
|
|
206
|
+
const handlePointerUp = /* @__PURE__ */ __name(() => cleanup = requestIdleCallback(ownerWindow, reset), "handlePointerUp");
|
|
203
207
|
ownerWindow.addEventListener("pointerup", handlePointerUp);
|
|
204
208
|
return () => {
|
|
205
209
|
cleanup();
|
|
@@ -258,11 +262,10 @@ var PasswordToggleFieldToggle = React.forwardRef(
|
|
|
258
262
|
children
|
|
259
263
|
}
|
|
260
264
|
);
|
|
261
|
-
}
|
|
265
|
+
}, "PasswordToggleFieldToggle")
|
|
262
266
|
);
|
|
263
|
-
PasswordToggleFieldToggle.displayName = PASSWORD_TOGGLE_FIELD_TOGGLE_NAME;
|
|
264
267
|
var PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Slot";
|
|
265
|
-
var PasswordToggleFieldSlot = ({
|
|
268
|
+
var PasswordToggleFieldSlot = /* @__PURE__ */ __name(({
|
|
266
269
|
__scopePasswordToggleField,
|
|
267
270
|
...props
|
|
268
271
|
}) => {
|
|
@@ -274,25 +277,24 @@ var PasswordToggleFieldSlot = ({
|
|
|
274
277
|
//
|
|
275
278
|
props.render({ visible })
|
|
276
279
|
) : visible ? props.visible : props.hidden;
|
|
277
|
-
};
|
|
278
|
-
PasswordToggleFieldSlot.displayName = PASSWORD_TOGGLE_FIELD_SLOT_NAME;
|
|
280
|
+
}, "PasswordToggleFieldSlot");
|
|
279
281
|
var PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Icon";
|
|
280
|
-
var PasswordToggleFieldIcon = React.forwardRef(
|
|
281
|
-
|
|
282
|
+
var PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef(
|
|
283
|
+
// blank line to reduce diff noise
|
|
284
|
+
/* @__PURE__ */ __name(function PasswordToggleFieldIcon2({
|
|
282
285
|
__scopePasswordToggleField,
|
|
283
286
|
// @ts-expect-error
|
|
284
287
|
children,
|
|
285
288
|
...props
|
|
286
|
-
}, forwardedRef)
|
|
289
|
+
}, forwardedRef) {
|
|
287
290
|
const { visible } = usePasswordToggleFieldContext(
|
|
288
291
|
PASSWORD_TOGGLE_FIELD_ICON_NAME,
|
|
289
292
|
__scopePasswordToggleField
|
|
290
293
|
);
|
|
291
294
|
const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;
|
|
292
295
|
return /* @__PURE__ */ jsx(Primitive.svg, { ...domProps, ref: forwardedRef, "aria-hidden": true, asChild: true, children: visible ? visibleIcon : hiddenIcon });
|
|
293
|
-
}
|
|
296
|
+
}, "PasswordToggleFieldIcon")
|
|
294
297
|
);
|
|
295
|
-
PasswordToggleFieldIcon.displayName = PASSWORD_TOGGLE_FIELD_ICON_NAME;
|
|
296
298
|
function requestIdleCallback(window2, callback, options) {
|
|
297
299
|
if (window2.requestIdleCallback) {
|
|
298
300
|
const id2 = window2.requestIdleCallback(callback, options);
|
|
@@ -302,13 +304,14 @@ function requestIdleCallback(window2, callback, options) {
|
|
|
302
304
|
}
|
|
303
305
|
const start = Date.now();
|
|
304
306
|
const id = window2.setTimeout(() => {
|
|
305
|
-
const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));
|
|
307
|
+
const timeRemaining = /* @__PURE__ */ __name(() => Math.max(0, 50 - (Date.now() - start)), "timeRemaining");
|
|
306
308
|
callback({ didTimeout: false, timeRemaining });
|
|
307
309
|
}, 1);
|
|
308
310
|
return () => {
|
|
309
311
|
window2.clearTimeout(id);
|
|
310
312
|
};
|
|
311
313
|
}
|
|
314
|
+
__name(requestIdleCallback, "requestIdleCallback");
|
|
312
315
|
export {
|
|
313
316
|
PasswordToggleFieldIcon as Icon,
|
|
314
317
|
PasswordToggleFieldInput as Input,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/password-toggle-field.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\nPasswordToggleField.displayName = PASSWORD_TOGGLE_FIELD_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = React.forwardRef<HTMLInputElement, PasswordToggleFieldInputProps>(\n (\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) => {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\nPasswordToggleFieldInput.displayName = PASSWORD_TOGGLE_FIELD_INPUT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n (\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) => {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\nPasswordToggleFieldToggle.displayName = PASSWORD_TOGGLE_FIELD_TOGGLE_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\nPasswordToggleFieldSlot.displayName = PASSWORD_TOGGLE_FIELD_SLOT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = React.forwardRef<SVGSVGElement, PasswordToggleFieldIconProps>(\n (\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\nPasswordToggleFieldIcon.displayName = PASSWORD_TOGGLE_FIELD_ICON_NAME;\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["window", "id"]
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,sBAA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WACE,oBAAC,UAAU,KAAV,EAAe,GAAG,UAAU,KAAK,cAAc,eAAW,MAAC,SAAO,MAChE,oBAAU,cAAc,YAC3B;AAAA,EAEJ,GAnBA;AAoBF;AAuBA,SAAS,oBACPC,SACA,UACA,SACY;AACZ,MAAKA,QAAe,qBAAqB;AACvC,UAAMC,MAAKD,QAAO,oBAAoB,UAAU,OAAO;AACvD,WAAO,MAAM;AACX,MAAAA,QAAO,mBAAmBC,GAAE;AAAA,IAC9B;AAAA,EACF;AACA,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,KAAKD,QAAO,WAAW,MAAM;AACjC,UAAM,gBAAgB,6BAAM,KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,GAA3C;AACtB,aAAS,EAAE,YAAY,OAAO,cAAc,CAAC;AAAA,EAC/C,GAAG,CAAC;AACJ,SAAO,MAAM;AACX,IAAAA,QAAO,aAAa,EAAE;AAAA,EACxB;AACF;AAnBS;",
|
|
6
|
+
"names": ["PasswordToggleFieldInput", "PasswordToggleFieldToggle", "PasswordToggleFieldIcon", "window", "id"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-password-toggle-field",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8-rc.1784074599772",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
],
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@radix-ui/primitive": "1.1.
|
|
15
|
+
"@radix-ui/primitive": "1.1.6-rc.1784074599772",
|
|
16
16
|
"@radix-ui/react-compose-refs": "1.1.3",
|
|
17
|
+
"@radix-ui/react-use-controllable-state": "1.2.4-rc.1784074599772",
|
|
17
18
|
"@radix-ui/react-context": "1.2.0",
|
|
18
|
-
"@radix-ui/react-id": "1.1.2",
|
|
19
19
|
"@radix-ui/react-primitive": "2.1.7",
|
|
20
|
-
"@radix-ui/react-
|
|
20
|
+
"@radix-ui/react-id": "1.1.2",
|
|
21
21
|
"@radix-ui/react-use-effect-event": "0.0.3",
|
|
22
22
|
"@radix-ui/react-use-is-hydrated": "0.1.1"
|
|
23
23
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"react": "^19.2.0",
|
|
28
28
|
"react-dom": "^19.2.0",
|
|
29
29
|
"typescript": "^5.9.3",
|
|
30
|
-
"@repo/
|
|
31
|
-
"@repo/
|
|
30
|
+
"@repo/typescript-config": "0.0.0",
|
|
31
|
+
"@repo/builder": "0.0.1-rc.1784074599772"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@types/react": "*",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { flushSync } from 'react-dom';
|
|
3
|
+
import { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';
|
|
3
4
|
import { composeEventHandlers } from '@radix-ui/primitive';
|
|
4
5
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
5
6
|
import { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';
|
|
@@ -84,7 +85,7 @@ const PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({
|
|
|
84
85
|
onVisibilityChange = props.onVisibilityChange;
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
if (
|
|
88
|
+
if (IS_DEVELOPMENT) {
|
|
88
89
|
// oxlint-disable-next-line react-hooks/rules-of-hooks
|
|
89
90
|
React.useEffect(() => {
|
|
90
91
|
if (shouldWarn) {
|
|
@@ -119,7 +120,6 @@ const PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({
|
|
|
119
120
|
</PasswordToggleFieldProvider>
|
|
120
121
|
);
|
|
121
122
|
};
|
|
122
|
-
PasswordToggleField.displayName = PASSWORD_TOGGLE_FIELD_NAME;
|
|
123
123
|
|
|
124
124
|
/* -------------------------------------------------------------------------------------------------
|
|
125
125
|
* PasswordToggleFieldInput
|
|
@@ -140,8 +140,12 @@ interface PasswordToggleFieldInputProps
|
|
|
140
140
|
autoComplete?: 'current-password' | 'new-password';
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
const PasswordToggleFieldInput = React.forwardRef<
|
|
144
|
-
|
|
143
|
+
const PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<
|
|
144
|
+
HTMLInputElement,
|
|
145
|
+
PasswordToggleFieldInputProps
|
|
146
|
+
>(
|
|
147
|
+
// blank line to reduce diff noise
|
|
148
|
+
function PasswordToggleFieldInput(
|
|
145
149
|
{
|
|
146
150
|
__scopePasswordToggleField,
|
|
147
151
|
autoComplete = 'current-password',
|
|
@@ -151,7 +155,7 @@ const PasswordToggleFieldInput = React.forwardRef<HTMLInputElement, PasswordTogg
|
|
|
151
155
|
...props
|
|
152
156
|
}: ScopedProps<PasswordToggleFieldInputProps>,
|
|
153
157
|
forwardedRef,
|
|
154
|
-
)
|
|
158
|
+
) {
|
|
155
159
|
const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =
|
|
156
160
|
usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);
|
|
157
161
|
|
|
@@ -218,7 +222,6 @@ const PasswordToggleFieldInput = React.forwardRef<HTMLInputElement, PasswordTogg
|
|
|
218
222
|
);
|
|
219
223
|
},
|
|
220
224
|
);
|
|
221
|
-
PasswordToggleFieldInput.displayName = PASSWORD_TOGGLE_FIELD_INPUT_NAME;
|
|
222
225
|
|
|
223
226
|
/* -------------------------------------------------------------------------------------------------
|
|
224
227
|
* PasswordToggleFieldToggle
|
|
@@ -230,11 +233,12 @@ type PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;
|
|
|
230
233
|
|
|
231
234
|
interface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}
|
|
232
235
|
|
|
233
|
-
const PasswordToggleFieldToggle = React.forwardRef<
|
|
236
|
+
const PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<
|
|
234
237
|
HTMLButtonElement,
|
|
235
238
|
PasswordToggleFieldToggleProps
|
|
236
239
|
>(
|
|
237
|
-
|
|
240
|
+
// blank line to reduce diff noise
|
|
241
|
+
function PasswordToggleFieldToggle(
|
|
238
242
|
{
|
|
239
243
|
__scopePasswordToggleField,
|
|
240
244
|
onClick,
|
|
@@ -250,7 +254,7 @@ const PasswordToggleFieldToggle = React.forwardRef<
|
|
|
250
254
|
...props
|
|
251
255
|
}: ScopedProps<PasswordToggleFieldToggleProps>,
|
|
252
256
|
forwardedRef,
|
|
253
|
-
)
|
|
257
|
+
) {
|
|
254
258
|
const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(
|
|
255
259
|
PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,
|
|
256
260
|
__scopePasswordToggleField,
|
|
@@ -386,7 +390,6 @@ const PasswordToggleFieldToggle = React.forwardRef<
|
|
|
386
390
|
);
|
|
387
391
|
},
|
|
388
392
|
);
|
|
389
|
-
PasswordToggleFieldToggle.displayName = PASSWORD_TOGGLE_FIELD_TOGGLE_NAME;
|
|
390
393
|
|
|
391
394
|
/* -------------------------------------------------------------------------------------------------
|
|
392
395
|
* PasswordToggleFieldSlot
|
|
@@ -423,7 +426,6 @@ const PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({
|
|
|
423
426
|
? props.visible
|
|
424
427
|
: props.hidden;
|
|
425
428
|
};
|
|
426
|
-
PasswordToggleFieldSlot.displayName = PASSWORD_TOGGLE_FIELD_SLOT_NAME;
|
|
427
429
|
|
|
428
430
|
/* -------------------------------------------------------------------------------------------------
|
|
429
431
|
* PasswordToggleFieldIcon
|
|
@@ -438,8 +440,12 @@ interface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children
|
|
|
438
440
|
hidden: React.ReactElement;
|
|
439
441
|
}
|
|
440
442
|
|
|
441
|
-
const PasswordToggleFieldIcon = React.forwardRef<
|
|
442
|
-
|
|
443
|
+
const PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<
|
|
444
|
+
SVGSVGElement,
|
|
445
|
+
PasswordToggleFieldIconProps
|
|
446
|
+
>(
|
|
447
|
+
// blank line to reduce diff noise
|
|
448
|
+
function PasswordToggleFieldIcon(
|
|
443
449
|
{
|
|
444
450
|
__scopePasswordToggleField,
|
|
445
451
|
// @ts-expect-error
|
|
@@ -447,7 +453,7 @@ const PasswordToggleFieldIcon = React.forwardRef<SVGSVGElement, PasswordToggleFi
|
|
|
447
453
|
...props
|
|
448
454
|
}: ScopedProps<PasswordToggleFieldIconProps>,
|
|
449
455
|
forwardedRef,
|
|
450
|
-
)
|
|
456
|
+
) {
|
|
451
457
|
const { visible } = usePasswordToggleFieldContext(
|
|
452
458
|
PASSWORD_TOGGLE_FIELD_ICON_NAME,
|
|
453
459
|
__scopePasswordToggleField,
|
|
@@ -460,7 +466,6 @@ const PasswordToggleFieldIcon = React.forwardRef<SVGSVGElement, PasswordToggleFi
|
|
|
460
466
|
);
|
|
461
467
|
},
|
|
462
468
|
);
|
|
463
|
-
PasswordToggleFieldIcon.displayName = PASSWORD_TOGGLE_FIELD_ICON_NAME;
|
|
464
469
|
|
|
465
470
|
export {
|
|
466
471
|
PasswordToggleField,
|