@particle-academy/react-fancy 5.65.0 → 5.67.0

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/{PastePills.types-CDyotkUb.d.cts → PastePills.types-CpXzsuwJ.d.cts} +2 -0
  3. package/dist/{PastePills.types-CDyotkUb.d.ts → PastePills.types-CpXzsuwJ.d.ts} +2 -0
  4. package/dist/{PastedFilesInput-CrgNoEBd.d.ts → PastedFilesInput-Bt3KSTVN.d.ts} +1 -1
  5. package/dist/{PastedFilesInput-DQ1eZaHk.d.cts → PastedFilesInput-CUQeOeOA.d.cts} +1 -1
  6. package/dist/button.cjs +3 -4
  7. package/dist/button.js +1 -2
  8. package/dist/{chunk-COXHFZR6.js → chunk-23AVEYUP.js} +14 -8
  9. package/dist/chunk-23AVEYUP.js.map +1 -0
  10. package/dist/{chunk-C5YX5XVL.cjs → chunk-3U7PUZLI.cjs} +214 -4
  11. package/dist/chunk-3U7PUZLI.cjs.map +1 -0
  12. package/dist/{chunk-ATIDUWY6.cjs → chunk-4S5DFN5N.cjs} +12 -12
  13. package/dist/{chunk-ATIDUWY6.cjs.map → chunk-4S5DFN5N.cjs.map} +1 -1
  14. package/dist/{chunk-CMC2TOEQ.cjs → chunk-6CAXLP7D.cjs} +6 -6
  15. package/dist/{chunk-CMC2TOEQ.cjs.map → chunk-6CAXLP7D.cjs.map} +1 -1
  16. package/dist/{chunk-TQGRXJ74.cjs → chunk-7FYRFNPX.cjs} +9 -9
  17. package/dist/{chunk-TQGRXJ74.cjs.map → chunk-7FYRFNPX.cjs.map} +1 -1
  18. package/dist/{chunk-MVVHUTXA.js → chunk-B4LVQ4QI.js} +3 -3
  19. package/dist/{chunk-MVVHUTXA.js.map → chunk-B4LVQ4QI.js.map} +1 -1
  20. package/dist/{chunk-QP35Z2WB.js → chunk-BL5IKSB3.js} +3 -3
  21. package/dist/{chunk-QP35Z2WB.js.map → chunk-BL5IKSB3.js.map} +1 -1
  22. package/dist/{chunk-SZH7TFME.js → chunk-DCAD2JPP.js} +4 -4
  23. package/dist/{chunk-SZH7TFME.js.map → chunk-DCAD2JPP.js.map} +1 -1
  24. package/dist/{chunk-MCQJFMDP.cjs → chunk-E5UU666U.cjs} +478 -36
  25. package/dist/chunk-E5UU666U.cjs.map +1 -0
  26. package/dist/{chunk-L24LUSEE.js → chunk-FXOT4P4P.js} +478 -36
  27. package/dist/chunk-FXOT4P4P.js.map +1 -0
  28. package/dist/{chunk-CAUEKGMR.js → chunk-HEY4SMS2.js} +4 -4
  29. package/dist/{chunk-CAUEKGMR.js.map → chunk-HEY4SMS2.js.map} +1 -1
  30. package/dist/{chunk-QNQNGARW.cjs → chunk-HFK5SBNM.cjs} +27 -9
  31. package/dist/chunk-HFK5SBNM.cjs.map +1 -0
  32. package/dist/{chunk-TLRRMYNV.js → chunk-OXERDFFF.js} +212 -4
  33. package/dist/chunk-OXERDFFF.js.map +1 -0
  34. package/dist/{chunk-ELFTEJBT.js → chunk-QSGAFKK2.js} +3 -3
  35. package/dist/{chunk-ELFTEJBT.js.map → chunk-QSGAFKK2.js.map} +1 -1
  36. package/dist/{chunk-SYEHWUM5.cjs → chunk-RALJMI7C.cjs} +4 -4
  37. package/dist/{chunk-SYEHWUM5.cjs.map → chunk-RALJMI7C.cjs.map} +1 -1
  38. package/dist/{chunk-UM4JXBRZ.cjs → chunk-S3NB6LDV.cjs} +4 -4
  39. package/dist/{chunk-UM4JXBRZ.cjs.map → chunk-S3NB6LDV.cjs.map} +1 -1
  40. package/dist/{chunk-C463C4MM.cjs → chunk-SAG6DHQK.cjs} +22 -16
  41. package/dist/chunk-SAG6DHQK.cjs.map +1 -0
  42. package/dist/{chunk-4XHG6Q42.cjs → chunk-U5LKNGHU.cjs} +21 -21
  43. package/dist/{chunk-4XHG6Q42.cjs.map → chunk-U5LKNGHU.cjs.map} +1 -1
  44. package/dist/{chunk-M52S3TFI.js → chunk-WFR7HKJL.js} +3 -3
  45. package/dist/{chunk-M52S3TFI.js.map → chunk-WFR7HKJL.js.map} +1 -1
  46. package/dist/{chunk-NILA2LZY.js → chunk-YIKXJWO4.js} +27 -9
  47. package/dist/chunk-YIKXJWO4.js.map +1 -0
  48. package/dist/composer.cjs +4 -4
  49. package/dist/composer.d.cts +2 -2
  50. package/dist/composer.d.ts +2 -2
  51. package/dist/composer.js +2 -2
  52. package/dist/content-renderer.cjs +7 -5
  53. package/dist/content-renderer.d.cts +56 -4
  54. package/dist/content-renderer.d.ts +56 -4
  55. package/dist/content-renderer.js +4 -2
  56. package/dist/editor.cjs +6 -5
  57. package/dist/editor.d.cts +1 -1
  58. package/dist/editor.d.ts +1 -1
  59. package/dist/editor.js +4 -3
  60. package/dist/{extensions-6PVd3-vB.d.cts → extensions-DiByZIpD.d.cts} +26 -3
  61. package/dist/{extensions-6PVd3-vB.d.ts → extensions-DiByZIpD.d.ts} +26 -3
  62. package/dist/{index-CCJVT9Hu.d.cts → index-DWtSViJ3.d.cts} +7 -1
  63. package/dist/{index-DRlltbdV.d.ts → index-XR5t8bTq.d.ts} +7 -1
  64. package/dist/index.cjs +47 -48
  65. package/dist/index.cjs.map +1 -1
  66. package/dist/index.d.cts +5 -5
  67. package/dist/index.d.ts +5 -5
  68. package/dist/index.js +10 -11
  69. package/dist/index.js.map +1 -1
  70. package/dist/input.cjs +3 -3
  71. package/dist/input.d.cts +1 -1
  72. package/dist/input.d.ts +1 -1
  73. package/dist/input.js +2 -2
  74. package/dist/inputs.cjs +3 -3
  75. package/dist/inputs.d.cts +1 -1
  76. package/dist/inputs.d.ts +1 -1
  77. package/dist/inputs.js +2 -2
  78. package/dist/json-editor.cjs +15 -16
  79. package/dist/json-editor.js +4 -5
  80. package/dist/magic-wand.cjs +3 -4
  81. package/dist/magic-wand.js +2 -3
  82. package/dist/paste-pills.cjs +14 -14
  83. package/dist/paste-pills.d.cts +3 -3
  84. package/dist/paste-pills.d.ts +3 -3
  85. package/dist/paste-pills.js +1 -1
  86. package/dist/prompt-input.cjs +6 -7
  87. package/dist/prompt-input.d.cts +2 -2
  88. package/dist/prompt-input.d.ts +2 -2
  89. package/dist/prompt-input.js +3 -4
  90. package/dist/reason-tag.cjs +3 -4
  91. package/dist/reason-tag.js +2 -3
  92. package/docs/ContentRenderer.md +138 -3
  93. package/docs/PromptInput.md +24 -1
  94. package/package.json +1 -1
  95. package/dist/chunk-6TBRBN7H.js +0 -212
  96. package/dist/chunk-6TBRBN7H.js.map +0 -1
  97. package/dist/chunk-C463C4MM.cjs.map +0 -1
  98. package/dist/chunk-C5YX5XVL.cjs.map +0 -1
  99. package/dist/chunk-COXHFZR6.js.map +0 -1
  100. package/dist/chunk-L24LUSEE.js.map +0 -1
  101. package/dist/chunk-MCQJFMDP.cjs.map +0 -1
  102. package/dist/chunk-NILA2LZY.js.map +0 -1
  103. package/dist/chunk-QNQNGARW.cjs.map +0 -1
  104. package/dist/chunk-TLRRMYNV.js.map +0 -1
  105. package/dist/chunk-X2FC7ODX.cjs +0 -215
  106. package/dist/chunk-X2FC7ODX.cjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { Textarea } from './chunk-UVUBV4VZ.js';
2
2
  import { Portal } from './chunk-RBCMKPBX.js';
3
3
  import { Badge } from './chunk-6FCQD2KQ.js';
4
- import { Button } from './chunk-TLRRMYNV.js';
4
+ import { Button } from './chunk-OXERDFFF.js';
5
5
  import { useRef, useState, useCallback, useEffect } from 'react';
6
6
  import { jsx, jsxs } from 'react/jsx-runtime';
7
7
 
@@ -260,5 +260,5 @@ function selectionPoint(ta, start, end) {
260
260
  }
261
261
 
262
262
  export { MagicWand };
