prompt-area 0.1.0 → 0.3.1

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 (44) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +11 -3
  3. package/dist/action-bar/index.js +1 -4
  4. package/dist/chat-prompt-layout/index.js +1 -4
  5. package/dist/chunk-23Y7B365.js +2 -0
  6. package/dist/chunk-2R57LWJO.js +3 -0
  7. package/dist/chunk-3D4ZBBYY.js +2 -0
  8. package/dist/chunk-6VISE4VA.js +2 -0
  9. package/dist/chunk-A6EFF4BI.js +1 -0
  10. package/dist/chunk-CRC4ST6U.js +3 -0
  11. package/dist/chunk-LJJ6HHR6.js +14 -0
  12. package/dist/chunk-MJSTEY4N.js +7 -0
  13. package/dist/chunk-VULUMPYE.js +2 -0
  14. package/dist/compact-prompt-area/index.js +1 -5
  15. package/dist/helpers/index.d.ts +3 -185
  16. package/dist/helpers/index.js +1 -291
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.js +1 -9
  19. package/dist/prompt-area/index.d.ts +4 -191
  20. package/dist/prompt-area/index.js +1 -5
  21. package/dist/status-bar/index.js +1 -4
  22. package/package.json +25 -13
  23. package/LICENSE +0 -21
  24. package/dist/action-bar/index.js.map +0 -1
  25. package/dist/chat-prompt-layout/index.js.map +0 -1
  26. package/dist/chunk-ANZZEZP2.js +0 -38
  27. package/dist/chunk-ANZZEZP2.js.map +0 -1
  28. package/dist/chunk-BPJO4DGM.js +0 -198
  29. package/dist/chunk-BPJO4DGM.js.map +0 -1
  30. package/dist/chunk-BWVBDP7C.js +0 -38
  31. package/dist/chunk-BWVBDP7C.js.map +0 -1
  32. package/dist/chunk-E7HUXORB.js +0 -2692
  33. package/dist/chunk-E7HUXORB.js.map +0 -1
  34. package/dist/chunk-NF2LHZIE.js +0 -12
  35. package/dist/chunk-NF2LHZIE.js.map +0 -1
  36. package/dist/chunk-UBBCAMJA.js +0 -116
  37. package/dist/chunk-UBBCAMJA.js.map +0 -1
  38. package/dist/chunk-XDKRP7UE.js +0 -125
  39. package/dist/chunk-XDKRP7UE.js.map +0 -1
  40. package/dist/compact-prompt-area/index.js.map +0 -1
  41. package/dist/helpers/index.js.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/prompt-area/index.js.map +0 -1
  44. package/dist/status-bar/index.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `prompt-area` package are documented here. This
