@adea-ai/ui 0.151.2 → 0.151.7
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/README.md +5 -0
- package/dist/components/composites/action-button/action-button.d.ts.map +1 -1
- package/dist/components/composites/action-button/action-button.js +8 -2
- package/dist/components/composites/action-button/action-button.js.map +1 -1
- package/dist/components/composites/inline-citation/inline-citation.d.ts.map +1 -1
- package/dist/components/composites/inline-citation/inline-citation.js +39 -36
- package/dist/components/composites/inline-citation/inline-citation.js.map +1 -1
- package/dist/components/conversation/scroll-follow-core.d.ts +13 -0
- package/dist/components/conversation/scroll-follow-core.d.ts.map +1 -1
- package/dist/components/conversation/scroll-follow-core.js +12 -1
- package/dist/components/conversation/scroll-follow-core.js.map +1 -1
- package/dist/components/conversation/scroll-follow.d.ts.map +1 -1
- package/dist/components/conversation/scroll-follow.js +52 -21
- package/dist/components/conversation/scroll-follow.js.map +1 -1
- package/dist/components/ui/calendar/calendar.d.ts.map +1 -1
- package/dist/components/ui/calendar/calendar.js +109 -115
- package/dist/components/ui/calendar/calendar.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/r/src/components/composites/action-button/action-button.tsx +11 -1
- package/dist/r/src/components/composites/inline-citation/inline-citation.tsx +112 -105
- package/dist/r/src/components/conversation/scroll-follow-core.ts +23 -0
- package/dist/r/src/components/conversation/scroll-follow.ts +69 -17
- package/dist/r/src/components/ui/calendar/calendar.tsx +99 -104
- package/package.json +8 -2
- package/src/components/composites/action-button/action-button.tsx +11 -1
- package/src/components/composites/inline-citation/inline-citation.tsx +112 -105
- package/src/components/conversation/scroll-follow-core.ts +23 -0
- package/src/components/conversation/scroll-follow.ts +69 -17
- package/src/components/ui/calendar/calendar.tsx +99 -104
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -40,6 +40,11 @@ The package includes source for Solid compilation and Tailwind discovery, and
|
|
|
40
40
|
compiled JavaScript plus declarations for other supported consumers. License and
|
|
41
41
|
donor notices travel in `dist/LICENSE` and `dist/NOTICE`.
|
|
42
42
|
|
|
43
|
+
For shortcut labels in server-side or other non-UI code, import
|
|
44
|
+
`platformModifierKey` from `@adea-ai/ui/components/ui/kbd/platform-modifier`.
|
|
45
|
+
This entry does not load the keyboard components; the keyboard folder entry
|
|
46
|
+
continues to export the same helper for component consumers.
|
|
47
|
+
|
|
43
48
|
## Native select
|
|
44
49
|
|
|
45
50
|
Use `NativeSelect` for a compact list of known choices that should keep native
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-button.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/action-button/action-button.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"action-button.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/action-button/action-button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,GAAG,EACR,KAAK,cAAc,EACpB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAI1D;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,cAAc,GAAG,QAAQ,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IACpF,8FAA8F;IAC9F,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iGAAiG;IACjG,WAAW,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACjD;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACzB,uFAAuF;IACvF,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAwDD,wBAAgB,YAAY,CAAC,CAAC,SAAS,cAAc,GAAG,QAAQ,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,eA6G5F"}
|
|
@@ -2,7 +2,7 @@ import { Button } from "../../ui/button/button.js";
|
|
|
2
2
|
import { Spinner } from "../../ui/spinner/spinner.js";
|
|
3
3
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../../ui/tooltip/tooltip.js";
|
|
4
4
|
import { createComponent, insert, memo, mergeProps, template } from "solid-js/web";
|
|
5
|
-
import { Show, createSignal, splitProps } from "solid-js";
|
|
5
|
+
import { Show, createRoot, createSignal, splitProps } from "solid-js";
|
|
6
6
|
// src/components/composites/action-button/action-button.tsx
|
|
7
7
|
var _tmpl$ = /*#__PURE__*/ template(`<span role=status aria-live=polite class=visually-hidden>`);
|
|
8
8
|
function invokeHandler(handler, event) {
|
|
@@ -19,7 +19,13 @@ function chainedHandler(handler, before) {
|
|
|
19
19
|
}
|
|
20
20
|
function guardedClick(handler, disabled, onActivate = () => {}) {
|
|
21
21
|
return (event) => {
|
|
22
|
-
if (
|
|
22
|
+
if (createRoot((dispose) => {
|
|
23
|
+
try {
|
|
24
|
+
return disabled();
|
|
25
|
+
} finally {
|
|
26
|
+
dispose();
|
|
27
|
+
}
|
|
28
|
+
})) {
|
|
23
29
|
event.preventDefault();
|
|
24
30
|
event.stopImmediatePropagation();
|
|
25
31
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-button.js","names":["Show","createSignal","splitProps","ComponentProps","JSX","ValidComponent","Button","ButtonProps","Spinner","Tooltip","TooltipContent","TooltipTrigger","ActionButtonProps","T","tooltip","tooltipSide","tooltipIcon","Element","busy","busyLabel","invokeHandler","handler","event","Event","Array","isArray","callback","data","chainedHandler","before","guardedClick","disabled","onActivate","MouseEvent","preventDefault","stopImmediatePropagation","ButtonTargetProps","Omit","actionAs","ButtonTarget","props","local","rest","PolymorphicButton","targetProps","_$createComponent","_$mergeProps","as","ActionButton","busyStatus","tooltipOpen","setTooltipOpen","tooltipSuppression","setTooltipSuppression","onClickCapture","buttonProps","PolymorphicButtonTarget","variant","size","touchTarget","class","filter","Boolean","join","tabIndex","undefined","role","href","onClick","detail","onPointerLeave","onBlur","Record","contents","when","children","label","_$memo","fallback","placement","open","onOpenChange","icon","_el$","_tmpl$","_$insert","_$createComponent","PolymorphicButton","_$mergeProps","_$memo"],"sources":["../../../../src/components/composites/action-button/action-button.tsx"],"sourcesContent":["import {\n Show,\n createSignal,\n splitProps,\n type ComponentProps,\n type JSX,\n type ValidComponent,\n} from 'solid-js'\nimport { Button, type ButtonProps } from '../../ui/button'\nimport { Spinner } from '../../ui/spinner'\nimport { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'\n\n/**\n * ActionButton.\n *\n * A Button with optional explanatory tooltip and busy feedback. Use it for a\n * simple action that needs these states; actions with product-specific rules\n * should compose Button directly.\n *\n * The tooltip trigger renders the polymorphic Button itself. A disabled native\n * control cannot receive pointer or keyboard events. When a tooltip is set,\n * disabled actions therefore use focusable `aria-disabled` semantics and guard\n * activation; without a tooltip, native buttons retain native disabling.\n * Custom polymorphic components must forward aria, event, and href props for\n * these guarantees to apply.\n */\nexport type ActionButtonProps<T extends ValidComponent = 'button'> = ButtonProps<T> & {\n /** A short explanation, also shown on keyboard focus. The Button still needs its own name. */\n tooltip?: string\n /** Placement of the explanation; icon actions live in bars, so it defaults below the control. */\n tooltipSide?: 'top' | 'right' | 'bottom' | 'left'\n /**\n * A leading icon repeated inside the explanation, forwarded to the shared\n * tooltip's `icon` slot so a bar of icon actions gets the icon+label tip\n * without hand-composing Button and Tooltip. Decorative by contract: the tip\n * is never the accessible name, so the icon must not carry meaning the label\n * lacks. Size it by leaving the svg bare; the slot fixes it to control size.\n */\n tooltipIcon?: JSX.Element\n /** Disables the action and announces the busy label through a polite status region. */\n busy?: boolean\n /** The activity announced while busy. The Button's accessible name stays unchanged. */\n busyLabel?: string\n}\n\nfunction invokeHandler(handler: unknown, event: Event) {\n if (Array.isArray(handler)) {\n const [callback, data] = handler as [(data: unknown, event: Event) => void, unknown]\n callback(data, event)\n } else if (typeof handler === 'function') {\n const callback = handler as (event: Event) => void\n callback(event)\n }\n}\n\nfunction chainedHandler(handler: unknown, before: (event: Event) => void) {\n return (event: Event) => {\n before(event)\n invokeHandler(handler, event)\n }\n}\n\nfunction guardedClick(\n handler: unknown,\n disabled: () => boolean,\n onActivate: (event: MouseEvent) => void = () => {}\n) {\n return (event: MouseEvent) => {\n if (disabled()) {\n event.preventDefault()\n event.stopImmediatePropagation()\n return\n }\n\n onActivate(event)\n invokeHandler(handler, event)\n }\n}\n\ntype ButtonTargetProps<T extends ValidComponent = 'button'> = Omit<ButtonProps<T>, 'as'> & {\n actionAs?: T\n}\n\n/** Adapter keeps TooltipTrigger's `as` separate from Button's polymorphic `as`. */\nfunction ButtonTarget<T extends ValidComponent = 'button'>(props: ButtonTargetProps<T>) {\n const [local, rest] = splitProps(props as ButtonTargetProps, ['actionAs'])\n const PolymorphicButton = Button as (targetProps: ButtonProps<T>) => JSX.Element\n return <PolymorphicButton as={(local.actionAs ?? 'button') as T} {...(rest as ButtonProps<T>)} />\n}\n\nexport function ActionButton<T extends ValidComponent = 'button'>(props: ActionButtonProps<T>) {\n const [local, rest] = splitProps(props as ActionButtonProps, [\n 'as',\n 'variant',\n 'size',\n 'touchTarget',\n 'class',\n 'children',\n 'disabled',\n 'aria-busy',\n 'tooltip',\n 'tooltipSide',\n 'tooltipIcon',\n 'busy',\n 'busyLabel',\n ])\n const busy = () => local.busy ?? false\n const disabled = () => busy() || !!local.disabled\n const busyStatus = () => local.busyLabel ?? 'Working'\n const [tooltipOpen, setTooltipOpen] = createSignal(false)\n const [tooltipSuppression, setTooltipSuppression] = createSignal<'pointer' | 'focus' | null>(null)\n const onClickCapture = (rest as { onClickCapture?: unknown }).onClickCapture\n const PolymorphicButton = Button as (buttonProps: ButtonProps<T>) => JSX.Element\n const PolymorphicButtonTarget = ButtonTarget as (targetProps: ButtonTargetProps<T>) => JSX.Element\n\n const buttonProps = () => ({\n ...rest,\n // The inner Button would otherwise announce itself as a plain `button`; a\n // caller's own slot still wins.\n 'data-slot': (rest as { 'data-slot'?: string })['data-slot'] ?? 'action-button',\n variant: local.variant,\n size: local.size,\n touchTarget: local.touchTarget,\n class: [local.class, local.tooltip && disabled() && 'aria-disabled:pointer-events-auto']\n .filter(Boolean)\n .join(' '),\n disabled: disabled() && !local.tooltip,\n 'aria-disabled': disabled() ? true : rest['aria-disabled'],\n // Make tooltip-bearing native controls explicit tab stops in WebKit configurations that\n // otherwise skip implicit button stops. A caller's tabIndex remains authoritative.\n tabIndex:\n rest.tabIndex ??\n (local.as === 'a' && disabled() ? (local.tooltip ? 0 : -1) : local.tooltip ? 0 : undefined),\n role: local.as === 'a' && disabled() ? 'link' : rest.role,\n href: local.as === 'a' && disabled() ? undefined : (rest as { href?: string }).href,\n 'aria-busy': busy() || local['aria-busy'],\n onClick: guardedClick(rest.onClick, disabled, (event) => {\n if (!local.tooltip) return\n setTooltipSuppression(event.detail > 0 ? 'pointer' : 'focus')\n setTooltipOpen(false)\n }),\n onPointerLeave: chainedHandler(rest.onPointerLeave, () => {\n if (tooltipSuppression() === 'pointer') setTooltipSuppression(null)\n }),\n onBlur: chainedHandler(rest.onBlur, () => {\n if (tooltipSuppression() === 'focus') setTooltipSuppression(null)\n }),\n onClickCapture: onClickCapture ? guardedClick(onClickCapture, disabled) : undefined,\n 'on:click': guardedClick((rest as Record<string, unknown>)['on:click'], disabled),\n 'oncapture:click': guardedClick((rest as Record<string, unknown>)['oncapture:click'], disabled),\n })\n\n const contents = () => (\n <>\n <Show when={busy()}>\n <Spinner size=\"sm\" label={false} aria-hidden=\"true\" data-icon=\"inline-start\" />\n </Show>\n {local.children}\n </>\n )\n\n return (\n <>\n <Show\n when={local.tooltip}\n fallback={\n <PolymorphicButton\n as={(local.as ?? 'button') as T}\n {...(buttonProps() as unknown as ButtonProps<T>)}\n >\n {contents()}\n </PolymorphicButton>\n }\n >\n <Tooltip\n placement={local.tooltipSide ?? 'bottom'}\n open={tooltipOpen()}\n onOpenChange={(open) => {\n if (open && tooltipSuppression()) return\n setTooltipOpen(open)\n }}\n >\n <TooltipTrigger\n as={PolymorphicButtonTarget}\n {...(buttonProps() as unknown as ComponentProps<typeof PolymorphicButtonTarget>)}\n actionAs={(local.as ?? 'button') as T}\n >\n {contents()}\n </TooltipTrigger>\n <TooltipContent icon={local.tooltipIcon}>{local.tooltip}</TooltipContent>\n </Tooltip>\n </Show>\n <Show when={busy()}>\n <span role=\"status\" aria-live=\"polite\" class=\"visually-hidden\">\n {busyStatus()}\n </span>\n </Show>\n </>\n )\n}\n"],"mappings":";;;;;;;AA6CA,SAASoB,cAAcC,SAAkBC,OAAc;CACrD,IAAIE,MAAMC,QAAQJ,OAAO,GAAG;EAC1B,MAAM,CAACK,UAAUC,QAAQN;EACzBK,SAASC,MAAML,KAAK;CACtB,OAAO,IAAI,OAAOD,YAAY,YAE5BK,QAASJ,KAAK;AAElB;AAEA,SAASM,eAAeP,SAAkBQ,QAAgC;CACxE,QAAQP,UAAiB;EACvBO,OAAOP,KAAK;EACZF,cAAcC,SAASC,KAAK;CAC9B;AACF;AAEA,SAASQ,aACPT,SACAU,UACAC,mBAAgD,CAAC,GACjD;CACA,QAAQV,UAAsB;EAC5B,IAAIS,SAAS,GAAG;GACdT,MAAMY,eAAe;GACrBZ,MAAMa,yBAAyB;GAC/B;EACF;EAEAH,WAAWV,KAAK;EAChBF,cAAcC,SAASC,KAAK;CAC9B;AACF;;AAOA,SAASiB,aAAkDC,OAA6B;CACtF,MAAM,CAACC,OAAOC,QAAQxC,WAAWsC,OAA4B,CAAC,UAAU,CAAC;CAEzE,OAAAK,gBAAQF,QAAiBG,WAAA,EAAA,IAACC,KAAE;EAAA,OAAGN,MAAMH,YAAY;CAAc,EAAA,GAAOI,IAAsB,CAAA;AAC9F;AAEA,SAAgBM,aAAkDR,OAA6B;CAC7F,MAAM,CAACC,OAAOC,QAAQxC,WAAWsC,OAA4B;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;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G,MAAMM,MAAM;MAAc;MAAA,IAAA4B,WAAA;OAAA,OAEpCF,SAAS;MAAC;KAAA,CAAA,CAAA,GAAA5B,gBAEZnC,gBAAc;MAAA,IAACwE,OAAI;OAAA,OAAEzC,MAAMzB;MAAW;MAAA,IAAA2D,WAAA;OAAA,OAAGlC,MAAM3B;MAAO;KAAA,CAAA,CAAA;IAAA;GAAA,CAAA;EAAA;CAAA,CAAA,GAAA+B,gBAG1D7C,MAAI;EAAA,IAAC0E,OAAI;GAAA,OAAExD,KAAK;EAAC;EAAA,IAAAyD,WAAA;GAAA,IAAAQ,OAAAC,OAAA;GAAAC,OAAAF,MAEblC,UAAU;GAAA,OAAAkC;EAAA;CAAA,CAAA,CAAA;AAKrB"}
|
|
1
|
+
{"version":3,"file":"action-button.js","names":["Show","createRoot","createSignal","splitProps","ComponentProps","JSX","ValidComponent","Button","ButtonProps","Spinner","Tooltip","TooltipContent","TooltipTrigger","ActionButtonProps","T","tooltip","tooltipSide","tooltipIcon","Element","busy","busyLabel","invokeHandler","handler","event","Event","Array","isArray","callback","data","chainedHandler","before","guardedClick","disabled","onActivate","MouseEvent","isDisabled","dispose","preventDefault","stopImmediatePropagation","ButtonTargetProps","Omit","actionAs","ButtonTarget","props","local","rest","PolymorphicButton","targetProps","_$createComponent","_$mergeProps","as","ActionButton","busyStatus","tooltipOpen","setTooltipOpen","tooltipSuppression","setTooltipSuppression","onClickCapture","buttonProps","PolymorphicButtonTarget","variant","size","touchTarget","class","filter","Boolean","join","tabIndex","undefined","role","href","onClick","detail","onPointerLeave","onBlur","Record","contents","when","children","label","_$memo","fallback","placement","open","onOpenChange","icon","_el$","_tmpl$","_$insert","_$createComponent","PolymorphicButton","_$mergeProps","_$memo"],"sources":["../../../../src/components/composites/action-button/action-button.tsx"],"sourcesContent":["import {\n Show,\n createRoot,\n createSignal,\n splitProps,\n type ComponentProps,\n type JSX,\n type ValidComponent,\n} from 'solid-js'\nimport { Button, type ButtonProps } from '../../ui/button'\nimport { Spinner } from '../../ui/spinner'\nimport { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'\n\n/**\n * ActionButton.\n *\n * A Button with optional explanatory tooltip and busy feedback. Use it for a\n * simple action that needs these states; actions with product-specific rules\n * should compose Button directly.\n *\n * The tooltip trigger renders the polymorphic Button itself. A disabled native\n * control cannot receive pointer or keyboard events. When a tooltip is set,\n * disabled actions therefore use focusable `aria-disabled` semantics and guard\n * activation; without a tooltip, native buttons retain native disabling.\n * Custom polymorphic components must forward aria, event, and href props for\n * these guarantees to apply.\n */\nexport type ActionButtonProps<T extends ValidComponent = 'button'> = ButtonProps<T> & {\n /** A short explanation, also shown on keyboard focus. The Button still needs its own name. */\n tooltip?: string\n /** Placement of the explanation; icon actions live in bars, so it defaults below the control. */\n tooltipSide?: 'top' | 'right' | 'bottom' | 'left'\n /**\n * A leading icon repeated inside the explanation, forwarded to the shared\n * tooltip's `icon` slot so a bar of icon actions gets the icon+label tip\n * without hand-composing Button and Tooltip. Decorative by contract: the tip\n * is never the accessible name, so the icon must not carry meaning the label\n * lacks. Size it by leaving the svg bare; the slot fixes it to control size.\n */\n tooltipIcon?: JSX.Element\n /** Disables the action and announces the busy label through a polite status region. */\n busy?: boolean\n /** The activity announced while busy. The Button's accessible name stays unchanged. */\n busyLabel?: string\n}\n\nfunction invokeHandler(handler: unknown, event: Event) {\n if (Array.isArray(handler)) {\n const [callback, data] = handler as [(data: unknown, event: Event) => void, unknown]\n callback(data, event)\n } else if (typeof handler === 'function') {\n const callback = handler as (event: Event) => void\n callback(event)\n }\n}\n\nfunction chainedHandler(handler: unknown, before: (event: Event) => void) {\n return (event: Event) => {\n before(event)\n invokeHandler(handler, event)\n }\n}\n\nfunction guardedClick(\n handler: unknown,\n disabled: () => boolean,\n onActivate: (event: MouseEvent) => void = () => {}\n) {\n return (event: MouseEvent) => {\n // A polymorphic trigger can provide a getter that creates reactive work.\n // Event callbacks have no owner, so dispose any such work after the read.\n const isDisabled = createRoot((dispose) => {\n try {\n return disabled()\n } finally {\n dispose()\n }\n })\n if (isDisabled) {\n event.preventDefault()\n event.stopImmediatePropagation()\n return\n }\n\n onActivate(event)\n invokeHandler(handler, event)\n }\n}\n\ntype ButtonTargetProps<T extends ValidComponent = 'button'> = Omit<ButtonProps<T>, 'as'> & {\n actionAs?: T\n}\n\n/** Adapter keeps TooltipTrigger's `as` separate from Button's polymorphic `as`. */\nfunction ButtonTarget<T extends ValidComponent = 'button'>(props: ButtonTargetProps<T>) {\n const [local, rest] = splitProps(props as ButtonTargetProps, ['actionAs'])\n const PolymorphicButton = Button as (targetProps: ButtonProps<T>) => JSX.Element\n return <PolymorphicButton as={(local.actionAs ?? 'button') as T} {...(rest as ButtonProps<T>)} />\n}\n\nexport function ActionButton<T extends ValidComponent = 'button'>(props: ActionButtonProps<T>) {\n const [local, rest] = splitProps(props as ActionButtonProps, [\n 'as',\n 'variant',\n 'size',\n 'touchTarget',\n 'class',\n 'children',\n 'disabled',\n 'aria-busy',\n 'tooltip',\n 'tooltipSide',\n 'tooltipIcon',\n 'busy',\n 'busyLabel',\n ])\n const busy = () => local.busy ?? false\n const disabled = () => busy() || !!local.disabled\n const busyStatus = () => local.busyLabel ?? 'Working'\n const [tooltipOpen, setTooltipOpen] = createSignal(false)\n const [tooltipSuppression, setTooltipSuppression] = createSignal<'pointer' | 'focus' | null>(null)\n const onClickCapture = (rest as { onClickCapture?: unknown }).onClickCapture\n const PolymorphicButton = Button as (buttonProps: ButtonProps<T>) => JSX.Element\n const PolymorphicButtonTarget = ButtonTarget as (targetProps: ButtonTargetProps<T>) => JSX.Element\n\n const buttonProps = () => ({\n ...rest,\n // The inner Button would otherwise announce itself as a plain `button`; a\n // caller's own slot still wins.\n 'data-slot': (rest as { 'data-slot'?: string })['data-slot'] ?? 'action-button',\n variant: local.variant,\n size: local.size,\n touchTarget: local.touchTarget,\n class: [local.class, local.tooltip && disabled() && 'aria-disabled:pointer-events-auto']\n .filter(Boolean)\n .join(' '),\n disabled: disabled() && !local.tooltip,\n 'aria-disabled': disabled() ? true : rest['aria-disabled'],\n // Make tooltip-bearing native controls explicit tab stops in WebKit configurations that\n // otherwise skip implicit button stops. A caller's tabIndex remains authoritative.\n tabIndex:\n rest.tabIndex ??\n (local.as === 'a' && disabled() ? (local.tooltip ? 0 : -1) : local.tooltip ? 0 : undefined),\n role: local.as === 'a' && disabled() ? 'link' : rest.role,\n href: local.as === 'a' && disabled() ? undefined : (rest as { href?: string }).href,\n 'aria-busy': busy() || local['aria-busy'],\n onClick: guardedClick(rest.onClick, disabled, (event) => {\n if (!local.tooltip) return\n setTooltipSuppression(event.detail > 0 ? 'pointer' : 'focus')\n setTooltipOpen(false)\n }),\n onPointerLeave: chainedHandler(rest.onPointerLeave, () => {\n if (tooltipSuppression() === 'pointer') setTooltipSuppression(null)\n }),\n onBlur: chainedHandler(rest.onBlur, () => {\n if (tooltipSuppression() === 'focus') setTooltipSuppression(null)\n }),\n onClickCapture: onClickCapture ? guardedClick(onClickCapture, disabled) : undefined,\n 'on:click': guardedClick((rest as Record<string, unknown>)['on:click'], disabled),\n 'oncapture:click': guardedClick((rest as Record<string, unknown>)['oncapture:click'], disabled),\n })\n\n const contents = () => (\n <>\n <Show when={busy()}>\n <Spinner size=\"sm\" label={false} aria-hidden=\"true\" data-icon=\"inline-start\" />\n </Show>\n {local.children}\n </>\n )\n\n return (\n <>\n <Show\n when={local.tooltip}\n fallback={\n <PolymorphicButton\n as={(local.as ?? 'button') as T}\n {...(buttonProps() as unknown as ButtonProps<T>)}\n >\n {contents()}\n </PolymorphicButton>\n }\n >\n <Tooltip\n placement={local.tooltipSide ?? 'bottom'}\n open={tooltipOpen()}\n onOpenChange={(open) => {\n if (open && tooltipSuppression()) return\n setTooltipOpen(open)\n }}\n >\n <TooltipTrigger\n as={PolymorphicButtonTarget}\n {...(buttonProps() as unknown as ComponentProps<typeof PolymorphicButtonTarget>)}\n actionAs={(local.as ?? 'button') as T}\n >\n {contents()}\n </TooltipTrigger>\n <TooltipContent icon={local.tooltipIcon}>{local.tooltip}</TooltipContent>\n </Tooltip>\n </Show>\n <Show when={busy()}>\n <span role=\"status\" aria-live=\"polite\" class=\"visually-hidden\">\n {busyStatus()}\n </span>\n </Show>\n </>\n )\n}\n"],"mappings":";;;;;;;AA8CA,SAASqB,cAAcC,SAAkBC,OAAc;CACrD,IAAIE,MAAMC,QAAQJ,OAAO,GAAG;EAC1B,MAAM,CAACK,UAAUC,QAAQN;EACzBK,SAASC,MAAML,KAAK;CACtB,OAAO,IAAI,OAAOD,YAAY,YAE5BK,QAASJ,KAAK;AAElB;AAEA,SAASM,eAAeP,SAAkBQ,QAAgC;CACxE,QAAQP,UAAiB;EACvBO,OAAOP,KAAK;EACZF,cAAcC,SAASC,KAAK;CAC9B;AACF;AAEA,SAASQ,aACPT,SACAU,UACAC,mBAAgD,CAAC,GACjD;CACA,QAAQV,UAAsB;EAU5B,IAPmBtB,YAAYmC,YAAY;GACzC,IAAI;IACF,OAAOJ,SAAS;GAClB,UAAU;IACRI,QAAQ;GACV;EACF,CACID,GAAY;GACdZ,MAAMc,eAAe;GACrBd,MAAMe,yBAAyB;GAC/B;EACF;EAEAL,WAAWV,KAAK;EAChBF,cAAcC,SAASC,KAAK;CAC9B;AACF;;AAOA,SAASmB,aAAkDC,OAA6B;CACtF,MAAM,CAACC,OAAOC,QAAQ1C,WAAWwC,OAA4B,CAAC,UAAU,CAAC;CAEzE,OAAAK,gBAAQF,QAAiBG,WAAA,EAAA,IAACC,KAAE;EAAA,OAAGN,MAAMH,YAAY;CAAc,EAAA,GAAOI,IAAsB,CAAA;AAC9F;AAEA,SAAgBM,aAAkDR,OAA6B;CAC7F,MAAM,CAACC,OAAOC,QAAQ1C,WAAWwC,OAA4B;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAAW,CACZ;CACD,MAAMxB,aAAayB,MAAMzB,QAAQ;CACjC,MAAMa,iBAAiBb,KAAK,KAAK,CAAC,CAACyB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c;MAAA,IAAC0E,OAAI;OAAA,OAAEzC,MAAM3B;MAAW;MAAA,IAAA6D,WAAA;OAAA,OAAGlC,MAAM7B;MAAO;KAAA,CAAA,CAAA;IAAA;GAAA,CAAA;EAAA;CAAA,CAAA,GAAAiC,gBAG1DhD,MAAI;EAAA,IAAC6E,OAAI;GAAA,OAAE1D,KAAK;EAAC;EAAA,IAAA2D,WAAA;GAAA,IAAAQ,OAAAC,OAAA;GAAAC,OAAAF,MAEblC,UAAU;GAAA,OAAAkC;EAAA;CAAA,CAAA,CAAA;AAKrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-citation.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/inline-citation/inline-citation.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAA;AAU1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,0DAA0D;IAC1D,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"inline-citation.d.ts","sourceRoot":"","sources":["../../../../src/components/composites/inline-citation/inline-citation.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,mBAAmB,CAAA;AAU1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,0DAA0D;IAC1D,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,kCAwMxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAa7E"}
|
|
@@ -11,12 +11,13 @@ import { Show, createEffect, createSignal, onCleanup, splitProps } from "solid-j
|
|
|
11
11
|
// src/components/composites/inline-citation/inline-citation.tsx
|
|
12
12
|
var _tmpl$ = /*#__PURE__*/ template(`<span aria-hidden=true class="max-w-32 truncate">`);
|
|
13
13
|
var _tmpl$2 = /*#__PURE__*/ template(`<span aria-hidden=true>+`);
|
|
14
|
-
var _tmpl$3 = /*#__PURE__*/ template(`<
|
|
15
|
-
var _tmpl$4 = /*#__PURE__*/ template(`<div class="flex
|
|
16
|
-
var _tmpl$5 = /*#__PURE__*/ template(`<
|
|
17
|
-
var _tmpl$6 = /*#__PURE__*/ template(`<p class="m-0 text-xs text-muted-foreground"
|
|
18
|
-
var _tmpl$7 = /*#__PURE__*/ template(`<p class="m-0
|
|
19
|
-
var _tmpl$8 = /*#__PURE__*/ template(`<
|
|
14
|
+
var _tmpl$3 = /*#__PURE__*/ template(`<span data-slot=inline-citation-root>`);
|
|
15
|
+
var _tmpl$4 = /*#__PURE__*/ template(`<div class="flex items-center justify-between gap-2"><span role=status aria-live=polite class="text-xs text-muted-foreground tabular-nums">Source <!> of </span><span class="flex items-center gap-0.5">`);
|
|
16
|
+
var _tmpl$5 = /*#__PURE__*/ template(`<div class="flex min-w-0 flex-col gap-1.5 px-2 py-1.5">`);
|
|
17
|
+
var _tmpl$6 = /*#__PURE__*/ template(`<p class="m-0 text-xs text-muted-foreground [overflow-wrap:anywhere]">`);
|
|
18
|
+
var _tmpl$7 = /*#__PURE__*/ template(`<p class="m-0 text-xs text-muted-foreground">Address not linked`);
|
|
19
|
+
var _tmpl$8 = /*#__PURE__*/ template(`<p class="m-0 line-clamp-6 text-xs text-muted-foreground [overflow-wrap:anywhere]">`);
|
|
20
|
+
var _tmpl$9 = /*#__PURE__*/ template(`<span class=visually-hidden> (opens in a new tab)`);
|
|
20
21
|
var LEAVE_DELAY = 200;
|
|
21
22
|
function InlineCitation(props) {
|
|
22
23
|
const [local] = splitProps(props, [
|
|
@@ -83,7 +84,8 @@ function InlineCitation(props) {
|
|
|
83
84
|
return count() > 0;
|
|
84
85
|
},
|
|
85
86
|
get children() {
|
|
86
|
-
|
|
87
|
+
var _el$ = _tmpl$3();
|
|
88
|
+
insert(_el$, createComponent(Popover, {
|
|
87
89
|
get open() {
|
|
88
90
|
return mode() !== "closed";
|
|
89
91
|
},
|
|
@@ -115,18 +117,18 @@ function InlineCitation(props) {
|
|
|
115
117
|
onBlur: () => dispatch("blur"),
|
|
116
118
|
get children() {
|
|
117
119
|
return [(() => {
|
|
118
|
-
var _el$ = _tmpl$();
|
|
119
|
-
insert(_el
|
|
120
|
-
return _el
|
|
120
|
+
var _el$2 = _tmpl$();
|
|
121
|
+
insert(_el$2, () => citationLabel(local.index, local.sources[0]));
|
|
122
|
+
return _el$2;
|
|
121
123
|
})(), createComponent(Show, {
|
|
122
124
|
get when() {
|
|
123
125
|
return count() > 1;
|
|
124
126
|
},
|
|
125
127
|
get children() {
|
|
126
|
-
var _el$
|
|
127
|
-
_el$
|
|
128
|
-
insert(_el$
|
|
129
|
-
return _el$
|
|
128
|
+
var _el$3 = _tmpl$2();
|
|
129
|
+
_el$3.firstChild;
|
|
130
|
+
insert(_el$3, () => count() - 1, null);
|
|
131
|
+
return _el$3;
|
|
130
132
|
}
|
|
131
133
|
})];
|
|
132
134
|
}
|
|
@@ -168,18 +170,18 @@ function InlineCitation(props) {
|
|
|
168
170
|
return active();
|
|
169
171
|
},
|
|
170
172
|
children: (source) => (() => {
|
|
171
|
-
var _el$
|
|
172
|
-
insert(_el$
|
|
173
|
+
var _el$5 = _tmpl$5();
|
|
174
|
+
insert(_el$5, createComponent(Show, {
|
|
173
175
|
get when() {
|
|
174
176
|
return count() > 1;
|
|
175
177
|
},
|
|
176
178
|
get children() {
|
|
177
|
-
var _el$
|
|
178
|
-
_el$
|
|
179
|
-
var _el$
|
|
180
|
-
insert(_el$
|
|
181
|
-
insert(_el$
|
|
182
|
-
insert(_el$
|
|
179
|
+
var _el$6 = _tmpl$4(), _el$7 = _el$6.firstChild, _el$0 = _el$7.firstChild.nextSibling;
|
|
180
|
+
_el$0.nextSibling;
|
|
181
|
+
var _el$1 = _el$7.nextSibling;
|
|
182
|
+
insert(_el$7, () => wrapIndex(position(), count()) + 1, _el$0);
|
|
183
|
+
insert(_el$7, count, null);
|
|
184
|
+
insert(_el$1, createComponent(ActionButton, {
|
|
183
185
|
variant: "ghost",
|
|
184
186
|
size: "icon-xs",
|
|
185
187
|
"aria-label": "Previous source",
|
|
@@ -189,7 +191,7 @@ function InlineCitation(props) {
|
|
|
189
191
|
return createComponent(ChevronLeft, {});
|
|
190
192
|
}
|
|
191
193
|
}), null);
|
|
192
|
-
insert(_el$
|
|
194
|
+
insert(_el$1, createComponent(ActionButton, {
|
|
193
195
|
variant: "ghost",
|
|
194
196
|
size: "icon-xs",
|
|
195
197
|
"aria-label": "Next source",
|
|
@@ -199,25 +201,26 @@ function InlineCitation(props) {
|
|
|
199
201
|
return createComponent(ChevronRight, {});
|
|
200
202
|
}
|
|
201
203
|
}), null);
|
|
202
|
-
return _el$
|
|
204
|
+
return _el$6;
|
|
203
205
|
}
|
|
204
206
|
}), null);
|
|
205
|
-
insert(_el$
|
|
207
|
+
insert(_el$5, createComponent(PopoverTitle, {
|
|
206
208
|
"class": "p-0 [overflow-wrap:anywhere]",
|
|
207
209
|
get children() {
|
|
208
210
|
return sourceTitle(source());
|
|
209
211
|
}
|
|
210
212
|
}), null);
|
|
211
|
-
insert(_el$
|
|
213
|
+
insert(_el$5, createComponent(CitationDetails, { get source() {
|
|
212
214
|
return source();
|
|
213
215
|
} }), null);
|
|
214
|
-
return _el$
|
|
216
|
+
return _el$5;
|
|
215
217
|
})()
|
|
216
218
|
});
|
|
217
219
|
}
|
|
218
220
|
})];
|
|
219
221
|
}
|
|
220
|
-
});
|
|
222
|
+
}));
|
|
223
|
+
return _el$;
|
|
221
224
|
}
|
|
222
225
|
});
|
|
223
226
|
}
|
|
@@ -258,9 +261,9 @@ function CitationDetails(props) {
|
|
|
258
261
|
return host();
|
|
259
262
|
},
|
|
260
263
|
get children() {
|
|
261
|
-
var _el$
|
|
262
|
-
insert(_el$
|
|
263
|
-
return _el$
|
|
264
|
+
var _el$10 = _tmpl$6();
|
|
265
|
+
insert(_el$10, host);
|
|
266
|
+
return _el$10;
|
|
264
267
|
}
|
|
265
268
|
}),
|
|
266
269
|
createComponent(Show, {
|
|
@@ -275,7 +278,7 @@ function CitationDetails(props) {
|
|
|
275
278
|
rel: "noreferrer noopener",
|
|
276
279
|
"class": "w-fit max-w-full text-xs [overflow-wrap:anywhere]",
|
|
277
280
|
get children() {
|
|
278
|
-
return [memo(() => boundText(url(), 96)), _tmpl$
|
|
281
|
+
return [memo(() => boundText(url(), 96)), _tmpl$9()];
|
|
279
282
|
}
|
|
280
283
|
})
|
|
281
284
|
}),
|
|
@@ -284,7 +287,7 @@ function CitationDetails(props) {
|
|
|
284
287
|
return withheld();
|
|
285
288
|
},
|
|
286
289
|
get children() {
|
|
287
|
-
return _tmpl$
|
|
290
|
+
return _tmpl$7();
|
|
288
291
|
}
|
|
289
292
|
}),
|
|
290
293
|
createComponent(Show, {
|
|
@@ -292,9 +295,9 @@ function CitationDetails(props) {
|
|
|
292
295
|
return snippet();
|
|
293
296
|
},
|
|
294
297
|
get children() {
|
|
295
|
-
var _el$
|
|
296
|
-
insert(_el$
|
|
297
|
-
return _el$
|
|
298
|
+
var _el$12 = _tmpl$8();
|
|
299
|
+
insert(_el$12, snippet);
|
|
300
|
+
return _el$12;
|
|
298
301
|
}
|
|
299
302
|
})
|
|
300
303
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-citation.js","names":["ChevronLeft","ChevronRight","createEffect","createSignal","onCleanup","Show","splitProps","cn","ActionButton","Button","MessageCitations","Popover","PopoverContent","PopoverTitle","PopoverTrigger","TextLink","SOURCE_SNIPPET_LIMIT","boundText","safeSourceUrl","sourceHost","sourceTitle","Source","citationLabel","citationName","nextCitationMode","wrapIndex","CitationEvent","CitationMode","InlineCitationProps","sources","index","hoverDelay","class","LEAVE_DELAY","InlineCitation","props","local","mode","setMode","position","setPosition","timer","ReturnType","setTimeout","content","HTMLElement","pressing","restoringFocus","keyboardPeek","setKeyboardPeek","focusInCard","escapeClosedTooltip","onWindowKeyDown","event","KeyboardEvent","key","ownerDocument","querySelector","window","addEventListener","removeEventListener","count","length","active","clear","undefined","clearTimeout","dispatch","current","next","schedule","delay","onPointerEnter","PointerEvent","pointerType","onPointerLeave","onClick","wasPeeking","queueMicrotask","focus","_$createComponent","when","children","open","onOpenChange","placement","gutter","as","variant","size","touchTarget","aria-label","onFocus","FocusEvent","currentTarget","matches","onBlur","_el$","_tmpl$","_$insert","_el$2","_tmpl$2","_el$3","firstChild","ref","element","inert","onOpenAutoFocus","Event","preventDefault","onFocusIn","onKeyDown","onCloseAutoFocus","returnFocus","source","_el$4","_tmpl$4","_el$5","_tmpl$3","_el$6","_el$7","_el$9","nextSibling","_el$8","_el$0","tooltip","value","CitationDetails","messageCitations","render","numbers","flatMap","number","href","url","host","snippet","withheld","_el$1","_tmpl$5","target","rel","_$memo","_tmpl$8","_tmpl$6","_el$11","_tmpl$7","_$createComponent","_$memo"],"sources":["../../../../src/components/composites/inline-citation/inline-citation.tsx"],"sourcesContent":["import { ChevronLeft, ChevronRight } from 'lucide-solid'\nimport { createEffect, createSignal, onCleanup, Show, splitProps } from 'solid-js'\nimport { cn } from '#lib/utils'\nimport { ActionButton } from '../action-button'\nimport { Button } from '../../ui/button'\nimport type { MessageCitations } from '../../ui/message'\nimport { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '../../ui/popover'\nimport { TextLink } from '../../ui/text-link'\nimport {\n SOURCE_SNIPPET_LIMIT,\n boundText,\n safeSourceUrl,\n sourceHost,\n sourceTitle,\n type Source,\n} from '../sources/source'\nimport {\n citationLabel,\n citationName,\n nextCitationMode,\n wrapIndex,\n type CitationEvent,\n type CitationMode,\n} from './citation'\n\n/**\n * InlineCitation.\n *\n * A small badge inside a sentence — \"1\", or a host — that opens the source(s)\n * behind the claim: title, host, address, snippet, and Previous/Next when several\n * sources share one marker. It is an inline element for prose such as\n * `MessageText`: it never breaks across lines, stays on the text baseline, and\n * adds no block of its own. For the list of everything a reply used, reach for\n * `Sources`; the two number sources the same way.\n *\n * ## One popover, two ways to open it\n *\n * A hover card would exclude everyone who is not holding a mouse, so this is a\n * `Popover` that a pointer can also *peek* at:\n *\n * - **Hover or keyboard focus peeks.** The popover opens without taking focus\n * and closes when the pointer or focus leaves. Touch has no hover, so a touch\n * never peeks. A keyboard peek's card is inert, so Tab moves on from the badge\n * to the next control on the page instead of into a card that is closing.\n * - **Click, tap, Enter or Space pins.** Focus moves into the popover so its\n * link and Previous/Next are reachable; it stays until Escape, an outside press,\n * or the badge is pressed again, and focus returns to the badge. Pressing a badge\n * that is only peeking pins it rather than toggling it shut — the transitions\n * are the pure `nextCitationMode`.\n *\n * Kobalte's trigger toggles on every press, so `open` is controlled and its own\n * close request is ignored for the press that we already decided (`pressing`).\n * Without that, hover-then-click, the commonest pointer path, would close the card.\n *\n * ## It makes no claim without sources\n *\n * No sources renders nothing: a marker that points nowhere is not a citation.\n * The address is a link only when `safeSourceUrl` allows it; the host comes from\n * the parsed URL; titles and snippets are clipped, cleaned of direction\n * overrides and rendered as text. The badge's accessible name carries the title\n * and host (the visible label is only a number or a host), so a reader hears\n * what is cited without opening anything.\n */\nexport type InlineCitationProps = {\n /** One source, or several that support the same claim. */\n sources: readonly Source[]\n /**\n * The 1-based number to show, matching the source's position in `Sources`.\n * Omit it to show the host instead; a number is never guessed.\n */\n index?: number\n /** Milliseconds a pointer rests before the peek opens. */\n hoverDelay?: number\n class?: string\n}\n\nconst LEAVE_DELAY = 200\n\nexport function InlineCitation(props: InlineCitationProps) {\n const [local] = splitProps(props, ['sources', 'index', 'hoverDelay', 'class'])\n const [mode, setMode] = createSignal<CitationMode>('closed')\n const [position, setPosition] = createSignal(0)\n let timer: ReturnType<typeof setTimeout> | undefined\n let content: HTMLElement | undefined\n let pressing = false\n // Focus handed back to the badge as the popover closes is not a request to\n // peek again; without this, Escape from a pinned card reopens it as a preview.\n let restoringFocus = false\n // A keyboard peek is a preview of the badge the reader is already on. Its card\n // sits in a portal at the end of the document, so if it stayed tabbable, Tab\n // from the badge would walk into the card, the card would close behind the\n // focus as the badge blurred, and focus would fall to <body> and be pulled\n // back to the badge: a keyboard trap. The card is inert until Enter or Space\n // pins it, and while it closes. A pointer peek stays interactive.\n const [keyboardPeek, setKeyboardPeek] = createSignal(false)\n // Focus goes back to the badge only when it was in the card. A peek never\n // held focus, and its close (finishing after its exit animation) must not\n // pull the reader back from wherever Tab has taken them since.\n let focusInCard = false\n // Escape closes the innermost layer first: an open Previous/Next tooltip, then\n // the card. Kobalte only lets the top-most layer take Escape, and a tooltip\n // that just closed stays the top layer while it animates out, so a second\n // Escape pressed during that exit used to vanish and leave the card open.\n // Whether a tooltip was open is read before any handler runs (window,\n // capture); an Escape that closed nothing else closes the card itself.\n let escapeClosedTooltip = false\n const onWindowKeyDown = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n escapeClosedTooltip =\n content?.ownerDocument.querySelector('[data-slot=\"tooltip-content\"][data-expanded]') != null\n }\n createEffect(() => {\n if (mode() !== 'pinned' || typeof window === 'undefined') return\n window.addEventListener('keydown', onWindowKeyDown, true)\n onCleanup(() => window.removeEventListener('keydown', onWindowKeyDown, true))\n })\n\n const count = () => local.sources.length\n const active = () => local.sources[wrapIndex(position(), count())]\n const clear = () => {\n if (timer !== undefined) clearTimeout(timer)\n timer = undefined\n }\n onCleanup(clear)\n\n const dispatch = (event: CitationEvent) =>\n setMode((current) => {\n const next = nextCitationMode(current, event)\n if (next !== 'peek') setKeyboardPeek(false)\n else if (current === 'closed') setKeyboardPeek(event === 'focus')\n return next\n })\n const schedule = (event: CitationEvent, delay: number) => {\n clear()\n timer = setTimeout(() => dispatch(event), delay)\n }\n\n const onPointerEnter = (event: PointerEvent) => {\n if (event.pointerType === 'touch') return\n schedule('enter', local.hoverDelay ?? 150)\n }\n const onPointerLeave = (event: PointerEvent) => {\n if (event.pointerType === 'touch') return\n schedule('leave', LEAVE_DELAY)\n }\n\n const onClick = () => {\n clear()\n const wasPeeking = mode() === 'peek'\n dispatch('press')\n // Kobalte toggles right after this handler; its request is not a dismissal.\n pressing = true\n queueMicrotask(() => {\n pressing = false\n })\n // The peek never took focus; a deliberate press must hand it over.\n if (wasPeeking) queueMicrotask(() => content?.focus())\n }\n\n return (\n <Show when={count() > 0}>\n <Popover\n open={mode() !== 'closed'}\n onOpenChange={(next) => {\n if (!next && !pressing) dispatch('dismiss')\n }}\n placement=\"bottom\"\n gutter={6}\n >\n <PopoverTrigger\n as={Button}\n variant=\"subtle\"\n size=\"2xs\"\n touchTarget=\"comfortable\"\n data-slot=\"inline-citation\"\n aria-label={citationName(local.sources, local.index)}\n class={cn('mx-0.5 align-baseline tabular-nums', local.class)}\n onClick={onClick}\n onPointerEnter={onPointerEnter}\n onPointerLeave={onPointerLeave}\n onFocus={(event: FocusEvent & { currentTarget: HTMLElement }) => {\n // Mouse focus follows the press; only keyboard focus peeks.\n if (restoringFocus) return\n if (event.currentTarget.matches(':focus-visible')) dispatch('focus')\n }}\n onBlur={() => dispatch('blur')}\n >\n <span aria-hidden=\"true\" class=\"max-w-32 truncate\">\n {citationLabel(local.index, local.sources[0])}\n </span>\n <Show when={count() > 1}>\n <span aria-hidden=\"true\">+{count() - 1}</span>\n </Show>\n </PopoverTrigger>\n <PopoverContent\n ref={(element: HTMLElement) => (content = element)}\n inert={keyboardPeek() || mode() === 'closed' || undefined}\n class=\"w-72 max-w-full\"\n onOpenAutoFocus={(event: Event) => {\n if (mode() === 'peek') event.preventDefault()\n }}\n onFocusIn={() => {\n focusInCard = true\n }}\n onKeyDown={(event: KeyboardEvent) => {\n if (event.key !== 'Escape' || escapeClosedTooltip || mode() !== 'pinned') return\n dispatch('dismiss')\n }}\n onCloseAutoFocus={(event: Event) => {\n const returnFocus = focusInCard\n focusInCard = false\n if (!returnFocus) {\n event.preventDefault()\n return\n }\n // The focus move that follows is synchronous; the microtask ends the window.\n restoringFocus = true\n queueMicrotask(() => {\n restoringFocus = false\n })\n }}\n onPointerEnter={(event: PointerEvent) => {\n if (event.pointerType !== 'touch') clear()\n }}\n onPointerLeave={onPointerLeave}\n >\n <Show when={active()}>\n {(source) => (\n <div class=\"flex min-w-0 flex-col gap-1.5 px-2 py-1.5\">\n <Show when={count() > 1}>\n <div class=\"flex items-center justify-between gap-2\">\n <span\n role=\"status\"\n aria-live=\"polite\"\n class=\"text-xs text-muted-foreground tabular-nums\"\n >\n Source {wrapIndex(position(), count()) + 1} of {count()}\n </span>\n <span class=\"flex items-center gap-0.5\">\n <ActionButton\n variant=\"ghost\"\n size=\"icon-xs\"\n aria-label=\"Previous source\"\n tooltip=\"Previous source\"\n onClick={() => setPosition((value) => wrapIndex(value - 1, count()))}\n >\n <ChevronLeft />\n </ActionButton>\n <ActionButton\n variant=\"ghost\"\n size=\"icon-xs\"\n aria-label=\"Next source\"\n tooltip=\"Next source\"\n onClick={() => setPosition((value) => wrapIndex(value + 1, count()))}\n >\n <ChevronRight />\n </ActionButton>\n </span>\n </div>\n </Show>\n <PopoverTitle class=\"p-0 [overflow-wrap:anywhere]\">\n {sourceTitle(source())}\n </PopoverTitle>\n <CitationDetails source={source()} />\n </div>\n )}\n </Show>\n </PopoverContent>\n </Popover>\n </Show>\n )\n}\n\n/**\n * Citation markers for `MessageText`, from the sources a reply really used.\n *\n * `[^2]` in the text becomes the second source's badge; `[^1,3]` one badge for\n * sources 1 and 3. A number beyond the list leaves the marker as written, and an\n * empty list makes every marker literal, so text can never cite a source the host\n * did not supply.\n *\n * <MessageText text={reply} citations={messageCitations(sources)} />\n */\nexport function messageCitations(sources: readonly Source[]): MessageCitations {\n return {\n count: sources.length,\n render: (numbers) => (\n <InlineCitation\n index={numbers[0]}\n sources={numbers.flatMap((number) => {\n const source = sources[number - 1]\n return source ? [source] : []\n })}\n />\n ),\n }\n}\n\nfunction CitationDetails(props: { source: Source }) {\n const href = () => safeSourceUrl(props.source.url)\n const host = () => sourceHost(props.source.url)\n const snippet = () =>\n props.source.snippet ? boundText(props.source.snippet, SOURCE_SNIPPET_LIMIT) : ''\n const withheld = () => props.source.url !== undefined && props.source.url !== '' && !href()\n\n return (\n <>\n <Show when={host()}>\n <p class=\"m-0 text-xs text-muted-foreground [overflow-wrap:anywhere]\">{host()}</p>\n </Show>\n <Show when={href()}>\n {(url) => (\n <TextLink\n href={url()}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n class=\"w-fit max-w-full text-xs [overflow-wrap:anywhere]\"\n >\n {boundText(url(), 96)}\n <span class=\"visually-hidden\"> (opens in a new tab)</span>\n </TextLink>\n )}\n </Show>\n <Show when={withheld()}>\n <p class=\"m-0 text-xs text-muted-foreground\">Address not linked</p>\n </Show>\n <Show when={snippet()}>\n <p class=\"m-0 line-clamp-6 text-xs text-muted-foreground [overflow-wrap:anywhere]\">\n {snippet()}\n </p>\n </Show>\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4EA,IAAMiC,cAAc;AAEpB,SAAgBC,eAAeC,OAA4B;CACzD,MAAM,CAACC,SAAS9B,WAAW6B,OAAO;EAAC;EAAW;EAAS;EAAc;CAAO,CAAC;CAC7E,MAAM,CAACE,MAAMC,WAAW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,OAAA8C,QAEhBT,OAAO;IAAA,OAAAS;GAAA;EAAA,CAAA;CAAA;AAKlB"}
|
|
1
|
+
{"version":3,"file":"inline-citation.js","names":["ChevronLeft","ChevronRight","createEffect","createSignal","onCleanup","Show","splitProps","cn","ActionButton","Button","MessageCitations","Popover","PopoverContent","PopoverTitle","PopoverTrigger","TextLink","SOURCE_SNIPPET_LIMIT","boundText","safeSourceUrl","sourceHost","sourceTitle","Source","citationLabel","citationName","nextCitationMode","wrapIndex","CitationEvent","CitationMode","InlineCitationProps","sources","index","hoverDelay","class","LEAVE_DELAY","InlineCitation","props","local","mode","setMode","position","setPosition","timer","ReturnType","setTimeout","content","HTMLElement","pressing","restoringFocus","keyboardPeek","setKeyboardPeek","focusInCard","escapeClosedTooltip","onWindowKeyDown","event","KeyboardEvent","key","ownerDocument","querySelector","window","addEventListener","removeEventListener","count","length","active","clear","undefined","clearTimeout","dispatch","current","next","schedule","delay","onPointerEnter","PointerEvent","pointerType","onPointerLeave","onClick","wasPeeking","queueMicrotask","focus","_$createComponent","when","children","_el$","_tmpl$3","_$insert","open","onOpenChange","placement","gutter","as","variant","size","touchTarget","aria-label","onFocus","FocusEvent","currentTarget","matches","onBlur","_el$2","_tmpl$","_el$3","_tmpl$2","_el$4","firstChild","ref","element","inert","onOpenAutoFocus","Event","preventDefault","onFocusIn","onKeyDown","onCloseAutoFocus","returnFocus","source","_el$5","_tmpl$5","_el$6","_tmpl$4","_el$7","_el$8","_el$0","nextSibling","_el$9","_el$1","tooltip","value","CitationDetails","messageCitations","render","numbers","flatMap","number","href","url","host","snippet","withheld","_el$10","_tmpl$6","target","rel","_$memo","_tmpl$9","_tmpl$7","_el$12","_tmpl$8","_$createComponent","_$memo"],"sources":["../../../../src/components/composites/inline-citation/inline-citation.tsx"],"sourcesContent":["import { ChevronLeft, ChevronRight } from 'lucide-solid'\nimport { createEffect, createSignal, onCleanup, Show, splitProps } from 'solid-js'\nimport { cn } from '#lib/utils'\nimport { ActionButton } from '../action-button'\nimport { Button } from '../../ui/button'\nimport type { MessageCitations } from '../../ui/message'\nimport { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '../../ui/popover'\nimport { TextLink } from '../../ui/text-link'\nimport {\n SOURCE_SNIPPET_LIMIT,\n boundText,\n safeSourceUrl,\n sourceHost,\n sourceTitle,\n type Source,\n} from '../sources/source'\nimport {\n citationLabel,\n citationName,\n nextCitationMode,\n wrapIndex,\n type CitationEvent,\n type CitationMode,\n} from './citation'\n\n/**\n * InlineCitation.\n *\n * A small badge inside a sentence — \"1\", or a host — that opens the source(s)\n * behind the claim: title, host, address, snippet, and Previous/Next when several\n * sources share one marker. It is an inline element for prose such as\n * `MessageText`: it never breaks across lines, stays on the text baseline, and\n * adds no block of its own. For the list of everything a reply used, reach for\n * `Sources`; the two number sources the same way.\n *\n * ## One popover, two ways to open it\n *\n * A hover card would exclude everyone who is not holding a mouse, so this is a\n * `Popover` that a pointer can also *peek* at:\n *\n * - **Hover or keyboard focus peeks.** The popover opens without taking focus\n * and closes when the pointer or focus leaves. Touch has no hover, so a touch\n * never peeks. A keyboard peek's card is inert, so Tab moves on from the badge\n * to the next control on the page instead of into a card that is closing.\n * - **Click, tap, Enter or Space pins.** Focus moves into the popover so its\n * link and Previous/Next are reachable; it stays until Escape, an outside press,\n * or the badge is pressed again, and focus returns to the badge. Pressing a badge\n * that is only peeking pins it rather than toggling it shut — the transitions\n * are the pure `nextCitationMode`.\n *\n * Kobalte's trigger toggles on every press, so `open` is controlled and its own\n * close request is ignored for the press that we already decided (`pressing`).\n * Without that, hover-then-click, the commonest pointer path, would close the card.\n *\n * ## It makes no claim without sources\n *\n * No sources renders nothing: a marker that points nowhere is not a citation.\n * The address is a link only when `safeSourceUrl` allows it; the host comes from\n * the parsed URL; titles and snippets are clipped, cleaned of direction\n * overrides and rendered as text. The badge's accessible name carries the title\n * and host (the visible label is only a number or a host), so a reader hears\n * what is cited without opening anything.\n */\nexport type InlineCitationProps = {\n /** One source, or several that support the same claim. */\n sources: readonly Source[]\n /**\n * The 1-based number to show, matching the source's position in `Sources`.\n * Omit it to show the host instead; a number is never guessed.\n */\n index?: number\n /** Milliseconds a pointer rests before the peek opens. */\n hoverDelay?: number\n class?: string\n}\n\nconst LEAVE_DELAY = 200\n\nexport function InlineCitation(props: InlineCitationProps) {\n const [local] = splitProps(props, ['sources', 'index', 'hoverDelay', 'class'])\n const [mode, setMode] = createSignal<CitationMode>('closed')\n const [position, setPosition] = createSignal(0)\n let timer: ReturnType<typeof setTimeout> | undefined\n let content: HTMLElement | undefined\n let pressing = false\n // Focus handed back to the badge as the popover closes is not a request to\n // peek again; without this, Escape from a pinned card reopens it as a preview.\n let restoringFocus = false\n // A keyboard peek is a preview of the badge the reader is already on. Its card\n // sits in a portal at the end of the document, so if it stayed tabbable, Tab\n // from the badge would walk into the card, the card would close behind the\n // focus as the badge blurred, and focus would fall to <body> and be pulled\n // back to the badge: a keyboard trap. The card is inert until Enter or Space\n // pins it, and while it closes. A pointer peek stays interactive.\n const [keyboardPeek, setKeyboardPeek] = createSignal(false)\n // Focus goes back to the badge only when it was in the card. A peek never\n // held focus, and its close (finishing after its exit animation) must not\n // pull the reader back from wherever Tab has taken them since.\n let focusInCard = false\n // Escape closes the innermost layer first: an open Previous/Next tooltip, then\n // the card. Kobalte only lets the top-most layer take Escape, and a tooltip\n // that just closed stays the top layer while it animates out, so a second\n // Escape pressed during that exit used to vanish and leave the card open.\n // Whether a tooltip was open is read before any handler runs (window,\n // capture); an Escape that closed nothing else closes the card itself.\n let escapeClosedTooltip = false\n const onWindowKeyDown = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n escapeClosedTooltip =\n content?.ownerDocument.querySelector('[data-slot=\"tooltip-content\"][data-expanded]') != null\n }\n createEffect(() => {\n if (mode() !== 'pinned' || typeof window === 'undefined') return\n window.addEventListener('keydown', onWindowKeyDown, true)\n onCleanup(() => window.removeEventListener('keydown', onWindowKeyDown, true))\n })\n\n const count = () => local.sources.length\n const active = () => local.sources[wrapIndex(position(), count())]\n const clear = () => {\n if (timer !== undefined) clearTimeout(timer)\n timer = undefined\n }\n onCleanup(clear)\n\n const dispatch = (event: CitationEvent) =>\n setMode((current) => {\n const next = nextCitationMode(current, event)\n if (next !== 'peek') setKeyboardPeek(false)\n else if (current === 'closed') setKeyboardPeek(event === 'focus')\n return next\n })\n const schedule = (event: CitationEvent, delay: number) => {\n clear()\n timer = setTimeout(() => dispatch(event), delay)\n }\n\n const onPointerEnter = (event: PointerEvent) => {\n if (event.pointerType === 'touch') return\n schedule('enter', local.hoverDelay ?? 150)\n }\n const onPointerLeave = (event: PointerEvent) => {\n if (event.pointerType === 'touch') return\n schedule('leave', LEAVE_DELAY)\n }\n\n const onClick = () => {\n clear()\n const wasPeeking = mode() === 'peek'\n dispatch('press')\n // Kobalte toggles right after this handler; its request is not a dismissal.\n pressing = true\n queueMicrotask(() => {\n pressing = false\n })\n // The peek never took focus; a deliberate press must hand it over.\n if (wasPeeking) queueMicrotask(() => content?.focus())\n }\n\n // The badge and the popover's portal marker share one wrapper. Without it they\n // are loose siblings in the host's node list, and when the portal marker comes\n // and goes as the card opens and closes, a host that renders its inline nodes\n // as one array (MessageText) reconciles that array and can move the badge,\n // which drops keyboard focus to <body> on the badge the reader just reached.\n return (\n <Show when={count() > 0}>\n <span data-slot=\"inline-citation-root\">\n <Popover\n open={mode() !== 'closed'}\n onOpenChange={(next) => {\n if (!next && !pressing) dispatch('dismiss')\n }}\n placement=\"bottom\"\n gutter={6}\n >\n <PopoverTrigger\n as={Button}\n variant=\"subtle\"\n size=\"2xs\"\n touchTarget=\"comfortable\"\n data-slot=\"inline-citation\"\n aria-label={citationName(local.sources, local.index)}\n class={cn('mx-0.5 align-baseline tabular-nums', local.class)}\n onClick={onClick}\n onPointerEnter={onPointerEnter}\n onPointerLeave={onPointerLeave}\n onFocus={(event: FocusEvent & { currentTarget: HTMLElement }) => {\n // Mouse focus follows the press; only keyboard focus peeks.\n if (restoringFocus) return\n if (event.currentTarget.matches(':focus-visible')) dispatch('focus')\n }}\n onBlur={() => dispatch('blur')}\n >\n <span aria-hidden=\"true\" class=\"max-w-32 truncate\">\n {citationLabel(local.index, local.sources[0])}\n </span>\n <Show when={count() > 1}>\n <span aria-hidden=\"true\">+{count() - 1}</span>\n </Show>\n </PopoverTrigger>\n <PopoverContent\n ref={(element: HTMLElement) => (content = element)}\n inert={keyboardPeek() || mode() === 'closed' || undefined}\n class=\"w-72 max-w-full\"\n onOpenAutoFocus={(event: Event) => {\n if (mode() === 'peek') event.preventDefault()\n }}\n onFocusIn={() => {\n focusInCard = true\n }}\n onKeyDown={(event: KeyboardEvent) => {\n if (event.key !== 'Escape' || escapeClosedTooltip || mode() !== 'pinned') return\n dispatch('dismiss')\n }}\n onCloseAutoFocus={(event: Event) => {\n const returnFocus = focusInCard\n focusInCard = false\n if (!returnFocus) {\n event.preventDefault()\n return\n }\n // The focus move that follows is synchronous; the microtask ends the window.\n restoringFocus = true\n queueMicrotask(() => {\n restoringFocus = false\n })\n }}\n onPointerEnter={(event: PointerEvent) => {\n if (event.pointerType !== 'touch') clear()\n }}\n onPointerLeave={onPointerLeave}\n >\n <Show when={active()}>\n {(source) => (\n <div class=\"flex min-w-0 flex-col gap-1.5 px-2 py-1.5\">\n <Show when={count() > 1}>\n <div class=\"flex items-center justify-between gap-2\">\n <span\n role=\"status\"\n aria-live=\"polite\"\n class=\"text-xs text-muted-foreground tabular-nums\"\n >\n Source {wrapIndex(position(), count()) + 1} of {count()}\n </span>\n <span class=\"flex items-center gap-0.5\">\n <ActionButton\n variant=\"ghost\"\n size=\"icon-xs\"\n aria-label=\"Previous source\"\n tooltip=\"Previous source\"\n onClick={() => setPosition((value) => wrapIndex(value - 1, count()))}\n >\n <ChevronLeft />\n </ActionButton>\n <ActionButton\n variant=\"ghost\"\n size=\"icon-xs\"\n aria-label=\"Next source\"\n tooltip=\"Next source\"\n onClick={() => setPosition((value) => wrapIndex(value + 1, count()))}\n >\n <ChevronRight />\n </ActionButton>\n </span>\n </div>\n </Show>\n <PopoverTitle class=\"p-0 [overflow-wrap:anywhere]\">\n {sourceTitle(source())}\n </PopoverTitle>\n <CitationDetails source={source()} />\n </div>\n )}\n </Show>\n </PopoverContent>\n </Popover>\n </span>\n </Show>\n )\n}\n\n/**\n * Citation markers for `MessageText`, from the sources a reply really used.\n *\n * `[^2]` in the text becomes the second source's badge; `[^1,3]` one badge for\n * sources 1 and 3. A number beyond the list leaves the marker as written, and an\n * empty list makes every marker literal, so text can never cite a source the host\n * did not supply.\n *\n * <MessageText text={reply} citations={messageCitations(sources)} />\n */\nexport function messageCitations(sources: readonly Source[]): MessageCitations {\n return {\n count: sources.length,\n render: (numbers) => (\n <InlineCitation\n index={numbers[0]}\n sources={numbers.flatMap((number) => {\n const source = sources[number - 1]\n return source ? [source] : []\n })}\n />\n ),\n }\n}\n\nfunction CitationDetails(props: { source: Source }) {\n const href = () => safeSourceUrl(props.source.url)\n const host = () => sourceHost(props.source.url)\n const snippet = () =>\n props.source.snippet ? boundText(props.source.snippet, SOURCE_SNIPPET_LIMIT) : ''\n const withheld = () => props.source.url !== undefined && props.source.url !== '' && !href()\n\n return (\n <>\n <Show when={host()}>\n <p class=\"m-0 text-xs text-muted-foreground [overflow-wrap:anywhere]\">{host()}</p>\n </Show>\n <Show when={href()}>\n {(url) => (\n <TextLink\n href={url()}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n class=\"w-fit max-w-full text-xs [overflow-wrap:anywhere]\"\n >\n {boundText(url(), 96)}\n <span class=\"visually-hidden\"> (opens in a new tab)</span>\n </TextLink>\n )}\n </Show>\n <Show when={withheld()}>\n <p class=\"m-0 text-xs text-muted-foreground\">Address not linked</p>\n </Show>\n <Show when={snippet()}>\n <p class=\"m-0 line-clamp-6 text-xs text-muted-foreground [overflow-wrap:anywhere]\">\n {snippet()}\n </p>\n </Show>\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4EA,IAAMiC,cAAc;AAEpB,SAAg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AAzD,WAAA;IAAA,OAAAgE,QAAA;GAAA;EAAA,CAAA;EAAAlE,gBAGrB3E,MAAI;GAAA,IAAC4E,OAAI;IAAA,OAAEyD,QAAQ;GAAC;GAAA,IAAAxD,WAAA;IAAA,IAAAiE,SAAAC,QAAA;IAAA/D,OAAA8D,QAEhBT,OAAO;IAAA,OAAAS;GAAA;EAAA,CAAA;CAAA;AAKlB"}
|
|
@@ -37,6 +37,19 @@ export declare function computeAtBottom(geom: ScrollGeom, threshold: number): bo
|
|
|
37
37
|
* any scroll is treated as the user's.
|
|
38
38
|
*/
|
|
39
39
|
export declare function isSelfScroll(scrollTop: number, lastWriteTop: number, epsilon?: number): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* A viewport can clamp our bottom write before its scroll/resize notification,
|
|
42
|
+
* then streamed content can reopen the gap before either callback runs. Accept
|
|
43
|
+
* only the exact offset explained by that growth, with no reader input. Other
|
|
44
|
+
* offsets still belong to the reader. A programmatic reveal landing at this
|
|
45
|
+
* same offset cannot be distinguished from native clamping by geometry alone.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isViewportGrowthClamp(args: {
|
|
48
|
+
geom: ScrollGeom;
|
|
49
|
+
lastWriteTop: number;
|
|
50
|
+
lastWriteClientHeight: number;
|
|
51
|
+
readerMovedSinceWrite: boolean;
|
|
52
|
+
}): boolean;
|
|
40
53
|
/**
|
|
41
54
|
* Distance (px) from the true bottom within which a user scroll RE-ENGAGES
|
|
42
55
|
* follow. Deliberately much tighter than DEFAULT_BOTTOM_THRESHOLD: that 100px
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-follow-core.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/scroll-follow-core.ts"],"names":[],"mappings":"AAqBA,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,MAAM,CAAA;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,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CAAE,CAAA;AAIhD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAW5D;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,GAAG,EAAE,OAAO,CAAA;IACZ,0EAA0E;IAC1E,KAAK,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,UAAU,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;;;;4CAUwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;;;;;;;;;mDAY+C;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;;;;;;;;;;;;;;kFAiB8E;IAC9E,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,GAAG,aAAa,CAsDhB"}
|
|
1
|
+
{"version":3,"file":"scroll-follow-core.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/scroll-follow-core.ts"],"names":[],"mappings":"AAqBA,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,MAAM,CAAA;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC;AAED,oEAAoE;AACpE,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAErD;AAED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;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAW5D;AAED,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,GAAG,EAAE,OAAO,CAAA;IACZ,0EAA0E;IAC1E,KAAK,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,UAAU,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;;;;4CAUwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;;;;;;;;;mDAY+C;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;;;;;;;;;;;;;;kFAiB8E;IAC9E,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,GAAG,aAAa,CAsDhB"}
|
|
@@ -34,6 +34,17 @@ function isSelfScroll(scrollTop, lastWriteTop, epsilon = 2) {
|
|
|
34
34
|
return lastWriteTop >= 0 && Math.abs(scrollTop - lastWriteTop) <= epsilon;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
+
* A viewport can clamp our bottom write before its scroll/resize notification,
|
|
38
|
+
* then streamed content can reopen the gap before either callback runs. Accept
|
|
39
|
+
* only the exact offset explained by that growth, with no reader input. Other
|
|
40
|
+
* offsets still belong to the reader. A programmatic reveal landing at this
|
|
41
|
+
* same offset cannot be distinguished from native clamping by geometry alone.
|
|
42
|
+
*/
|
|
43
|
+
function isViewportGrowthClamp(args) {
|
|
44
|
+
const growth = args.geom.clientHeight - args.lastWriteClientHeight;
|
|
45
|
+
return !args.readerMovedSinceWrite && args.lastWriteTop >= 0 && args.lastWriteClientHeight >= 0 && growth > 2 && Math.abs(args.geom.scrollTop - Math.max(0, args.lastWriteTop - growth)) <= 2;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
37
48
|
* Direction-aware `stick` decision for a *user-initiated* scroll (self-scrolls
|
|
38
49
|
* filtered out by the caller via `isSelfScroll`):
|
|
39
50
|
*
|
|
@@ -155,6 +166,6 @@ function evaluateAutoPin(args) {
|
|
|
155
166
|
target
|
|
156
167
|
};
|
|
157
168
|
}
|
|
158
|
-
export { atBottomEpsilon, bottomTarget, computeAtBottom, distanceFromBottom, evaluateAutoPin, isScrollUpIntent, isSelfScroll, resolveUserScrollStick };
|
|
169
|
+
export { atBottomEpsilon, bottomTarget, computeAtBottom, distanceFromBottom, evaluateAutoPin, isScrollUpIntent, isSelfScroll, isViewportGrowthClamp, resolveUserScrollStick };
|
|
159
170
|
|
|
160
171
|
//# sourceMappingURL=scroll-follow-core.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-follow-core.js","names":[],"sources":["../../../src/components/conversation/scroll-follow-core.ts"],"sourcesContent":["/*\n * Substantially translated from KiroCrew website/src/hooks/virtualizer/FollowController.ts\n * (plain-scroller decision units), pinned at\n * 283e136c0f902e965a535a7c9548c57c7504fed0.\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * This product includes software developed at Amazon.com, Inc.\n * (https://www.amazon.com/).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Pure plain-scroller decisions retained from FollowController; virtual row\n * measurement, persisted anchor resolution and restore settling are excluded.\n */\n/** Default distance (px) from the bottom within which `isAtBottom` is true. */\nexport const DEFAULT_BOTTOM_THRESHOLD = 100\n\n/**\n * Tolerance (px) for treating a scroll position as \"the same\" as a value we\n * wrote programmatically. Covers sub-pixel rounding and 1px momentum overshoot.\n * Must stay small so a deliberate user scroll of even a few px is still seen as\n * a user scroll.\n */\nexport const SELF_SCROLL_EPSILON = 2\n\n/**\n * \"At the bottom\" tolerance (px) for deciding whether an auto-pin still has\n * work to do. A flat 0.5 is UNDER one device pixel at fractional device-pixel\n * ratios (0.67 CSS px at 150% zoom, 0.8 at 125%): the scroller's resting\n * maximum scrollTop lands on a fractional value, so `|scrollTop - target|`\n * stays just above 0.5 even when the viewport is visually pinned to the\n * bottom — making the pin re-fire on every ResizeObserver tick. Scaling the\n * epsilon to the device pixel (never below 1 CSS px) absorbs that fractional\n * resting error. `devicePixelRatio` is read defensively so a jsdom / SSR\n * environment that leaves it undefined falls back to 1 (→ 1.5px).\n */\nexport function atBottomEpsilon(): number {\n const dpr =\n typeof window !== 'undefined' &&\n typeof window.devicePixelRatio === 'number' &&\n window.devicePixelRatio > 0\n ? window.devicePixelRatio\n : 1\n return Math.max(1, 1 / dpr + 0.5)\n}\n\n/** Live scroll geometry snapshot read from the scroller element. */\nexport interface ScrollGeom {\n scrollTop: number\n scrollHeight: number\n clientHeight: number\n}\n\n/** scrollTop that places the viewport exactly at the bottom (never negative). */\nexport function bottomTarget(geom: ScrollGeom): number {\n return Math.max(0, geom.scrollHeight - geom.clientHeight)\n}\n\n/** Pixels between the current scroll position and the bottom. */\nexport function distanceFromBottom(geom: ScrollGeom): number {\n return geom.scrollHeight - geom.scrollTop - geom.clientHeight\n}\n\n/** Whether the scroller is within `threshold` px of the bottom. */\nexport function computeAtBottom(geom: ScrollGeom, threshold: number): boolean {\n return distanceFromBottom(geom) <= threshold\n}\n\n/**\n * Recognise a `scroll` event caused by our own programmatic write rather than\n * by the user. `lastWriteTop < 0` means \"we have not written this session\", so\n * any scroll is treated as the user's.\n */\nexport function isSelfScroll(\n scrollTop: number,\n lastWriteTop: number,\n epsilon: number = SELF_SCROLL_EPSILON\n): boolean {\n return lastWriteTop >= 0 && Math.abs(scrollTop - lastWriteTop) <= epsilon\n}\n\n/**\n * Distance (px) from the true bottom within which a user scroll RE-ENGAGES\n * follow. Deliberately much tighter than DEFAULT_BOTTOM_THRESHOLD: that 100px\n * band drives the jump-to-bottom pill's visibility, and reusing it for follow\n * meant a deliberate 3-99px scroll-up kept `stick` armed — the next content\n * change then yanked the reader back to the bottom. Re-engaging only when the\n * user has returned essentially to the bottom keeps \"scrolled up to read\"\n * positions belonging to the user.\n */\nexport const FOLLOW_REENGAGE_PX = 16\n\n/**\n * Direction-aware `stick` decision for a *user-initiated* scroll (self-scrolls\n * filtered out by the caller via `isSelfScroll`):\n *\n * 1. At the true bottom (within the DPR-aware epsilon) → follow. This also\n * absorbs the layout engine's clamp: a mid-stream content SHRINK drops\n * scrollTop (which reads as an upward move) but lands exactly at the new\n * bottom — releasing there froze streaming follow for the rest of the\n * turn.\n * 2. Any other upward move → release, regardless of distance from the\n * bottom. The scroll position now belongs to the user; only returning to\n * the bottom (3) re-engages.\n * 3. A genuine DOWNWARD move that arrives within FOLLOW_REENGAGE_PX of the\n * bottom → re-engage. A neutral event inside the band does NOT: that is\n * how content collapsing under a still reader re-armed follow.\n * 4. Otherwise (downward/neutral, still away from the bottom) → keep the\n * previous state.\n *\n * `prevScrollTop < 0` means \"no prior observation this session\". Direction is\n * unknowable then, so the decision is position-only and CONSERVATIVE: follow\n * only within the re-engage band. Keeping a stale `stick` on an unattributable\n * away-from-bottom scroll is how a reader gets yanked.\n */\nexport function resolveUserScrollStick(args: {\n stick: boolean\n followOutput: boolean\n scrollTop: number\n prevScrollTop: number\n geom: ScrollGeom\n /** Change in the scroller's own height since the previous scroll event.\n *\n * Positive = the viewport GREW (the composer shrank under a deletion, the\n * keyboard closed). That growth lowers the maximum scrollTop, so the engine\n * clamps any reader parked closer to the bottom than the growth — with no\n * application write anywhere. The clamp then arrives here as an ordinary\n * scroll event sitting at distance ~0, which rule 1 below used to read as\n * \"the reader came back to the bottom\" and re-arm follow for someone who\n * never touched the scroller. The next turn to start then took them to the\n * end. Rule 1 exists to absorb a CONTENT-shrink clamp mid-stream, and content\n * shrink moves `scrollHeight`, not `clientHeight` — so the two are\n * distinguishable, and this is the delta that tells them apart. */\n viewportGrowth?: number\n}): boolean {\n const { stick, followOutput, scrollTop, prevScrollTop, geom } = args\n if (!followOutput) return false\n const dist = distanceFromBottom(geom)\n // A viewport growth large enough to explain the reader's arrival at the bottom\n // is the engine's clamp, not the reader. Leave `stick` exactly as it was.\n // A native clamp only ever LOWERS scrollTop, so a downward move concurrent with\n // the growth is the user's own and must still re-engage follow. Without the\n // direction term a reader who deliberately scrolls down while the keyboard\n // closes is refused their re-engagement.\n const clampedByViewport =\n (args.viewportGrowth ?? 0) > atBottomEpsilon() && scrollTop <= prevScrollTop + atBottomEpsilon()\n if (dist <= atBottomEpsilon()) return clampedByViewport ? stick : true\n if (prevScrollTop < 0) return dist <= FOLLOW_REENGAGE_PX\n if (scrollTop < prevScrollTop - 0.5) return false\n // Re-engagement requires a genuine DOWNWARD move, not merely a non-upward\n // event that finds the reader inside the band. A neutral event (identical\n // scrollTop -- the tail of an iOS momentum run, or any scroll fired while the\n // reader is at rest) used to satisfy this, so a reader sitting mid-transcript\n // could be re-armed by CONTENT rather than by their own hand: when rows\n // outside the window reprice smaller than their estimates, the remaining\n // content collapses under them and the bottom band arrives at the reader\n // instead of the reader arriving at it. Follow re-engaged, and the next pin\n // took them to the end -- reported as scrolling along and suddenly landing at\n // the bottom. Distance alone cannot tell those apart; the direction of the\n // reader's own move can.\n if (scrollTop > prevScrollTop + 0.5 && dist <= FOLLOW_REENGAGE_PX) return true\n return stick\n}\n\n/** What the reader did to the scroller, as far as telling a scroll-up from anything else. */\nexport type ReaderInput =\n | { kind: 'wheel'; deltaY: number }\n | { kind: 'key'; key: string; shiftKey: boolean }\n | { kind: 'touchmove' }\n | { kind: 'pointerdown'; onScroller: boolean }\n\nconst SCROLL_UP_KEYS = new Set(['ArrowUp', 'PageUp', 'Home'])\n\n/**\n * Is this the reader moving the view up, right now?\n *\n * A held position (see `createScrollFollow().hold`) is the caller's until the reader takes it,\n * and only an input that can scroll the view up takes it: a wheel notch up, an up key, a\n * touch drag, or a press on the scroller itself (its scrollbar or gutter). A click or a\n * selection inside the content, a letter, a wheel notch down or a down key do not move the\n * view away from the end, so they leave it where it is.\n */\nexport function isScrollUpIntent(input: ReaderInput): boolean {\n switch (input.kind) {\n case 'wheel':\n return input.deltaY < 0\n case 'key':\n return SCROLL_UP_KEYS.has(input.key) || (input.key === ' ' && input.shiftKey)\n case 'touchmove':\n return true\n case 'pointerdown':\n return input.onScroller\n }\n}\n\n/** Result of an automatic (RO / append) pin evaluation. */\nexport interface AutoPinResult {\n /** Whether to write `el.scrollTop = target` now. */\n pin: boolean\n /** Next value for `stick` (released to false if the user scrolled up). */\n stick: boolean\n /** The bottom scrollTop the caller should write when `pin` is true. */\n target: number\n}\n\n/**\n * Decide an automatic pin at the moment content changed (RO callback / append\n * layout effect / its follow-up rAF), reading LIVE geometry.\n *\n * - Not sticking → never pin.\n * - Sticking but the user has scrolled up since our last write\n * (`scrollTop < lastWriteTop - epsilon`) → release stick, don't pin.\n * This is the synchronous, race-proof guard.\n * - Otherwise → pin to the bottom (only actually move if not already there).\n *\n * `lastWriteTop < 0` disables the scroll-up guard (used right after a slot\n * switch, before we have written anything this session).\n *\n * `viewportShrink` (px, default 0) is how much the SCROLLER'S OWN BOX has\n * shrunk since that reference was recorded — chrome mounting below the\n * transcript (a queue band, an attachment strip, a tip card), often\n * spring-animated over several frames. Our own shrink inflates\n * `distanceFromBottom` with no user input, so without this allowance the\n * distance guard reads it as \"meaningfully away from the bottom\". Paired with\n * a content SHRINK in the same commit window — a tail-row remount clamping\n * scrollTop below `lastWriteTop` — that produced a full user-scroll-up\n * signature out of two of our own layout changes: follow released mid\n * animation and the content settled a card-height low. Judging the distance\n * against the box we were last a bottom FOR keeps the guard measuring the\n * user's move rather than our own. Only the shrink's own pixels are forgiven,\n * so a genuine drag inside the same tick still releases.\n */\nexport function evaluateAutoPin(args: {\n stick: boolean\n geom: ScrollGeom\n lastWriteTop: number\n epsilon?: number\n viewportShrink?: number\n /** Is a turn actually producing output right now?\n *\n * Follow means \"keep me at the end of a LIVE turn\". With nothing running there\n * is no output to follow, so a reader sitting above the bottom is not\n * following — and an automatic pin there is a yank with no cause, reported\n * from a phone as the transcript springing back after scrolling up about a\n * hundred pixels with nothing streaming.\n *\n * Defaults to `true` = assume a run is live, which keeps the behaviour of a\n * caller that has no run signal to give (the app-SDK chat surface). The chat\n * transcript passes the real thing. */\n runActive?: boolean\n /** Is an anchor restore currently OWNING the scroll position?\n *\n * A restore places the reader at an absolute offset and then re-lands it as\n * measurements arrive. An automatic pin during that window is a second owner\n * writing the same scroller, and the two fight: captured on a phone as\n * `WRITE autopin 3091->4245` answered by `WRITE settle 4245->3091`, twice in\n * 120ms, 1,154px each way. The settle won those rounds, but only because its\n * budget had not expired yet -- which is why the same switch sometimes landed\n * at the bottom and sometimes did not.\n *\n * Released rather than merely skipped, for the reason the idle branch below\n * gives: skipping leaves follow armed, so the next growth yanks the reader\n * from wherever the restore just put them. */\n restoreGate?: boolean\n /** Has hardware input -- wheel / touch / pointer / a scrolling key -- reached\n * the scroller since we last placed the reader at the bottom?\n *\n * False means the reader has done nothing, so a gap that opened while they\n * rest on our last write was opened by content -- a row settling from its\n * estimate, a code-block stand-in swapping for the highlighted block, the\n * top spacer repricing -- and is a gap WE owe them, not one they chose.\n *\n * The idle rule below cannot tell those apart from distance alone, and it\n * errs toward release, which was invisible wherever the browser's native\n * scroll anchoring quietly carried the reader through the growth. WebKit has\n * no scroll anchoring at all, so on an iPhone every entry into an idle\n * session paid the whole post-pin reprice as a displacement and then had\n * follow released on top of it: the transcript opened a viewport or more\n * above the end with nothing streaming to bring it back.\n *\n * Defaults to `true` = assume the reader may have moved, which is the\n * release-leaning legacy behaviour for a caller that has no input signal. */\n readerMovedSinceWrite?: boolean\n}): AutoPinResult {\n const { stick, geom, lastWriteTop } = args\n const epsilon = args.epsilon ?? SELF_SCROLL_EPSILON\n const viewportShrink = Math.max(0, args.viewportShrink ?? 0)\n const runActive = args.runActive ?? true\n const readerMovedSinceWrite = args.readerMovedSinceWrite ?? true\n const target = bottomTarget(geom)\n if (args.restoreGate) return { pin: false, stick: false, target }\n if (!stick) return { pin: false, stick: false, target }\n // The reader is resting exactly where we last put them and has given no input\n // since, so any gap is content settling under them -- carry them back, live\n // turn or not. Both conditions are load-bearing. Position alone would read our\n // own write as consent for a reader who wheeled up and happened to stop on it;\n // input alone would drag back a programmatic reveal -- a search hit, a pinned\n // prompt, find-in-page -- whose scroll event has not dispatched yet when a\n // height commit lands, since none of those touch the scroller's input\n // listeners. A reveal moves scrollTop off our write; a reprice does not.\n const restingOnOurWrite = lastWriteTop >= 0 && Math.abs(geom.scrollTop - lastWriteTop) <= epsilon\n if (!readerMovedSinceWrite && restingOnOurWrite) {\n return { pin: distanceFromBottom(geom) > atBottomEpsilon(), stick: true, target }\n }\n // Idle: release rather than merely skip the pin. Skipping would leave follow\n // armed, so the next turn to start would yank this reader to the bottom from\n // wherever they had settled — the same defect one event later.\n //\n // But distance alone cannot say WHO opened that gap, and the two causes want\n // opposite answers: a reader who scrolled up should be released, while a\n // reader the CONTENT moved away from should be carried back.\n if (!runActive && distanceFromBottom(geom) > atBottomEpsilon()) {\n // Released. The question this branch cannot answer from geometry -- did the\n // reader open this gap, or did the content -- is answered ABOVE by\n // `readerMovedSinceWrite`: reaching here means input or an unexplained\n // scroll has been seen since our last positioning, so a reader who is now\n // above the bottom while nothing runs is one who left it. Reading our own\n // last write as consent would be an automatic action authorizing itself;\n // the only evidence that the reader never moved is the absence of input,\n // and that is what the branch above requires.\n return { pin: false, stick: false, target }\n }\n // Release only on a genuine user scroll-UP: scrollTop dropped below our last\n // write AND we are now meaningfully away from the bottom. A pure content\n // SHRINK mid-stream (a partial markdown line re-parsing, a code fence opening\n // and reclassifying the block) clamps scrollTop below lastWriteTop too, but\n // leaves us still AT the new bottom (distance ~0). Without the distance guard\n // that shrink looked like a scroll-up and froze streaming follow — once\n // released, nothing re-armed stick for the rest of the response.\n if (\n lastWriteTop >= 0 &&\n geom.scrollTop < lastWriteTop - epsilon &&\n distanceFromBottom(geom) - viewportShrink > epsilon\n ) {\n return { pin: false, stick: false, target }\n }\n return { pin: Math.abs(geom.scrollTop - target) > atBottomEpsilon(), stick: true, target }\n}\n"],"mappings":";;;;;;;;;;;AA2CA,SAAgB,kBAA0B;CACxC,MAAM,MACJ,OAAO,WAAW,eAClB,OAAO,OAAO,qBAAqB,YACnC,OAAO,mBAAmB,IACtB,OAAO,mBACP;CACN,OAAO,KAAK,IAAI,GAAG,IAAI,MAAM,EAAG;AAClC;;AAUA,SAAgB,aAAa,MAA0B;CACrD,OAAO,KAAK,IAAI,GAAG,KAAK,eAAe,KAAK,YAAY;AAC1D;;AAGA,SAAgB,mBAAmB,MAA0B;CAC3D,OAAO,KAAK,eAAe,KAAK,YAAY,KAAK;AACnD;;AAGA,SAAgB,gBAAgB,MAAkB,WAA4B;CAC5E,OAAO,mBAAmB,IAAI,KAAK;AACrC;;;;;;AAOA,SAAgB,aACd,WACA,cACA,UAAA,GACS;CACT,OAAO,gBAAgB,KAAK,KAAK,IAAI,YAAY,YAAY,KAAK;AACpE;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,uBAAuB,MAmB3B;CACV,MAAM,EAAE,OAAO,cAAc,WAAW,eAAe,SAAS;CAChE,IAAI,CAAC,cAAc,OAAO;CAC1B,MAAM,OAAO,mBAAmB,IAAI;CAOpC,MAAM,qBACH,KAAK,kBAAkB,KAAK,gBAAgB,KAAK,aAAa,gBAAgB,gBAAgB;CACjG,IAAI,QAAQ,gBAAgB,GAAG,OAAO,oBAAoB,QAAQ;CAClE,IAAI,gBAAgB,GAAG,OAAO,QAAA;CAC9B,IAAI,YAAY,gBAAgB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E,KAAK,KAAK,IAAI,KAAK,YAAY,MAAM,IAAI,gBAAgB;EAAG,OAAO;EAAM;CAAO;AAC3F"}
|
|
1
|
+
{"version":3,"file":"scroll-follow-core.js","names":[],"sources":["../../../src/components/conversation/scroll-follow-core.ts"],"sourcesContent":["/*\n * Substantially translated from KiroCrew website/src/hooks/virtualizer/FollowController.ts\n * (plain-scroller decision units), pinned at\n * 283e136c0f902e965a535a7c9548c57c7504fed0.\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * This product includes software developed at Amazon.com, Inc.\n * (https://www.amazon.com/).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Pure plain-scroller decisions retained from FollowController; virtual row\n * measurement, persisted anchor resolution and restore settling are excluded.\n */\n/** Default distance (px) from the bottom within which `isAtBottom` is true. */\nexport const DEFAULT_BOTTOM_THRESHOLD = 100\n\n/**\n * Tolerance (px) for treating a scroll position as \"the same\" as a value we\n * wrote programmatically. Covers sub-pixel rounding and 1px momentum overshoot.\n * Must stay small so a deliberate user scroll of even a few px is still seen as\n * a user scroll.\n */\nexport const SELF_SCROLL_EPSILON = 2\n\n/**\n * \"At the bottom\" tolerance (px) for deciding whether an auto-pin still has\n * work to do. A flat 0.5 is UNDER one device pixel at fractional device-pixel\n * ratios (0.67 CSS px at 150% zoom, 0.8 at 125%): the scroller's resting\n * maximum scrollTop lands on a fractional value, so `|scrollTop - target|`\n * stays just above 0.5 even when the viewport is visually pinned to the\n * bottom — making the pin re-fire on every ResizeObserver tick. Scaling the\n * epsilon to the device pixel (never below 1 CSS px) absorbs that fractional\n * resting error. `devicePixelRatio` is read defensively so a jsdom / SSR\n * environment that leaves it undefined falls back to 1 (→ 1.5px).\n */\nexport function atBottomEpsilon(): number {\n const dpr =\n typeof window !== 'undefined' &&\n typeof window.devicePixelRatio === 'number' &&\n window.devicePixelRatio > 0\n ? window.devicePixelRatio\n : 1\n return Math.max(1, 1 / dpr + 0.5)\n}\n\n/** Live scroll geometry snapshot read from the scroller element. */\nexport interface ScrollGeom {\n scrollTop: number\n scrollHeight: number\n clientHeight: number\n}\n\n/** scrollTop that places the viewport exactly at the bottom (never negative). */\nexport function bottomTarget(geom: ScrollGeom): number {\n return Math.max(0, geom.scrollHeight - geom.clientHeight)\n}\n\n/** Pixels between the current scroll position and the bottom. */\nexport function distanceFromBottom(geom: ScrollGeom): number {\n return geom.scrollHeight - geom.scrollTop - geom.clientHeight\n}\n\n/** Whether the scroller is within `threshold` px of the bottom. */\nexport function computeAtBottom(geom: ScrollGeom, threshold: number): boolean {\n return distanceFromBottom(geom) <= threshold\n}\n\n/**\n * Recognise a `scroll` event caused by our own programmatic write rather than\n * by the user. `lastWriteTop < 0` means \"we have not written this session\", so\n * any scroll is treated as the user's.\n */\nexport function isSelfScroll(\n scrollTop: number,\n lastWriteTop: number,\n epsilon: number = SELF_SCROLL_EPSILON\n): boolean {\n return lastWriteTop >= 0 && Math.abs(scrollTop - lastWriteTop) <= epsilon\n}\n\n/**\n * A viewport can clamp our bottom write before its scroll/resize notification,\n * then streamed content can reopen the gap before either callback runs. Accept\n * only the exact offset explained by that growth, with no reader input. Other\n * offsets still belong to the reader. A programmatic reveal landing at this\n * same offset cannot be distinguished from native clamping by geometry alone.\n */\nexport function isViewportGrowthClamp(args: {\n geom: ScrollGeom\n lastWriteTop: number\n lastWriteClientHeight: number\n readerMovedSinceWrite: boolean\n}): boolean {\n const growth = args.geom.clientHeight - args.lastWriteClientHeight\n return (\n !args.readerMovedSinceWrite &&\n args.lastWriteTop >= 0 &&\n args.lastWriteClientHeight >= 0 &&\n growth > SELF_SCROLL_EPSILON &&\n Math.abs(args.geom.scrollTop - Math.max(0, args.lastWriteTop - growth)) <= SELF_SCROLL_EPSILON\n )\n}\n\n/**\n * Distance (px) from the true bottom within which a user scroll RE-ENGAGES\n * follow. Deliberately much tighter than DEFAULT_BOTTOM_THRESHOLD: that 100px\n * band drives the jump-to-bottom pill's visibility, and reusing it for follow\n * meant a deliberate 3-99px scroll-up kept `stick` armed — the next content\n * change then yanked the reader back to the bottom. Re-engaging only when the\n * user has returned essentially to the bottom keeps \"scrolled up to read\"\n * positions belonging to the user.\n */\nexport const FOLLOW_REENGAGE_PX = 16\n\n/**\n * Direction-aware `stick` decision for a *user-initiated* scroll (self-scrolls\n * filtered out by the caller via `isSelfScroll`):\n *\n * 1. At the true bottom (within the DPR-aware epsilon) → follow. This also\n * absorbs the layout engine's clamp: a mid-stream content SHRINK drops\n * scrollTop (which reads as an upward move) but lands exactly at the new\n * bottom — releasing there froze streaming follow for the rest of the\n * turn.\n * 2. Any other upward move → release, regardless of distance from the\n * bottom. The scroll position now belongs to the user; only returning to\n * the bottom (3) re-engages.\n * 3. A genuine DOWNWARD move that arrives within FOLLOW_REENGAGE_PX of the\n * bottom → re-engage. A neutral event inside the band does NOT: that is\n * how content collapsing under a still reader re-armed follow.\n * 4. Otherwise (downward/neutral, still away from the bottom) → keep the\n * previous state.\n *\n * `prevScrollTop < 0` means \"no prior observation this session\". Direction is\n * unknowable then, so the decision is position-only and CONSERVATIVE: follow\n * only within the re-engage band. Keeping a stale `stick` on an unattributable\n * away-from-bottom scroll is how a reader gets yanked.\n */\nexport function resolveUserScrollStick(args: {\n stick: boolean\n followOutput: boolean\n scrollTop: number\n prevScrollTop: number\n geom: ScrollGeom\n /** Change in the scroller's own height since the previous scroll event.\n *\n * Positive = the viewport GREW (the composer shrank under a deletion, the\n * keyboard closed). That growth lowers the maximum scrollTop, so the engine\n * clamps any reader parked closer to the bottom than the growth — with no\n * application write anywhere. The clamp then arrives here as an ordinary\n * scroll event sitting at distance ~0, which rule 1 below used to read as\n * \"the reader came back to the bottom\" and re-arm follow for someone who\n * never touched the scroller. The next turn to start then took them to the\n * end. Rule 1 exists to absorb a CONTENT-shrink clamp mid-stream, and content\n * shrink moves `scrollHeight`, not `clientHeight` — so the two are\n * distinguishable, and this is the delta that tells them apart. */\n viewportGrowth?: number\n}): boolean {\n const { stick, followOutput, scrollTop, prevScrollTop, geom } = args\n if (!followOutput) return false\n const dist = distanceFromBottom(geom)\n // A viewport growth large enough to explain the reader's arrival at the bottom\n // is the engine's clamp, not the reader. Leave `stick` exactly as it was.\n // A native clamp only ever LOWERS scrollTop, so a downward move concurrent with\n // the growth is the user's own and must still re-engage follow. Without the\n // direction term a reader who deliberately scrolls down while the keyboard\n // closes is refused their re-engagement.\n const clampedByViewport =\n (args.viewportGrowth ?? 0) > atBottomEpsilon() && scrollTop <= prevScrollTop + atBottomEpsilon()\n if (dist <= atBottomEpsilon()) return clampedByViewport ? stick : true\n if (prevScrollTop < 0) return dist <= FOLLOW_REENGAGE_PX\n if (scrollTop < prevScrollTop - 0.5) return false\n // Re-engagement requires a genuine DOWNWARD move, not merely a non-upward\n // event that finds the reader inside the band. A neutral event (identical\n // scrollTop -- the tail of an iOS momentum run, or any scroll fired while the\n // reader is at rest) used to satisfy this, so a reader sitting mid-transcript\n // could be re-armed by CONTENT rather than by their own hand: when rows\n // outside the window reprice smaller than their estimates, the remaining\n // content collapses under them and the bottom band arrives at the reader\n // instead of the reader arriving at it. Follow re-engaged, and the next pin\n // took them to the end -- reported as scrolling along and suddenly landing at\n // the bottom. Distance alone cannot tell those apart; the direction of the\n // reader's own move can.\n if (scrollTop > prevScrollTop + 0.5 && dist <= FOLLOW_REENGAGE_PX) return true\n return stick\n}\n\n/** What the reader did to the scroller, as far as telling a scroll-up from anything else. */\nexport type ReaderInput =\n | { kind: 'wheel'; deltaY: number }\n | { kind: 'key'; key: string; shiftKey: boolean }\n | { kind: 'touchmove' }\n | { kind: 'pointerdown'; onScroller: boolean }\n\nconst SCROLL_UP_KEYS = new Set(['ArrowUp', 'PageUp', 'Home'])\n\n/**\n * Is this the reader moving the view up, right now?\n *\n * A held position (see `createScrollFollow().hold`) is the caller's until the reader takes it,\n * and only an input that can scroll the view up takes it: a wheel notch up, an up key, a\n * touch drag, or a press on the scroller itself (its scrollbar or gutter). A click or a\n * selection inside the content, a letter, a wheel notch down or a down key do not move the\n * view away from the end, so they leave it where it is.\n */\nexport function isScrollUpIntent(input: ReaderInput): boolean {\n switch (input.kind) {\n case 'wheel':\n return input.deltaY < 0\n case 'key':\n return SCROLL_UP_KEYS.has(input.key) || (input.key === ' ' && input.shiftKey)\n case 'touchmove':\n return true\n case 'pointerdown':\n return input.onScroller\n }\n}\n\n/** Result of an automatic (RO / append) pin evaluation. */\nexport interface AutoPinResult {\n /** Whether to write `el.scrollTop = target` now. */\n pin: boolean\n /** Next value for `stick` (released to false if the user scrolled up). */\n stick: boolean\n /** The bottom scrollTop the caller should write when `pin` is true. */\n target: number\n}\n\n/**\n * Decide an automatic pin at the moment content changed (RO callback / append\n * layout effect / its follow-up rAF), reading LIVE geometry.\n *\n * - Not sticking → never pin.\n * - Sticking but the user has scrolled up since our last write\n * (`scrollTop < lastWriteTop - epsilon`) → release stick, don't pin.\n * This is the synchronous, race-proof guard.\n * - Otherwise → pin to the bottom (only actually move if not already there).\n *\n * `lastWriteTop < 0` disables the scroll-up guard (used right after a slot\n * switch, before we have written anything this session).\n *\n * `viewportShrink` (px, default 0) is how much the SCROLLER'S OWN BOX has\n * shrunk since that reference was recorded — chrome mounting below the\n * transcript (a queue band, an attachment strip, a tip card), often\n * spring-animated over several frames. Our own shrink inflates\n * `distanceFromBottom` with no user input, so without this allowance the\n * distance guard reads it as \"meaningfully away from the bottom\". Paired with\n * a content SHRINK in the same commit window — a tail-row remount clamping\n * scrollTop below `lastWriteTop` — that produced a full user-scroll-up\n * signature out of two of our own layout changes: follow released mid\n * animation and the content settled a card-height low. Judging the distance\n * against the box we were last a bottom FOR keeps the guard measuring the\n * user's move rather than our own. Only the shrink's own pixels are forgiven,\n * so a genuine drag inside the same tick still releases.\n */\nexport function evaluateAutoPin(args: {\n stick: boolean\n geom: ScrollGeom\n lastWriteTop: number\n epsilon?: number\n viewportShrink?: number\n /** Is a turn actually producing output right now?\n *\n * Follow means \"keep me at the end of a LIVE turn\". With nothing running there\n * is no output to follow, so a reader sitting above the bottom is not\n * following — and an automatic pin there is a yank with no cause, reported\n * from a phone as the transcript springing back after scrolling up about a\n * hundred pixels with nothing streaming.\n *\n * Defaults to `true` = assume a run is live, which keeps the behaviour of a\n * caller that has no run signal to give (the app-SDK chat surface). The chat\n * transcript passes the real thing. */\n runActive?: boolean\n /** Is an anchor restore currently OWNING the scroll position?\n *\n * A restore places the reader at an absolute offset and then re-lands it as\n * measurements arrive. An automatic pin during that window is a second owner\n * writing the same scroller, and the two fight: captured on a phone as\n * `WRITE autopin 3091->4245` answered by `WRITE settle 4245->3091`, twice in\n * 120ms, 1,154px each way. The settle won those rounds, but only because its\n * budget had not expired yet -- which is why the same switch sometimes landed\n * at the bottom and sometimes did not.\n *\n * Released rather than merely skipped, for the reason the idle branch below\n * gives: skipping leaves follow armed, so the next growth yanks the reader\n * from wherever the restore just put them. */\n restoreGate?: boolean\n /** Has hardware input -- wheel / touch / pointer / a scrolling key -- reached\n * the scroller since we last placed the reader at the bottom?\n *\n * False means the reader has done nothing, so a gap that opened while they\n * rest on our last write was opened by content -- a row settling from its\n * estimate, a code-block stand-in swapping for the highlighted block, the\n * top spacer repricing -- and is a gap WE owe them, not one they chose.\n *\n * The idle rule below cannot tell those apart from distance alone, and it\n * errs toward release, which was invisible wherever the browser's native\n * scroll anchoring quietly carried the reader through the growth. WebKit has\n * no scroll anchoring at all, so on an iPhone every entry into an idle\n * session paid the whole post-pin reprice as a displacement and then had\n * follow released on top of it: the transcript opened a viewport or more\n * above the end with nothing streaming to bring it back.\n *\n * Defaults to `true` = assume the reader may have moved, which is the\n * release-leaning legacy behaviour for a caller that has no input signal. */\n readerMovedSinceWrite?: boolean\n}): AutoPinResult {\n const { stick, geom, lastWriteTop } = args\n const epsilon = args.epsilon ?? SELF_SCROLL_EPSILON\n const viewportShrink = Math.max(0, args.viewportShrink ?? 0)\n const runActive = args.runActive ?? true\n const readerMovedSinceWrite = args.readerMovedSinceWrite ?? true\n const target = bottomTarget(geom)\n if (args.restoreGate) return { pin: false, stick: false, target }\n if (!stick) return { pin: false, stick: false, target }\n // The reader is resting exactly where we last put them and has given no input\n // since, so any gap is content settling under them -- carry them back, live\n // turn or not. Both conditions are load-bearing. Position alone would read our\n // own write as consent for a reader who wheeled up and happened to stop on it;\n // input alone would drag back a programmatic reveal -- a search hit, a pinned\n // prompt, find-in-page -- whose scroll event has not dispatched yet when a\n // height commit lands, since none of those touch the scroller's input\n // listeners. A reveal moves scrollTop off our write; a reprice does not.\n const restingOnOurWrite = lastWriteTop >= 0 && Math.abs(geom.scrollTop - lastWriteTop) <= epsilon\n if (!readerMovedSinceWrite && restingOnOurWrite) {\n return { pin: distanceFromBottom(geom) > atBottomEpsilon(), stick: true, target }\n }\n // Idle: release rather than merely skip the pin. Skipping would leave follow\n // armed, so the next turn to start would yank this reader to the bottom from\n // wherever they had settled — the same defect one event later.\n //\n // But distance alone cannot say WHO opened that gap, and the two causes want\n // opposite answers: a reader who scrolled up should be released, while a\n // reader the CONTENT moved away from should be carried back.\n if (!runActive && distanceFromBottom(geom) > atBottomEpsilon()) {\n // Released. The question this branch cannot answer from geometry -- did the\n // reader open this gap, or did the content -- is answered ABOVE by\n // `readerMovedSinceWrite`: reaching here means input or an unexplained\n // scroll has been seen since our last positioning, so a reader who is now\n // above the bottom while nothing runs is one who left it. Reading our own\n // last write as consent would be an automatic action authorizing itself;\n // the only evidence that the reader never moved is the absence of input,\n // and that is what the branch above requires.\n return { pin: false, stick: false, target }\n }\n // Release only on a genuine user scroll-UP: scrollTop dropped below our last\n // write AND we are now meaningfully away from the bottom. A pure content\n // SHRINK mid-stream (a partial markdown line re-parsing, a code fence opening\n // and reclassifying the block) clamps scrollTop below lastWriteTop too, but\n // leaves us still AT the new bottom (distance ~0). Without the distance guard\n // that shrink looked like a scroll-up and froze streaming follow — once\n // released, nothing re-armed stick for the rest of the response.\n if (\n lastWriteTop >= 0 &&\n geom.scrollTop < lastWriteTop - epsilon &&\n distanceFromBottom(geom) - viewportShrink > epsilon\n ) {\n return { pin: false, stick: false, target }\n }\n return { pin: Math.abs(geom.scrollTop - target) > atBottomEpsilon(), stick: true, target }\n}\n"],"mappings":";;;;;;;;;;;AA2CA,SAAgB,kBAA0B;CACxC,MAAM,MACJ,OAAO,WAAW,eAClB,OAAO,OAAO,qBAAqB,YACnC,OAAO,mBAAmB,IACtB,OAAO,mBACP;CACN,OAAO,KAAK,IAAI,GAAG,IAAI,MAAM,EAAG;AAClC;;AAUA,SAAgB,aAAa,MAA0B;CACrD,OAAO,KAAK,IAAI,GAAG,KAAK,eAAe,KAAK,YAAY;AAC1D;;AAGA,SAAgB,mBAAmB,MAA0B;CAC3D,OAAO,KAAK,eAAe,KAAK,YAAY,KAAK;AACnD;;AAGA,SAAgB,gBAAgB,MAAkB,WAA4B;CAC5E,OAAO,mBAAmB,IAAI,KAAK;AACrC;;;;;;AAOA,SAAgB,aACd,WACA,cACA,UAAA,GACS;CACT,OAAO,gBAAgB,KAAK,KAAK,IAAI,YAAY,YAAY,KAAK;AACpE;;;;;;;;AASA,SAAgB,sBAAsB,MAK1B;CACV,MAAM,SAAS,KAAK,KAAK,eAAe,KAAK;CAC7C,OACE,CAAC,KAAK,yBACN,KAAK,gBAAgB,KACrB,KAAK,yBAAyB,KAC9B,SAAA,KACA,KAAK,IAAI,KAAK,KAAK,YAAY,KAAK,IAAI,GAAG,KAAK,eAAe,MAAM,CAAC,KAAA;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,uBAAuB,MAmB3B;CACV,MAAM,EAAE,OAAO,cAAc,WAAW,eAAe,SAAS;CAChE,IAAI,CAAC,cAAc,OAAO;CAC1B,MAAM,OAAO,mBAAmB,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gBAAgB,GAS3D,OAAO;EAAE,KAAK;EAAO,OAAO;EAAO;CAAO;CAS5C,IACE,gBAAgB,KAChB,KAAK,YAAY,eAAe,WAChC,mBAAmB,IAAI,IAAI,iBAAiB,SAE5C,OAAO;EAAE,KAAK;EAAO,OAAO;EAAO;CAAO;CAE5C,OAAO;EAAE,KAAK,KAAK,IAAI,KAAK,YAAY,MAAM,IAAI,gBAAgB;EAAG,OAAO;EAAM;CAAO;AAC3F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-follow.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/scroll-follow.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"scroll-follow.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/scroll-follow.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AAsBzE,yGAAyG;AACzG,MAAM,MAAM,gBAAgB,GAAG,MAAM,MAAM,IAAI,CAAA;AAE/C,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,OAAO,EAAE,MAAM,OAAO,CAAA;IACtB,QAAQ,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IAClC,SAAS,EAAE,MAAM,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,2BAA2B,GAAG,SAAS,CAAA;IAC/D,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,2BAA2B,KAAK,IAAI,CAAA;CACnE;;;;;4BAwV2B,cAAc;2BAKf,cAAc;EAIxC"}
|