{"version":3,"file":"prompt-input-context.cjs","sources":["../../../components/prompt-input/prompt-input-context.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, type RefObject, useContext } from 'react';\nimport type { EditorMention } from '../editor/mention';\nimport type {\n  PromptInputMentionItem,\n  PromptInputMentionRegistry\n} from './prompt-input-mention-registry';\n\nexport type PromptInputStatus = 'idle' | 'submitted' | 'streaming' | 'error';\n\n/** A mention as reported on change and on submit. Offsets index into `text`. */\nexport interface PromptInputMention extends EditorMention {\n  /** Whatever the item carried when it was picked or resolved. */\n  data?: unknown;\n}\n\nexport interface PromptInputMessage {\n  /** Plain text with each label inlined behind its trigger. */\n  text: string;\n  /** Round-trippable markup — feeds straight back into `value`. */\n  markup: string;\n  /** Document order; duplicates preserved. */\n  mentions: PromptInputMention[];\n}\n\n/** What the mounted input part derives from its own state. */\nexport interface PromptInputValueDetails {\n  text: string;\n  mentions: PromptInputMention[];\n}\n\n/**\n * The channel the mounted input part reports through. `Textarea` and `Editor`\n * both implement it, so Root never has to know which substrate is underneath.\n */\nexport interface PromptInputInputApi {\n  focus: () => void;\n  /** Push a value that came from outside the part (controlled prop, reset). */\n  setMarkup: (markup: string) => void;\n  /** Text and mentions for a markup string the part has not seen yet. */\n  deriveExternal: (markup: string) => PromptInputValueDetails;\n  /** The live value, read off the part rather than off React state. */\n  getMessage: () => PromptInputMessage;\n  insertMention?: (\n    item: PromptInputMentionItem,\n    options?: { trigger?: string }\n  ) => void;\n}\n\nexport type PromptInputPartKind = 'textarea' | 'editor';\n\nexport interface PromptInputContextValue {\n  /** Markup — opaque to Root, interpreted only by `Editor`. */\n  value: string;\n  details: PromptInputValueDetails;\n  /** No mentions, and text that trims to `\"\"`. */\n  empty: boolean;\n  /** Called by the mounted part on every change it makes. */\n  setValue: (markup: string, details: PromptInputValueDetails) => void;\n  status: PromptInputStatus;\n  disabled: boolean;\n  onStop?: () => void;\n  inputRef: RefObject<HTMLElement | null>;\n  /** The `<form>`, so the suggestion menu can size itself to the composer. */\n  frameRef: RefObject<HTMLFormElement | null>;\n  registerInput: (\n    node: HTMLElement | null,\n    api?: PromptInputInputApi,\n    kind?: PromptInputPartKind\n  ) => void;\n  requestSubmit: () => void;\n  mentions: PromptInputMentionRegistry;\n  /** Whether an `Editor` part is mounted — `Mentions` requires one. */\n  editorMounted: boolean;\n}\n\nexport const PromptInputContext = createContext<PromptInputContextValue | null>(\n  null\n);\n\nexport function usePromptInputContext(part: string): PromptInputContextValue {\n  const context = useContext(PromptInputContext);\n  if (!context) {\n    throw new Error(`PromptInput.${part} must be used within <PromptInput>`);\n  }\n  return context;\n}\n\n/**\n * The one emptiness predicate, read by submit gating, `data-empty` and the\n * placeholder so they cannot disagree: a message of nothing but a chip is not\n * empty, and the space auto-inserted after a chip does not make it non-empty.\n */\nexport function isEmptyValue(details: PromptInputValueDetails): boolean {\n  return details.mentions.length === 0 && details.text.trim() === '';\n}\n"],"names":[],"mappings":";;;;;;AAiFM;AACJ;;AAEE;;AAEF;AACF;AAEA;;;;AAIG;AACG;AACJ;AACF;;;;"}