263
- //# sourceMappingURL=chunk-M52S3TFI.js.map
264
- //# sourceMappingURL=chunk-M52S3TFI.js.map
263
+ //# sourceMappingURL=chunk-WFR7HKJL.js.map
264
+ //# sourceMappingURL=chunk-WFR7HKJL.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/MagicWand/MagicWand.ts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A,CAAI,YAAY,SAAS,CAAA;AAEzB,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,GAAG,CAAA;AAC7B,EAAA,MAAM,MAAA,GAAS,GAAG,qBAAA,EAAsB;AACxC,EAAA,MAAM,QAAA,GAAW,UAAU,qBAAA,EAAsB;AACjD,EAAA,MAAM,OAAA,GAAU,IAAI,qBAAA,EAAsB;AAC1C,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,GAAO,OAAA,CAAQ,IAAA;AACxC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,GAAA,GAAM,OAAA,CAAQ,GAAA;AACvC,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,GAAG,CAAA;AAE7B,EAAA,OAAO;AAAA,IACL,CAAA,EAAG,MAAA,CAAO,IAAA,GAAO,OAAA,GAAU,SAAS,KAAA,GAAQ,CAAA;AAAA,IAC5C,CAAA,EAAG,MAAA,CAAO,GAAA,GAAM,OAAA,GAAU,EAAA,CAAG;AAAA,GAC/B;AACF","file":"chunk-M52S3TFI.js","sourcesContent":["import { useCallback, useEffect, useRef, useState, type RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport { Badge } from \"../Badge\";\nimport { Portal } from \"../Portal\";\nimport { Textarea } from \"../inputs/Textarea/Textarea\";\n\n/**\n * MagicWand — selection-anchored floating toolbar for text inputs.\n *\n * When the user highlights text inside the wrapped <Textarea>, a small\n * pill of AI quick-actions floats above the selection. Clicking an\n * action invokes the host callback with the selected substring + range;\n * the host returns a replacement string and MagicWand swaps it in-place.\n *\n * <MagicWand\n * value={body}\n * onValueChange={setBody}\n * actions={[\n * { id: \"rephrase\", label: \"Rephrase\", hint: \"same meaning, different words\",\n * run: async (s) => await ai.rephrase(s) },\n * …\n * ]}\n * />\n *\n * Pass `target` to act on a textarea, input or editor the HOST renders instead:\n * MagicWand then renders no textarea of its own, only the floating wand.\n *\n * <textarea ref={ref} value={body} onChange={(e) => setBody(e.target.value)} />\n * <MagicWand target={ref} value={body} onValueChange={setBody} actions={…} />\n *\n * Two appearances: `\"floating\"` (default — full labels) and `\"pill\"`\n * (icon-only, compact). Auto-hides on click-away or scroll by default.\n */\nexport type MagicWandSelection = { start: number; end: number; text: string };\n\nexport type MagicWandAction = {\n /** Stable id, also shown as the busy-state key. */\n id: string;\n /** Display label (first character used in `pill` mode). */\n label: string;\n /** Tooltip body. */\n hint?: string;\n /** Optional kind chip rendered next to the label. */\n tag?: string;\n /** Returns the replacement text for the selection. */\n run: (selection: string, range: MagicWandSelection) => Promise<string> | string;\n};\n\nexport type MagicWandAppearance = \"pill\" | \"floating\";\n\n/** A viewport rectangle, the shape `getBoundingClientRect()` returns. */\nexport type MagicWandRect = { left: number; top: number; width: number; height: number };\n\n/**\n * How MagicWand reads a selection out of an editor it does not own — a code\n * editor, a contenteditable, anything that is not a plain textarea.\n *\n * Read-only on purpose. The write goes through `onValueChange`, like every other\n * edit, so the host's `value` stays the one source of truth and the editor is\n * updated the way it always is: from that value.\n */\nexport interface MagicWandTargetAdapter {\n /**\n * The editor's element. MagicWand listens on it for `mouseup` / `keyup` /\n * `select` to know the selection may have changed, and treats a click inside\n * it as \"not away\" for `autoHide`.\n */\n element: RefObject<HTMLElement | null> | HTMLElement | null;\n /** The selection as offsets into `value`. `null` or `start === end` hides the wand. */\n getSelection: () => { start: number; end: number } | null;\n /** Where the selection is on screen. Default: the top-centre of `element`. */\n getSelectionRect?: () => MagicWandRect | null;\n}\n\n/** A host-owned textarea / input by ref, or an adapter for anything else. */\nexport type MagicWandTarget =\n | RefObject<HTMLTextAreaElement | HTMLInputElement | null>\n | MagicWandTargetAdapter;\n\nexport interface MagicWandProps {\n /** Controlled value — of the built-in textarea, or of `target`. */\n value: string;\n /** Called on every edit, and with the result of an action. */\n onValueChange: (v: string) => void;\n /** Action list. */\n actions: MagicWandAction[];\n /**\n * Act on a textarea / input / editor the host renders, instead of rendering\n * one. A ref to a textarea or input works as is; anything else takes a\n * `MagicWandTargetAdapter`. `value` must still be the target's current value.\n */\n target?: MagicWandTarget;\n /** Visual treatment. Defaults to \"floating\". */\n appearance?: MagicWandAppearance;\n /** Auto-hide the wand on click-away or scroll. Defaults to true. */\n autoHide?: boolean;\n /** Textarea rows (built-in textarea only). */\n rows?: number;\n /** Placeholder (built-in textarea only). */\n placeholder?: string;\n /** Called after an action runs successfully. */\n onAction?: (action: MagicWandAction, selection: MagicWandSelection, replacement: string) => void;\n}\n\nfunction isAdapter(target: MagicWandTarget): target is MagicWandTargetAdapter {\n return typeof (target as MagicWandTargetAdapter).getSelection === \"function\";\n}\n\nfunction targetElement(target: MagicWandTarget | undefined): HTMLElement | null {\n if (!target) return null;\n if (!isAdapter(target)) return target.current;\n const el = target.element;\n if (!el) return null;\n return el instanceof HTMLElement ? el : el.current;\n}\n\ntype TextField = HTMLTextAreaElement | HTMLInputElement;\n\n/** The selection and the viewport point the wand should sit above, or null. */\nfunction readTarget(\n target: MagicWandTarget,\n): { start: number; end: number; point: { x: number; y: number } } | null {\n if (!isAdapter(target)) {\n const field = target.current as TextField | null;\n if (!field) return null;\n const start = field.selectionStart ?? 0;\n const end = field.selectionEnd ?? 0;\n if (start === end) return null;\n return { start, end, point: selectionPoint(field, start, end) };\n }\n\n const range = target.getSelection();\n if (!range || range.start === range.end) return null;\n const rect = target.getSelectionRect?.() ?? targetElement(target)?.getBoundingClientRect() ?? null;\n const point = rect ? { x: rect.left + rect.width / 2, y: rect.top } : { x: 0, y: 0 };\n return { start: Math.min(range.start, range.end), end: Math.max(range.start, range.end), point };\n}\n\nexport function MagicWand({\n value,\n onValueChange,\n actions,\n target,\n appearance = \"floating\",\n autoHide = true,\n rows = 6,\n placeholder,\n onAction,\n}: MagicWandProps) {\n const taRef = useRef<HTMLTextAreaElement>(null);\n const wandRef = useRef<HTMLDivElement>(null);\n const [sel, setSel] = useState<MagicWandSelection | null>(null);\n const [pos, setPos] = useState<{ x: number; y: number } | null>(null);\n const [busy, setBusy] = useState<string | null>(null);\n\n const external = target !== undefined;\n // Latest value + target for the listeners, which attach once per element.\n const latest = useRef({ value, target });\n latest.current = { value, target };\n\n const hide = useCallback(() => {\n setSel(null);\n setPos(null);\n }, []);\n\n const measureSelection = useCallback(() => {\n const ta = taRef.current;\n if (!ta) return;\n const start = ta.selectionStart ?? 0;\n const end = ta.selectionEnd ?? 0;\n if (start === end) {\n hide();\n return;\n }\n const text = ta.value.slice(start, end);\n setSel({ start, end, text });\n // The built-in wand is positioned inside this component's `relative` box.\n const point = selectionPoint(ta, start, end);\n const box = (ta.offsetParent as HTMLElement | null)?.getBoundingClientRect() ?? ta.getBoundingClientRect();\n setPos({ x: point.x - box.left, y: point.y - box.top });\n }, [hide]);\n\n const measureTarget = useCallback(() => {\n const { target: t, value: v } = latest.current;\n if (!t) return;\n const read = readTarget(t);\n if (!read) {\n hide();\n return;\n }\n setSel({ start: read.start, end: read.end, text: v.slice(read.start, read.end) });\n setPos(read.point);\n }, [hide]);\n\n // The target's element is only known after the host renders it, so it is\n // re-resolved after every render and the listeners move if it changes.\n const [targetEl, setTargetEl] = useState<HTMLElement | null>(null);\n useEffect(() => {\n const next = targetElement(target);\n if (next !== targetEl) setTargetEl(next);\n });\n\n useEffect(() => {\n if (!targetEl) return;\n const events = [\"mouseup\", \"keyup\", \"select\"] as const;\n for (const e of events) targetEl.addEventListener(e, measureTarget);\n return () => {\n for (const e of events) targetEl.removeEventListener(e, measureTarget);\n };\n }, [targetEl, measureTarget]);\n\n useEffect(() => {\n if (!autoHide) return;\n window.addEventListener(\"scroll\", hide, true);\n return () => window.removeEventListener(\"scroll\", hide, true);\n }, [autoHide, hide]);\n\n useEffect(() => {\n if (!autoHide) return;\n const onDocMouseDown = (e: MouseEvent) => {\n const node = e.target as Node;\n if (wandRef.current?.contains(node)) return;\n if (taRef.current?.contains(node)) return;\n if (targetElement(latest.current.target)?.contains(node)) return;\n hide();\n };\n document.addEventListener(\"mousedown\", onDocMouseDown);\n return () => document.removeEventListener(\"mousedown\", onDocMouseDown);\n }, [autoHide, hide]);\n\n const handleAction = async (action: MagicWandAction) => {\n if (!sel) return;\n setBusy(action.id);\n try {\n const replacement = await action.run(sel.text, sel);\n const next = value.slice(0, sel.start) + replacement + value.slice(sel.end);\n onValueChange(next);\n onAction?.(action, sel, replacement);\n } finally {\n setBusy(null);\n hide();\n }\n };\n\n const wand =\n sel && pos ? (\n <Wand\n ref={wandRef}\n pos={pos}\n fixed={external}\n actions={actions}\n appearance={appearance}\n busy={busy}\n onAction={handleAction}\n selectionLength={sel.text.length}\n />\n ) : null;\n\n if (external) {\n return wand ? <Portal>{wand}</Portal> : null;\n }\n\n return (\n <div className=\"relative\">\n <Textarea\n ref={taRef as unknown as React.Ref<HTMLTextAreaElement>}\n value={value}\n onValueChange={onValueChange}\n onSelect={measureSelection}\n onKeyUp={measureSelection}\n onMouseUp={measureSelection}\n rows={rows}\n placeholder={placeholder}\n />\n {wand}\n </div>\n );\n}\n\nfunction Wand({\n ref,\n pos,\n fixed,\n actions,\n appearance,\n busy,\n onAction,\n selectionLength,\n}: {\n ref: React.RefObject<HTMLDivElement | null>;\n pos: { x: number; y: number };\n /** Viewport-positioned (portalled, for an external target) rather than inside the wrapper. */\n fixed: boolean;\n actions: MagicWandAction[];\n appearance: MagicWandAppearance;\n busy: string | null;\n onAction: (a: MagicWandAction) => void;\n selectionLength: number;\n}) {\n return (\n <div\n ref={ref}\n data-react-fancy-magic-wand=\"\"\n className={`${fixed ? \"fixed z-50\" : \"absolute z-20\"} -translate-x-1/2 -translate-y-full`}\n style={{ left: pos.x, top: pos.y - 6 }}\n >\n <div className=\"flex items-center gap-1 rounded-full border border-violet-300 bg-[color:var(--fancy-surface,var(--color-white))] px-1.5 py-1 shadow-lg ring-1 ring-violet-200 dark:border-violet-700 dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))] dark:ring-violet-900\">\n <span className=\"ml-1 mr-0.5 inline-flex items-center gap-1 text-[10px] font-medium text-violet-700 dark:text-violet-300\">\n <span aria-hidden>✦</span>\n {appearance === \"floating\" && (\n <Badge color=\"violet\">{selectionLength} chars</Badge>\n )}\n </span>\n {actions.map((a) => (\n <Button\n key={a.id}\n size=\"sm\"\n variant=\"ghost\"\n data-react-fancy-magic-wand-action={a.id}\n onClick={() => onAction(a)}\n disabled={busy !== null}\n title={a.hint}\n >\n {busy === a.id ? \"…\" : appearance === \"pill\" ? a.label[0] : a.label}\n {appearance === \"floating\" && a.tag && (\n <span className=\"ml-1 rounded-full bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] px-1 text-[9px] font-medium text-zinc-500 dark:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\">\n {a.tag}\n </span>\n )}\n </Button>\n ))}\n </div>\n <div className=\"absolute left-1/2 top-full -translate-x-1/2 -translate-y-px\">\n <div className=\"h-2 w-2 rotate-45 border-b border-r border-violet-300 bg-[color:var(--fancy-surface,var(--color-white))] dark:border-violet-700 dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\" />\n </div>\n </div>\n );\n}\n\n/**\n * Caret/selection geometry: mirror the field into a hidden div and measure the\n * selected substring's bounding rect. Returns the VIEWPORT point at the top\n * centre of the selection. Not perfect for resized textareas, but works for\n * typical chat composers.\n */\nfunction selectionPoint(ta: TextField, start: number, end: number): { x: number; y: number } {\n const div = document.createElement(\"div\");\n const style = getComputedStyle(ta);\n const props = [\n \"boxSizing\",\n \"width\",\n \"height\",\n \"overflowX\",\n \"overflowY\",\n \"borderTopWidth\",\n \"borderRightWidth\",\n \"borderBottomWidth\",\n \"borderLeftWidth\",\n \"paddingTop\",\n \"paddingRight\",\n \"paddingBottom\",\n \"paddingLeft\",\n \"fontStyle\",\n \"fontVariant\",\n \"fontWeight\",\n \"fontStretch\",\n \"fontSize\",\n \"fontSizeAdjust\",\n \"lineHeight\",\n \"fontFamily\",\n \"textAlign\",\n \"textTransform\",\n \"textIndent\",\n \"letterSpacing\",\n \"wordSpacing\",\n \"tabSize\",\n ] as const;\n for (const p of props) (div.style as any)[p] = (style as any)[p];\n div.style.position = \"absolute\";\n div.style.top = \"-9999px\";\n div.style.left = \"-9999px\";\n div.style.whiteSpace = \"pre-wrap\";\n div.style.wordWrap = \"break-word\";\n\n const value = ta.value;\n div.textContent = value.substring(0, start);\n const startSpan = document.createElement(\"span\");\n startSpan.textContent = value.substring(start, end) || \".\";\n div.appendChild(startSpan);\n\n document.body.appendChild(div);\n const taRect = ta.getBoundingClientRect();\n const spanRect = startSpan.getBoundingClientRect();\n const divRect = div.getBoundingClientRect();\n const offsetX = spanRect.left - divRect.left;\n const offsetY = spanRect.top - divRect.top;\n document.body.removeChild(div);\n\n return {\n x: taRect.left + offsetX + spanRect.width / 2,\n y: taRect.top + offsetY - ta.scrollTop,\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/components/MagicWand/MagicWand.tsx"],"names":[],"mappings":";;;;;;;AAwGA,SAAS,UAAU,MAAA,EAA2D;AAC5E,EAAA,OAAO,OAAQ,OAAkC,YAAA,KAAiB,UAAA;AACpE;AAEA,SAAS,cAAc,MAAA,EAAyD;AAC9E,EAAA,IAAI,CAAC,QAAQ,OAAO,IAAA;AACpB,EAAA,IAAI,CAAC,SAAA,CAAU,MAAM,CAAA,SAAU,MAAA,CAAO,OAAA;AACtC,EAAA,MAAM,KAAK,MAAA,CAAO,OAAA;AAClB,EAAA,IAAI,CAAC,IAAI,OAAO,IAAA;AAChB,EAAA,OAAO,EAAA,YAAc,WAAA,GAAc,EAAA,GAAK,EAAA,CAAG,OAAA;AAC7C;AAKA,SAAS,WACP,MAAA,EACwE;AACxE,EAAA,IAAI,CAAC,SAAA,CAAU,MAAM,CAAA,EAAG;AACtB,IAAA,MAAM,QAAQ,MAAA,CAAO,OAAA;AACrB,IAAA,IAAI,CAAC,OAAO,OAAO,IAAA;AACnB,IAAA,MAAM,KAAA,GAAQ,MAAM,cAAA,IAAkB,CAAA;AACtC,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,IAAgB,CAAA;AAClC,IAAA,IAAI,KAAA,KAAU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,EAAA,GAAA,CAAI,MAAM,GAAA,GAAM,SAAA;AAChB,EAAA,GAAA,CAAI,MAAM,IAAA,GAAO,SAAA;AACjB,EAAA,GAAA,CAAI,MAAM,UAAA,GAAa,UAAA;AACvB,EAAA,GAAA,CAAI,MAAM,QAAA,GAAW,YAAA;AAErB,EAAA,MAAM,QAAQ,EAAA,CAAG,KAAA;AACjB,EAAA,GAAA,CAAI,WAAA,GAAc,KAAA,CAAM,SAAA,CAAU,CAAA,EAAG,KAAK,CAAA;AAC1C,EAAA,MAAM,SAAA,GAAY,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA;AAC/C,EAAA,SAAA,CAAU,WAAA,GAAc,KAAA,CAAM,SAAA,CAAU,KAAA,EAAO,GAAG,CAAA,IAAK,GAAA;AACvD,EAAA,GAAA,CAAI,YAAY,SAAS,CAAA;AAEzB,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,GAAG,CAAA;AAC7B,EAAA,MAAM,MAAA,GAAS,GAAG,qBAAA,EAAsB;AACxC,EAAA,MAAM,QAAA,GAAW,UAAU,qBAAA,EAAsB;AACjD,EAAA,MAAM,OAAA,GAAU,IAAI,qBAAA,EAAsB;AAC1C,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,GAAO,OAAA,CAAQ,IAAA;AACxC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,GAAA,GAAM,OAAA,CAAQ,GAAA;AACvC,EAAA,QAAA,CAAS,IAAA,CAAK,YAAY,GAAG,CAAA;AAE7B,EAAA,OAAO;AAAA,IACL,CAAA,EAAG,MAAA,CAAO,IAAA,GAAO,OAAA,GAAU,SAAS,KAAA,GAAQ,CAAA;AAAA,IAC5C,CAAA,EAAG,MAAA,CAAO,GAAA,GAAM,OAAA,GAAU,EAAA,CAAG;AAAA,GAC/B;AACF","file":"chunk-WFR7HKJL.js","sourcesContent":["import { useCallback, useEffect, useRef, useState, type RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport { Badge } from \"../Badge\";\nimport { Portal } from \"../Portal\";\nimport { Textarea } from \"../inputs/Textarea/Textarea\";\n\n/**\n * MagicWand — selection-anchored floating toolbar for text inputs.\n *\n * When the user highlights text inside the wrapped <Textarea>, a small\n * pill of AI quick-actions floats above the selection. Clicking an\n * action invokes the host callback with the selected substring + range;\n * the host returns a replacement string and MagicWand swaps it in-place.\n *\n * <MagicWand\n * value={body}\n * onValueChange={setBody}\n * actions={[\n * { id: \"rephrase\", label: \"Rephrase\", hint: \"same meaning, different words\",\n * run: async (s) => await ai.rephrase(s) },\n * …\n * ]}\n * />\n *\n * Pass `target` to act on a textarea, input or editor the HOST renders instead:\n * MagicWand then renders no textarea of its own, only the floating wand.\n *\n * <textarea ref={ref} value={body} onChange={(e) => setBody(e.target.value)} />\n * <MagicWand target={ref} value={body} onValueChange={setBody} actions={…} />\n *\n * Two appearances: `\"floating\"` (default — full labels) and `\"pill\"`\n * (icon-only, compact). Auto-hides on click-away or scroll by default.\n */\nexport type MagicWandSelection = { start: number; end: number; text: string };\n\nexport type MagicWandAction = {\n /** Stable id, also shown as the busy-state key. */\n id: string;\n /** Display label (first character used in `pill` mode). */\n label: string;\n /** Tooltip body. */\n hint?: string;\n /** Optional kind chip rendered next to the label. */\n tag?: string;\n /** Returns the replacement text for the selection. */\n run: (selection: string, range: MagicWandSelection) => Promise<string> | string;\n};\n\nexport type MagicWandAppearance = \"pill\" | \"floating\";\n\n/** A viewport rectangle, the shape `getBoundingClientRect()` returns. */\nexport type MagicWandRect = { left: number; top: number; width: number; height: number };\n\n/**\n * How MagicWand reads a selection out of an editor it does not own — a code\n * editor, a contenteditable, anything that is not a plain textarea.\n *\n * Read-only on purpose. The write goes through `onValueChange`, like every other\n * edit, so the host's `value` stays the one source of truth and the editor is\n * updated the way it always is: from that value.\n */\nexport interface MagicWandTargetAdapter {\n /**\n * The editor's element. MagicWand listens on it for `mouseup` / `keyup` /\n * `select` to know the selection may have changed, and treats a click inside\n * it as \"not away\" for `autoHide`.\n */\n element: RefObject<HTMLElement | null> | HTMLElement | null;\n /** The selection as offsets into `value`. `null` or `start === end` hides the wand. */\n getSelection: () => { start: number; end: number } | null;\n /** Where the selection is on screen. Default: the top-centre of `element`. */\n getSelectionRect?: () => MagicWandRect | null;\n}\n\n/** A host-owned textarea / input by ref, or an adapter for anything else. */\nexport type MagicWandTarget =\n | RefObject<HTMLTextAreaElement | HTMLInputElement | null>\n | MagicWandTargetAdapter;\n\nexport interface MagicWandProps {\n /** Controlled value — of the built-in textarea, or of `target`. */\n value: string;\n /** Called on every edit, and with the result of an action. */\n onValueChange: (v: string) => void;\n /** Action list. */\n actions: MagicWandAction[];\n /**\n * Act on a textarea / input / editor the host renders, instead of rendering\n * one. A ref to a textarea or input works as is; anything else takes a\n * `MagicWandTargetAdapter`. `value` must still be the target's current value.\n */\n target?: MagicWandTarget;\n /** Visual treatment. Defaults to \"floating\". */\n appearance?: MagicWandAppearance;\n /** Auto-hide the wand on click-away or scroll. Defaults to true. */\n autoHide?: boolean;\n /** Textarea rows (built-in textarea only). */\n rows?: number;\n /** Placeholder (built-in textarea only). */\n placeholder?: string;\n /** Called after an action runs successfully. */\n onAction?: (action: MagicWandAction, selection: MagicWandSelection, replacement: string) => void;\n}\n\nfunction isAdapter(target: MagicWandTarget): target is MagicWandTargetAdapter {\n return typeof (target as MagicWandTargetAdapter).getSelection === \"function\";\n}\n\nfunction targetElement(target: MagicWandTarget | undefined): HTMLElement | null {\n if (!target) return null;\n if (!isAdapter(target)) return target.current;\n const el = target.element;\n if (!el) return null;\n return el instanceof HTMLElement ? el : el.current;\n}\n\ntype TextField = HTMLTextAreaElement | HTMLInputElement;\n\n/** The selection and the viewport point the wand should sit above, or null. */\nfunction readTarget(\n target: MagicWandTarget,\n): { start: number; end: number; point: { x: number; y: number } } | null {\n if (!isAdapter(target)) {\n const field = target.current as TextField | null;\n if (!field) return null;\n const start = field.selectionStart ?? 0;\n const end = field.selectionEnd ?? 0;\n if (start === end) return null;\n return { start, end, point: selectionPoint(field, start, end) };\n }\n\n const range = target.getSelection();\n if (!range || range.start === range.end) return null;\n const rect = target.getSelectionRect?.() ?? targetElement(target)?.getBoundingClientRect() ?? null;\n const point = rect ? { x: rect.left + rect.width / 2, y: rect.top } : { x: 0, y: 0 };\n return { start: Math.min(range.start, range.end), end: Math.max(range.start, range.end), point };\n}\n\nexport function MagicWand({\n value,\n onValueChange,\n actions,\n target,\n appearance = \"floating\",\n autoHide = true,\n rows = 6,\n placeholder,\n onAction,\n}: MagicWandProps) {\n const taRef = useRef<HTMLTextAreaElement>(null);\n const wandRef = useRef<HTMLDivElement>(null);\n const [sel, setSel] = useState<MagicWandSelection | null>(null);\n const [pos, setPos] = useState<{ x: number; y: number } | null>(null);\n const [busy, setBusy] = useState<string | null>(null);\n\n const external = target !== undefined;\n // Latest value + target for the listeners, which attach once per element.\n const latest = useRef({ value, target });\n latest.current = { value, target };\n\n const hide = useCallback(() => {\n setSel(null);\n setPos(null);\n }, []);\n\n const measureSelection = useCallback(() => {\n const ta = taRef.current;\n if (!ta) return;\n const start = ta.selectionStart ?? 0;\n const end = ta.selectionEnd ?? 0;\n if (start === end) {\n hide();\n return;\n }\n const text = ta.value.slice(start, end);\n setSel({ start, end, text });\n // The built-in wand is positioned inside this component's `relative` box.\n const point = selectionPoint(ta, start, end);\n const box = (ta.offsetParent as HTMLElement | null)?.getBoundingClientRect() ?? ta.getBoundingClientRect();\n setPos({ x: point.x - box.left, y: point.y - box.top });\n }, [hide]);\n\n const measureTarget = useCallback(() => {\n const { target: t, value: v } = latest.current;\n if (!t) return;\n const read = readTarget(t);\n if (!read) {\n hide();\n return;\n }\n setSel({ start: read.start, end: read.end, text: v.slice(read.start, read.end) });\n setPos(read.point);\n }, [hide]);\n\n // The target's element is only known after the host renders it, so it is\n // re-resolved after every render and the listeners move if it changes.\n const [targetEl, setTargetEl] = useState<HTMLElement | null>(null);\n useEffect(() => {\n const next = targetElement(target);\n if (next !== targetEl) setTargetEl(next);\n });\n\n useEffect(() => {\n if (!targetEl) return;\n const events = [\"mouseup\", \"keyup\", \"select\"] as const;\n for (const e of events) targetEl.addEventListener(e, measureTarget);\n return () => {\n for (const e of events) targetEl.removeEventListener(e, measureTarget);\n };\n }, [targetEl, measureTarget]);\n\n useEffect(() => {\n if (!autoHide) return;\n window.addEventListener(\"scroll\", hide, true);\n return () => window.removeEventListener(\"scroll\", hide, true);\n }, [autoHide, hide]);\n\n useEffect(() => {\n if (!autoHide) return;\n const onDocMouseDown = (e: MouseEvent) => {\n const node = e.target as Node;\n if (wandRef.current?.contains(node)) return;\n if (taRef.current?.contains(node)) return;\n if (targetElement(latest.current.target)?.contains(node)) return;\n hide();\n };\n document.addEventListener(\"mousedown\", onDocMouseDown);\n return () => document.removeEventListener(\"mousedown\", onDocMouseDown);\n }, [autoHide, hide]);\n\n const handleAction = async (action: MagicWandAction) => {\n if (!sel) return;\n setBusy(action.id);\n try {\n const replacement = await action.run(sel.text, sel);\n const next = value.slice(0, sel.start) + replacement + value.slice(sel.end);\n onValueChange(next);\n onAction?.(action, sel, replacement);\n } finally {\n setBusy(null);\n hide();\n }\n };\n\n const wand =\n sel && pos ? (\n <Wand\n ref={wandRef}\n pos={pos}\n fixed={external}\n actions={actions}\n appearance={appearance}\n busy={busy}\n onAction={handleAction}\n selectionLength={sel.text.length}\n />\n ) : null;\n\n if (external) {\n return wand ? <Portal>{wand}</Portal> : null;\n }\n\n return (\n <div className=\"relative\">\n <Textarea\n ref={taRef as unknown as React.Ref<HTMLTextAreaElement>}\n value={value}\n onValueChange={onValueChange}\n onSelect={measureSelection}\n onKeyUp={measureSelection}\n onMouseUp={measureSelection}\n rows={rows}\n placeholder={placeholder}\n />\n {wand}\n </div>\n );\n}\n\nfunction Wand({\n ref,\n pos,\n fixed,\n actions,\n appearance,\n busy,\n onAction,\n selectionLength,\n}: {\n ref: React.RefObject<HTMLDivElement | null>;\n pos: { x: number; y: number };\n /** Viewport-positioned (portalled, for an external target) rather than inside the wrapper. */\n fixed: boolean;\n actions: MagicWandAction[];\n appearance: MagicWandAppearance;\n busy: string | null;\n onAction: (a: MagicWandAction) => void;\n selectionLength: number;\n}) {\n return (\n <div\n ref={ref}\n data-react-fancy-magic-wand=\"\"\n className={`${fixed ? \"fixed z-50\" : \"absolute z-20\"} -translate-x-1/2 -translate-y-full`}\n style={{ left: pos.x, top: pos.y - 6 }}\n >\n <div className=\"flex items-center gap-1 rounded-full border border-violet-300 bg-[color:var(--fancy-surface,var(--color-white))] px-1.5 py-1 shadow-lg ring-1 ring-violet-200 dark:border-violet-700 dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))] dark:ring-violet-900\">\n <span className=\"ml-1 mr-0.5 inline-flex items-center gap-1 text-[10px] font-medium text-violet-700 dark:text-violet-300\">\n <span aria-hidden>✦</span>\n {appearance === \"floating\" && (\n <Badge color=\"violet\">{selectionLength} chars</Badge>\n )}\n </span>\n {actions.map((a) => (\n <Button\n key={a.id}\n size=\"sm\"\n variant=\"ghost\"\n data-react-fancy-magic-wand-action={a.id}\n onClick={() => onAction(a)}\n disabled={busy !== null}\n title={a.hint}\n >\n {busy === a.id ? \"…\" : appearance === \"pill\" ? a.label[0] : a.label}\n {appearance === \"floating\" && a.tag && (\n <span className=\"ml-1 rounded-full bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] px-1 text-[9px] font-medium text-zinc-500 dark:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))]\">\n {a.tag}\n </span>\n )}\n </Button>\n ))}\n </div>\n <div className=\"absolute left-1/2 top-full -translate-x-1/2 -translate-y-px\">\n <div className=\"h-2 w-2 rotate-45 border-b border-r border-violet-300 bg-[color:var(--fancy-surface,var(--color-white))] dark:border-violet-700 dark:bg-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\" />\n </div>\n </div>\n );\n}\n\n/**\n * Caret/selection geometry: mirror the field into a hidden div and measure the\n * selected substring's bounding rect. Returns the VIEWPORT point at the top\n * centre of the selection. Not perfect for resized textareas, but works for\n * typical chat composers.\n */\nfunction selectionPoint(ta: TextField, start: number, end: number): { x: number; y: number } {\n const div = document.createElement(\"div\");\n const style = getComputedStyle(ta);\n const props = [\n \"boxSizing\",\n \"width\",\n \"height\",\n \"overflowX\",\n \"overflowY\",\n \"borderTopWidth\",\n \"borderRightWidth\",\n \"borderBottomWidth\",\n \"borderLeftWidth\",\n \"paddingTop\",\n \"paddingRight\",\n \"paddingBottom\",\n \"paddingLeft\",\n \"fontStyle\",\n \"fontVariant\",\n \"fontWeight\",\n \"fontStretch\",\n \"fontSize\",\n \"fontSizeAdjust\",\n \"lineHeight\",\n \"fontFamily\",\n \"textAlign\",\n \"textTransform\",\n \"textIndent\",\n \"letterSpacing\",\n \"wordSpacing\",\n \"tabSize\",\n ] as const;\n for (const p of props) (div.style as any)[p] = (style as any)[p];\n div.style.position = \"absolute\";\n div.style.top = \"-9999px\";\n div.style.left = \"-9999px\";\n div.style.whiteSpace = \"pre-wrap\";\n div.style.wordWrap = \"break-word\";\n\n const value = ta.value;\n div.textContent = value.substring(0, start);\n const startSpan = document.createElement(\"span\");\n startSpan.textContent = value.substring(start, end) || \".\";\n div.appendChild(startSpan);\n\n document.body.appendChild(div);\n const taRect = ta.getBoundingClientRect();\n const spanRect = startSpan.getBoundingClientRect();\n const divRect = div.getBoundingClientRect();\n const offsetX = spanRect.left - divRect.left;\n const offsetY = spanRect.top - divRect.top;\n document.body.removeChild(div);\n\n return {\n x: taRect.left + offsetX + spanRect.width / 2,\n y: taRect.top + offsetY - ta.scrollTop,\n };\n}\n"]}
@@ -62,6 +62,26 @@ function endsOf(text, chars) {
62
62
  if (text.length <= chars * 2) return text;
63
63
  return `${text.slice(0, chars)} \u2026 ${text.slice(-chars)}`;
64
64
  }
