prompt-area 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,60 @@
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.4.0
7
+
8
+ ### Added
9
+
10
+ - **Consumer control surface for embedding the editor.** New props to drive
11
+ PromptArea from a host composer: `onKeyDown`, `onBlur` and `onRawPaste` (the
12
+ consumer runs first; call `preventDefault()` to suppress the built-in
13
+ handling), plus `maxLength`, `submitOnEnter`, `spellCheck` and
14
+ `aria-describedby`.
15
+ - **Imperative handle methods** on the PromptArea ref — `setText`, `appendText`,
16
+ `getCursorPosition`, `setCursorPosition`, `setCursorToEnd`, `getSelection` and
17
+ `setSelection` — a textarea-shaped surface for programmatic control. Cursor
18
+ offsets are plain-text character indices; `setText` / `appendText` are not
19
+ capped by `maxLength`.
20
+ - **`maxLength` prop** — caps typed input at N plain-text characters (chips
21
+ count as their `trigger + displayText` length). Paste is not capped; divert it
22
+ via `onRawPaste`.
23
+ - **`normalizeBullets` prop** — set `false` to keep a typed `- ` as literal
24
+ markdown instead of rewriting it to `• `.
25
+ - **`'launch'` trigger mode** — fires `onActivate` on keydown and suppresses the
26
+ character, for opening an external surface (command palette, context picker)
27
+ instead of the built-in dropdown.
28
+ - **Trigger popover flips above the trigger** when there isn't room below, so
29
+ the suggestion list stays on-screen.
30
+ - **ActionBar `leftClassName` / `rightClassName`** for styling the left and
31
+ right slot wrappers.
32
+
33
+ ### Changed
34
+
35
+ - **`commandTrigger()` now fires anywhere in the input by default, and exposes a
36
+ `position` option.** Previously the preset hardcoded `position: 'start'` and
37
+ did not let you override it, so `/commands` only worked at the very start of a
38
+ line — an artificial limitation. The default is now `position: 'any'` (a `/`
39
+ after any whitespace opens the menu), and you can opt back into the classic
40
+ line-start behavior with `commandTrigger({ position: 'start' })`. Consumers
41
+ using the raw `TriggerConfig` are unaffected — they already set `position`
42
+ explicitly.
43
+ - **BREAKING: `clsx` and `tailwind-merge` are now peer dependencies** instead of
44
+ bundled runtime dependencies. The package no longer ships its own copies of
45
+ the two `cn` helpers; they dedupe with the copies any shadcn/Tailwind project
46
+ already has, so prompt-area now declares **zero bundled runtime dependencies**
47
+ (`tailwind-merge` alone was ~17 KB gzipped — larger than the rest of the
48
+ package combined). Both are tiny and present in essentially every shadcn
49
+ project, but if your project doesn't already depend on them, install them
50
+ explicitly: `pnpm add clsx tailwind-merge`.
51
+
52
+ ### Fixed
53
+
54
+ - **`autoGrow` now respects the `maxHeight` prop.** Previously, enabling
55
+ `autoGrow` ignored `maxHeight` and always capped the editor at `70dvh`, so a
56
+ composer seeded with lots of content could grow to fill most of the screen.
57
+ The explicit `maxHeight` is now honored (falling back to `70dvh` only when no
58
+ cap is provided).
59
+
6
60
  ## 0.3.2
7
61
 
8
62
  ### Fixed
package/README.md CHANGED
@@ -11,6 +11,8 @@ Ships **two ways** from the same source:
11
11
  - **npm package** (this package) — `npm install prompt-area`, import the component and a stylesheet. Versioned, opinionated, batteries-included.
