{"version":3,"file":"mention.cjs","sources":["../../../components/editor/mention.ts"],"sourcesContent":["/**\n * The parts of the mention model that are pure strings and offsets — no\n * ProseMirror. Kept in its own module so `PromptInput`'s root, its textarea and\n * the mention registry can share the vocabulary without pulling the editor\n * engine into their module graph.\n */\n\n/** Attributes carried by a mention node. All of them survive serialization. */\nexport interface MentionAttrs {\n  id: string;\n  label: string;\n  /** Entity kind — `\"project\"`, `\"user\"`, … */\n  type: string;\n  /** The character that opened the menu this mention was picked from. */\n  trigger: string;\n}\n\n/**\n * A mention as it appears in a value change or a submitted message. Offsets\n * index into the derived plain text.\n */\nexport interface EditorMention extends MentionAttrs {\n  start: number;\n  end: number;\n}\n\n/** Cache key for the item store that backs a chip's icon, trailing and data. */\nexport function mentionKey(trigger: string, type: string, id: string): string {\n  return `${trigger}|${type}|${id}`;\n}\n\n/**\n * A trigger is a single ASCII punctuation character. `[`, `]` and `\\` are\n * excluded because the dialect uses them as delimiters, and `_` because it\n * reads as a word character — so a bare markdown link (`[label](a:b)`) and a\n * snake_cased word are never mistaken for a mention.\n */\nconst TRIGGER_PATTERN = new RegExp(\n  '^[\\\\u0021-\\\\u002F\\\\u003A-\\\\u0040\\\\u005E\\\\u0060\\\\u007B-\\\\u007E]$'\n);\n\nexport function isTriggerCharacter(char: string): boolean {\n  return char.length === 1 && TRIGGER_PATTERN.test(char);\n}\n\nfunction escapeLabel(value: string): string {\n  return value.replace(/[\\\\\\])]/g, match => `\\\\${match}`);\n}\n\nfunction escapeRef(value: string): string {\n  return value.replace(/[\\\\:)]/g, match => `\\\\${match}`);\n}\n\n/** Serializes one mention — `@[label](type:id)`. */\nexport function serializeMention(attrs: MentionAttrs): string {\n  return `${attrs.trigger}[${escapeLabel(attrs.label)}](${escapeRef(\n    attrs.type\n  )}:${escapeRef(attrs.id)})`;\n}\n\n/**\n * Drops whitespace at the document edges — including the space auto-inserted\n * after a chip — while leaving mentions alone, then re-bases the offsets. A\n * chip is never at an edge in the whitespace sense, so trimming can only ever\n * remove text.\n */\nexport function trimDetails<\n  T extends { markup: string; text: string; mentions: EditorMention[] }\n>(details: T): T {\n  const leading = details.text.length - details.text.trimStart().length;\n  return {\n    ...details,\n    markup: details.markup.trim(),\n    text: details.text.trim(),\n    mentions: details.mentions.map(mention => ({\n      ...mention,\n      start: mention.start - leading,\n      end: mention.end - leading\n    }))\n  };\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AAqBH;SACgB,UAAU,CAAC,OAAe,EAAE,IAAY,EAAE,EAAU,EAAA;AAClE,IAAA,OAAO,GAAG,OAAO,CAAA,CAAA,EAAI,IAAI,CAAI,CAAA,EAAA,EAAE,EAAE,CAAC;AACpC,CAAC;AAED;;;;;AAKG;AACH,MAAM,eAAe,GAAG,IAAI,MAAM,CAChC,iEAAiE,CAClE,CAAC;AAEI,SAAU,kBAAkB,CAAC,IAAY,EAAA;AAC7C,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,WAAW,CAAC,KAAa,EAAA;AAChC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,IAAI,CAAA,EAAA,EAAK,KAAK,CAAA,CAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS,CAAC,KAAa,EAAA;AAC9B,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,CAAA,EAAA,EAAK,KAAK,CAAA,CAAE,CAAC,CAAC;AACzD,CAAC;AAED;AACM,SAAU,gBAAgB,CAAC,KAAmB,EAAA;IAClD,OAAO,CAAA,EAAG,KAAK,CAAC,OAAO,CAAA,CAAA,EAAI,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAK,EAAA,EAAA,SAAS,CAC/D,KAAK,CAAC,IAAI,CACX,CAAI,CAAA,EAAA,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA,CA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