prompt-area 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +5 -3
- package/dist/chunk-2R57LWJO.js +3 -0
- package/dist/chunk-3D4ZBBYY.js +2 -0
- package/dist/chunk-A6EFF4BI.js +1 -0
- package/dist/chunk-LJJ6HHR6.js +14 -0
- package/dist/chunk-MJSTEY4N.js +7 -0
- package/dist/compact-prompt-area/index.js +1 -1
- package/dist/helpers/index.d.ts +3 -185
- package/dist/helpers/index.js +1 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/prompt-area/index.d.ts +4 -191
- package/dist/prompt-area/index.js +1 -1
- package/package.json +3 -13
- package/dist/chunk-2DBBB352.js +0 -3
- package/dist/chunk-AUCRB7HL.js +0 -2
- package/dist/chunk-WBAKQRYT.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
All notable changes to the `prompt-area` package are documented here. This
|
|
4
4
|
project adheres to [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 0.3.2
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **Installs cleanly alongside Tailwind v3 (or no Tailwind).** `tailwindcss` and
|
|
11
|
+
`tw-animate-css` are no longer declared as (optional) peer dependencies — they
|
|
12
|
+
are build-time tools, and an optional peer still triggers an npm `ERESOLVE`
|
|
13
|
+
conflict when the consumer has a non-matching version (e.g. Tailwind v3)
|
|
14
|
+
installed. The prebuilt `prompt-area/styles.css` is self-contained and works
|
|
15
|
+
with any stack; the optional `prompt-area/tailwind.css` preset still requires
|
|
16
|
+
Tailwind v4 in your own project (documented, not version-gated). No API or
|
|
17
|
+
runtime changes.
|
|
18
|
+
|
|
19
|
+
## 0.3.1
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- **Smaller package** — the framework-agnostic engine is now emitted once as a
|
|
24
|
+
shared chunk instead of being bundled into both the components and the
|
|
25
|
+
`prompt-area/helpers` entry. The published tarball dropped from ~36 kB to
|
|
26
|
+
~33 kB (unpacked ~134 kB → ~117 kB), and the core `PromptArea` import is
|
|
27
|
+
~14 kB gzipped. No API changes.
|
|
28
|
+
|
|
29
|
+
## 0.3.0
|
|
30
|
+
|
|
31
|
+
First npm publish since `0.1.0`. `0.1.1` was tagged but never published, so
|
|
32
|
+
its packaging changes (listed below) reached npm as part of this release. No
|
|
33
|
+
`0.2.0` was ever released — the version jumped straight from `0.1.1` to `0.3.0`.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- Install docs now show `pnpm` / `npm` / `yarn` side by side and clarify that
|
|
38
|
+
`react` and `react-dom` are peer dependencies. No functional or API changes
|
|
39
|
+
versus `0.1.1`.
|
|
40
|
+
|
|
6
41
|
## 0.1.1
|
|
7
42
|
|
|
8
43
|
### Changed
|
package/README.md
CHANGED
|
@@ -111,9 +111,11 @@ The components are client components and carry a `'use client'` boundary, so you
|
|
|
111
111
|
## Dependencies
|
|
112
112
|
|
|
113
113
|
- **Peer:** `react`, `react-dom` (>= 18)
|
|
114
|
-
- **
|
|
115
|
-
|
|
116
|
-
`prompt-area/
|
|
114
|
+
- **Tailwind is not a peer dependency.** The prebuilt `prompt-area/styles.css`
|
|
115
|
+
is self-contained and works with **any** stack — Tailwind v4, v3, or no
|
|
116
|
+
Tailwind at all. The optional `prompt-area/tailwind.css` preset uses Tailwind
|
|
117
|
+
v4 syntax, so it requires Tailwind v4 in your own project; if you're on v3 or
|
|
118
|
+
not using Tailwind, use `styles.css` (and theme via the CSS variables above).
|
|
117
119
|
- **Runtime:** `clsx`, `tailwind-merge` — the two `cn` helpers, both already
|
|
118
120
|
present in any shadcn/Tailwind project.
|
|
119
121
|
|
|
@@ -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 @@
|
|
|
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,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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
export{a as CompactPromptArea}from'../chunk-
|
|
2
|
+
export{a as CompactPromptArea}from'../chunk-2R57LWJO.js';import'../chunk-LJJ6HHR6.js';import'../chunk-23Y7B365.js';import'../chunk-MJSTEY4N.js';
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,187 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 {
|
|
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 };
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`:i===" "||i===`
|
|
3
|
-
`||i===" "}function C(e,t,r){if(!e||t===0||r.length===0)return null;for(let i=t-1;i>=0;i--){let n=e[i];if(n===" "||n===`
|
|
4
|
-
`||n===" "){if(i+1<t){let s=e[i+1],a=r.find(l=>l.char===s);if(a&&m(e,i+1,a.position))return {config:a,startOffset:i+1,query:e.slice(i+2,t)}}return null}let g=r.find(s=>s.char===n);if(g&&m(e,i,g.position))return {config:g,startOffset:i,query:e.slice(i+1,t)}}return null}function b(e,t,r){let i=t.startOffset,n=i+1+t.query.length,g=[],s=0;for(let o of e)if(o.type==="chip"){let u=`${o.trigger}${o.displayText}`,h=s,f=s+u.length;(f<=i||h>=n)&&g.push(o),s=f;}else {let u=s,h=s+o.text.length;if(h<=i)g.push(o);else if(u>=n)g.push(o);else {let f=o.text.slice(0,Math.max(0,i-u)),T=o.text.slice(Math.min(o.text.length,n-u));f&&g.push({type:"text",text:f});let y={type:"chip",trigger:t.config.char,value:r.value,displayText:r.displayText,...r.data!==void 0?{data:r.data}:{},...r.autoResolved?{autoResolved:true}:{}};g.push(y),T?g.push({type:"text",text:" "+T.replace(/^\s/,"")}):g.push({type:"text",text:" "});}s=h;}let a=x(g),l=-1,p=0;for(let o of a)o.type==="text"?p+=o.text.length:(p+=o.trigger.length+o.displayText.length,o.value===r.value&&o.displayText===r.displayText&&o.trigger===t.config.char&&(l=p));let c=l===-1?p:l+1;return {segments:a,cursorOffset:c}}function O(e,t){let r=t.filter(g=>g.resolveOnSpace);if(r.length===0)return e;let i=new Set(r.map(g=>g.char)),n=[];for(let g of e){if(g.type==="chip"){n.push(g);continue}let s=v(g.text,r,i);n.push(...s);}return x(n)}function v(e,t,r){if(!e)return [];let i=[],n=0;for(;n<e.length;){let g=e[n];if(r.has(g)&&(n===0||e[n-1]===" "||e[n-1]===`
|
|
5
|
-
`||e[n-1]===" ")){let l=t.find(p=>p.char===g);if(l&&m(e,n,l.position)){let p=n+1;for(;p<e.length&&e[p]!==" "&&e[p]!==`
|
|
6
|
-
`&&e[p]!==" ";)p++;let c=e.slice(n+1,p);if(c.length>0){let o=l.onSelect?.({value:c,label:c})||c;i.push({type:"chip",trigger:g,value:c,displayText:o,autoResolved:true}),n=p;continue}}}let s=n;for(n++;n<e.length&&!(r.has(e[n])&&(e[n-1]===" "||e[n-1]===`
|
|
7
|
-
`||e[n-1]===" "));)n++;i.push({type:"text",text:e.slice(s,n)});}return i}function w(e){if(!e)return [];let t=[],r=/(\*{3}(.+?)\*{3})|(\*{2}(.+?)\*{2})|(\*(.+?)\*)|(https?:\/\/[^\s),]+)/g,i=0,n;for(;(n=r.exec(e))!==null;)n.index>i&&t.push({type:"plain",text:e.slice(i,n.index)}),n[1]&&n[2]?t.push({type:"bold-italic",text:n[2]}):n[3]&&n[4]?t.push({type:"bold",text:n[4]}):n[5]&&n[6]?t.push({type:"italic",text:n[6]}):n[7]&&t.push({type:"url",text:n[7]}),i=n.index+n[0].length;return i<e.length&&t.push({type:"plain",text:e.slice(i)}),t}function A(e,t){if(e===t)return true;if(e.length!==t.length)return false;for(let r=0;r<e.length;r++){let i=e[r],n=t[r];if(i.type!==n.type)return false;if(i.type==="text"){if(n.type!=="text"||i.text!==n.text)return false}else if(n.type!=="chip"||i.trigger!==n.trigger||i.value!==n.value||i.displayText!==n.displayText||i.autoResolved!==n.autoResolved)return false}return true}function x(e){let t=[];for(let r of e){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}function M(e){return {type:"text",text:e}}function k(e){return {type:"chip",...e}}function P(e){return e.length===0?true:e.every(t=>t.type==="text"&&t.text.trim()==="")}function R(e){return e.some(t=>t.type==="chip")}function $(e){return e.filter(t=>t.type==="chip")}function B(e,t){return e.filter(r=>r.type==="chip"&&r.trigger===t)}function I(e={}){let{char:t="@",...r}=e;return {char:t,position:"any",mode:"dropdown",chipStyle:"pill",accessibilityLabel:"mention",...r}}function q(e={}){let{char:t="/",...r}=e;return {char:t,position:"start",mode:"dropdown",chipStyle:"inline",accessibilityLabel:"command",...r}}function E(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{L as callbackTrigger,k as chip,q as commandTrigger,C as detectActiveTrigger,$ as getChips,B as getChipsByTrigger,R as hasChips,E as hashtagTrigger,P as isSegmentsEmpty,m as isValidTriggerPosition,I as mentionTrigger,x as mergeAdjacentTextSegments,w as parseInlineMarkdown,S as plainTextToSegments,b as resolveChip,O as resolveTriggersInSegments,A as segmentsEqual,d as segmentsToPlainText,M as text};
|
|
1
|
+
export{j as callbackTrigger,b as chip,h as commandTrigger,e as getChips,f as getChipsByTrigger,d as hasChips,i as hashtagTrigger,c as isSegmentsEmpty,g as mentionTrigger,a as text}from'../chunk-A6EFF4BI.js';export{d as detectActiveTrigger,c as isValidTriggerPosition,m as mergeAdjacentTextSegments,k as parseInlineMarkdown,b as plainTextToSegments,e as resolveChip,h as resolveTriggersInSegments,l as segmentsEqual,a as segmentsToPlainText}from'../chunk-MJSTEY4N.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { PromptArea, PromptAreaBind, PromptAreaState, UsePromptAreaStateOptions, usePromptArea, usePromptAreaState } from './prompt-area/index.js';
|
|
2
2
|
export { A as ActiveTrigger, C as ChipSegment, a as ChipStyle, P as PromptAreaFile, b as PromptAreaHandle, c as PromptAreaImage, d as PromptAreaProps, S as Segment, T as TextSegment, e as TriggerActivateContext, f as TriggerConfig, g as TriggerMode, h as TriggerPosition, i as TriggerSuggestion } from './types-C4BgDEpe.js';
|
|
3
|
+
export { CallbackTriggerOptions, CommandTriggerOptions, HashtagTriggerOptions, MarkdownToken, MentionTriggerOptions, callbackTrigger, chip, commandTrigger, detectActiveTrigger, getChips, getChipsByTrigger, hasChips, hashtagTrigger, isSegmentsEmpty, isValidTriggerPosition, mentionTrigger, mergeAdjacentTextSegments, parseInlineMarkdown, plainTextToSegments, resolveChip, resolveTriggersInSegments, segmentsEqual, segmentsToPlainText, text } from './helpers/index.js';
|
|
3
4
|
export { ActionBar, ActionBarProps } from './action-bar/index.js';
|
|
4
5
|
export { StatusBar, StatusBarProps } from './status-bar/index.js';
|
|
5
6
|
export { CompactPromptArea, CompactPromptAreaProps } from './compact-prompt-area/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
export{
|
|
2
|
+
export{a as usePromptAreaState}from'./chunk-3D4ZBBYY.js';export{a as ActionBar}from'./chunk-VULUMPYE.js';export{a as StatusBar}from'./chunk-6VISE4VA.js';export{a as CompactPromptArea}from'./chunk-2R57LWJO.js';export{c as PromptArea,b as usePromptArea}from'./chunk-LJJ6HHR6.js';export{a as ChatPromptLayout}from'./chunk-CRC4ST6U.js';import'./chunk-23Y7B365.js';export{j as callbackTrigger,b as chip,h as commandTrigger,e as getChips,f as getChipsByTrigger,d as hasChips,i as hashtagTrigger,c as isSegmentsEmpty,g as mentionTrigger,a as text}from'./chunk-A6EFF4BI.js';export{d as detectActiveTrigger,c as isValidTriggerPosition,m as mergeAdjacentTextSegments,k as parseInlineMarkdown,b as plainTextToSegments,e as resolveChip,h as resolveTriggersInSegments,l as segmentsEqual,a as segmentsToPlainText}from'./chunk-MJSTEY4N.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { d as PromptAreaProps, b as PromptAreaHandle, S as Segment, f as TriggerConfig, C as ChipSegment, A as ActiveTrigger, i as TriggerSuggestion
|
|
3
|
-
export { a as ChipStyle, P as PromptAreaFile, c as PromptAreaImage, e as TriggerActivateContext, g as TriggerMode } from '../types-C4BgDEpe.js';
|
|
2
|
+
import { d as PromptAreaProps, b as PromptAreaHandle, S as Segment, f as TriggerConfig, C as ChipSegment, A as ActiveTrigger, i as TriggerSuggestion } from '../types-C4BgDEpe.js';
|
|
3
|
+
export { a as ChipStyle, P as PromptAreaFile, c as PromptAreaImage, T as TextSegment, e as TriggerActivateContext, g as TriggerMode, h as TriggerPosition } from '../types-C4BgDEpe.js';
|
|
4
|
+
export { CallbackTriggerOptions, CommandTriggerOptions, HashtagTriggerOptions, MarkdownToken, MentionTriggerOptions, callbackTrigger, chip, commandTrigger, detectActiveTrigger, getChips, getChipsByTrigger, hasChips, hashtagTrigger, isSegmentsEmpty, isValidTriggerPosition, mentionTrigger, mergeAdjacentTextSegments, parseInlineMarkdown, plainTextToSegments, resolveChip, resolveTriggersInSegments, segmentsEqual, segmentsToPlainText, text } from '../helpers/index.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* PromptArea - A lightweight rich text input with trigger support.
|
|
@@ -136,192 +137,4 @@ type PromptAreaState = {
|
|
|
136
137
|
};
|
|
137
138
|
declare function usePromptAreaState(options?: UsePromptAreaStateOptions): PromptAreaState;
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
* Pure logic engine for the PromptArea component.
|
|
141
|
-
* No DOM dependencies - fully testable in Node.
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Converts an array of segments to a plain text string.
|
|
146
|
-
* Chips are represented as `{trigger}{displayText}` (e.g., "@Alice").
|
|
147
|
-
*/
|
|
148
|
-
declare function segmentsToPlainText(segments: Segment[]): string;
|
|
149
|
-
/**
|
|
150
|
-
* Converts plain text into a single text segment.
|
|
151
|
-
* Used for initial value conversion from plain strings.
|
|
152
|
-
*/
|
|
153
|
-
declare function plainTextToSegments(text: string): Segment[];
|
|
154
|
-
/**
|
|
155
|
-
* Checks whether a trigger character at the given position in text
|
|
156
|
-
* is valid according to the position rule.
|
|
157
|
-
*
|
|
158
|
-
* @param text - The full text content
|
|
159
|
-
* @param charIndex - The index of the trigger character in the text
|
|
160
|
-
* @param position - The position rule to validate against
|
|
161
|
-
*/
|
|
162
|
-
declare function isValidTriggerPosition(text: string, charIndex: number, position: TriggerPosition): boolean;
|
|
163
|
-
/**
|
|
164
|
-
* Scans backwards from the cursor position to detect if the user is
|
|
165
|
-
* currently typing a trigger word.
|
|
166
|
-
*
|
|
167
|
-
* Returns the active trigger info, or null if no trigger is active.
|
|
168
|
-
*
|
|
169
|
-
* @param text - The full plain text content
|
|
170
|
-
* @param cursorPos - The cursor position (character offset from start)
|
|
171
|
-
* @param triggers - Available trigger configurations
|
|
172
|
-
*/
|
|
173
|
-
declare function detectActiveTrigger(text: string, cursorPos: number, triggers: TriggerConfig[]): ActiveTrigger | null;
|
|
174
|
-
/**
|
|
175
|
-
* Resolves an active trigger into a chip within the segments array.
|
|
176
|
-
* Replaces the trigger text (trigger char + query) with a chip segment.
|
|
177
|
-
*
|
|
178
|
-
* @param segments - Current document segments
|
|
179
|
-
* @param activeTrigger - The active trigger to resolve
|
|
180
|
-
* @param chip - The chip data (value, displayText, optional data)
|
|
181
|
-
* @returns New segments array with the chip inserted, and the new cursor position
|
|
182
|
-
*/
|
|
183
|
-
declare function resolveChip(segments: Segment[], activeTrigger: ActiveTrigger, chip: {
|
|
184
|
-
value: string;
|
|
185
|
-
displayText: string;
|
|
186
|
-
data?: unknown;
|
|
187
|
-
autoResolved?: boolean;
|
|
188
|
-
}): {
|
|
189
|
-
segments: Segment[];
|
|
190
|
-
cursorOffset: number;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Scans text segments for trigger patterns and auto-resolves them into chips.
|
|
194
|
-
* Only resolves triggers that have `resolveOnSpace: true`.
|
|
195
|
-
*
|
|
196
|
-
* Trigger patterns must appear at word boundaries: start of text, after
|
|
197
|
-
* whitespace, or after a newline. This avoids false positives like email
|
|
198
|
-
* addresses (user@example.com).
|
|
199
|
-
*/
|
|
200
|
-
declare function resolveTriggersInSegments(segments: Segment[], triggers: TriggerConfig[]): Segment[];
|
|
201
|
-
type MarkdownToken = {
|
|
202
|
-
type: 'plain';
|
|
203
|
-
text: string;
|
|
204
|
-
} | {
|
|
205
|
-
type: 'bold';
|
|
206
|
-
text: string;
|
|
207
|
-
} | {
|
|
208
|
-
type: 'italic';
|
|
209
|
-
text: string;
|
|
210
|
-
} | {
|
|
211
|
-
type: 'bold-italic';
|
|
212
|
-
text: string;
|
|
213
|
-
} | {
|
|
214
|
-
type: 'url';
|
|
215
|
-
text: string;
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Parses text for simple inline markdown: bold, italic, bold-italic, and URLs.
|
|
219
|
-
* Does NOT handle block-level markdown (lists, headings, etc.).
|
|
220
|
-
*/
|
|
221
|
-
declare function parseInlineMarkdown(text: string): MarkdownToken[];
|
|
222
|
-
/**
|
|
223
|
-
* Shallow equality check for two segment arrays.
|
|
224
|
-
* Compares type, text, trigger, value, displayText, and autoResolved fields.
|
|
225
|
-
* Avoids JSON.stringify overhead for the common case.
|
|
226
|
-
*/
|
|
227
|
-
declare function segmentsEqual(a: Segment[], b: Segment[]): boolean;
|
|
228
|
-
/**
|
|
229
|
-
* Merges adjacent text segments into single text segments.
|
|
230
|
-
* Also removes empty text segments.
|
|
231
|
-
*/
|
|
232
|
-
declare function mergeAdjacentTextSegments(segments: Segment[]): Segment[];
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Convenience helpers for creating and inspecting Segments.
|
|
236
|
-
*
|
|
237
|
-
* These reduce boilerplate when building AI chat UIs that work with the
|
|
238
|
-
* PromptArea document model.
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```ts
|
|
242
|
-
* import { text, chip, isSegmentsEmpty, segmentsToPlainText } from './segment-helpers'
|
|
243
|
-
*
|
|
244
|
-
* const greeting = [text('Hello '), chip({ trigger: '@', value: 'u1', displayText: 'Alice' })]
|
|
245
|
-
* isSegmentsEmpty(greeting) // false
|
|
246
|
-
* segmentsToPlainText(greeting) // "Hello @Alice"
|
|
247
|
-
* ```
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
/** Create a text segment. */
|
|
251
|
-
declare function text(value: string): TextSegment;
|
|
252
|
-
/** Create a chip segment. */
|
|
253
|
-
declare function chip(opts: Omit<ChipSegment, 'type'>): ChipSegment;
|
|
254
|
-
/** Returns `true` when the segment array is empty or contains only whitespace text. */
|
|
255
|
-
declare function isSegmentsEmpty(segments: Segment[]): boolean;
|
|
256
|
-
/** Returns `true` when the segment array contains at least one chip. */
|
|
257
|
-
declare function hasChips(segments: Segment[]): boolean;
|
|
258
|
-
/** Extracts all chip segments from a segment array. */
|
|
259
|
-
declare function getChips(segments: Segment[]): ChipSegment[];
|
|
260
|
-
/** Extracts chips matching a specific trigger character. */
|
|
261
|
-
declare function getChipsByTrigger(segments: Segment[], trigger: string): ChipSegment[];
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Pre-built trigger configuration factories for common AI chat patterns.
|
|
265
|
-
*
|
|
266
|
-
* Each factory returns a full `TriggerConfig` with sensible defaults.
|
|
267
|
-
* Pass only what you need to override.
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```tsx
|
|
271
|
-
* <PromptArea
|
|
272
|
-
* triggers={[
|
|
273
|
-
* mentionTrigger({ onSearch: searchUsers }),
|
|
274
|
-
* commandTrigger({ onSearch: searchCommands }),
|
|
275
|
-
* hashtagTrigger(),
|
|
276
|
-
* ]}
|
|
277
|
-
* />
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
type TriggerPresetOptions = Omit<Partial<TriggerConfig>, 'char' | 'position' | 'mode'>;
|
|
282
|
-
type MentionTriggerOptions = TriggerPresetOptions & {
|
|
283
|
-
/** Override the trigger character. Defaults to `'@'`. */
|
|
284
|
-
char?: string;
|
|
285
|
-
};
|
|
286
|
-
/**
|
|
287
|
-
* Creates a **mention** trigger (`@`).
|
|
288
|
-
*
|
|
289
|
-
* Defaults: `position: 'any'`, `mode: 'dropdown'`, `chipStyle: 'pill'`,
|
|
290
|
-
* accessible label `"mention"`.
|
|
291
|
-
*/
|
|
292
|
-
declare function mentionTrigger(opts?: MentionTriggerOptions): TriggerConfig;
|
|
293
|
-
type CommandTriggerOptions = TriggerPresetOptions & {
|
|
294
|
-
/** Override the trigger character. Defaults to `'/'`. */
|
|
295
|
-
char?: string;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Creates a **command** trigger (`/`).
|
|
299
|
-
*
|
|
300
|
-
* Defaults: `position: 'start'`, `mode: 'dropdown'`, `chipStyle: 'inline'`,
|
|
301
|
-
* accessible label `"command"`.
|
|
302
|
-
*/
|
|
303
|
-
declare function commandTrigger(opts?: CommandTriggerOptions): TriggerConfig;
|
|
304
|
-
type HashtagTriggerOptions = TriggerPresetOptions & {
|
|
305
|
-
/** Override the trigger character. Defaults to `'#'`. */
|
|
306
|
-
char?: string;
|
|
307
|
-
};
|
|
308
|
-
/**
|
|
309
|
-
* Creates a **hashtag / tag** trigger (`#`).
|
|
310
|
-
*
|
|
311
|
-
* Defaults: `position: 'any'`, `mode: 'dropdown'`, `chipStyle: 'pill'`,
|
|
312
|
-
* `resolveOnSpace: true`, accessible label `"tag"`.
|
|
313
|
-
*/
|
|
314
|
-
declare function hashtagTrigger(opts?: HashtagTriggerOptions): TriggerConfig;
|
|
315
|
-
type CallbackTriggerOptions = Omit<Partial<TriggerConfig>, 'mode'> & {
|
|
316
|
-
/** The trigger character. Required. */
|
|
317
|
-
char: string;
|
|
318
|
-
};
|
|
319
|
-
/**
|
|
320
|
-
* Creates a **callback** trigger that fires `onActivate` instead of showing
|
|
321
|
-
* a dropdown. Useful for opening file pickers, model selectors, etc.
|
|
322
|
-
*
|
|
323
|
-
* Defaults: `position: 'start'`, `mode: 'callback'`.
|
|
324
|
-
*/
|
|
325
|
-
declare function callbackTrigger(opts: CallbackTriggerOptions): TriggerConfig;
|
|
326
|
-
|
|
327
|
-
export { ActiveTrigger, type CallbackTriggerOptions, ChipSegment, type CommandTriggerOptions, type HashtagTriggerOptions, type MarkdownToken, type MentionTriggerOptions, PromptArea, type PromptAreaBind, PromptAreaHandle, PromptAreaProps, type PromptAreaState, Segment, TextSegment, TriggerConfig, TriggerPosition, TriggerSuggestion, type UsePromptAreaStateOptions, callbackTrigger, chip, commandTrigger, detectActiveTrigger, getChips, getChipsByTrigger, hasChips, hashtagTrigger, isSegmentsEmpty, isValidTriggerPosition, mentionTrigger, mergeAdjacentTextSegments, parseInlineMarkdown, plainTextToSegments, resolveChip, resolveTriggersInSegments, segmentsEqual, segmentsToPlainText, text, usePromptArea, usePromptAreaState };
|
|
140
|
+
export { ActiveTrigger, ChipSegment, PromptArea, type PromptAreaBind, PromptAreaHandle, PromptAreaProps, type PromptAreaState, Segment, TriggerConfig, TriggerSuggestion, type UsePromptAreaStateOptions, usePromptArea, usePromptAreaState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
export{
|
|
2
|
+
export{a as usePromptAreaState}from'../chunk-3D4ZBBYY.js';export{c as PromptArea,b as usePromptArea}from'../chunk-LJJ6HHR6.js';import'../chunk-23Y7B365.js';export{j as callbackTrigger,b as chip,h as commandTrigger,e as getChips,f as getChipsByTrigger,d as hasChips,i as hashtagTrigger,c as isSegmentsEmpty,g as mentionTrigger,a as text}from'../chunk-A6EFF4BI.js';export{d as detectActiveTrigger,c as isValidTriggerPosition,m as mergeAdjacentTextSegments,k as parseInlineMarkdown,b as plainTextToSegments,e as resolveChip,h as resolveTriggersInSegments,l as segmentsEqual,a as segmentsToPlainText}from'../chunk-MJSTEY4N.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prompt-area",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "An opinionated, dependency-light React rich-text prompt input with trigger-based chips (@mentions, /commands, #tags), inline markdown, undo/redo, file & image attachments, and a complete chat-input layout. Ships as an npm package or a shadcn registry.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -79,17 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": ">=18",
|
|
82
|
-
"react-dom": ">=18"
|
|
83
|
-
"tailwindcss": ">=4",
|
|
84
|
-
"tw-animate-css": ">=1"
|
|
85
|
-
},
|
|
86
|
-
"peerDependenciesMeta": {
|
|
87
|
-
"tailwindcss": {
|
|
88
|
-
"optional": true
|
|
89
|
-
},
|
|
90
|
-
"tw-animate-css": {
|
|
91
|
-
"optional": true
|
|
92
|
-
}
|
|
82
|
+
"react-dom": ">=18"
|
|
93
83
|
},
|
|
94
84
|
"dependencies": {
|
|
95
85
|
"clsx": "^2.1.1",
|
|
@@ -106,7 +96,7 @@
|
|
|
106
96
|
"tailwindcss": "^4.3.0",
|
|
107
97
|
"tsup": "^8.5.0",
|
|
108
98
|
"tw-animate-css": "^1.4.0",
|
|
109
|
-
"typescript": "^
|
|
99
|
+
"typescript": "^6.0.3"
|
|
110
100
|
},
|
|
111
101
|
"publishConfig": {
|
|
112
102
|
"access": "public"
|
package/dist/chunk-2DBBB352.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {j,l}from'./chunk-WBAKQRYT.js';import {a}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$1=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$1,onPlusClick:p,submitButtonIcon:L,beforeSubmitSlot:M,maxHeight:j$1=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);},j);},[]),b=useCallback(()=>{d?.(t);},[d,t]);return jsx("div",{ref:m,onFocus:G,onBlur:V,"aria-label":D,"data-test-id":T,className:a("compact-prompt-area","bg-background border transition-all duration-200 ease-out",r?"rounded-2xl":"rounded-full",B),children:jsxs("div",{className:a("flex",r?"flex-col":"items-center p-1.5"),children:[!r&&jsx("button",{type:"button",onClick:p,disabled:a$1,className:a("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$1??jsx(v,{className:"size-4"})}),jsx("div",{className:a("min-w-0 flex-1",r?"px-5 pt-4 pb-2":"overflow-hidden px-3"),onClick:()=>i.current?.focus(),children:jsx(l,{ref:i,value:t,onChange:s,triggers:P,placeholder:k,disabled:a$1,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$1})}),jsxs("div",{className:a("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$1,className:a("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$1??jsx(v,{className:"size-4"})}),jsxs("div",{className:"flex items-center gap-1.5",children:[M,jsx("button",{type:"button",onClick:b,disabled:a$1||f,className:a("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};
|
package/dist/chunk-AUCRB7HL.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {a}from'./chunk-WBAKQRYT.js';import {useState,useRef,useMemo,useCallback}from'react';function C(e={}){let{initialValue:r=[]}=e,[t,s]=useState(r),n=useRef(null),a$1=useMemo(()=>a(t),[t]),m=useMemo(()=>t.length===0?true:t.every(i=>i.type==="text"&&i.text.trim()===""),[t]),c=useMemo(()=>t.some(i=>i.type==="chip"),[t]),l=useMemo(()=>t.filter(i=>i.type==="chip"),[t]),h=useMemo(()=>({ref:n,value:t,onChange:s}),[t]),T=useCallback(()=>{n.current?n.current.clear():s([]);},[]),u=useCallback(()=>n.current?.focus(),[]),x=useCallback(()=>n.current?.blur(),[]),f=useCallback(i=>n.current?.insertChip(i),[]);return {bind:h,plainText:a$1,isEmpty:m,hasChips:c,chips:l,clear:T,focus:u,blur:x,insertChip:f}}function d(e){return {type:"text",text:e}}function P(e){return {type:"chip",...e}}function O(e){return e.length===0?true:e.every(r=>r.type==="text"&&r.text.trim()==="")}function A(e){return e.some(r=>r.type==="chip")}function b(e){return e.filter(r=>r.type==="chip")}function v(e,r){return e.filter(t=>t.type==="chip"&&t.trigger===r)}function k(e={}){let{char:r="@",...t}=e;return {char:r,position:"any",mode:"dropdown",chipStyle:"pill",accessibilityLabel:"mention",...t}}function H(e={}){let{char:r="/",...t}=e;return {char:r,position:"start",mode:"dropdown",chipStyle:"inline",accessibilityLabel:"command",...t}}function M(e={}){let{char:r="#",...t}=e;return {char:r,position:"any",mode:"dropdown",chipStyle:"pill",resolveOnSpace:true,accessibilityLabel:"tag",...t}}function B(e){let{char:r,...t}=e;return {char:r,position:"start",mode:"callback",...t}}export{C as a,d as b,P as c,O as d,A as e,b as f,v as g,k as h,H as i,M as j,B as k};
|
package/dist/chunk-WBAKQRYT.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import {a}from'./chunk-23Y7B365.js';import {useRef,useState,useCallback,useEffect,useMemo,useImperativeHandle}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function Y(e){return e.map(n=>n.type==="text"?n.text:`${n.trigger}${n.displayText}`).join("")}function vn(e){return e?[{type:"text",text:e}]:[]}function qe(e,n,o){if(n===0)return true;let t=e[n-1];return o==="start"?t===`
|
|
3
|
-
`:t===" "||t===`
|
|
4
|
-
`||t===" "}function st(e,n,o){if(!e||n===0||o.length===0)return null;for(let t=n-1;t>=0;t--){let r=e[t];if(r===" "||r===`
|
|
5
|
-
`||r===" "){if(t+1<n){let a=e[t+1],u=o.find(g=>g.char===a);if(u&&qe(e,t+1,u.position))return {config:u,startOffset:t+1,query:e.slice(t+2,n)}}return null}let s=o.find(a=>a.char===r);if(s&&qe(e,t,s.position))return {config:s,startOffset:t,query:e.slice(t+1,n)}}return null}function Be(e,n,o){let t=n.startOffset,r=t+1+n.query.length,s=[],a=0;for(let m of e)if(m.type==="chip"){let S=`${m.trigger}${m.displayText}`,v=a,f=a+S.length;(f<=t||v>=r)&&s.push(m),a=f;}else {let S=a,v=a+m.text.length;if(v<=t)s.push(m);else if(S>=r)s.push(m);else {let f=m.text.slice(0,Math.max(0,t-S)),b=m.text.slice(Math.min(m.text.length,r-S));f&&s.push({type:"text",text:f});let P={type:"chip",trigger:n.config.char,value:o.value,displayText:o.displayText,...o.data!==void 0?{data:o.data}:{},...o.autoResolved?{autoResolved:true}:{}};s.push(P),b?s.push({type:"text",text:" "+b.replace(/^\s/,"")}):s.push({type:"text",text:" "});}a=v;}let u=fe(s),g=-1,p=0;for(let m of u)m.type==="text"?p+=m.text.length:(p+=m.trigger.length+m.displayText.length,m.value===o.value&&m.displayText===o.displayText&&m.trigger===n.config.char&&(g=p));let T=g===-1?p:g+1;return {segments:u,cursorOffset:T}}function it(e,n){if(n<0||n>=e.length||e[n].type!=="chip")return e;let o=[...e.slice(0,n),...e.slice(n+1)];return fe(o)}function lt(e,n){if(n<0||n>=e.length)return null;let o=e[n];if(o.type!=="chip"||!o.autoResolved)return null;let t=`${o.trigger}${o.displayText}`,r=[...e.slice(0,n),{type:"text",text:t},...e.slice(n+1)];return {segments:fe(r),revertedText:t}}function at(e,n){let o=n.filter(s=>s.resolveOnSpace);if(o.length===0)return e;let t=new Set(o.map(s=>s.char)),r=[];for(let s of e){if(s.type==="chip"){r.push(s);continue}let a=Xt(s.text,o,t);r.push(...a);}return fe(r)}function Xt(e,n,o){if(!e)return [];let t=[],r=0;for(;r<e.length;){let s=e[r];if(o.has(s)&&(r===0||e[r-1]===" "||e[r-1]===`
|
|
6
|
-
`||e[r-1]===" ")){let g=n.find(p=>p.char===s);if(g&&qe(e,r,g.position)){let p=r+1;for(;p<e.length&&e[p]!==" "&&e[p]!==`
|
|
7
|
-
`&&e[p]!==" ";)p++;let T=e.slice(r+1,p);if(T.length>0){let m=g.onSelect?.({value:T,label:T})||T;t.push({type:"chip",trigger:s,value:T,displayText:m,autoResolved:true}),r=p;continue}}}let a=r;for(r++;r<e.length&&!(o.has(e[r])&&(e[r-1]===" "||e[r-1]===`
|
|
8
|
-
`||e[r-1]===" "));)r++;t.push({type:"text",text:e.slice(a,r)});}return t}function W(e,n,o,t){let r=[],s=0,a=false;for(let u of e)if(u.type==="chip"){let g=`${u.trigger}${u.displayText}`,p=s,T=s+g.length;!a&&n===o&&p===n&&(r.push({type:"text",text:t}),a=true),(T<=n||p>=o)&&r.push(u),s=T;}else {let g=s,p=s+u.text.length,T=n===o?p<n:p<=n,m=n===o?g>o:g>=o;if(T)r.push(u);else if(m)r.push(u);else {let S=u.text.slice(0,Math.max(0,n-g)),v=u.text.slice(Math.min(u.text.length,o-g));S&&r.push({type:"text",text:S}),!a&&g<=n&&(r.push({type:"text",text:t}),a=true),v&&r.push({type:"text",text:v});}s=p;}return !a&&t&&r.push({type:"text",text:t}),fe(r)}function ct(e,n,o,t){if(n===o)return null;let r=Y(e),s=t.length,a=n>=s&&r.slice(n-s,n)===t,u=o+s<=r.length&&r.slice(o,o+s)===t,g=a&&u;if(g&&s===1){let m=n>s?r[n-s-1]:"",S=o+s<r.length?r[o+s]:"";(m===t||S===t)&&(g=false);}if(g){let m=W(e,o,o+s,"");return {segments:W(m,n-s,n,""),selectionStart:n-s,selectionEnd:o-s}}let p=W(e,o,o,t);return {segments:W(p,n,n,t),selectionStart:n+s,selectionEnd:o+s}}function yn(e){if(!e)return [];let n=[],o=/(\*{3}(.+?)\*{3})|(\*{2}(.+?)\*{2})|(\*(.+?)\*)|(https?:\/\/[^\s),]+)/g,t=0,r;for(;(r=o.exec(e))!==null;)r.index>t&&n.push({type:"plain",text:e.slice(t,r.index)}),r[1]&&r[2]?n.push({type:"bold-italic",text:r[2]}):r[3]&&r[4]?n.push({type:"bold",text:r[4]}):r[5]&&r[6]?n.push({type:"italic",text:r[6]}):r[7]&&n.push({type:"url",text:r[7]}),t=r.index+r[0].length;return t<e.length&&n.push({type:"plain",text:e.slice(t)}),n}function ut(e,n){if(e===n)return true;if(e.length!==n.length)return false;for(let o=0;o<e.length;o++){let t=e[o],r=n[o];if(t.type!==r.type)return false;if(t.type==="text"){if(r.type!=="text"||t.text!==r.text)return false}else if(r.type!=="chip"||t.trigger!==r.trigger||t.value!==r.value||t.displayText!==r.displayText||t.autoResolved!==r.autoResolved)return false}return true}function fe(e){let n=[];for(let o of e){if(o.type==="text"&&o.text==="")continue;let t=n[n.length-1];o.type==="text"&&t?.type==="text"?n[n.length-1]={type:"text",text:t.text+o.text}:n.push(o);}return n}function ge(e,n){let o=e.lastIndexOf(`
|
|
9
|
-
`,n-1)+1,t=e.indexOf(`
|
|
10
|
-
`,n),r=e.slice(o,t===-1?e.length:t),s=r.match(/^(\s*)([•\-*]) /);if(s){let u=s[1];return {lineStart:o,prefix:s[0],indent:Math.floor(u.length/2),listType:"bullet",contentStart:o+s[0].length}}let a=r.match(/^(\s*)(\d+)\. /);if(a){let u=a[1];return {lineStart:o,prefix:a[0],indent:Math.floor(u.length/2),listType:"numbered",number:parseInt(a[2],10),contentStart:o+a[0].length}}return null}function dt(e,n){let o=Y(e),t=o.lastIndexOf(`
|
|
11
|
-
`,n-1)+1,r=o.slice(t,n),s=r.match(/^(\s*)[-*] $/);if(!s)return null;let u=`${s[1]}\u2022 `,g=t,p=t+r.length;return {segments:W(e,g,p,u),cursorOffset:t+u.length}}function ft(e,n){let o=Y(e),t=ge(o,n);if(!t)return null;let r=o.indexOf(`
|
|
12
|
-
`,n);if(o.slice(t.contentStart,r===-1?o.length:r).trim()==="")return {segments:W(e,t.lineStart,t.lineStart+t.prefix.length,""),cursorOffset:t.lineStart};let a=" ".repeat(t.indent),u;if(t.listType==="bullet")u=`${a}\u2022 `;else {let T=(t.number??1)+1;u=`${a}${T}. `;}let g=`
|
|
13
|
-
${u}`;return {segments:W(e,n,n,g),cursorOffset:n+g.length}}function gt(e,n){let o=Y(e),t=ge(o,n);return t?{segments:W(e,t.lineStart,t.lineStart," "),cursorOffset:n+2}:null}function pt(e,n){let o=Y(e),t=ge(o,n);return !t||t.indent===0?null:{segments:W(e,t.lineStart,t.lineStart+2,""),cursorOffset:Math.max(t.lineStart,n-2)}}function mt(e,n){let o=Y(e),t=ge(o,n);return !t||n>t.contentStart?null:{segments:W(e,t.lineStart,t.contentStart," ".repeat(t.indent)),cursorOffset:t.lineStart+t.indent*2}}function je(e,n){let o=false,t=e.map(r=>{if(r.type!=="text")return r;let s=n?r.text.replace(/(^|\n)(\s*)- /g,"$1$2\u2022 "):r.text.replace(/(^|\n)(\s*)• /g,"$1$2- ");return s===r.text?r:(o=true,{...r,text:s})});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 me(e){return B(e)&&e.dataset.chipAutoResolved==="true"}function yt(e){return e instanceof HTMLAnchorElement&&e.dataset.url==="true"}function Vt(e){try{return JSON.parse(e)}catch{return}}function $e(e){try{return JSON.stringify(e)}catch{return}}function Se(e){if(B(e))return e.dataset.chipTrigger}function Re(e){if(B(e))return e.dataset.chipValue}function Ce(e){if(B(e))return e.dataset.chipDisplay??e.textContent??void 0}function De(e){if(!B(e))return;let n=e.dataset.chipData;if(n)return Vt(n)}function Me(e,n){let o=e.childNodes;for(let t=0;t<o.length;t++)if(o[t]===n)return t;return -1}function we(e,n){let o=n;for(;o!==null;){if(o.parentNode===e)return o;o=o.parentNode;}return null}function qt(e,n){let o=document.createDocumentFragment();for(;n.firstChild;)o.appendChild(n.firstChild);o.appendChild(document.createElement("br")),e.replaceChild(o,n);}function Oe(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 s=r.tagName;if(o.has(s))qt(e,r),n=true;else if(s==="FONT"||s==="B"||s==="I"||s==="U"||s==="STRONG"||s==="EM"||s==="A"||s==="SPAN"){let a=r.textContent??"";a?e.replaceChild(document.createTextNode(a),r):e.removeChild(r),n=true;}}return e.normalize(),n}var ht=/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??"";ht.lastIndex=0;let s=[],a;for(;(a=ht.exec(r))!==null;){let m=a[0];for(;m.length>0&&/[.;:!?]$/.test(m);)m=m.slice(0,-1);m.length>0&&s.push({url:m,index:a.index});}if(s.length===0)continue;let u=t.parentNode;if(!u)continue;let g=[];for(let{url:m,index:S}of s)try{let v=new URL(m);(v.protocol==="http:"||v.protocol==="https:")&&g.push({url:m,href:v.href,index:S});}catch{}if(g.length===0)continue;n=true;let p=document.createDocumentFragment(),T=0;for(let{url:m,href:S,index:v}of g){v>T&&p.appendChild(document.createTextNode(r.slice(T,v)));let f=document.createElement("a");f.href=S,f.target="_blank",f.rel="noopener noreferrer",f.dataset.url="true",f.className="text-primary hover:text-primary/80 underline cursor-pointer",f.textContent=m,p.appendChild(f),T=v+m.length;}T<r.length&&p.appendChild(document.createTextNode(r.slice(T))),u.replaceChild(p,t);}return n}var xt=/(\*{3})(.+?)\*{3}|(\*{2})(.+?)\*{2}|(\*)(.+?)\*/g;function Ye(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??"";xt.lastIndex=0;let s=[],a;for(;(a=xt.exec(r))!==null;)a[1]&&a[2]?s.push({fullMatch:a[0],marker:a[1],content:a[2],index:a.index,className:"font-bold italic"}):a[3]&&a[4]?s.push({fullMatch:a[0],marker:a[3],content:a[4],index:a.index,className:"font-bold"}):a[5]&&a[6]&&s.push({fullMatch:a[0],marker:a[5],content:a[6],index:a.index,className:"italic"});if(s.length===0)continue;n=true;let u=t.parentNode;if(!u)continue;let g=document.createDocumentFragment(),p=0;for(let{fullMatch:T,marker:m,content:S,index:v,className:f}of s){v>p&&g.appendChild(document.createTextNode(r.slice(p,v)));let b=document.createElement("span");b.dataset.md="true";let P=document.createElement("span");P.className="prompt-area-md-marker",P.textContent=m;let K=document.createElement("span");K.className=f,K.textContent=S;let $=document.createElement("span");$.className="prompt-area-md-marker",$.textContent=m,b.appendChild(P),b.appendChild(K),b.appendChild($),g.appendChild(b),p=v+T.length;}p<r.length&&g.appendChild(document.createTextNode(r.slice(p))),u.replaceChild(g,t);}return n}function X(){let e=window.getSelection();return !e||e.rangeCount===0?null:e.getRangeAt(0)}function Tt(e){let n=X();if(!n||!e.contains(n.startContainer))return null;let o=n.startContainer;if(o===e)return {nodeIndex:n.startOffset,offset:0};let t=we(e,o);return t?{nodeIndex:Me(e,t),offset:n.startOffset}:null}function St(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 s=t[t.length-1];s.nodeType===Node.TEXT_NODE?r.setStart(s,(s.textContent??"").length):r.setStartAfter(s);}else {let s=t[n.nodeIndex];if(s.nodeType===Node.TEXT_NODE){let a=(s.textContent??"").length;r.setStart(s,Math.min(n.offset,a));}else r.setStartAfter(s);}r.collapse(true),o.removeAllRanges(),o.addRange(r);}function be(e){let n=X();if(!n||!e.contains(n.startContainer))return null;let o=document.createRange();return o.selectNodeContents(e),o.setEnd(n.startContainer,n.startOffset),Le(o)}function Ct(e,n){let o=ke(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=ke(e,n);if(t){let s=document.createRange();s.setStart(t.node,t.offset),s.collapse(true),o.removeAllRanges(),o.addRange(s);return}let r=document.createRange();r.selectNodeContents(e),r.collapse(false),o.removeAllRanges(),o.addRange(r);}function Le(e){let n=e.cloneContents(),o=0,t=r=>{if(r.nodeType===Node.TEXT_NODE)o+=(r.textContent??"").length;else if(B(r)){let s=r.dataset.chipTrigger??"",a=r.dataset.chipDisplay??r.textContent??"";o+=s.length+a.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=X();if(!n||!e.contains(n.startContainer))return null;let o=document.createRange();o.selectNodeContents(e),o.setEnd(n.startContainer,n.startOffset);let t=Le(o);if(n.collapsed)return {start:t,end:t};let r=document.createRange();r.selectNodeContents(e),r.setEnd(n.endContainer,n.endOffset);let s=Le(r);return {start:t,end:s}}function bt(e,n,o){let t=window.getSelection();if(!t)return;if(n===o){ne(e,n);return}let r=ke(e,n),s=ke(e,o);if(!r||!s)return;let a=document.createRange();a.setStart(r.node,r.offset),a.setEnd(s.node,s.offset),t.removeAllRanges(),t.addRange(a);}function ke(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 s=(r.textContent??"").length;if(o<=s)return {node:r,offset:o};o-=s;}else if(B(r)){let s=r.dataset.chipTrigger??"",a=r.dataset.chipDisplay??r.textContent??"",u=s.length+a.length;if(o<=u)return {node:e,offset:t+1};o-=u;}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 s=(r.textContent??"").length;if(o<=s){let a=ke(r,o);if(a)return a}o-=s;}}return {node:e,offset:e.childNodes.length}}function jt(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=Se(t)??"",s=Ce(t)??"";n+=r+s;}else te(t)&&t.tagName==="BR"?n+=`
|
|
14
|
-
`:t.childNodes.forEach(o);};return e.childNodes.forEach(o),n}function Nt(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=Se(t),s=Re(t),a=Ce(t),u=De(t),g=me(t);if(r&&s!==void 0&&a){let p={type:"chip",trigger:r,value:s,displayText:a,...u!==void 0?{data:u}:{},...g?{autoResolved:true}:{}};n.push(p);}}else te(t)&&t.tagName==="BR"?n.push({type:"text",text:`
|
|
15
|
-
`}):t.childNodes.forEach(o);};return e.childNodes.forEach(o),n}function Rt(e){try{let n=JSON.parse(e);if(!Array.isArray(n))return null;let o=[];for(let t of n){if(!jt(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 Dt(e,n,o){let t=X();if(!t)return [...e,...n];let r=document.createRange();r.selectNodeContents(o),r.setEnd(t.startContainer,t.startOffset);let s=Le(r),a=[],u=0,g=false,p=()=>{g||(a.push(...n),g=true);};for(let T of e){if(T.type==="chip"){let S=T.trigger.length+T.displayText.length;u>=s&&p(),a.push(T),u+=S;continue}let m=u+T.text.length;if(m<=s)a.push(T);else if(u>=s)p(),a.push(T);else {let S=s-u,v=T.text.slice(0,S),f=T.text.slice(S);v&&a.push({type:"text",text:v}),p(),f&&a.push({type:"text",text:f});}u=m;}return p(),fe(a)}var Jt=100,Qe=150;function wt(e){let{editorRef:n,readSegmentsFromDOM:o,onChange:t,renderSegmentsToDOM:r,runTriggerDetection:s,dismissTrigger:a,triggers:u,onPaste:g,onUndo:p,onRedo:T,onChipAdd:m,onImagePaste:S}=e,v=useRef(false),f=useRef({undoStack:[],redoStack:[]}),b=useCallback(N=>{let w=f.current;w.undoStack.push(N),w.undoStack.length>Jt&&w.undoStack.shift(),w.redoStack=[];},[]),P=useCallback(()=>{f.current={undoStack:[],redoStack:[]};},[]),K=useCallback(N=>{N.preventDefault();let w=n.current;if(!w)return;let D=Array.from(N.clipboardData.files).find(O=>O.type.startsWith("image/"))??Array.from(N.clipboardData.items).find(_=>_.type.startsWith("image/"))?.getAsFile()??null;if(D){S?.(D);return}let L=o();b(L);let E=N.clipboardData.getData("text/prompt-area-segments");if(E){let O=Rt(E);if(O&&O.length>0){let _=X();if(!_)return;_.deleteContents();let ye=o(),ie=Dt(ye,O,w);t(ie),r(ie),g?.({segments:ie,source:"internal"});for(let ue of O)ue.type==="chip"&&m?.(ue);s();return}}let k=N.clipboardData.getData("text/plain");if(!k)return;let M=X();if(!M)return;M.deleteContents();let U=k.split(`
|
|
16
|
-
`),R=document.createDocumentFragment();for(let O=0;O<U.length;O++)U[O]&&R.appendChild(document.createTextNode(U[O])),O<U.length-1&&R.appendChild(document.createElement("br"));M.insertNode(R),M.collapse(false);let ce=window.getSelection();ce?.removeAllRanges(),ce?.addRange(M),Oe(w);let se=o(),ee=at(se,u);if(ee!==se){t(ee),r(ee);for(let O of ee)O.type==="chip"&&!se.some(_=>_.type==="chip"&&_.trigger===O.trigger&&_.value===O.value&&_.displayText===O.displayText)&&m?.(O);}else t(se);g?.({segments:ee,source:"external"}),s();},[n,o,t,b,s,r,u,g,m,S]),$=useCallback(N=>{N.preventDefault();let w=X();if(!w)return;let D=w.cloneContents(),L=Et(D);N.clipboardData.setData("text/plain",L);let E=Nt(D);if(E.some(M=>M.type==="chip")){let M=$e(E);M&&N.clipboardData.setData("text/prompt-area-segments",M);}},[]),I=useCallback(N=>{$(N);let w=X();if(!w)return;let D=o();b(D),w.deleteContents();let L=n.current;L&&Oe(L);let E=o();t(E),s();},[$,n,o,t,b,s]),V=useCallback(N=>{N.preventDefault();},[]),G=useCallback(N=>{N.preventDefault();},[]),xe=useCallback(()=>{v.current=true;},[]),ae=useCallback(()=>{v.current=false,s();},[s]),ve=useCallback(()=>{setTimeout(()=>{let N=n.current;if(!N)return;let w=document.activeElement;w&&N.parentElement?.contains(w)||a();},Qe);},[n,a]),oe=useCallback(N=>{if(!(N.metaKey||N.ctrlKey)||N.key!=="z")return false;N.preventDefault();let D=f.current;if(N.shiftKey){if(D.redoStack.length===0)return true;let L=D.redoStack.pop();if(!L)return true;let E=o();D.undoStack.push(E),t(L),r(L),T?.(L);}else {if(D.undoStack.length===0)return true;let L=D.undoStack.pop();if(!L)return true;let E=o();D.redoStack.push(E),t(L),r(L),p?.(L);}return true},[o,t,r,p,T]);return {handlePaste:K,handleCopy:$,handleCut:I,handleDrop:V,handleDragOver:G,handleCompositionStart:xe,handleCompositionEnd:ae,handleBlur:ve,handleKeyDownForUndoRedo:oe,pushUndo:b,resetUndoHistory:P,isComposing:v}}function Lt(){let[e,n]=useState([]),[o,t]=useState(false),[r,s]=useState(null),a=useRef(0),u=useRef(null),g=useRef(null),p=useCallback(()=>{u.current?.abort(),g.current&&clearTimeout(g.current),n([]),t(false),s(null);},[]),T=useCallback((m,S)=>{if(!S.onSearch)return;u.current?.abort(),g.current&&clearTimeout(g.current),t(true),s(null),a.current++;let v=a.current,f=new AbortController;u.current=f;let{onSearch:b,onSearchError:P,searchDebounceMs:K}=S,$=()=>{let I=b(m,{signal:f.signal});I instanceof Promise?I.then(V=>{f.signal.aborted||a.current!==v||(n(V),t(false));},V=>{f.signal.aborted||a.current!==v||V instanceof DOMException&&V.name==="AbortError"||(s(V instanceof Error?V.message:"Search failed"),t(false),P?.(V));}):(n(I),t(false));};K&&K>0&&m.length>0?g.current=setTimeout($,K):$();},[]);return useEffect(()=>()=>{u.current?.abort(),g.current&&clearTimeout(g.current);},[]),{suggestions:e,suggestionsLoading:o,suggestionsError:r,search:T,reset:p}}var Qt=300;function At({value:e,onChange:n,triggers:o=[],onSubmit:t,onEscape:r,onChipClick:s,onChipAdd:a$1,onChipDelete:u,onLinkClick:g,onPaste:p,onUndo:T,onRedo:m,onImagePaste:S,markdown:v=true}){let f=useRef(null),[b,P]=useState(null),[K,$]=useState(0),[I,V]=useState(null),{suggestions:G,suggestionsLoading:xe,suggestionsError:ae,search:ve,reset:oe}=Lt(),N=useRef(false),w=useRef([]),D=useRef(null),L=useRef(null),E=useCallback(()=>{let i=f.current;if(!i)return [];let h=[];for(let y=0;y<i.childNodes.length;y++){let l=i.childNodes[y];if(l.nodeType===Node.TEXT_NODE){let c=l.textContent??"";c&&h.push({type:"text",text:c});}else if(B(l)){let c=Se(l),d=Re(l),x=Ce(l),C=De(l);if(c&&d!==void 0&&x){let H=me(l);h.push({type:"chip",trigger:c,value:d,displayText:x,...C!==void 0?{data:C}:{},...H?{autoResolved:true}:{}});}}else if(pe(l)){if(l.dataset.sentinel)continue;h.push({type:"text",text:`
|
|
17
|
-
`});}else if(te(l)){let c=l.textContent??"";c&&h.push({type:"text",text:c});}}return h},[]),k=useCallback(i=>{let h=f.current;if(!h)return;N.current=true;let y=Tt(h);for(;h.firstChild;)h.removeChild(h.firstChild);for(let l of i)if(l.type==="text"){let c=l.text.split(`
|
|
18
|
-
`);for(let d=0;d<c.length;d++)c[d]&&h.appendChild(document.createTextNode(c[d])),d<c.length-1&&h.appendChild(document.createElement("br"));}else {let c=document.createElement("span");if(c.contentEditable="false",c.dataset.chipTrigger=l.trigger,c.dataset.chipValue=l.value,c.dataset.chipDisplay=l.displayText,l.data!==void 0){let C=$e(l.data);C&&(c.dataset.chipData=C);}l.autoResolved&&(c.dataset.chipAutoResolved="true");let d=o.find(C=>C.char===l.trigger),x=d?.chipStyle??"pill";c.dataset.chipStyle=x,c.className=a("prompt-area-chip",x==="inline"&&"prompt-area-chip--inline",d?.chipClassName),c.textContent=`${l.trigger}${l.displayText}`,c.setAttribute("role","button"),c.setAttribute("tabindex","-1"),h.appendChild(c);}if(h.lastChild&&pe(h.lastChild)){let l=document.createElement("br");l.dataset.sentinel="true",h.appendChild(l);}Je(h),v&&Ye(h),y&&St(h,y),w.current=i,N.current=false;},[o,v]),M=useCallback(()=>{let i=f.current;if(!i)return;let h=E(),y=Y(h),l=be(i);if(l===null)return;let c=st(y,l,o);if(c){P(c),$(0);let d=Ct(i,c.startOffset);if(d){let x=d.getBoundingClientRect();(x.height>0||x.left>0||x.top>0)&&V(x);}c.config.mode==="dropdown"&&c.config.onSearch&&ve(c.query,c.config),c.config.mode==="callback"&&c.config.onActivate&&c.config.onActivate({text:y,cursorPosition:l,insertChip:x=>{let C=Be(h,c,{value:x.value,displayText:x.displayText,data:x.data});n(C.segments),k(C.segments),a$1?.({type:"chip",trigger:c.config.char,value:x.value,displayText:x.displayText,...x.data!==void 0?{data:x.data}:{}});let H=f.current;H&&ne(H,C.cursorOffset);}});}else P(null),oe();},[o,E,n,k,a$1,oe,ve]),U=useCallback(()=>{P(null),$(0),oe();},[oe]),R=wt({editorRef:f,readSegmentsFromDOM:E,onChange:n,renderSegmentsToDOM:k,runTriggerDetection:M,dismissTrigger:U,triggers:o,onPaste:p,onUndo:T,onRedo:m,onChipAdd:a$1,onImagePaste:S});useEffect(()=>{if(!N.current&&!ut(e,w.current)){if(v){let i=je(e,true);if(i!==e){n(i);return}}k(e);}},[e,k,v,n]);let ce=useRef(v);useEffect(()=>{if(ce.current===v)return;ce.current=v;let i=je(e,v);i!==e?n(i):k(e);},[v,k,e,n]),useEffect(()=>()=>{D.current&&clearTimeout(D.current);},[]);let se=useCallback(()=>{if(N.current)return;if(R.isComposing.current){let l=E();w.current=l,n(l);return}let i=f.current,h=i?be(i):null;i&&Oe(i);let y=E();if(v&&i&&h!==null){let l=dt(y,h);if(l){w.current=l.segments,n(l.segments),k(l.segments),ne(i,l.cursorOffset),M();return}}L.current||(L.current=w.current),w.current=y,n(y),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{L.current&&(R.pushUndo(L.current),L.current=null),D.current=null;},Qt),i&&(Je(i),v&&Ye(i),h!==null&&ne(i,h)),M();},[n,E,M,k,v,R]),ee=useCallback(i=>{let h=i.target;if(!(h instanceof Node))return;let y=f.current;if(!y)return;let l=h;for(;l&&l!==y;){if(yt(l)){if(i.metaKey||i.ctrlKey){i.preventDefault(),g?.(l.href),window.open(l.href,"_blank","noopener,noreferrer");return}break}if(B(l)){let c=l,d=c.getBoundingClientRect(),x=document.createElement("span");x.className="prompt-area-chip-ripple";let C=Math.max(d.width,d.height);if(x.style.width=`${C}px`,x.style.height=`${C}px`,x.style.left=`${i.clientX-d.left-C/2}px`,x.style.top=`${i.clientY-d.top-C/2}px`,c.appendChild(x),x.addEventListener("animationend",()=>x.remove()),!s)return;let H=Se(l),z=Re(l),Ie=Ce(l),Ne=De(l);if(H&&z!==void 0&&Ie){let Fe=me(l),Q={type:"chip",trigger:H,value:z,displayText:Ie,...Ne!==void 0?{data:Ne}:{},...Fe?{autoResolved:true}:{}};s(Q);}return}l=l.parentNode;}},[s,g]),O=useCallback((i,h)=>{let y=E(),l=Me(i,h);if(l===-1)return false;let c=0;for(let C=0;C<l;C++){let H=i.childNodes[C];(H.nodeType===Node.TEXT_NODE&&(H.textContent??"")!==""||B(H)||pe(H))&&c++;}let d=y[c],x=it(y,c);return n(x),k(x),d?.type==="chip"&&u?.(d),true},[E,n,k,u]),_=useCallback((i,h)=>{let y=E(),l=Me(i,h);if(l===-1)return false;let c=0;for(let H=0;H<l;H++){let z=i.childNodes[H];(z.nodeType===Node.TEXT_NODE&&(z.textContent??"")!==""||B(z)||pe(z))&&c++;}let d=y[c],x=lt(y,c);if(!x)return false;let C=0;for(let H=0;H<c;H++){let z=y[H];z.type==="text"?C+=z.text.length:C+=z.trigger.length+z.displayText.length;}return C+=x.revertedText.length,n(x.segments),k(x.segments),ne(i,C),d?.type==="chip"&&u?.(d),true},[E,n,k,u]),ye=useCallback(()=>{let i=f.current;if(!i)return false;let h=X();if(!h||!h.collapsed)return false;let y=h.startContainer,l=h.startOffset;if(y===i&&l>0){let c=i.childNodes[l-1];if(c&&B(c))return me(c)?_(i,c):O(i,c)}if(y.nodeType===Node.TEXT_NODE&&l===0){let c=we(i,y);if(!c)return false;let d=c.previousSibling;for(;d&&d.nodeType===Node.TEXT_NODE&&d.textContent==="";)d=d.previousSibling;if(d&&B(d))return me(d)?_(i,d):O(i,d)}return false},[O,_]),ie=useCallback(()=>{let i=f.current;if(!i)return false;let h=X();if(!h||!h.collapsed)return false;let y=h.startContainer,l=h.startOffset;if(y===i&&l<i.childNodes.length){let c=i.childNodes[l];if(c&&B(c))return O(i,c)}if(y.nodeType===Node.TEXT_NODE&&l===(y.textContent??"").length){let c=we(i,y);if(!c)return false;let d=c.nextSibling;for(;d&&d.nodeType===Node.TEXT_NODE&&d.textContent==="";)d=d.nextSibling;if(d&&B(d))return O(i,d)}return false},[O]),ue=useCallback(i=>{let h=E(),y=i.query,l={value:y,label:y},c=i.config.onSelect?.(l)??y,d={value:y,displayText:c||y,autoResolved:true},x=Be(h,i,d);n(x.segments),k(x.segments),a$1?.({type:"chip",trigger:i.config.char,...d});let C=f.current;C&&ne(C,x.cursorOffset),U();},[E,n,k,U,a$1]),Te=useCallback(i=>{if(!b)return;let h=E(),y=b.config.onSelect?.(i)??i.label,l={value:i.value,displayText:y||i.label,data:i.data},c=Be(h,b,l);n(c.segments),k(c.segments),a$1?.({type:"chip",trigger:b.config.char,...l});let d=f.current;d&&ne(d,c.cursorOffset),U(),setTimeout(()=>{f.current?.focus();},0);},[b,E,n,k,U,a$1]),Xe=Te,J=useCallback(i=>{let h=(l,c)=>{w.current=c.segments,n(c.segments),k(c.segments),ne(l,c.cursorOffset);},y=l=>{if(!v)return false;let c=E(),d=be(l);if(d===null)return false;let x=Y(c);if(!ge(x,d))return false;let C=ft(c,d);return C&&h(l,C),true};if((i.metaKey||i.ctrlKey)&&i.key==="z"&&L.current&&(D.current&&(clearTimeout(D.current),D.current=null),R.pushUndo(L.current),L.current=null),!R.handleKeyDownForUndoRedo(i)){if(v&&(i.metaKey||i.ctrlKey)&&!i.shiftKey&&(i.key==="b"||i.key==="i")){i.preventDefault();let l=f.current;if(!l)return;let c=Ue(l);if(!c||c.start===c.end)return;let d=i.key==="b"?"**":"*",x=E();R.pushUndo(x);let C=ct(x,c.start,c.end,d);if(!C)return;w.current=C.segments,n(C.segments),k(C.segments),bt(l,C.selectionStart,C.selectionEnd);return}if(b&&b.config.mode==="dropdown"&&G.length>0){if(i.key==="ArrowDown"){i.preventDefault(),$(l=>Math.min(l+1,G.length-1));return}if(i.key==="ArrowUp"){i.preventDefault(),$(l=>Math.max(l-1,0));return}if(i.key==="Enter"||i.key==="Tab"){i.preventDefault();let l=G[K];l&&Te(l);return}if(i.key==="Escape"){i.preventDefault(),U();return}}if(i.key===" "&&b&&b.config.resolveOnSpace&&b.query.trim().length>0){i.preventDefault(),ue(b);return}if(v&&i.key==="Tab"&&!b){let l=f.current;if(l){let c=E(),d=Y(c),x=be(l);if(x!==null&&ge(d,x)){i.preventDefault();let H=i.shiftKey?pt(c,x):gt(c,x);H&&h(l,H);return}}}if(i.key==="Enter"&&i.shiftKey&&!i.nativeEvent.isComposing){i.preventDefault();let l=f.current;if(l){if(y(l))return;let c=Ue(l);if(c){let d=E();R.pushUndo(d);let x=W(d,c.start,c.end,`
|
|
19
|
-
`);h(l,{segments:x,cursorOffset:c.start+1});}}return}if(i.key==="Enter"&&!i.shiftKey&&!i.nativeEvent.isComposing){let l=f.current;if(l&&y(l)){i.preventDefault();return}if(t){i.preventDefault(),t(E());return}}if(i.key==="Escape"&&r){r();return}if((i.key==="Backspace"||i.key==="Delete")&&!i.nativeEvent.isComposing){let l=f.current;if(l){let c=Ue(l);if(c&&c.start!==c.end){i.preventDefault();let d=E();R.pushUndo(d);let x=W(d,c.start,c.end,"");h(l,{segments:x,cursorOffset:c.start}),M();return}}}if(i.key==="Backspace"){let l=f.current;if(l){let c=E(),d=be(l);if(v&&d!==null){let x=mt(c,d);if(x){i.preventDefault(),h(l,x),M();return}}}if(ye()){i.preventDefault(),M();return}}if(i.key==="Delete"&&ie()){i.preventDefault(),M();return}}},[b,G,K,t,r,E,n,k,v,U,ye,ie,ue,M,Te,R]),q=useMemo(()=>({focus:()=>f.current?.focus(),blur:()=>f.current?.blur(),insertChip:i=>{let h=E(),y={type:"chip",...i},l=[...h,y,{type:"text",text:" "}];n(l),k(l),a$1?.(y);},getPlainText:()=>Y(E()),clear:()=>{n([]);let i=f.current;if(i)for(;i.firstChild;)i.removeChild(i.firstChild);R.resetUndoHistory(),D.current&&(clearTimeout(D.current),D.current=null),L.current=null;}}),[E,n,k,a$1,R]),Pe=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:f,activeTrigger:b,suggestions:G,suggestionsLoading:xe,suggestionsError:ae,selectedSuggestionIndex:K,handleInput:se,handleKeyDown:J,handleClick:ee,selectSuggestion:Xe,dismissTrigger:U,handle:q,triggerRect:I,eventHandlers:Pe}}function Ft({suggestions:e,loading:n,error:o,emptyMessage:t,selectedIndex:r,onSelect:s,onDismiss:a$1,triggerRect:u,triggerChar:g}){let p=useRef(null),T=useRef(null);if(useEffect(()=>{T.current?.scrollIntoView({block:"nearest"});},[r]),useEffect(()=>{let f=b=>{let P=b.target;p.current&&P instanceof Node&&!p.current.contains(P)&&a$1();};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[a$1]),!u||e.length===0&&!n&&!o&&!t)return null;let m=Math.min(320,window.innerWidth-16),S=Math.min(u.left,window.innerWidth-m-8),v={position:"fixed",left:`${Math.max(8,S)}px`,top:`${u.bottom+4}px`,zIndex:50,maxWidth:`${m}px`};return jsx("div",{ref:p,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:v,role:"listbox","aria-label":`${g} 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((f,b)=>jsxs("button",{ref:b===r?T:void 0,type:"button",role:"option","aria-selected":b===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",b===r&&"bg-accent"),onMouseDown:P=>{P.preventDefault(),s(f);},children:[f.icon&&jsx("span",{className:"mt-0.5 shrink-0",children:f.icon}),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:"truncate font-medium",children:f.label}),f.description&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:f.description})]})]},f.value))})}function $t({texts:e,interval:n=3e3}){let[o,t]=useState(0);return useEffect(()=>{if(e.length<=1)return;let r=setInterval(()=>{t(s=>(s+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 Ke({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(Ke,{onClick:()=>n(r),label:`Remove ${r.alt??"image"}`})]},r.id))})}function He({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 ze=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"})]}),on=({className:e})=>jsx(He,{className:e,children:ze}),sn=({className:e})=>jsxs(He,{className:e,children:[ze,jsx("path",{d:"M10 9H8"}),jsx("path",{d:"M16 13H8"}),jsx("path",{d:"M16 17H8"})]}),ln=({className:e})=>jsxs(He,{className:e,children:[ze,jsx("path",{d:"M8 13h2"}),jsx("path",{d:"M14 13h2"}),jsx("path",{d:"M8 17h2"}),jsx("path",{d:"M14 17h2"})]}),an=({className:e})=>jsxs(He,{className:e,children:[ze,jsx("path",{d:"M10 12.5 8 15l2 2.5"}),jsx("path",{d:"m14 12.5 2 2.5-2 2.5"})]}),cn=({className:e})=>jsxs(He,{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"})]}),_e=3;function un(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 dn={pdf:sn,spreadsheet:ln,code:an,image:cn,default:on};function fn(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 gn(e){let n=e.lastIndexOf(".");return n===-1||n===e.length-1?null:e.slice(n+1).toUpperCase()}function _t({file:e,compact:n,onRemove:o,onClick:t}){let r=gn(e.name),s=e.size!=null?fn(e.size):null,a$1=[r,s].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 u=dn[un(e.type)];return jsx(u,{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&&a$1&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:a$1})]}),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(Ke,{onClick:()=>o(e),label:`Remove ${e.name}`})]})}function zt({files:e,onRemove:n,onClick:o,className:t}){let[r,s]=useState(false),a$1=useRef(null),u=useRef(null);if(useEffect(()=>{if(!r)return;let S=v=>{let f=v.target;a$1.current&&!a$1.current.contains(f)&&!u.current?.contains(f)&&s(false);};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r]),e.length===0)return null;let g=e.length>_e,p=g,T=e.length-_e,m=e.slice(0,_e);return jsxs("div",{className:a("relative",t),children:[jsxs("div",{className:"flex flex-wrap gap-2",role:"list","aria-label":"Attached files",children:[(g?m:e).map(S=>jsx(_t,{file:S,compact:p,onRemove:n,onClick:o},S.id)),g&&jsx("div",{role:"listitem",children:jsx("button",{ref:u,type:"button",onClick:()=>s(S=>!S),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",p?"h-10 px-3 text-xs":"h-14 px-4 text-sm"),children:r?"Show less":`+${T} more`})})]}),r&&jsx("div",{ref:a$1,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(_e).map(S=>jsx(_t,{file:S,compact:p,onRemove:n,onClick:o},S.id))})})]})}function yr({value:e,onChange:n,triggers:o,placeholder:t,className:r,disabled:s=false,markdown:a$1,onSubmit:u,onEscape:g,onChipClick:p,onChipAdd:T,onChipDelete:m,onLinkClick:S,onPaste:v,onUndo:f,onRedo:b,minHeight:P=80,maxHeight:K,autoFocus:$=false,autoGrow:I=false,"aria-label":V,"data-test-id":G,images:xe=[],imagePosition:ae="above",onImagePaste:ve,onImageRemove:oe,onImageClick:N,files:w=[],filePosition:D="above",onFileRemove:L,onFileClick:E,ref:k}){let{editorRef:M,activeTrigger:U,suggestions:R,suggestionsLoading:ce,suggestionsError:se,selectedSuggestionIndex:ee,handleInput:O,handleKeyDown:_,handleClick:ye,selectSuggestion:ie,dismissTrigger:ue,handle:Te,triggerRect:Xe,eventHandlers:J}=At({value:e,onChange:n,triggers:o,onSubmit:u,onEscape:g,onChipClick:p,onChipAdd:T,onChipDelete:m,onLinkClick:S,onPaste:v,onUndo:f,onRedo:b,onImagePaste:ve,markdown:a$1});useImperativeHandle(k,()=>Te,[Te]),useEffect(()=>{$&&M.current?.focus();},[$,M]);let[q,Pe]=useState(false),[i,h]=useState(void 0),y=useCallback(()=>{let Q=M.current;if(!Q)return;Q.style.height="auto";let de=Q.scrollHeight;Q.style.height=`${de}px`,h(de);},[M]),l=useCallback(()=>{I&&(Pe(true),y());},[I,y]),c=useCallback(()=>{J.onBlur(),I&&setTimeout(()=>{let Q=M.current;if(!Q)return;let de=document.activeElement;de&&Q.parentElement?.contains(de)||(Pe(false),h(void 0));},Qe);},[J,I,M]),d=useCallback(()=>{O(),I&&q&&y();},[O,I,q,y]);useEffect(()=>{I&&q&&requestAnimationFrame(()=>y());},[e,I,q,y]);let[x,C]=useState(false),H=useRef(null);useEffect(()=>{if(!I)return;let Q=()=>{if(q){C(false);return}let Ve=M.current;Ve&&C(Ve.scrollHeight>Ve.clientHeight);},de=q?0:160;return H.current=setTimeout(Q,de),()=>{H.current!==null&&clearTimeout(H.current);}},[I,q,e,M]);let z=useMemo(()=>I?{height:q&&i?`${i}px`:`${P}px`,minHeight:`${P}px`,maxHeight:"70dvh",overflowY:q?"auto":"hidden",transition:"height 150ms ease-out"}:{minHeight:`${P}px`,...K?{maxHeight:`${K}px`,overflowY:"auto"}:{}},[I,P,K,q,i]),Ie=e.length===0||e.length===1&&e[0].type==="text"&&e[0].text==="",Ne=xe.length>0?jsx(Ut,{images:xe,onRemove:oe,onClick:N,className:ae==="above"?"pb-2":"pt-2"}):null,Fe=w.length>0?jsx(zt,{files:w,onRemove:L,onClick:E,className:D==="above"?"pb-2":"pt-2"}):null;return jsxs("div",{className:a("prompt-area-container relative",r),children:[ae==="above"&&Ne,D==="above"&&Fe,jsxs("div",{className:"relative",children:[jsx("div",{ref:M,contentEditable:!s,suppressContentEditableWarning:true,role:"textbox","aria-label":V??"Text input","aria-multiline":"true","aria-disabled":s||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",s&&"cursor-not-allowed opacity-50"),style:z,onFocus:l,onInput:I?d:O,onKeyDown:_,onClick:ye,onPaste:J.onPaste,onCopy:J.onCopy,onCut:J.onCut,onDrop:J.onDrop,onDragOver:J.onDragOver,onCompositionStart:J.onCompositionStart,onCompositionEnd:J.onCompositionEnd,onBlur:I?c:J.onBlur}),I&&x&&!q&&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)))"}})}),Ie&&t&&(Array.isArray(t)?jsx($t,{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"&&Fe,ae==="below"&&Ne,U&&U.config.mode==="dropdown"&&jsx(Ft,{suggestions:R,loading:ce,error:se,emptyMessage:U.config.emptyMessage,selectedIndex:ee,onSelect:ie,onDismiss:ue,triggerRect:Xe,triggerChar:U.config.char})]})}
|
|
20
|
-
export{Y as a,vn as b,qe as c,st as d,Be as e,at as f,yn as g,ut as h,fe as i,Qe as j,At as k,yr as l};
|