65
+ var TEXT_PILL_LABEL_MAX = 80;
66
+ function textPillLabel(raw) {
67
+ if (typeof raw !== "string") return null;
68
+ let out = "";
69
+ let pendingSpace = false;
70
+ for (const ch of raw) {
71
+ const c = ch.codePointAt(0);
72
+ const blank = c < 32 || c >= 127 && c <= 159 || c === 65532 || ch.trim() === "";
73
+ if (blank) {
74
+ pendingSpace = out.length > 0;
75
+ continue;
76
+ }
77
+ if (pendingSpace) out += " ";
78
+ pendingSpace = false;
79
+ out += ch;
80
+ }
81
+ if (out === "") return null;
82
+ const points = Array.from(out);
83
+ return points.length > TEXT_PILL_LABEL_MAX ? `${points.slice(0, TEXT_PILL_LABEL_MAX - 1).join("").trimEnd()}\u2026` : out;
84
+ }
65
85
  var PILL_BASE = "inline-flex select-none items-center rounded-md px-2 py-0.5 text-xs leading-5 transition-colors";
66
86
  var TEXT_PILL = "cursor-pointer bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] text-zinc-700 hover:bg-zinc-200 dark:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))] dark:text-zinc-200 dark:hover:bg-zinc-700";
67
87
  var IMAGE_PILL = "bg-rose-100 font-medium text-rose-600 dark:bg-rose-500/20 dark:text-rose-300";
