@wow-two-beta/fe 0.0.39 → 0.0.40
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/formsEngine/AppForm.d.ts +12 -3
- package/dist/formsEngine/FormOperations.d.ts +18 -0
- package/dist/formsEngine/FormOperations.js +9 -0
- package/dist/formsEngine/FormOperations.js.map +1 -1
- package/dist/formsEngine/adapters/house/HouseFormCore.js +15 -6
- package/dist/formsEngine/adapters/house/HouseFormCore.js.map +1 -1
- package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.d.ts +4 -0
- package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.js +10 -1
- package/dist/formsEngine/adapters/tanstack/TanstackFormOverlay.js.map +1 -1
- package/dist/formsEngine/adapters/tanstack/UseAppForm.js +9 -6
- package/dist/formsEngine/adapters/tanstack/UseAppForm.js.map +1 -1
- package/dist/foundation/animation/animatedLayout/AnimatedLayout.d.ts +3 -3
- package/dist/foundation/dom/FocusTarget.d.ts +13 -0
- package/dist/foundation/dom/FocusTarget.js +12 -0
- package/dist/foundation/dom/FocusTarget.js.map +1 -0
- package/dist/foundation/dom/index.d.ts +1 -0
- package/dist/foundation/dom/index.js +3 -0
- package/dist/foundation/dom/index.js.map +1 -1
- package/dist/foundation/primitives/index.d.ts +1 -0
- package/dist/foundation/primitives/index.js +3 -0
- package/dist/foundation/primitives/index.js.map +1 -1
- package/dist/foundation/primitives/swapTransition/SwapTransition.d.ts +76 -0
- package/dist/foundation/primitives/swapTransition/SwapTransition.js +240 -0
- package/dist/foundation/primitives/swapTransition/SwapTransition.js.map +1 -0
- package/dist/foundation/primitives/swapTransition/index.d.ts +1 -0
- package/dist/index.css +11 -0
- package/dist/presentation/display/animatedNumberText/AnimatedNumberText.vue.d.ts +1 -1
- package/dist/presentation/display/carousel/Carousel.vue.d.ts +1 -1
- package/dist/presentation/display/countUpText/CountUpText.vue.d.ts +1 -1
- package/dist/presentation/display/scrollRevealGroup/ScrollRevealGroup.vue.d.ts +2 -2
- package/dist/presentation/forms/imageCropEditor/ImageCropEditor.vue.d.ts +1 -1
- package/dist/presentation/forms/imageEditor/ImageEditor.vue.d.ts +1 -1
- package/dist/presentation/forms/phoneInput/PhoneInput.vue.d.ts +4 -0
- package/dist/presentation/forms/phoneInput/PhoneInput.vue.js +19 -6
- package/dist/presentation/forms/phoneInput/PhoneInput.vue.js.map +1 -1
- package/dist/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue.js +17 -5
- package/dist/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwapTransition.js","sources":["../../../../src/foundation/primitives/swapTransition/SwapTransition.ts"],"sourcesContent":["// A content swap that never jumps: the old content fades out, the box animates its height to the new content's\n// height, and the new content fades in. Between swaps the box follows its content's own height changes.\n//\n// AUTHORED AS `defineComponent` IN PLAIN TS, like `Presence`: the whole job is a render function around Vue's\n// `<Transition>` and imperative motion on two wrapper elements.\n//\n// NON-OBVIOUS DECISIONS:\n//\n// - VUE'S `<Transition mode=\"out-in\">` OWNS THE SWAP. It keeps the leaving child mounted until its leave hook\n// calls `done`, waits for it before rendering the newest child, and cancels an entering child that a newer swap\n// replaces. This component only supplies JS hooks (`css: false`); it never retains a vnode of its own.\n//\n// - THE WRAPPERS ANIMATE, NEVER THE CONTENT. The fades run on the inner wrapper and the height on the outer box,\n// so a child's own inline styles and root shape are untouched. The inner wrapper is `display: flow-root`, so a\n// child's margins stay inside the measured height in every phase.\n//\n// - COMMIT THE END, ANIMATE FROM THE START. Each phase writes its final value inline and runs a `fill: 'none'`\n// WAAPI animation from the current value (`foundation/animation` `animate`), so a cancelled or finished phase\n// always leaves the committed value behind. A swap that interrupts another reads the height and opacity on\n// screen first, so it continues from where the previous motion stood.\n//\n// - A TIMER FLOOR UNDER EVERY PHASE. A hidden document runs no animation frames, so a WAAPI `finish` may never\n// arrive while a tab is in the background; out-in would then never render the new content. Each phase settles\n// on its animation or on a timer past its duration, whichever lands first.\n\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n Transition,\n type SlotsType,\n type StyleValue,\n type VNode,\n} from 'vue';\n\nimport { animate, AnimationDefaults, type AnimationHandle } from '../../animation';\nimport { useReducedMotion } from '../../device';\nimport { FocusTargetAttribute, focusTarget } from '../../dom';\n\n/** Present on the box while a swap runs — from the old content's fade-out to the new content's fade-in. */\nexport const SwapTransitionAttribute = 'data-swapping';\n\n/** The default length of each fade, in milliseconds. */\nconst FadeDurationMs = 120;\n\n/** How long past its duration a phase waits for its animation before settling on a timer instead. */\nconst SettleSlackMs = 250;\n\n/** Keeps a child's margins inside the measured content box in every phase. */\nconst ContentStyle: StyleValue = { display: 'flow-root' };\n\n/** Props for `SwapTransition`. */\nexport interface SwapTransitionProps {\n /** Whether swaps and height changes animate. Defaults to `true`; `false` swaps instantly. */\n readonly isEnabled?: boolean;\n /** The height phase in milliseconds. Defaults to `200`. */\n readonly duration?: number;\n /** Each fade phase in milliseconds. Defaults to `120`. */\n readonly fadeDuration?: number;\n /** The easing curve of every phase. Defaults to the house ease-out curve. */\n readonly easing?: string;\n}\n\n/** Settles when `handle` finishes, or `ms` plus a slack later when no animation frame runs (a hidden document). */\nfunction settle(handle: AnimationHandle, ms: number): Promise<void> {\n return new Promise((resolve) => {\n const timer = setTimeout(() => {\n handle.finish();\n resolve();\n }, ms + SettleSlackMs);\n void handle.finished.then(() => {\n clearTimeout(timer);\n resolve();\n });\n });\n}\n\n/**\n * Swaps its content with a fade and a height animation: on a change of the single child's key or type, the old\n * content fades out, the box animates to the new content's height, and the new content fades in. While shown, the box\n * follows its content's own height changes the same way. The first render, `:is-enabled=\"false\"` and\n * `prefers-reduced-motion` swap and resize instantly.\n *\n * Renders a `div` box (caller `class`, `style` and attributes fall through to it) around a `flow-root` content\n * wrapper. The leaving content is `inert`; focus inside it moves to the box as a programmatic focus target, so it\n * never falls back to the document body.\n */\nexport const SwapTransition = defineComponent({\n name: 'SwapTransition',\n\n props: {\n /** Whether swaps and height changes animate. Defaults to `true`. */\n isEnabled: { type: Boolean, default: undefined },\n /** The height phase in milliseconds. Defaults to `200`. */\n duration: { type: Number, default: undefined },\n /** Each fade phase in milliseconds. Defaults to `120`. */\n fadeDuration: { type: Number, default: undefined },\n /** The easing curve of every phase. Defaults to the house ease-out curve. */\n easing: { type: String, default: undefined },\n },\n\n slots: Object as SlotsType<{ default?: () => VNode[] }>,\n\n setup(props, { slots }) {\n const box = shallowRef<HTMLElement | null>(null);\n const content = shallowRef<HTMLElement | null>(null);\n const prefersReducedMotion = useReducedMotion();\n\n let phase = 0;\n let handle: AnimationHandle | null = null;\n let isSwapping = false;\n let isEntering = false;\n let isFollowing = false;\n let isDisposed = false;\n let lastHeight: number | null = null;\n let observer: ResizeObserver | null = null;\n\n const heightDuration = (): number => props.duration ?? AnimationDefaults.duration;\n const fadeDuration = (): number => props.fadeDuration ?? FadeDurationMs;\n const isAnimated = (): boolean =>\n (props.isEnabled ?? true) && !prefersReducedMotion.value && document.visibilityState !== 'hidden';\n\n /** Cancels the running phase; its continuation sees a newer `phase` and stops. */\n function stop(): void {\n phase += 1;\n handle?.cancel();\n handle = null;\n }\n\n /** Runs one phase; resolves `true` when it ran to its end, `false` when a newer phase or unmount replaced it. */\n async function play(element: HTMLElement, keyframes: Keyframe[], duration: number): Promise<boolean> {\n stop();\n const token = phase;\n const current = animate(element, keyframes, { duration, easing: props.easing });\n handle = current;\n await settle(current, duration);\n if (token !== phase || isDisposed) return false;\n handle = null;\n return true;\n }\n\n /** Animates the box from the height on screen to `to`, committing `to` first. */\n async function resizeTo(boxElement: HTMLElement, to: number): Promise<boolean> {\n const from = boxElement.getBoundingClientRect().height;\n boxElement.style.height = `${to}px`;\n if (from === to) return true;\n return play(boxElement, [{ height: `${from}px` }, { height: `${to}px` }], heightDuration());\n }\n\n /** Holds the box at the height on screen, stopping whatever motion ran, for the swap that starts now. */\n function pin(boxElement: HTMLElement): void {\n const height = boxElement.getBoundingClientRect().height;\n stop();\n isFollowing = false;\n isSwapping = true;\n boxElement.setAttribute(SwapTransitionAttribute, '');\n boxElement.style.height = `${height}px`;\n boxElement.style.overflow = 'hidden';\n }\n\n /** Hands the box back to its content: auto height, visible overflow, full opacity. */\n function release(): void {\n isSwapping = false;\n isFollowing = false;\n const boxElement = box.value;\n if (boxElement) {\n boxElement.style.height = '';\n boxElement.style.overflow = '';\n boxElement.removeAttribute(SwapTransitionAttribute);\n }\n const inner = content.value;\n if (inner) {\n inner.style.opacity = '';\n inner.inert = false;\n lastHeight = inner.getBoundingClientRect().height;\n }\n }\n\n /** Moves focus held inside the leaving content to the box, removing the box's focus target marks on blur. */\n function parkFocus(boxElement: HTMLElement, inner: HTMLElement): void {\n const active = boxElement.ownerDocument.activeElement;\n if (!active || !inner.contains(active)) return;\n const hadTabIndex = boxElement.hasAttribute('tabindex');\n const hadMarker = boxElement.hasAttribute(FocusTargetAttribute);\n if (!focusTarget(boxElement)) return;\n boxElement.addEventListener(\n 'blur',\n () => {\n if (!hadTabIndex) boxElement.removeAttribute('tabindex');\n if (!hadMarker) boxElement.removeAttribute(FocusTargetAttribute);\n },\n { once: true },\n );\n }\n\n function onBeforeLeave(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n parkFocus(boxElement, inner);\n if (!isAnimated()) return;\n // A swap that cancels an entering one fades out from the opacity on screen.\n const opacity = getComputedStyle(inner).opacity;\n pin(boxElement);\n inner.style.opacity = opacity;\n inner.inert = true;\n }\n\n function onLeave(_element: Element, done: () => void): void {\n const inner = content.value;\n if (!inner || !isSwapping) {\n // Out-in renders the next child from `done`; called inside this patch, it would patch over a placeholder\n // that is not mounted yet. A microtask later the patch is over and nothing has painted.\n queueMicrotask(done);\n return;\n }\n const from = inner.style.opacity || '1';\n inner.style.opacity = '0';\n // Content still transparent (a swap that cancels one mid-height) has nothing to fade.\n if (Number(from) === 0) {\n queueMicrotask(done);\n return;\n }\n // Always finish the leave: out-in renders nothing new until `done` runs.\n void play(inner, [{ opacity: from }, { opacity: '0' }], fadeDuration()).then(() => {\n if (!isDisposed) done();\n });\n }\n\n function onAfterLeave(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (inner) inner.inert = false;\n // Out-in mounts the next child before this hook runs; none (a `v-if` turned false) settles on empty content.\n if (!boxElement || !inner || !isSwapping || isEntering) return;\n void resizeTo(boxElement, inner.getBoundingClientRect().height).then((isComplete) => {\n if (isComplete) release();\n });\n }\n\n function onBeforeEnter(): void {\n isEntering = true;\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n inner.inert = false;\n if (!isAnimated()) {\n if (isSwapping) {\n stop();\n release();\n }\n return;\n }\n pin(boxElement);\n inner.style.opacity = '0';\n }\n\n function onEnter(_element: Element, done: () => void): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner || !isSwapping) {\n done();\n return;\n }\n void (async () => {\n if (!(await resizeTo(boxElement, inner.getBoundingClientRect().height))) return;\n inner.style.opacity = '';\n if (!(await play(inner, [{ opacity: '0' }, { opacity: '1' }], fadeDuration()))) return;\n done();\n })();\n }\n\n function onAfterEnter(): void {\n isEntering = false;\n release();\n }\n\n function onEnterCancelled(): void {\n // The leave hooks that follow read the height and opacity on screen before stopping this motion.\n isEntering = false;\n }\n\n /** Between swaps, animates the box from the content's previous height to its new one. */\n function onResize(): void {\n const boxElement = box.value;\n const inner = content.value;\n if (!boxElement || !inner) return;\n const height = inner.getBoundingClientRect().height;\n const previous = lastHeight;\n lastHeight = height;\n if (isSwapping || previous === null || previous === height || !isAnimated()) return;\n // Idle, the auto-height box already shows the new height; a running follow shows its own frame.\n const from = isFollowing ? boxElement.getBoundingClientRect().height : previous;\n stop();\n isFollowing = true;\n boxElement.style.height = `${height}px`;\n boxElement.style.overflow = 'hidden';\n void play(boxElement, [{ height: `${from}px` }, { height: `${height}px` }], heightDuration()).then(\n (isComplete) => {\n if (isComplete && !isSwapping) release();\n },\n );\n }\n\n // `onMounted` never runs on the server: the observer and every measurement stay client-side.\n onMounted(() => {\n const inner = content.value;\n if (!inner || typeof ResizeObserver === 'undefined') return;\n lastHeight = inner.getBoundingClientRect().height;\n observer = new ResizeObserver(onResize);\n observer.observe(inner);\n });\n\n onBeforeUnmount(() => {\n isDisposed = true;\n stop();\n observer?.disconnect();\n observer = null;\n });\n\n return () =>\n h('div', { ref: box }, [\n h('div', { ref: content, style: ContentStyle }, [\n h(\n Transition,\n {\n mode: 'out-in',\n css: false,\n onBeforeLeave,\n onLeave,\n onAfterLeave,\n onBeforeEnter,\n onEnter,\n onAfterEnter,\n onEnterCancelled,\n },\n () => slots.default?.(),\n ),\n ]),\n ]);\n },\n});\n"],"names":[],"mappings":";;;;AA0CO,MAAM,0BAA0B;AAGvC,MAAM,iBAAiB;AAGvB,MAAM,gBAAgB;AAGtB,MAAM,eAA2B,EAAE,SAAS,YAAA;AAe5C,SAAS,OAAO,QAAyB,IAA2B;AAClE,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,QAAQ,WAAW,MAAM;AAC7B,aAAO,OAAA;AACP,cAAA;AAAA,IACF,GAAG,KAAK,aAAa;AACrB,SAAK,OAAO,SAAS,KAAK,MAAM;AAC9B,mBAAa,KAAK;AAClB,cAAA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AAYO,MAAM,iBAAiB,gBAAgB;AAAA,EAC5C,MAAM;AAAA,EAEN,OAAO;AAAA;AAAA,IAEL,WAAW,EAAE,MAAM,SAAS,SAAS,OAAA;AAAA;AAAA,IAErC,UAAU,EAAE,MAAM,QAAQ,SAAS,OAAA;AAAA;AAAA,IAEnC,cAAc,EAAE,MAAM,QAAQ,SAAS,OAAA;AAAA;AAAA,IAEvC,QAAQ,EAAE,MAAM,QAAQ,SAAS,OAAA;AAAA,EAAU;AAAA,EAG7C,OAAO;AAAA,EAEP,MAAM,OAAO,EAAE,SAAS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AAA,MACxB,CACD;AAAA,IAAA,CACF;AAAA,EACL;AACF,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SwapTransition, SwapTransitionAttribute, type SwapTransitionProps } from './SwapTransition';
|
package/dist/index.css
CHANGED
|
@@ -291,6 +291,17 @@ body {
|
|
|
291
291
|
color: var(--color-foreground);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/* A programmatic focus target — what `focusTarget` (`foundation/dom`) marks with `data-focus-target`: a page's `main`
|
|
295
|
+
after a route change, a heading, a region holding focus while its content swaps. It is not a control, so it draws
|
|
296
|
+
no focus ring, and a screen reader still lands on it. The selector outweighs preflight's Firefox ring in the same
|
|
297
|
+
layer, `:-moz-focusring:where(:not(iframe)) { outline: auto }`, which a zero-specificity `:where()` lost to;
|
|
298
|
+
`@layer base` still leaves a utility the app sets on the element in charge. */
|
|
299
|
+
@layer base {
|
|
300
|
+
[data-focus-target]:focus {
|
|
301
|
+
outline: none;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
294
305
|
/* ---------------------------------------------------------------------------
|
|
295
306
|
* Scrollbars — a slim themed track and a pill-shaped thumb on every scroll container, always visible.
|
|
296
307
|
*
|
|
@@ -16,8 +16,8 @@ declare const _default: __VLS_WithSlots<import('vue').DefineComponent<AnimatedNu
|
|
|
16
16
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<AnimatedNumberTextProps> & Readonly<{}>, {
|
|
17
17
|
readonly as: ElementTag;
|
|
18
18
|
readonly format: (value: number) => string;
|
|
19
|
-
readonly duration: number;
|
|
20
19
|
readonly easing: (t: number) => number;
|
|
20
|
+
readonly duration: number;
|
|
21
21
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, {
|
|
22
22
|
/** The rich override for the formatted number — receives the live tween value. */
|
|
23
23
|
value?(props: {
|
|
@@ -21,8 +21,8 @@ declare const _default: __VLS_WithSlots<import('vue').DefineComponent<CarouselPr
|
|
|
21
21
|
}, string, import('vue').PublicProps, Readonly<CarouselProps> & Readonly<{
|
|
22
22
|
"onUpdate:index"?: ((index: number) => any) | undefined;
|
|
23
23
|
}>, {
|
|
24
|
-
readonly canLoop: boolean;
|
|
25
24
|
readonly index: number;
|
|
25
|
+
readonly canLoop: boolean;
|
|
26
26
|
readonly defaultIndex: number;
|
|
27
27
|
readonly autoPlay: number;
|
|
28
28
|
readonly slidesCount: number;
|
|
@@ -21,8 +21,8 @@ declare const _default: __VLS_WithSlots<import('vue').DefineComponent<CountUpTex
|
|
|
21
21
|
readonly as: ElementTag;
|
|
22
22
|
readonly format: (value: number) => string;
|
|
23
23
|
readonly from: number;
|
|
24
|
-
readonly duration: number;
|
|
25
24
|
readonly easing: (t: number) => number;
|
|
25
|
+
readonly duration: number;
|
|
26
26
|
readonly canTriggerOnView: boolean;
|
|
27
27
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, {
|
|
28
28
|
/** The rich override for the formatted number — receives the live tween value. */
|
|
@@ -33,10 +33,10 @@ declare const _default: __VLS_WithSlots<import('vue').DefineComponent<ScrollReve
|
|
|
33
33
|
el: Readonly<import('vue').ShallowRef<HTMLElement | null>>;
|
|
34
34
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<ScrollRevealGroupProps> & Readonly<{}>, {
|
|
35
35
|
readonly as: ElementTag;
|
|
36
|
-
readonly threshold: number;
|
|
37
36
|
readonly duration: number;
|
|
38
|
-
readonly effect: ScrollRevealGroupEffect;
|
|
39
37
|
readonly delay: number;
|
|
38
|
+
readonly threshold: number;
|
|
39
|
+
readonly effect: ScrollRevealGroupEffect;
|
|
40
40
|
readonly isOnce: boolean;
|
|
41
41
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, {
|
|
42
42
|
default(): unknown;
|
|
@@ -33,10 +33,10 @@ declare const _default: import('vue').DefineComponent<ImageCropEditorProps, {
|
|
|
33
33
|
}, string, import('vue').PublicProps, Readonly<ImageCropEditorProps> & Readonly<{
|
|
34
34
|
"onUpdate:modelValue"?: ((crop: CropRect) => any) | undefined;
|
|
35
35
|
}>, {
|
|
36
|
+
readonly alt: string;
|
|
36
37
|
readonly isDisabled: boolean;
|
|
37
38
|
readonly isReadOnly: boolean;
|
|
38
39
|
readonly maxHeight: string;
|
|
39
|
-
readonly alt: string;
|
|
40
40
|
readonly defaultValue: CropRect | null;
|
|
41
41
|
readonly modelValue: CropRect | null;
|
|
42
42
|
readonly aspectRatio: number;
|
|
@@ -26,9 +26,9 @@ declare const _default: import('vue').DefineComponent<ImageEditorProps, {}, {},
|
|
|
26
26
|
onPreview?: ((recipe: ImageEditRecipe) => any) | undefined;
|
|
27
27
|
}>, {
|
|
28
28
|
readonly error: string;
|
|
29
|
+
readonly alt: string;
|
|
29
30
|
readonly isDisabled: boolean;
|
|
30
31
|
readonly isReadOnly: boolean;
|
|
31
|
-
readonly alt: string;
|
|
32
32
|
readonly defaultValue: ImageEditRecipe;
|
|
33
33
|
readonly modelValue: ImageEditRecipe;
|
|
34
34
|
readonly maxDimension: number;
|
|
@@ -20,8 +20,12 @@ export interface PhoneInputProps extends /* @vue-ignore */ NativeInputAttributes
|
|
|
20
20
|
readonly name?: string;
|
|
21
21
|
}
|
|
22
22
|
declare const _default: import('vue').DefineComponent<PhoneInputProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
23
|
+
blur: (event: FocusEvent) => any;
|
|
24
|
+
focus: (event: FocusEvent) => any;
|
|
23
25
|
"update:modelValue": (e164: string) => any;
|
|
24
26
|
}, string, import('vue').PublicProps, Readonly<PhoneInputProps> & Readonly<{
|
|
27
|
+
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
28
|
+
onFocus?: ((event: FocusEvent) => any) | undefined;
|
|
25
29
|
"onUpdate:modelValue"?: ((e164: string) => any) | undefined;
|
|
26
30
|
}>, {
|
|
27
31
|
readonly placeholder: string;
|
|
@@ -27,7 +27,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
27
27
|
placeholder: { default: void 0 },
|
|
28
28
|
name: {}
|
|
29
29
|
},
|
|
30
|
-
emits: ["update:modelValue"],
|
|
30
|
+
emits: ["update:modelValue", "focus", "blur"],
|
|
31
31
|
setup(__props, { emit: __emit }) {
|
|
32
32
|
const props = __props;
|
|
33
33
|
const emit = __emit;
|
|
@@ -147,13 +147,23 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
147
147
|
function placeCaret(field, caret) {
|
|
148
148
|
if (field.ownerDocument.activeElement === field) field.setSelectionRange(caret, caret);
|
|
149
149
|
}
|
|
150
|
+
function isInside(event) {
|
|
151
|
+
const root = event.currentTarget;
|
|
152
|
+
return event.relatedTarget instanceof Node && root.contains(event.relatedTarget);
|
|
153
|
+
}
|
|
154
|
+
function onFocusin(event) {
|
|
155
|
+
if (!isInside(event)) emit("focus", event);
|
|
156
|
+
}
|
|
157
|
+
function onFocusout(event) {
|
|
158
|
+
if (!isInside(event)) emit("blur", event);
|
|
159
|
+
}
|
|
150
160
|
const OwnedAttributes = /* @__PURE__ */ new Set(["class"]);
|
|
151
161
|
const passthroughAttrs = computed(
|
|
152
162
|
() => Object.fromEntries(Object.entries(attrs).filter(([key]) => !OwnedAttributes.has(key)))
|
|
153
163
|
);
|
|
154
164
|
const rootClass = computed(
|
|
155
165
|
() => cn(
|
|
156
|
-
"inline-flex items-stretch overflow-hidden rounded-md border bg-background",
|
|
166
|
+
"inline-flex h-10 items-stretch overflow-hidden rounded-md border bg-background",
|
|
157
167
|
invalid.value ? "border-destructive" : "border-input",
|
|
158
168
|
disabled.value && "opacity-60",
|
|
159
169
|
readOnly.value && "bg-muted text-muted-foreground",
|
|
@@ -162,19 +172,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
162
172
|
);
|
|
163
173
|
const selectClass = computed(
|
|
164
174
|
() => cn(
|
|
165
|
-
"h-
|
|
175
|
+
"h-full cursor-pointer border-r border-input bg-card pl-2 pr-1 text-sm outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
|
|
166
176
|
readOnly.value && "cursor-default bg-muted text-muted-foreground"
|
|
167
177
|
)
|
|
168
178
|
);
|
|
169
179
|
const prefixClass = computed(
|
|
170
180
|
() => cn(
|
|
171
|
-
"flex h-
|
|
181
|
+
"flex h-full items-center border-r border-input bg-card px-2 text-sm",
|
|
172
182
|
readOnly.value && "bg-muted text-muted-foreground"
|
|
173
183
|
)
|
|
174
184
|
);
|
|
175
185
|
const inputClass = cn(
|
|
176
186
|
inputBaseVariants({ size: InputSize.Md }),
|
|
177
|
-
"rounded-none border-0 focus-visible:ring-0 readonly:focus-visible:ring-0"
|
|
187
|
+
"h-full rounded-none border-0 focus-visible:ring-0 readonly:focus-visible:ring-0"
|
|
178
188
|
);
|
|
179
189
|
const formResetAnchor = useTemplateRef("formResetAnchor");
|
|
180
190
|
const formResetRevision = useNativeFormReset(formResetAnchor, () => {
|
|
@@ -186,7 +196,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
186
196
|
key: unref(formResetRevision),
|
|
187
197
|
"data-readonly": readOnly.value || void 0,
|
|
188
198
|
class: rootClass.value
|
|
189
|
-
}, passthroughAttrs.value
|
|
199
|
+
}, passthroughAttrs.value, {
|
|
200
|
+
onFocusin,
|
|
201
|
+
onFocusout
|
|
202
|
+
}), [
|
|
190
203
|
allowed.value.length === 1 ? (openBlock(), createElementBlock("span", {
|
|
191
204
|
key: 0,
|
|
192
205
|
class: normalizeClass(prefixClass.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.vue.js","sources":["../../../../src/presentation/forms/phoneInput/PhoneInput.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { NativeInputAttributes } from '../NativeControlAttributes';\n\nexport interface PhoneInputProps extends /* @vue-ignore */ NativeInputAttributes {\n /** The E.164 value, controlled. The `v-model` binding target. */\n readonly modelValue?: string;\n\n /** The initial E.164 value when uncontrolled. */\n readonly defaultValue?: string;\n\n /** The ISO code selected before the value carries a recognisable dial prefix. Default `US`. */\n readonly defaultCountry?: string;\n\n /** The ISO codes the reader may pick, in display order; unknown codes are ignored. Default every known country. */\n readonly countries?: ReadonlyArray<string>;\n\n /** The disabled state. Falls back to the surrounding form control's `isDisabled`. */\n readonly isDisabled?: boolean;\n\n /** The read-only state. Falls back to the surrounding form control's `isReadOnly`. */\n readonly isReadOnly?: boolean;\n\n /** The invalid surface override. Falls back to the surrounding form control's `isInvalid`. */\n readonly isInvalid?: boolean;\n\n /** The national-number placeholder. Default the country's mask with zeros (`00-000-00-00`), none without a mask. */\n readonly placeholder?: string;\n\n /** The hidden input name; the hidden input emits the full E.164 value. */\n readonly name?: string;\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, ref, useAttrs, useTemplateRef } from 'vue';\nimport type { ClassValue } from 'clsx';\nimport { useLocale } from '../../../foundation/i18n';\nimport { PhoneFormats, PhoneNumberExtensions } from '../../../foundation/phone';\nimport { useFormControl } from '../../../foundation/primitives';\nimport { useControlled } from '../../../foundation/state';\nimport { cn } from '../../../foundation/styles';\nimport { inputBaseVariants, InputSize } from '../InputStyles';\nimport { useNativeFormReset } from '../UseNativeFormReset';\n\n/**\n * Renders a country dial-code select beside a national-number field, emitting one E.164 string.\n *\n * The field takes digits only and shows them through the country's mask (`foundation/phone` `PhoneFormats`); the\n * value never carries a mask character. Pair it with the `phone()` validator for the per-country digit count.\n */\n/* `inheritAttrs: false` so `class` folds into the root's own `cn()` call — plain fallthrough\n appends outside it and loses tailwind-merge conflict resolution. */\ndefineOptions({ name: 'PhoneInput', inheritAttrs: false });\n\nconst props = withDefaults(defineProps<PhoneInputProps>(), {\n defaultCountry: 'US',\n placeholder: undefined,\n /* Explicit `undefined` defaults: `useControlled` keys on `=== undefined`, and Vue casts an\n absent `boolean` prop to `false` — which would shadow the form control context. */\n modelValue: undefined,\n isDisabled: undefined,\n isReadOnly: undefined,\n isInvalid: undefined,\n});\n\nconst emit = defineEmits<{\n /** Fires when the reader edits the number or switches country — the `v-model` half. */\n 'update:modelValue': [e164: string];\n}>();\n\nconst attrs = useAttrs();\n\nconst controlled = useControlled<string>({\n controlled: () => props.modelValue,\n default: () => props.defaultValue ?? '',\n onChange: (next) => {\n emit('update:modelValue', next);\n },\n});\n\nconst e164 = controlled.value;\n\n/* FormControlContext adoption — explicit props stay as overrides. The national-number\n input is the composite's primary control (carries the context id + describedby);\n a user `id` attr stays on the root div. */\nconst ctx = useFormControl();\nconst disabled = computed(() => props.isDisabled ?? ctx?.isDisabled);\nconst readOnly = computed(() => props.isReadOnly ?? ctx?.isReadOnly);\nconst invalid = computed(() => props.isInvalid ?? ctx?.isInvalid);\n\nconst allowed = computed(() => PhoneNumberExtensions.resolveCountries(props.countries));\n/* The fallback must be selectable: a `defaultCountry` outside the list gives way to the first allowed country. */\nconst fallbackIso = computed(\n () => allowed.value.find((c) => c.iso === props.defaultCountry)?.iso ?? allowed.value[0]!.iso,\n);\n\n/* Selected ISO is state — shared dial codes (+1 US/CA) make it unrecoverable from the value\n alone. Re-derive only when the value's dial prefix becomes incompatible with the selection. */\nconst selectedIso = ref(fallbackIso.value);\n\n/* A value whose dial prefix is outside the list matches no allowed country: its digits stay, under the fallback. */\nconst split = computed(() => {\n const selected = allowed.value.find((c) => c.iso === selectedIso.value);\n if (selected && (!e164.value || e164.value.startsWith(selected.dial))) {\n return {\n iso: selected.iso,\n national: PhoneNumberExtensions.digitsOf(e164.value.slice(selected.dial.length)),\n };\n }\n return PhoneNumberExtensions.split(e164.value, allowed.value, fallbackIso.value);\n});\n\nconst iso = computed(() => split.value.iso);\nconst national = computed(() => split.value.national);\nconst country = computed(() => allowed.value.find((c) => c.iso === iso.value) ?? allowed.value[0]!);\nconst format = computed(() => PhoneNumberExtensions.formatOf(country.value));\n/* A value under a dial code the field does not show (outside `countries`) displays its bare digits: the country's\n mask would read them as a national number they are not. */\nconst isForeign = computed(() => e164.value !== '' && !e164.value.startsWith(country.value.dial));\nconst displayed = computed(() =>\n isForeign.value ? national.value : PhoneNumberExtensions.formatNational(national.value, format.value),\n);\nconst placeholderText = computed(() => {\n if (props.placeholder !== undefined) return props.placeholder;\n const mask = PhoneFormats[country.value.iso]?.mask;\n return mask ? mask.replace(/X/g, '0') : undefined;\n});\n\n/* A dial code alone is not a phone number: with no national digits the value is empty, so a blank field submits\n nothing and fails `required` — the selected country survives in `selectedIso`. */\nfunction e164For(dial: string, digits: string): string {\n return digits ? `${dial}${digits}` : '';\n}\n\nfunction setCountry(event: Event): void {\n const nextIso = (event.target as HTMLSelectElement).value;\n const next = allowed.value.find((c) => c.iso === nextIso) ?? country.value;\n selectedIso.value = next.iso;\n const nextValue = e164For(next.dial, national.value);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n}\n\nfunction setDigits(digits: string): void {\n /* Deriving the country before the write keeps a shared dial code (+1 US / CA) on the reader's pick. */\n selectedIso.value = country.value.iso;\n const nextValue = e164For(country.value.dial, digits);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n}\n\n/* An international number replaces the whole field: an allowed dial prefix picks its country, any other keeps every\n digit as a foreign value, where the `phone()` rule reports it. Returns the text the field shows for it — computed\n here, since a controlled value reaches `displayed` only after the parent re-renders. */\nfunction setInternational(text: string): string {\n const parsed = PhoneNumberExtensions.parseInternational(text, allowed.value, country.value.iso);\n if (parsed.country) {\n const max = PhoneNumberExtensions.lengthOf(parsed.country).max;\n const digits = parsed.e164.slice(parsed.country.dial.length, parsed.country.dial.length + max);\n selectedIso.value = parsed.country.iso;\n const nextValue = e164For(parsed.country.dial, digits);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n return PhoneNumberExtensions.formatNational(digits, PhoneNumberExtensions.formatOf(parsed.country));\n }\n\n const nextValue = parsed.e164.length > 1 ? parsed.e164 : '';\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n return nextValue.slice(1);\n}\n\n/* Replacement text (autofill, drop, an untyped `input`) may carry a full `+…` number; typed text never does. */\nconst ReplacementInputTypes: ReadonlySet<string | undefined> = new Set([\n undefined,\n 'insertReplacementText',\n 'insertFromDrop',\n 'insertFromPaste',\n]);\n\n/* The text is rewritten in place on every input: a rejected character changes no state, so Vue would leave it on\n screen. The caret goes back after the digit it followed. */\nfunction setNational(event: Event): void {\n const field = event.target as HTMLInputElement;\n const inputEvent = event as InputEvent;\n if (inputEvent.isComposing) return;\n\n if (ReplacementInputTypes.has(inputEvent.inputType) && field.value.trimStart().startsWith('+')) {\n field.value = setInternational(field.value);\n placeCaret(field, field.value.length);\n return;\n }\n\n const edit = PhoneNumberExtensions.editNational({\n text: field.value,\n caret: field.selectionStart ?? field.value.length,\n previousDigits: national.value,\n inputType: inputEvent.inputType,\n format: format.value,\n });\n field.value = edit.text;\n placeCaret(field, edit.caret);\n setDigits(edit.digits);\n}\n\n/* A pasted `+…` number is international; digits that spell the selected country's dial code and a full national\n number (`998996632582`) lose the dial code; any other paste inserts at the caret as digits. */\nfunction pasteNational(event: ClipboardEvent): void {\n const text = event.clipboardData?.getData('text') ?? '';\n const field = event.target as HTMLInputElement;\n if (text.trimStart().startsWith('+')) {\n event.preventDefault();\n field.value = setInternational(text);\n placeCaret(field, field.value.length);\n return;\n }\n\n const digits = PhoneNumberExtensions.digitsOf(text);\n const stripped = PhoneNumberExtensions.withoutDialCode(digits, country.value);\n if (stripped === digits) return;\n event.preventDefault();\n setDigits(stripped);\n field.value = PhoneNumberExtensions.formatNational(stripped, format.value);\n placeCaret(field, field.value.length);\n}\n\nfunction placeCaret(field: HTMLInputElement, caret: number): void {\n if (field.ownerDocument.activeElement === field) field.setSelectionRange(caret, caret);\n}\n\nconst OwnedAttributes: ReadonlySet<string> = new Set(['class']);\nconst passthroughAttrs = computed(() =>\n Object.fromEntries(Object.entries(attrs).filter(([key]) => !OwnedAttributes.has(key))),\n);\n\nconst rootClass = computed(() =>\n cn(\n 'inline-flex items-stretch overflow-hidden rounded-md border bg-background',\n invalid.value ? 'border-destructive' : 'border-input',\n disabled.value && 'opacity-60',\n readOnly.value && 'bg-muted text-muted-foreground',\n attrs.class as ClassValue,\n ),\n);\n\n/* The country select is a native `<select>`, which has no `readonly`: a read-only phone input disables it, so it\n takes the frame's muted surface and the default cursor rather than the pointer. */\nconst selectClass = computed(() =>\n cn(\n 'h-10 cursor-pointer border-r border-input bg-card pl-2 pr-1 text-sm outline-hidden focus-visible:ring-2 focus-visible:ring-ring',\n readOnly.value && 'cursor-default bg-muted text-muted-foreground',\n ),\n);\n\n/* One allowed country leaves nothing to pick: its flag and dial code sit in the select's place as plain text. */\nconst prefixClass = computed(() =>\n cn(\n 'flex h-10 items-center border-r border-input bg-card px-2 text-sm',\n readOnly.value && 'bg-muted text-muted-foreground',\n ),\n);\n\nconst inputClass = cn(\n inputBaseVariants({ size: InputSize.Md }),\n 'rounded-none border-0 focus-visible:ring-0 readonly:focus-visible:ring-0',\n);\n\nconst formResetAnchor = useTemplateRef<HTMLInputElement>('formResetAnchor');\nconst formResetRevision = useNativeFormReset(formResetAnchor, () => {\n controlled.reset();\n});\n\nconst locale = useLocale();\n</script>\n\n<template>\n <div :key=\"formResetRevision\" :data-readonly=\"readOnly || undefined\" :class=\"rootClass\" v-bind=\"passthroughAttrs\">\n <span v-if=\"allowed.length === 1\" :class=\"prefixClass\">{{ country.flag }} {{ country.dial }}</span>\n <select\n v-else\n :aria-label=\"locale.t('PhoneInput.country', undefined, 'Country')\"\n :value=\"iso\"\n :disabled=\"disabled || readOnly\"\n :class=\"selectClass\"\n :style=\"{ minWidth: '90px' }\"\n @change=\"setCountry\"\n >\n <option v-for=\"c in allowed\" :key=\"c.iso\" :value=\"c.iso\">{{ c.flag }} {{ c.dial }}</option>\n </select>\n <input\n type=\"tel\"\n inputmode=\"tel\"\n autocomplete=\"tel-national\"\n :id=\"ctx?.id\"\n :value=\"displayed\"\n :placeholder=\"placeholderText\"\n :disabled=\"disabled\"\n :readonly=\"readOnly\"\n :aria-invalid=\"invalid || undefined\"\n :aria-describedby=\"ctx?.describedBy\"\n :aria-required=\"ctx?.isRequired || undefined\"\n :class=\"inputClass\"\n @input=\"setNational\"\n @paste=\"pasteNational\"\n />\n <input\n v-if=\"name\"\n type=\"hidden\"\n :disabled=\"disabled\"\n :form=\"typeof $attrs.form === 'string' ? $attrs.form : undefined\"\n :name=\"name\"\n :value=\"e164\"\n />\n <input\n ref=\"formResetAnchor\"\n type=\"hidden\"\n :form=\"typeof $attrs.form === 'string' ? $attrs.form : undefined\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"names":["nextValue","_openBlock","_createElementBlock","_mergeProps","_unref","_toDisplayString","_Fragment","_renderList","_createElementVNode","$attrs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,UAAM,QAAQ;AAWd,UAAM,OAAO;AAKb,UAAM,QAAQ,SAAA;AAEd,UAAM,aAAa,cAAsB;AAAA,MACvC,YAAY,MAAM,MAAM;AAAA,MACxB,SAAS,MAAM,MAAM,gBAAgB;AAAA,MACrC,UAAU,CAAC,SAAS;AAClB,aAAK,qBAAqB,IAAI;AAAA,MAChC;AAAA,IAAA,CACD;AAED,UAAM,OAAO,WAAW;AAKxB,UAAM,MAAM,eAAA;AACZ,UAAM,WAAW,SAAS,MAAM,MAAM,cAAc,KAAK,UAAU;AACnE,UAAM,WAAW,SAAS,MAAM,MAAM,cAAc,KAAK,UAAU;AACnE,UAAM,UAAU,SAAS,MAAM,MAAM,aAAa,KAAK,SAAS;AAEhE,UAAM,UAAU,SAAS,MAAM,sBAAsB,iBAAiB,MAAM,SAAS,CAAC;AAEtF,UAAM,cAAc;AAAA,MAClB,MAAM,QAAQ,MAAM,KAAK,CAAC,MAAM,EAAE,QAAQ,MAAM,cAAc,GAAG,OAAO,QAAQ,MAAM,CAAC,EAAG;AAAA,IAAA;AAK5F,UAAM,cAAc,IAAI,YAAY,KAAK;AAGzC,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,mBAA2FI,UAAA,MAAAC,WAAvE,QAAA,OAAO,CAAZ,MAAC;gCAAhBL,mBAA2F,UAAA;AAAA,cAA7D,KAAK,EAAE;AAAA,cAAM,OAAO,EAAE;AAAA,YAAA,GAAQG,gBAAA,EAAE,IAAI,IAAG,MAACA,gBAAG,EAAE,IAAI,GAAA,GAAA,UAAA;AAAA;;QAEjFG,mBAeE,SAAA;AAAA,UAdA,MAAK;AAAA,UACL,WAAU;AAAA,UACV,cAAa;AAAA,UACZ,IAAIJ,MAAA,GAAA,GAAK;AAAA,UACT,OAAO,UAAA;AAAA,UACP,aAAa,gBAAA;AAAA,UACb,UAAU,SAAA;AAAA,UACV,UAAU,SAAA;AAAA,UACV,gBAAc,QAAA,SAAW;AAAA,UACzB,oBAAkBA,MAAA,GAAA,GAAK;AAAA,UACvB,iBAAeA,MAAA,GAAA,GAAK,cAAc;AAAA,UAClC,sBAAOA,MAAA,UAAA,CAAU;AAAA,UACjB,SAAO;AAAA,UACP,SAAO;AAAA,QAAA;QAGF,QAAA,qBADRF,mBAOE,SAAA;AAAA;UALA,MAAK;AAAA,UACJ,UAAU,SAAA;AAAA,UACV,MAAI,OAASO,YAAO,oBAAoBA,KAAAA,OAAO,OAAO;AAAA,UACtD,MAAM,QAAA;AAAA,UACN,OAAOL,MAAA,IAAA;AAAA,QAAA;QAEVI,mBAKE,SAAA;AAAA,mBAJI;AAAA,UAAJ,KAAI;AAAA,UACJ,MAAK;AAAA,UACJ,MAAI,OAASC,YAAO,oBAAoBA,KAAAA,OAAO,OAAO;AAAA,UACvD,eAAY;AAAA,QAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"PhoneInput.vue.js","sources":["../../../../src/presentation/forms/phoneInput/PhoneInput.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { NativeInputAttributes } from '../NativeControlAttributes';\n\nexport interface PhoneInputProps extends /* @vue-ignore */ NativeInputAttributes {\n /** The E.164 value, controlled. The `v-model` binding target. */\n readonly modelValue?: string;\n\n /** The initial E.164 value when uncontrolled. */\n readonly defaultValue?: string;\n\n /** The ISO code selected before the value carries a recognisable dial prefix. Default `US`. */\n readonly defaultCountry?: string;\n\n /** The ISO codes the reader may pick, in display order; unknown codes are ignored. Default every known country. */\n readonly countries?: ReadonlyArray<string>;\n\n /** The disabled state. Falls back to the surrounding form control's `isDisabled`. */\n readonly isDisabled?: boolean;\n\n /** The read-only state. Falls back to the surrounding form control's `isReadOnly`. */\n readonly isReadOnly?: boolean;\n\n /** The invalid surface override. Falls back to the surrounding form control's `isInvalid`. */\n readonly isInvalid?: boolean;\n\n /** The national-number placeholder. Default the country's mask with zeros (`00-000-00-00`), none without a mask. */\n readonly placeholder?: string;\n\n /** The hidden input name; the hidden input emits the full E.164 value. */\n readonly name?: string;\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, ref, useAttrs, useTemplateRef } from 'vue';\nimport type { ClassValue } from 'clsx';\nimport { useLocale } from '../../../foundation/i18n';\nimport { PhoneFormats, PhoneNumberExtensions } from '../../../foundation/phone';\nimport { useFormControl } from '../../../foundation/primitives';\nimport { useControlled } from '../../../foundation/state';\nimport { cn } from '../../../foundation/styles';\nimport { inputBaseVariants, InputSize } from '../InputStyles';\nimport { useNativeFormReset } from '../UseNativeFormReset';\n\n/**\n * Renders a country dial-code select beside a national-number field, emitting one E.164 string.\n *\n * The field takes digits only and shows them through the country's mask (`foundation/phone` `PhoneFormats`); the\n * value never carries a mask character. Pair it with the `phone()` validator for the per-country digit count.\n */\n/* `inheritAttrs: false` so `class` folds into the root's own `cn()` call — plain fallthrough\n appends outside it and loses tailwind-merge conflict resolution. */\ndefineOptions({ name: 'PhoneInput', inheritAttrs: false });\n\nconst props = withDefaults(defineProps<PhoneInputProps>(), {\n defaultCountry: 'US',\n placeholder: undefined,\n /* Explicit `undefined` defaults: `useControlled` keys on `=== undefined`, and Vue casts an\n absent `boolean` prop to `false` — which would shadow the form control context. */\n modelValue: undefined,\n isDisabled: undefined,\n isReadOnly: undefined,\n isInvalid: undefined,\n});\n\nconst emit = defineEmits<{\n /** Fires when the reader edits the number or switches country — the `v-model` half. */\n 'update:modelValue': [e164: string];\n /** Fires when focus enters the control from outside it — the country select or the number field. */\n focus: [event: FocusEvent];\n /** Fires when focus leaves the whole control; moving between the country select and the number field stays inside. */\n blur: [event: FocusEvent];\n}>();\n\nconst attrs = useAttrs();\n\nconst controlled = useControlled<string>({\n controlled: () => props.modelValue,\n default: () => props.defaultValue ?? '',\n onChange: (next) => {\n emit('update:modelValue', next);\n },\n});\n\nconst e164 = controlled.value;\n\n/* FormControlContext adoption — explicit props stay as overrides. The national-number\n input is the composite's primary control (carries the context id + describedby);\n a user `id` attr stays on the root div. */\nconst ctx = useFormControl();\nconst disabled = computed(() => props.isDisabled ?? ctx?.isDisabled);\nconst readOnly = computed(() => props.isReadOnly ?? ctx?.isReadOnly);\nconst invalid = computed(() => props.isInvalid ?? ctx?.isInvalid);\n\nconst allowed = computed(() => PhoneNumberExtensions.resolveCountries(props.countries));\n/* The fallback must be selectable: a `defaultCountry` outside the list gives way to the first allowed country. */\nconst fallbackIso = computed(\n () => allowed.value.find((c) => c.iso === props.defaultCountry)?.iso ?? allowed.value[0]!.iso,\n);\n\n/* Selected ISO is state — shared dial codes (+1 US/CA) make it unrecoverable from the value\n alone. Re-derive only when the value's dial prefix becomes incompatible with the selection. */\nconst selectedIso = ref(fallbackIso.value);\n\n/* A value whose dial prefix is outside the list matches no allowed country: its digits stay, under the fallback. */\nconst split = computed(() => {\n const selected = allowed.value.find((c) => c.iso === selectedIso.value);\n if (selected && (!e164.value || e164.value.startsWith(selected.dial))) {\n return {\n iso: selected.iso,\n national: PhoneNumberExtensions.digitsOf(e164.value.slice(selected.dial.length)),\n };\n }\n return PhoneNumberExtensions.split(e164.value, allowed.value, fallbackIso.value);\n});\n\nconst iso = computed(() => split.value.iso);\nconst national = computed(() => split.value.national);\nconst country = computed(() => allowed.value.find((c) => c.iso === iso.value) ?? allowed.value[0]!);\nconst format = computed(() => PhoneNumberExtensions.formatOf(country.value));\n/* A value under a dial code the field does not show (outside `countries`) displays its bare digits: the country's\n mask would read them as a national number they are not. */\nconst isForeign = computed(() => e164.value !== '' && !e164.value.startsWith(country.value.dial));\nconst displayed = computed(() =>\n isForeign.value ? national.value : PhoneNumberExtensions.formatNational(national.value, format.value),\n);\nconst placeholderText = computed(() => {\n if (props.placeholder !== undefined) return props.placeholder;\n const mask = PhoneFormats[country.value.iso]?.mask;\n return mask ? mask.replace(/X/g, '0') : undefined;\n});\n\n/* A dial code alone is not a phone number: with no national digits the value is empty, so a blank field submits\n nothing and fails `required` — the selected country survives in `selectedIso`. */\nfunction e164For(dial: string, digits: string): string {\n return digits ? `${dial}${digits}` : '';\n}\n\nfunction setCountry(event: Event): void {\n const nextIso = (event.target as HTMLSelectElement).value;\n const next = allowed.value.find((c) => c.iso === nextIso) ?? country.value;\n selectedIso.value = next.iso;\n const nextValue = e164For(next.dial, national.value);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n}\n\nfunction setDigits(digits: string): void {\n /* Deriving the country before the write keeps a shared dial code (+1 US / CA) on the reader's pick. */\n selectedIso.value = country.value.iso;\n const nextValue = e164For(country.value.dial, digits);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n}\n\n/* An international number replaces the whole field: an allowed dial prefix picks its country, any other keeps every\n digit as a foreign value, where the `phone()` rule reports it. Returns the text the field shows for it — computed\n here, since a controlled value reaches `displayed` only after the parent re-renders. */\nfunction setInternational(text: string): string {\n const parsed = PhoneNumberExtensions.parseInternational(text, allowed.value, country.value.iso);\n if (parsed.country) {\n const max = PhoneNumberExtensions.lengthOf(parsed.country).max;\n const digits = parsed.e164.slice(parsed.country.dial.length, parsed.country.dial.length + max);\n selectedIso.value = parsed.country.iso;\n const nextValue = e164For(parsed.country.dial, digits);\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n return PhoneNumberExtensions.formatNational(digits, PhoneNumberExtensions.formatOf(parsed.country));\n }\n\n const nextValue = parsed.e164.length > 1 ? parsed.e164 : '';\n if (nextValue !== e164.value) controlled.setValue(nextValue);\n return nextValue.slice(1);\n}\n\n/* Replacement text (autofill, drop, an untyped `input`) may carry a full `+…` number; typed text never does. */\nconst ReplacementInputTypes: ReadonlySet<string | undefined> = new Set([\n undefined,\n 'insertReplacementText',\n 'insertFromDrop',\n 'insertFromPaste',\n]);\n\n/* The text is rewritten in place on every input: a rejected character changes no state, so Vue would leave it on\n screen. The caret goes back after the digit it followed. */\nfunction setNational(event: Event): void {\n const field = event.target as HTMLInputElement;\n const inputEvent = event as InputEvent;\n if (inputEvent.isComposing) return;\n\n if (ReplacementInputTypes.has(inputEvent.inputType) && field.value.trimStart().startsWith('+')) {\n field.value = setInternational(field.value);\n placeCaret(field, field.value.length);\n return;\n }\n\n const edit = PhoneNumberExtensions.editNational({\n text: field.value,\n caret: field.selectionStart ?? field.value.length,\n previousDigits: national.value,\n inputType: inputEvent.inputType,\n format: format.value,\n });\n field.value = edit.text;\n placeCaret(field, edit.caret);\n setDigits(edit.digits);\n}\n\n/* A pasted `+…` number is international; digits that spell the selected country's dial code and a full national\n number (`998996632582`) lose the dial code; any other paste inserts at the caret as digits. */\nfunction pasteNational(event: ClipboardEvent): void {\n const text = event.clipboardData?.getData('text') ?? '';\n const field = event.target as HTMLInputElement;\n if (text.trimStart().startsWith('+')) {\n event.preventDefault();\n field.value = setInternational(text);\n placeCaret(field, field.value.length);\n return;\n }\n\n const digits = PhoneNumberExtensions.digitsOf(text);\n const stripped = PhoneNumberExtensions.withoutDialCode(digits, country.value);\n if (stripped === digits) return;\n event.preventDefault();\n setDigits(stripped);\n field.value = PhoneNumberExtensions.formatNational(stripped, format.value);\n placeCaret(field, field.value.length);\n}\n\nfunction placeCaret(field: HTMLInputElement, caret: number): void {\n if (field.ownerDocument.activeElement === field) field.setSelectionRange(caret, caret);\n}\n\n/* The composite's focus is one focus: the root div never takes focus itself, so `focus` and `blur` follow the\n bubbling `focusin` / `focusout` of its parts and skip a move between them. A `null` related target (focus left\n for the body, or the window lost focus) counts as outside. */\nfunction isInside(event: FocusEvent): boolean {\n const root = event.currentTarget as HTMLElement;\n return event.relatedTarget instanceof Node && root.contains(event.relatedTarget);\n}\n\nfunction onFocusin(event: FocusEvent): void {\n if (!isInside(event)) emit('focus', event);\n}\n\nfunction onFocusout(event: FocusEvent): void {\n if (!isInside(event)) emit('blur', event);\n}\n\nconst OwnedAttributes: ReadonlySet<string> = new Set(['class']);\nconst passthroughAttrs = computed(() =>\n Object.fromEntries(Object.entries(attrs).filter(([key]) => !OwnedAttributes.has(key))),\n);\n\nconst rootClass = computed(() =>\n cn(\n 'inline-flex h-10 items-stretch overflow-hidden rounded-md border bg-background',\n invalid.value ? 'border-destructive' : 'border-input',\n disabled.value && 'opacity-60',\n readOnly.value && 'bg-muted text-muted-foreground',\n attrs.class as ClassValue,\n ),\n);\n\n/* The frame is the medium input step (`h-10`, border included); its parts fill it rather than add their own height\n to the border. The country select is a native `<select>`, which has no `readonly`: a read-only phone input\n disables it, so it takes the frame's muted surface and the default cursor rather than the pointer. */\nconst selectClass = computed(() =>\n cn(\n 'h-full cursor-pointer border-r border-input bg-card pl-2 pr-1 text-sm outline-hidden focus-visible:ring-2 focus-visible:ring-ring',\n readOnly.value && 'cursor-default bg-muted text-muted-foreground',\n ),\n);\n\n/* One allowed country leaves nothing to pick: its flag and dial code sit in the select's place as plain text. */\nconst prefixClass = computed(() =>\n cn(\n 'flex h-full items-center border-r border-input bg-card px-2 text-sm',\n readOnly.value && 'bg-muted text-muted-foreground',\n ),\n);\n\nconst inputClass = cn(\n inputBaseVariants({ size: InputSize.Md }),\n 'h-full rounded-none border-0 focus-visible:ring-0 readonly:focus-visible:ring-0',\n);\n\nconst formResetAnchor = useTemplateRef<HTMLInputElement>('formResetAnchor');\nconst formResetRevision = useNativeFormReset(formResetAnchor, () => {\n controlled.reset();\n});\n\nconst locale = useLocale();\n</script>\n\n<template>\n <div\n :key=\"formResetRevision\"\n :data-readonly=\"readOnly || undefined\"\n :class=\"rootClass\"\n v-bind=\"passthroughAttrs\"\n @focusin=\"onFocusin\"\n @focusout=\"onFocusout\"\n >\n <span v-if=\"allowed.length === 1\" :class=\"prefixClass\">{{ country.flag }} {{ country.dial }}</span>\n <select\n v-else\n :aria-label=\"locale.t('PhoneInput.country', undefined, 'Country')\"\n :value=\"iso\"\n :disabled=\"disabled || readOnly\"\n :class=\"selectClass\"\n :style=\"{ minWidth: '90px' }\"\n @change=\"setCountry\"\n >\n <option v-for=\"c in allowed\" :key=\"c.iso\" :value=\"c.iso\">{{ c.flag }} {{ c.dial }}</option>\n </select>\n <input\n type=\"tel\"\n inputmode=\"tel\"\n autocomplete=\"tel-national\"\n :id=\"ctx?.id\"\n :value=\"displayed\"\n :placeholder=\"placeholderText\"\n :disabled=\"disabled\"\n :readonly=\"readOnly\"\n :aria-invalid=\"invalid || undefined\"\n :aria-describedby=\"ctx?.describedBy\"\n :aria-required=\"ctx?.isRequired || undefined\"\n :class=\"inputClass\"\n @input=\"setNational\"\n @paste=\"pasteNational\"\n />\n <input\n v-if=\"name\"\n type=\"hidden\"\n :disabled=\"disabled\"\n :form=\"typeof $attrs.form === 'string' ? $attrs.form : undefined\"\n :name=\"name\"\n :value=\"e164\"\n />\n <input\n ref=\"formResetAnchor\"\n type=\"hidden\"\n :form=\"typeof $attrs.form === 'string' ? $attrs.form : undefined\"\n aria-hidden=\"true\"\n />\n </div>\n</template>\n"],"names":["nextValue","_openBlock","_createElementBlock","_mergeProps","_unref","_toDisplayString","_Fragment","_renderList","_createElementVNode","$attrs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,UAAM,QAAQ;AAWd,UAAM,OAAO;AASb,UAAM,QAAQ,SAAA;AAEd,UAAM,aAAa,cAAsB;AAAA,MACvC,YAAY,MAAM,MAAM;AAAA,MACxB,SAAS,MAAM,MAAM,gBAAgB;AAAA,MACrC,UAAU,CAAC,SAAS;AAClB,aAAK,qBAAqB,IAAI;AAAA,MA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AAU,SAAA;AAAA,UACV,gBAAc,QAAA,SAAW;AAAA,UACzB,oBAAkBA,MAAA,GAAA,GAAK;AAAA,UACvB,iBAAeA,MAAA,GAAA,GAAK,cAAc;AAAA,UAClC,sBAAOA,MAAA,UAAA,CAAU;AAAA,UACjB,SAAO;AAAA,UACP,SAAO;AAAA,QAAA;QAGF,QAAA,qBADRF,mBAOE,SAAA;AAAA;UALA,MAAK;AAAA,UACJ,UAAU,SAAA;AAAA,UACV,MAAI,OAASO,YAAO,oBAAoBA,KAAAA,OAAO,OAAO;AAAA,UACtD,MAAM,QAAA;AAAA,UACN,OAAOL,MAAA,IAAA;AAAA,QAAA;QAEVI,mBAKE,SAAA;AAAA,mBAJI;AAAA,UAAJ,KAAI;AAAA,UACJ,MAAK;AAAA,UACJ,MAAI,OAASC,YAAO,oBAAoBA,KAAAA,OAAO,OAAO;AAAA,UACvD,eAAY;AAAA,QAAA;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineComponent, shallowRef, onScopeDispose, onMounted, watch, nextTick, openBlock, createElementBlock, toDisplayString } from "vue";
|
|
2
|
-
import { useRoute } from "vue-router";
|
|
2
|
+
import { useRoute, useRouter, START_LOCATION } from "vue-router";
|
|
3
3
|
import { deepestHandleValue, resolveHandleValue } from "../RouteHandles.js";
|
|
4
|
+
import { focusTarget } from "../../../../foundation/dom/FocusTarget.js";
|
|
4
5
|
const _hoisted_1 = {
|
|
5
6
|
"aria-live": "polite",
|
|
6
7
|
"aria-atomic": "true",
|
|
@@ -8,9 +9,7 @@ const _hoisted_1 = {
|
|
|
8
9
|
};
|
|
9
10
|
function focusMainContent() {
|
|
10
11
|
const target = document.getElementById("app-shell-main") ?? document.querySelector("main") ?? document.querySelector("h1");
|
|
11
|
-
if (
|
|
12
|
-
target.tabIndex = -1;
|
|
13
|
-
target.focus({ preventScroll: true });
|
|
12
|
+
if (target) focusTarget(target);
|
|
14
13
|
}
|
|
15
14
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
16
15
|
...{ name: "RouteAnnouncer" },
|
|
@@ -22,8 +21,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
22
21
|
setup(__props) {
|
|
23
22
|
const props = __props;
|
|
24
23
|
const route = useRoute();
|
|
24
|
+
const router = useRouter();
|
|
25
25
|
const message = shallowRef("");
|
|
26
26
|
let lastPath = null;
|
|
27
|
+
let isInitialPending = false;
|
|
27
28
|
let generation = 0;
|
|
28
29
|
let disposed = false;
|
|
29
30
|
onScopeDispose(() => {
|
|
@@ -32,13 +33,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
32
33
|
});
|
|
33
34
|
onMounted(() => {
|
|
34
35
|
const announcesInitial = props.canAnnounceInitial ?? !(props.skipInitial ?? true);
|
|
36
|
+
if (router.currentRoute.value === START_LOCATION) {
|
|
37
|
+
isInitialPending = true;
|
|
38
|
+
const settleInitial = () => {
|
|
39
|
+
isInitialPending = false;
|
|
40
|
+
if (disposed) return;
|
|
41
|
+
if (announcesInitial) void announce(route.path);
|
|
42
|
+
else lastPath = route.path;
|
|
43
|
+
};
|
|
44
|
+
router.isReady().then(settleInitial, settleInitial);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
35
47
|
lastPath = announcesInitial ? null : route.path;
|
|
36
48
|
if (announcesInitial) void announce(route.path);
|
|
37
49
|
});
|
|
38
50
|
watch(
|
|
39
51
|
() => route.path,
|
|
40
52
|
(path) => {
|
|
41
|
-
if (lastPath === path) return;
|
|
53
|
+
if (isInitialPending || lastPath === path) return;
|
|
42
54
|
void announce(path);
|
|
43
55
|
},
|
|
44
56
|
{ flush: "post" }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteAnnouncer.vue.js","sources":["../../../../../src/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue"],"sourcesContent":["<script lang=\"ts\">\n/** Defines the props for {@link RouteAnnouncer}. */\nexport interface RouteAnnouncerProps {\n /** Whether the very first mount resets focus and announces the route too. Default `false`. */\n readonly canAnnounceInitial?: boolean;\n /** @deprecated Use `canAnnounceInitial` (inverted); this alias is removed next release. */\n readonly skipInitial?: boolean;\n}\n\n
|
|
1
|
+
{"version":3,"file":"RouteAnnouncer.vue.js","sources":["../../../../../src/router/adapters/vueRouter/routeAnnouncer/RouteAnnouncer.vue"],"sourcesContent":["<script lang=\"ts\">\nimport { focusTarget } from '../../../../foundation/dom';\n\n/** Defines the props for {@link RouteAnnouncer}. */\nexport interface RouteAnnouncerProps {\n /** Whether the very first mount resets focus and announces the route too. Default `false`. */\n readonly canAnnounceInitial?: boolean;\n /** @deprecated Use `canAnnounceInitial` (inverted); this alias is removed next release. */\n readonly skipInitial?: boolean;\n}\n\n/**\n * Moves keyboard and screen-reader focus to main content — the shell `<main>`, else any `<main>`, else `<h1>` — as a\n * programmatic focus target, which draws no focus ring.\n */\nfunction focusMainContent(): void {\n const target =\n document.getElementById('app-shell-main') ??\n document.querySelector<HTMLElement>('main') ??\n document.querySelector<HTMLElement>('h1');\n if (target) focusTarget(target);\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { nextTick, onMounted, onScopeDispose, shallowRef, watch } from 'vue';\nimport { START_LOCATION, useRoute, useRouter } from 'vue-router';\n\nimport { deepestHandleValue, resolveHandleValue } from '../RouteHandles';\n\n/**\n * Renders a polite, visually-hidden live region that announces the newly navigated page title and resets\n * focus to the main content; skips the initial page, including a first navigation still resolving at mount.\n *\n * Unlike the other root behaviors this stays a COMPONENT rather than becoming a router hook — it\n * owns a live region in the DOM, so it has to render.\n */\ndefineOptions({ name: 'RouteAnnouncer' });\n\nconst props = withDefaults(defineProps<RouteAnnouncerProps>(), {\n canAnnounceInitial: undefined,\n skipInitial: undefined,\n});\n\nconst route = useRoute();\nconst router = useRouter();\nconst message = shallowRef('');\n\n// Keyed on `path` — not `fullPath` — so search/hash-only updates (a filter input syncing through\n// `router.replace`) never yank focus back to main mid-interaction. React needed a ref to absorb\n// StrictMode's double-invoked mount effect; a non-immediate watcher cannot double-fire.\nlet lastPath: string | null = null;\nlet isInitialPending = false;\nlet generation = 0;\nlet disposed = false;\nonScopeDispose(() => {\n disposed = true;\n generation += 1;\n});\n\n// `onMounted` never runs on the server, which is what this needs: it reads and focuses the DOM.\nonMounted(() => {\n const announcesInitial = props.canAnnounceInitial ?? !(props.skipInitial ?? true);\n // An app that mounts before its first navigation resolves (no `await router.isReady()`) still sits on\n // `START_LOCATION` here. That first navigation is the initial page, not a path change: settle on it once the\n // router is ready, in whichever order its path watcher and `isReady` land.\n if (router.currentRoute.value === START_LOCATION) {\n isInitialPending = true;\n const settleInitial = (): void => {\n isInitialPending = false;\n if (disposed) return;\n if (announcesInitial) void announce(route.path);\n else lastPath = route.path;\n };\n router.isReady().then(settleInitial, settleInitial);\n return;\n }\n lastPath = announcesInitial ? null : route.path;\n if (announcesInitial) void announce(route.path);\n});\n\nwatch(\n () => route.path,\n (path) => {\n if (isInitialPending || lastPath === path) return;\n void announce(path);\n },\n { flush: 'post' },\n);\n\nasync function announce(path: string): Promise<void> {\n const current = ++generation;\n lastPath = path;\n // Clear the live region so adjacent pages with the same title still announce once.\n message.value = '';\n await nextTick();\n if (disposed || current !== generation || route.path !== path) return;\n focusMainContent();\n message.value = deepestHandleValue(route, (handle) => resolveHandleValue(handle.title, route)) ?? document.title;\n}\n</script>\n\n<template>\n <div aria-live=\"polite\" aria-atomic=\"true\" class=\"sr-only\">{{ message }}</div>\n</template>\n"],"names":["_createElementBlock","_toDisplayString"],"mappings":";;;;;;;;;AAeA,SAAS,mBAAyB;AAChC,QAAM,SACJ,SAAS,eAAe,gBAAgB,KACxC,SAAS,cAA2B,MAAM,KAC1C,SAAS,cAA2B,IAAI;AAC1C,MAAI,oBAAoB,MAAM;AAChC;;;;;;;;;AAkBA,UAAM,QAAQ;AAKd,UAAM,QAAQ,SAAA;AACd,UAAM,SAAS,UAAA;AACf,UAAM,UAAU,WAAW,EAAE;AAK7B,QAAI,WAA0B;AAC9B,QAAI,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