12
12
  - **[shadcn registry](https://prompt-area.com)** — `npx shadcn@latest add https://prompt-area.com/r/prompt-area.json` to copy the source into your project and own it.
13
13
 
14
+ **Try it live:** [run the example in your browser](https://prompt-area.com/docs/try-it-live) — a full Vite + React app, no setup. ([source](https://github.com/just-marketing/prompt-area/tree/main/examples/basic))
15
+
14
16
  ## Install
15
17
 
16
18
  ```bash
@@ -18,7 +20,13 @@ pnpm add prompt-area
18
20
  # or: npm install prompt-area · yarn add prompt-area
19
21
  ```
20
22
 
21
- `react` and `react-dom` are peer dependencies (most React apps already have them).
23
+ Peer dependencies: `react` and `react-dom` (most React apps already have them),
24
+ plus `clsx` and `tailwind-merge` — the two `cn` helpers, already present in any
25
+ shadcn/Tailwind project. If you don't have them yet:
26
+
27
+ ```bash
28
+ pnpm add clsx tailwind-merge
29
+ ```
22
30
 
23
31
  ## Quick start
24
32
 
@@ -110,14 +118,17 @@ The components are client components and carry a `'use client'` boundary, so you
110
118
 
111
119
  ## Dependencies
112
120
 
113
- - **Peer:** `react`, `react-dom` (>= 18)
121
+ - **Peer:** `react`, `react-dom` (>= 18), plus `clsx` and `tailwind-merge` —
122
+ the two `cn` helpers. These are peer (not bundled) dependencies so they
123
+ dedupe with the copies any shadcn/Tailwind project already ships, keeping
124
+ prompt-area's own footprint to **zero bundled runtime dependencies**. Both
125
+ are tiny and already present in shadcn projects; install them explicitly if
126
+ you don't have them (`pnpm add clsx tailwind-merge`).
114
127
  - **Tailwind is not a peer dependency.** The prebuilt `prompt-area/styles.css`
115
128
  is self-contained and works with **any** stack — Tailwind v4, v3, or no
116
129
  Tailwind at all. The optional `prompt-area/tailwind.css` preset uses Tailwind
117
130
  v4 syntax, so it requires Tailwind v4 in your own project; if you're on v3 or
118
131
  not using Tailwind, use `styles.css` (and theme via the CSS variables above).
119
- - **Runtime:** `clsx`, `tailwind-merge` — the two `cn` helpers, both already
120
- present in any shadcn/Tailwind project.
121
132
 
122
133
  No animation library and no icon library: animations use CSS (`tw-animate-css`
123
134
  utilities) and icons are inline SVGs. No editor framework (ProseMirror, Slate,
@@ -17,6 +17,10 @@ type ActionBarProps = {
17
17
  right?: React.ReactNode;
18
18
  /** Additional CSS class for the root element */
19
19
  className?: string;
20
+ /** Additional CSS class for the left slot wrapper */
21
+ leftClassName?: string;
22
+ /** Additional CSS class for the right slot wrapper */
23
+ rightClassName?: string;
20
24
  /** Whether the action bar is disabled (visually dims and disables pointer events) */
21
25
  disabled?: boolean;
22
26
  /** Accessible label for the toolbar */
@@ -53,7 +57,7 @@ type ActionBarProps = {
53
57
  * </div>
54
58
  * ```
55
59
  */
56
- declare function ActionBar({ left, right, className, disabled, 'aria-label': ariaLabel, 'data-test-id': dataTestId, ref, }: ActionBarProps & {
60
+ declare function ActionBar({ left, right, className, leftClassName, rightClassName, disabled, 'aria-label': ariaLabel, 'data-test-id': dataTestId, ref, }: ActionBarProps & {
57
61
  ref?: React.Ref<HTMLDivElement>;
58
62
  }): react.JSX.Element;
59
63
 
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- export{a as ActionBar}from'../chunk-VULUMPYE.js';import'../chunk-23Y7B365.js';
2
+ export{a as ActionBar}from'../chunk-REFXDE4K.js';import'../chunk-23Y7B365.js';
@@ -0,0 +1 @@
1
+ function n(e){return {type:"text",text:e}}function o(e){return {type:"chip",...e}}function g(e){return e.length===0?true:e.every(t=>t.type==="text"&&t.text.trim()==="")}function p(e){return e.some(t=>t.type==="chip")}function s(e){return e.filter(t=>t.type==="chip")}function a(e,t){return e.filter(r=>r.type==="chip"&&r.trigger===t)}function m(e={}){let{char:t="@",...r}=e;return {char:t,position:"any",mode:"dropdown",chipStyle:"pill",accessibilityLabel:"mention",...r}}function h(e={}){let{char:t="/",position:r="any",...i}=e;return {char:t,position:r,mode:"dropdown",chipStyle:"inline",accessibilityLabel:"command",...i}}function l(e={}){let{char:t="#",...r}=e;return {char:t,position:"any",mode:"dropdown",chipStyle:"pill",resolveOnSpace:true,accessibilityLabel:"tag",...r}}function T(e){let{char:t,...r}=e;return {char:t,position:"start",mode:"callback",...r}}export{n as a,o as b,g as c,p as d,s as e,a as f,m as g,h,l as i,T as j};
@@ -1,2 +1,2 @@
1
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};
2
+ import {a}from'./chunk-NXA7D75N.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,3 @@
1
+ 'use client';
2
+ import {a,c}from'./chunk-ZOC6DT7K.js';import {a as a$1}from'./chunk-23Y7B365.js';import {useRef,useState,useImperativeHandle,useCallback}from'react';import {jsxs,jsx}from'react/jsx-runtime';function C({className:t,children:i}){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:i})}var J=({className:t})=>jsxs(C,{className:t,children:[jsx("path",{d:"M5 12h14"}),jsx("path",{d:"M12 5v14"})]}),K=({className:t})=>jsxs(C,{className:t,children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]}),P="duration-[240ms] ease-[cubic-bezier(0.33,1,0.68,1)] motion-reduce:transition-none";function Q({value:t,onChange:i,triggers:v,placeholder:y,disabled:c$1=false,markdown:k,onSubmit:d,onEscape:w,onChipClick:A,onChipAdd:N,onChipDelete:R,onPaste:T,images:I,onImagePaste:S,onImageRemove:E,files:H,onFileRemove:z,plusButtonIcon:M,onPlusClick:F,submitButtonIcon:L,beforeSubmitSlot:p,maxHeight:B=320,className:D,"aria-label":_,"data-test-id":j,ref:G}){let e=useRef(null),m=useRef(null),[U,u]=useState(false);useImperativeHandle(G,()=>({focus:()=>e.current?.focus(),blur:()=>e.current?.blur(),insertChip:o=>e.current?.insertChip(o),getPlainText:()=>e.current?.getPlainText()??"",clear:()=>e.current?.clear(),setText:o=>e.current?.setText(o),appendText:o=>e.current?.appendText(o),getCursorPosition:()=>e.current?.getCursorPosition()??null,setCursorPosition:o=>e.current?.setCursorPosition(o),setCursorToEnd:()=>e.current?.setCursorToEnd(),getSelection:()=>e.current?.getSelection()??null,setSelection:(o,W)=>e.current?.setSelection(o,W)}),[]);let g=t.length===0||t.length===1&&t[0].type==="text"&&t[0].text==="",s=U||!g,O=useCallback(()=>{u(true);},[]),V=useCallback(()=>{setTimeout(()=>{m.current?.contains(document.activeElement)||u(false);},a);},[]),f=useCallback(()=>{d?.(t);},[d,t]);return jsxs("div",{ref:m,onFocus:O,onBlur:V,"aria-label":_,"data-test-id":j,"data-expanded":s||void 0,className:a$1("compact-prompt-area relative isolate overflow-hidden","bg-background border","transition-[border-radius,box-shadow,border-color]",P,s?"rounded-2xl shadow-sm":"rounded-3xl",D),children:[jsx("div",{onClick:()=>e.current?.focus(),className:a$1("min-w-0 cursor-text","transition-[padding]",P,s?"pb-14 pl-5 pr-5 pt-4":a$1("py-3 pl-[3.25rem]",p?"pr-[5.5rem]":"pr-[3.25rem]")),children:jsx(c,{ref:e,value:t,onChange:i,triggers:v,placeholder:y,disabled:c$1,markdown:k,onSubmit:f,onEscape:w,onChipClick:A,onChipAdd:N,onChipDelete:R,onPaste:T,images:I,onImagePaste:S,onImageRemove:E,files:H,onFileRemove:z,autoGrow:true,minHeight:s?48:24,maxHeight:B})}),jsx("button",{type:"button",onClick:F,disabled:c$1,className:a$1("absolute bottom-1.5 left-1.5 z-10 flex size-9 shrink-0 items-center justify-center","rounded-xl transition-colors","bg-muted text-muted-foreground","hover:bg-accent hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),"aria-label":"Add attachment",children:M??jsx(J,{className:"size-4"})}),jsxs("div",{className:"absolute bottom-1.5 right-1.5 z-10 flex items-center gap-1.5",children:[p,jsx("button",{type:"button",onClick:f,disabled:c$1||g,className:a$1("flex size-9 shrink-0 items-center justify-center rounded-xl transition-colors","bg-primary text-primary-foreground","hover:bg-primary/90","disabled:pointer-events-none disabled:opacity-50"),"aria-label":"Send message",children:L??jsx(K,{className:"size-4"})})]})]})}
3
+ export{Q as a};
@@ -0,0 +1,3 @@
1
+ function b(n){return n.map(t=>t.type==="text"?t.text:`${t.trigger}${t.displayText}`).join("")}function M(n){return n?[{type:"text",text:n}]:[]}function w(n,t){if(t<=0)return [];let r=[],i=0;for(let e of n){let s=e.type==="text"?e.text.length:e.trigger.length+e.displayText.length;if(i+s<=t){r.push(e),i+=s;continue}if(e.type==="text"){let o=t-i;if(o>0){let l=e.text.charCodeAt(o-1);l>=55296&&l<=56319&&(o-=1),o>0&&r.push({type:"text",text:e.text.slice(0,o)});}}break}return r}function x(n){return n===" "||n===`
2
+ `||n===" "}function S(n){let t=new Map;for(let r of n)t.has(r.char)||t.set(r.char,r);return t}function T(n,t,r){if(t===0)return true;let i=n[t-1];return r==="start"?i===`
3
+ `:x(i)}function O(n,t,r){if(!n||t===0||r.length===0)return null;let i=S(r);for(let e=t-1;e>=0;e--){let s=n[e];if(x(s)){if(e+1<t){let l=n[e+1],g=i.get(l);if(g&&T(n,e+1,g.position))return {config:g,startOffset:e+1,query:n.slice(e+2,t)}}return null}let o=i.get(s);if(o&&T(n,e,o.position))return {config:o,startOffset:e,query:n.slice(e+1,t)}}return null}function A(n,t,r){let i=t.startOffset,e=i+1+t.query.length,s=[],o=0;for(let u of n)if(u.type==="chip"){let p=`${u.trigger}${u.displayText}`,a=o,h=o+p.length;(h<=i||a>=e)&&s.push(u),o=h;}else {let p=o,a=o+u.text.length;if(a<=i)s.push(u);else if(p>=e)s.push(u);else {let h=u.text.slice(0,Math.max(0,i-p)),d=u.text.slice(Math.min(u.text.length,e-p));h&&s.push({type:"text",text:h});let v={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(v),d?s.push({type:"text",text:" "+d.replace(/^\s/,"")}):s.push({type:"text",text:" "});}o=a;}let l=y(s),g=-1,f=0;for(let u of l)u.type==="text"?f+=u.text.length:(f+=u.trigger.length+u.displayText.length,u.value===r.value&&u.displayText===r.displayText&&u.trigger===t.config.char&&(g=f));let c=g===-1?f:g+1;return {segments:l,cursorOffset:c}}function R(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 y(r)}function k(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:y(e),revertedText:i}}function $(n,t){let r=t.filter(s=>s.resolveOnSpace);if(r.length===0)return n;let i=S(r),e=[];for(let s of n){if(s.type==="chip"){e.push(s);continue}let o=C(s.text,i);e.push(...o);}return y(e)}function C(n,t){if(!n)return [];let r=[],i=0;for(;i<n.length;){let e=n[i];if(t.has(e)&&(i===0||x(n[i-1]))){let l=t.get(e);if(l&&T(n,i,l.position)){let g=i+1;for(;g<n.length&&!x(n[g]);)g++;let f=n.slice(i+1,g);if(f.length>0){let c=l.onSelect?.({value:f,label:f})||f;r.push({type:"chip",trigger:e,value:f,displayText:c,autoResolved:true}),i=g;continue}}}let s=i;for(i++;i<n.length&&!(t.has(n[i])&&x(n[i-1]));)i++;r.push({type:"text",text:n.slice(s,i)});}return r}function m(n,t,r,i){let e=[],s=0,o=false;for(let l of n)if(l.type==="chip"){let g=`${l.trigger}${l.displayText}`,f=s,c=s+g.length;!o&&t===r&&f===t&&(e.push({type:"text",text:i}),o=true),(c<=t||f>=r)&&e.push(l),s=c;}else {let g=s,f=s+l.text.length,c=t===r?f<t:f<=t,u=t===r?g>r:g>=r;if(c)e.push(l);else if(u)e.push(l);else {let p=l.text.slice(0,Math.max(0,t-g)),a=l.text.slice(Math.min(l.text.length,r-g));p&&e.push({type:"text",text:p}),!o&&g<=t&&(e.push({type:"text",text:i}),o=true),a&&e.push({type:"text",text:a});}s=f;}return !o&&i&&e.push({type:"text",text:i}),y(e)}function q(n,t,r,i){if(t===r)return null;let e=b(n),s=i.length,o=t>=s&&e.slice(t-s,t)===i,l=r+s<=e.length&&e.slice(r,r+s)===i,g=o&&l;if(g&&s===1){let u=t>s?e[t-s-1]:"",p=r+s<e.length?e[r+s]:"";(u===i||p===i)&&(g=false);}if(g){let u=m(n,r,r+s,"");return {segments:m(u,t-s,t,""),selectionStart:t-s,selectionEnd:r-s}}let f=m(n,r,r,i);return {segments:m(f,t,t,i),selectionStart:t+s,selectionEnd:r+s}}function B(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 I(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 y(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{b as a,M as b,w as c,T as d,O as e,A as f,R as g,k as h,$ as i,m as j,q as k,B as l,I as m,y as n};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {jsxs,jsx}from'react/jsx-runtime';function f({left:t,right:a$1,className:o,leftClassName:n,rightClassName:s,disabled:r=false,"aria-label":p,"data-test-id":c,ref:l}){return jsxs("div",{ref:l,role:"toolbar","aria-label":p??"Action bar","aria-disabled":r||void 0,"data-test-id":c,className:a("action-bar","flex items-center justify-between gap-2 pt-2",r&&"pointer-events-none opacity-50",o),children:[t&&jsx("div",{className:a("flex items-center gap-1",n),children:t}),a$1&&jsx("div",{className:a("ml-auto flex items-center gap-1",s),children:a$1})]})}export{f as a};
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import {a}from'./chunk-23Y7B365.js';import {f,a as a$1,e,m,c,g,h,k,d,j,b,i,n}from'./chunk-NXA7D75N.js';import {useRef,useState,useCallback,useEffect,useMemo,useImperativeHandle}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function me(e,t){let o=e.lastIndexOf(`
3
+ `,t-1)+1,n=e.indexOf(`
4
+ `,t),s=e.slice(o,n===-1?e.length:n),l=s.match(/^(\s*)([•\-*]) /);if(l){let g=l[1];return {lineStart:o,prefix:l[0],indent:Math.floor(g.length/2),listType:"bullet",marker:l[2],contentStart:o+l[0].length}}let d=s.match(/^(\s*)(\d+)\. /);if(d){let g=d[1];return {lineStart:o,prefix:d[0],indent:Math.floor(g.length/2),listType:"numbered",number:parseInt(d[2],10),contentStart:o+d[0].length}}return null}function yt(e,t){let o=a$1(e),n=o.lastIndexOf(`
5
+ `,t-1)+1,s=o.slice(n,t),l=s.match(/^(\s*)[-*] $/);if(!l)return null;let g=`${l[1]}\u2022 `,x=n,y=n+s.length;return {segments:j(e,x,y,g),cursorOffset:n+g.length}}function Ct(e,t){let o=a$1(e),n=me(o,t);if(!n)return null;let s=o.indexOf(`
6
+ `,t);if(o.slice(n.contentStart,s===-1?o.length:s).trim()==="")return {segments:j(e,n.lineStart,n.lineStart+n.prefix.length,""),cursorOffset:n.lineStart};let d=" ".repeat(n.indent),g;if(n.listType==="bullet")g=`${d}${n.marker??"\u2022"} `;else {let C=(n.number??1)+1;g=`${d}${C}. `;}let x=`
7
+ ${g}`;return {segments:j(e,t,t,x),cursorOffset:t+x.length}}function bt(e,t){let o=a$1(e),n=me(o,t);return n?{segments:j(e,n.lineStart,n.lineStart," "),cursorOffset:t+2}:null}function Et(e,t){let o=a$1(e),n=me(o,t);return !n||n.indent===0?null:{segments:j(e,n.lineStart,n.lineStart+2,""),cursorOffset:Math.max(n.lineStart,t-2)}}function Nt(e,t){let o=a$1(e),n=me(o,t);return !n||t>n.contentStart?null:{segments:j(e,n.lineStart,n.contentStart," ".repeat(n.indent)),cursorOffset:n.lineStart+n.indent*2}}function Ve(e,t){let o=false,n=e.map(s=>{if(s.type!=="text")return s;let l=t?s.text.replace(/(^|\n)(\s*)- /g,"$1$2\u2022 "):s.text.replace(/(^|\n)(\s*)• /g,"$1$2- ");return l===s.text?s:(o=true,{...s,text:l})});return o?n:e}function le(e){return e instanceof HTMLElement}function W(e){return e instanceof HTMLElement&&e.dataset.chipTrigger!==void 0}function ve(e){return e instanceof HTMLBRElement}function Mt(e){return e instanceof Text}function Ie(e){return W(e)&&e.dataset.chipAutoResolved==="true"}function Lt(e){return e instanceof HTMLAnchorElement&&e.dataset.url==="true"}function ln(e){try{return JSON.parse(e)}catch{return}}function Fe(e){try{return JSON.stringify(e)}catch{return}}function je(e){if(W(e))return e.dataset.chipTrigger}function an(e){if(W(e))return e.dataset.chipValue}function qe(e){if(W(e))return e.dataset.chipDisplay??e.textContent??void 0}function cn(e){if(!W(e))return;let t=e.dataset.chipData;if(t)return ln(t)}function Je(e){let t=e.dataset.chipTrigger??"",o=e.dataset.chipDisplay??e.textContent??"";return t.length+o.length}function Ee(e){if(!W(e))return null;let t=je(e),o=an(e),n=qe(e);if(!t||o===void 0||!n)return null;let s=cn(e),l=Ie(e);return {type:"chip",trigger:t,value:o,displayText:n,...s!==void 0?{data:s}:{},...l?{autoResolved:true}:{}}}function Ne(e,t){let o=e.childNodes;for(let n=0;n<o.length;n++)if(o[n]===t)return n;return -1}function Ye(e,t){let o=0;for(let n=0;n<t;n++){let s=e.childNodes[n];(s.nodeType===Node.TEXT_NODE&&(s.textContent??"")!==""||W(s)||ve(s))&&o++;}return o}function Re(e,t){let o=t;for(;o!==null;){if(o.parentNode===e)return o;o=o.parentNode;}return null}function un(e,t){let o=document.createDocumentFragment();for(;t.firstChild;)o.appendChild(t.firstChild);o.appendChild(document.createElement("br")),e.replaceChild(o,t);}function De(e){let t=false,o=new Set(["DIV","P","SECTION","ARTICLE","BLOCKQUOTE"]);for(let n=e.childNodes.length-1;n>=0;n--){let s=e.childNodes[n];if(!(s instanceof HTMLElement)||s.dataset.chipTrigger!==void 0||s instanceof HTMLBRElement)continue;let l=s.tagName;if(o.has(l))un(e,s),t=true;else if(l==="FONT"||l==="B"||l==="I"||l==="U"||l==="STRONG"||l==="EM"||l==="A"||l==="SPAN"){let d=s.textContent??"";d?e.replaceChild(document.createTextNode(d),s):e.removeChild(s),t=true;}}return e.normalize(),t}var Rt=/https?:\/\/[^\s),]+/g;function Qe(e){let t=false,o=[];for(let n=0;n<e.childNodes.length;n++){let s=e.childNodes[n];Mt(s)&&s.textContent&&o.push(s);}for(let n of o){let s=n.textContent??"";Rt.lastIndex=0;let l=[],d;for(;(d=Rt.exec(s))!==null;){let b=d[0];for(;b.length>0&&/[.;:!?]$/.test(b);)b=b.slice(0,-1);b.length>0&&l.push({url:b,index:d.index});}if(l.length===0)continue;let g=n.parentNode;if(!g)continue;let x=[];for(let{url:b,index:E}of l)try{let D=new URL(b);(D.protocol==="http:"||D.protocol==="https:")&&x.push({url:b,href:D.href,index:E});}catch{}if(x.length===0)continue;t=true;let y=document.createDocumentFragment(),C=0;for(let{url:b,href:E,index:D}of x){D>C&&y.appendChild(document.createTextNode(s.slice(C,D)));let v=document.createElement("a");v.href=E,v.target="_blank",v.rel="noopener noreferrer",v.dataset.url="true",v.className="text-primary hover:text-primary/80 underline cursor-pointer",v.textContent=b,y.appendChild(v),C=D+b.length;}C<s.length&&y.appendChild(document.createTextNode(s.slice(C))),g.replaceChild(y,n);}return t}var Dt=/(\*{3})(.+?)\*{3}|(\*{2})(.+?)\*{2}|(\*)(.+?)\*/g;function Ze(e){let t=false,o=[];for(let n=0;n<e.childNodes.length;n++){let s=e.childNodes[n];Mt(s)&&s.textContent&&o.push(s);}for(let n of o){let s=n.textContent??"";Dt.lastIndex=0;let l=[],d;for(;(d=Dt.exec(s))!==null;)d[1]&&d[2]?l.push({fullMatch:d[0],marker:d[1],content:d[2],index:d.index,className:"font-bold italic"}):d[3]&&d[4]?l.push({fullMatch:d[0],marker:d[3],content:d[4],index:d.index,className:"font-bold"}):d[5]&&d[6]&&l.push({fullMatch:d[0],marker:d[5],content:d[6],index:d.index,className:"italic"});if(l.length===0)continue;t=true;let g=n.parentNode;if(!g)continue;let x=document.createDocumentFragment(),y=0;for(let{fullMatch:C,marker:b,content:E,index:D,className:v}of l){D>y&&x.appendChild(document.createTextNode(s.slice(y,D)));let U=document.createElement("span");U.dataset.md="true";let w=document.createElement("span");w.className="prompt-area-md-marker",w.textContent=b;let k=document.createElement("span");k.className=v,k.textContent=E;let h=document.createElement("span");h.className="prompt-area-md-marker",h.textContent=b,U.appendChild(w),U.appendChild(k),U.appendChild(h),x.appendChild(U),y=D+C.length;}y<s.length&&x.appendChild(document.createTextNode(s.slice(y))),g.replaceChild(x,n);}return t}function q(){let e=window.getSelection();return !e||e.rangeCount===0?null:e.getRangeAt(0)}function wt(e){let t=q();if(!t||!e.contains(t.startContainer))return null;let o=t.startContainer;if(o===e)return {nodeIndex:t.startOffset,offset:0};let n=Re(e,o);return n?{nodeIndex:Ne(e,n),offset:t.startOffset}:null}function kt(e,t){let o=window.getSelection();if(!o)return;let n=e.childNodes;if(n.length===0)return;let s=document.createRange();if(t.nodeIndex>=n.length){let l=n[n.length-1];l.nodeType===Node.TEXT_NODE?s.setStart(l,(l.textContent??"").length):s.setStartAfter(l);}else {let l=n[t.nodeIndex];if(l.nodeType===Node.TEXT_NODE){let d=(l.textContent??"").length;s.setStart(l,Math.min(t.offset,d));}else s.setStartAfter(l);}s.collapse(true),o.removeAllRanges(),o.addRange(s);}function re(e){let t=q();if(!t||!e.contains(t.startContainer))return null;let o=document.createRange();return o.selectNodeContents(e),o.setEnd(t.startContainer,t.startOffset),Me(o)}function Ot(e,t){let o=Le(e,t);if(!o)return null;let n=document.createRange();return n.setStart(o.node,o.offset),n.collapse(true),n}function J(e,t){let o=window.getSelection();if(!o)return;let n=Le(e,t);if(n){let l=document.createRange();l.setStart(n.node,n.offset),l.collapse(true),o.removeAllRanges(),o.addRange(l);return}let s=document.createRange();s.selectNodeContents(e),s.collapse(false),o.removeAllRanges(),o.addRange(s);}function Me(e){let t=e.cloneContents(),o=0,n=s=>{if(s.nodeType===Node.TEXT_NODE)o+=(s.textContent??"").length;else if(W(s))o+=Je(s);else if(le(s)&&s.tagName==="BR"){if(s.dataset.sentinel)return;o+=1;}else le(s)&&s.childNodes.forEach(n);};return t.childNodes.forEach(n),o}function we(e){let t=q();if(!t||!e.contains(t.startContainer))return null;let o=document.createRange();o.selectNodeContents(e),o.setEnd(t.startContainer,t.startOffset);let n=Me(o);if(t.collapsed)return {start:n,end:n};let s=document.createRange();s.selectNodeContents(e),s.setEnd(t.endContainer,t.endOffset);let l=Me(s);return {start:n,end:l}}function Ge(e,t,o){let n=window.getSelection();if(!n)return;if(t===o){J(e,t);return}let s=Le(e,t),l=Le(e,o);if(!s||!l)return;let d=document.createRange();d.setStart(s.node,s.offset),d.setEnd(l.node,l.offset),n.removeAllRanges(),n.addRange(d);}function Le(e,t){let o=t;for(let n=0;n<e.childNodes.length;n++){let s=e.childNodes[n];if(s.nodeType===Node.TEXT_NODE){let l=(s.textContent??"").length;if(o<=l)return {node:s,offset:o};o-=l;}else if(W(s)){let l=Je(s);if(o<=l)return {node:e,offset:n+1};o-=l;}else if(ve(s)){if(s.dataset.sentinel)continue;if(o<=1)return {node:e,offset:n+1};o-=1;}else if(le(s)){let l=(s.textContent??"").length;if(o<=l){let d=Le(s,o);if(d)return d}o-=l;}}return {node:e,offset:e.childNodes.length}}function dn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Pt(e,t){let o=n=>{n.nodeType===Node.TEXT_NODE?t.onText(n.textContent??""):W(n)?t.onChip(n):le(n)&&n.tagName==="BR"?t.onBreak():n.childNodes.forEach(o);};e.childNodes.forEach(o);}function At(e){let t="";return Pt(e,{onText:o=>{t+=o;},onChip:o=>{t+=(je(o)??"")+(qe(o)??"");},onBreak:()=>{t+=`
8
+ `;}}),t}function Ht(e){let t=[];return Pt(e,{onText:o=>{o&&t.push({type:"text",text:o});},onChip:o=>{let n=Ee(o);n&&t.push(n);},onBreak:()=>{t.push({type:"text",text:`
9
+ `});}}),t}function It(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return null;let o=[];for(let n of t){if(!dn(n))return null;if(n.type==="text"&&typeof n.text=="string")o.push({type:"text",text:n.text});else if(n.type==="chip"&&typeof n.trigger=="string"&&typeof n.value=="string"&&typeof n.displayText=="string"){let s={type:"chip",trigger:n.trigger,value:n.value,displayText:n.displayText,...n.data!==void 0?{data:n.data}:{},...n.autoResolved?{autoResolved:!0}:{}};o.push(s);}else return null}return o}catch{return null}}function Ft(e,t,o){let n$1=q();if(!n$1)return [...e,...t];let s=document.createRange();s.selectNodeContents(o),s.setEnd(n$1.startContainer,n$1.startOffset);let l=Me(s),d=[],g=0,x=false,y=()=>{x||(d.push(...t),x=true);};for(let C of e){if(C.type==="chip"){let E=C.trigger.length+C.displayText.length;g>=l&&y(),d.push(C),g+=E;continue}let b=g+C.text.length;if(b<=l)d.push(C);else if(g>=l)y(),d.push(C);else {let E=l-g,D=C.text.slice(0,E),v=C.text.slice(E);D&&d.push({type:"text",text:D}),y(),v&&d.push({type:"text",text:v});}g=b;}return y(),n(d)}var fn=100,et=150;function Ut(e){let{editorRef:t,readSegmentsFromDOM:o,onChange:n,renderSegmentsToDOM:s,runTriggerDetection:l,dismissTrigger:d,triggers:g,onPaste:x,onUndo:y,onRedo:C,onChipAdd:b,onImagePaste:E,onRawPaste:D}=e,v=useRef(false),U=useRef({undoStack:[],redoStack:[]}),w=useCallback(N=>{let P=U.current;P.undoStack.push(N),P.undoStack.length>fn&&P.undoStack.shift(),P.redoStack=[];},[]),k=useCallback(()=>{U.current={undoStack:[],redoStack:[]};},[]),h=useCallback(N=>{if(D?.(N),N.defaultPrevented)return;N.preventDefault();let P=t.current;if(!P)return;let A=Array.from(N.clipboardData.files).find(p=>p.type.startsWith("image/"))??Array.from(N.clipboardData.items).find(B=>B.type.startsWith("image/"))?.getAsFile()??null;if(A){E?.(A);return}let H=o();w(H);let I=N.clipboardData.getData("text/prompt-area-segments");if(I){let p=It(I);if(p&&p.length>0){let B=q();if(!B)return;B.deleteContents();let ie=o(),de=Ft(ie,p,P);n(de),s(de),x?.({segments:de,source:"internal"});for(let Q of p)Q.type==="chip"&&b?.(Q);l();return}}let K=N.clipboardData.getData("text/plain");if(!K)return;let F=q();if(!F)return;F.deleteContents();let S=K.split(`
10
+ `),R=document.createDocumentFragment();for(let p=0;p<S.length;p++)S[p]&&R.appendChild(document.createTextNode(S[p])),p<S.length-1&&R.appendChild(document.createElement("br"));F.insertNode(R),F.collapse(false);let te=window.getSelection();te?.removeAllRanges(),te?.addRange(F),De(P);let X=o(),V=i(X,g);if(V!==X){n(V),s(V);for(let p of V)p.type==="chip"&&!X.some(B=>B.type==="chip"&&B.trigger===p.trigger&&B.value===p.value&&B.displayText===p.displayText)&&b?.(p);}else n(X);x?.({segments:V,source:"external"}),l();},[t,o,n,w,l,s,g,x,b,E,D]),O=useCallback(N=>{N.preventDefault();let P=q();if(!P)return;let A=P.cloneContents(),H=At(A);N.clipboardData.setData("text/plain",H);let I=Ht(A);if(I.some(F=>F.type==="chip")){let F=Fe(I);F&&N.clipboardData.setData("text/prompt-area-segments",F);}},[]),M=useCallback(N=>{O(N);let P=q();if(!P)return;let A=o();w(A),P.deleteContents();let H=t.current;H&&De(H);let I=o();n(I),l();},[O,t,o,n,w,l]),ce=useCallback(N=>{N.preventDefault();},[]),se=useCallback(N=>{N.preventDefault();},[]),ge=useCallback(()=>{v.current=true;},[]),ue=useCallback(()=>{v.current=false,l();},[l]),ee=useCallback(()=>{setTimeout(()=>{let N=t.current;if(!N)return;let P=document.activeElement;P&&N.parentElement?.contains(P)||d();},et);},[t,d]),Se=useCallback(N=>{if(!(N.metaKey||N.ctrlKey)||N.key!=="z")return false;N.preventDefault();let A=U.current;if(N.shiftKey){if(A.redoStack.length===0)return true;let H=A.redoStack.pop();if(!H)return true;let I=o();A.undoStack.push(I),n(H),s(H),C?.(H);}else {if(A.undoStack.length===0)return true;let H=A.undoStack.pop();if(!H)return true;let I=o();A.redoStack.push(I),n(H),s(H),y?.(H);}return true},[o,n,s,y,C]);return {handlePaste:h,handleCopy:O,handleCut:M,handleDrop:ce,handleDragOver:se,handleCompositionStart:ge,handleCompositionEnd:ue,handleBlur:ee,handleKeyDownForUndoRedo:Se,pushUndo:w,resetUndoHistory:k,isComposing:v}}function Kt(){let[e,t]=useState([]),[o,n]=useState(false),[s,l]=useState(null),d=useRef(0),g=useRef(null),x=useRef(null),y=useCallback(()=>{g.current?.abort(),x.current&&clearTimeout(x.current),t([]),n(false),l(null);},[]),C=useCallback((b,E)=>{if(!E.onSearch)return;g.current?.abort(),x.current&&clearTimeout(x.current),n(true),l(null),d.current++;let D=d.current,v=new AbortController;g.current=v;let{onSearch:U,onSearchError:w,searchDebounceMs:k}=E,h=()=>{let O=U(b,{signal:v.signal});O instanceof Promise?O.then(M=>{v.signal.aborted||d.current!==D||(t(M),n(false));},M=>{v.signal.aborted||d.current!==D||M instanceof DOMException&&M.name==="AbortError"||(l(M instanceof Error?M.message:"Search failed"),n(false),w?.(M));}):(t(O),n(false));};k&&k>0&&b.length>0?x.current=setTimeout(h,k):h();},[]);return useEffect(()=>()=>{g.current?.abort(),x.current&&clearTimeout(x.current);},[]),{suggestions:e,suggestionsLoading:o,suggestionsError:s,search:C,reset:y}}var pn=300;function zt({value:e$1,onChange:t,triggers:o=[],onSubmit:n,onEscape:s,onChipClick:l,onChipAdd:d$1,onChipDelete:g$1,onLinkClick:x,onPaste:y,onRawPaste:C,onUndo:b$1,onRedo:E,onImagePaste:D,markdown:v=true,normalizeBullets:U=true,submitOnEnter:w=true,maxLength:k$1}){let h$1=useRef(null),[O,M]=useState(null),[ce,se]=useState(0),[ge,ue]=useState(null),{suggestions:ee,suggestionsLoading:Se,suggestionsError:N,search:P,reset:A}=Kt(),H=useRef(false),I=useRef([]),K=useRef(null),F=useRef(null),S=useCallback(()=>{let r=h$1.current;if(!r)return [];let u=[];for(let f=0;f<r.childNodes.length;f++){let c=r.childNodes[f];if(c.nodeType===Node.TEXT_NODE){let i=c.textContent??"";i&&u.push({type:"text",text:i});}else if(W(c)){let i=Ee(c);i&&u.push(i);}else if(ve(c)){if(c.dataset.sentinel)continue;u.push({type:"text",text:`
11
+ `});}else if(le(c)){let i=c.textContent??"";i&&u.push({type:"text",text:i});}}return u},[]),R=useCallback(r=>{let u=h$1.current;if(!u)return;H.current=true;let f=wt(u);for(;u.firstChild;)u.removeChild(u.firstChild);for(let c of r)if(c.type==="text"){let i=c.text.split(`
12
+ `);for(let a=0;a<i.length;a++)i[a]&&u.appendChild(document.createTextNode(i[a])),a<i.length-1&&u.appendChild(document.createElement("br"));}else {let i=document.createElement("span");if(i.contentEditable="false",i.dataset.chipTrigger=c.trigger,i.dataset.chipValue=c.value,i.dataset.chipDisplay=c.displayText,c.data!==void 0){let T=Fe(c.data);T&&(i.dataset.chipData=T);}c.autoResolved&&(i.dataset.chipAutoResolved="true");let a$1=o.find(T=>T.char===c.trigger),m=a$1?.chipStyle??"pill";i.dataset.chipStyle=m,i.className=a("prompt-area-chip",m==="inline"&&"prompt-area-chip--inline",a$1?.chipClassName),i.textContent=`${c.trigger}${c.displayText}`,i.setAttribute("role","button"),i.setAttribute("tabindex","-1"),u.appendChild(i);}if(u.lastChild&&ve(u.lastChild)){let c=document.createElement("br");c.dataset.sentinel="true",u.appendChild(c);}Qe(u),v&&Ze(u),f&&kt(u,f),I.current=r,H.current=false;},[o,v]),te=useCallback((r,u)=>f$1=>{let c=f(r,u,{value:f$1.value,displayText:f$1.displayText,data:f$1.data});t(c.segments),R(c.segments),d$1?.({type:"chip",trigger:u.config.char,value:f$1.value,displayText:f$1.displayText,...f$1.data!==void 0?{data:f$1.data}:{}});let i=h$1.current;i&&J(i,c.cursorOffset);},[t,R,d$1]),X=useCallback(()=>{let r=h$1.current;if(!r)return;let u=S(),f=a$1(u),c=re(r);if(c===null)return;let i=e(f,c,o);if(i){M(i),se(0);let a=Ot(r,i.startOffset);if(a){let m=a.getBoundingClientRect();(m.height>0||m.left>0||m.top>0)&&ue(m);}i.config.mode==="dropdown"&&i.config.onSearch&&P(i.query,i.config),i.config.mode==="callback"&&i.config.onActivate&&i.config.onActivate({text:f,cursorPosition:c,insertChip:te(u,i)});}else M(null),A();},[o,S,te,A,P]),V=useCallback(()=>{M(null),se(0),A();},[A]),p=Ut({editorRef:h$1,readSegmentsFromDOM:S,onChange:t,renderSegmentsToDOM:R,runTriggerDetection:X,dismissTrigger:V,triggers:o,onPaste:y,onRawPaste:C,onUndo:b$1,onRedo:E,onChipAdd:d$1,onImagePaste:D});useEffect(()=>{if(!H.current&&!m(e$1,I.current)){if(v&&U){let r=Ve(e$1,true);if(r!==e$1){t(r);return}}R(e$1);}},[e$1,R,v,U,t]);let B=useRef(v);useEffect(()=>{if(B.current===v)return;B.current=v;let r=U?Ve(e$1,v):e$1;r!==e$1?t(r):R(e$1);},[v,U,R,e$1,t]),useEffect(()=>()=>{K.current&&clearTimeout(K.current);},[]);let ie=useCallback(()=>{if(H.current)return;if(p.isComposing.current){let c=S();I.current=c,t(c);return}let r=h$1.current,u=r?re(r):null;r&&De(r);let f=S();if(k$1!=null&&r&&a$1(f).length>k$1){let c$1=re(r),i=c(f,k$1);I.current=i,t(i),R(i),J(r,c$1!=null?Math.min(c$1,k$1):k$1),X();return}if(v&&U&&r&&u!==null){let c=yt(f,u);if(c){I.current=c.segments,t(c.segments),R(c.segments),J(r,c.cursorOffset),X();return}}F.current||(F.current=I.current),I.current=f,t(f),K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{F.current&&(p.pushUndo(F.current),F.current=null),K.current=null;},pn),r&&(Qe(r),v&&Ze(r),u!==null&&J(r,u)),X();},[t,S,X,R,v,U,k$1,p]),de=useCallback(r=>{let u=r.target;if(!(u instanceof Node))return;let f=h$1.current;if(!f)return;let c=u;for(;c&&c!==f;){if(Lt(c)){if(r.metaKey||r.ctrlKey){r.preventDefault(),x?.(c.href),window.open(c.href,"_blank","noopener,noreferrer");return}break}if(W(c)){let i=c.getBoundingClientRect(),a=document.createElement("span");a.className="prompt-area-chip-ripple";let m=Math.max(i.width,i.height);if(a.style.width=`${m}px`,a.style.height=`${m}px`,a.style.left=`${r.clientX-i.left-m/2}px`,a.style.top=`${r.clientY-i.top-m/2}px`,c.appendChild(a),a.addEventListener("animationend",()=>a.remove()),!l)return;let T=Ee(c);T&&l(T);return}c=c.parentNode;}},[l,x]),Q=useCallback((r,u)=>{let f=S(),c=Ne(r,u);if(c===-1)return false;let i=Ye(r,c),a=f[i],m=g(f,i);return t(m),R(m),a?.type==="chip"&&g$1?.(a),true},[S,t,R,g$1]),ye=useCallback((r,u)=>{let f=S(),c=Ne(r,u);if(c===-1)return false;let i=Ye(r,c),a=f[i],m=h(f,i);if(!m)return false;let T=0;for(let _=0;_<i;_++){let ne=f[_];ne.type==="text"?T+=ne.text.length:T+=ne.trigger.length+ne.displayText.length;}return T+=m.revertedText.length,t(m.segments),R(m.segments),J(r,T),a?.type==="chip"&&g$1?.(a),true},[S,t,R,g$1]),Pe=useCallback(()=>{let r=h$1.current;if(!r)return false;let u=q();if(!u||!u.collapsed)return false;let f=u.startContainer,c=u.startOffset;if(f===r&&c>0){let i=r.childNodes[c-1];if(i&&W(i))return Ie(i)?ye(r,i):Q(r,i)}if(f.nodeType===Node.TEXT_NODE&&c===0){let i=Re(r,f);if(!i)return false;let a=i.previousSibling;for(;a&&a.nodeType===Node.TEXT_NODE&&a.textContent==="";)a=a.previousSibling;if(a&&W(a))return Ie(a)?ye(r,a):Q(r,a)}return false},[Q,ye]),he=useCallback(()=>{let r=h$1.current;if(!r)return false;let u=q();if(!u||!u.collapsed)return false;let f=u.startContainer,c=u.startOffset;if(f===r&&c<r.childNodes.length){let i=r.childNodes[c];if(i&&W(i))return Q(r,i)}if(f.nodeType===Node.TEXT_NODE&&c===(f.textContent??"").length){let i=Re(r,f);if(!i)return false;let a=i.nextSibling;for(;a&&a.nodeType===Node.TEXT_NODE&&a.textContent==="";)a=a.nextSibling;if(a&&W(a))return Q(r,a)}return false},[Q]),Ce=useCallback(r=>{let u=S(),f$1=r.query,c={value:f$1,label:f$1},i=r.config.onSelect?.(c)??f$1,a={value:f$1,displayText:i||f$1,autoResolved:true},m=f(u,r,a);t(m.segments),R(m.segments),d$1?.({type:"chip",trigger:r.config.char,...a});let T=h$1.current;T&&J(T,m.cursorOffset),V();},[S,t,R,V,d$1]),be=useCallback(r=>{if(!O)return;let u=S(),f$1=O.config.onSelect?.(r)??r.label,c={value:r.value,displayText:f$1||r.label,data:r.data},i=f(u,O,c);t(i.segments),R(i.segments),d$1?.({type:"chip",trigger:O.config.char,...c});let a=h$1.current;a&&J(a,i.cursorOffset),V(),setTimeout(()=>{h$1.current?.focus();},0);},[O,S,t,R,V,d$1]),Ke=be,_e=useCallback(r=>{let u=(i,a)=>{I.current=a.segments,t(a.segments),R(a.segments),J(i,a.cursorOffset);},f=i=>{if(!v)return false;let a=S(),m=re(i);if(m===null)return false;let T=a$1(a);if(!me(T,m))return false;let _=Ct(a,m);return _&&u(i,_),true};if((r.metaKey||r.ctrlKey)&&r.key==="z"&&F.current&&(K.current&&(clearTimeout(K.current),K.current=null),p.pushUndo(F.current),F.current=null),p.handleKeyDownForUndoRedo(r))return;if(v&&(r.metaKey||r.ctrlKey)&&!r.shiftKey&&(r.key==="b"||r.key==="i")){r.preventDefault();let i=h$1.current;if(!i)return;let a=we(i);if(!a||a.start===a.end)return;let m=r.key==="b"?"**":"*",T=S();p.pushUndo(T);let _=k(T,a.start,a.end,m);if(!_)return;I.current=_.segments,t(_.segments),R(_.segments),Ge(i,_.selectionStart,_.selectionEnd);return}if(!r.metaKey&&!r.ctrlKey&&!r.altKey&&!r.nativeEvent.isComposing&&r.key.length===1){let i=o.find(m=>m.mode==="launch"&&m.char===r.key),a=h$1.current;if(i?.onActivate&&a){let m=re(a);if(m!==null){let T=S(),_=a$1(T);if(d(_,m,i.position)){r.preventDefault(),i.onActivate({text:_,cursorPosition:m,insertChip:te(j(T,m,m,i.char),{config:i,startOffset:m,query:""})});return}}}}if(O&&O.config.mode==="dropdown"&&ee.length>0){if(r.key==="ArrowDown"){r.preventDefault(),se(i=>Math.min(i+1,ee.length-1));return}if(r.key==="ArrowUp"){r.preventDefault(),se(i=>Math.max(i-1,0));return}if(r.key==="Enter"||r.key==="Tab"){r.preventDefault();let i=ee[ce];i&&be(i);return}if(r.key==="Escape"){r.preventDefault(),V();return}}if(r.key===" "&&O&&O.config.resolveOnSpace&&O.query.trim().length>0){r.preventDefault(),Ce(O);return}if(v&&r.key==="Tab"&&!O){let i=h$1.current;if(i){let a=S(),m=a$1(a),T=re(i);if(T!==null&&me(m,T)){r.preventDefault();let ne=r.shiftKey?Et(a,T):bt(a,T);ne&&u(i,ne);return}}}let c=i=>{let a=we(i);if(!a)return;let m=S();p.pushUndo(m);let T=j(m,a.start,a.end,`
13
+ `);u(i,{segments:T,cursorOffset:a.start+1});};if(r.key==="Enter"&&r.shiftKey&&!r.nativeEvent.isComposing){r.preventDefault();let i=h$1.current;i&&!f(i)&&c(i);return}if(r.key==="Enter"&&!r.shiftKey&&!r.nativeEvent.isComposing){let i=h$1.current;if(i&&f(i)){r.preventDefault();return}if(w){r.preventDefault(),n?.(S());return}r.preventDefault(),i&&c(i);return}if(r.key==="Escape"&&s){s();return}if((r.key==="Backspace"||r.key==="Delete")&&!r.nativeEvent.isComposing){let i=h$1.current;if(i){let a=we(i);if(a&&a.start!==a.end){r.preventDefault();let m=S();p.pushUndo(m);let T=j(m,a.start,a.end,"");u(i,{segments:T,cursorOffset:a.start}),X();return}}}if(r.key==="Backspace"){let i=h$1.current;if(i){let a=S(),m=re(i);if(v&&m!==null){let T=Nt(a,m);if(T){r.preventDefault(),u(i,T),X();return}}}if(Pe()){r.preventDefault(),X();return}}if(r.key==="Delete"&&he()){r.preventDefault(),X();return}},[O,ee,ce,n,w,s,S,t,R,v,V,Pe,he,Ce,X,be,p,o,te]),Ae=useMemo(()=>({focus:()=>h$1.current?.focus(),blur:()=>h$1.current?.blur(),insertChip:r=>{let u=S(),f={type:"chip",...r},c=[...u,f,{type:"text",text:" "}];t(c),R(c),d$1?.(f);},getPlainText:()=>a$1(S()),clear:()=>{t([]);let r=h$1.current;if(r)for(;r.firstChild;)r.removeChild(r.firstChild);p.resetUndoHistory(),K.current&&(clearTimeout(K.current),K.current=null),F.current=null;},setText:r=>{p.pushUndo(S());let u=b(r);t(u),R(u);let f=h$1.current;f&&J(f,r.length);},appendText:r=>{let u=S();p.pushUndo(u);let f=u[u.length-1],c=f?.type==="text"?[...u.slice(0,-1),{type:"text",text:f.text+r}]:[...u,{type:"text",text:r}];t(c),R(c);let i=h$1.current;i&&J(i,a$1(c).length);},getCursorPosition:()=>{let r=h$1.current;return r?re(r):null},setCursorPosition:r=>{let u=h$1.current;u&&J(u,r);},setCursorToEnd:()=>{let r=h$1.current;r&&J(r,a$1(S()).length);},getSelection:()=>{let r=h$1.current;return r?we(r):null},setSelection:(r,u)=>{let f=h$1.current;f&&Ge(f,r,u);}}),[S,t,R,d$1,p]),ze=useMemo(()=>({onPaste:p.handlePaste,onCopy:p.handleCopy,onCut:p.handleCut,onDrop:p.handleDrop,onDragOver:p.handleDragOver,onCompositionStart:p.handleCompositionStart,onCompositionEnd:p.handleCompositionEnd,onBlur:p.handleBlur}),[p.handlePaste,p.handleCopy,p.handleCut,p.handleDrop,p.handleDragOver,p.handleCompositionStart,p.handleCompositionEnd,p.handleBlur]);return {editorRef:h$1,activeTrigger:O,suggestions:ee,suggestionsLoading:Se,suggestionsError:N,selectedSuggestionIndex:ce,handleInput:ie,handleKeyDown:_e,handleClick:de,selectSuggestion:Ke,dismissTrigger:V,handle:Ae,triggerRect:ge,eventHandlers:ze}}var Vt=240;function qt({suggestions:e,loading:t,error:o,emptyMessage:n,selectedIndex:s,onSelect:l,onDismiss:d,triggerRect:g,triggerChar:x}){let y=useRef(null),C=useRef(null);if(useEffect(()=>{C.current?.scrollIntoView({block:"nearest"});},[s]),useEffect(()=>{let w=k=>{let h=k.target;y.current&&h instanceof Node&&!y.current.contains(h)&&d();};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[d]),!g||e.length===0&&!t&&!o&&!n)return null;let b=Math.min(320,window.innerWidth-16),E=Math.min(g.left,window.innerWidth-b-8),D=window.innerHeight-g.bottom,v=D<Vt&&g.top>D,U={position:"fixed",left:`${Math.max(8,E)}px`,zIndex:50,maxWidth:`${b}px`,maxHeight:`${Vt}px`,...v?{bottom:`${window.innerHeight-g.top+4}px`}:{top:`${g.bottom+4}px`}};return jsx("div",{ref:y,className:a("min-w-[200px] overflow-y-auto","bg-popover rounded-xl border p-2 shadow-md","animate-in fade-in-0 zoom-in-95"),style:U,role:"listbox","aria-label":`${x} suggestions`,children:t?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&&n?jsx("div",{role:"option","aria-selected":false,className:"text-muted-foreground px-3 py-2 text-sm",children:n}):e.map((w,k)=>jsxs("button",{ref:k===s?C:void 0,type:"button",role:"option","aria-selected":k===s,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",k===s&&"bg-accent"),onMouseDown:h=>{h.preventDefault(),l(w);},children:[w.icon&&jsx("span",{className:"mt-0.5 shrink-0",children:w.icon}),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:"truncate font-medium",children:w.label}),w.description&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:w.description})]})]},w.value))})}function Yt({texts:e,interval:t=3e3}){let[o,n]=useState(0);return useEffect(()=>{if(e.length<=1)return;let s=setInterval(()=>{n(l=>(l+1)%e.length);},t);return ()=>clearInterval(s)},[e.length,t]),jsx("div",{className:"pointer-events-none absolute top-0 left-0 overflow-hidden 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 Be({onClick:e,label:t,className:o}){return jsx("button",{type:"button",onClick:n=>{n.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":t,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 Qt({images:e,onRemove:t,onClick:o,className:n}){return e.length===0?null:jsx("div",{className:a("flex flex-wrap gap-2",n),role:"list","aria-label":"Attached images",children:e.map(s=>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?.(s),children:[jsx("img",{src:s.url,alt:s.alt??"Attached image",className:"h-full w-full object-cover"}),s.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"})}),t&&jsx(Be,{onClick:()=>t(s),label:`Remove ${s.alt??"image"}`})]},s.id))})}function Oe({className:e,children:t}){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:t})}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"})]}),yn=({className:e})=>jsx(Oe,{className:e,children:$e}),Cn=({className:e})=>jsxs(Oe,{className:e,children:[$e,jsx("path",{d:"M10 9H8"}),jsx("path",{d:"M16 13H8"}),jsx("path",{d:"M16 17H8"})]}),bn=({className:e})=>jsxs(Oe,{className:e,children:[$e,jsx("path",{d:"M8 13h2"}),jsx("path",{d:"M14 13h2"}),jsx("path",{d:"M8 17h2"}),jsx("path",{d:"M14 17h2"})]}),En=({className:e})=>jsxs(Oe,{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"})]}),Nn=({className:e})=>jsxs(Oe,{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"})]}),Ue=3;function Rn(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:Cn,spreadsheet:bn,code:En,image:Nn,default:yn};function Mn(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 Ln(e){let t=e.lastIndexOf(".");return t===-1||t===e.length-1?null:e.slice(t+1).toUpperCase()}function Gt({file:e,compact:t,onRemove:o,onClick:n}){let s=Ln(e.name),l=e.size!=null?Mn(e.size):null,d=[s,l].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",t?"h-10 w-36 px-2":"h-14 w-48 px-3",n&&"cursor-pointer"),onClick:()=>n?.(e),children:[(()=>{let g=Dn[Rn(e.type)];return jsx(g,{className:a("text-muted-foreground flex-shrink-0",t?"h-4 w-4":"h-5 w-5")})})(),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:a("truncate font-medium",t?"text-xs":"text-sm"),title:e.name,children:e.name}),!t&&d&&jsx("div",{className:"text-muted-foreground truncate text-xs",children:d})]}),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(Be,{onClick:()=>o(e),label:`Remove ${e.name}`})]})}function en({files:e,onRemove:t,onClick:o,className:n}){let[s,l]=useState(false),d=useRef(null),g=useRef(null);if(useEffect(()=>{if(!s)return;let E=D=>{let v=D.target;v instanceof Node&&d.current&&!d.current.contains(v)&&!g.current?.contains(v)&&l(false);};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[s]),e.length===0)return null;let x=e.length>Ue,y=x,C=e.length-Ue,b=e.slice(0,Ue);return jsxs("div",{className:a("relative",n),children:[jsxs("div",{className:"flex flex-wrap gap-2",role:"list","aria-label":"Attached files",children:[(x?b:e).map(E=>jsx(Gt,{file:E,compact:y,onRemove:t,onClick:o},E.id)),x&&jsx("div",{role:"listitem",children:jsx("button",{ref:g,type:"button",onClick:()=>l(E=>!E),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",y?"h-10 px-3 text-xs":"h-14 px-4 text-sm"),children:s?"Show less":`+${C} more`})})]}),s&&jsx("div",{ref:d,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(Ue).map(E=>jsx(Gt,{file:E,compact:y,onRemove:t,onClick:o},E.id))})})]})}function Or({value:e,onChange:t,triggers:o,placeholder:n,className:s,disabled:l=false,markdown:d,normalizeBullets:g,onSubmit:x,onEscape:y,onChipClick:C,onChipAdd:b,onChipDelete:E,onLinkClick:D,onPaste:v,onUndo:U,onRedo:w,minHeight:k=80,maxHeight:h,autoFocus:O=false,autoGrow:M=false,"aria-label":ce,"data-test-id":se,images:ge=[],imagePosition:ue="above",onImagePaste:ee,onImageRemove:Se,onImageClick:N,files:P=[],filePosition:A="above",onFileRemove:H,onFileClick:I,onKeyDown:K,onBlur:F,onRawPaste:S,submitOnEnter:R,spellCheck:te,maxLength:X,"aria-describedby":V,ref:p}){let{editorRef:B,activeTrigger:ie,suggestions:de,suggestionsLoading:Q,suggestionsError:ye,selectedSuggestionIndex:Pe,handleInput:he,handleKeyDown:Ce,handleClick:be,selectSuggestion:Ke,dismissTrigger:_e,handle:Ae,triggerRect:ze,eventHandlers:r}=zt({value:e,onChange:t,triggers:o,onSubmit:x,onEscape:y,onChipClick:C,onChipAdd:b,onChipDelete:E,onLinkClick:D,onPaste:v,onRawPaste:S,onUndo:U,onRedo:w,onImagePaste:ee,markdown:d,normalizeBullets:g,submitOnEnter:R,maxLength:X});useImperativeHandle(p,()=>Ae,[Ae]),useEffect(()=>{O&&B.current?.focus();},[O,B]);let[u,f]=useState(false),[c,i]=useState(void 0),a$1=useCallback(()=>{let z=B.current;if(!z)return;z.style.height="auto";let fe=z.scrollHeight;z.style.height=`${fe}px`,i(fe);},[B]),m=useCallback(()=>{M&&(f(true),a$1());},[M,a$1]),T=useCallback(()=>{r.onBlur(),M&&setTimeout(()=>{let z=B.current;if(!z)return;let fe=document.activeElement;fe&&z.parentElement?.contains(fe)||(f(false),i(void 0));},et);},[r,M,B]),_=useCallback(()=>{he(),M&&u&&a$1();},[he,M,u,a$1]);useEffect(()=>{M&&u&&requestAnimationFrame(()=>a$1());},[e,M,u,a$1]);let[ne,at]=useState(false),We=useRef(null);useEffect(()=>{if(!M)return;let z=()=>{if(u){at(false);return}let Xe=B.current;Xe&&at(Xe.scrollHeight>Xe.clientHeight);},fe=u?0:160;return We.current=setTimeout(z,fe),()=>{We.current!==null&&clearTimeout(We.current);}},[M,u,e,B]);let nn=useMemo(()=>{if(!M){let z={minHeight:`${k}px`};return h&&(z.maxHeight=`${h}px`,z.overflowY="auto"),z}return {height:u&&c?`${c}px`:`${k}px`,minHeight:`${k}px`,maxHeight:h?`${h}px`:"70dvh",overflowY:u?"auto":"hidden",transition:"height 150ms ease-out, min-height 240ms cubic-bezier(0.33, 1, 0.68, 1)"}},[M,k,h,u,c]),rn=useCallback(z=>{K?.(z),!z.defaultPrevented&&Ce(z);},[K,Ce]),on=useCallback(z=>{F?.(z),T();},[F,T]),sn=e.length===0||e.length===1&&e[0].type==="text"&&e[0].text==="",ct=ge.length>0?jsx(Qt,{images:ge,onRemove:Se,onClick:N,className:ue==="above"?"pb-2":"pt-2"}):null,ut=P.length>0?jsx(en,{files:P,onRemove:H,onClick:I,className:A==="above"?"pb-2":"pt-2"}):null;return jsxs("div",{className:a("prompt-area-container relative text-sm leading-relaxed",s),children:[ue==="above"&&ct,A==="above"&&ut,jsxs("div",{className:"relative",children:[jsx("div",{ref:B,contentEditable:!l,suppressContentEditableWarning:true,role:"textbox","aria-label":ce??"Text input","aria-multiline":"true","aria-disabled":l||void 0,"aria-describedby":V,"data-test-id":se,spellCheck:te,className:a("prompt-area-editor","w-full min-w-0 break-words whitespace-pre-wrap outline-none",l&&"cursor-not-allowed opacity-50"),style:nn,onFocus:m,onInput:M?_:he,onKeyDown:rn,onClick:be,onPaste:r.onPaste,onCopy:r.onCopy,onCut:r.onCut,onDrop:r.onDrop,onDragOver:r.onDragOver,onCompositionStart:r.onCompositionStart,onCompositionEnd:r.onCompositionEnd,onBlur:on}),M&&ne&&!u&&jsx("div",{"aria-hidden":"true",className:"pointer-events-auto absolute right-0 bottom-0 left-0 cursor-pointer",style:{height:"32px"},onClick:()=>B.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)))"}})}),sn&&n&&(Array.isArray(n)?jsx(Yt,{texts:n}):jsx("div",{className:"pointer-events-none absolute top-0 left-0 select-none",style:{color:"var(--prompt-area-placeholder, var(--muted-foreground))"},"aria-hidden":"true",children:n}))]}),A==="below"&&ut,ue==="below"&&ct,ie&&ie.config.mode==="dropdown"&&jsx(qt,{suggestions:de,loading:Q,error:ye,emptyMessage:ie.config.emptyMessage,selectedIndex:Pe,onSelect:Ke,onDismiss:_e,triggerRect:ze,triggerChar:ie.config.char})]})}
14
+ export{et as a,zt as b,Or as c};
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { S as Segment, f as TriggerConfig, C as ChipSegment, c as PromptAreaImage, P as PromptAreaFile, b as PromptAreaHandle } from '../types-C4BgDEpe.js';
2
+ import { S as Segment, f as TriggerConfig, C as ChipSegment, c as PromptAreaImage, P as PromptAreaFile, b as PromptAreaHandle } from '../types-BFUUkyja.js';
3
3
 
4
4
  type CompactPromptAreaProps = {
5
5
  /** The document segments (controlled) */
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- export{a as CompactPromptArea}from'../chunk-2R57LWJO.js';import'../chunk-LJJ6HHR6.js';import'../chunk-23Y7B365.js';import'../chunk-MJSTEY4N.js';
2
+ export{a as CompactPromptArea}from'../chunk-L4CDMX5T.js';import'../chunk-ZOC6DT7K.js';import'../chunk-23Y7B365.js';import'../chunk-NXA7D75N.js';
@@ -1,5 +1,5 @@
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';
1
+ import { f as TriggerConfig, A as ActiveTrigger, h as TriggerPosition, S as Segment, C as ChipSegment, T as TextSegment } from '../types-BFUUkyja.js';
2
+ export { a as ChipStyle, P as PromptAreaFile, c as PromptAreaImage, e as TriggerActivateContext, g as TriggerMode, i as TriggerSuggestion } from '../types-BFUUkyja.js';
3
3
 
4
4
  /**
5
5
  * Pure logic engine for the PromptArea component.
@@ -158,12 +158,22 @@ declare function mentionTrigger(opts?: MentionTriggerOptions): TriggerConfig;
158
158
  type CommandTriggerOptions = TriggerPresetOptions & {
159
159
  /** Override the trigger character. Defaults to `'/'`. */
160
160
  char?: string;
161
+ /**
162
+ * Where the command trigger is valid. Defaults to `'any'`, so commands fire
163
+ * anywhere a `/` follows whitespace — not just at the start of a line.
164
+ * Set to `'start'` to restrict the dropdown to the very start of the input
165
+ * or immediately after a newline (the classic slash-command behavior).
166
+ */
167
+ position?: TriggerPosition;
161
168
  };
162
169
  /**
163
170
  * Creates a **command** trigger (`/`).
164
171
  *
165
- * Defaults: `position: 'start'`, `mode: 'dropdown'`, `chipStyle: 'inline'`,
172
+ * Defaults: `position: 'any'`, `mode: 'dropdown'`, `chipStyle: 'inline'`,
166
173
  * accessible label `"command"`.
174
+ *
175
+ * By default commands work everywhere in the input. Pass `position: 'start'`
176
+ * to limit them to the start of a line.
167
177
  */
168
178
  declare function commandTrigger(opts?: CommandTriggerOptions): TriggerConfig;
169
179
  type HashtagTriggerOptions = TriggerPresetOptions & {
@@ -1 +1 @@
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';
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-2NJF7OW6.js';export{e as detectActiveTrigger,d as isValidTriggerPosition,n as mergeAdjacentTextSegments,l as parseInlineMarkdown,b as plainTextToSegments,f as resolveChip,i as resolveTriggersInSegments,m as segmentsEqual,a as segmentsToPlainText}from'../chunk-NXA7D75N.js';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { PromptArea, PromptAreaBind, PromptAreaState, UsePromptAreaStateOptions, usePromptArea, usePromptAreaState } from './prompt-area/index.js';
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';
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-BFUUkyja.js';
3
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';
4
4
  export { ActionBar, ActionBarProps } from './action-bar/index.js';
5
5
  export { StatusBar, StatusBarProps } from './status-bar/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  'use client';
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';
2
+ export{a as usePromptAreaState}from'./chunk-IVIA26DG.js';export{a as ActionBar}from'./chunk-REFXDE4K.js';export{a as StatusBar}from'./chunk-6VISE4VA.js';export{a as CompactPromptArea}from'./chunk-L4CDMX5T.js';export{c as PromptArea,b as usePromptArea}from'./chunk-ZOC6DT7K.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-2NJF7OW6.js';export{e as detectActiveTrigger,d as isValidTriggerPosition,n as mergeAdjacentTextSegments,l as parseInlineMarkdown,b as plainTextToSegments,f as resolveChip,i as resolveTriggersInSegments,m as segmentsEqual,a as segmentsToPlainText}from'./chunk-NXA7D75N.js';
@@ -1,6 +1,6 @@
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 } 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';
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-BFUUkyja.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-BFUUkyja.js';
4
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';
5
5
 
6
6
  /**
@@ -28,7 +28,7 @@ export { CallbackTriggerOptions, CommandTriggerOptions, HashtagTriggerOptions, M
28
28
  * />
29
29
  * ```
30
30
  */
31
- declare function PromptArea({ value, onChange, triggers, placeholder, className, disabled, markdown, onSubmit, onEscape, onChipClick, onChipAdd, onChipDelete, onLinkClick, onPaste, onUndo, onRedo, minHeight, maxHeight, autoFocus, autoGrow, 'aria-label': ariaLabel, 'data-test-id': dataTestId, images, imagePosition, onImagePaste, onImageRemove, onImageClick, files, filePosition, onFileRemove, onFileClick, ref, }: PromptAreaProps & {
31
+ declare function PromptArea({ value, onChange, triggers, placeholder, className, disabled, markdown, normalizeBullets, onSubmit, onEscape, onChipClick, onChipAdd, onChipDelete, onLinkClick, onPaste, onUndo, onRedo, minHeight, maxHeight, autoFocus, autoGrow, 'aria-label': ariaLabel, 'data-test-id': dataTestId, images, imagePosition, onImagePaste, onImageRemove, onImageClick, files, filePosition, onFileRemove, onFileClick, onKeyDown, onBlur, onRawPaste, submitOnEnter, spellCheck, maxLength, 'aria-describedby': ariaDescribedBy, ref, }: PromptAreaProps & {
32
32
  ref?: React.Ref<PromptAreaHandle>;
33
33
  }): react.JSX.Element;
34
34
 
@@ -46,10 +46,14 @@ type UsePromptAreaOptions = {
46
46
  segments: Segment[];
47
47
  source: 'internal' | 'external';
48
48
  }) => void;
49
+ onRawPaste?: (e: React.ClipboardEvent<HTMLDivElement>) => void;
49
50
  onUndo?: (segments: Segment[]) => void;
50
51
  onRedo?: (segments: Segment[]) => void;
51
52
  onImagePaste?: (file: File) => void;
52
53
  markdown?: boolean;
54
+ normalizeBullets?: boolean;
55
+ submitOnEnter?: boolean;
56
+ maxLength?: number;
53
57
  };
54
58
  type UsePromptAreaReturn = {
55
59
  editorRef: React.RefObject<HTMLDivElement | null>;
@@ -76,7 +80,7 @@ type UsePromptAreaReturn = {
76
80
  onBlur: () => void;
77
81
  };
78
82
  };
79
- declare function usePromptArea({ value, onChange, triggers, onSubmit, onEscape, onChipClick, onChipAdd, onChipDelete, onLinkClick, onPaste, onUndo, onRedo, onImagePaste, markdown: markdownEnabled, }: UsePromptAreaOptions): UsePromptAreaReturn;
83
+ declare function usePromptArea({ value, onChange, triggers, onSubmit, onEscape, onChipClick, onChipAdd, onChipDelete, onLinkClick, onPaste, onRawPaste, onUndo, onRedo, onImagePaste, markdown: markdownEnabled, normalizeBullets, submitOnEnter, maxLength, }: UsePromptAreaOptions): UsePromptAreaReturn;
80
84
 
81
85
  /**
82
86
  * Convenience hook that wires up all the boilerplate state for a PromptArea.
@@ -1,2 +1,2 @@
1
1
  'use client';
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';
2
+ export{a as usePromptAreaState}from'../chunk-IVIA26DG.js';export{c as PromptArea,b as usePromptArea}from'../chunk-ZOC6DT7K.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-2NJF7OW6.js';export{e as detectActiveTrigger,d as isValidTriggerPosition,n as mergeAdjacentTextSegments,l as parseInlineMarkdown,b as plainTextToSegments,f as resolveChip,i as resolveTriggersInSegments,m as segmentsEqual,a as segmentsToPlainText}from'../chunk-NXA7D75N.js';
package/dist/styles.css CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! tailwindcss v4.3.1 | MIT License | https://tailwindcss.com */
2
- @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-duration:initial;--tw-ease:initial;--tw-animation-delay:0s;--tw-animation-direction:normal;--tw-animation-duration:initial;--tw-animation-fill-mode:none;--tw-animation-iteration-count:1;--tw-enter-blur:0;--tw-enter-opacity:1;--tw-enter-rotate:0;--tw-enter-scale:1;--tw-enter-translate-x:0;--tw-enter-translate-y:0;--tw-exit-blur:0;--tw-exit-opacity:1;--tw-exit-rotate:0;--tw-exit-scale:1;--tw-exit-translate-x:0;--tw-exit-translate-y:0}}}@layer theme{:root,:host{--color-blue-100:oklch(93.2% .032 255.585);--color-black:#000;--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--font-weight-medium:500;--font-weight-bold:700;--leading-relaxed:1.625;--radius-2xl:1rem;--ease-out:cubic-bezier(0, 0, .2, 1);--ease-in-out:cubic-bezier(.4, 0, .2, 1);--animate-spin:spin 1s linear infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}}@layer base;@layer components{.prompt-area-chip{cursor:pointer;-webkit-user-select:none;user-select:none;vertical-align:baseline;background-color:var(--secondary);color:var(--foreground);border-radius:4px;align-items:center;margin:0 1px;padding:1px 6px;font-size:.875rem;font-weight:500;transition:background-color .2s,transform .15s cubic-bezier(.4,0,.2,1),box-shadow .2s;display:inline-flex;position:relative;overflow:hidden}.prompt-area-chip:hover{background-color:var(--secondary)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:hover{background-color:color-mix(in srgb, var(--secondary) 80%, var(--foreground) 20%)}}.prompt-area-chip:hover{box-shadow:0 1px 4px var(--foreground)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:hover{box-shadow:0 1px 4px color-mix(in srgb, var(--foreground) 10%, transparent)}}.prompt-area-chip:active{background-color:var(--secondary);transform:scale(.93)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:active{background-color:color-mix(in srgb, var(--secondary) 70%, var(--foreground) 30%)}}.prompt-area-chip:active{transition:background-color 50ms,transform 80ms cubic-bezier(.4,0,.2,1),box-shadow 50ms;box-shadow:0 0 #0000}@keyframes prompt-area-chip-ripple{0%{opacity:.4;transform:scale(0)}to{opacity:0;transform:scale(2.5)}}.prompt-area-chip-ripple{aspect-ratio:1;background:var(--foreground);border-radius:50%;width:100%;position:absolute}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip-ripple{background:color-mix(in srgb, var(--foreground) 15%, transparent)}}.prompt-area-chip-ripple{pointer-events:none;animation:.45s ease-out forwards prompt-area-chip-ripple}.prompt-area-md-marker{font-size:0;display:inline}.prompt-area-chip--inline{border-radius:0;margin:0;padding:0;font-weight:700}}@layer utilities{.pointer-events-auto{pointer-events:auto}.pointer-events-none{pointer-events:none}.collapse{visibility:collapse}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.inset-0{inset:0}.top-0{top:0}.top-0\.5{top:calc(var(--spacing) * .5)}.right-0{right:0}.right-0\.5{right:calc(var(--spacing) * .5)}.bottom-0{bottom:0}.bottom-4{bottom:calc(var(--spacing) * 4)}.bottom-full{bottom:100%}.left-0{left:0}.z-10{z-index:10}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.mt-0\.5{margin-top:calc(var(--spacing) * .5)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.ml-auto{margin-left:auto}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.size-4{width:calc(var(--spacing) * 4);height:calc(var(--spacing) * 4)}.size-9{width:calc(var(--spacing) * 9);height:calc(var(--spacing) * 9)}.h-3\.5{height:calc(var(--spacing) * 3.5)}.h-4{height:calc(var(--spacing) * 4)}.h-5{height:calc(var(--spacing) * 5)}.h-10{height:calc(var(--spacing) * 10)}.h-14{height:calc(var(--spacing) * 14)}.h-16{height:calc(var(--spacing) * 16)}.h-\[600px\]{height:600px}.h-full{height:100%}.max-h-48{max-height:calc(var(--spacing) * 48)}.max-h-\[240px\]{max-height:240px}.w-3\.5{width:calc(var(--spacing) * 3.5)}.w-4{width:calc(var(--spacing) * 4)}.w-5{width:calc(var(--spacing) * 5)}.w-16{width:calc(var(--spacing) * 16)}.w-36{width:calc(var(--spacing) * 36)}.w-48{width:calc(var(--spacing) * 48)}.w-full{width:100%}.min-w-0{min-width:0}.min-w-\[200px\]{min-width:200px}.flex-1{flex:1}.flex-shrink-0{flex-shrink:0}.shrink{flex-shrink:1}.shrink-0{flex-shrink:0}.animate-in{animation:enter var(--tw-animation-duration,var(--tw-duration,.15s))var(--tw-ease,ease)var(--tw-animation-delay,0s)var(--tw-animation-iteration-count,1)var(--tw-animation-direction,normal)var(--tw-animation-fill-mode,none)}.animate-spin{animation:var(--animate-spin)}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.place-items-center{place-items:center}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-1{gap:var(--spacing)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius)}.rounded-md{border-radius:calc(var(--radius) - 2px)}.rounded-xl{border-radius:calc(var(--radius) + 4px)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-border{border-color:var(--border)}.border-white{border-color:var(--color-white)}.border-t-transparent{border-top-color:#0000}.bg-accent{background-color:var(--accent)}.bg-background{background-color:var(--background)}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab, red, red)){.bg-black\/40{background-color:color-mix(in oklab, var(--color-black) 40%, transparent)}}.bg-black\/60{background-color:#0009}@supports (color:color-mix(in lab, red, red)){.bg-black\/60{background-color:color-mix(in oklab, var(--color-black) 60%, transparent)}}.bg-blue-100{background-color:var(--color-blue-100)}.bg-muted{background-color:var(--muted)}.bg-popover{background-color:var(--popover)}.bg-primary{background-color:var(--primary)}.object-cover{object-fit:cover}.p-1\.5{padding:calc(var(--spacing) * 1.5)}.p-2{padding:calc(var(--spacing) * 2)}.p-4{padding:calc(var(--spacing) * 4)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.px-5{padding-inline:calc(var(--spacing) * 5)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.pt-1{padding-top:var(--spacing)}.pt-2{padding-top:calc(var(--spacing) * 2)}.pt-4{padding-top:calc(var(--spacing) * 4)}.pb-2{padding-bottom:calc(var(--spacing) * 2)}.pb-3{padding-bottom:calc(var(--spacing) * 3)}.text-left{text-align:left}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.break-words{overflow-wrap:break-word}.whitespace-pre-wrap{white-space:pre-wrap}.text-destructive{color:var(--destructive)}.text-foreground{color:var(--foreground)}.text-muted-foreground{color:var(--muted-foreground)}.text-primary{color:var(--primary)}.text-primary-foreground{color:var(--primary-foreground)}.text-white{color:var(--color-white)}.italic{font-style:italic}.underline{text-decoration-line:underline}.opacity-50{opacity:.5}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a), 0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a), 0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.fade-in-0{--tw-enter-opacity:0}.outline-none{--tw-outline-style:none;outline-style:none}.select-none{-webkit-user-select:none;user-select:none}.zoom-in-95{--tw-enter-scale:.95}.slide-in-from-top-4{--tw-enter-translate-y:calc(4*var(--spacing)*-1)}@media (hover:hover){.hover\:bg-accent:hover{background-color:var(--accent)}.hover\:bg-black\/80:hover{background-color:#000c}@supports (color:color-mix(in lab, red, red)){.hover\:bg-black\/80:hover{background-color:color-mix(in oklab, var(--color-black) 80%, transparent)}}.hover\:bg-primary\/90:hover{background-color:var(--primary)}@supports (color:color-mix(in lab, red, red)){.hover\:bg-primary\/90:hover{background-color:color-mix(in oklab, var(--primary) 90%, transparent)}}.hover\:text-foreground:hover{color:var(--foreground)}.hover\:text-primary\/80:hover{color:var(--primary)}@supports (color:color-mix(in lab, red, red)){.hover\:text-primary\/80:hover{color:color-mix(in oklab, var(--primary) 80%, transparent)}}}.disabled\:pointer-events-none:disabled{pointer-events:none}.disabled\:opacity-50:disabled{opacity:.5}.dark\:bg-white\/60:is(.dark *){background-color:#fff9}@supports (color:color-mix(in lab, red, red)){.dark\:bg-white\/60:is(.dark *){background-color:color-mix(in oklab, var(--color-white) 60%, transparent)}}.dark\:text-black:is(.dark *){color:var(--color-black)}@media (hover:hover){.dark\:hover\:bg-white\/80:is(.dark *):hover{background-color:#fffc}@supports (color:color-mix(in lab, red, red)){.dark\:hover\:bg-white\/80:is(.dark *):hover{background-color:color-mix(in oklab, var(--color-white) 80%, transparent)}}}}@property --tw-animation-delay{syntax:"*";inherits:false;initial-value:0s}@property --tw-animation-direction{syntax:"*";inherits:false;initial-value:normal}@property --tw-animation-duration{syntax:"*";inherits:false}@property --tw-animation-fill-mode{syntax:"*";inherits:false;initial-value:none}@property --tw-animation-iteration-count{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-translate-y{syntax:"*";inherits:false;initial-value:0}:root{--radius:.625rem;--background:oklch(100% 0 0);--foreground:oklch(14.5% 0 0);--card:oklch(100% 0 0);--card-foreground:oklch(14.5% 0 0);--popover:oklch(100% 0 0);--popover-foreground:oklch(14.5% 0 0);--primary:oklch(20.5% 0 0);--primary-foreground:oklch(98.5% 0 0);--secondary:oklch(97% 0 0);--secondary-foreground:oklch(20.5% 0 0);--muted:oklch(97% 0 0);--muted-foreground:oklch(55.6% 0 0);--accent:oklch(97% 0 0);--accent-foreground:oklch(20.5% 0 0);--destructive:oklch(57.7% .245 27.325);--border:oklch(92.2% 0 0);--input:oklch(92.2% 0 0);--ring:oklch(70.8% 0 0)}.dark{--background:oklch(14.5% 0 0);--foreground:oklch(98.5% 0 0);--card:oklch(20.5% 0 0);--card-foreground:oklch(98.5% 0 0);--popover:oklch(20.5% 0 0);--popover-foreground:oklch(98.5% 0 0);--primary:oklch(92.2% 0 0);--primary-foreground:oklch(20.5% 0 0);--secondary:oklch(26.9% 0 0);--secondary-foreground:oklch(98.5% 0 0);--muted:oklch(26.9% 0 0);--muted-foreground:oklch(70.8% 0 0);--accent:oklch(26.9% 0 0);--accent-foreground:oklch(98.5% 0 0);--destructive:oklch(70.4% .191 22.216);--border:oklch(100% 0 0/.14);--input:oklch(100% 0 0/.2);--ring:oklch(55.6% 0 0)}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0)scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1))rotate(var(--tw-enter-rotate,0));filter:blur(var(--tw-enter-blur,0))}}
2
+ @layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-duration:initial;--tw-ease:initial;--tw-animation-delay:0s;--tw-animation-direction:normal;--tw-animation-duration:initial;--tw-animation-fill-mode:none;--tw-animation-iteration-count:1;--tw-enter-blur:0;--tw-enter-opacity:1;--tw-enter-rotate:0;--tw-enter-scale:1;--tw-enter-translate-x:0;--tw-enter-translate-y:0;--tw-exit-blur:0;--tw-exit-opacity:1;--tw-exit-rotate:0;--tw-exit-scale:1;--tw-exit-translate-x:0;--tw-exit-translate-y:0}}}@layer theme{:root,:host{--color-blue-100:oklch(93.2% .032 255.585);--color-black:#000;--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-base:1rem;--text-base--line-height:calc(1.5 / 1);--font-weight-medium:500;--font-weight-bold:700;--leading-relaxed:1.625;--radius-2xl:1rem;--radius-3xl:1.5rem;--ease-in-out:cubic-bezier(.4, 0, .2, 1);--animate-spin:spin 1s linear infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}}@layer base;@layer components{.prompt-area-chip{cursor:pointer;-webkit-user-select:none;user-select:none;vertical-align:baseline;background-color:var(--secondary);color:var(--foreground);border-radius:4px;align-items:center;margin:0 1px;padding:1px 6px;font-size:.875rem;font-weight:500;transition:background-color .2s,transform .15s cubic-bezier(.4,0,.2,1),box-shadow .2s;display:inline-flex;position:relative;overflow:hidden}.prompt-area-chip:hover{background-color:var(--secondary)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:hover{background-color:color-mix(in srgb, var(--secondary) 80%, var(--foreground) 20%)}}.prompt-area-chip:hover{box-shadow:0 1px 4px var(--foreground)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:hover{box-shadow:0 1px 4px color-mix(in srgb, var(--foreground) 10%, transparent)}}.prompt-area-chip:active{background-color:var(--secondary);transform:scale(.93)}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip:active{background-color:color-mix(in srgb, var(--secondary) 70%, var(--foreground) 30%)}}.prompt-area-chip:active{transition:background-color 50ms,transform 80ms cubic-bezier(.4,0,.2,1),box-shadow 50ms;box-shadow:0 0 #0000}@keyframes prompt-area-chip-ripple{0%{opacity:.4;transform:scale(0)}to{opacity:0;transform:scale(2.5)}}.prompt-area-chip-ripple{aspect-ratio:1;background:var(--foreground);border-radius:50%;width:100%;position:absolute}@supports (color:color-mix(in lab, red, red)){.prompt-area-chip-ripple{background:color-mix(in srgb, var(--foreground) 15%, transparent)}}.prompt-area-chip-ripple{pointer-events:none;animation:.45s ease-out forwards prompt-area-chip-ripple}.prompt-area-md-marker{font-size:0;display:inline}.prompt-area-chip--inline{border-radius:0;margin:0;padding:0;font-weight:700}@media (prefers-reduced-motion:reduce){.prompt-area-editor{transition:none!important}}}@layer utilities{.pointer-events-auto{pointer-events:auto}.pointer-events-none{pointer-events:none}.collapse{visibility:collapse}.visible{visibility:visible}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.sticky{position:sticky}.inset-0{inset:0}.top-0{top:0}.top-0\.5{top:calc(var(--spacing) * .5)}.right-0{right:0}.right-0\.5{right:calc(var(--spacing) * .5)}.right-1\.5{right:calc(var(--spacing) * 1.5)}.bottom-0{bottom:0}.bottom-1\.5{bottom:calc(var(--spacing) * 1.5)}.bottom-4{bottom:calc(var(--spacing) * 4)}.bottom-full{bottom:100%}.left-0{left:0}.left-1\.5{left:calc(var(--spacing) * 1.5)}.isolate{isolation:isolate}.z-10{z-index:10}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.mt-0\.5{margin-top:calc(var(--spacing) * .5)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.ml-auto{margin-left:auto}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.size-4{width:calc(var(--spacing) * 4);height:calc(var(--spacing) * 4)}.size-9{width:calc(var(--spacing) * 9);height:calc(var(--spacing) * 9)}.h-3\.5{height:calc(var(--spacing) * 3.5)}.h-4{height:calc(var(--spacing) * 4)}.h-5{height:calc(var(--spacing) * 5)}.h-10{height:calc(var(--spacing) * 10)}.h-14{height:calc(var(--spacing) * 14)}.h-16{height:calc(var(--spacing) * 16)}.h-\[600px\]{height:600px}.h-full{height:100%}.max-h-48{max-height:calc(var(--spacing) * 48)}.w-3\.5{width:calc(var(--spacing) * 3.5)}.w-4{width:calc(var(--spacing) * 4)}.w-5{width:calc(var(--spacing) * 5)}.w-16{width:calc(var(--spacing) * 16)}.w-36{width:calc(var(--spacing) * 36)}.w-48{width:calc(var(--spacing) * 48)}.w-full{width:100%}.min-w-0{min-width:0}.min-w-\[200px\]{min-width:200px}.flex-1{flex:1}.flex-shrink-0{flex-shrink:0}.shrink{flex-shrink:1}.shrink-0{flex-shrink:0}.grow{flex-grow:1}.animate-in{animation:enter var(--tw-animation-duration,var(--tw-duration,.15s))var(--tw-ease,ease)var(--tw-animation-delay,0s)var(--tw-animation-iteration-count,1)var(--tw-animation-direction,normal)var(--tw-animation-fill-mode,none)}.animate-spin{animation:var(--animate-spin)}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.cursor-text{cursor:text}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.place-items-center{place-items:center}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-1{gap:var(--spacing)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-3xl{border-radius:var(--radius-3xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius)}.rounded-md{border-radius:calc(var(--radius) - 2px)}.rounded-xl{border-radius:calc(var(--radius) + 4px)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-border{border-color:var(--border)}.border-white{border-color:var(--color-white)}.border-t-transparent{border-top-color:#0000}.bg-accent{background-color:var(--accent)}.bg-background{background-color:var(--background)}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab, red, red)){.bg-black\/40{background-color:color-mix(in oklab, var(--color-black) 40%, transparent)}}.bg-black\/60{background-color:#0009}@supports (color:color-mix(in lab, red, red)){.bg-black\/60{background-color:color-mix(in oklab, var(--color-black) 60%, transparent)}}.bg-blue-100{background-color:var(--color-blue-100)}.bg-muted{background-color:var(--muted)}.bg-popover{background-color:var(--popover)}.bg-primary{background-color:var(--primary)}.object-cover{object-fit:cover}.p-2{padding:calc(var(--spacing) * 2)}.p-4{padding:calc(var(--spacing) * 4)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-3{padding-block:calc(var(--spacing) * 3)}.pt-2{padding-top:calc(var(--spacing) * 2)}.pt-4{padding-top:calc(var(--spacing) * 4)}.pr-5{padding-right:calc(var(--spacing) * 5)}.pr-\[3\.25rem\]{padding-right:3.25rem}.pr-\[5\.5rem\]{padding-right:5.5rem}.pb-2{padding-bottom:calc(var(--spacing) * 2)}.pb-14{padding-bottom:calc(var(--spacing) * 14)}.pl-5{padding-left:calc(var(--spacing) * 5)}.pl-\[3\.25rem\]{padding-left:3.25rem}.text-left{text-align:left}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-6{--tw-leading:calc(var(--spacing) * 6);line-height:calc(var(--spacing) * 6)}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.break-words{overflow-wrap:break-word}.whitespace-pre-wrap{white-space:pre-wrap}.text-destructive{color:var(--destructive)}.text-foreground{color:var(--foreground)}.text-muted-foreground{color:var(--muted-foreground)}.text-primary{color:var(--primary)}.text-primary-foreground{color:var(--primary-foreground)}.text-white{color:var(--color-white)}.italic{font-style:italic}.underline{text-decoration-line:underline}.opacity-50{opacity:.5}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a), 0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-md{--tw-shadow:0 4px 6px -1px var(--tw-shadow-color,#0000001a), 0 2px 4px -2px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-\[border-radius\,box-shadow\,border-color\]{transition-property:border-radius,box-shadow,border-color;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-\[padding\]{transition-property:padding;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.duration-\[240ms\]{--tw-duration:.24s;transition-duration:.24s}.ease-\[cubic-bezier\(0\.33\,1\,0\.68\,1\)\]{--tw-ease:cubic-bezier(.33,1,.68,1);transition-timing-function:cubic-bezier(.33,1,.68,1)}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.fade-in-0{--tw-enter-opacity:0}.outline-none{--tw-outline-style:none;outline-style:none}.select-none{-webkit-user-select:none;user-select:none}.zoom-in-95{--tw-enter-scale:.95}.slide-in-from-top-4{--tw-enter-translate-y:calc(4*var(--spacing)*-1)}@media (hover:hover){.hover\:bg-accent:hover{background-color:var(--accent)}.hover\:bg-black\/80:hover{background-color:#000c}@supports (color:color-mix(in lab, red, red)){.hover\:bg-black\/80:hover{background-color:color-mix(in oklab, var(--color-black) 80%, transparent)}}.hover\:bg-primary\/90:hover{background-color:var(--primary)}@supports (color:color-mix(in lab, red, red)){.hover\:bg-primary\/90:hover{background-color:color-mix(in oklab, var(--primary) 90%, transparent)}}.hover\:text-foreground:hover{color:var(--foreground)}.hover\:text-primary\/80:hover{color:var(--primary)}@supports (color:color-mix(in lab, red, red)){.hover\:text-primary\/80:hover{color:color-mix(in oklab, var(--primary) 80%, transparent)}}}.disabled\:pointer-events-none:disabled{pointer-events:none}.disabled\:opacity-50:disabled{opacity:.5}@media (prefers-reduced-motion:reduce){.motion-reduce\:transition-none{transition-property:none}}.dark\:bg-white\/60:is(.dark *){background-color:#fff9}@supports (color:color-mix(in lab, red, red)){.dark\:bg-white\/60:is(.dark *){background-color:color-mix(in oklab, var(--color-white) 60%, transparent)}}.dark\:text-black:is(.dark *){color:var(--color-black)}@media (hover:hover){.dark\:hover\:bg-white\/80:is(.dark *):hover{background-color:#fffc}@supports (color:color-mix(in lab, red, red)){.dark\:hover\:bg-white\/80:is(.dark *):hover{background-color:color-mix(in oklab, var(--color-white) 80%, transparent)}}}}@property --tw-animation-delay{syntax:"*";inherits:false;initial-value:0s}@property --tw-animation-direction{syntax:"*";inherits:false;initial-value:normal}@property --tw-animation-duration{syntax:"*";inherits:false}@property --tw-animation-fill-mode{syntax:"*";inherits:false;initial-value:none}@property --tw-animation-iteration-count{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-enter-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-enter-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-blur{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-opacity{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-rotate{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-scale{syntax:"*";inherits:false;initial-value:1}@property --tw-exit-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-exit-translate-y{syntax:"*";inherits:false;initial-value:0}:root{--radius:.625rem;--background:oklch(100% 0 0);--foreground:oklch(14.5% 0 0);--card:oklch(100% 0 0);--card-foreground:oklch(14.5% 0 0);--popover:oklch(100% 0 0);--popover-foreground:oklch(14.5% 0 0);--primary:oklch(20.5% 0 0);--primary-foreground:oklch(98.5% 0 0);--secondary:oklch(97% 0 0);--secondary-foreground:oklch(20.5% 0 0);--muted:oklch(97% 0 0);--muted-foreground:oklch(55.6% 0 0);--accent:oklch(97% 0 0);--accent-foreground:oklch(20.5% 0 0);--destructive:oklch(57.7% .245 27.325);--border:oklch(92.2% 0 0);--input:oklch(92.2% 0 0);--ring:oklch(70.8% 0 0)}.dark{--background:oklch(14.5% 0 0);--foreground:oklch(98.5% 0 0);--card:oklch(20.5% 0 0);--card-foreground:oklch(98.5% 0 0);--popover:oklch(20.5% 0 0);--popover-foreground:oklch(98.5% 0 0);--primary:oklch(92.2% 0 0);--primary-foreground:oklch(20.5% 0 0);--secondary:oklch(26.9% 0 0);--secondary-foreground:oklch(98.5% 0 0);--muted:oklch(26.9% 0 0);--muted-foreground:oklch(70.8% 0 0);--accent:oklch(26.9% 0 0);--accent-foreground:oklch(98.5% 0 0);--destructive:oklch(70.4% .191 22.216);--border:oklch(100% 0 0/.14);--input:oklch(100% 0 0/.2);--ring:oklch(55.6% 0 0)}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0)scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1))rotate(var(--tw-enter-rotate,0));filter:blur(var(--tw-enter-blur,0))}}
package/dist/tailwind.css CHANGED
@@ -178,4 +178,14 @@
178
178
  /* Base styles for status-bar; Tailwind utilities handle the layout.
179
179
  This class exists as a stable selector for consumer overrides. */
180
180
  }
181
+
182
+ /* Honour reduced-motion for the auto-grow editor. Its height / min-height
183
+ transition is applied via inline styles (e.g. the compact prompt area's
184
+ collapse/expand), so it sits outside Tailwind's `motion-reduce` variant
185
+ and needs an explicit override here. */
186
+ @media (prefers-reduced-motion: reduce) {
187
+ .prompt-area-editor {
188
+ transition: none !important;
189
+ }
190
+ }
181
191
  }
@@ -41,9 +41,12 @@ type TriggerPosition = 'start' | 'any';
41
41
  /**
42
42
  * Defines how a trigger behaves when activated.
43
43
  * - 'dropdown': Shows a popover with suggestions from `onSearch`
44
- * - 'callback': Fires `onActivate` immediately without a dropdown
44
+ * - 'callback': Inserts the char, then fires `onActivate` with the typed query
45
+ * - 'launch': Fires `onActivate` on keydown and SUPPRESSES the char (it never
46
+ * enters the editor) — for opening an external surface (dialog, palette) where
47
+ * no in-editor text should appear. Honors `position` like the other modes.
45
48
  */
46
- type TriggerMode = 'dropdown' | 'callback';
49
+ type TriggerMode = 'dropdown' | 'callback' | 'launch';
47
50
  /**
48
51
  * Visual style for rendered chips.
49
52
  * - 'pill': Button-like pill with background color, padding, border-radius (default)
@@ -92,8 +95,9 @@ type TriggerConfig = {
92
95
  */
93
96
  onSelect?: (suggestion: TriggerSuggestion) => string | void;
94
97
  /**
95
- * For 'callback' mode: called when the trigger is activated.
96
- * Receives the full input text and cursor position.
98
+ * For 'callback' and 'launch' modes: called when the trigger is activated.
99
+ * Receives the full input text and cursor position. For 'launch' it fires on
100
+ * keydown (before the char would insert); for 'callback' it fires after.
97
101
  */
98
102
  onActivate?: (context: TriggerActivateContext) => void;
99
103
  /**
@@ -200,6 +204,13 @@ type PromptAreaProps = {
200
204
  disabled?: boolean;
201
205
  /** Whether to render simple inline markdown (bold, italic, URLs, lists) */
202
206
  markdown?: boolean;
207
+ /**
208
+ * When markdown is on, the editor rewrites typed list markers (`- ` / `* `)
209
+ * to a `•` bullet glyph in the model. Set to `false` to keep the original
210
+ * marker in the value/`onChange` text — needed when a host renders the output
211
+ * as real markdown, where `•` is not a valid list marker. Default `true`.
212
+ */
213
+ normalizeBullets?: boolean;
203
214
  /** Called when Enter is pressed (without Shift) */
204
215
  onSubmit?: (segments: Segment[]) => void;
205
216
  /** Called when Escape is pressed */
@@ -225,6 +236,18 @@ type PromptAreaProps = {
225
236
  minHeight?: number;
226
237
  /** Maximum height in pixels */
227
238
  maxHeight?: number;
239
+ /**
240
+ * Maximum number of plain-text characters allowed, enforced on typed input:
241
+ * once the editor exceeds the cap it is truncated back to this length, with
242
+ * the caret kept where the edit happened. Chips count as their
243
+ * `trigger + displayText` length.
244
+ *
245
+ * The cap applies to typing only. Paste is not capped — divert it via
246
+ * `onRawPaste` if needed — and the imperative `setText` / `appendText` also
247
+ * bypass it, so a programmatic write can exceed the cap until the next
248
+ * keystroke truncates.
249
+ */
250
+ maxLength?: number;
228
251
  /** Auto-focus on mount */
229
252
  autoFocus?: boolean;
230
253
  /** When true, the area auto-grows to fit content on focus and shrinks on blur */
@@ -251,6 +274,34 @@ type PromptAreaProps = {
251
274
  onFileRemove?: (file: PromptAreaFile) => void;
252
275
  /** Called when the user clicks a file attachment */
253
276
  onFileClick?: (file: PromptAreaFile) => void;
277
+ /**
278
+ * Called on keydown before PromptArea's own handling. Call `preventDefault()`
279
+ * to suppress the built-in behaviour (submit, trigger navigation, etc.) for
280
+ * that key and take over entirely.
281
+ */
282
+ onKeyDown?: (e: React.KeyboardEvent<HTMLDivElement>) => void;
283
+ /**
284
+ * Called on blur with the native FocusEvent, so consumers can inspect
285
+ * `relatedTarget` (e.g. to retain focus when a composer toolbar is clicked).
286
+ */
287
+ onBlur?: (e: React.FocusEvent<HTMLDivElement>) => void;
288
+ /**
289
+ * Called at the start of a paste, before PromptArea reads the clipboard. Call
290
+ * `preventDefault()` to take over the paste completely — e.g. to divert large
291
+ * text or non-image files to an upload pipeline. The built-in segment/image
292
+ * paste handling is skipped when the event's default is prevented.
293
+ */
294
+ onRawPaste?: (e: React.ClipboardEvent<HTMLDivElement>) => void;
295
+ /**
296
+ * Whether pressing Enter (without Shift) submits. Defaults to true. Set false
297
+ * to make Enter insert a newline instead (e.g. on touch devices where submit
298
+ * is a dedicated button).
299
+ */
300
+ submitOnEnter?: boolean;
301
+ /** Forwarded to the editable element. */
302
+ spellCheck?: boolean;
303
+ /** Forwarded to the editable element as `aria-describedby`. */
304
+ 'aria-describedby'?: string;
254
305
  };
255
306
  /**
256
307
  * Ref handle exposed by PromptArea via useImperativeHandle.
@@ -266,6 +317,29 @@ type PromptAreaHandle = {
266
317
  getPlainText: () => string;
267
318
  /** Clear all content */
268
319
  clear: () => void;
320
+ /**
321
+ * Replace all content with plain text (chips dropped), caret moved to the
322
+ * end. Not capped by `maxLength` (see its docs); undoable.
323
+ */
324
+ setText: (text: string) => void;
325
+ /**
326
+ * Append plain text at the end (existing chips preserved), caret moved to the
327
+ * end. Not capped by `maxLength` (see its docs); undoable.
328
+ */
329
+ appendText: (text: string) => void;
330
+ /** Caret offset in plain-text characters, or null when unavailable. */
331
+ getCursorPosition: () => number | null;
332
+ /** Move the caret to a plain-text offset. */
333
+ setCursorPosition: (offset: number) => void;
334
+ /** Move the caret to the end of the content. */
335
+ setCursorToEnd: () => void;
336
+ /** Current selection as plain-text offsets, or null when there is none. */
337
+ getSelection: () => {
338
+ start: number;
339
+ end: number;
340
+ } | null;
341
+ /** Set the selection between two plain-text offsets. */
342
+ setSelection: (start: number, end: number) => void;
269
343
  };
270
344
 
271
345
  export type { ActiveTrigger as A, ChipSegment as C, PromptAreaFile as P, Segment as S, TextSegment as T, ChipStyle as a, PromptAreaHandle as b, PromptAreaImage as c, PromptAreaProps as d, TriggerActivateContext as e, TriggerConfig as f, TriggerMode as g, TriggerPosition as h, TriggerSuggestion as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prompt-area",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
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",
@@ -72,27 +72,30 @@
72
72
  "clean": "rm -rf dist",
73
73
  "typecheck": "tsc --noEmit",
74
74
  "lint:exports": "publint && attw --pack . --profile esm-only --exclude-entrypoints styles.css tailwind.css",
75
+ "size": "size-limit",
75
76
  "prepublishOnly": "pnpm run build"
76
77
  },
77
78
  "engines": {
78
79
  "node": ">=18"
79
80
  },
80
81
  "peerDependencies": {
82
+ "clsx": ">=2",
81
83
  "react": ">=18",
82
- "react-dom": ">=18"
83
- },
84
- "dependencies": {
85
- "clsx": "^2.1.1",
86
- "tailwind-merge": "^3.6.0"
84
+ "react-dom": ">=18",
85
+ "tailwind-merge": ">=2"
87
86
  },
88
87
  "devDependencies": {
89
- "@arethetypeswrong/cli": "^0.18.2",
88
+ "@arethetypeswrong/cli": "^0.18.4",
89
+ "@size-limit/preset-small-lib": "^12.1.0",
90
90
  "@tailwindcss/cli": "^4.3.0",
91
91
  "@types/react": "19.2.17",
92
92
  "@types/react-dom": "^19.2.3",
93
+ "clsx": "^2.1.1",
93
94
  "publint": "^0.3.14",
94
95
  "react": "^19.2.7",
95
96
  "react-dom": "^19.2.7",
97
+ "size-limit": "^12.1.0",
98
+ "tailwind-merge": "^3.6.0",
96
99
  "tailwindcss": "^4.3.0",
97
100
  "tsup": "^8.5.0",
98
101
  "tw-animate-css": "^1.4.0",
@@ -1,3 +0,0 @@
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};
@@ -1 +0,0 @@
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};
@@ -1,14 +0,0 @@
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};
@@ -1,7 +0,0 @@
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 +0,0 @@
1
- 'use client';
2
- import {a}from'./chunk-23Y7B365.js';import {jsxs,jsx}from'react/jsx-runtime';function c({left:e,right:t,className:o,disabled:a$1=false,"aria-label":n,"data-test-id":s,ref:p}){return jsxs("div",{ref:p,role:"toolbar","aria-label":n??"Action bar","aria-disabled":a$1||void 0,"data-test-id":s,className:a("action-bar","flex items-center justify-between gap-2 pt-2",a$1&&"pointer-events-none opacity-50",o),children:[e&&jsx("div",{className:"flex items-center gap-1",children:e}),t&&jsx("div",{className:"ml-auto flex items-center gap-1",children:t})]})}export{c as a};