{"version":3,"file":"insert-mention.cjs","names":["getMarkupRange","getMentionPlainText"],"sources":["../../../../src/components/Mentions/utils/insert-mention.ts"],"sourcesContent":["import { getMarkupRange } from './map-plain-text-index';\nimport type { MentionConfig } from './types';\nimport { getMentionPlainText, type MentionWalk } from './walk-mentions';\n\ninterface InsertMentionInput {\n  walk: MentionWalk;\n  config: MentionConfig;\n  queryStart: number;\n  queryEnd: number;\n  id: string;\n  display: string;\n  appendSpace: boolean;\n}\n\nexport function insertMention({\n  walk,\n  config,\n  queryStart,\n  queryEnd,\n  id,\n  display,\n  appendSpace,\n}: InsertMentionInput) {\n  const { markupStart, markupEnd } = getMarkupRange(walk, queryStart, queryEnd);\n  const after = walk.value.slice(markupEnd);\n  const space = appendSpace && !after.startsWith(' ') ? ' ' : '';\n  const markup = config.serializer.insert({ id, display });\n\n  return {\n    value: walk.value.slice(0, markupStart) + markup + space + after,\n    caret: queryStart + getMentionPlainText(config, id, display).length + (appendSpace ? 1 : 0),\n  };\n}\n"],"mappings":";;;;AAcA,SAAgB,cAAc,EAC5B,MACA,QACA,YACA,UACA,IACA,SACA,eACqB;CACrB,MAAM,EAAE,aAAa,cAAcA,6BAAAA,eAAe,MAAM,YAAY,QAAQ;CAC5E,MAAM,QAAQ,KAAK,MAAM,MAAM,SAAS;CACxC,MAAM,QAAQ,eAAe,CAAC,MAAM,WAAW,GAAG,IAAI,MAAM;CAC5D,MAAM,SAAS,OAAO,WAAW,OAAO;EAAE;EAAI;CAAQ,CAAC;CAEvD,OAAO;EACL,OAAO,KAAK,MAAM,MAAM,GAAG,WAAW,IAAI,SAAS,QAAQ;EAC3D,OAAO,aAAaC,sBAAAA,oBAAoB,QAAQ,IAAI,OAAO,CAAC,CAAC,UAAU,cAAc,IAAI;CAC3F;AACF"}