4
+ project adheres to [Semantic Versioning](https://semver.org/).
5
+
6
+ ## 0.3.1
7
+
8
+ ### Changed
9
+
10
+ - **Smaller package** — the framework-agnostic engine is now emitted once as a
11
+ shared chunk instead of being bundled into both the components and the
12
+ `prompt-area/helpers` entry. The published tarball dropped from ~36 kB to
13
+ ~33 kB (unpacked ~134 kB → ~117 kB), and the core `PromptArea` import is
14
+ ~14 kB gzipped. No API changes.
15
+
16
+ ## 0.3.0
17
+
18
+ First npm publish since `0.1.0`. `0.1.1` was tagged but never published, so
19
+ its packaging changes (listed below) reached npm as part of this release. No
20
+ `0.2.0` was ever released — the version jumped straight from `0.1.1` to `0.3.0`.
21
+
22
+ ### Changed
23
+
24
+ - Install docs now show `pnpm` / `npm` / `yarn` side by side and clarify that
25
+ `react` and `react-dom` are peer dependencies. No functional or API changes
26
+ versus `0.1.1`.
27
+
28
+ ## 0.1.1
29
+
30
+ ### Changed
31
+
32
+ - **Much smaller package** — the published tarball dropped from ~109 kB to
33
+ ~37 kB (unpacked 513 kB → 135 kB). The build is now minified and no longer
34
+ ships source maps.
35
+ - `tailwindcss` (>= 4) is now declared as an **optional** peer dependency, for
36
+ consumers who use the `prompt-area/tailwind.css` preset. The prebuilt
37
+ `prompt-area/styles.css` still works with zero Tailwind setup.
38
+
39
+ ## 0.1.0
40
+
41
+ Initial release.
42
+
43
+ - `PromptArea` contentEditable rich-text input with trigger-based chips
44
+ (`@mentions`, `/commands`, `#tags`), inline markdown, undo/redo, URL
45
+ detection, list auto-formatting, IME support, and file & image attachments.
46
+ - Companion components: `ActionBar`, `StatusBar`, `CompactPromptArea`,
47
+ `ChatPromptLayout`.
48
+ - `usePromptAreaState` hook, trigger presets, and segment helpers.
49
+ - Server-safe helpers re-exported from `prompt-area/helpers`.
50
+ - Prebuilt `styles.css` (zero-config) and an optional Tailwind v4 preset.
51
+ - ESM, per-entry types, and tree-shakeable subpath exports.
52
+ - Zero runtime dependencies beyond `clsx` + `tailwind-merge`.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # prompt-area
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/prompt-area.svg)](https://www.npmjs.com/package/prompt-area)
4
+ [![npm downloads](https://img.shields.io/npm/dm/prompt-area.svg)](https://www.npmjs.com/package/prompt-area)
5
+ [![license](https://img.shields.io/npm/l/prompt-area.svg)](https://github.com/just-marketing/prompt-area/blob/main/LICENSE)
6
+
3
7
  An opinionated, dependency-light React rich-text **prompt input** — trigger-based chips (`@mentions`, `/commands`, `#tags`), inline markdown, undo/redo, file & image attachments, and a complete chat-input layout.
4
8
 
5
9
  Ships **two ways** from the same source:
@@ -10,11 +14,12 @@ Ships **two ways** from the same source:
10
14
  ## Install
11
15
 
12
16
  ```bash
13
- npm install prompt-area
14
- # peer deps (most React apps already have these)
15
- npm install react react-dom
17
+ pnpm add prompt-area
18
+ # or: npm install prompt-area · yarn add prompt-area
16
19
  ```
17
20
 
21
+ `react` and `react-dom` are peer dependencies (most React apps already have them).
22
+
18
23
  ## Quick start
19
24
 
20
25
  ```tsx
@@ -106,6 +111,9 @@ The components are client components and carry a `'use client'` boundary, so you
106
111
  ## Dependencies
107
112
 
108
113
  - **Peer:** `react`, `react-dom` (>= 18)
114
+ - **Optional peer:** `tailwindcss` (>= 4) and `tw-animate-css` — only needed if
115
+ you use the `prompt-area/tailwind.css` preset. The prebuilt
116
+ `prompt-area/styles.css` needs neither.
109
117
  - **Runtime:** `clsx`, `tailwind-merge` — the two `cn` helpers, both already
110
118
  present in any shadcn/Tailwind project.
111
119
 
@@ -1,5 +1,2 @@
1
1
  'use client';
2
- export { ActionBar } from '../chunk-BWVBDP7C.js';
3
- import '../chunk-NF2LHZIE.js';
4
- //# sourceMappingURL=index.js.map
5
- //# sourceMappingURL=index.js.map
2
+ export{a as ActionBar}from'../chunk-VULUMPYE.js';import'../chunk-23Y7B365.js';
@@ -1,5 +1,2 @@
1
1
  'use client';
2
- export { ChatPromptLayout } from '../chunk-XDKRP7UE.js';
3
- import '../chunk-NF2LHZIE.js';
4
- //# sourceMappingURL=index.js.map
5
- //# sourceMappingURL=index.js.map
2
+ export{a as ChatPromptLayout}from'../chunk-CRC4ST6U.js';import'../chunk-23Y7B365.js';
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {clsx}from'clsx';import {twMerge}from'tailwind-merge';function s(...r){return twMerge(clsx(r))}export{s as a};
@@ -0,0 +1,3 @@
1
+ 'use client';
2
+ import {a,c}from'./chunk-LJJ6HHR6.js';import {a as a$1}from'./chunk-23Y7B365.js';import {useRef,useState,useImperativeHandle,useCallback}from'react';import {jsx,jsxs}from'react/jsx-runtime';function y({className:t,children:s}){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:t,children:s})}var v=({className:t})=>jsxs(y,{className:t,children:[jsx("path",{d:"M5 12h14"}),jsx("path",{d:"M12 5v14"})]}),q=({className:t})=>jsxs(y,{className:t,children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]});function J({value:t,onChange:s,triggers:P,placeholder:k,disabled:a$2=false,markdown:C,onSubmit:d,onEscape:N,onChipClick:A,onChipAdd:w,onChipDelete:R,onPaste:H,images:I,onImagePaste:S,onImageRemove:z,files:E,onFileRemove:F,plusButtonIcon:l,onPlusClick:p,submitButtonIcon:L,beforeSubmitSlot:M,maxHeight:j=320,className:B,"aria-label":D,"data-test-id":T,ref:U}){let i=useRef(null),m=useRef(null),[_,u]=useState(false);useImperativeHandle(U,()=>i.current,[]);let f=t.length===0||t.length===1&&t[0].type==="text"&&t[0].text==="",r=_||!f,G=useCallback(()=>{u(true);},[]),V=useCallback(()=>{setTimeout(()=>{m.current?.contains(document.activeElement)||u(false);},a);},[]),b=useCallback(()=>{d?.(t);},[d,t]);return jsx("div",{ref:m,onFocus:G,onBlur:V,"aria-label":D,"data-test-id":T,className:a$1("compact-prompt-area","bg-background border transition-all duration-200 ease-out",r?"rounded-2xl":"rounded-full",B),children:jsxs("div",{className:a$1("flex",r?"flex-col":"items-center p-1.5"),children:[!r&&jsx("button",{type:"button",onClick:p,disabled:a$2,className:a$1("flex shrink-0 items-center justify-center rounded-xl transition-colors","bg-muted text-muted-foreground size-9","hover:bg-accent hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),"aria-label":"Add attachment",children:l??jsx(v,{className:"size-4"})}),jsx("div",{className:a$1("min-w-0 flex-1",r?"px-5 pt-4 pb-2":"overflow-hidden px-3"),onClick:()=>i.current?.focus(),children:jsx(c,{ref:i,value:t,onChange:s,triggers:P,placeholder:k,disabled:a$2,markdown:C,onSubmit:b,onEscape:N,onChipClick:A,onChipAdd:w,onChipDelete:R,onPaste:H,images:I,onImagePaste:S,onImageRemove:z,files:E,onFileRemove:F,autoGrow:true,minHeight:r?48:24,maxHeight:j})}),jsxs("div",{className:a$1("flex shrink-0 items-center",r?"justify-between px-3 pt-1 pb-3":"gap-1.5"),children:[r&&jsx("button",{type:"button",onClick:p,disabled:a$2,className:a$1("flex shrink-0 items-center justify-center rounded-xl transition-colors","bg-muted text-muted-foreground size-9","hover:bg-accent hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),"aria-label":"Add attachment",children:l??jsx(v,{className:"size-4"})}),jsxs("div",{className:"flex items-center gap-1.5",children:[M,jsx("button",{type:"button",onClick:b,disabled:a$2||f,className:a$1("flex shrink-0 items-center justify-center rounded-xl transition-colors","bg-primary text-primary-foreground size-9","hover:bg-primary/90","disabled:pointer-events-none disabled:opacity-50"),"aria-label":"Send message",children:L??jsx(q,{className:"size-4"})})]})]})]})})}
3
+ export{J as a};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {a}from'./chunk-MJSTEY4N.js';import {useState,useRef,useMemo,useCallback}from'react';function A(s={}){let{initialValue:a$1=[]}=s,[e,p]=useState(a$1),r=useRef(null),m=useMemo(()=>a(e),[e]),g=useMemo(()=>e.length===0?true:e.every(t=>t.type==="text"&&t.text.trim()===""),[e]),l=useMemo(()=>e.some(t=>t.type==="chip"),[e]),c=useMemo(()=>e.filter(t=>t.type==="chip"),[e]),u=useMemo(()=>({ref:r,value:e,onChange:p}),[e]),h=useCallback(()=>{r.current?r.current.clear():p([]);},[]),T=useCallback(()=>r.current?.focus(),[]),S=useCallback(()=>r.current?.blur(),[]),P=useCallback(t=>r.current?.insertChip(t),[]);return {bind:u,plainText:m,isEmpty:g,hasChips:l,chips:c,clear:h,focus:T,blur:S,insertChip:P}}export{A as a};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {jsxs,jsx}from'react/jsx-runtime';function l({left:e,right:t,className:i,disabled:a$1=false,"aria-label":p,"data-test-id":o,ref:n}){return jsxs("div",{ref:n,role:"group","aria-label":p??"Status bar","aria-disabled":a$1||void 0,"data-test-id":o,className:a("status-bar","flex items-center justify-between gap-2 px-3 py-1.5 text-xs",a$1&&"pointer-events-none opacity-50",i),children:[e&&jsx("div",{className:"flex items-center gap-1.5",children:e}),t&&jsx("div",{className:"ml-auto flex items-center gap-1.5",children:t})]})}export{l as a};
@@ -0,0 +1 @@
1
+ function i(e){return {type:"text",text:e}}function n(e){return {type:"chip",...e}}function o(e){return e.length===0?true:e.every(t=>t.type==="text"&&t.text.trim()==="")}function g(e){return e.some(t=>t.type==="chip")}function p(e){return e.filter(t=>t.type==="chip")}function s(e,t){return e.filter(r=>r.type==="chip"&&r.trigger===t)}function c(e={}){let{char:t="@",...r}=e;return {char:t,position:"any",mode:"dropdown",chipStyle:"pill",accessibilityLabel:"mention",...r}}function m(e={}){let{char:t="/",...r}=e;return {char:t,position:"start",mode:"dropdown",chipStyle:"inline",accessibilityLabel:"command",...r}}function h(e={}){let{char:t="#",...r}=e;return {char:t,position:"any",mode:"dropdown",chipStyle:"pill",resolveOnSpace:true,accessibilityLabel:"tag",...r}}function l(e){let{char:t,...r}=e;return {char:t,position:"start",mode:"callback",...r}}export{i as a,n as b,o as c,g as d,p as e,s as f,c as g,m as h,h as i,l as j};
@@ -0,0 +1,3 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {useRef,useState,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';var g=300,w=100;function y(){let t=useRef(null),[s,c]=useState(false),[i,u]=useState(false),n=useRef(0),r=useCallback(()=>{cancelAnimationFrame(n.current),n.current=requestAnimationFrame(()=>{let o=t.current;if(!o)return;let a=o.scrollTop,h=o.scrollHeight-a-o.clientHeight;c(d=>d?a>w:a>g),u(d=>d?h>w:h>g);});},[]);useEffect(()=>{let o=t.current;if(o)return o.addEventListener("scroll",r,{passive:true}),r(),()=>{o.removeEventListener("scroll",r),cancelAnimationFrame(n.current);}},[r]);let m=useCallback(()=>{t.current?.scrollTo({top:0,behavior:"smooth"});},[]),p=useCallback(()=>{let o=t.current;o&&o.scrollTo({top:o.scrollHeight,behavior:"smooth"});},[]);return {scrollRef:t,showGoToTop:s,showGoToBottom:i,scrollToTop:m,scrollToBottom:p}}var N="pointer-events-auto rounded-full border bg-background p-2 shadow-sm text-muted-foreground hover:bg-accent hover:text-foreground transition-colors animate-in fade-in-0 zoom-in-95 duration-150";function S({className:t,children:s}){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:t,children:s})}var x=({className:t})=>jsxs(S,{className:t,children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]}),P=({className:t})=>jsxs(S,{className:t,children:[jsx("path",{d:"M12 5v14"}),jsx("path",{d:"m19 12-7 7-7-7"})]});function C({children:t,prompt:s,className:c,"aria-label":i,"data-test-id":u,ref:n}){let{scrollRef:r,showGoToTop:m,showGoToBottom:p,scrollToTop:o,scrollToBottom:a$1}=y();return jsxs("div",{ref:n,role:"region","aria-label":i??"Chat layout","data-test-id":u,className:a("chat-prompt-layout","flex h-full flex-col",c),children:[jsxs("div",{ref:r,className:"relative flex-1 overflow-y-auto",children:[t,jsxs("div",{className:"pointer-events-none sticky bottom-4 flex justify-end gap-2 px-4 pb-2",children:[m&&jsx("button",{type:"button",onClick:o,className:N,"aria-label":"Scroll to top",children:jsx(x,{className:"size-4"})}),p&&jsx("button",{type:"button",onClick:a$1,className:N,"aria-label":"Scroll to bottom",children:jsx(P,{className:"size-4"})})]})]}),jsx("div",{className:"shrink-0",children:s})]})}
3
+ export{C as a};
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {a as a$1,d,e,l,f,g,j,i,h,m}from'./chunk-MJSTEY4N.js';import {useRef,useState,useCallback,useEffect,useMemo,useImperativeHandle}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function fe(e,n){let o=e.lastIndexOf(`
3
+ `,n-1)+1,t=e.indexOf(`
4
+ `,n),r=e.slice(o,t===-1?e.length:t),a=r.match(/^(\s*)([•\-*]) /);if(a){let g=a[1];return {lineStart:o,prefix:a[0],indent:Math.floor(g.length/2),listType:"bullet",contentStart:o+a[0].length}}let c=r.match(/^(\s*)(\d+)\. /);if(c){let g=c[1];return {lineStart:o,prefix:c[0],indent:Math.floor(g.length/2),listType:"numbered",number:parseInt(c[2],10),contentStart:o+c[0].length}}return null}function ut(e,n){let o=a$1(e),t=o.lastIndexOf(`
5
+ `,n-1)+1,r=o.slice(t,n),a=r.match(/^(\s*)[-*] $/);if(!a)return null;let g=`${a[1]}\u2022 `,x=t,T=t+r.length;return {segments:i(e,x,T,g),cursorOffset:t+g.length}}function dt(e,n){let o=a$1(e),t=fe(o,n);if(!t)return null;let r=o.indexOf(`
6
+ `,n);if(o.slice(t.contentStart,r===-1?o.length:r).trim()==="")return {segments:i(e,t.lineStart,t.lineStart+t.prefix.length,""),cursorOffset:t.lineStart};let c=" ".repeat(t.indent),g;if(t.listType==="bullet")g=`${c}\u2022 `;else {let C=(t.number??1)+1;g=`${c}${C}. `;}let x=`
7
+ ${g}`;return {segments:i(e,n,n,x),cursorOffset:n+x.length}}function ft(e,n){let o=a$1(e),t=fe(o,n);return t?{segments:i(e,t.lineStart,t.lineStart," "),cursorOffset:n+2}:null}function pt(e,n){let o=a$1(e),t=fe(o,n);return !t||t.indent===0?null:{segments:i(e,t.lineStart,t.lineStart+2,""),cursorOffset:Math.max(t.lineStart,n-2)}}function gt(e,n){let o=a$1(e),t=fe(o,n);return !t||n>t.contentStart?null:{segments:i(e,t.lineStart,t.contentStart," ".repeat(t.indent)),cursorOffset:t.lineStart+t.indent*2}}function Ve(e,n){let o=false,t=e.map(r=>{if(r.type!=="text")return r;let a=n?r.text.replace(/(^|\n)(\s*)- /g,"$1$2\u2022 "):r.text.replace(/(^|\n)(\s*)• /g,"$1$2- ");return a===r.text?r:(o=true,{...r,text:a})});return o?t:e}function te(e){return e instanceof HTMLElement}function B(e){return e instanceof HTMLElement&&e.dataset.chipTrigger!==void 0}function pe(e){return e instanceof HTMLBRElement}function vt(e){return e instanceof Text}function ge(e){return B(e)&&e.dataset.chipAutoResolved==="true"}function xt(e){return e instanceof HTMLAnchorElement&&e.dataset.url==="true"}function Wt(e){try{return JSON.parse(e)}catch{return}}function Be(e){try{return JSON.stringify(e)}catch{return}}function Te(e){if(B(e))return e.dataset.chipTrigger}function Ne(e){if(B(e))return e.dataset.chipValue}function ye(e){if(B(e))return e.dataset.chipDisplay??e.textContent??void 0}function Re(e){if(!B(e))return;let n=e.dataset.chipData;if(n)return Wt(n)}function De(e,n){let o=e.childNodes;for(let t=0;t<o.length;t++)if(o[t]===n)return t;return -1}function Me(e,n){let o=n;for(;o!==null;){if(o.parentNode===e)return o;o=o.parentNode;}return null}function Xt(e,n){let o=document.createDocumentFragment();for(;n.firstChild;)o.appendChild(n.firstChild);o.appendChild(document.createElement("br")),e.replaceChild(o,n);}function Le(e){let n=false,o=new Set(["DIV","P","SECTION","ARTICLE","BLOCKQUOTE"]);for(let t=e.childNodes.length-1;t>=0;t--){let r=e.childNodes[t];if(!(r instanceof HTMLElement)||r.dataset.chipTrigger!==void 0||r instanceof HTMLBRElement)continue;let a=r.tagName;if(o.has(a))Xt(e,r),n=true;else if(a==="FONT"||a==="B"||a==="I"||a==="U"||a==="STRONG"||a==="EM"||a==="A"||a==="SPAN"){let c=r.textContent??"";c?e.replaceChild(document.createTextNode(c),r):e.removeChild(r),n=true;}}return e.normalize(),n}var mt=/https?:\/\/[^\s),]+/g;function je(e){let n=false,o=[];for(let t=0;t<e.childNodes.length;t++){let r=e.childNodes[t];vt(r)&&r.textContent&&o.push(r);}for(let t of o){let r=t.textContent??"";mt.lastIndex=0;let a=[],c;for(;(c=mt.exec(r))!==null;){let E=c[0];for(;E.length>0&&/[.;:!?]$/.test(E);)E=E.slice(0,-1);E.length>0&&a.push({url:E,index:c.index});}if(a.length===0)continue;let g=t.parentNode;if(!g)continue;let x=[];for(let{url:E,index:b}of a)try{let h=new URL(E);(h.protocol==="http:"||h.protocol==="https:")&&x.push({url:E,href:h.href,index:b});}catch{}if(x.length===0)continue;n=true;let T=document.createDocumentFragment(),C=0;for(let{url:E,href:b,index:h}of x){h>C&&T.appendChild(document.createTextNode(r.slice(C,h)));let d=document.createElement("a");d.href=b,d.target="_blank",d.rel="noopener noreferrer",d.dataset.url="true",d.className="text-primary hover:text-primary/80 underline cursor-pointer",d.textContent=E,T.appendChild(d),C=h+E.length;}C<r.length&&T.appendChild(document.createTextNode(r.slice(C))),g.replaceChild(T,t);}return n}var ht=/(\*{3})(.+?)\*{3}|(\*{2})(.+?)\*{2}|(\*)(.+?)\*/g;function qe(e){let n=false,o=[];for(let t=0;t<e.childNodes.length;t++){let r=e.childNodes[t];vt(r)&&r.textContent&&o.push(r);}for(let t of o){let r=t.textContent??"";ht.lastIndex=0;let a=[],c;for(;(c=ht.exec(r))!==null;)c[1]&&c[2]?a.push({fullMatch:c[0],marker:c[1],content:c[2],index:c.index,className:"font-bold italic"}):c[3]&&c[4]?a.push({fullMatch:c[0],marker:c[3],content:c[4],index:c.index,className:"font-bold"}):c[5]&&c[6]&&a.push({fullMatch:c[0],marker:c[5],content:c[6],index:c.index,className:"italic"});if(a.length===0)continue;n=true;let g=t.parentNode;if(!g)continue;let x=document.createDocumentFragment(),T=0;for(let{fullMatch:C,marker:E,content:b,index:h,className:d}of a){h>T&&x.appendChild(document.createTextNode(r.slice(T,h)));let y=document.createElement("span");y.dataset.md="true";let I=document.createElement("span");I.className="prompt-area-md-marker",I.textContent=E;let K=document.createElement("span");K.className=d,K.textContent=b;let U=document.createElement("span");U.className="prompt-area-md-marker",U.textContent=E,y.appendChild(I),y.appendChild(K),y.appendChild(U),x.appendChild(y),T=h+C.length;}T<r.length&&x.appendChild(document.createTextNode(r.slice(T))),g.replaceChild(x,t);}return n}function W(){let e=window.getSelection();return !e||e.rangeCount===0?null:e.getRangeAt(0)}function St(e){let n=W();if(!n||!e.contains(n.startContainer))return null;let o=n.startContainer;if(o===e)return {nodeIndex:n.startOffset,offset:0};let t=Me(e,o);return t?{nodeIndex:De(e,t),offset:n.startOffset}:null}function Tt(e,n){let o=window.getSelection();if(!o)return;let t=e.childNodes;if(t.length===0)return;let r=document.createRange();if(n.nodeIndex>=t.length){let a=t[t.length-1];a.nodeType===Node.TEXT_NODE?r.setStart(a,(a.textContent??"").length):r.setStartAfter(a);}else {let a=t[n.nodeIndex];if(a.nodeType===Node.TEXT_NODE){let c=(a.textContent??"").length;r.setStart(a,Math.min(n.offset,c));}else r.setStartAfter(a);}r.collapse(true),o.removeAllRanges(),o.addRange(r);}function Ce(e){let n=W();if(!n||!e.contains(n.startContainer))return null;let o=document.createRange();return o.selectNodeContents(e),o.setEnd(n.startContainer,n.startOffset),we(o)}function yt(e,n){let o=Oe(e,n);if(!o)return null;let t=document.createRange();return t.setStart(o.node,o.offset),t.collapse(true),t}function ne(e,n){let o=window.getSelection();if(!o)return;let t=Oe(e,n);if(t){let a=document.createRange();a.setStart(t.node,t.offset),a.collapse(true),o.removeAllRanges(),o.addRange(a);return}let r=document.createRange();r.selectNodeContents(e),r.collapse(false),o.removeAllRanges(),o.addRange(r);}function we(e){let n=e.cloneContents(),o=0,t=r=>{if(r.nodeType===Node.TEXT_NODE)o+=(r.textContent??"").length;else if(B(r)){let a=r.dataset.chipTrigger??"",c=r.dataset.chipDisplay??r.textContent??"";o+=a.length+c.length;}else if(te(r)&&r.tagName==="BR"){if(r.dataset.sentinel)return;o+=1;}else te(r)&&r.childNodes.forEach(t);};return n.childNodes.forEach(t),o}function Ue(e){let n=W();if(!n||!e.contains(n.startContainer))return null;let o=document.createRange();o.selectNodeContents(e),o.setEnd(n.startContainer,n.startOffset);let t=we(o);if(n.collapsed)return {start:t,end:t};let r=document.createRange();r.selectNodeContents(e),r.setEnd(n.endContainer,n.endOffset);let a=we(r);return {start:t,end:a}}function Ct(e,n,o){let t=window.getSelection();if(!t)return;if(n===o){ne(e,n);return}let r=Oe(e,n),a=Oe(e,o);if(!r||!a)return;let c=document.createRange();c.setStart(r.node,r.offset),c.setEnd(a.node,a.offset),t.removeAllRanges(),t.addRange(c);}function Oe(e,n){let o=n;for(let t=0;t<e.childNodes.length;t++){let r=e.childNodes[t];if(r.nodeType===Node.TEXT_NODE){let a=(r.textContent??"").length;if(o<=a)return {node:r,offset:o};o-=a;}else if(B(r)){let a=r.dataset.chipTrigger??"",c=r.dataset.chipDisplay??r.textContent??"",g=a.length+c.length;if(o<=g)return {node:e,offset:t+1};o-=g;}else if(pe(r)){if(r.dataset.sentinel)continue;if(o<=1)return {node:e,offset:t+1};o-=1;}else if(te(r)){let a=(r.textContent??"").length;if(o<=a){let c=Oe(r,o);if(c)return c}o-=a;}}return {node:e,offset:e.childNodes.length}}function Vt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Et(e){let n="",o=t=>{if(t.nodeType===Node.TEXT_NODE)n+=t.textContent??"";else if(B(t)){let r=Te(t)??"",a=ye(t)??"";n+=r+a;}else te(t)&&t.tagName==="BR"?n+=`
8
+ `:t.childNodes.forEach(o);};return e.childNodes.forEach(o),n}function bt(e){let n=[],o=t=>{if(t.nodeType===Node.TEXT_NODE){let r=t.textContent??"";r&&n.push({type:"text",text:r});}else if(B(t)){let r=Te(t),a=Ne(t),c=ye(t),g=Re(t),x=ge(t);if(r&&a!==void 0&&c){let T={type:"chip",trigger:r,value:a,displayText:c,...g!==void 0?{data:g}:{},...x?{autoResolved:true}:{}};n.push(T);}}else te(t)&&t.tagName==="BR"?n.push({type:"text",text:`
9
+ `}):t.childNodes.forEach(o);};return e.childNodes.forEach(o),n}function Nt(e){try{let n=JSON.parse(e);if(!Array.isArray(n))return null;let o=[];for(let t of n){if(!Vt(t))return null;if(t.type==="text"&&typeof t.text=="string")o.push({type:"text",text:t.text});else if(t.type==="chip"&&typeof t.trigger=="string"&&typeof t.value=="string"&&typeof t.displayText=="string"){let r={type:"chip",trigger:t.trigger,value:t.value,displayText:t.displayText,...t.data!==void 0?{data:t.data}:{},...t.autoResolved?{autoResolved:!0}:{}};o.push(r);}else return null}return o}catch{return null}}function Rt(e,n,o){let t=W();if(!t)return [...e,...n];let r=document.createRange();r.selectNodeContents(o),r.setEnd(t.startContainer,t.startOffset);let a=we(r),c=[],g=0,x=false,T=()=>{x||(c.push(...n),x=true);};for(let C of e){if(C.type==="chip"){let b=C.trigger.length+C.displayText.length;g>=a&&T(),c.push(C),g+=b;continue}let E=g+C.text.length;if(E<=a)c.push(C);else if(g>=a)T(),c.push(C);else {let b=a-g,h=C.text.slice(0,b),d=C.text.slice(b);h&&c.push({type:"text",text:h}),T(),d&&c.push({type:"text",text:d});}g=E;}return T(),m(c)}var jt=100,Je=150;function Mt(e){let{editorRef:n,readSegmentsFromDOM:o,onChange:t,renderSegmentsToDOM:r,runTriggerDetection:a,dismissTrigger:c,triggers:g,onPaste:x,onUndo:T,onRedo:C,onChipAdd:E,onImagePaste:b}=e,h$1=useRef(false),d=useRef({undoStack:[],redoStack:[]}),y=useCallback(N=>{let L=d.current;L.undoStack.push(N),L.undoStack.length>jt&&L.undoStack.shift(),L.redoStack=[];},[]),I=useCallback(()=>{d.current={undoStack:[],redoStack:[]};},[]),K=useCallback(N=>{N.preventDefault();let L=n.current;if(!L)return;let D=Array.from(N.clipboardData.files).find(w=>w.type.startsWith("image/"))??Array.from(N.clipboardData.items).find(_=>_.type.startsWith("image/"))?.getAsFile()??null;if(D){b?.(D);return}let O=o();y(O);let S=N.clipboardData.getData("text/prompt-area-segments");if(S){let w=Nt(S);if(w&&w.length>0){let _=W();if(!_)return;_.deleteContents();let xe=o(),ie=Rt(xe,w,L);t(ie),r(ie),x?.({segments:ie,source:"internal"});for(let ue of w)ue.type==="chip"&&E?.(ue);a();return}}let k=N.clipboardData.getData("text/plain");if(!k)return;let M=W();if(!M)return;M.deleteContents();let $=k.split(`
10
+ `),R=document.createDocumentFragment();for(let w=0;w<$.length;w++)$[w]&&R.appendChild(document.createTextNode($[w])),w<$.length-1&&R.appendChild(document.createElement("br"));M.insertNode(R),M.collapse(false);let ce=window.getSelection();ce?.removeAllRanges(),ce?.addRange(M),Le(L);let se=o(),ee=h(se,g);if(ee!==se){t(ee),r(ee);for(let w of ee)w.type==="chip"&&!se.some(_=>_.type==="chip"&&_.trigger===w.trigger&&_.value===w.value&&_.displayText===w.displayText)&&E?.(w);}else t(se);x?.({segments:ee,source:"external"}),a();},[n,o,t,y,a,r,g,x,E,b]),U=useCallback(N=>{N.preventDefault();let L=W();if(!L)return;let D=L.cloneContents(),O=Et(D);N.clipboardData.setData("text/plain",O);let S=bt(D);if(S.some(M=>M.type==="chip")){let M=Be(S);M&&N.clipboardData.setData("text/prompt-area-segments",M);}},[]),P=useCallback(N=>{U(N);let L=W();if(!L)return;let D=o();y(D),L.deleteContents();let O=n.current;O&&Le(O);let S=o();t(S),a();},[U,n,o,t,y,a]),X=useCallback(N=>{N.preventDefault();},[]),G=useCallback(N=>{N.preventDefault();},[]),he=useCallback(()=>{h$1.current=true;},[]),ae=useCallback(()=>{h$1.current=false,a();},[a]),ve=useCallback(()=>{setTimeout(()=>{let N=n.current;if(!N)return;let L=document.activeElement;L&&N.parentElement?.contains(L)||c();},Je);},[n,c]),oe=useCallback(N=>{if(!(N.metaKey||N.ctrlKey)||N.key!=="z")return false;N.preventDefault();let D=d.current;if(N.shiftKey){if(D.redoStack.length===0)return true;let O=D.redoStack.pop();if(!O)return true;let S=o();D.undoStack.push(S),t(O),r(O),C?.(O);}else {if(D.undoStack.length===0)return true;let O=D.undoStack.pop();if(!O)return true;let S=o();D.redoStack.push(S),t(O),r(O),T?.(O);}return true},[o,t,r,T,C]);return {handlePaste:K,handleCopy:U,handleCut:P,handleDrop:X,handleDragOver:G,handleCompositionStart:he,handleCompositionEnd:ae,handleBlur:ve,handleKeyDownForUndoRedo:oe,pushUndo:y,resetUndoHistory:I,isComposing:h$1}}function wt(){let[e,n]=useState([]),[o,t]=useState(false),[r,a]=useState(null),c=useRef(0),g=useRef(null),x=useRef(null),T=useCallback(()=>{g.current?.abort(),x.current&&clearTimeout(x.current),n([]),t(false),a(null);},[]),C=useCallback((E,b)=>{if(!b.onSearch)return;g.current?.abort(),x.current&&clearTimeout(x.current),t(true),a(null),c.current++;let h=c.current,d=new AbortController;g.current=d;let{onSearch:y,onSearchError:I,searchDebounceMs:K}=b,U=()=>{let P=y(E,{signal:d.signal});P instanceof Promise?P.then(X=>{d.signal.aborted||c.current!==h||(n(X),t(false));},X=>{d.signal.aborted||c.current!==h||X instanceof DOMException&&X.name==="AbortError"||(a(X instanceof Error?X.message:"Search failed"),t(false),I?.(X));}):(n(P),t(false));};K&&K>0&&E.length>0?x.current=setTimeout(U,K):U();},[]);return useEffect(()=>()=>{g.current?.abort(),x.current&&clearTimeout(x.current);},[]),{suggestions:e,suggestionsLoading:o,suggestionsError:r,search:C,reset:T}}var Jt=300;function kt({value:e$1,onChange:n,triggers:o=[],onSubmit:t,onEscape:r,onChipClick:a$2,onChipAdd:c,onChipDelete:g$1,onLinkClick:x,onPaste:T,onUndo:C,onRedo:E,onImagePaste:b,markdown:h=true}){let d$1=useRef(null),[y,I]=useState(null),[K,U]=useState(0),[P,X]=useState(null),{suggestions:G,suggestionsLoading:he,suggestionsError:ae,search:ve,reset:oe}=wt(),N=useRef(false),L=useRef([]),D=useRef(null),O=useRef(null),S=useCallback(()=>{let s=d$1.current;if(!s)return [];let f=[];for(let m=0;m<s.childNodes.length;m++){let i=s.childNodes[m];if(i.nodeType===Node.TEXT_NODE){let l=i.textContent??"";l&&f.push({type:"text",text:l});}else if(B(i)){let l=Te(i),u=Ne(i),p=ye(i),v=Re(i);if(l&&u!==void 0&&p){let H=ge(i);f.push({type:"chip",trigger:l,value:u,displayText:p,...v!==void 0?{data:v}:{},...H?{autoResolved:true}:{}});}}else if(pe(i)){if(i.dataset.sentinel)continue;f.push({type:"text",text:`
11
+ `});}else if(te(i)){let l=i.textContent??"";l&&f.push({type:"text",text:l});}}return f},[]),k=useCallback(s=>{let f=d$1.current;if(!f)return;N.current=true;let m=St(f);for(;f.firstChild;)f.removeChild(f.firstChild);for(let i of s)if(i.type==="text"){let l=i.text.split(`
12
+ `);for(let u=0;u<l.length;u++)l[u]&&f.appendChild(document.createTextNode(l[u])),u<l.length-1&&f.appendChild(document.createElement("br"));}else {let l=document.createElement("span");if(l.contentEditable="false",l.dataset.chipTrigger=i.trigger,l.dataset.chipValue=i.value,l.dataset.chipDisplay=i.displayText,i.data!==void 0){let v=Be(i.data);v&&(l.dataset.chipData=v);}i.autoResolved&&(l.dataset.chipAutoResolved="true");let u=o.find(v=>v.char===i.trigger),p=u?.chipStyle??"pill";l.dataset.chipStyle=p,l.className=a("prompt-area-chip",p==="inline"&&"prompt-area-chip--inline",u?.chipClassName),l.textContent=`${i.trigger}${i.displayText}`,l.setAttribute("role","button"),l.setAttribute("tabindex","-1"),f.appendChild(l);}if(f.lastChild&&pe(f.lastChild)){let i=document.createElement("br");i.dataset.sentinel="true",f.appendChild(i);}je(f),h&&qe(f),m&&Tt(f,m),L.current=s,N.current=false;},[o,h]),M=useCallback(()=>{let s=d$1.current;if(!s)return;let f=S(),m=a$1(f),i=Ce(s);if(i===null)return;let l=d(m,i,o);if(l){I(l),U(0);let u=yt(s,l.startOffset);if(u){let p=u.getBoundingClientRect();(p.height>0||p.left>0||p.top>0)&&X(p);}l.config.mode==="dropdown"&&l.config.onSearch&&ve(l.query,l.config),l.config.mode==="callback"&&l.config.onActivate&&l.config.onActivate({text:m,cursorPosition:i,insertChip:p=>{let v=e(f,l,{value:p.value,displayText:p.displayText,data:p.data});n(v.segments),k(v.segments),c?.({type:"chip",trigger:l.config.char,value:p.value,displayText:p.displayText,...p.data!==void 0?{data:p.data}:{}});let H=d$1.current;H&&ne(H,v.cursorOffset);}});}else I(null),oe();},[o,S,n,k,c,oe,ve]),$=useCallback(()=>{I(null),U(0),oe();},[oe]),R=Mt({editorRef:d$1,readSegmentsFromDOM:S,onChange:n,renderSegmentsToDOM:k,runTriggerDetection:M,dismissTrigger:$,triggers:o,onPaste:T,onUndo:C,onRedo:E,onChipAdd:c,onImagePaste:b});useEffect(()=>{if(!N.current&&!l(e$1,L.current)){if(h){let s=Ve(e$1,true);if(s!==e$1){n(s);return}}k(e$1);}},[e$1,k,h,n]);let ce=useRef(h);useEffect(()=>{if(ce.current===h)return;ce.current=h;let s=Ve(e$1,h);s!==e$1?n(s):k(e$1);},[h,k,e$1,n]),useEffect(()=>()=>{D.current&&clearTimeout(D.current);},[]);let se=useCallback(()=>{if(N.current)return;if(R.isComposing.current){let i=S();L.current=i,n(i);return}let s=d$1.current,f=s?Ce(s):null;s&&Le(s);let m=S();if(h&&s&&f!==null){let i=ut(m,f);if(i){L.current=i.segments,n(i.segments),k(i.segments),ne(s,i.cursorOffset),M();return}}O.current||(O.current=L.current),L.current=m,n(m),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{O.current&&(R.pushUndo(O.current),O.current=null),D.current=null;},Jt),s&&(je(s),h&&qe(s),f!==null&&ne(s,f)),M();},[n,S,M,k,h,R]),ee=useCallback(s=>{let f=s.target;if(!(f instanceof Node))return;let m=d$1.current;if(!m)return;let i=f;for(;i&&i!==m;){if(xt(i)){if(s.metaKey||s.ctrlKey){s.preventDefault(),x?.(i.href),window.open(i.href,"_blank","noopener,noreferrer");return}break}if(B(i)){let l=i,u=l.getBoundingClientRect(),p=document.createElement("span");p.className="prompt-area-chip-ripple";let v=Math.max(u.width,u.height);if(p.style.width=`${v}px`,p.style.height=`${v}px`,p.style.left=`${s.clientX-u.left-v/2}px`,p.style.top=`${s.clientY-u.top-v/2}px`,l.appendChild(p),p.addEventListener("animationend",()=>p.remove()),!a$2)return;let H=Te(i),z=Ne(i),Pe=ye(i),be=Re(i);if(H&&z!==void 0&&Pe){let Ie=ge(i),J={type:"chip",trigger:H,value:z,displayText:Pe,...be!==void 0?{data:be}:{},...Ie?{autoResolved:true}:{}};a$2(J);}return}i=i.parentNode;}},[a$2,x]),w=useCallback((s,f$1)=>{let m=S(),i=De(s,f$1);if(i===-1)return false;let l=0;for(let v=0;v<i;v++){let H=s.childNodes[v];(H.nodeType===Node.TEXT_NODE&&(H.textContent??"")!==""||B(H)||pe(H))&&l++;}let u=m[l],p=f(m,l);return n(p),k(p),u?.type==="chip"&&g$1?.(u),true},[S,n,k,g$1]),_=useCallback((s,f)=>{let m=S(),i=De(s,f);if(i===-1)return false;let l=0;for(let H=0;H<i;H++){let z=s.childNodes[H];(z.nodeType===Node.TEXT_NODE&&(z.textContent??"")!==""||B(z)||pe(z))&&l++;}let u=m[l],p=g(m,l);if(!p)return false;let v=0;for(let H=0;H<l;H++){let z=m[H];z.type==="text"?v+=z.text.length:v+=z.trigger.length+z.displayText.length;}return v+=p.revertedText.length,n(p.segments),k(p.segments),ne(s,v),u?.type==="chip"&&g$1?.(u),true},[S,n,k,g$1]),xe=useCallback(()=>{let s=d$1.current;if(!s)return false;let f=W();if(!f||!f.collapsed)return false;let m=f.startContainer,i=f.startOffset;if(m===s&&i>0){let l=s.childNodes[i-1];if(l&&B(l))return ge(l)?_(s,l):w(s,l)}if(m.nodeType===Node.TEXT_NODE&&i===0){let l=Me(s,m);if(!l)return false;let u=l.previousSibling;for(;u&&u.nodeType===Node.TEXT_NODE&&u.textContent==="";)u=u.previousSibling;if(u&&B(u))return ge(u)?_(s,u):w(s,u)}return false},[w,_]),ie=useCallback(()=>{let s=d$1.current;if(!s)return false;let f=W();if(!f||!f.collapsed)return false;let m=f.startContainer,i=f.startOffset;if(m===s&&i<s.childNodes.length){let l=s.childNodes[i];if(l&&B(l))return w(s,l)}if(m.nodeType===Node.TEXT_NODE&&i===(m.textContent??"").length){let l=Me(s,m);if(!l)return false;let u=l.nextSibling;for(;u&&u.nodeType===Node.TEXT_NODE&&u.textContent==="";)u=u.nextSibling;if(u&&B(u))return w(s,u)}return false},[w]),ue=useCallback(s=>{let f=S(),m=s.query,i={value:m,label:m},l=s.config.onSelect?.(i)??m,u={value:m,displayText:l||m,autoResolved:true},p=e(f,s,u);n(p.segments),k(p.segments),c?.({type:"chip",trigger:s.config.char,...u});let v=d$1.current;v&&ne(v,p.cursorOffset),$();},[S,n,k,$,c]),Se=useCallback(s=>{if(!y)return;let f=S(),m=y.config.onSelect?.(s)??s.label,i={value:s.value,displayText:m||s.label,data:s.data},l=e(f,y,i);n(l.segments),k(l.segments),c?.({type:"chip",trigger:y.config.char,...i});let u=d$1.current;u&&ne(u,l.cursorOffset),$(),setTimeout(()=>{d$1.current?.focus();},0);},[y,S,n,k,$,c]),We=Se,q=useCallback(s=>{let f=(i,l)=>{L.current=l.segments,n(l.segments),k(l.segments),ne(i,l.cursorOffset);},m=i=>{if(!h)return false;let l=S(),u=Ce(i);if(u===null)return false;let p=a$1(l);if(!fe(p,u))return false;let v=dt(l,u);return v&&f(i,v),true};if((s.metaKey||s.ctrlKey)&&s.key==="z"&&O.current&&(D.current&&(clearTimeout(D.current),D.current=null),R.pushUndo(O.current),O.current=null),!R.handleKeyDownForUndoRedo(s)){if(h&&(s.metaKey||s.ctrlKey)&&!s.shiftKey&&(s.key==="b"||s.key==="i")){s.preventDefault();let i=d$1.current;if(!i)return;let l=Ue(i);if(!l||l.start===l.end)return;let u=s.key==="b"?"**":"*",p=S();R.pushUndo(p);let v=j(p,l.start,l.end,u);if(!v)return;L.current=v.segments,n(v.segments),k(v.segments),Ct(i,v.selectionStart,v.selectionEnd);return}if(y&&y.config.mode==="dropdown"&&G.length>0){if(s.key==="ArrowDown"){s.preventDefault(),U(i=>Math.min(i+1,G.length-1));return}if(s.key==="ArrowUp"){s.preventDefault(),U(i=>Math.max(i-1,0));return}if(s.key==="Enter"||s.key==="Tab"){s.preventDefault();let i=G[K];i&&Se(i);return}if(s.key==="Escape"){s.preventDefault(),$();return}}if(s.key===" "&&y&&y.config.resolveOnSpace&&y.query.trim().length>0){s.preventDefault(),ue(y);return}if(h&&s.key==="Tab"&&!y){let i=d$1.current;if(i){let l=S(),u=a$1(l),p=Ce(i);if(p!==null&&fe(u,p)){s.preventDefault();let H=s.shiftKey?pt(l,p):ft(l,p);H&&f(i,H);return}}}if(s.key==="Enter"&&s.shiftKey&&!s.nativeEvent.isComposing){s.preventDefault();let i$1=d$1.current;if(i$1){if(m(i$1))return;let l=Ue(i$1);if(l){let u=S();R.pushUndo(u);let p=i(u,l.start,l.end,`
13
+ `);f(i$1,{segments:p,cursorOffset:l.start+1});}}return}if(s.key==="Enter"&&!s.shiftKey&&!s.nativeEvent.isComposing){let i=d$1.current;if(i&&m(i)){s.preventDefault();return}if(t){s.preventDefault(),t(S());return}}if(s.key==="Escape"&&r){r();return}if((s.key==="Backspace"||s.key==="Delete")&&!s.nativeEvent.isComposing){let i$1=d$1.current;if(i$1){let l=Ue(i$1);if(l&&l.start!==l.end){s.preventDefault();let u=S();R.pushUndo(u);let p=i(u,l.start,l.end,"");f(i$1,{segments:p,cursorOffset:l.start}),M();return}}}if(s.key==="Backspace"){let i=d$1.current;if(i){let l=S(),u=Ce(i);if(h&&u!==null){let p=gt(l,u);if(p){s.preventDefault(),f(i,p),M();return}}}if(xe()){s.preventDefault(),M();return}}if(s.key==="Delete"&&ie()){s.preventDefault(),M();return}}},[y,G,K,t,r,S,n,k,h,$,xe,ie,ue,M,Se,R]),V=useMemo(()=>({focus:()=>d$1.current?.focus(),blur:()=>d$1.current?.blur(),insertChip:s=>{let f=S(),m={type:"chip",...s},i=[...f,m,{type:"text",text:" "}];n(i),k(i),c?.(m);},getPlainText:()=>a$1(S()),clear:()=>{n([]);let s=d$1.current;if(s)for(;s.firstChild;)s.removeChild(s.firstChild);R.resetUndoHistory(),D.current&&(clearTimeout(D.current),D.current=null),O.current=null;}}),[S,n,k,c,R]),He=useMemo(()=>({onPaste:R.handlePaste,onCopy:R.handleCopy,onCut:R.handleCut,onDrop:R.handleDrop,onDragOver:R.handleDragOver,onCompositionStart:R.handleCompositionStart,onCompositionEnd:R.handleCompositionEnd,onBlur:R.handleBlur}),[R.handlePaste,R.handleCopy,R.handleCut,R.handleDrop,R.handleDragOver,R.handleCompositionStart,R.handleCompositionEnd,R.handleBlur]);return {editorRef:d$1,activeTrigger:y,suggestions:G,suggestionsLoading:he,suggestionsError:ae,selectedSuggestionIndex:K,handleInput:se,handleKeyDown:q,handleClick:ee,selectSuggestion:We,dismissTrigger:$,handle:V,triggerRect:P,eventHandlers:He}}function It({suggestions:e,loading:n,error:o,emptyMessage:t,selectedIndex:r,onSelect:a$1,onDismiss:c,triggerRect:g,triggerChar:x}){let T=useRef(null),C=useRef(null);if(useEffect(()=>{C.current?.scrollIntoView({block:"nearest"});},[r]),useEffect(()=>{let d=y=>{let I=y.target;T.current&&I instanceof Node&&!T.current.contains(I)&&c();};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[c]),!g||e.length===0&&!n&&!o&&!t)return null;let E=Math.min(320,window.innerWidth-16),b=Math.min(g.left,window.innerWidth-E-8),h={position:"fixed",left:`${Math.max(8,b)}px`,top:`${g.bottom+4}px`,zIndex:50,maxWidth:`${E}px`};return jsx("div",{ref:T,className:a("max-h-[240px] min-w-[200px] overflow-y-auto","bg-popover rounded-xl border p-2 shadow-md","animate-in fade-in-0 zoom-in-95"),style:h,role:"listbox","aria-label":`${x} suggestions`,children:n?jsx("div",{role:"option","aria-selected":false,className:"text-muted-foreground px-3 py-2 text-sm",children:"Loading suggestions..."}):o?jsx("div",{role:"option","aria-selected":false,className:"text-destructive px-3 py-2 text-sm",children:o}):e.length===0&&t?jsx("div",{role:"option","aria-selected":false,className:"text-muted-foreground px-3 py-2 text-sm",children:t}):e.map((d,y)=>jsxs("button",{ref:y===r?C:void 0,type:"button",role:"option","aria-selected":y===r,className:a("text-foreground flex w-full items-start gap-2 rounded-lg px-3 py-2 text-left text-sm","hover:bg-accent cursor-pointer transition-colors",y===r&&"bg-accent"),onMouseDown:I=>{I.preventDefault(),a$1(d);},children:[d.icon&&jsx("span",{className:"mt-0.5 shrink-0",children:d.icon}),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:"truncate font-medium",children:d.label}),d.description&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:d.description})]})]},d.value))})}function Bt({texts:e,interval:n=3e3}){let[o,t]=useState(0);return useEffect(()=>{if(e.length<=1)return;let r=setInterval(()=>{t(a=>(a+1)%e.length);},n);return ()=>clearInterval(r)},[e.length,n]),jsx("div",{className:"pointer-events-none absolute top-0 left-0 overflow-hidden text-sm leading-relaxed select-none",style:{color:"var(--prompt-area-placeholder, var(--muted-foreground))"},"aria-hidden":"true",children:jsx("div",{className:"animate-in fade-in-0 slide-in-from-top-4 duration-300 ease-in-out",children:e[o]},o)})}function $e({onClick:e,label:n,className:o}){return jsx("button",{type:"button",onClick:t=>{t.stopPropagation(),e();},className:a("absolute top-0.5 right-0.5 grid h-3.5 w-3.5 cursor-pointer place-items-center","rounded-full bg-black/60 text-white hover:bg-black/80 dark:bg-white/60 dark:text-black dark:hover:bg-white/80","transition-colors",o),"aria-label":n,children:jsxs("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[jsx("line",{x1:"2.75",y1:"2.75",x2:"7.25",y2:"7.25"}),jsx("line",{x1:"7.25",y1:"2.75",x2:"2.75",y2:"7.25"})]})})}function Ut({images:e,onRemove:n,onClick:o,className:t}){return e.length===0?null:jsx("div",{className:a("flex flex-wrap gap-2",t),role:"list","aria-label":"Attached images",children:e.map(r=>jsxs("div",{role:"listitem",className:a("border-border relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md border",o&&"cursor-pointer"),onClick:()=>o?.(r),children:[jsx("img",{src:r.url,alt:r.alt??"Attached image",className:"h-full w-full object-cover"}),r.loading&&jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/40",children:jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent"})}),n&&jsx($e,{onClick:()=>n(r),label:`Remove ${r.alt??"image"}`})]},r.id))})}function Ae({className:e,children:n}){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:e,children:n})}var _e=jsxs(Fragment,{children:[jsx("path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}),jsx("path",{d:"M14 2v5a1 1 0 0 0 1 1h5"})]}),nn=({className:e})=>jsx(Ae,{className:e,children:_e}),rn=({className:e})=>jsxs(Ae,{className:e,children:[_e,jsx("path",{d:"M10 9H8"}),jsx("path",{d:"M16 13H8"}),jsx("path",{d:"M16 17H8"})]}),on=({className:e})=>jsxs(Ae,{className:e,children:[_e,jsx("path",{d:"M8 13h2"}),jsx("path",{d:"M14 13h2"}),jsx("path",{d:"M8 17h2"}),jsx("path",{d:"M14 17h2"})]}),sn=({className:e})=>jsxs(Ae,{className:e,children:[_e,jsx("path",{d:"M10 12.5 8 15l2 2.5"}),jsx("path",{d:"m14 12.5 2 2.5-2 2.5"})]}),ln=({className:e})=>jsxs(Ae,{className:e,children:[jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsx("circle",{cx:"9",cy:"9",r:"2"}),jsx("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]}),Ke=3;function an(e){return e?e==="application/pdf"?"pdf":e.includes("spreadsheet")||e==="text/csv"?"spreadsheet":e.startsWith("text/")||e.includes("javascript")||e.includes("json")||e.includes("xml")?"code":e.startsWith("image/")?"image":"default":"default"}var cn={pdf:rn,spreadsheet:on,code:sn,image:ln,default:nn};function un(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function dn(e){let n=e.lastIndexOf(".");return n===-1||n===e.length-1?null:e.slice(n+1).toUpperCase()}function Kt({file:e,compact:n,onRemove:o,onClick:t}){let r=dn(e.name),a$1=e.size!=null?un(e.size):null,c=[r,a$1].filter(Boolean).join(" \xB7 ");return jsxs("div",{role:"listitem",className:a("border-border relative flex flex-shrink-0 items-center gap-2 overflow-hidden rounded-lg border transition-colors","hover:bg-accent",n?"h-10 w-36 px-2":"h-14 w-48 px-3",t&&"cursor-pointer"),onClick:()=>t?.(e),children:[(()=>{let g=cn[an(e.type)];return jsx(g,{className:a("text-muted-foreground flex-shrink-0",n?"h-4 w-4":"h-5 w-5")})})(),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:a("truncate font-medium",n?"text-xs":"text-sm"),title:e.name,children:e.name}),!n&&c&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:c})]}),e.loading&&jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/40",children:jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent"})}),o&&jsx($e,{onClick:()=>o(e),label:`Remove ${e.name}`})]})}function _t({files:e,onRemove:n,onClick:o,className:t}){let[r,a$1]=useState(false),c=useRef(null),g=useRef(null);if(useEffect(()=>{if(!r)return;let b=h=>{let d=h.target;c.current&&!c.current.contains(d)&&!g.current?.contains(d)&&a$1(false);};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[r]),e.length===0)return null;let x=e.length>Ke,T=x,C=e.length-Ke,E=e.slice(0,Ke);return jsxs("div",{className:a("relative",t),children:[jsxs("div",{className:"flex flex-wrap gap-2",role:"list","aria-label":"Attached files",children:[(x?E:e).map(b=>jsx(Kt,{file:b,compact:T,onRemove:n,onClick:o},b.id)),x&&jsx("div",{role:"listitem",children:jsx("button",{ref:g,type:"button",onClick:()=>a$1(b=>!b),className:a("border-border text-muted-foreground hover:bg-accent flex flex-shrink-0 cursor-pointer items-center justify-center rounded-lg border transition-colors",T?"h-10 px-3 text-xs":"h-14 px-4 text-sm"),children:r?"Show less":`+${C} more`})})]}),r&&jsx("div",{ref:c,className:a("bg-popover border-border absolute bottom-full left-0 z-10 mb-2 max-h-48 overflow-y-auto rounded-lg border p-2 shadow-lg"),children:jsx("div",{className:"flex flex-wrap gap-2",role:"list","aria-label":"More attached files",children:e.slice(Ke).map(b=>jsx(Kt,{file:b,compact:T,onRemove:n,onClick:o},b.id))})})]})}function gr({value:e,onChange:n,triggers:o,placeholder:t,className:r,disabled:a$1=false,markdown:c,onSubmit:g,onEscape:x,onChipClick:T,onChipAdd:C,onChipDelete:E,onLinkClick:b,onPaste:h,onUndo:d,onRedo:y,minHeight:I=80,maxHeight:K,autoFocus:U=false,autoGrow:P=false,"aria-label":X,"data-test-id":G,images:he=[],imagePosition:ae="above",onImagePaste:ve,onImageRemove:oe,onImageClick:N,files:L=[],filePosition:D="above",onFileRemove:O,onFileClick:S,ref:k}){let{editorRef:M,activeTrigger:$,suggestions:R,suggestionsLoading:ce,suggestionsError:se,selectedSuggestionIndex:ee,handleInput:w,handleKeyDown:_,handleClick:xe,selectSuggestion:ie,dismissTrigger:ue,handle:Se,triggerRect:We,eventHandlers:q}=kt({value:e,onChange:n,triggers:o,onSubmit:g,onEscape:x,onChipClick:T,onChipAdd:C,onChipDelete:E,onLinkClick:b,onPaste:h,onUndo:d,onRedo:y,onImagePaste:ve,markdown:c});useImperativeHandle(k,()=>Se,[Se]),useEffect(()=>{U&&M.current?.focus();},[U,M]);let[V,He]=useState(false),[s,f]=useState(void 0),m=useCallback(()=>{let J=M.current;if(!J)return;J.style.height="auto";let de=J.scrollHeight;J.style.height=`${de}px`,f(de);},[M]),i=useCallback(()=>{P&&(He(true),m());},[P,m]),l=useCallback(()=>{q.onBlur(),P&&setTimeout(()=>{let J=M.current;if(!J)return;let de=document.activeElement;de&&J.parentElement?.contains(de)||(He(false),f(void 0));},Je);},[q,P,M]),u=useCallback(()=>{w(),P&&V&&m();},[w,P,V,m]);useEffect(()=>{P&&V&&requestAnimationFrame(()=>m());},[e,P,V,m]);let[p,v]=useState(false),H=useRef(null);useEffect(()=>{if(!P)return;let J=()=>{if(V){v(false);return}let Xe=M.current;Xe&&v(Xe.scrollHeight>Xe.clientHeight);},de=V?0:160;return H.current=setTimeout(J,de),()=>{H.current!==null&&clearTimeout(H.current);}},[P,V,e,M]);let z=useMemo(()=>P?{height:V&&s?`${s}px`:`${I}px`,minHeight:`${I}px`,maxHeight:"70dvh",overflowY:V?"auto":"hidden",transition:"height 150ms ease-out"}:{minHeight:`${I}px`,...K?{maxHeight:`${K}px`,overflowY:"auto"}:{}},[P,I,K,V,s]),Pe=e.length===0||e.length===1&&e[0].type==="text"&&e[0].text==="",be=he.length>0?jsx(Ut,{images:he,onRemove:oe,onClick:N,className:ae==="above"?"pb-2":"pt-2"}):null,Ie=L.length>0?jsx(_t,{files:L,onRemove:O,onClick:S,className:D==="above"?"pb-2":"pt-2"}):null;return jsxs("div",{className:a("prompt-area-container relative",r),children:[ae==="above"&&be,D==="above"&&Ie,jsxs("div",{className:"relative",children:[jsx("div",{ref:M,contentEditable:!a$1,suppressContentEditableWarning:true,role:"textbox","aria-label":X??"Text input","aria-multiline":"true","aria-disabled":a$1||void 0,"data-test-id":G,className:a("prompt-area-editor","w-full min-w-0 break-words whitespace-pre-wrap outline-none","text-sm leading-relaxed",a$1&&"cursor-not-allowed opacity-50"),style:z,onFocus:i,onInput:P?u:w,onKeyDown:_,onClick:xe,onPaste:q.onPaste,onCopy:q.onCopy,onCut:q.onCut,onDrop:q.onDrop,onDragOver:q.onDragOver,onCompositionStart:q.onCompositionStart,onCompositionEnd:q.onCompositionEnd,onBlur:P?l:q.onBlur}),P&&p&&!V&&jsx("div",{"aria-hidden":"true",className:"pointer-events-auto absolute right-0 bottom-0 left-0 cursor-pointer",style:{height:"32px"},onClick:()=>M.current?.focus(),children:jsx("div",{className:"h-full w-full",style:{background:"linear-gradient(to bottom, transparent, color-mix(in srgb, var(--prompt-area-surface, var(--background)) 80%, transparent), var(--prompt-area-surface, var(--background)))"}})}),Pe&&t&&(Array.isArray(t)?jsx(Bt,{texts:t}):jsx("div",{className:"pointer-events-none absolute top-0 left-0 text-sm leading-relaxed select-none",style:{color:"var(--prompt-area-placeholder, var(--muted-foreground))"},"aria-hidden":"true",children:t}))]}),D==="below"&&Ie,ae==="below"&&be,$&&$.config.mode==="dropdown"&&jsx(It,{suggestions:R,loading:ce,error:se,emptyMessage:$.config.emptyMessage,selectedIndex:ee,onSelect:ie,onDismiss:ue,triggerRect:We,triggerChar:$.config.char})]})}
14
+ export{Je as a,kt as b,gr as c};
@@ -0,0 +1,7 @@
1
+ function S(n){return n.map(t=>t.type==="text"?t.text:`${t.trigger}${t.displayText}`).join("")}function b(n){return n?[{type:"text",text:n}]:[]}function m(n,t,r){if(t===0)return true;let i=n[t-1];return r==="start"?i===`
2
+ `:i===" "||i===`
3
+ `||i===" "}function C(n,t,r){if(!n||t===0||r.length===0)return null;for(let i=t-1;i>=0;i--){let e=n[i];if(e===" "||e===`
4
+ `||e===" "){if(i+1<t){let g=n[i+1],p=r.find(u=>u.char===g);if(p&&m(n,i+1,p.position))return {config:p,startOffset:i+1,query:n.slice(i+2,t)}}return null}let s=r.find(g=>g.char===e);if(s&&m(n,i,s.position))return {config:s,startOffset:i,query:n.slice(i+1,t)}}return null}function w(n,t,r){let i=t.startOffset,e=i+1+t.query.length,s=[],g=0;for(let o of n)if(o.type==="chip"){let c=`${o.trigger}${o.displayText}`,a=g,h=g+c.length;(h<=i||a>=e)&&s.push(o),g=h;}else {let c=g,a=g+o.text.length;if(a<=i)s.push(o);else if(c>=e)s.push(o);else {let h=o.text.slice(0,Math.max(0,i-c)),T=o.text.slice(Math.min(o.text.length,e-c));h&&s.push({type:"text",text:h});let d={type:"chip",trigger:t.config.char,value:r.value,displayText:r.displayText,...r.data!==void 0?{data:r.data}:{},...r.autoResolved?{autoResolved:true}:{}};s.push(d),T?s.push({type:"text",text:" "+T.replace(/^\s/,"")}):s.push({type:"text",text:" "});}g=a;}let p=x(s),u=-1,l=0;for(let o of p)o.type==="text"?l+=o.text.length:(l+=o.trigger.length+o.displayText.length,o.value===r.value&&o.displayText===r.displayText&&o.trigger===t.config.char&&(u=l));let f=u===-1?l:u+1;return {segments:p,cursorOffset:f}}function O(n,t){if(t<0||t>=n.length||n[t].type!=="chip")return n;let r=[...n.slice(0,t),...n.slice(t+1)];return x(r)}function A(n,t){if(t<0||t>=n.length)return null;let r=n[t];if(r.type!=="chip"||!r.autoResolved)return null;let i=`${r.trigger}${r.displayText}`,e=[...n.slice(0,t),{type:"text",text:i},...n.slice(t+1)];return {segments:x(e),revertedText:i}}function M(n,t){let r=t.filter(s=>s.resolveOnSpace);if(r.length===0)return n;let i=new Set(r.map(s=>s.char)),e=[];for(let s of n){if(s.type==="chip"){e.push(s);continue}let g=v(s.text,r,i);e.push(...g);}return x(e)}function v(n,t,r){if(!n)return [];let i=[],e=0;for(;e<n.length;){let s=n[e];if(r.has(s)&&(e===0||n[e-1]===" "||n[e-1]===`
5
+ `||n[e-1]===" ")){let u=t.find(l=>l.char===s);if(u&&m(n,e,u.position)){let l=e+1;for(;l<n.length&&n[l]!==" "&&n[l]!==`
6
+ `&&n[l]!==" ";)l++;let f=n.slice(e+1,l);if(f.length>0){let o=u.onSelect?.({value:f,label:f})||f;i.push({type:"chip",trigger:s,value:f,displayText:o,autoResolved:true}),e=l;continue}}}let g=e;for(e++;e<n.length&&!(r.has(n[e])&&(n[e-1]===" "||n[e-1]===`
7
+ `||n[e-1]===" "));)e++;i.push({type:"text",text:n.slice(g,e)});}return i}function y(n,t,r,i){let e=[],s=0,g=false;for(let p of n)if(p.type==="chip"){let u=`${p.trigger}${p.displayText}`,l=s,f=s+u.length;!g&&t===r&&l===t&&(e.push({type:"text",text:i}),g=true),(f<=t||l>=r)&&e.push(p),s=f;}else {let u=s,l=s+p.text.length,f=t===r?l<t:l<=t,o=t===r?u>r:u>=r;if(f)e.push(p);else if(o)e.push(p);else {let c=p.text.slice(0,Math.max(0,t-u)),a=p.text.slice(Math.min(p.text.length,r-u));c&&e.push({type:"text",text:c}),!g&&u<=t&&(e.push({type:"text",text:i}),g=true),a&&e.push({type:"text",text:a});}s=l;}return !g&&i&&e.push({type:"text",text:i}),x(e)}function R(n,t,r,i){if(t===r)return null;let e=S(n),s=i.length,g=t>=s&&e.slice(t-s,t)===i,p=r+s<=e.length&&e.slice(r,r+s)===i,u=g&&p;if(u&&s===1){let o=t>s?e[t-s-1]:"",c=r+s<e.length?e[r+s]:"";(o===i||c===i)&&(u=false);}if(u){let o=y(n,r,r+s,"");return {segments:y(o,t-s,t,""),selectionStart:t-s,selectionEnd:r-s}}let l=y(n,r,r,i);return {segments:y(l,t,t,i),selectionStart:t+s,selectionEnd:r+s}}function $(n){if(!n)return [];let t=[],r=/(\*{3}(.+?)\*{3})|(\*{2}(.+?)\*{2})|(\*(.+?)\*)|(https?:\/\/[^\s),]+)/g,i=0,e;for(;(e=r.exec(n))!==null;)e.index>i&&t.push({type:"plain",text:n.slice(i,e.index)}),e[1]&&e[2]?t.push({type:"bold-italic",text:e[2]}):e[3]&&e[4]?t.push({type:"bold",text:e[4]}):e[5]&&e[6]?t.push({type:"italic",text:e[6]}):e[7]&&t.push({type:"url",text:e[7]}),i=e.index+e[0].length;return i<n.length&&t.push({type:"plain",text:n.slice(i)}),t}function k(n,t){if(n===t)return true;if(n.length!==t.length)return false;for(let r=0;r<n.length;r++){let i=n[r],e=t[r];if(i.type!==e.type)return false;if(i.type==="text"){if(e.type!=="text"||i.text!==e.text)return false}else if(e.type!=="chip"||i.trigger!==e.trigger||i.value!==e.value||i.displayText!==e.displayText||i.autoResolved!==e.autoResolved)return false}return true}function x(n){let t=[];for(let r of n){if(r.type==="text"&&r.text==="")continue;let i=t[t.length-1];r.type==="text"&&i?.type==="text"?t[t.length-1]={type:"text",text:i.text+r.text}:t.push(r);}return t}export{S as a,b,m as c,C as d,w as e,O as f,A as g,M as h,y as i,R as j,$ as k,k as l,x as m};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {jsxs,jsx}from'react/jsx-runtime';function c({left:e,right:t,className:o,disabled:a$1=false,"aria-label":n,"data-test-id":s,ref:p}){return jsxs("div",{ref:p,role:"toolbar","aria-label":n??"Action bar","aria-disabled":a$1||void 0,"data-test-id":s,className:a("action-bar","flex items-center justify-between gap-2 pt-2",a$1&&"pointer-events-none opacity-50",o),children:[e&&jsx("div",{className:"flex items-center gap-1",children:e}),t&&jsx("div",{className:"ml-auto flex items-center gap-1",children:t})]})}export{c as a};
@@ -1,6 +1,2 @@
1
1
  'use client';
2
- export { CompactPromptArea } from '../chunk-BPJO4DGM.js';
3
- import '../chunk-E7HUXORB.js';
4
- import '../chunk-NF2LHZIE.js';
5
- //# sourceMappingURL=index.js.map
6
- //# sourceMappingURL=index.js.map
2
+ export{a as CompactPromptArea}from'../chunk-2R57LWJO.js';import'../chunk-LJJ6HHR6.js';import'../chunk-23Y7B365.js';import'../chunk-MJSTEY4N.js';
@@ -1,187 +1,5 @@
1
- /**
2
- * PromptArea component types
3
- *
4
- * A lightweight contentEditable-based text input that supports:
5
- * - Trigger characters (/, @, #) that activate handlers
6
- * - Immutable chips for resolved mentions/commands
7
- * - Configurable trigger behavior (dropdown vs callback)
8
- * - Simple inline markdown rendering
9
- */
10
- /**
11
- * A segment of content within the editable text.
12
- * The document model is an ordered array of these segments.
13
- */
14
- type TextSegment = {
15
- type: 'text';
16
- text: string;
17
- };
18
- type ChipSegment = {
19
- type: 'chip';
20
- /** The trigger character that created this chip (e.g., '@', '#') */
21
- trigger: string;
22
- /** The resolved value/ID (e.g., user ID, file ID) */
23
- value: string;
24
- /** The display text shown in the chip */
25
- displayText: string;
26
- /** Optional data payload attached to the chip */
27
- data?: unknown;
28
- /**
29
- * True when this chip was auto-created by pressing space (resolveOnSpace).
30
- * Backspace on an auto-resolved chip reverts it to plain text instead of deleting.
31
- */
32
- autoResolved?: boolean;
33
- };
34
- type Segment = TextSegment | ChipSegment;
35
- /**
36
- * Determines where a trigger character is valid.
37
- * - 'start': Only valid at the very start of input or after a newline (e.g., slash commands)
38
- * - 'any': Valid after any whitespace boundary (e.g., @mentions)
39
- */
40
- type TriggerPosition = 'start' | 'any';
41
- /**
42
- * Defines how a trigger behaves when activated.
43
- * - 'dropdown': Shows a popover with suggestions from `onSearch`
44
- * - 'callback': Fires `onActivate` immediately without a dropdown
45
- */
46
- type TriggerMode = 'dropdown' | 'callback';
47
- /**
48
- * Visual style for rendered chips.
49
- * - 'pill': Button-like pill with background color, padding, border-radius (default)
50
- * - 'inline': Bold inline text that flows naturally with surrounding content
51
- */
52
- type ChipStyle = 'pill' | 'inline';
53
- /**
54
- * A suggestion item shown in the trigger dropdown.
55
- */
56
- type TriggerSuggestion = {
57
- /** Unique value/ID for this suggestion */
58
- value: string;
59
- /** Display label shown in the dropdown */
60
- label: string;
61
- /** Optional description shown below the label */
62
- description?: string;
63
- /** Optional icon element rendered before the label */
64
- icon?: React.ReactNode;
65
- /** Optional arbitrary data passed through on selection */
66
- data?: unknown;
67
- };
68
- /**
69
- * Configuration for a trigger character.
70
- */
71
- type TriggerConfig = {
72
- /** The trigger character (e.g., '/', '@', '#') */
73
- char: string;
74
- /** Where this trigger is valid */
75
- position: TriggerPosition;
76
- /** How this trigger behaves */
77
- mode: TriggerMode;
78
- /**
79
- * For 'dropdown' mode: called with the current query to fetch suggestions.
80
- * Should return a list of suggestions to display.
81
- *
82
- * Receives an options object with an `AbortSignal` that is aborted when a
83
- * newer search supersedes this one. Pass it to `fetch()` or other async
84
- * APIs to cancel in-flight work automatically.
85
- */
86
- onSearch?: (query: string, options: {
87
- signal: AbortSignal;
88
- }) => TriggerSuggestion[] | Promise<TriggerSuggestion[]>;
89
- /**
90
- * For 'dropdown' mode: called when a suggestion is selected.
91
- * Return the display text for the chip, or void to use `suggestion.label`.
92
- */
93
- onSelect?: (suggestion: TriggerSuggestion) => string | void;
94
- /**
95
- * For 'callback' mode: called when the trigger is activated.
96
- * Receives the full input text and cursor position.
97
- */
98
- onActivate?: (context: TriggerActivateContext) => void;
99
- /**
100
- * When true, pressing space while this trigger is active (with a non-empty query)
101
- * auto-resolves the typed text into a chip without selecting from the dropdown.
102
- * The auto-resolved chip can be reverted to plain text with backspace.
103
- * Useful for free-form tags (e.g., #hashtag).
104
- */
105
- resolveOnSpace?: boolean;
106
- /**
107
- * Visual style for chips created by this trigger.
108
- * - 'pill' (default): Button-like pill with background, padding, border-radius
109
- * - 'inline': Bold inline text without pill styling
110
- */
111
- chipStyle?: ChipStyle;
112
- /** CSS class name(s) applied to chips created by this trigger */
113
- chipClassName?: string;
114
- /** Label used for accessibility (e.g., "mention", "command") */
115
- accessibilityLabel?: string;
116
- /**
117
- * Debounce delay in milliseconds before calling `onSearch`.
118
- * Defaults to 0 (immediate). The initial empty-query search always fires
119
- * immediately regardless of this setting so the dropdown appears instantly.
120
- */
121
- searchDebounceMs?: number;
122
- /**
123
- * Called when `onSearch` rejects or throws (non-abort errors only).
124
- * Use this to log errors or show toast notifications.
125
- */
126
- onSearchError?: (error: unknown) => void;
127
- /**
128
- * Message shown in the dropdown when `onSearch` returns an empty array.
129
- * If omitted, the popover hides when there are no results (current behavior).
130
- */
131
- emptyMessage?: string;
132
- };
133
- /**
134
- * Context passed to callback-mode trigger handlers.
135
- */
136
- type TriggerActivateContext = {
137
- /** The full plain text content at the time of activation */
138
- text: string;
139
- /** The cursor offset position */
140
- cursorPosition: number;
141
- /** Function to insert a chip at the current cursor position */
142
- insertChip: (chip: Omit<ChipSegment, 'type'>) => void;
143
- };
144
- /**
145
- * Represents an active trigger being typed by the user.
146
- */
147
- type ActiveTrigger = {
148
- /** The trigger config that was activated */
149
- config: TriggerConfig;
150
- /** Position (character offset) where the trigger character was typed */
151
- startOffset: number;
152
- /** The text typed after the trigger character so far */
153
- query: string;
154
- };
155
- /**
156
- * An image attachment displayed in the prompt area.
157
- * State is managed externally by the parent component.
158
- */
159
- type PromptAreaImage = {
160
- /** Unique identifier for this image */
161
- id: string;
162
- /** URL to display (CDN URL or temporary blob URL for preview) */
163
- url: string;
164
- /** Optional alt text for accessibility */
165
- alt?: string;
166
- /** When true, shows a loading indicator over the thumbnail */
167
- loading?: boolean;
168
- };
169
- /**
170
- * A file attachment displayed in the prompt area.
171
- * State is managed externally by the parent component.
172
- */
173
- type PromptAreaFile = {
174
- /** Unique identifier for this file */
175
- id: string;
176
- /** Display filename (e.g., "report.pdf") */
177
- name: string;
178
- /** File size in bytes */
179
- size?: number;
180
- /** MIME type (used for icon selection, e.g., "application/pdf") */
181
- type?: string;
182
- /** When true, shows a loading indicator over the file card */
183
- loading?: boolean;
184
- };
1
+ import { f as TriggerConfig, A as ActiveTrigger, h as TriggerPosition, S as Segment, C as ChipSegment, T as TextSegment } from '../types-C4BgDEpe.js';
2
+ export { a as ChipStyle, P as PromptAreaFile, c as PromptAreaImage, e as TriggerActivateContext, g as TriggerMode, i as TriggerSuggestion } from '../types-C4BgDEpe.js';
185
3
 
186
4
  /**
187
5
  * Pure logic engine for the PromptArea component.
@@ -371,4 +189,4 @@ type CallbackTriggerOptions = Omit<Partial<TriggerConfig>, 'mode'> & {
371
189
  */
372
190
  declare function callbackTrigger(opts: CallbackTriggerOptions): TriggerConfig;
373
191
 
374
- export { type ActiveTrigger, type CallbackTriggerOptions, type ChipSegment, type ChipStyle, type CommandTriggerOptions, type HashtagTriggerOptions, type MarkdownToken, type MentionTriggerOptions, type PromptAreaFile, type PromptAreaImage, type Segment, type TextSegment, type TriggerActivateContext, type TriggerConfig, type TriggerMode, type TriggerPosition, type TriggerSuggestion, callbackTrigger, chip, commandTrigger, detectActiveTrigger, getChips, getChipsByTrigger, hasChips, hashtagTrigger, isSegmentsEmpty, isValidTriggerPosition, mentionTrigger, mergeAdjacentTextSegments, parseInlineMarkdown, plainTextToSegments, resolveChip, resolveTriggersInSegments, segmentsEqual, segmentsToPlainText, text };
192
+ export { ActiveTrigger, type CallbackTriggerOptions, ChipSegment, type CommandTriggerOptions, type HashtagTriggerOptions, type MarkdownToken, type MentionTriggerOptions, Segment, TextSegment, TriggerConfig, TriggerPosition, callbackTrigger, chip, commandTrigger, detectActiveTrigger, getChips, getChipsByTrigger, hasChips, hashtagTrigger, isSegmentsEmpty, isValidTriggerPosition, mentionTrigger, mergeAdjacentTextSegments, parseInlineMarkdown, plainTextToSegments, resolveChip, resolveTriggersInSegments, segmentsEqual, segmentsToPlainText, text };