@adea-ai/ui 0.151.0 → 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/internal/chat-composer-shell.d.ts.map +1 -1
- package/dist/components/conversation/internal/chat-composer-shell.js +28 -4
- package/dist/components/conversation/internal/chat-composer-shell.js.map +1 -1
- package/dist/components/conversation/paste-token-editor.d.ts.map +1 -1
- package/dist/components/conversation/paste-token-editor.js +127 -37
- package/dist/components/conversation/paste-token-editor.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/appearance-editor.json +1 -1
- package/dist/r/lib.json +1 -1
- package/dist/r/registry.json +3 -3
- 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/internal/chat-composer-shell.tsx +36 -2
- package/dist/r/src/components/conversation/paste-token-editor.tsx +191 -49
- 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/dist/r/theming.json +1 -1
- package/package.json +9 -3
- package/registry.json +3 -3
- 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/internal/chat-composer-shell.tsx +36 -2
- package/src/components/conversation/paste-token-editor.tsx +191 -49
- 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;E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AAM;GAAc,EAAA,SAC1BQ,YAAY,GAA8B,EAAA,IAAAoB,WAAA;IAAA,OAE9CF,SAAS;GAAC,EAAA,CAAA,CAAA;EAAA;EAAA,IAAAE,WAAA;GAAA,OAAA9B,gBAIdpC,SAAO;IAAA,IACNsE,YAAS;KAAA,OAAEtC,MAAM1B,eAAe;IAAQ;IAAA,IACxCiE,OAAI;KAAA,OAAE9B,YAAY;IAAC;IACnB+B,eAAeD,SAAS;KACtB,IAAIA,QAAQ5B,mBAAmB,GAAG;KAClCD,eAAe6B,IAAI;IACrB;IAAC,IAAAL,WAAA;KAAA,OAAA,CAAA9B,gBAEAlC,gBAAcmC,WAAA,EACbC,IAAIS,wBAAuB,SACtBD,YAAY,GAA8D;MAAA,IAC/EjB,WAAQ;OAAA,OAAGG,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,cAA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A;EAAA,IAAAE,WAAA;GAAA,OAAA9B,gBAIdtC,SAAO;IAAA,IACNwE,YAAS;KAAA,OAAEtC,MAAM5B,eAAe;IAAQ;IAAA,IACxCmE,OAAI;KAAA,OAAE9B,YAAY;IAAC;IACnB+B,eAAeD,SAAS;KACtB,IAAIA,QAAQ5B,mBAAmB,GAAG;KAClCD,eAAe6B,IAAI;IACrB;IAAC,IAAAL,WAAA;KAAA,OAAA,CAAA9B,gBAEApC,gBAAcqC,WAAA,EACbC,IAAIS,wBAAuB,SACtBD,YAAY,GAA8D;MAAA,IAC/EjB,WAAQ;OAAA,OAAGG,MAAMM,MAAM;MAAc;MAAA,IAAA4B,WAAA;OAAA,OAEpCF,SAAS;MAAC;KAAA,CAAA,CAAA,GAAA5B,gBAEZrC,gBAAc;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,WAAWnC,aAA2B,QAAQ;CAC3D,MAAM,CAACoC,UAAUC,eAAerC,aAAa,CAAC;CAC9C,IAAIsC;CACJ,IAAIG;CACJ,IAAIE,WAAW;CAGf,IAAIC,iBAAiB;CAOrB,MAAM,CAACC,cAAcC,mBAAmB9C,aAAa,KAAK;CAI1D,IAAI+C,cAAc;CAOlB,IAAIC,sBAAsB;CAC1B,MAAMC,mBAAmBC,UAAyB;EAChD,IAAIA,MAAME,QAAQ,UAAU;EAC5BJ,sBACEP,SAASY,cAAcC,cAAc,gDAA8C,KAAK;CAC5F;CACAvD,mBAAmB;EACjB,IAAImC,KAAK,MAAM,YAAY,OAAOqB,WAAW,aAAa;EAC1DA,OAAOC,iBAAiB,WAAWP,iBAAiB,IAAI;EACxDhD,gBAAgBsD,OAAOE,oBAAoB,WAAWR,iBAAiB,IAAI,CAAC;CAC9E,CAAC;CAED,MAAMS,cAAczB,MAAMP,QAAQiC;CAClC,MAAMC,eAAe3B,MAAMP,QAAQJ,UAAUc,SAAS,GAAGsB,MAAM,CAAC;CAChE,MAAMG,cAAc;EAClB,IAAIvB,UAAUwB,KAAAA,GAAWC,aAAazB,KAAK;EAC3CA,QAAQwB,KAAAA;CACV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D,gBACFjE,UAAQ;IAAA,IACPsH,OAAI;KAAA,OAAEC,IAAI;IAAC;IACXM,QAAM;IACNC,KAAG;IAAA,SAAA;IAAA,IAAA3D,WAAA;KAAA,OAAA,CAAA4D,WAGF7H,UAAUqH,IAAI,GAAG,EAAE,CAAC,GAAAS,QAAA,CAAA;IAAA;GAAA,CAAA;EAGxB,CAAA;EAAA/D,gBAEF3E,MAAI;GAAA,IAAC4E,OAAI;IAAA,OAAEwD,SAAS;GAAC;GAAA,IAAAvD,WAAA;IAAA,OAAA8D,QAAA;GAAA;EAAA,CAAA;EAAAhE,gBAGrB3E,MAAI;GAAA,IAAC4E,OAAI;IAAA,OAAEuD,QAAQ;GAAC;GAAA,IAAAtD,WAAA;IAAA,IAAA+D,SAAAC,QAAA;IAAA/C,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,SAAgBC,eAAeC,OAA4B;CACzD,MAAM,CAACC,SAAS9B,WAAW6B,OAAO;EAAC;EAAW;EAAS;EAAc;CAAO,CAAC;CAC7E,MAAM,CAACE,MAAMC,WAAWnC,aAA2B,QAAQ;CAC3D,MAAM,CAACoC,UAAUC,eAAerC,aAAa,CAAC;CAC9C,IAAIsC;CACJ,IAAIG;CACJ,IAAIE,WAAW;CAGf,IAAIC,iBAAiB;CAOrB,MAAM,CAACC,cAAcC,mBAAmB9C,aAAa,KAAK;CAI1D,IAAI+C,cAAc;CAOlB,IAAIC,sBAAsB;CAC1B,MAAMC,mBAAmBC,UAAyB;EAChD,IAAIA,MAAME,QAAQ,UAAU;EAC5BJ,sBACEP,SAASY,cAAcC,cAAc,gDAA8C,KAAK;CAC5F;CACAvD,mBAAmB;EACjB,IAAImC,KAAK,MAAM,YAAY,OAAOqB,WAAW,aAAa;EAC1DA,OAAOC,iBAAiB,WAAWP,iBAAiB,IAAI;EACxDhD,gBAAgBsD,OAAOE,oBAAoB,WAAWR,iBAAiB,IAAI,CAAC;CAC9E,CAAC;CAED,MAAMS,cAAczB,MAAMP,QAAQiC;CAClC,MAAMC,eAAe3B,MAAMP,QAAQJ,UAAU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AA,IAAA0D,SAAAC,QAAA;IAAAxD,OAAAuD,QACuDH,IAAI;IAAA,OAAAG;GAAA;EAAA,CAAA;EAAA5D,gBAE5E3E,MAAI;GAAA,IAAC4E,OAAI;IAAA,OAAEsD,KAAK;GAAC;GAAArD,WACdsD,QAAGxD,gBACFjE,UAAQ;IAAA,IACPwH,OAAI;KAAA,OAAEC,IAAI;IAAC;IACXM,QAAM;IACNC,KAAG;IAAA,SAAA;IAAA,IAAA7D,WAAA;KAAA,OAAA,CAAA8D,WAGF/H,UAAUuH,IAAI,GAAG,EAAE,CAAC,GAAAS,QAAA,CAAA;IAAA;GAAA,CAAA;EAGxB,CAAA;EAAAjE,gBAEF3E,MAAI;GAAA,IAAC4E,OAAI;IAAA,OAAE0D,SAAS;GAAC;GAAA,IAAAzD,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-composer-shell.d.ts","sourceRoot":"","sources":["../../../../src/components/conversation/internal/chat-composer-shell.tsx"],"names":[],"mappings":"AAOA,OAAO,EAOL,KAAK,QAAQ,EACb,KAAK,GAAG,EACT,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAEV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,kBAAkB,CAAA;AAYzB,6EAA6E;AAC7E,KAAK,4BAA4B,GAAG;IAClC,GAAG,EAAE,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,KAAK,IAAI,CAAA;IACvD,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvB,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC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|
import { BusySendButton } from "../busy-send-button.js";
|
|
5
5
|
import { createComposerImeGuard } from "../ime-guard.js";
|
|
6
|
-
import { createComponent, insert, memo, mergeProps, template } from "solid-js/web";
|
|
6
|
+
import { createComponent, insert, memo, mergeProps, template, use } from "solid-js/web";
|
|
7
7
|
import { ArrowUp, ChevronsDownUp, ChevronsUpDown, MoreHorizontal } from "lucide-solid";
|
|
8
8
|
import { Show, createEffect, createSignal, on, onCleanup, onMount } from "solid-js";
|
|
9
9
|
// src/components/conversation/internal/chat-composer-shell.tsx
|
|
@@ -39,6 +39,7 @@ function ChatComposerShell(props) {
|
|
|
39
39
|
const [error, setError] = createSignal(null);
|
|
40
40
|
let field;
|
|
41
41
|
let restoreBar;
|
|
42
|
+
let root;
|
|
42
43
|
let focusFrame;
|
|
43
44
|
let focusTarget;
|
|
44
45
|
let selection;
|
|
@@ -54,9 +55,16 @@ function ChatComposerShell(props) {
|
|
|
54
55
|
const requestFocus = (target) => {
|
|
55
56
|
cancelFocus();
|
|
56
57
|
focusTarget = target;
|
|
58
|
+
const requester = document.activeElement;
|
|
57
59
|
focusFrame = requestAnimationFrame(() => {
|
|
58
60
|
focusFrame = void 0;
|
|
59
61
|
if (!active || props.approvalFocus) return;
|
|
62
|
+
const current = document.activeElement;
|
|
63
|
+
if (current && current !== document.body && current !== requester && !root?.contains(current)) {
|
|
64
|
+
focusTarget = void 0;
|
|
65
|
+
if (target === "input") selection = void 0;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
60
68
|
if (target === "bar" && collapsed()) restoreBar?.focus();
|
|
61
69
|
if (target === "input" && !collapsed() && !props.disabled && field) {
|
|
62
70
|
field.focus();
|
|
@@ -65,6 +73,16 @@ function ChatComposerShell(props) {
|
|
|
65
73
|
focusTarget = void 0;
|
|
66
74
|
});
|
|
67
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* A press or key in the input before the deferred expand restore runs is a
|
|
78
|
+
* newer selection owner: the restore must not move its caret back.
|
|
79
|
+
*/
|
|
80
|
+
const yieldInputRestore = () => {
|
|
81
|
+
if (focusTarget !== "input") return;
|
|
82
|
+
cancelFocus();
|
|
83
|
+
focusTarget = void 0;
|
|
84
|
+
selection = void 0;
|
|
85
|
+
};
|
|
68
86
|
const changeCollapsed = (value) => {
|
|
69
87
|
if (!props.collapse || props.approvalFocus) return;
|
|
70
88
|
if (value && field) selection = {
|
|
@@ -133,6 +151,7 @@ function ChatComposerShell(props) {
|
|
|
133
151
|
return first.length > 120 ? `${first.slice(0, 120)}…` : first;
|
|
134
152
|
};
|
|
135
153
|
const handleInputKeyDown = (event) => {
|
|
154
|
+
yieldInputRestore();
|
|
136
155
|
if (event.key === "Escape" && error()) {
|
|
137
156
|
setError(null);
|
|
138
157
|
return;
|
|
@@ -157,6 +176,7 @@ function ChatComposerShell(props) {
|
|
|
157
176
|
};
|
|
158
177
|
return (() => {
|
|
159
178
|
var _el$ = _tmpl$1(), _el$5 = _el$.firstChild;
|
|
179
|
+
use((element) => root = element, _el$);
|
|
160
180
|
insert(_el$, createComponent(Show, {
|
|
161
181
|
get when() {
|
|
162
182
|
return !props.approvalFocus;
|
|
@@ -298,9 +318,13 @@ function ChatComposerShell(props) {
|
|
|
298
318
|
insert(_el$9, () => props.renderInput({
|
|
299
319
|
ref: (element) => {
|
|
300
320
|
field = element;
|
|
301
|
-
if (element)
|
|
302
|
-
|
|
303
|
-
|
|
321
|
+
if (element) {
|
|
322
|
+
element.addEventListener("pointerdown", yieldInputRestore);
|
|
323
|
+
onCleanup(() => {
|
|
324
|
+
element.removeEventListener("pointerdown", yieldInputRestore);
|
|
325
|
+
if (field === element) field = void 0;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
304
328
|
},
|
|
305
329
|
value: () => props.value,
|
|
306
330
|
resetKey: () => props.resetKey,
|