@@ -101,6 +121,8 @@ function InlinePill({
101
121
  onFocus: () => setOpen(true),
102
122
  onBlur: () => setOpen(false)
103
123
  };
124
+ const textLabel = preview.kind === "text" ? textPillLabel(preview.paste.label) : null;
125
+ const textSize = preview.kind === "text" ? `${withSeparators(preview.paste.text.length)} characters` : "";
104
126
  const pill = preview.kind === "image" ? /* @__PURE__ */ jsx(
105
127
  "span",
106
128
  {
@@ -112,21 +134,17 @@ function InlinePill({
112
134
  className: cn(PILL_BASE, IMAGE_PILL, classNames?.pill, classNames?.imagePill),
113
135
  children: preview.image.label
114
136
  }
115
- ) : /* @__PURE__ */ jsxs(
137
+ ) : /* @__PURE__ */ jsx(
116
138
  "button",
117
139
  {
118
140
  type: "button",
119
141
  "data-react-fancy-composer-paste-pill": id,
120
142
  onClick: () => onExpand(id),
121
143
  disabled,
122
- "aria-label": `Insert this pasted text, ${withSeparators(preview.paste.text.length)} characters`,
144
+ "aria-label": textLabel === null ? `Insert this pasted text, ${textSize}` : `Insert this pasted text: ${textLabel}, ${textSize}`,
123
145
  ...focusOpen,
124
146
  className: cn(PILL_BASE, TEXT_PILL, classNames?.pill, classNames?.textPill),
125
- children: [
126
- "Pasted text \xB7 ",
127
- withSeparators(preview.paste.text.length),
128
- " characters"
129
- ]
147
+ children: textLabel ?? `Pasted text \xB7 ${textSize}`
130
148
  }
131
149
  );
132
150
  return /* @__PURE__ */ jsxs(Popover, { hover: true, open, onOpenChange: setOpen, placement: "top", children: [
@@ -656,5 +674,5 @@ function PastedFilesInput({ name, files, form }) {
656
674
  }
657
675
 
658
676
  export { HOST_ATTR, InlinePasteEditor, InlinePill, PILL_MARK, PastedFilesInput, endsOf, expandMarkers, markedIds, pasteMarker, segmentValue, useInlinePaste, usePastePills, withSeparators };
659
- //# sourceMappingURL=chunk-NILA2LZY.js.map
660
- //# sourceMappingURL=chunk-NILA2LZY.js.map
677
+ //# sourceMappingURL=chunk-YIKXJWO4.js.map
678
+ //# sourceMappingURL=chunk-YIKXJWO4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/PastePills/use-paste-pills.ts","../src/components/PastePills/InlinePill.tsx","../src/components/PastePills/paste-markers.ts","../src/components/PastePills/use-inline-paste.tsx","../src/components/PastePills/InlinePasteEditor.tsx","../src/components/PastePills/PastedFilesInput.tsx"],"names":["useRef","useCallback","useState","jsx","InlinePasteEditor","id","range","jsxs","useEffect"],"mappings":";;;;;;;AAkIO,SAAS,aAAA,CAAc;AAAA,EAC5B,SAAA;AAAA,EACA,UAAA,EAAY,oBAAA;AAAA,EACZ;AACF,CAAA,GAA0B,EAAC,EAAwB;AACjD,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,oBAAA;AAAA,IAClC,oBAAA;AAAA,IACA,EAAC;AAAA,IACD;AAAA,GACF;AAUA,EAAA,MAAM,MAAA,GAAS,OAAO,CAAC,CAAA;AAEvB,EAAA,MAAM,IAAA,GAAO,WAAA;AAAA,IACX,CAAC,IAAA,KAAyB;AAOxB,MAAA,IAAI,EAAA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ACA;AAAA;AACF;AAAA;AACF,KAAA,EACF,CAAA;AAAA,EAEJ;AACF;ACteO,SAAS,gBAAA,CAAiB,EAAE,IAAA,EAAM,KAAA,EAAO,MAAK,EAA0B;AAC7E,EAAA,MAAM,GAAA,GAAMH,OAAyB,IAAI,CAAA;AAEzC,EAAAQ,UAAU,MAAM;AACd,IAAA,MAAM,KAAK,GAAA,CAAI,OAAA;AAGf,IAAA,IAAI,CAAC,EAAA,IAAM,OAAO,YAAA,KAAiB,WAAA,EAAa;AAEhD,IAAA,MAAM,QAAA,GAAW,IAAI,YAAA,EAAa;AAClC,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAA,EAAO,QAAA,CAAS,KAAA,CAAM,IAAI,IAAI,CAAA;AACjD,IAAA,EAAA,CAAG,QAAQ,QAAA,CAAS,KAAA;AAAA,EACtB,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,uBACEL,GAAAA;AAAA,IAAC,OAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,IAAA,EAAK,MAAA;AAAA,MACL,IAAA;AAAA,MACA,IAAA;AAAA,MACA,QAAA,EAAQ,IAAA;AAAA,MACR,MAAA,EAAM,IAAA;AAAA,MACN,QAAA,EAAU,EAAA;AAAA,MACV,+BAAA,EAA+B;AAAA;AAAA,GACjC;AAEJ","file":"chunk-YIKXJWO4.js","sourcesContent":["import { useCallback, useRef } from \"react\";\nimport { useControllableState } from \"../../hooks/use-controllable-state\";\n\n/**\n * A paste held beside a composer rather than inserted into it.\n *\n * There is deliberately **no `length` field.** It would be `text.length` and\n * nothing else, and a derived value stored beside its source is a value that can\n * disagree with it — the two drift the moment anything edits one. Read\n * `paste.text.length`.\n */\nexport interface HeldPaste {\n id: string;\n text: string;\n /** Shown on the pill instead of `Pasted text · N characters`. Display only. */\n label?: string;\n}\n\n/**\n * The minimum of a clipboard event this hook touches.\n *\n * Structural rather than `React.ClipboardEvent` so a host can call it from a\n * native listener, a synthetic one, or a test double. React's own event satisfies\n * it.\n */\nexport interface PasteEventLike {\n clipboardData?: { getData(type: string): string } | null;\n preventDefault(): void;\n}\n\nexport interface UsePastePillsOptions {\n /**\n * Hold a paste of at least this many characters. Try 500 — about a long\n * paragraph.\n *\n * **No default, on purpose.** Paste is a fundamental interaction, so holding one\n * is something a host asks for rather than something it discovers. Omit this and\n * `handlePaste` always returns `false` and touches nothing.\n */\n threshold?: number;\n /** Own the list yourself. Omit to let the hook keep it. */\n heldPastes?: HeldPaste[];\n onHeldPastesChange?: (pastes: HeldPaste[]) => void;\n}\n\nexport interface UsePastePillsResult {\n heldPastes: HeldPaste[];\n /**\n * Call this from your OWN paste handler. Returns `true` if it took the paste —\n * in which case it has already called `preventDefault()` — and `false` if it\n * declined, having touched nothing.\n *\n * Composable on purpose: a host whose handler already intercepts paste for its\n * own reasons needs to ask \"did you want this?\" rather than hand over the event.\n *\n * function onPaste(e) {\n * if (pills.handlePaste(e)) return;\n * // ...your own handling\n * }\n */\n handlePaste: (event: PasteEventLike) => boolean;\n /**\n * Hold `text` unconditionally and return the new pill's id.\n *\n * For a host that decides for itself what to hold and needs to know WHICH pill\n * it made — `Composer`'s inline placement puts the pill at the caret, so it needs\n * the id at paste time. Ignores `threshold`; the caller has already decided.\n */\n hold: (text: string) => string;\n /**\n * Removes the paste and returns its text, for the host to insert into its own\n * surface. `undefined` if there is no such id.\n *\n * The hook cannot insert it — it owns no DOM and does not know what a host's\n * surface is. That is the point.\n */\n expand: (id: string) => string | undefined;\n /** Discard one without returning it. */\n remove: (id: string) => void;\n /** Empty the list, e.g. after a send. */\n clear: () => void;\n}\n\n/**\n * Hold a large paste as state, so a composer can show it as a pill instead of\n * turning itself into a scrolling wall.\n *\n * ---------------------------------------------------------------------------\n * Why this is a hook and not just a feature of `Composer`\n * ---------------------------------------------------------------------------\n *\n * `Composer` shipped the behaviour in 5.31.0 and the MOIC estate, who specified it,\n * then established something I had missed: their chat input is a contenteditable\n * rendering inline `[deal:42|Acme]` badges, so they **cannot** adopt `Composer` (a\n * plain textarea) however much they want its behaviour. Their plan to delete their\n * own composer when ours landed could never have worked.\n *\n * So the logic lives here and **`Composer` is its first caller.** One\n * implementation rather than two, which matters more than the convenience: two\n * copies of a rule drift, and the copy nobody reads is the one that rots. The rule\n * that must not drift is the one in `Composer`'s own tests — a send with pills\n * still closed carries the text.\n *\n * It owns no DOM. The host renders the pills.\n *\n * ---------------------------------------------------------------------------\n * Who actually calls this (as of 5.32.0): `Composer`, and nothing else\n * ---------------------------------------------------------------------------\n *\n * The estate that specified it **withdrew before adopting it**, hours after it\n * shipped — their design moved the pill INTO the message as a `[paste:id|label]`\n * marker in the same grammar as their other object tags, which makes the message\n * itself the record of what is attached. A parallel `heldPastes` array would then be\n * a second place answering \"what am I sending?\", and the two would disagree the\n * moment someone backspaced a badge. Their reasoning was better than the spec.\n *\n * Recorded because a reader should not infer an extension point under active\n * external use. It is kept rather than withdrawn for two reasons that are about\n * cost, not optimism: it is published API on a 5.x package, so removing it needs a\n * major; and `Composer` calls it, so it is exercised by that component's tests on\n * every run and cannot rot unnoticed.\n *\n * **It gets no further surface without a real caller.** No extra options, no second\n * hook. An API with one hypothetical consumer is how a package accumulates surface\n * nobody uses.\n *\n * `hold` (5.38.0) met that bar: `Composer`'s inline placement — MOIC's\n * pill-inside-the-message design, built into the component — needs the id of the\n * pill it just made so it can put it at the caret.\n */\nexport function usePastePills({\n threshold,\n heldPastes: controlledHeldPastes,\n onHeldPastesChange,\n}: UsePastePillsOptions = {}): UsePastePillsResult {\n const [heldPastes, setHeldPastes] = useControllableState<HeldPaste[]>(\n controlledHeldPastes,\n [],\n onHeldPastesChange,\n );\n\n /*\n * A counter rather than `crypto.randomUUID()` or an index.\n *\n * An index is not an id — removing the first pill renumbers the rest, and a host\n * keying its DOM on that remounts every pill and loses hover state. A counter in\n * a ref is stable for the life of the component and needs no platform API that a\n * server renderer might lack.\n */\n const nextId = useRef(0);\n\n const hold = useCallback(\n (text: string): string => {\n /*\n * Skip any id the list already holds. A controlled list can arrive seeded\n * (restored drafts, an agent attaching a paste) before this counter has\n * counted anything, and minting `paste-1` beside an existing `paste-1` gives\n * two pills one id — expanding either then takes both.\n */\n let id: string;\n do {\n nextId.current += 1;\n id = `paste-${nextId.current}`;\n } while (heldPastes.some((p) => p.id === id));\n\n setHeldPastes((current) => [...current, { id, text }]);\n\n return id;\n },\n [heldPastes, setHeldPastes],\n );\n\n const handlePaste = useCallback(\n (event: PasteEventLike): boolean => {\n if (!threshold || threshold <= 0) return false;\n\n const text = event.clipboardData?.getData(\"text/plain\") ?? \"\";\n\n // Below the threshold, decline WITHOUT touching the event. A host calling\n // this from inside its own handler has to be able to carry on as if the hook\n // were not there.\n if (text.length < threshold) return false;\n\n event.preventDefault();\n hold(text);\n\n return true;\n },\n [threshold, hold],\n );\n\n const expand = useCallback(\n (id: string): string | undefined => {\n const found = heldPastes.find((p) => p.id === id);\n\n if (found === undefined) return undefined;\n\n setHeldPastes((current) => current.filter((p) => p.id !== id));\n\n return found.text;\n },\n [heldPastes, setHeldPastes],\n );\n\n const remove = useCallback(\n (id: string) => setHeldPastes((current) => current.filter((p) => p.id !== id)),\n [setHeldPastes],\n );\n\n const clear = useCallback(() => setHeldPastes([]), [setHeldPastes]);\n\n return { heldPastes, handlePaste, hold, expand, remove, clear };\n}\n","import { useEffect, useState, type ReactNode } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Popover } from \"../Popover\";\nimport type { ComposerPasteClassNames, ComposerPastePreview } from \"./PastePills.types\";\n\n/**\n * Thousands separators, written out rather than left to `toLocaleString()`.\n *\n * The number exists so someone can size the paste at a glance, and `2,036` sizes\n * faster than `2036`. It is not left to the runtime locale because the label beside\n * it (\"Pasted text\") is not localised either, so a locale-formatted number next to\n * an English noun would be half a translation.\n */\nexport function withSeparators(n: number): string {\n return String(n).replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n}\n\n/** First and last N characters, middle elided. The ends say WHICH paste this is. */\nexport function endsOf(text: string, chars: number): string {\n if (text.length <= chars * 2) return text;\n\n return `${text.slice(0, chars)} … ${text.slice(-chars)}`;\n}\n\n/** The most a text pill's label shows, counted in code points, ellipsis included. */\nexport const TEXT_PILL_LABEL_MAX = 80;\n\n/**\n * A host-supplied text pill label as it may be drawn: one line of plain text.\n *\n * Whitespace, C0/C1 control characters and U+FFFC (the pill marker character)\n * each become a space, runs collapse to one, the ends are trimmed, and anything\n * past `TEXT_PILL_LABEL_MAX` is cut with an ellipsis, so a label cannot reflow the\n * message, smuggle a marker, or swallow the composer. It is rendered as a React\n * text node, never as HTML. `null` when there is nothing left to show, which\n * means the generic `Pasted text · N characters` is drawn instead.\n *\n * Checked by code point rather than with a regex so the source carries no\n * escape sequences (see the envelope rule on escapes).\n */\nexport function textPillLabel(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n let out = \"\";\n let pendingSpace = false;\n for (const ch of raw) {\n const c = ch.codePointAt(0)!;\n const blank = c < 0x20 || (c >= 0x7f && c <= 0x9f) || c === 0xfffc || ch.trim() === \"\";\n if (blank) {\n pendingSpace = out.length > 0;\n continue;\n }\n if (pendingSpace) out += \" \";\n pendingSpace = false;\n out += ch;\n }\n if (out === \"\") return null;\n const points = Array.from(out);\n return points.length > TEXT_PILL_LABEL_MAX\n ? `${points.slice(0, TEXT_PILL_LABEL_MAX - 1).join(\"\").trimEnd()}…`\n : out;\n}\n\nconst PILL_BASE =\n \"inline-flex select-none items-center rounded-md px-2 py-0.5 text-xs leading-5 transition-colors\";\nconst TEXT_PILL =\n \"cursor-pointer bg-[color:var(--fancy-surface-muted,var(--color-zinc-100))] text-zinc-700 hover:bg-zinc-200 dark:bg-[color:var(--fancy-surface-muted-dark,var(--color-zinc-800))] dark:text-zinc-200 dark:hover:bg-zinc-700\";\nconst IMAGE_PILL =\n \"bg-rose-100 font-medium text-rose-600 dark:bg-rose-500/20 dark:text-rose-300\";\n/** Merged onto the Popover panel's own defaults: tighter padding for a preview. */\nconst PREVIEW_BASE = \"max-w-xs whitespace-pre-wrap break-all p-2 text-xs\";\n\n/**\n * An image's thumbnail, made from the File only while the preview is open.\n *\n * If the image cannot be shown — a Content-Security-Policy without `blob:` in\n * `img-src` is the usual reason — the label is shown instead. A broken `<img>`\n * with an empty `alt` renders as nothing at all, which is how a preview ends up\n * as an empty box.\n */\nfunction ImageThumb({ file, label }: { file: File; label: string }) {\n const [url, setUrl] = useState<string | null>(null);\n const [failed, setFailed] = useState(false);\n\n useEffect(() => {\n if (typeof URL.createObjectURL !== \"function\") return;\n const made = URL.createObjectURL(file);\n setUrl(made);\n setFailed(false);\n return () => URL.revokeObjectURL(made);\n }, [file]);\n\n return url && !failed ? (\n <img\n src={url}\n alt={label}\n onError={() => setFailed(true)}\n className=\"block max-h-40 max-w-[16rem] rounded\"\n />\n ) : (\n <span>{label}</span>\n );\n}\n\ninterface InlinePillProps {\n preview: ComposerPastePreview;\n previewChars: number;\n renderPastePreview?: (preview: ComposerPastePreview) => ReactNode;\n classNames?: ComposerPasteClassNames;\n disabled: boolean;\n onExpand: (id: string) => void;\n}\n\n/**\n * One pill inside the message, portalled by `Composer` into a placeholder the\n * editor made. Internal — its own file so its props are not read as `Composer`'s.\n *\n * The preview is a hover `Popover` (portalled, so the scrolling input cannot clip\n * it), and it opens on FOCUS too, so a keyboard user reaches the same preview. It\n * was a `Tooltip` until 5.51.0; a tooltip is for a short label, not an image.\n */\nexport function InlinePill({\n preview,\n previewChars,\n renderPastePreview,\n classNames,\n disabled,\n onExpand,\n}: InlinePillProps) {\n const [open, setOpen] = useState(false);\n const id = preview.kind === \"text\" ? preview.paste.id : preview.image.id;\n const content = (\n <span data-react-fancy-composer-paste-pill-preview={id}>\n {renderPastePreview?.(preview) ??\n (preview.kind === \"text\" ? (\n endsOf(preview.paste.text, previewChars)\n ) : (\n <ImageThumb file={preview.image.file} label={preview.image.label} />\n ))}\n </span>\n );\n const focusOpen = {\n onFocus: () => setOpen(true),\n onBlur: () => setOpen(false),\n };\n\n const textLabel = preview.kind === \"text\" ? textPillLabel(preview.paste.label) : null;\n const textSize =\n preview.kind === \"text\" ? `${withSeparators(preview.paste.text.length)} characters` : \"\";\n\n const pill =\n preview.kind === \"image\" ? (\n <span\n data-react-fancy-composer-image-pill={id}\n role=\"img\"\n tabIndex={0}\n aria-label={preview.image.label}\n {...focusOpen}\n className={cn(PILL_BASE, IMAGE_PILL, classNames?.pill, classNames?.imagePill)}\n >\n {preview.image.label}\n </span>\n ) : (\n <button\n type=\"button\"\n data-react-fancy-composer-paste-pill={id}\n onClick={() => onExpand(id)}\n disabled={disabled}\n aria-label={\n textLabel === null\n ? `Insert this pasted text, ${textSize}`\n : `Insert this pasted text: ${textLabel}, ${textSize}`\n }\n {...focusOpen}\n className={cn(PILL_BASE, TEXT_PILL, classNames?.pill, classNames?.textPill)}\n >\n {textLabel ?? `Pasted text · ${textSize}`}\n </button>\n );\n\n return (\n <Popover hover open={open} onOpenChange={setOpen} placement=\"top\">\n <Popover.Trigger>{pill}</Popover.Trigger>\n <Popover.Content className={cn(PREVIEW_BASE, classNames?.preview)}>\n {content}\n </Popover.Content>\n </Popover>\n );\n}\n","import type { HeldPaste } from \"./use-paste-pills\";\n\n/**\n * An image pasted into a `Composer` and held as a pill.\n *\n * `label` is stored rather than derived because the number in it is the order of\n * ARRIVAL: \"Pasted image 2\" must stay 2 after image 1 is deleted, and nothing left\n * in the list could recompute that.\n */\nexport interface HeldImage {\n id: string;\n file: File;\n label: string;\n}\n\n/**\n * U+FFFC OBJECT REPLACEMENT CHARACTER — Unicode's own \"an embedded object sits\n * here\". A marker is the id wrapped in a pair of them.\n *\n * Why the message carries a marker at all: with inline placement the message\n * ITSELF is the record of what is attached and where, so there is one answer to\n * \"what am I sending?\" rather than a text plus a parallel list that can disagree\n * the moment someone backspaces a pill. This is the MOIC estate's design for their\n * own composer, and the reason they withdrew from the beside-the-input layout.\n *\n * Only a marker whose id the composer actually holds is a pill; anything else is\n * left as text, so a stray U+FFFC in pasted content cannot invent an attachment.\n */\nexport const PILL_MARK = \"\\uFFFC\";\n\nconst MARKER = /\\uFFFC([^\\uFFFC\\n]+)\\uFFFC/g;\n\n/** The marker for a held paste or image, for a host or agent writing `value` itself. */\nexport function pasteMarker(id: string): string {\n return `${PILL_MARK}${id}${PILL_MARK}`;\n}\n\nexport type ValueSegment =\n | { type: \"text\"; text: string }\n | { type: \"pill\"; id: string };\n\n/** Split a value into text and pills. Markers for ids not in `known` stay text. */\nexport function segmentValue(value: string, known: ReadonlySet<string>): ValueSegment[] {\n const out: ValueSegment[] = [];\n let last = 0;\n\n for (const match of value.matchAll(MARKER)) {\n const id = match[1];\n if (!known.has(id)) continue;\n\n const start = match.index ?? 0;\n if (start > last) out.push({ type: \"text\", text: value.slice(last, start) });\n out.push({ type: \"pill\", id });\n last = start + match[0].length;\n }\n\n if (last < value.length) out.push({ type: \"text\", text: value.slice(last) });\n\n return out;\n}\n\n/** The id of every marker the value contains, in order, held or not. */\nexport function markedIds(value: string): string[] {\n return Array.from(value.matchAll(MARKER), (m) => m[1]);\n}\n\n/**\n * What actually gets sent: every text pill replaced by its full text, every image\n * pill by `[Pasted image N]` so the reader of the message can see where the image\n * sat. The images themselves go to `onSubmit`'s second argument.\n */\nexport function expandMarkers(\n value: string,\n pastes: readonly HeldPaste[],\n images: readonly HeldImage[],\n): string {\n const text = new Map(pastes.map((p) => [p.id, p.text]));\n const image = new Map(images.map((i) => [i.id, `[${i.label}]`]));\n\n return value.replace(MARKER, (whole, id: string) => text.get(id) ?? image.get(id) ?? whole);\n}\n","import { useCallback, useMemo, useRef, useState, type ReactNode, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useControllableState } from \"../../hooks/use-controllable-state\";\nimport { usePastePills, type HeldPaste } from \"./use-paste-pills\";\nimport { InlinePill } from \"./InlinePill\";\nimport type { InlinePasteEditorHandle, PillToInsert } from \"./InlinePasteEditor\";\nimport { expandMarkers, markedIds, type HeldImage } from \"./paste-markers\";\nimport type { ComposerPasteClassNames, ComposerPastePreview } from \"./PastePills.types\";\n\nexport interface UseInlinePasteOptions {\n pasteThreshold?: number;\n pasteImages?: boolean;\n previewChars: number;\n renderPastePreview?: (preview: ComposerPastePreview) => ReactNode;\n classNames?: ComposerPasteClassNames;\n disabled: boolean;\n heldPastes?: HeldPaste[];\n onHeldPastesChange?: (pastes: HeldPaste[]) => void;\n heldImages?: HeldImage[];\n onHeldImagesChange?: (images: HeldImage[]) => void;\n editorRef: RefObject<InlinePasteEditorHandle | null>;\n /**\n * Give a text pill a line to itself. Default `true`; a single-line field\n * (`Input`) has no lines to give, so its pills sit in the text.\n */\n blockText?: boolean;\n}\n\n/**\n * Everything inline paste pills need besides the editor itself: the held pastes\n * and images, deciding what a paste becomes, dropping a pill's hold when it is\n * deleted from the message, rendering the pills into the editor, and expanding\n * them on send.\n *\n * Shared by `Composer`, `PromptInput` and `Input` so they cannot disagree about\n * what a pill means. The rule that must not drift is the one `expand` and `imagesIn`\n * carry: a send with pills still closed carries everything they hold.\n */\nexport function useInlinePaste({\n pasteThreshold,\n pasteImages = false,\n previewChars,\n renderPastePreview,\n classNames,\n disabled,\n heldPastes: controlledHeldPastes,\n onHeldPastesChange,\n heldImages: controlledHeldImages,\n onHeldImagesChange,\n editorRef,\n blockText = true,\n}: UseInlinePasteOptions) {\n const pills = usePastePills({\n threshold: pasteThreshold,\n heldPastes: controlledHeldPastes,\n onHeldPastesChange,\n });\n const heldPastes = pills.heldPastes;\n const [heldImages, setHeldImages] = useControllableState<HeldImage[]>(\n controlledHeldImages,\n [],\n onHeldImagesChange,\n );\n const imageCount = useRef(0);\n\n const known = useMemo(\n () => new Set([...heldPastes.map((p) => p.id), ...heldImages.map((i) => i.id)]),\n [heldPastes, heldImages],\n );\n\n const holdImage = useCallback(\n (file: File): string => {\n let id: string;\n do {\n imageCount.current += 1;\n id = `image-${imageCount.current}`;\n } while (heldImages.some((i) => i.id === id));\n\n const image = { id, file, label: `Pasted image ${imageCount.current}` };\n setHeldImages((current) => [...current, image]);\n\n return id;\n },\n [heldImages, setHeldImages],\n );\n\n /** What a paste becomes. `null` means \"just text\". */\n const decidePaste = useCallback(\n (data: DataTransfer | null): PillToInsert[] | null => {\n const text = data?.getData(\"text/plain\") ?? \"\";\n\n // Only a PURE image paste: a clipboard with text as well usually carries a\n // picture OF that text (copying from a document), and holding it would turn\n // every pasted sentence into a screenshot of the sentence.\n if (pasteImages && text === \"\") {\n const files = Array.from(data?.files ?? []).filter((f) =>\n f.type.startsWith(\"image/\"),\n );\n if (files.length > 0) {\n return files.map((file) => ({ id: holdImage(file), block: false }));\n }\n }\n\n if (pasteThreshold && pasteThreshold > 0 && text.length >= pasteThreshold) {\n return [{ id: pills.hold(text), block: blockText }];\n }\n\n return null;\n },\n [pasteImages, pasteThreshold, holdImage, pills, blockText],\n );\n\n /*\n * The message is the record of what is attached. A pill backspaced out of it is\n * no longer attached, so its held entry goes too — otherwise state would say\n * \"attached\" about something the message no longer contains.\n */\n const prune = useCallback(\n (next: string) => {\n const present = new Set(markedIds(next));\n for (const paste of heldPastes) if (!present.has(paste.id)) pills.remove(paste.id);\n if (heldImages.some((i) => !present.has(i.id))) {\n setHeldImages((current) => current.filter((i) => present.has(i.id)));\n }\n },\n [heldPastes, heldImages, pills, setHeldImages],\n );\n\n const [hosts, setHosts] = useState<ReadonlyMap<string, HTMLElement>>(new Map());\n const onHostsChange = useCallback((next: ReadonlyMap<string, HTMLElement>) => {\n setHosts((prev) => {\n if (prev.size === next.size && [...next].every(([id, el]) => prev.get(id) === el)) {\n return prev;\n }\n return next;\n });\n }, []);\n\n /** Click a text pill and its full text takes the pill's place. */\n const expandPill = useCallback(\n (id: string) => {\n const text = pills.expand(id);\n if (text === undefined) return;\n editorRef.current?.replacePill(id, text);\n },\n [pills, editorRef],\n );\n\n /** The value as it is sent: every text pill expanded, every image marked. */\n const expand = useCallback(\n (value: string) => expandMarkers(value, heldPastes, heldImages),\n [heldPastes, heldImages],\n );\n\n /** The images the value still contains, in message order. */\n const imagesIn = useCallback(\n (value: string) =>\n markedIds(value).flatMap((id) => heldImages.filter((i) => i.id === id)),\n [heldImages],\n );\n\n const clear = useCallback(() => {\n pills.clear();\n setHeldImages([]);\n }, [pills, setHeldImages]);\n\n /** The pills, portalled into the placeholders the editor made. Render this anywhere. */\n const portals = Array.from(hosts, ([id, host]) => {\n const paste = heldPastes.find((p) => p.id === id);\n const image = paste ? undefined : heldImages.find((i) => i.id === id);\n const preview: ComposerPastePreview | null = paste\n ? { kind: \"text\", paste }\n : image\n ? { kind: \"image\", image }\n : null;\n\n return preview\n ? createPortal(\n <InlinePill\n preview={preview}\n previewChars={previewChars}\n renderPastePreview={renderPastePreview}\n classNames={classNames}\n disabled={disabled}\n onExpand={expandPill}\n />,\n host,\n id,\n )\n : null;\n });\n\n return {\n pills,\n heldPastes,\n heldImages,\n known,\n decidePaste,\n prune,\n onHostsChange,\n expand,\n imagesIn,\n clear,\n portals,\n };\n}\n","import {\n forwardRef,\n useCallback,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n} from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { PILL_MARK, pasteMarker, segmentValue } from \"./paste-markers\";\n\n/** The attribute on the placeholder span a pill is portalled into. */\nexport const HOST_ATTR = \"data-react-fancy-composer-paste-host\";\n\n/** What a paste becomes, as decided by `Composer`. `block` pills get their own line. */\nexport interface PillToInsert {\n id: string;\n block: boolean;\n}\n\nexport interface InlinePasteEditorHandle {\n focus(): void;\n /** Swap a pill for plain text, where it sits. */\n replacePill(id: string, text: string): void;\n /**\n * Replace the whole value and put the caret at `caret` (an offset into the\n * value). For a host that edits text itself — `PromptInput`'s `/` and `@`\n * pickers — where rebuilding from `value` alone would lose the caret.\n */\n setValue(value: string, caret: number): void;\n}\n\ninterface InlinePasteEditorProps {\n value: string;\n /** Ids the composer holds. A marker for anything else stays text. */\n known: ReadonlySet<string>;\n /** `caret` is the caret's offset into `value`, or `value.length` if it is elsewhere. */\n onChange(value: string, caret: number): void;\n onSubmit(): void;\n /**\n * Which key sends. `\"enter\"` (default): Enter sends, Shift+Enter is a newline.\n * `\"mod-enter\"`: Ctrl/⌘+Enter sends and a plain Enter is a newline.\n */\n submitKey?: \"enter\" | \"mod-enter\";\n /** Runs BEFORE the editor's own key handling; `preventDefault()` to claim the key. */\n onKeyDown?(e: React.KeyboardEvent<HTMLDivElement>): void;\n placeholderClassName?: string;\n /** Height in px past which the input scrolls. Defaults to the class's max height. */\n maxHeight?: number;\n /** Return the pills a paste becomes, or null to insert its text as typed. */\n onPaste(data: DataTransfer | null): PillToInsert[] | null;\n /** Every pill placeholder currently in the editor, for the composer to portal into. */\n onHostsChange(hosts: ReadonlyMap<string, HTMLElement>): void;\n placeholder: string;\n disabled: boolean;\n className?: string;\n /**\n * `false` makes it a single-line field, as `Input` uses it: Enter always\n * submits, and a newline in pasted text becomes a space, as a browser does for\n * an `<input>`. A held paste keeps its newlines; it is only the field that has\n * one line. Default `true`.\n */\n multiline?: boolean;\n /** The editable surface's id, so a host can find it. */\n id?: string;\n /** Names the textbox for assistive tech; a `<div>` cannot be the target of a `<label>`. */\n ariaLabelledBy?: string;\n ariaInvalid?: boolean;\n style?: React.CSSProperties;\n}\n\n/**\n * Walk a node's children back into a value string.\n *\n * `<br>` as the LAST child of its parent is filler — browsers put one in an empty\n * line, and this editor puts one after a trailing newline so the caret has a line\n * to sit on — so it counts for nothing. Block elements a browser invents count as\n * a line break before them. Non-breaking spaces become spaces: a browser inserts\n * them for typed spaces it fears would collapse, not because anyone asked.\n */\nfunction serialize(parent: Node, keep: (id: string) => boolean): string {\n let out = \"\";\n const children = Array.from(parent.childNodes);\n\n children.forEach((node, i) => {\n if (node.nodeType === Node.TEXT_NODE) {\n out += (node.textContent ?? \"\").replace(/\\u00A0/g, \" \");\n return;\n }\n if (!(node instanceof HTMLElement)) return;\n\n const id = node.getAttribute(HOST_ATTR);\n if (id !== null) {\n if (keep(id)) out += pasteMarker(id);\n return;\n }\n if (node.tagName === \"BR\") {\n if (i !== children.length - 1) out += \"\\n\";\n return;\n }\n if (/^(DIV|P)$/.test(node.tagName) && out.length > 0 && !out.endsWith(\"\\n\")) {\n out += \"\\n\";\n }\n out += serialize(node, keep);\n });\n\n return out;\n}\n\nfunction makeHost(id: string): HTMLElement {\n const host = document.createElement(\"span\");\n host.setAttribute(\"contenteditable\", \"false\");\n host.setAttribute(HOST_ATTR, id);\n host.className = \"inline-block align-baseline\";\n return host;\n}\n\n/** A value ending in a newline needs a `<br>` after it, or the caret has no line to sit on. */\nfunction ensureTrailingBreak(root: HTMLElement, value: string) {\n const last = root.lastChild;\n const hasBreak = last instanceof HTMLElement && last.tagName === \"BR\";\n\n if (value.endsWith(\"\\n\") && !hasBreak) root.append(document.createElement(\"br\"));\n if (!value.endsWith(\"\\n\") && hasBreak && value.length > 0) last.remove();\n}\n\nfunction placeCaretAfter(node: Node) {\n const selection = window.getSelection();\n if (!selection) return;\n\n const range = document.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\n/**\n * Put the caret `offset` characters into the serialised value. Walks the shape\n * `render` produces — text nodes, pill hosts (each worth its marker's length) and\n * a trailing `<br>` — so it is only called straight after a render.\n */\nfunction placeCaretAtOffset(root: HTMLElement, offset: number, keep: (id: string) => boolean) {\n const selection = window.getSelection();\n if (!selection) return;\n\n const range = document.createRange();\n let remaining = offset;\n let placed = false;\n\n for (const node of Array.from(root.childNodes)) {\n if (node.nodeType === Node.TEXT_NODE) {\n const length = node.textContent?.length ?? 0;\n if (remaining <= length) {\n range.setStart(node, remaining);\n placed = true;\n break;\n }\n remaining -= length;\n continue;\n }\n const id = node instanceof HTMLElement ? node.getAttribute(HOST_ATTR) : null;\n if (id !== null && keep(id)) {\n const length = pasteMarker(id).length;\n if (remaining < length) {\n range.setStartAfter(node);\n placed = true;\n break;\n }\n remaining -= length;\n }\n }\n\n if (!placed) {\n range.selectNodeContents(root);\n range.collapse(false);\n const last = root.lastChild;\n if (last instanceof HTMLElement && last.tagName === \"BR\") range.setStartBefore(last);\n }\n range.collapse(true);\n selection.removeAllRanges();\n selection.addRange(range);\n}\n\n/**\n * The plain-text-plus-pills surface behind `Composer`'s inline placement.\n *\n * The DOM is the source of truth WHILE TYPING and `value` is its serialisation;\n * the DOM is rebuilt from `value` only when `value` changes from outside (a send,\n * a host, an agent). Rebuilding on every keystroke would throw the caret away.\n *\n * Every insertion is done here by hand, never by the browser: a paste is always\n * intercepted, so no foreign HTML ever lands in the editor, and Enter is handled\n * so a browser never invents a `<div>` per line.\n */\nexport const InlinePasteEditor = forwardRef<InlinePasteEditorHandle, InlinePasteEditorProps>(\n function InlinePasteEditor(\n {\n value,\n known,\n onChange,\n onSubmit,\n onPaste,\n onHostsChange,\n placeholder,\n disabled,\n className,\n submitKey = \"enter\",\n onKeyDown,\n placeholderClassName,\n maxHeight,\n multiline = true,\n id,\n ariaLabelledBy,\n ariaInvalid,\n style,\n },\n ref,\n ) {\n const rootRef = useRef<HTMLDivElement>(null);\n /** The last value this editor produced or rendered. Anything else came from outside. */\n const lastValue = useRef<string | null>(null);\n /**\n * Ids inserted here whose hold has not reached `known` yet. A pill is held and\n * placed in the same event, and the composer's state lands a render later.\n */\n const pending = useRef(new Set<string>());\n const knownRef = useRef(known);\n knownRef.current = known;\n\n const keep = useCallback(\n (id: string) => knownRef.current.has(id) || pending.current.has(id),\n [],\n );\n\n const reportHosts = useCallback(() => {\n const root = rootRef.current;\n if (!root) return;\n\n const hosts = new Map<string, HTMLElement>();\n root.querySelectorAll<HTMLElement>(`[${HOST_ATTR}]`).forEach((el) => {\n const id = el.getAttribute(HOST_ATTR)!;\n if (keep(id)) hosts.set(id, el);\n });\n onHostsChange(hosts);\n }, [keep, onHostsChange]);\n\n /** The caret's offset into the serialised value, or its length if the caret is elsewhere. */\n const caretOffset = useCallback(\n (whole: string): number => {\n const root = rootRef.current;\n const selection = window.getSelection();\n if (!root || !selection || selection.rangeCount === 0) return whole.length;\n\n const range = selection.getRangeAt(0);\n if (!root.contains(range.endContainer)) return whole.length;\n\n const head = document.createRange();\n head.selectNodeContents(root);\n head.setEnd(range.endContainer, range.endOffset);\n return serialize(head.cloneContents(), keep).length;\n },\n [keep],\n );\n\n /** Read the DOM back into a value and tell the composer. */\n const emit = useCallback(() => {\n const root = rootRef.current;\n if (!root) return;\n\n const next = serialize(root, keep);\n ensureTrailingBreak(root, next);\n reportHosts();\n\n // Reported even when the value is unchanged: a host reading the caret (a\n // `/` picker) needs to hear about it.\n lastValue.current = next;\n onChange(next, caretOffset(next));\n }, [keep, onChange, reportHosts, caretOffset]);\n\n /** Rebuild the DOM from a value. Throws the caret away; callers put it back. */\n const render = useCallback(\n (next: string) => {\n const root = rootRef.current;\n if (!root) return;\n\n root.replaceChildren();\n for (const segment of segmentValue(next, knownRef.current)) {\n if (segment.type === \"text\") {\n root.append(document.createTextNode(segment.text));\n } else {\n root.append(makeHost(segment.id));\n }\n }\n ensureTrailingBreak(root, next);\n lastValue.current = next;\n reportHosts();\n },\n [reportHosts],\n );\n\n /** The caret's range, or the end of the editor if the caret is elsewhere. */\n const caret = useCallback((): Range => {\n const root = rootRef.current!;\n const selection = window.getSelection();\n\n if (selection && selection.rangeCount > 0) {\n const range = selection.getRangeAt(0);\n if (root.contains(range.commonAncestorContainer)) return range;\n }\n\n const range = document.createRange();\n range.selectNodeContents(root);\n range.collapse(false);\n const last = root.lastChild;\n if (last instanceof HTMLElement && last.tagName === \"BR\") {\n range.setStartBefore(last);\n range.collapse(true);\n }\n return range;\n }, []);\n\n /** Replace the selection with `nodes` and leave the caret after them. */\n const insert = useCallback(\n (build: (before: string, after: string) => Node[]) => {\n const root = rootRef.current!;\n const range = caret();\n range.deleteContents();\n\n const head = document.createRange();\n head.selectNodeContents(root);\n head.setEnd(range.startContainer, range.startOffset);\n const tail = document.createRange();\n tail.selectNodeContents(root);\n tail.setStart(range.endContainer, range.endOffset);\n\n const nodes = build(\n serialize(head.cloneContents(), () => true),\n serialize(tail.cloneContents(), () => true),\n );\n if (nodes.length === 0) return;\n\n const fragment = document.createDocumentFragment();\n nodes.forEach((n) => fragment.append(n));\n range.insertNode(fragment);\n placeCaretAfter(nodes[nodes.length - 1]);\n emit();\n },\n [caret, emit],\n );\n\n const insertText = useCallback(\n (text: string) => insert(() => (text ? [document.createTextNode(text)] : [])),\n [insert],\n );\n\n /*\n * Rebuild from `value` when it changed from outside — or when `known` now\n * disagrees with the pills on screen, e.g. a host set a marker and then the\n * paste it names. Never on our own edits: that would discard the caret.\n */\n useLayoutEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n for (const id of pending.current) if (known.has(id)) pending.current.delete(id);\n\n const wanted = segmentValue(value, known)\n .flatMap((s) => (s.type === \"pill\" ? [s.id] : []))\n .join(PILL_MARK);\n const onScreen = Array.from(root.querySelectorAll(`[${HOST_ATTR}]`))\n .map((el) => el.getAttribute(HOST_ATTR))\n .filter((id): id is string => id !== null && keep(id))\n .join(PILL_MARK);\n\n if (value === lastValue.current && wanted === onScreen) return;\n\n render(value);\n }, [value, known, keep, render]);\n\n useImperativeHandle(\n ref,\n () => ({\n focus() {\n const root = rootRef.current;\n if (!root) return;\n root.focus();\n const range = caret();\n const selection = window.getSelection();\n selection?.removeAllRanges();\n selection?.addRange(range);\n },\n replacePill(id, text) {\n const root = rootRef.current;\n const host = Array.from(\n root?.querySelectorAll(`[${HOST_ATTR}]`) ?? [],\n ).find((el) => el.getAttribute(HOST_ATTR) === id);\n if (!root || !host) return;\n\n const node = document.createTextNode(text);\n host.replaceWith(node);\n root.focus();\n placeCaretAfter(node);\n emit();\n },\n setValue(next, offset) {\n const root = rootRef.current;\n if (!root) return;\n\n render(next);\n root.focus();\n placeCaretAtOffset(root, offset, keep);\n emit();\n },\n }),\n [caret, emit, render, keep],\n );\n\n const handlePaste = (e: React.ClipboardEvent<HTMLDivElement>) => {\n // ALWAYS intercepted: a browser left to paste into a contenteditable inserts\n // the clipboard's HTML, styles and all.\n e.preventDefault();\n if (disabled) return;\n\n const pills = onPaste(e.clipboardData);\n\n if (pills === null) {\n const text = (e.clipboardData?.getData(\"text/plain\") ?? \"\").replace(/\\r\\n?/g, \"\\n\");\n insertText(multiline ? text : text.replace(/\\n+/g, \" \"));\n return;\n }\n\n for (const { id } of pills) pending.current.add(id);\n\n insert((before, after) => {\n const nodes: Node[] = [];\n\n for (const { id, block } of pills) {\n if (block) {\n // A text pill gets a line to itself: a newline above unless it is\n // already at the start of one, and below unless one follows.\n const precededByBreak =\n nodes.length === 0\n ? before === \"\" || before.endsWith(\"\\n\")\n : nodes[nodes.length - 1].textContent === \"\\n\";\n if (!precededByBreak) nodes.push(document.createTextNode(\"\\n\"));\n nodes.push(makeHost(id));\n nodes.push(document.createTextNode(\"\\n\"));\n } else {\n nodes.push(makeHost(id));\n }\n }\n\n // The trailing newline of a block pill is redundant if one already follows.\n const last = nodes[nodes.length - 1];\n if (last.textContent === \"\\n\" && after.startsWith(\"\\n\")) nodes.pop();\n\n return nodes;\n });\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n if (e.key !== \"Enter\" || e.nativeEvent.isComposing) return;\n\n e.preventDefault();\n const sends =\n !multiline || (submitKey === \"mod-enter\" ? e.ctrlKey || e.metaKey : !e.shiftKey);\n if (sends) {\n onSubmit();\n } else {\n insertText(\"\\n\");\n }\n };\n\n return (\n <div className=\"relative\">\n {value === \"\" && (\n <span\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute left-4 top-3 text-sm text-zinc-400\",\n placeholderClassName,\n )}\n >\n {placeholder}\n </span>\n )}\n <div\n ref={rootRef}\n id={id}\n data-react-fancy-composer-input=\"\"\n role=\"textbox\"\n aria-multiline={multiline}\n aria-labelledby={ariaLabelledBy}\n aria-invalid={ariaInvalid || undefined}\n aria-placeholder={placeholder}\n aria-disabled={disabled || undefined}\n contentEditable={!disabled}\n suppressContentEditableWarning\n onInput={emit}\n onPaste={handlePaste}\n onKeyDown={handleKeyDown}\n style={maxHeight === undefined ? style : { ...style, maxHeight }}\n className={cn(\n \"max-h-72 min-h-[4.5rem] w-full overflow-y-auto whitespace-pre-wrap break-words bg-transparent px-4 pt-3 text-sm outline-none\",\n className,\n )}\n />\n </div>\n );\n },\n);\n","import { useEffect, useRef } from \"react\";\n\nexport interface PastedFilesInputProps {\n /** The form field name the files are submitted under. */\n name: string;\n /** The files to submit, in the order the message holds them. */\n files: readonly File[];\n /** Associate with a `<form id>` elsewhere in the document, as `<input form>` does. */\n form?: string;\n}\n\n/**\n * A hidden `<input type=\"file\">` carrying the files pasted into a field, so a\n * plain `<form>` submits them with everything else.\n *\n * A pasted file is not in any form field: the clipboard hands it to the paste\n * handler and nowhere else. Held as a pill, it is attached as far as the person can\n * see, and a native submit would then post the text without it. A file input is\n * the one element a form posts files from, and its `files` can be set from a\n * `DataTransfer`, so the pills keep it in step: delete a pill and its file leaves\n * the input too.\n *\n * Hidden rather than visually hidden: `hidden` keeps it out of the tab order and\n * the accessibility tree, where the pills already represent it, and does not stop\n * a form submitting it.\n */\nexport function PastedFilesInput({ name, files, form }: PastedFilesInputProps) {\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n const el = ref.current;\n // No DataTransfer (a server render, an old engine): nothing can be set, and\n // the host still has the files from its own state.\n if (!el || typeof DataTransfer === \"undefined\") return;\n\n const transfer = new DataTransfer();\n for (const file of files) transfer.items.add(file);\n el.files = transfer.files;\n }, [files]);\n\n return (\n <input\n ref={ref}\n type=\"file\"\n name={name}\n form={form}\n multiple\n hidden\n tabIndex={-1}\n data-react-fancy-pasted-files={name}\n />\n );\n}\n"]}
package/dist/composer.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkTQGRXJ74_cjs = require('./chunk-TQGRXJ74.cjs');
4
- var chunkQNQNGARW_cjs = require('./chunk-QNQNGARW.cjs');
3
+ var chunk7FYRFNPX_cjs = require('./chunk-7FYRFNPX.cjs');
4
+ var chunkHFK5SBNM_cjs = require('./chunk-HFK5SBNM.cjs');
5
5
  require('./chunk-MKGWHSNV.cjs');
6
6
  require('./chunk-J2DI6RMR.cjs');
7
7
  require('./chunk-MKHYENKR.cjs');
@@ -15,11 +15,11 @@ require('./chunk-ZU5Q77OT.cjs');
15
15
 
16
16
  Object.defineProperty(exports, "Composer", {
17
17
  enumerable: true,
18
- get: function () { return chunkTQGRXJ74_cjs.Composer; }
18
+ get: function () { return chunk7FYRFNPX_cjs.Composer; }
19
19
  });
20
20
  Object.defineProperty(exports, "pasteMarker", {
21
21
  enumerable: true,
22
- get: function () { return chunkQNQNGARW_cjs.pasteMarker; }
22
+ get: function () { return chunkHFK5SBNM_cjs.pasteMarker; }
23
23
  });
24
24
  //# sourceMappingURL=composer.cjs.map
25
25
  //# sourceMappingURL=composer.cjs.map
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { H as HeldImage, C as ComposerPastePreview, a as ComposerPasteClassNames, b as HeldPaste } from './PastePills.types-CDyotkUb.cjs';
4
- export { p as pasteMarker } from './PastePills.types-CDyotkUb.cjs';
3
+ import { H as HeldImage, C as ComposerPastePreview, a as ComposerPasteClassNames, b as HeldPaste } from './PastePills.types-CpXzsuwJ.cjs';
4
+ export { p as pasteMarker } from './PastePills.types-CpXzsuwJ.cjs';
5
5
 
6
6
  interface ComposerSubmitExtras {
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { H as HeldImage, C as ComposerPastePreview, a as ComposerPasteClassNames, b as HeldPaste } from './PastePills.types-CDyotkUb.js';
4
- export { p as pasteMarker } from './PastePills.types-CDyotkUb.js';
3
+ import { H as HeldImage, C as ComposerPastePreview, a as ComposerPasteClassNames, b as HeldPaste } from './PastePills.types-CpXzsuwJ.js';
4
+ export { p as pasteMarker } from './PastePills.types-CpXzsuwJ.js';
5
5
 
6
6
  interface ComposerSubmitExtras {
7
7
  /**
package/dist/composer.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Composer } from './chunk-ELFTEJBT.js';
2
- export { pasteMarker } from './chunk-NILA2LZY.js';
1
+ export { Composer } from './chunk-QSGAFKK2.js';
2
+ export { pasteMarker } from './chunk-YIKXJWO4.js';
3
3
  import './chunk-QTS4Q2NK.js';
4
4
  import './chunk-MQ6VGG62.js';
5
5
  import './chunk-5VMILVWD.js';
@@ -1,23 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  require('./chunk-S3TRSECD.cjs');
4
- var chunkMCQJFMDP_cjs = require('./chunk-MCQJFMDP.cjs');
5
- require('./chunk-X2FC7ODX.cjs');
4
+ var chunkE5UU666U_cjs = require('./chunk-E5UU666U.cjs');
5
+ require('./chunk-3U7PUZLI.cjs');
6
+ require('./chunk-XCZZVRBY.cjs');
7
+ require('./chunk-MXWR3T3N.cjs');
6
8
  require('./chunk-ZU5Q77OT.cjs');
7
9
 
8
10
 
9
11
 
10
12
  Object.defineProperty(exports, "ContentRenderer", {
11
13
  enumerable: true,
12
- get: function () { return chunkMCQJFMDP_cjs.ContentRenderer; }
14
+ get: function () { return chunkE5UU666U_cjs.ContentRenderer; }
13
15
  });
14
16
  Object.defineProperty(exports, "registerExtension", {
15
17
  enumerable: true,
16
- get: function () { return chunkMCQJFMDP_cjs.registerExtension; }
18
+ get: function () { return chunkE5UU666U_cjs.registerExtension; }
17
19
  });
18
20
  Object.defineProperty(exports, "registerExtensions", {
19
21
  enumerable: true,
20
- get: function () { return chunkMCQJFMDP_cjs.registerExtensions; }
22
+ get: function () { return chunkE5UU666U_cjs.registerExtensions; }
21
23
  });
22
24
  //# sourceMappingURL=content-renderer.cjs.map
23
25
  //# sourceMappingURL=content-renderer.cjs.map
@@ -1,7 +1,33 @@
1
1
  import * as react from 'react';
2
- import { R as RenderExtension } from './extensions-6PVd3-vB.cjs';
3
- export { C as ContentSegment, a as RenderExtensionProps, r as registerExtension, b as registerExtensions } from './extensions-6PVd3-vB.cjs';
2
+ import { R as RenderExtension } from './extensions-DiByZIpD.cjs';
3
+ export { C as ContentSegment, a as RenderExtensionProps, r as registerExtension, b as registerExtensions } from './extensions-DiByZIpD.cjs';
4
4
 
5
+ /** What a copy button copies. */
6
+ type ContentCopyKind = "code" | "table";
7
+ /** What is handed to a clipboard writer. */
8
+ interface ContentClipboardPayload {
9
+ kind: ContentCopyKind;
10
+ /**
11
+ * Plain text. For code: exactly the code between the fences, with no
12
+ * language label and no added trailing newline. For a table: TSV (tab
13
+ * between cells, newline between rows, no trailing newline).
14
+ */
15
+ text: string;
16
+ /** The block's sanitised HTML (`<pre>…</pre>` or `<table>…</table>`), for rich paste. */
17
+ html: string;
18
+ }
19
+ /**
20
+ * Writes one copy to the clipboard. Throwing, rejecting, or returning `false`
21
+ * means the copy failed; the failure is announced, never swallowed.
22
+ */
23
+ type ContentClipboardWriter = (payload: ContentClipboardPayload) => void | boolean | Promise<void | boolean>;
24
+ /** Reported through `onCopy` after every copy attempt. */
25
+ interface ContentCopyEvent extends ContentClipboardPayload {
26
+ /** Position of the button among this renderer's copy buttons, in document order. */
27
+ index: number;
28
+ /** Whether the clipboard write succeeded. */
29
+ ok: boolean;
30
+ }
5
31
  interface ContentRendererProps {
6
32
  value: string;
7
33
  format?: "html" | "markdown" | "auto";
@@ -17,11 +43,37 @@ interface ContentRendererProps {
17
43
  * @default false
18
44
  */
19
45
  unsafe?: boolean;
46
+ /**
47
+ * Copy buttons on code blocks and tables. `false` turns them all off; an
48
+ * object turns kinds off individually (`{ table: false }`).
49
+ * @default true
50
+ */
51
+ copyButtons?: boolean | {
52
+ code?: boolean;
53
+ table?: boolean;
54
+ };
55
+ /** Called after every copy attempt, successful or not. */
56
+ onCopy?: (event: ContentCopyEvent) => void;
57
+ /**
58
+ * Host-supplied clipboard writer, for environments where
59
+ * `navigator.clipboard` is unreliable (e.g. a sandboxed Electron window:
60
+ * pass one that calls Electron's `clipboard`). The default writes
61
+ * text/html + text/plain via `ClipboardItem`, falling back to `writeText`.
62
+ */
63
+ clipboardWriter?: ContentClipboardWriter;
64
+ /**
65
+ * The value is still arriving. Holds back an unfinished trailing custom tag
66
+ * (of a registered extension) or code fence, so a partial `<result` or
67
+ * half a code block never flashes as raw text. Set it back to `false` when
68
+ * the stream ends and everything renders.
69
+ * @default false
70
+ */
71
+ streaming?: boolean;
20
72
  }
21
73
 
22
- declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, }: ContentRendererProps): react.JSX.Element;
74
+ declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, copyButtons, onCopy, clipboardWriter, streaming, }: ContentRendererProps): react.JSX.Element;
23
75
  declare namespace ContentRenderer {
24
76
  var displayName: string;
25
77
  }
26
78
 
27
- export { ContentRenderer, type ContentRendererProps, RenderExtension };
79
+ export { type ContentClipboardPayload, type ContentClipboardWriter, type ContentCopyEvent, type ContentCopyKind, ContentRenderer, type ContentRendererProps, RenderExtension };
@@ -1,7 +1,33 @@
1
1
  import * as react from 'react';
2
- import { R as RenderExtension } from './extensions-6PVd3-vB.js';
3
- export { C as ContentSegment, a as RenderExtensionProps, r as registerExtension, b as registerExtensions } from './extensions-6PVd3-vB.js';
2
+ import { R as RenderExtension } from './extensions-DiByZIpD.js';
3
+ export { C as ContentSegment, a as RenderExtensionProps, r as registerExtension, b as registerExtensions } from './extensions-DiByZIpD.js';
4
4
 
5
+ /** What a copy button copies. */
6
+ type ContentCopyKind = "code" | "table";
7
+ /** What is handed to a clipboard writer. */
8
+ interface ContentClipboardPayload {
9
+ kind: ContentCopyKind;
10
+ /**
11
+ * Plain text. For code: exactly the code between the fences, with no
12
+ * language label and no added trailing newline. For a table: TSV (tab
13
+ * between cells, newline between rows, no trailing newline).
14
+ */
15
+ text: string;
16
+ /** The block's sanitised HTML (`<pre>…</pre>` or `<table>…</table>`), for rich paste. */
17
+ html: string;
18
+ }
19
+ /**
20
+ * Writes one copy to the clipboard. Throwing, rejecting, or returning `false`
21
+ * means the copy failed; the failure is announced, never swallowed.
22
+ */
23
+ type ContentClipboardWriter = (payload: ContentClipboardPayload) => void | boolean | Promise<void | boolean>;
24
+ /** Reported through `onCopy` after every copy attempt. */
25
+ interface ContentCopyEvent extends ContentClipboardPayload {
26
+ /** Position of the button among this renderer's copy buttons, in document order. */
27
+ index: number;
28
+ /** Whether the clipboard write succeeded. */
29
+ ok: boolean;
30
+ }
5
31
  interface ContentRendererProps {
6
32
  value: string;
7
33
  format?: "html" | "markdown" | "auto";
@@ -17,11 +43,37 @@ interface ContentRendererProps {
17
43
  * @default false
18
44
  */
19
45
  unsafe?: boolean;
46
+ /**
47
+ * Copy buttons on code blocks and tables. `false` turns them all off; an
48
+ * object turns kinds off individually (`{ table: false }`).
49
+ * @default true
50
+ */
51
+ copyButtons?: boolean | {
52
+ code?: boolean;
53
+ table?: boolean;
54
+ };
55
+ /** Called after every copy attempt, successful or not. */
56
+ onCopy?: (event: ContentCopyEvent) => void;
57
+ /**
58
+ * Host-supplied clipboard writer, for environments where
59
+ * `navigator.clipboard` is unreliable (e.g. a sandboxed Electron window:
60
+ * pass one that calls Electron's `clipboard`). The default writes
61
+ * text/html + text/plain via `ClipboardItem`, falling back to `writeText`.
62
+ */
63
+ clipboardWriter?: ContentClipboardWriter;
64
+ /**
65
+ * The value is still arriving. Holds back an unfinished trailing custom tag
66
+ * (of a registered extension) or code fence, so a partial `<result` or
67
+ * half a code block never flashes as raw text. Set it back to `false` when
68
+ * the stream ends and everything renders.
69
+ * @default false
70
+ */
71
+ streaming?: boolean;
20
72
  }
21
73
 
22
- declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, }: ContentRendererProps): react.JSX.Element;
74
+ declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, copyButtons, onCopy, clipboardWriter, streaming, }: ContentRendererProps): react.JSX.Element;
23
75
  declare namespace ContentRenderer {
24
76
  var displayName: string;
25
77
  }
26
78
 
27
- export { ContentRenderer, type ContentRendererProps, RenderExtension };
79
+ export { type ContentClipboardPayload, type ContentClipboardWriter, type ContentCopyEvent, type ContentCopyKind, ContentRenderer, type ContentRendererProps, RenderExtension };