@pixerate/editor 0.26.0 → 0.27.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.
Files changed (79) hide show
  1. package/README.md +8 -2
  2. package/dist/agent/index.cjs +59 -9
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +6 -4
  5. package/dist/agent/index.d.ts +6 -4
  6. package/dist/agent/index.js +52 -2
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/{builtins-Chj6zv_O.d.ts → builtins-haN82vjT.d.ts} +33 -3
  9. package/dist/{builtins-CdPcLwwF.d.cts → builtins-nMXh9sT3.d.cts} +33 -3
  10. package/dist/canvas/index.cjs +372 -8
  11. package/dist/canvas/index.cjs.map +1 -1
  12. package/dist/canvas/index.d.cts +72 -4
  13. package/dist/canvas/index.d.ts +72 -4
  14. package/dist/canvas/index.js +368 -4
  15. package/dist/canvas/index.js.map +1 -1
  16. package/dist/{chunk-UBCFIABU.js → chunk-5H2OPMXZ.js} +183 -6
  17. package/dist/chunk-5H2OPMXZ.js.map +1 -0
  18. package/dist/{chunk-NFVBT3UZ.cjs → chunk-66IMF6OD.cjs} +108 -25
  19. package/dist/chunk-66IMF6OD.cjs.map +1 -0
  20. package/dist/{chunk-Q2OHWD2A.js → chunk-6IO7WUSU.js} +19 -5
  21. package/dist/chunk-6IO7WUSU.js.map +1 -0
  22. package/dist/{chunk-YOMYSFJU.cjs → chunk-AGR7EVRW.cjs} +49 -35
  23. package/dist/chunk-AGR7EVRW.cjs.map +1 -0
  24. package/dist/{chunk-RRREAOVM.cjs → chunk-HNDSPZ5T.cjs} +4 -4
  25. package/dist/{chunk-RRREAOVM.cjs.map → chunk-HNDSPZ5T.cjs.map} +1 -1
  26. package/dist/chunk-HXDMZQTD.cjs +497 -0
  27. package/dist/chunk-HXDMZQTD.cjs.map +1 -0
  28. package/dist/chunk-IB3ZHQAX.js +497 -0
  29. package/dist/chunk-IB3ZHQAX.js.map +1 -0
  30. package/dist/{chunk-X7HXL2SB.js → chunk-JT7AXQTE.js} +336 -10
  31. package/dist/chunk-JT7AXQTE.js.map +1 -0
  32. package/dist/{chunk-HDYMLS3X.cjs → chunk-MC2LQN5S.cjs} +196 -19
  33. package/dist/chunk-MC2LQN5S.cjs.map +1 -0
  34. package/dist/{chunk-JOIREKL7.js → chunk-UKI64KUD.js} +85 -2
  35. package/dist/chunk-UKI64KUD.js.map +1 -0
  36. package/dist/{chunk-MHEPLBFB.js → chunk-WON34HKM.js} +2 -2
  37. package/dist/{chunk-NQF32I6Z.cjs → chunk-YK5TATOF.cjs} +461 -135
  38. package/dist/chunk-YK5TATOF.cjs.map +1 -0
  39. package/dist/commands/index.cjs +30 -410
  40. package/dist/commands/index.cjs.map +1 -1
  41. package/dist/commands/index.d.cts +1 -1
  42. package/dist/commands/index.d.ts +1 -1
  43. package/dist/commands/index.js +17 -397
  44. package/dist/commands/index.js.map +1 -1
  45. package/dist/{controller-CxXGOEmy.d.cts → controller-w6eRTjF8.d.cts} +67 -2
  46. package/dist/{controller-CxXGOEmy.d.ts → controller-w6eRTjF8.d.ts} +67 -2
  47. package/dist/extensions/index.cjs +23 -5
  48. package/dist/extensions/index.cjs.map +1 -1
  49. package/dist/extensions/index.d.cts +1 -1
  50. package/dist/extensions/index.d.ts +1 -1
  51. package/dist/extensions/index.js +23 -5
  52. package/dist/{index-jcJwmBYt.d.cts → index-C6gaQRH0.d.cts} +53 -4
  53. package/dist/{index-B273Zllk.d.ts → index-DXAv_R08.d.ts} +53 -4
  54. package/dist/index.cjs +66 -26
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +8 -6
  57. package/dist/index.d.ts +8 -6
  58. package/dist/index.js +46 -6
  59. package/dist/index.js.map +1 -1
  60. package/dist/serializers/index.cjs +5 -3
  61. package/dist/serializers/index.cjs.map +1 -1
  62. package/dist/serializers/index.d.cts +13 -3
  63. package/dist/serializers/index.d.ts +13 -3
  64. package/dist/serializers/index.js +4 -2
  65. package/dist/spreadsheet/index.cjs +22 -2
  66. package/dist/spreadsheet/index.cjs.map +1 -1
  67. package/dist/spreadsheet/index.d.cts +76 -3
  68. package/dist/spreadsheet/index.d.ts +76 -3
  69. package/dist/spreadsheet/index.js +21 -1
  70. package/package.json +1 -1
  71. package/dist/chunk-HDYMLS3X.cjs.map +0 -1
  72. package/dist/chunk-JOIREKL7.js.map +0 -1
  73. package/dist/chunk-NFVBT3UZ.cjs.map +0 -1
  74. package/dist/chunk-NQF32I6Z.cjs.map +0 -1
  75. package/dist/chunk-Q2OHWD2A.js.map +0 -1
  76. package/dist/chunk-UBCFIABU.js.map +0 -1
  77. package/dist/chunk-X7HXL2SB.js.map +0 -1
  78. package/dist/chunk-YOMYSFJU.cjs.map +0 -1
  79. /package/dist/{chunk-MHEPLBFB.js.map → chunk-WON34HKM.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-HDYMLS3X.cjs","../src/extensions/table/extension.ts","../src/extensions/table/actions.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,oCAAqD;AACrD,yCAAuD;AACvD,gHAAwB;AACxB,6HAA2B;AAC3B,yIAA8B;AAC9B,iIAA4B;AAE5B,IAAM,WAAA,EAAa,CAAC,GAAA,EAAU,IAAA,EAAA,mBAC5B,GAAA,0BAAA,CAAM,IAAI,IAAA,mBAAK,GAAA,6BAAK,OAAA,4BAAA,CAAU,IAAI,IAAA,mBAAK,GAAA,6BAAK,OAAA,6BAAS,UAAA,mBAAW,GAAA,6BAAK,UAAA,GAAW,GAAA;AAElF,IAAM,UAAA,EAAY,UAAA,CAAW,MAAA,EAAQ,OAAO,CAAA;AAC5C,IAAM,aAAA,EAAe,UAAA,CAAW,SAAA,EAAW,UAAU,CAAA;AACrD,IAAM,gBAAA,EAAkB,UAAA,CAAW,YAAA,EAAc,aAAa,CAAA;AAC9D,IAAM,cAAA,EAAgB,UAA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B,MAAA;AACT,MAAA;AACc,QAAA;AACG,QAAA;AAC9B,MAAA;AACF,IAAA;AACU,IAAA;AACD,MAAA;AACS,MAAA;AAClB,IAAA;AACF,EAAA;AACF;AF1BmD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-HDYMLS3X.cjs","sourcesContent":[null,"import { getHTMLFromFragment, type Extensions } from \"@tiptap/core\";\nimport { Fragment, type Node as ProsemirrorNode } from \"@tiptap/pm/model\";\nimport * as _Table from \"@tiptap/extension-table\";\nimport * as _TableRow from \"@tiptap/extension-table-row\";\nimport * as _TableHeader from \"@tiptap/extension-table-header\";\nimport * as _TableCell from \"@tiptap/extension-table-cell\";\n\nconst resolveExt = (mod: any, name: string) =>\n mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;\n\nconst BaseTable = resolveExt(_Table, \"Table\");\nconst BaseTableRow = resolveExt(_TableRow, \"TableRow\");\nconst BaseTableHeader = resolveExt(_TableHeader, \"TableHeader\");\nconst BaseTableCell = resolveExt(_TableCell, \"TableCell\");\n\n/** Horizontal alignment of a table cell (`align` attribute). */\nexport type TableCellAlignment = \"left\" | \"center\" | \"right\" | \"justify\";\n\nconst ALIGNMENTS = new Set<TableCellAlignment>([\"left\", \"center\", \"right\", \"justify\"]);\n\n/** Returns a valid cell alignment, or `null`. */\nexport function normalizeTableCellAlignment(value: unknown): TableCellAlignment | null {\n const v = typeof value === \"string\" ? value.trim().toLowerCase() : \"\";\n return ALIGNMENTS.has(v as TableCellAlignment) ? (v as TableCellAlignment) : null;\n}\n\n/**\n * Color values allowed as a cell background: hex, `rgb()/rgba()/hsl()/hsla()`\n * with numeric arguments, or a CSS color keyword. Anything else (e.g.\n * `url(...)`, `expression(...)`, `;`) is rejected because the value ends up in\n * a `style` attribute.\n */\nconst COLOR_REGEX =\n /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\\(\\s*[-0-9.%\\s,/deg]+\\)|[a-z]{3,20})$/i;\n\n/** Returns a safe CSS color for a cell background, or `null`. */\nexport function normalizeTableCellColor(value: unknown): string | null {\n const v = typeof value === \"string\" ? value.trim() : \"\";\n if (!v || v.length > 64 || !COLOR_REGEX.test(v)) return null;\n if (/^(?:inherit|initial|unset|revert|transparent)$/i.test(v)) return null;\n return v;\n}\n\n/** Cell attributes added on top of TipTap's `colspan` / `rowspan` / `colwidth`. */\nconst cellAttributes = () => ({\n align: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellAlignment(element.style?.textAlign || element.getAttribute(\"align\")),\n renderHTML: (attrs: Record<string, any>) => {\n const align = normalizeTableCellAlignment(attrs.align);\n return align ? { style: `text-align: ${align}` } : {};\n },\n },\n backgroundColor: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellColor(\n element.getAttribute(\"data-background-color\") ||\n element.style?.backgroundColor ||\n element.getAttribute(\"bgcolor\"),\n ),\n renderHTML: (attrs: Record<string, any>) => {\n const color = normalizeTableCellColor(attrs.backgroundColor);\n return color ? { style: `background-color: ${color}`, \"data-background-color\": color } : {};\n },\n },\n});\n\n// ---------------------------------------------------------------------------\n// Markdown (tiptap-markdown)\n// ---------------------------------------------------------------------------\n\nconst children = (node: ProsemirrorNode) => {\n const list: ProsemirrorNode[] = [];\n node.forEach((child) => list.push(child));\n return list;\n};\n\nconst hasSpan = (cell: ProsemirrorNode) => (cell.attrs.colspan ?? 1) > 1 || (cell.attrs.rowspan ?? 1) > 1;\n\n/**\n * Whether a table can be written as a GFM pipe table: the first row is all\n * header cells, the other rows have none, no cell spans rows or columns, and\n * every cell holds a single paragraph.\n */\nexport function isGfmTable(node: ProsemirrorNode): boolean {\n const rows = children(node);\n if (rows.length === 0) return false;\n const width = rows[0].childCount;\n return rows.every(\n (row, r) =>\n row.childCount === width &&\n children(row).every(\n (cell) =>\n (r === 0 ? cell.type.name === \"tableHeader\" : cell.type.name === \"tableCell\") &&\n !hasSpan(cell) &&\n cell.childCount === 1 &&\n cell.firstChild!.type.name === \"paragraph\",\n ),\n );\n}\n\nconst DELIMITERS: Record<string, string> = { left: \":---\", center: \":---:\", right: \"---:\" };\n\n/**\n * tiptap-markdown serializer for tables: GFM pipe tables (with column\n * alignment from the header cells and `|` escaped) when `isGfmTable`, HTML\n * otherwise (spans, header columns, multi-paragraph cells).\n */\nfunction serializeTableMarkdown(state: any, node: ProsemirrorNode) {\n if (!isGfmTable(node)) {\n const html = getHTMLFromFragment(Fragment.from(node), node.type.schema);\n // An HTML block must start on its own line and contain no blank lines.\n state.write(html.replace(/\\n{2,}/g, \"\\n\"));\n state.closeBlock(node);\n return;\n }\n const previous = state.inTable;\n state.inTable = true;\n children(node).forEach((row, r) => {\n if (r) state.ensureNewLine();\n state.write(\"| \");\n children(row).forEach((cell, c) => {\n if (c) state.write(\" | \");\n const paragraph = cell.firstChild!;\n // Render in place (mid-line, so no block prefix is added), then escape\n // the cell's pipes and line breaks, which would end the cell or row.\n const start = state.out.length;\n if (paragraph.childCount) state.renderInline(paragraph);\n const text: string = state.out.slice(start);\n state.out = state.out.slice(0, start) + text.replace(/\\n/g, \" \").replace(/\\|/g, \"\\\\|\");\n });\n state.write(\" |\");\n if (r === 0) {\n const delimiter = children(row).map((cell) => DELIMITERS[cell.attrs.align] ?? \"---\");\n state.ensureNewLine();\n state.write(`| ${delimiter.join(\" | \")} |`);\n }\n });\n state.inTable = previous;\n state.closeBlock(node);\n}\n\n// ---------------------------------------------------------------------------\n// Extensions\n// ---------------------------------------------------------------------------\n\nexport interface RichTextTableOptions {\n /** Drag column borders to resize columns (stored as `colwidth`). Default `true`. */\n resizable: boolean;\n /** Width of the resize handle in pixels. Default 5. */\n handleWidth: number;\n /** Minimum cell width in pixels. Default 25. */\n cellMinWidth: number;\n /** Whether the last column can be resized. Default `true`. */\n lastColumnResizable: boolean;\n /** Allow selecting the whole table as a node (click its border, Esc from a cell selection). Default `true`. */\n allowTableNodeSelection: boolean;\n /** HTML attributes of the `<table>` element. */\n HTMLAttributes: Record<string, any>;\n /** HTML attributes of `<td>` elements. */\n cellHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<th>` elements. */\n headerHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<tr>` elements. */\n rowHTMLAttributes: Record<string, any>;\n}\n\nexport const DEFAULT_TABLE_OPTIONS: RichTextTableOptions = {\n resizable: true,\n handleWidth: 5,\n cellMinWidth: 25,\n lastColumnResizable: true,\n allowTableNodeSelection: true,\n HTMLAttributes: { class: \"pixerate-table\" },\n cellHTMLAttributes: {},\n headerHTMLAttributes: {},\n rowHTMLAttributes: {},\n};\n\n/** TipTap's `Table` with the GFM-aware markdown serializer. */\nexport const Table = BaseTable.extend({\n addStorage() {\n return { markdown: { serialize: serializeTableMarkdown } };\n },\n});\n\nexport const TableRow = BaseTableRow;\n\n/** TipTap's `TableCell` plus `align` and `backgroundColor` attributes. */\nexport const TableCell = BaseTableCell.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/** TipTap's `TableHeader` plus `align` and `backgroundColor` attributes. */\nexport const TableHeader = BaseTableHeader.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/**\n * The table extensions (`table`, `tableRow`, `tableHeader`, `tableCell`)\n * configured for rich documents: resizable columns, header rows, columns and\n * cells, `colspan` / `rowspan` from imported HTML, cell alignment and\n * background, table node selection and GFM markdown. `createRichTextPreset`\n * adds them unless `table: false`.\n */\nexport function createTableExtensions(options: Partial<RichTextTableOptions> = {}): Extensions {\n const o = { ...DEFAULT_TABLE_OPTIONS, ...options };\n return [\n Table.configure({\n resizable: o.resizable,\n handleWidth: o.handleWidth,\n cellMinWidth: o.cellMinWidth,\n lastColumnResizable: o.lastColumnResizable,\n allowTableNodeSelection: o.allowTableNodeSelection,\n HTMLAttributes: o.HTMLAttributes,\n }),\n TableRow.configure({ HTMLAttributes: o.rowHTMLAttributes }),\n TableHeader.configure({ HTMLAttributes: o.headerHTMLAttributes }),\n TableCell.configure({ HTMLAttributes: o.cellHTMLAttributes }),\n ];\n}\n","import type { Editor } from \"@tiptap/core\";\nimport type { EditorState } from \"@tiptap/pm/state\";\nimport { CellSelection, isInTable, selectedRect } from \"@tiptap/pm/tables\";\nimport { isTrackChangesEnabled } from \"../track-changes\";\nimport {\n normalizeTableCellAlignment,\n normalizeTableCellColor,\n type TableCellAlignment,\n} from \"./extension\";\n\n/** Table operations shared by the command registry, the toolbars and agent tools. */\nexport type TableAction =\n | \"insertTable\"\n | \"addRowBefore\"\n | \"addRowAfter\"\n | \"deleteRow\"\n | \"addColumnBefore\"\n | \"addColumnAfter\"\n | \"deleteColumn\"\n | \"deleteTable\"\n | \"mergeCells\"\n | \"splitCell\"\n | \"toggleHeaderRow\"\n | \"toggleHeaderColumn\"\n | \"toggleHeaderCell\"\n | \"goToNextCell\"\n | \"goToPreviousCell\"\n | \"setCellAlignment\"\n | \"setCellBackground\";\n\n/** Parameters of `insertTable`, `setCellAlignment` and `setCellBackground`. */\nexport interface TableActionParams {\n /** `insertTable`: number of rows (1–100, default 3). */\n rows?: number;\n /** `insertTable`: number of columns (1–50, default 3). */\n cols?: number;\n /** `insertTable`: make the first row a header row (default `true`). */\n withHeaderRow?: boolean;\n /** `setCellAlignment`: `left`, `center`, `right`, `justify`, or `null` to clear. */\n align?: TableCellAlignment | null;\n /** `setCellBackground`: a CSS color, or `null` to clear. */\n color?: string | null;\n}\n\nexport interface TableActionInfo {\n action: TableAction;\n label: string;\n description: string;\n keywords: readonly string[];\n}\n\n/** Every table action with its label, in toolbar order. */\nexport const TABLE_ACTIONS: readonly TableActionInfo[] = [\n { action: \"insertTable\", label: \"Insert Table\", description: \"Inserts a table (rows, cols, withHeaderRow) at the cursor.\", keywords: [\"table\", \"grid\", \"new\"] },\n { action: \"addRowBefore\", label: \"Insert Row Above\", description: \"Adds a row above the current row.\", keywords: [\"row\", \"add\", \"above\"] },\n { action: \"addRowAfter\", label: \"Insert Row Below\", description: \"Adds a row below the current row.\", keywords: [\"row\", \"add\", \"below\"] },\n { action: \"deleteRow\", label: \"Delete Row\", description: \"Deletes the selected rows.\", keywords: [\"row\", \"remove\"] },\n { action: \"addColumnBefore\", label: \"Insert Column Left\", description: \"Adds a column left of the current column.\", keywords: [\"column\", \"add\", \"left\", \"before\"] },\n { action: \"addColumnAfter\", label: \"Insert Column Right\", description: \"Adds a column right of the current column.\", keywords: [\"column\", \"add\", \"right\", \"after\"] },\n { action: \"deleteColumn\", label: \"Delete Column\", description: \"Deletes the selected columns.\", keywords: [\"column\", \"remove\"] },\n { action: \"deleteTable\", label: \"Delete Table\", description: \"Deletes the table around the cursor.\", keywords: [\"table\", \"remove\"] },\n { action: \"mergeCells\", label: \"Merge Cells\", description: \"Merges the selected cells into one.\", keywords: [\"combine\", \"join\", \"span\"] },\n { action: \"splitCell\", label: \"Split Cell\", description: \"Splits a merged cell back into single cells.\", keywords: [\"unmerge\", \"span\"] },\n { action: \"toggleHeaderRow\", label: \"Toggle Header Row\", description: \"Turns the first row into header cells, or back.\", keywords: [\"header\", \"row\", \"th\"] },\n { action: \"toggleHeaderColumn\", label: \"Toggle Header Column\", description: \"Turns the first column into header cells, or back.\", keywords: [\"header\", \"column\", \"th\"] },\n { action: \"toggleHeaderCell\", label: \"Toggle Header Cell\", description: \"Turns the selected cells into header cells, or back.\", keywords: [\"header\", \"cell\", \"th\"] },\n { action: \"goToNextCell\", label: \"Next Cell\", description: \"Moves the cursor to the next cell.\", keywords: [\"tab\", \"navigate\"] },\n { action: \"goToPreviousCell\", label: \"Previous Cell\", description: \"Moves the cursor to the previous cell.\", keywords: [\"shift tab\", \"navigate\"] },\n { action: \"setCellAlignment\", label: \"Align Cells…\", description: \"Sets the horizontal alignment (align: left | center | right | justify | null) of the selected cells.\", keywords: [\"align\", \"left\", \"center\", \"right\"] },\n { action: \"setCellBackground\", label: \"Cell Background…\", description: \"Sets the background color (color: CSS color or null) of the selected cells.\", keywords: [\"shading\", \"fill\", \"color\"] },\n];\n\n/** A button of the table toolbars (`TableToolbar` in React and Svelte). */\nexport interface TableToolbarItem {\n /** Unique id (also the button's `data-action`). */\n id: string;\n action: TableAction;\n params?: TableActionParams;\n /** Short button text. */\n label: string;\n /** Accessible name and tooltip. */\n title: string;\n /** Items of one group are separated from the next group. */\n group: string;\n /** Toggle buttons: whether the button shows as pressed. */\n active?: (state: TableState) => boolean;\n}\n\n/** The default table toolbar: rows, columns, cells, headers, alignment, delete. */\nexport const DEFAULT_TABLE_TOOLBAR: readonly TableToolbarItem[] = [\n { id: \"addRowBefore\", action: \"addRowBefore\", label: \"+ Row ↑\", title: \"Insert row above\", group: \"rows\" },\n { id: \"addRowAfter\", action: \"addRowAfter\", label: \"+ Row ↓\", title: \"Insert row below\", group: \"rows\" },\n { id: \"deleteRow\", action: \"deleteRow\", label: \"− Row\", title: \"Delete row\", group: \"rows\" },\n { id: \"addColumnBefore\", action: \"addColumnBefore\", label: \"+ Col ←\", title: \"Insert column left\", group: \"columns\" },\n { id: \"addColumnAfter\", action: \"addColumnAfter\", label: \"+ Col →\", title: \"Insert column right\", group: \"columns\" },\n { id: \"deleteColumn\", action: \"deleteColumn\", label: \"− Col\", title: \"Delete column\", group: \"columns\" },\n { id: \"mergeCells\", action: \"mergeCells\", label: \"Merge\", title: \"Merge cells\", group: \"cells\" },\n { id: \"splitCell\", action: \"splitCell\", label: \"Split\", title: \"Split cell\", group: \"cells\" },\n { id: \"toggleHeaderRow\", action: \"toggleHeaderRow\", label: \"Header row\", title: \"Toggle header row\", group: \"headers\", active: (s) => s.headerRow },\n { id: \"toggleHeaderColumn\", action: \"toggleHeaderColumn\", label: \"Header col\", title: \"Toggle header column\", group: \"headers\", active: (s) => s.headerColumn },\n { id: \"toggleHeaderCell\", action: \"toggleHeaderCell\", label: \"Header cell\", title: \"Toggle header cell\", group: \"headers\", active: (s) => s.headerCell },\n { id: \"alignLeft\", action: \"setCellAlignment\", params: { align: \"left\" }, label: \"Left\", title: \"Align cell left\", group: \"align\", active: (s) => s.cellAlignment === \"left\" },\n { id: \"alignCenter\", action: \"setCellAlignment\", params: { align: \"center\" }, label: \"Center\", title: \"Align cell center\", group: \"align\", active: (s) => s.cellAlignment === \"center\" },\n { id: \"alignRight\", action: \"setCellAlignment\", params: { align: \"right\" }, label: \"Right\", title: \"Align cell right\", group: \"align\", active: (s) => s.cellAlignment === \"right\" },\n { id: \"deleteTable\", action: \"deleteTable\", label: \"Delete table\", title: \"Delete table\", group: \"table\" },\n];\n\nexport const MAX_TABLE_ROWS = 100;\nexport const MAX_TABLE_COLUMNS = 50;\n\nconst live = (editor: Editor | null | undefined): editor is Editor => !!editor && !editor.isDestroyed;\n\n/** Whether the editor's schema has the table nodes (`createRichTextPreset({ table })`). */\nexport function isTableEnabled(editor: Editor | null | undefined): boolean {\n return live(editor) && !!editor.schema.nodes.table && !!editor.schema.nodes.tableRow;\n}\n\n/** Whether the selection (cursor, text or cell selection) is inside a table. */\nexport function isSelectionInTable(state: EditorState): boolean {\n if (!state.schema.nodes.table) return false;\n return state.selection instanceof CellSelection || isInTable(state);\n}\n\n/**\n * `shouldShow` for a table bubble menu (TipTap's `BubbleMenuPlugin`): shown\n * while an editable editor's selection is in a table, even a collapsed cursor.\n */\nexport function shouldShowTableBubbleMenu({ editor, state }: { editor: Editor; state: EditorState }): boolean {\n return editor.isEditable && isSelectionInTable(state);\n}\n\nconst isInt = (value: unknown, min: number, max: number) =>\n typeof value === \"number\" && Number.isInteger(value) && value >= min && value <= max;\n\nconst can = (editor: Editor, run: (chain: any) => any): boolean => {\n try {\n return !!run(editor.can().chain()).run();\n } catch {\n return false;\n }\n};\n\n/**\n * Whether a table action can run: `true`, or the reason it cannot (e.g.\n * \"Place the cursor in a table first.\").\n */\nexport function getTableActionState(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n): true | string {\n if (!live(editor)) return \"The editor is not available.\";\n if (!isTableEnabled(editor)) return \"Tables are not enabled in this editor.\";\n if (!editor.isEditable) return \"The editor is read-only.\";\n const state = editor.state;\n const inTable = isSelectionInTable(state);\n\n if (action === \"insertTable\") {\n if (inTable) return \"Tables cannot be nested: move the cursor out of the table first.\";\n if (params.rows !== undefined && !isInt(params.rows, 1, MAX_TABLE_ROWS)) {\n return `Rows must be a whole number from 1 to ${MAX_TABLE_ROWS}.`;\n }\n if (params.cols !== undefined && !isInt(params.cols, 1, MAX_TABLE_COLUMNS)) {\n return `Columns must be a whole number from 1 to ${MAX_TABLE_COLUMNS}.`;\n }\n return can(editor, (c) => c.insertTable({ rows: 1, cols: 1 })) ? true : \"A table cannot be inserted here.\";\n }\n\n if (!inTable) return \"Place the cursor in a table first.\";\n\n switch (action) {\n case \"mergeCells\":\n case \"splitCell\": {\n if (isTrackChangesEnabled(editor)) {\n return `${action === \"mergeCells\" ? \"Merging\" : \"Splitting\"} cells cannot be tracked: turn off Track Changes first.`;\n }\n if (action === \"mergeCells\") {\n return can(editor, (c) => c.mergeCells()) ? true : \"Select two or more adjacent cells to merge.\";\n }\n return can(editor, (c) => c.splitCell()) ? true : \"Only a merged cell can be split.\";\n }\n case \"deleteRow\":\n case \"deleteColumn\": {\n // prosemirror-tables only refuses to delete every row/column when dispatching.\n const rect = selectedRect(state);\n const all = action === \"deleteRow\"\n ? rect.top === 0 && rect.bottom === rect.map.height\n : rect.left === 0 && rect.right === rect.map.width;\n const what = action === \"deleteRow\" ? \"rows\" : \"columns\";\n if (all || !can(editor, (c) => c[action]())) return `These are all the ${what}: delete the table instead.`;\n return true;\n }\n case \"goToNextCell\":\n return can(editor, (c) => c.goToNextCell()) ? true : \"This is the last cell.\";\n case \"goToPreviousCell\":\n return can(editor, (c) => c.goToPreviousCell()) ? true : \"This is the first cell.\";\n case \"setCellAlignment\":\n if (params.align !== undefined && params.align !== null && !normalizeTableCellAlignment(params.align)) {\n return 'Alignment must be \"left\", \"center\", \"right\", \"justify\" or null.';\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.align) return \"Cell alignment is not supported by this schema.\";\n return true;\n case \"setCellBackground\":\n if (params.color !== undefined && params.color !== null && !normalizeTableCellColor(params.color)) {\n return \"Color must be a CSS color such as #fde68a, rgb(…) or a color name, or null.\";\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.backgroundColor) return \"Cell backgrounds are not supported by this schema.\";\n return true;\n default:\n return can(editor, (c) => c[action]()) ? true : \"This table action is not available here.\";\n }\n}\n\nexport interface RunTableActionOptions {\n /** Focus the editor (toolbars). Default `false`. */\n focus?: boolean;\n}\n\n/**\n * Runs a table action. Returns `false` (and changes nothing) when it cannot\n * run; check `getTableActionState` for the reason.\n */\nexport function runTableAction(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n options: RunTableActionOptions = {},\n): boolean {\n if (getTableActionState(editor, action, params) !== true) return false;\n const ed = editor as Editor;\n let chain: any = ed.chain();\n if (options.focus) chain = chain.focus();\n switch (action) {\n case \"insertTable\":\n chain = chain.insertTable({\n rows: params.rows ?? 3,\n cols: params.cols ?? 3,\n withHeaderRow: params.withHeaderRow ?? true,\n });\n break;\n case \"setCellAlignment\":\n chain = chain.setCellAttribute(\"align\", normalizeTableCellAlignment(params.align));\n break;\n case \"setCellBackground\":\n chain = chain.setCellAttribute(\"backgroundColor\", normalizeTableCellColor(params.color));\n break;\n default:\n chain = chain[action]();\n }\n return !!chain.run();\n}\n\nexport interface TableActionStatus {\n enabled: boolean;\n /** Why the action cannot run (only when `enabled` is false). */\n reason?: string;\n}\n\n/** The table at the selection and what can be done there. */\nexport interface TableState {\n /** The schema has tables. */\n enabled: boolean;\n /** The selection is inside a table. */\n inTable: boolean;\n /** Cells are selected (a `CellSelection`). */\n cellSelection: boolean;\n /** Size of the table (0 outside a table). */\n rows: number;\n columns: number;\n /** Row and column (0-based) of the selection's first cell, or -1. */\n row: number;\n column: number;\n /** The first row / first column are all header cells. */\n headerRow: boolean;\n headerColumn: boolean;\n /** The cell at the selection is a header cell. */\n headerCell: boolean;\n /** Alignment / background of the cell at the selection. */\n cellAlignment: TableCellAlignment | null;\n cellBackground: string | null;\n /** Enablement of every action (with the default params). */\n actions: Record<TableAction, TableActionStatus>;\n}\n\nconst NO_ACTIONS = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => [action, { enabled: false, reason: \"The editor is not available.\" }]),\n) as Record<TableAction, TableActionStatus>;\n\nexport const EMPTY_TABLE_STATE: TableState = Object.freeze({\n enabled: false,\n inTable: false,\n cellSelection: false,\n rows: 0,\n columns: 0,\n row: -1,\n column: -1,\n headerRow: false,\n headerColumn: false,\n headerCell: false,\n cellAlignment: null,\n cellBackground: null,\n actions: NO_ACTIONS,\n}) as TableState;\n\n/** Computes the table state at the editor's selection. */\nexport function getTableState(editor: Editor | null | undefined): TableState {\n if (!live(editor)) return EMPTY_TABLE_STATE;\n const actions = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => {\n const result = getTableActionState(editor, action);\n return [action, result === true ? { enabled: true } : { enabled: false, reason: result }];\n }),\n ) as Record<TableAction, TableActionStatus>;\n const state = editor.state;\n const base: TableState = { ...EMPTY_TABLE_STATE, enabled: isTableEnabled(editor), actions };\n if (!base.enabled || !isSelectionInTable(state)) return base;\n try {\n const rect = selectedRect(state);\n const { map, table } = rect;\n const cellAt = (row: number, col: number) => table.nodeAt(map.map[row * map.width + col]);\n const allHeaders = (positions: number[]) =>\n positions.length > 0 && positions.every((pos) => table.nodeAt(pos)?.type.name === \"tableHeader\");\n const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });\n const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });\n const cell = cellAt(rect.top, rect.left);\n return {\n ...base,\n inTable: true,\n cellSelection: state.selection instanceof CellSelection,\n rows: map.height,\n columns: map.width,\n row: rect.top,\n column: rect.left,\n headerRow: allHeaders(firstRow),\n headerColumn: allHeaders(firstColumn),\n headerCell: cell?.type.name === \"tableHeader\",\n cellAlignment: normalizeTableCellAlignment(cell?.attrs.align),\n cellBackground: normalizeTableCellColor(cell?.attrs.backgroundColor),\n };\n } catch {\n return { ...base, inTable: true };\n }\n}\n\nconst stateKey = (state: TableState) => JSON.stringify(state);\n\nexport interface TableStore {\n getSnapshot(): TableState;\n subscribe(listener: () => void): () => void;\n destroy(): void;\n}\n\n/**\n * An external store of `getTableState(editor)` for UI bindings (React's\n * `useSyncExternalStore`, Svelte runes). The snapshot object only changes\n * when the state does, and the store listens to the editor only while it\n * has subscribers.\n */\nexport function createTableStore(editor: Editor | null | undefined): TableStore {\n const listeners = new Set<() => void>();\n let snapshot = getTableState(editor);\n let key = stateKey(snapshot);\n\n const update = () => {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey === key) return;\n snapshot = next;\n key = nextKey;\n listeners.forEach((listener) => listener());\n };\n const detach = () => {\n editor?.off(\"transaction\", update);\n editor?.off(\"update\", update);\n editor?.off(\"focus\", update);\n editor?.off(\"destroy\", update);\n };\n\n return {\n getSnapshot: () => {\n if (!listeners.size) {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey !== key) {\n snapshot = next;\n key = nextKey;\n }\n }\n return snapshot;\n },\n subscribe(listener) {\n if (!listeners.size && editor) {\n update();\n editor.on(\"transaction\", update);\n // `setEditable` emits `update` without a transaction.\n editor.on(\"update\", update);\n editor.on(\"focus\", update);\n editor.on(\"destroy\", update);\n }\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (!listeners.size) detach();\n };\n },\n destroy() {\n detach();\n listeners.clear();\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/serializers/plain-text.ts","../src/serializers/html-scan.ts","../src/serializers/mentions.ts","../src/serializers/markdown.ts"],"sourcesContent":["import { DOMSerializer, Slice, Fragment, Node as ProsemirrorNode, type Schema } from \"@tiptap/pm/model\";\nimport {\n BLOCK_CHANGE_ATTRIBUTE,\n MOVE_ID_ATTRIBUTE,\n resolveTrackedChanges,\n type TrackedChangesView,\n} from \"../extensions/track-changes\";\nimport { findTagSpans, replaceTagSpans, stripTags } from \"./html-scan\";\n\nexport interface PlainTextOptions {\n /**\n * How tracked changes (`TrackChanges` extension) appear in the text.\n * Defaults to `\"accepted\"`: deleted text is dropped and inserted text kept,\n * so suggested deletions never leak into exported text. `\"original\"` drops\n * insertions and keeps deletions; `\"all\"` keeps both.\n */\n trackedChanges?: TrackedChangesView;\n}\n\n/**\n * Match tracked deletion / insertion elements. They never nest within\n * themselves, so a lazy match is enough.\n */\nconst TRACKED_DELETION_ATTRIBUTE = /\\bdata-change-type=[\"']deletion[\"']/i;\nconst TRACKED_INSERTION_ATTRIBUTE = /\\bdata-change-type=[\"']insertion[\"']/i;\n\nfunction stripTrackedChanges(html: string, view: TrackedChangesView): string {\n if (view === \"all\" || !html.includes(\"data-change-type\")) return html;\n return view === \"accepted\"\n ? replaceTagSpans(html, \"del\", TRACKED_DELETION_ATTRIBUTE, () => \"\")\n : replaceTagSpans(html, \"ins\", TRACKED_INSERTION_ATTRIBUTE, () => \"\");\n}\n\n/**\n * Escapes characters that have syntactic meaning in HTML text.\n */\nexport function escapeHtml(text: string): string {\n if (!text) return \"\";\n return text\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#039;\");\n}\n\n/**\n * Matches strings that are already TipTap paragraph HTML (start with `<p>` and\n * end with `</p>`), as opposed to plain text that merely mentions a `<p>` tag.\n */\nconst PARAGRAPH_HTML_REGEX = /^\\s*<p[\\s>][\\s\\S]*<\\/p>\\s*$/i;\n\n/**\n * Converts a plain-text string with newlines into HTML paragraphs suitable\n * for TipTap initial content or setContent, preserving line breaks.\n * Input that is already paragraph HTML (`<p>…</p>`) is passed through as-is.\n */\nexport function plainTextToTipTapHtml(text: string): string {\n if (!text) return \"<p></p>\";\n if (PARAGRAPH_HTML_REGEX.test(text)) {\n return text;\n }\n return text\n .replace(/\\r\\n/g, \"\\n\")\n .replace(/\\r/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => `<p>${escapeHtml(line)}</p>`)\n .join(\"\");\n}\n\n/**\n * Builds an open ProseMirror slice with one paragraph per line, so inserting it\n * splits the surrounding paragraph like typing Enter would. Use it for\n * plain-text paste handling (`clipboardTextParser`) and literal text insertion.\n */\nexport function plainTextToSlice(text: string, schema: Schema): Slice {\n const nodes: ProsemirrorNode[] = [];\n text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .forEach((line) => {\n const nodeJson: any = { type: \"paragraph\" };\n if (line.length > 0) {\n nodeJson.content = [{ type: \"text\", text: line }];\n }\n try {\n nodes.push(ProsemirrorNode.fromJSON(schema, nodeJson));\n } catch {\n // Ignore invalid node\n }\n });\n return Slice.maxOpen(Fragment.fromArray(nodes));\n}\n\n/**\n * Block-level elements that start a new line in plain-text output.\n */\nconst BLOCK_TAGS = new Set([\n \"P\", \"DIV\", \"LI\", \"UL\", \"OL\", \"PRE\", \"BLOCKQUOTE\", \"TABLE\", \"TR\",\n \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"HR\",\n]);\n\nconst MENTION_TYPE_ATTRIBUTE = /\\bdata-type=[\"']mention[\"']/i;\n\nfunction getHtmlAttribute(attrs: string, name: string): string | undefined {\n const match = new RegExp(`\\\\b${name}=(?:\"([^\"]*)\"|'([^']*)')`, \"i\").exec(\n attrs,\n );\n return match ? (match[1] ?? match[2]) : undefined;\n}\n\n/**\n * Parses HTML into an inert fragment. Content of a `<template>` element is not\n * rendered, so `<img onerror>` and similar handlers never run.\n */\nfunction parseHtmlFragment(html: string): DocumentFragment {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content;\n}\n\nfunction decodeHtmlEntities(text: string): string {\n return text\n .replace(/&lt;/g, \"<\")\n .replace(/&gt;/g, \">\")\n .replace(/&quot;/g, '\"')\n .replace(/&#0*39;/g, \"'\")\n .replace(/&nbsp;/g, \"\\u00a0\")\n .replace(/&amp;/g, \"&\");\n}\n\nconst CELL_TAGS = new Set([\"TD\", \"TH\"]);\n\n/**\n * Walks DOM nodes and emits one line per *innermost* block, so nested blocks\n * (e.g. TipTap's `<li><p>…</p></li>`) are not repeated. A table row is one\n * line of tab-separated cells: a cell's paragraphs are joined with spaces and\n * a cell spanning several columns is followed by empty cells.\n */\nfunction blockLines(nodes: readonly ChildNode[]): string[] {\n const lines: string[] = [];\n let current: string | null = null;\n const flush = () => {\n if (current !== null) {\n lines.push(current);\n current = null;\n }\n };\n const visit = (node: Node) => {\n if (node.nodeType === 3) {\n const value = node.nodeValue ?? \"\";\n // Skip formatting whitespace between blocks.\n if (current === null && value.trim() === \"\") return;\n current = (current ?? \"\") + value;\n return;\n }\n if (node.nodeType !== 1) return;\n const element = node as Element;\n const tag = element.tagName.toUpperCase();\n if (tag === \"BR\") {\n current = (current ?? \"\") + \"\\n\";\n return;\n }\n if (tag === \"TR\") {\n flush();\n const cells: string[] = [];\n element.childNodes.forEach((child) => {\n if (child.nodeType !== 1 || !CELL_TAGS.has((child as Element).tagName.toUpperCase())) return;\n const cell = child as Element;\n cells.push(\n blockLines(Array.from(cell.childNodes))\n .filter((line) => line !== \"\")\n .join(\" \")\n .replace(/[\\t\\n]+/g, \" \"),\n );\n const span = parseInt(cell.getAttribute(\"colspan\") ?? \"1\", 10);\n for (let i = 1; i < Math.min(Number.isFinite(span) ? span : 1, 1000); i++) cells.push(\"\");\n });\n lines.push(cells.join(\"\\t\"));\n return;\n }\n if (!BLOCK_TAGS.has(tag)) {\n node.childNodes.forEach(visit);\n return;\n }\n flush();\n const linesBefore = lines.length;\n node.childNodes.forEach(visit);\n flush();\n // An empty block (e.g. <p></p>) is an empty line.\n if (lines.length === linesBefore && tag !== \"HR\" && tag !== \"TABLE\") {\n lines.push(\"\");\n }\n };\n nodes.forEach(visit);\n flush();\n return lines;\n}\n\n/**\n * Extracts plain text from an HTML string or TipTap HTML, preserving newlines\n * between block tags. Table rows become lines of tab-separated cells.\n */\nexport function htmlToPlainText(html: string, options: PlainTextOptions = {}): string {\n if (!html) return \"\";\n\n // Normalize mentions so data-label is preserved as @label even if textContent is empty\n const trackedResolved = stripTrackedChanges(\n html,\n options.trackedChanges ?? \"accepted\",\n );\n const mentionNormalized = replaceTagSpans(trackedResolved, \"span\", MENTION_TYPE_ATTRIBUTE, (match, attrs) => {\n const label =\n getHtmlAttribute(attrs, \"data-label\") || getHtmlAttribute(attrs, \"data-id\");\n const role = getHtmlAttribute(attrs, \"data-role\");\n // A role is written as `@label:role`, the text syntax `extractMentions` reads.\n const validRole = role && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(role) ? role : \"\";\n return label ? `@${label}${validRole ? `:${validRole}` : \"\"}` : match;\n });\n\n if (typeof document !== \"undefined\") {\n const fragment = parseHtmlFragment(mentionNormalized);\n fragment\n .querySelectorAll(\"br.ProseMirror-trailingBreak\")\n .forEach((br) => br.remove());\n\n return blockLines(Array.from(fragment.childNodes)).join(\"\\n\");\n }\n\n // Node.js fallback regex. Table cells are tab-separated and rows end lines\n // (a cell's own closing paragraph is dropped first so it does not end the line).\n const text = mentionNormalized\n .replace(/<\\/p>\\s*<\\/t([dh])>/gi, \"</t$1>\")\n .replace(/<\\/t[dh]>\\s*(?=<t[dh][\\s>])/gi, \"\\t\")\n .replace(/<\\/tr>/gi, \"\\n\")\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n // A closing block, plus any closing wrappers right after it, ends one line.\n .replace(\n /<\\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\\s*<\\/(?:li|ul|ol|blockquote|div)>)*/gi,\n \"\\n\",\n );\n return decodeHtmlEntities(stripTags(text)).replace(/\\n$/, \"\");\n}\n\n/**\n * Whole-block insertions/deletions (`blockChange.operation`, from document\n * comparison) have no `<ins>`/`<del>` elements to strip, and resolving a\n * moved paragraph removes its whole block, so documents with either are\n * resolved first and serialized from the resolved document.\n */\nfunction resolvedBlockOperationsHtml(editor: any, view: TrackedChangesView): string | null {\n const doc: ProsemirrorNode | undefined = editor?.state?.doc;\n if (!doc || view === \"all\" || typeof document === \"undefined\") return null;\n let found = false;\n doc.descendants((node) => {\n if (found) return false;\n if (node.isTextblock) {\n if (node.attrs?.[BLOCK_CHANGE_ATTRIBUTE]?.operation) found = true;\n else node.forEach((child) => {\n if (child.marks.some((mark) => mark.attrs?.[MOVE_ID_ATTRIBUTE])) found = true;\n });\n return false;\n }\n return true;\n });\n if (!found) return null;\n const resolved = resolveTrackedChanges(doc, view);\n const container = document.createElement(\"div\");\n container.appendChild(DOMSerializer.fromSchema(doc.type.schema).serializeFragment(resolved.content));\n return container.innerHTML;\n}\n\n/**\n * Extracts plain text from a TipTap editor instance, preserving newline separators\n * between block nodes and converting mention nodes to @label. Tracked changes\n * are rendered as accepted unless `options.trackedChanges` says otherwise.\n */\nexport function getEditorText(editor: any, options: PlainTextOptions = {}): string {\n if (!editor) return \"\";\n const html =\n resolvedBlockOperationsHtml(editor, options.trackedChanges ?? \"accepted\") ??\n (typeof editor.getHTML === \"function\" ? editor.getHTML() : \"\");\n if (html) {\n return htmlToPlainText(html, options);\n }\n if (typeof editor.getText === \"function\") {\n try {\n return editor.getText({ blockSeparator: \"\\n\" });\n } catch {\n return editor.getText();\n }\n }\n return \"\";\n}\n\nexport interface ExtractedMention {\n id: string;\n label: string;\n type?: string;\n /** Asset role (`data-role`), when set. */\n role?: string;\n avatarUrl?: string;\n color?: string;\n [key: string]: any;\n}\n\nimport { extractMentions } from \"./mentions\";\n\n/**\n * Traverses an editor instance, ProseMirror document, JSONContent, or HTML string\n * and extracts all mention attributes without needing regex.\n */\nexport function extractMentionsFromDoc(docOrEditor: any): ExtractedMention[] {\n if (!docOrEditor) return [];\n const mentions: ExtractedMention[] = [];\n\n // TipTap editor or ProseMirror Node with .descendants()\n const doc =\n docOrEditor?.state?.doc ||\n (typeof docOrEditor?.descendants === \"function\" ? docOrEditor : null);\n\n if (doc && typeof doc.descendants === \"function\") {\n doc.descendants((node: any) => {\n if (node.type?.name === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n ...(node.attrs.assetRole ? { role: node.attrs.assetRole } : {}),\n });\n }\n });\n return mentions;\n }\n\n // JSONContent tree\n if (typeof docOrEditor === \"object\" && docOrEditor.content) {\n const walk = (nodes: any[]) => {\n for (const node of nodes) {\n if (node.type === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n ...(node.attrs.assetRole ? { role: node.attrs.assetRole } : {}),\n });\n }\n if (Array.isArray(node.content)) {\n walk(node.content);\n }\n }\n };\n walk(docOrEditor.content);\n return mentions;\n }\n\n // HTML String\n if (typeof docOrEditor === \"string\") {\n if (typeof document !== \"undefined\") {\n parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type=\"mention\"]').forEach((el) => {\n mentions.push({\n id: el.getAttribute(\"data-id\") || \"\",\n label: el.getAttribute(\"data-label\") || \"\",\n type: el.getAttribute(\"data-type-name\") || undefined,\n avatarUrl: el.getAttribute(\"data-avatar-url\") || undefined,\n color: el.getAttribute(\"data-color\") || undefined,\n ...(el.getAttribute(\"data-role\") ? { role: el.getAttribute(\"data-role\")! } : {}),\n });\n });\n } else {\n for (const span of findTagSpans(docOrEditor, \"span\", MENTION_TYPE_ATTRIBUTE, false)) {\n const attrStr = span.attrs;\n const getAttr = (name: string) => {\n const m = new RegExp(`${name}=[\"']([^\"']*)[\"']`, \"i\").exec(attrStr);\n return m ? m[1] : undefined;\n };\n mentions.push({\n id: getAttr(\"data-id\") || \"\",\n label: getAttr(\"data-label\") || \"\",\n type: getAttr(\"data-type-name\") || getAttr(\"data-entity-type\"),\n avatarUrl: getAttr(\"data-avatar-url\"),\n color: getAttr(\"data-color\"),\n ...(getAttr(\"data-role\") ? { role: getAttr(\"data-role\") } : {}),\n });\n }\n }\n\n // Fallback: If no HTML mention tags were found, extract raw @mentions from text or markdown\n if (mentions.length === 0) {\n const rawHandles = extractMentions(docOrEditor);\n for (const handle of rawHandles) {\n mentions.push({\n id: handle,\n label: handle,\n type: \"user\",\n });\n }\n }\n }\n\n return mentions;\n}\n","/**\n * Linear-time scanners for the HTML-ish strings the serializers handle.\n *\n * Regexes like `/<span\\b[^>]*…[^>]*>/`, `/<[^>]+>/g` or `/<pre[\\s\\S]*?<\\/pre>/g` are\n * quadratic (or worse) on malformed input: every opener without its closer\n * rescans to the end of the string. These helpers find each closer once and\n * reuse it, so untrusted input can't stall the main thread (see GOTCHAS).\n */\n\nexport interface TagSpan {\n /** Index of the opening `<tag`. */\n start: number;\n /** Index just past the opening tag's `>`. */\n openEnd: number;\n /** Index just past the close tag (or `openEnd` when the close tag isn't required). */\n end: number;\n /** Attribute text between `<span` and `>`. */\n attrs: string;\n}\n\n/**\n * Finds `<tag …attrs…>…</tag>` elements whose attributes match `attrTest`, in\n * one linear pass. A regex such as `/<span\\b(?=[^>]*…)([^>]*)>[\\s\\S]*?<\\/span>/g`\n * rescans to the end of the input from every `<span` when a `>` or `</span>` is\n * missing, which is quadratic on malformed input. Here the next `>` and the next\n * close tag are found once and reused until the scan passes them, and the scan\n * stops as soon as either no longer exists further on. The first close tag after\n * the opening tag ends the element (no nesting), as with a lazy regex.\n */\nexport function findTagSpans(\n html: string,\n tag: string,\n attrTest: RegExp | ((attrs: string) => boolean),\n requireClose: boolean,\n): TagSpan[] {\n const matches = typeof attrTest === \"function\" ? attrTest : (attrs: string) => attrTest.test(attrs);\n const spans: TagSpan[] = [];\n const openTag = new RegExp(`<${tag}\\\\b`, \"gi\");\n const closeTag = new RegExp(`</${tag}>`, \"gi\");\n const closeLength = tag.length + 3;\n let nextGt = -1;\n let nextClose = -1;\n let from = 0;\n for (;;) {\n openTag.lastIndex = from;\n const open = openTag.exec(html);\n if (!open) break;\n const start = open.index;\n const attrsStart = start + open[0].length;\n if (nextGt < attrsStart) {\n nextGt = html.indexOf(\">\", attrsStart);\n if (nextGt === -1) break;\n }\n const attrs = html.slice(attrsStart, nextGt);\n const openEnd = nextGt + 1;\n if (!matches(attrs)) {\n from = attrsStart;\n continue;\n }\n if (!requireClose) {\n spans.push({ start, openEnd, end: openEnd, attrs });\n from = openEnd;\n continue;\n }\n if (nextClose < openEnd) {\n closeTag.lastIndex = openEnd;\n const close = closeTag.exec(html);\n if (!close) break;\n nextClose = close.index;\n }\n const end = nextClose + closeLength;\n spans.push({ start, openEnd, end, attrs });\n from = end;\n }\n return spans;\n}\n\n/** Replaces each matching element (opening tag through close tag) using `replace`. */\nexport function replaceTagSpans(\n html: string,\n tag: string,\n attrTest: RegExp | ((attrs: string) => boolean),\n replace: (match: string, attrs: string) => string,\n): string {\n const spans = findTagSpans(html, tag, attrTest, true);\n if (spans.length === 0) return html;\n let out = \"\";\n let last = 0;\n for (const span of spans) {\n out += html.slice(last, span.start) + replace(html.slice(span.start, span.end), span.attrs);\n last = span.end;\n }\n return out + html.slice(last);\n}\n\n/**\n * Replaces `<…>` tags in one pass. Same result as `.replace(/<[^>]+>/g, replacement)`,\n * which is quadratic when many `<` have no closing `>`: each one rescans to the\n * end. Once no `>` is left, the rest of the input is plain text.\n */\nexport function stripTags(html: string, replacement = \"\"): string {\n let out = \"\";\n let from = 0;\n for (;;) {\n const lt = html.indexOf(\"<\", from);\n if (lt === -1) break;\n const gt = html.indexOf(\">\", lt + 1);\n if (gt === -1) break;\n if (gt === lt + 1) {\n // \"<>\" is not a tag (the regex needs at least one character).\n out += html.slice(from, gt + 1);\n } else {\n out += html.slice(from, lt) + replacement;\n }\n from = gt + 1;\n }\n return out + html.slice(from);\n}\n\n/**\n * Removes (or replaces) regions that start with a match of `open` and end at the\n * next `close`, in one pass. Equivalent to `.replace(/<open>[\\s\\S]*?<close>/g, …)`\n * but linear: such a lazy regex rescans to the end of the input from every\n * unclosed opener. The next close position is cached until the scan passes it,\n * and scanning stops once no close is left. `open` must have the `g` flag.\n */\nexport function replaceDelimited(\n text: string,\n open: RegExp,\n close: string,\n replace: (match: string) => string = () => \"\",\n caseInsensitiveClose = false,\n): string {\n const haystack = caseInsensitiveClose ? asciiLower(text) : text;\n const needle = caseInsensitiveClose ? close.toLowerCase() : close;\n let out = \"\";\n let last = 0;\n let from = 0;\n let nextClose = -1;\n for (;;) {\n open.lastIndex = from;\n const opened = open.exec(text);\n if (!opened) break;\n const afterOpen = opened.index + Math.max(opened[0].length, 1);\n if (nextClose < afterOpen) {\n nextClose = haystack.indexOf(needle, afterOpen);\n if (nextClose === -1) break;\n }\n const end = nextClose + close.length;\n out += text.slice(last, opened.index) + replace(text.slice(opened.index, end));\n last = from = end;\n }\n return out + text.slice(last);\n}\n\n/** Lower-cases ASCII letters only, so indices match the original string. */\nfunction asciiLower(text: string): string {\n return text.replace(/[A-Z]+/g, (m) => m.toLowerCase());\n}\n","import { escapeHtml } from \"./plain-text\";\nimport {\n MENTION_REGEX,\n NODE_ROLE_MARK,\n formatMentionHandle,\n readRoleSuffix,\n type MentionRoleSyntax,\n} from \"./mention-text\";\n\nexport {\n MENTION_REGEX,\n findTextMentions,\n formatMentionText,\n setMentionRoleInText,\n type MentionRoleSyntax,\n type TextMention,\n} from \"./mention-text\";\nimport { findTagSpans, replaceDelimited, stripTags } from \"./html-scan\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n\n/**\n * Split regex identifying markdown code blocks, inline code, URLs, and existing HTML tags.\n * Used by preprocessMarkdownMentions to ensure non-mention regions remain completely untouched.\n */\nexport const MARKDOWN_MENTION_SPLIT_REGEX =\n /(```[\\s\\S]*?```|~~~[\\s\\S]*?~~~|<pre[\\s\\S]*?<\\/pre>|<code[\\s\\S]*?<\\/code>|`[^`\\n]+`|<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])[^>]*>[\\s\\S]*?<\\/span>|<[^>]+>|\\]\\([^)]+\\)|(?:https?|file|vscode|cursor|mailto):\\/\\/[^\\s<)]+)/gi;\n\nexport interface MentionSegment {\n type: \"text\" | \"mention\";\n value: string;\n handle?: string;\n /** Role written after the handle (`@fox:style`), when role syntax is enabled. */\n role?: string;\n}\n\n\n/** A mention with its role (asset mentions: `@fox:style`, or `data-role` on a mention node). */\nexport interface MentionDetail {\n handle: string;\n role?: string;\n}\n\nexport interface ExtractMentionsOptions {\n /** Return `{ handle, role }` objects instead of handles. */\n details?: boolean;\n /** Read `@handle:role` suffixes in text (see {@link MentionRoleSyntax}). Mention nodes' `data-role` is always read in `details` mode. */\n roles?: MentionRoleSyntax;\n}\n\nexport interface PreprocessMarkdownMentionsOptions {\n /**\n * Known pool of mentionable entities (users, agents, teams, etc.).\n */\n mentionables?: MentionEntity[];\n /**\n * Default entity type assigned when a handle does not match any entry in mentionables.\n * Defaults to 'user'.\n */\n defaultType?: string;\n /**\n * Custom resolver callback to derive entity metadata for unmatched handles.\n */\n resolveMention?: (handle: string) => Partial<MentionEntity> | null | undefined;\n /**\n * Read `@handle:role` and emit the role as `data-role` (the `:role` text is\n * consumed). Off by default. See {@link MentionRoleSyntax}.\n */\n roles?: MentionRoleSyntax;\n}\n\n/**\n * Strips code blocks and inline code from markdown or HTML content:\n * - Fenced code blocks: ```...``` and ~~~...~~~\n * - Inline backtick code: `...`\n * - HTML code/pre tags: <pre>...</pre>, <code>...</code>\n * Used to avoid false-positive mention parsing and keyword analysis within code snippets, terminal logs, or stack traces.\n */\nexport function stripMarkdownCode(content: string): string {\n if (!content || typeof content !== \"string\") return \"\";\n // Linear scans instead of lazy `[\\s\\S]*?` regexes, which rescan to the end of the\n // input from every unclosed opener (see html-scan.ts).\n let text = replaceDelimited(content, /```/g, \"```\");\n text = replaceDelimited(text, /~~~/g, \"~~~\");\n text = replaceDelimited(text, /<pre/gi, \"</pre>\", undefined, true);\n text = replaceDelimited(text, /<code/gi, \"</code>\", undefined, true);\n return text.replace(/`[^`\\n]*`/g, \"\");\n}\n\n/** True for the attributes of a mention node: `data-type=\"mention\"` or the `pixerate-mention-node` class. */\nfunction isMentionNodeAttributes(attrs: string): boolean {\n if (/\\bdata-type=[\"']mention[\"']/i.test(attrs)) return true;\n const classAttr = /\\bclass=([\"'])/i.exec(attrs);\n if (!classAttr) return false;\n const valueStart = classAttr.index + classAttr[0].length;\n const valueEnd = attrs.indexOf(classAttr[1], valueStart);\n return valueEnd !== -1 && attrs.slice(valueStart, valueEnd).includes(\"pixerate-mention-node\");\n}\n\n/**\n * Extracts unique mention handles from a text, markdown, or HTML string,\n * ignoring trailing punctuation, code blocks, URLs, and pre-existing HTML mention attributes.\n *\n * With `{ details: true }` it returns `{ handle, role }` objects, unique per\n * handle and role: roles come from mention nodes' `data-role` and, when\n * `roles` is set, from `@handle:role` text. Without options the result is\n * unchanged.\n */\nexport function extractMentions(content: string, options?: ExtractMentionsOptions & { details?: false }): string[];\nexport function extractMentions(content: string, options: ExtractMentionsOptions & { details: true }): MentionDetail[];\nexport function extractMentions(content: string, options?: ExtractMentionsOptions): string[] | MentionDetail[];\nexport function extractMentions(content: string, options: ExtractMentionsOptions = {}): string[] | MentionDetail[] {\n if (!content || typeof content !== \"string\") return [];\n const details = options.details === true;\n\n // Normalize existing HTML mention nodes (e.g. from TipTap or rich text serializers)\n // so data-mention-suggestion-char=\"@\" does not trigger spurious quoted matches against attributes,\n // and ensure the actual mentioned label or ID is preserved cleanly.\n // A linear scan: the equivalent regex (`<span\\b[^>]*\\b(?:…)[^>]*>`) backtracks\n // cubically on malformed input without a `>` (see html-scan.ts).\n let normalizedMentionNodes = \"\";\n let last = 0;\n for (const span of findTagSpans(content, \"span\", isMentionNodeAttributes, true)) {\n const labelMatch = /\\bdata-label=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const idMatch = labelMatch ? null : /\\bdata-id=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const inner = content.slice(span.openEnd, span.end - \"</span>\".length);\n let replacement = labelMatch ? ` @${labelMatch[1]} ` : idMatch ? ` @${idMatch[1]} ` : ` ${inner} `;\n if (details && (labelMatch || idMatch)) {\n const roleMatch = /\\bdata-role=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const role = roleMatch && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(roleMatch[1]) ? roleMatch[1] : null;\n const label = (labelMatch ?? idMatch)![1];\n replacement = ` ${formatMentionHandle(label)}${role ? NODE_ROLE_MARK + role : \"\"} `;\n }\n normalizedMentionNodes += content.slice(last, span.start) + replacement;\n last = span.end;\n }\n normalizedMentionNodes += content.slice(last);\n\n const cleanContent = stripMarkdownCode(normalizedMentionNodes);\n // Strip URLs and markdown link destinations so @package or @handles in URLs are not extracted as mentions\n const withoutUrls = cleanContent\n .replace(/(?:https?|ftp|file|vscode|cursor|mailto):\\/\\/[^\\s<>()]+/gi, \"\");\n // Markdown link destinations: `](…)` → `]` (linear; `/\\]\\([^)]*\\)/g` is quadratic\n // when many `](` have no `)`).\n const withoutLinks = replaceDelimited(withoutUrls, /\\]\\(/g, \")\", () => \"]\");\n // Strip remaining HTML tags so attributes containing '@' or '>' aren't treated as mention triggers\n const textOnly = stripTags(withoutLinks, \" \");\n\n const mentions: string[] = [];\n const detailed: MentionDetail[] = [];\n const seen = new Set<string>();\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(textOnly)) !== null) {\n const handle = (match[1] ?? match[2] ?? match[3] ?? \"\").trim();\n if (details) {\n const suffix = readRoleSuffix(textOnly, regex.lastIndex, options.roles);\n if (suffix) regex.lastIndex = suffix.end;\n const key = `${handle}\\u0000${suffix?.role ?? \"\"}`;\n if (handle && !seen.has(key)) {\n seen.add(key);\n detailed.push(suffix ? { handle, role: suffix.role } : { handle });\n }\n continue;\n }\n if (handle && !seen.has(handle)) {\n seen.add(handle);\n mentions.push(handle);\n }\n }\n\n return details ? detailed : mentions;\n}\n\n/**\n * Segments a text string into plain text parts and mention tokens.\n * Correctly leaves trailing punctuation (like \".\") as part of the following text segment.\n */\nexport function parseMentionSegments(\n content: string,\n options: { roles?: MentionRoleSyntax } = {},\n): MentionSegment[] {\n if (!content) return [];\n\n const segments: MentionSegment[] = [];\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(content)) !== null) {\n const fullMatch = match[0];\n const atIndex = fullMatch.indexOf(\"@\");\n const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : \"\";\n let mentionToken = fullMatch.slice(atIndex);\n const handle = match[1] ?? match[2] ?? match[3];\n const matchStart = match.index + prefix.length;\n const suffix =\n options.roles && content.charAt(regex.lastIndex) === \":\"\n ? readRoleSuffix(content, regex.lastIndex, options.roles)\n : null;\n if (suffix) {\n mentionToken = content.slice(matchStart, suffix.end);\n regex.lastIndex = suffix.end;\n }\n\n if (matchStart > lastIndex) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex, matchStart),\n });\n }\n\n segments.push({\n type: \"mention\",\n value: mentionToken,\n handle,\n ...(suffix ? { role: suffix.role } : {}),\n });\n\n lastIndex = matchStart + mentionToken.length;\n }\n\n if (lastIndex < content.length) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex),\n });\n }\n\n return segments;\n}\n\n/**\n * Preprocesses markdown text by turning raw @mention handles into TipTap-compatible\n * mention HTML spans (<span class=\"pixerate-mention-node\" data-type=\"mention\" ...>),\n * ensuring code blocks, inline code, existing mention nodes, and URLs remain immune.\n */\nexport function preprocessMarkdownMentions(\n content: string,\n optionsOrMentionables: MentionEntity[] | PreprocessMarkdownMentionsOptions = []\n): string {\n if (!content || typeof content !== \"string\") return \"\";\n\n const options: PreprocessMarkdownMentionsOptions = Array.isArray(optionsOrMentionables)\n ? { mentionables: optionsOrMentionables }\n : optionsOrMentionables;\n\n const allMentionables = options.mentionables || [];\n const defaultType = options.defaultType || \"user\";\n const resolveMention = options.resolveMention;\n\n const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);\n\n return parts\n .map((part) => {\n if (!part) return \"\";\n\n // Preserve code fences, code tags, inline backticks, existing mention spans,\n // HTML tags, markdown link targets, and raw URLs untouched.\n if (\n part.startsWith(\"```\") ||\n part.startsWith(\"~~~\") ||\n part.startsWith(\"`\") ||\n part.startsWith(\"](\") ||\n /^(?:https?|file|vscode|cursor|mailto):\\/\\//i.test(part) ||\n /^<pre[\\s>]/i.test(part) ||\n /^<code[\\s>]/i.test(part) ||\n /^<[^>]+>$/i.test(part) ||\n /^<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])/i.test(\n part\n )\n ) {\n return part;\n }\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n const render = (\n match: string,\n quotedHandle: string | undefined,\n escapedQuotedHandle: string | undefined,\n standardHandle: string | undefined,\n role?: string,\n ): string => {\n const atIndex = match.indexOf(\"@\");\n const prefix = atIndex > 0 ? match.slice(0, atIndex) : \"\";\n const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || \"\").trim();\n if (!rawHandle) return match;\n\n const lowerHandle = rawHandle.toLowerCase();\n const entity = allMentionables.find((e) => {\n if (e.label?.toLowerCase() === lowerHandle) return true;\n if (e.handle?.toLowerCase() === lowerHandle) return true;\n if (e.name?.toLowerCase() === lowerHandle) return true;\n if (e.id?.toLowerCase() === lowerHandle) return true;\n if (e.type === \"agent\" && `agent${(e.handle || e.label || \"\").toLowerCase()}` === lowerHandle) return true;\n if (\n e.aliases?.some(\n (a: string) =>\n a.toLowerCase() === lowerHandle ||\n (e.type === \"agent\" && `agent${a.toLowerCase()}` === lowerHandle)\n )\n ) {\n return true;\n }\n return false;\n });\n\n let id = entity?.id;\n let label = entity?.label || entity?.handle || rawHandle;\n let type = entity?.type;\n let avatarUrl = entity?.avatarUrl;\n let color = entity?.color || entity?.hexColor;\n\n if (!entity) {\n const customResolved = resolveMention?.(rawHandle);\n if (customResolved) {\n id = customResolved.id ?? id;\n label = customResolved.label ?? customResolved.handle ?? label;\n type = customResolved.type ?? type;\n avatarUrl = customResolved.avatarUrl ?? avatarUrl;\n color = customResolved.color ?? customResolved.hexColor ?? color;\n } else {\n const stripped = lowerHandle.replace(/^agent[\\s\\-_]*/i, \"\");\n if (\n [\"supervisor\", \"coordinator\", \"planner\", \"validator\", \"executor\"].includes(stripped)\n ) {\n type = \"agent\";\n id = stripped;\n label = stripped;\n } else if (lowerHandle === \"agents\") {\n type = \"team\";\n id = \"agents\";\n label = \"agents\";\n } else {\n type = defaultType;\n id = rawHandle;\n label = rawHandle;\n }\n }\n }\n\n const avatarAttr = avatarUrl ? ` data-avatar-url=\"${escapeHtml(avatarUrl)}\"` : \"\";\n const colorAttr = color ? ` data-color=\"${escapeHtml(color)}\"` : \"\";\n\n return `${prefix}<span class=\"pixerate-mention-node\" data-type=\"mention\" data-id=\"${escapeHtml(\n id || label\n )}\" data-label=\"${escapeHtml(label)}\" data-mention-suggestion-char=\"@\" data-type-name=\"${escapeHtml(\n type || defaultType\n )}\"${avatarAttr}${colorAttr}${role ? ` data-role=\"${escapeHtml(role)}\"` : \"\"}>@${escapeHtml(label)}</span>`;\n };\n if (!options.roles) {\n return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) =>\n render(match, quotedHandle, escapedQuotedHandle, standardHandle),\n );\n }\n // Role syntax: consume a `:role` suffix after each mention.\n let out = \"\";\n let last = 0;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(part)) !== null) {\n const suffix = readRoleSuffix(part, regex.lastIndex, options.roles);\n const rendered = render(match[0], match[1], match[2], match[3], suffix?.role);\n if (suffix && rendered !== match[0]) regex.lastIndex = suffix.end;\n out += part.slice(last, match.index) + rendered;\n last = regex.lastIndex;\n }\n return out + part.slice(last);\n })\n .join(\"\");\n}\n","import MarkdownIt from \"markdown-it\";\nimport taskLists from \"markdown-it-task-lists\";\nimport { escapeHtml, getEditorText, type PlainTextOptions } from \"./plain-text\";\nimport { resolveTrackedChanges } from \"../extensions/track-changes\";\n\nconst md = new MarkdownIt({\n html: true,\n linkify: true,\n breaks: true,\n}).use(taskLists);\n\nconst defaultValidateLink = md.validateLink;\nmd.validateLink = (url: string) => {\n if (\n url.startsWith(\"file://\") ||\n url.startsWith(\"vscode://\") ||\n url.startsWith(\"cursor://\")\n ) {\n return true;\n }\n return defaultValidateLink.call(md, url);\n};\n\n/**\n * Tags allowed through from raw HTML embedded in markdown (e.g. mention spans\n * and file links that tiptap-markdown serializes as HTML). Anything else is\n * rendered as escaped text. `input` is limited to checkboxes, which\n * markdown-it-task-lists emits as raw HTML.\n */\nconst ALLOWED_HTML_TAGS = new Set([\n \"a\", \"abbr\", \"b\", \"blockquote\", \"br\", \"code\", \"col\", \"colgroup\", \"del\", \"details\", \"div\", \"em\",\n \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"hr\", \"i\", \"img\", \"input\", \"ins\", \"kbd\", \"li\", \"mark\",\n \"ol\", \"p\", \"pre\", \"s\", \"span\", \"strong\", \"sub\", \"summary\", \"sup\", \"table\",\n \"tbody\", \"td\", \"tfoot\", \"th\", \"thead\", \"tr\", \"u\", \"ul\",\n]);\n\nconst ALLOWED_HTML_ATTRS = new Set([\n \"alt\", \"align\", \"checked\", \"class\", \"colspan\", \"colwidth\", \"disabled\", \"height\", \"href\",\n \"rel\", \"rowspan\", \"src\", \"start\", \"target\", \"title\", \"type\", \"width\",\n]);\n\nconst HTML_TAG_REGEX =\n /<(\\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\\s+[^\\s\"'>\\/=]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'=<>`]+))?)*)\\s*\\/?>/g;\nconst HTML_ATTR_REGEX =\n /([^\\s\"'>\\/=]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\nfunction sanitizeTag(\n tagText: string,\n isClosing: string,\n rawTagName: string,\n rawAttrs: string,\n stripDisallowed: boolean,\n): string {\n const tagName = rawTagName.toLowerCase();\n const reject = () => (stripDisallowed ? \"\" : escapeHtml(tagText));\n if (!ALLOWED_HTML_TAGS.has(tagName)) return reject();\n if (isClosing) return `</${tagName}>`;\n if (tagName === \"input\" && !/\\stype\\s*=\\s*[\"']?checkbox[\"']?[\\s>/]/i.test(tagText)) {\n return reject();\n }\n\n let attrs = \"\";\n let attrMatch: RegExpExecArray | null;\n HTML_ATTR_REGEX.lastIndex = 0;\n while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {\n const name = attrMatch[1].toLowerCase();\n if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {\n continue;\n }\n const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];\n if (rawValue === undefined) {\n attrs += ` ${name}`;\n continue;\n }\n const value = md.utils.unescapeAll(rawValue);\n if (\n (name === \"href\" || name === \"src\") &&\n // Browsers ignore control characters and whitespace inside schemes.\n !md.validateLink(value.replace(/[\\u0000-\\u0020\\u007f]/g, \"\"))\n ) {\n continue;\n }\n attrs += ` ${name}=\"${escapeHtml(value)}\"`;\n }\n return `<${tagName}${attrs}>`;\n}\n\nexport interface SanitizeHtmlOptions {\n /**\n * What to do with tags outside the allowlist: `escape` (default) renders\n * them as literal text, `strip` removes the tag but keeps its text content.\n */\n disallowedTags?: \"escape\" | \"strip\";\n}\n\n/**\n * Sanitizes raw HTML with the same allowlist the markdown renderer applies to\n * embedded HTML: event handlers, `style` and unsafe URL schemes are dropped,\n * and disallowed tags are escaped (or removed with `disallowedTags: \"strip\"`).\n * It is string-based, so it works without a DOM and never runs handlers.\n */\nexport function sanitizeHtml(html: string, options: SanitizeHtmlOptions = {}): string {\n return sanitizeEmbeddedHtml(html, options.disallowedTags === \"strip\");\n}\n\nfunction sanitizeEmbeddedHtml(html: string, stripDisallowed = false): string {\n let result = \"\";\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n HTML_TAG_REGEX.lastIndex = 0;\n while ((match = HTML_TAG_REGEX.exec(html)) !== null) {\n result += html.slice(lastIndex, match.index).replace(/</g, \"&lt;\");\n result += sanitizeTag(match[0], match[1], match[2], match[3], stripDisallowed);\n lastIndex = match.index + match[0].length;\n }\n return result + html.slice(lastIndex).replace(/</g, \"&lt;\");\n}\n\nconst defaultHtmlInline = md.renderer.rules.html_inline;\nconst defaultHtmlBlock = md.renderer.rules.html_block;\nmd.renderer.rules.html_inline = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlInline!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\nmd.renderer.rules.html_block = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlBlock!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\n\nimport {\n preprocessMarkdownMentions,\n type PreprocessMarkdownMentionsOptions,\n} from \"./mentions\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n/**\n * Preprocesses file-protocol and editor-protocol links in markdown content:\n * converts [label](file://...), vscode://, and cursor:// links into anchor tags\n * annotated with data-file-link=\"true\", preserving code backticks in labels.\n */\nexport function preprocessMarkdownFileLinks(content: string): string {\n if (!content) return \"\";\n return content.replace(\n /\\[([^\\]]+)\\]\\(((?:file|vscode|cursor):\\/\\/[^)]+)\\)/g,\n (_match, rawLabel, href) => {\n const trimmed = rawLabel.trim();\n const codeMatch = trimmed.match(/^`([^`]+)`$/);\n const labelContent = codeMatch\n ? `<code>${escapeHtml(codeMatch[1])}</code>`\n : escapeHtml(trimmed);\n return `<a href=\"${escapeHtml(href)}\" data-file-link=\"true\" title=\"Click to copy file path\">${labelContent}</a>`;\n }\n );\n}\n\nexport interface MarkdownToHtmlOptions {\n /**\n * Preprocess file, vscode, and cursor links into clickable data-file-link tags.\n */\n preprocessFileLinks?: boolean;\n /**\n * Whether to preprocess @mentions into TipTap mention node HTML spans.\n */\n preprocessMentions?: boolean;\n /**\n * Pool of mentionables to pass to preprocessMarkdownMentions.\n */\n mentionables?: MentionEntity[];\n /**\n * Full options for preprocessMarkdownMentions.\n */\n preprocessOptions?: PreprocessMarkdownMentionsOptions;\n /**\n * Render raw HTML embedded in the markdown without sanitizing it. By default,\n * embedded HTML is restricted to an allowlist of tags and attributes (event\n * handlers, `style` and unsafe URL schemes are removed). Only enable this for\n * fully trusted input.\n */\n allowUnsafeHtml?: boolean;\n}\n\n/**\n * Converts a markdown string into HTML suitable for TipTap initial content or setContent.\n * Raw HTML embedded in the markdown is sanitized unless `allowUnsafeHtml` is set.\n */\nexport function markdownToTipTapHtml(\n markdown: string,\n options?: MarkdownToHtmlOptions\n): string {\n if (!markdown) return \"<p></p>\";\n let content = markdown;\n if (options?.preprocessFileLinks) {\n content = preprocessMarkdownFileLinks(content);\n }\n if (\n options?.preprocessMentions ||\n options?.mentionables ||\n options?.preprocessOptions\n ) {\n const mentionOpts = options.preprocessOptions || {\n mentionables: options.mentionables,\n };\n content = preprocessMarkdownMentions(content, mentionOpts);\n }\n return md.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });\n}\n\n/**\n * Extracts clean markdown from a TipTap editor instance.\n * If the editor has the Markdown extension configured, it uses editor.storage.markdown.getMarkdown().\n * Otherwise, it falls back to getEditorText(editor).\n * Tracked changes are exported as accepted unless `options.trackedChanges`\n * says otherwise (`\"all\"` renders deletions as `~~strikethrough~~`).\n */\nexport function getEditorMarkdown(editor: any, options: PlainTextOptions = {}): string {\n if (!editor) return \"\";\n const markdown = editor.storage?.markdown;\n if (typeof markdown?.getMarkdown === \"function\") {\n const doc = editor.state?.doc;\n if (doc && typeof markdown.serializer?.serialize === \"function\") {\n const resolved = resolveTrackedChanges(doc, options.trackedChanges ?? \"accepted\");\n if (resolved !== doc) return markdown.serializer.serialize(resolved);\n }\n return markdown.getMarkdown();\n }\n return getEditorText(editor, options);\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,eAAe,OAAO,UAAU,QAAQ,uBAAoC;;;AC6B9E,SAAS,aACd,MACA,KACA,UACA,cACW;AACX,QAAM,UAAU,OAAO,aAAa,aAAa,WAAW,CAAC,UAAkB,SAAS,KAAK,KAAK;AAClG,QAAM,QAAmB,CAAC;AAC1B,QAAM,UAAU,IAAI,OAAO,IAAI,GAAG,OAAO,IAAI;AAC7C,QAAM,WAAW,IAAI,OAAO,KAAK,GAAG,KAAK,IAAI;AAC7C,QAAM,cAAc,IAAI,SAAS;AACjC,MAAI,SAAS;AACb,MAAI,YAAY;AAChB,MAAI,OAAO;AACX,aAAS;AACP,YAAQ,YAAY;AACpB,UAAM,OAAO,QAAQ,KAAK,IAAI;AAC9B,QAAI,CAAC,KAAM;AACX,UAAM,QAAQ,KAAK;AACnB,UAAM,aAAa,QAAQ,KAAK,CAAC,EAAE;AACnC,QAAI,SAAS,YAAY;AACvB,eAAS,KAAK,QAAQ,KAAK,UAAU;AACrC,UAAI,WAAW,GAAI;AAAA,IACrB;AACA,UAAM,QAAQ,KAAK,MAAM,YAAY,MAAM;AAC3C,UAAM,UAAU,SAAS;AACzB,QAAI,CAAC,QAAQ,KAAK,GAAG;AACnB,aAAO;AACP;AAAA,IACF;AACA,QAAI,CAAC,cAAc;AACjB,YAAM,KAAK,EAAE,OAAO,SAAS,KAAK,SAAS,MAAM,CAAC;AAClD,aAAO;AACP;AAAA,IACF;AACA,QAAI,YAAY,SAAS;AACvB,eAAS,YAAY;AACrB,YAAM,QAAQ,SAAS,KAAK,IAAI;AAChC,UAAI,CAAC,MAAO;AACZ,kBAAY,MAAM;AAAA,IACpB;AACA,UAAM,MAAM,YAAY;AACxB,UAAM,KAAK,EAAE,OAAO,SAAS,KAAK,MAAM,CAAC;AACzC,W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AAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ;AAAA,IACb;AAAA,IACA,CAAC,QAAQ,UAAU,SAAS;AAC1B,YAAM,UAAU,SAAS,KAAK;AAC9B,YAAM,YAAY,QAAQ,MAAM,aAAa;AAC7C,YAAM,eAAe,YACjB,SAAS,WAAW,UAAU,CAAC,CAAC,CAAC,YACjC,WAAW,OAAO;AACtB,aAAO,YAAY,WAAW,IAAI,CAAC,2DAA2D,YAAY;AAAA,IAC5G;AAAA,EACF;AACF;AAgCO,SAAS,qBACd,UACA,SACQ;AACR,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI,UAAU;AACd,MAAI,SAAS,qBAAqB;AAChC,cAAU,4BAA4B,OAAO;AAAA,EAC/C;AACA,MACE,SAAS,sBACT,SAAS,gBACT,SAAS,mBACT;AACA,UAAM,cAAc,QAAQ,qBAAqB;AAAA,MAC/C,cAAc,QAAQ;AAAA,IACxB;AACA,cAAU,2BAA2B,SAAS,WAAW;AAAA,EAC3D;AACA,SAAO,GAAG,OAAO,SAAS,EAAE,iBAAiB,SAAS,gBAAgB,CAAC;AACzE;AASO,SAAS,kBAAkB,QAAa,UAA4B,CAAC,GAAW;AACrF,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,WAAW,OAAO,SAAS;AACjC,MAAI,OAAO,UAAU,gBAAgB,YAAY;AAC/C,UAAM,MAAM,OAAO,OAAO;AAC1B,QAAI,OAAO,OAAO,SAAS,YAAY,cAAc,YAAY;AAC/D,YAAM,WAAW,sBAAsB,KAAK,QAAQ,kBAAkB,UAAU;AAChF,UAAI,aAAa,IAAK,QAAO,SAAS,WAAW,UAAU,QAAQ;AAAA,IACrE;AACA,WAAO,SAAS,YAAY;AAAA,EAC9B;AACA,SAAO,cAAc,QAAQ,OAAO;AACtC;","names":["match"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-NFVBT3UZ.cjs","../src/serializers/plain-text.ts","../src/serializers/html-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ACD,MAAA;AACE,MAAA;AACG,MAAA;AAGF,MAAA;AACrB,IAAA;AACF,EAAA;AACF;AAgCgB;AAIQ,EAAA;AACR,EAAA;AACD,EAAA;AACD,IAAA;AACZ,EAAA;AAEW,EAAA;AAIW,IAAA;AACI,MAAA;AACxB,IAAA;AACU,IAAA;AACZ,EAAA;AAC0B,EAAA;AAC5B;AASkC;AACZ,EAAA;AACI,EAAA;AACH,EAAA;AACA,IAAA;AACD,IAAA;AACC,MAAA;AACK,MAAA;AACxB,IAAA;AACgB,IAAA;AAClB,EAAA;AACqB,EAAA;AACvB;AJugB6B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-NFVBT3UZ.cjs","sourcesContent":[null,"import { DOMSerializer, Slice, Fragment, Node as ProsemirrorNode, type Schema } from \"@tiptap/pm/model\";\nimport {\n BLOCK_CHANGE_ATTRIBUTE,\n MOVE_ID_ATTRIBUTE,\n resolveTrackedChanges,\n type TrackedChangesView,\n} from \"../extensions/track-changes\";\nimport { findTagSpans, replaceTagSpans, stripTags } from \"./html-scan\";\n\nexport interface PlainTextOptions {\n /**\n * How tracked changes (`TrackChanges` extension) appear in the text.\n * Defaults to `\"accepted\"`: deleted text is dropped and inserted text kept,\n * so suggested deletions never leak into exported text. `\"original\"` drops\n * insertions and keeps deletions; `\"all\"` keeps both.\n */\n trackedChanges?: TrackedChangesView;\n}\n\n/**\n * Match tracked deletion / insertion elements. They never nest within\n * themselves, so a lazy match is enough.\n */\nconst TRACKED_DELETION_ATTRIBUTE = /\\bdata-change-type=[\"']deletion[\"']/i;\nconst TRACKED_INSERTION_ATTRIBUTE = /\\bdata-change-type=[\"']insertion[\"']/i;\n\nfunction stripTrackedChanges(html: string, view: TrackedChangesView): string {\n if (view === \"all\" || !html.includes(\"data-change-type\")) return html;\n return view === \"accepted\"\n ? replaceTagSpans(html, \"del\", TRACKED_DELETION_ATTRIBUTE, () => \"\")\n : replaceTagSpans(html, \"ins\", TRACKED_INSERTION_ATTRIBUTE, () => \"\");\n}\n\n/**\n * Escapes characters that have syntactic meaning in HTML text.\n */\nexport function escapeHtml(text: string): string {\n if (!text) return \"\";\n return text\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&#039;\");\n}\n\n/**\n * Matches strings that are already TipTap paragraph HTML (start with `<p>` and\n * end with `</p>`), as opposed to plain text that merely mentions a `<p>` tag.\n */\nconst PARAGRAPH_HTML_REGEX = /^\\s*<p[\\s>][\\s\\S]*<\\/p>\\s*$/i;\n\n/**\n * Converts a plain-text string with newlines into HTML paragraphs suitable\n * for TipTap initial content or setContent, preserving line breaks.\n * Input that is already paragraph HTML (`<p>…</p>`) is passed through as-is.\n */\nexport function plainTextToTipTapHtml(text: string): string {\n if (!text) return \"<p></p>\";\n if (PARAGRAPH_HTML_REGEX.test(text)) {\n return text;\n }\n return text\n .replace(/\\r\\n/g, \"\\n\")\n .replace(/\\r/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => `<p>${escapeHtml(line)}</p>`)\n .join(\"\");\n}\n\n/**\n * Builds an open ProseMirror slice with one paragraph per line, so inserting it\n * splits the surrounding paragraph like typing Enter would. Use it for\n * plain-text paste handling (`clipboardTextParser`) and literal text insertion.\n */\nexport function plainTextToSlice(text: string, schema: Schema): Slice {\n const nodes: ProsemirrorNode[] = [];\n text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .forEach((line) => {\n const nodeJson: any = { type: \"paragraph\" };\n if (line.length > 0) {\n nodeJson.content = [{ type: \"text\", text: line }];\n }\n try {\n nodes.push(ProsemirrorNode.fromJSON(schema, nodeJson));\n } catch {\n // Ignore invalid node\n }\n });\n return Slice.maxOpen(Fragment.fromArray(nodes));\n}\n\n/**\n * Block-level elements that start a new line in plain-text output.\n */\nconst BLOCK_TAGS = new Set([\n \"P\", \"DIV\", \"LI\", \"UL\", \"OL\", \"PRE\", \"BLOCKQUOTE\", \"TABLE\", \"TR\",\n \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"HR\",\n]);\n\nconst MENTION_TYPE_ATTRIBUTE = /\\bdata-type=[\"']mention[\"']/i;\n\nfunction getHtmlAttribute(attrs: string, name: string): string | undefined {\n const match = new RegExp(`\\\\b${name}=(?:\"([^\"]*)\"|'([^']*)')`, \"i\").exec(\n attrs,\n );\n return match ? (match[1] ?? match[2]) : undefined;\n}\n\n/**\n * Parses HTML into an inert fragment. Content of a `<template>` element is not\n * rendered, so `<img onerror>` and similar handlers never run.\n */\nfunction parseHtmlFragment(html: string): DocumentFragment {\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n return template.content;\n}\n\nfunction decodeHtmlEntities(text: string): string {\n return text\n .replace(/&lt;/g, \"<\")\n .replace(/&gt;/g, \">\")\n .replace(/&quot;/g, '\"')\n .replace(/&#0*39;/g, \"'\")\n .replace(/&nbsp;/g, \"\\u00a0\")\n .replace(/&amp;/g, \"&\");\n}\n\nconst CELL_TAGS = new Set([\"TD\", \"TH\"]);\n\n/**\n * Walks DOM nodes and emits one line per *innermost* block, so nested blocks\n * (e.g. TipTap's `<li><p>…</p></li>`) are not repeated. A table row is one\n * line of tab-separated cells: a cell's paragraphs are joined with spaces and\n * a cell spanning several columns is followed by empty cells.\n */\nfunction blockLines(nodes: readonly ChildNode[]): string[] {\n const lines: string[] = [];\n let current: string | null = null;\n const flush = () => {\n if (current !== null) {\n lines.push(current);\n current = null;\n }\n };\n const visit = (node: Node) => {\n if (node.nodeType === 3) {\n const value = node.nodeValue ?? \"\";\n // Skip formatting whitespace between blocks.\n if (current === null && value.trim() === \"\") return;\n current = (current ?? \"\") + value;\n return;\n }\n if (node.nodeType !== 1) return;\n const element = node as Element;\n const tag = element.tagName.toUpperCase();\n if (tag === \"BR\") {\n current = (current ?? \"\") + \"\\n\";\n return;\n }\n if (tag === \"TR\") {\n flush();\n const cells: string[] = [];\n element.childNodes.forEach((child) => {\n if (child.nodeType !== 1 || !CELL_TAGS.has((child as Element).tagName.toUpperCase())) return;\n const cell = child as Element;\n cells.push(\n blockLines(Array.from(cell.childNodes))\n .filter((line) => line !== \"\")\n .join(\" \")\n .replace(/[\\t\\n]+/g, \" \"),\n );\n const span = parseInt(cell.getAttribute(\"colspan\") ?? \"1\", 10);\n for (let i = 1; i < Math.min(Number.isFinite(span) ? span : 1, 1000); i++) cells.push(\"\");\n });\n lines.push(cells.join(\"\\t\"));\n return;\n }\n if (!BLOCK_TAGS.has(tag)) {\n node.childNodes.forEach(visit);\n return;\n }\n flush();\n const linesBefore = lines.length;\n node.childNodes.forEach(visit);\n flush();\n // An empty block (e.g. <p></p>) is an empty line.\n if (lines.length === linesBefore && tag !== \"HR\" && tag !== \"TABLE\") {\n lines.push(\"\");\n }\n };\n nodes.forEach(visit);\n flush();\n return lines;\n}\n\n/**\n * Extracts plain text from an HTML string or TipTap HTML, preserving newlines\n * between block tags. Table rows become lines of tab-separated cells.\n */\nexport function htmlToPlainText(html: string, options: PlainTextOptions = {}): string {\n if (!html) return \"\";\n\n // Normalize mentions so data-label is preserved as @label even if textContent is empty\n const trackedResolved = stripTrackedChanges(\n html,\n options.trackedChanges ?? \"accepted\",\n );\n const mentionNormalized = replaceTagSpans(trackedResolved, \"span\", MENTION_TYPE_ATTRIBUTE, (match, attrs) => {\n const label =\n getHtmlAttribute(attrs, \"data-label\") || getHtmlAttribute(attrs, \"data-id\");\n const role = getHtmlAttribute(attrs, \"data-role\");\n // A role is written as `@label:role`, the text syntax `extractMentions` reads.\n const validRole = role && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(role) ? role : \"\";\n return label ? `@${label}${validRole ? `:${validRole}` : \"\"}` : match;\n });\n\n if (typeof document !== \"undefined\") {\n const fragment = parseHtmlFragment(mentionNormalized);\n fragment\n .querySelectorAll(\"br.ProseMirror-trailingBreak\")\n .forEach((br) => br.remove());\n\n return blockLines(Array.from(fragment.childNodes)).join(\"\\n\");\n }\n\n // Node.js fallback regex. Table cells are tab-separated and rows end lines\n // (a cell's own closing paragraph is dropped first so it does not end the line).\n const text = mentionNormalized\n .replace(/<\\/p>\\s*<\\/t([dh])>/gi, \"</t$1>\")\n .replace(/<\\/t[dh]>\\s*(?=<t[dh][\\s>])/gi, \"\\t\")\n .replace(/<\\/tr>/gi, \"\\n\")\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n // A closing block, plus any closing wrappers right after it, ends one line.\n .replace(\n /<\\/(?:p|div|li|pre|blockquote|h[1-6])>(?:\\s*<\\/(?:li|ul|ol|blockquote|div)>)*/gi,\n \"\\n\",\n );\n return decodeHtmlEntities(stripTags(text)).replace(/\\n$/, \"\");\n}\n\n/**\n * Whole-block insertions/deletions (`blockChange.operation`, from document\n * comparison) have no `<ins>`/`<del>` elements to strip, and resolving a\n * moved paragraph removes its whole block, so documents with either are\n * resolved first and serialized from the resolved document.\n */\nfunction resolvedBlockOperationsHtml(editor: any, view: TrackedChangesView): string | null {\n const doc: ProsemirrorNode | undefined = editor?.state?.doc;\n if (!doc || view === \"all\" || typeof document === \"undefined\") return null;\n let found = false;\n doc.descendants((node) => {\n if (found) return false;\n if (node.isTextblock) {\n if (node.attrs?.[BLOCK_CHANGE_ATTRIBUTE]?.operation) found = true;\n else node.forEach((child) => {\n if (child.marks.some((mark) => mark.attrs?.[MOVE_ID_ATTRIBUTE])) found = true;\n });\n return false;\n }\n return true;\n });\n if (!found) return null;\n const resolved = resolveTrackedChanges(doc, view);\n const container = document.createElement(\"div\");\n container.appendChild(DOMSerializer.fromSchema(doc.type.schema).serializeFragment(resolved.content));\n return container.innerHTML;\n}\n\n/**\n * Extracts plain text from a TipTap editor instance, preserving newline separators\n * between block nodes and converting mention nodes to @label. Tracked changes\n * are rendered as accepted unless `options.trackedChanges` says otherwise.\n */\nexport function getEditorText(editor: any, options: PlainTextOptions = {}): string {\n if (!editor) return \"\";\n const html =\n resolvedBlockOperationsHtml(editor, options.trackedChanges ?? \"accepted\") ??\n (typeof editor.getHTML === \"function\" ? editor.getHTML() : \"\");\n if (html) {\n return htmlToPlainText(html, options);\n }\n if (typeof editor.getText === \"function\") {\n try {\n return editor.getText({ blockSeparator: \"\\n\" });\n } catch {\n return editor.getText();\n }\n }\n return \"\";\n}\n\nexport interface ExtractedMention {\n id: string;\n label: string;\n type?: string;\n /** Asset role (`data-role`), when set. */\n role?: string;\n avatarUrl?: string;\n color?: string;\n [key: string]: any;\n}\n\nimport { extractMentions } from \"./mentions\";\n\n/**\n * Traverses an editor instance, ProseMirror document, JSONContent, or HTML string\n * and extracts all mention attributes without needing regex.\n */\nexport function extractMentionsFromDoc(docOrEditor: any): ExtractedMention[] {\n if (!docOrEditor) return [];\n const mentions: ExtractedMention[] = [];\n\n // TipTap editor or ProseMirror Node with .descendants()\n const doc =\n docOrEditor?.state?.doc ||\n (typeof docOrEditor?.descendants === \"function\" ? docOrEditor : null);\n\n if (doc && typeof doc.descendants === \"function\") {\n doc.descendants((node: any) => {\n if (node.type?.name === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n ...(node.attrs.assetRole ? { role: node.attrs.assetRole } : {}),\n });\n }\n });\n return mentions;\n }\n\n // JSONContent tree\n if (typeof docOrEditor === \"object\" && docOrEditor.content) {\n const walk = (nodes: any[]) => {\n for (const node of nodes) {\n if (node.type === \"mention\" && node.attrs) {\n mentions.push({\n id: node.attrs.id || \"\",\n label: node.attrs.label || \"\",\n type: node.attrs.type,\n avatarUrl: node.attrs.avatarUrl,\n color: node.attrs.color,\n ...node.attrs,\n ...(node.attrs.assetRole ? { role: node.attrs.assetRole } : {}),\n });\n }\n if (Array.isArray(node.content)) {\n walk(node.content);\n }\n }\n };\n walk(docOrEditor.content);\n return mentions;\n }\n\n // HTML String\n if (typeof docOrEditor === \"string\") {\n if (typeof document !== \"undefined\") {\n parseHtmlFragment(docOrEditor).querySelectorAll('span[data-type=\"mention\"]').forEach((el) => {\n mentions.push({\n id: el.getAttribute(\"data-id\") || \"\",\n label: el.getAttribute(\"data-label\") || \"\",\n type: el.getAttribute(\"data-type-name\") || undefined,\n avatarUrl: el.getAttribute(\"data-avatar-url\") || undefined,\n color: el.getAttribute(\"data-color\") || undefined,\n ...(el.getAttribute(\"data-role\") ? { role: el.getAttribute(\"data-role\")! } : {}),\n });\n });\n } else {\n for (const span of findTagSpans(docOrEditor, \"span\", MENTION_TYPE_ATTRIBUTE, false)) {\n const attrStr = span.attrs;\n const getAttr = (name: string) => {\n const m = new RegExp(`${name}=[\"']([^\"']*)[\"']`, \"i\").exec(attrStr);\n return m ? m[1] : undefined;\n };\n mentions.push({\n id: getAttr(\"data-id\") || \"\",\n label: getAttr(\"data-label\") || \"\",\n type: getAttr(\"data-type-name\") || getAttr(\"data-entity-type\"),\n avatarUrl: getAttr(\"data-avatar-url\"),\n color: getAttr(\"data-color\"),\n ...(getAttr(\"data-role\") ? { role: getAttr(\"data-role\") } : {}),\n });\n }\n }\n\n // Fallback: If no HTML mention tags were found, extract raw @mentions from text or markdown\n if (mentions.length === 0) {\n const rawHandles = extractMentions(docOrEditor);\n for (const handle of rawHandles) {\n mentions.push({\n id: handle,\n label: handle,\n type: \"user\",\n });\n }\n }\n }\n\n return mentions;\n}\n","/**\n * Linear-time scanners for the HTML-ish strings the serializers handle.\n *\n * Regexes like `/<span\\b[^>]*…[^>]*>/`, `/<[^>]+>/g` or `/<pre[\\s\\S]*?<\\/pre>/g` are\n * quadratic (or worse) on malformed input: every opener without its closer\n * rescans to the end of the string. These helpers find each closer once and\n * reuse it, so untrusted input can't stall the main thread (see GOTCHAS).\n */\n\nexport interface TagSpan {\n /** Index of the opening `<tag`. */\n start: number;\n /** Index just past the opening tag's `>`. */\n openEnd: number;\n /** Index just past the close tag (or `openEnd` when the close tag isn't required). */\n end: number;\n /** Attribute text between `<span` and `>`. */\n attrs: string;\n}\n\n/**\n * Finds `<tag …attrs…>…</tag>` elements whose attributes match `attrTest`, in\n * one linear pass. A regex such as `/<span\\b(?=[^>]*…)([^>]*)>[\\s\\S]*?<\\/span>/g`\n * rescans to the end of the input from every `<span` when a `>` or `</span>` is\n * missing, which is quadratic on malformed input. Here the next `>` and the next\n * close tag are found once and reused until the scan passes them, and the scan\n * stops as soon as either no longer exists further on. The first close tag after\n * the opening tag ends the element (no nesting), as with a lazy regex.\n */\nexport function findTagSpans(\n html: string,\n tag: string,\n attrTest: RegExp | ((attrs: string) => boolean),\n requireClose: boolean,\n): TagSpan[] {\n const matches = typeof attrTest === \"function\" ? attrTest : (attrs: string) => attrTest.test(attrs);\n const spans: TagSpan[] = [];\n const openTag = new RegExp(`<${tag}\\\\b`, \"gi\");\n const closeTag = new RegExp(`</${tag}>`, \"gi\");\n const closeLength = tag.length + 3;\n let nextGt = -1;\n let nextClose = -1;\n let from = 0;\n for (;;) {\n openTag.lastIndex = from;\n const open = openTag.exec(html);\n if (!open) break;\n const start = open.index;\n const attrsStart = start + open[0].length;\n if (nextGt < attrsStart) {\n nextGt = html.indexOf(\">\", attrsStart);\n if (nextGt === -1) break;\n }\n const attrs = html.slice(attrsStart, nextGt);\n const openEnd = nextGt + 1;\n if (!matches(attrs)) {\n from = attrsStart;\n continue;\n }\n if (!requireClose) {\n spans.push({ start, openEnd, end: openEnd, attrs });\n from = openEnd;\n continue;\n }\n if (nextClose < openEnd) {\n closeTag.lastIndex = openEnd;\n const close = closeTag.exec(html);\n if (!close) break;\n nextClose = close.index;\n }\n const end = nextClose + closeLength;\n spans.push({ start, openEnd, end, attrs });\n from = end;\n }\n return spans;\n}\n\n/** Replaces each matching element (opening tag through close tag) using `replace`. */\nexport function replaceTagSpans(\n html: string,\n tag: string,\n attrTest: RegExp | ((attrs: string) => boolean),\n replace: (match: string, attrs: string) => string,\n): string {\n const spans = findTagSpans(html, tag, attrTest, true);\n if (spans.length === 0) return html;\n let out = \"\";\n let last = 0;\n for (const span of spans) {\n out += html.slice(last, span.start) + replace(html.slice(span.start, span.end), span.attrs);\n last = span.end;\n }\n return out + html.slice(last);\n}\n\n/**\n * Replaces `<…>` tags in one pass. Same result as `.replace(/<[^>]+>/g, replacement)`,\n * which is quadratic when many `<` have no closing `>`: each one rescans to the\n * end. Once no `>` is left, the rest of the input is plain text.\n */\nexport function stripTags(html: string, replacement = \"\"): string {\n let out = \"\";\n let from = 0;\n for (;;) {\n const lt = html.indexOf(\"<\", from);\n if (lt === -1) break;\n const gt = html.indexOf(\">\", lt + 1);\n if (gt === -1) break;\n if (gt === lt + 1) {\n // \"<>\" is not a tag (the regex needs at least one character).\n out += html.slice(from, gt + 1);\n } else {\n out += html.slice(from, lt) + replacement;\n }\n from = gt + 1;\n }\n return out + html.slice(from);\n}\n\n/**\n * Removes (or replaces) regions that start with a match of `open` and end at the\n * next `close`, in one pass. Equivalent to `.replace(/<open>[\\s\\S]*?<close>/g, …)`\n * but linear: such a lazy regex rescans to the end of the input from every\n * unclosed opener. The next close position is cached until the scan passes it,\n * and scanning stops once no close is left. `open` must have the `g` flag.\n */\nexport function replaceDelimited(\n text: string,\n open: RegExp,\n close: string,\n replace: (match: string) => string = () => \"\",\n caseInsensitiveClose = false,\n): string {\n const haystack = caseInsensitiveClose ? asciiLower(text) : text;\n const needle = caseInsensitiveClose ? close.toLowerCase() : close;\n let out = \"\";\n let last = 0;\n let from = 0;\n let nextClose = -1;\n for (;;) {\n open.lastIndex = from;\n const opened = open.exec(text);\n if (!opened) break;\n const afterOpen = opened.index + Math.max(opened[0].length, 1);\n if (nextClose < afterOpen) {\n nextClose = haystack.indexOf(needle, afterOpen);\n if (nextClose === -1) break;\n }\n const end = nextClose + close.length;\n out += text.slice(last, opened.index) + replace(text.slice(opened.index, end));\n last = from = end;\n }\n return out + text.slice(last);\n}\n\n/** Lower-cases ASCII letters only, so indices match the original string. */\nfunction asciiLower(text: string): string {\n return text.replace(/[A-Z]+/g, (m) => m.toLowerCase());\n}\n","import { escapeHtml } from \"./plain-text\";\nimport {\n MENTION_REGEX,\n NODE_ROLE_MARK,\n formatMentionHandle,\n readRoleSuffix,\n type MentionRoleSyntax,\n} from \"./mention-text\";\n\nexport {\n MENTION_REGEX,\n findTextMentions,\n formatMentionText,\n setMentionRoleInText,\n type MentionRoleSyntax,\n type TextMention,\n} from \"./mention-text\";\nimport { findTagSpans, replaceDelimited, stripTags } from \"./html-scan\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n\n/**\n * Split regex identifying markdown code blocks, inline code, URLs, and existing HTML tags.\n * Used by preprocessMarkdownMentions to ensure non-mention regions remain completely untouched.\n */\nexport const MARKDOWN_MENTION_SPLIT_REGEX =\n /(```[\\s\\S]*?```|~~~[\\s\\S]*?~~~|<pre[\\s\\S]*?<\\/pre>|<code[\\s\\S]*?<\\/code>|`[^`\\n]+`|<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])[^>]*>[\\s\\S]*?<\\/span>|<[^>]+>|\\]\\([^)]+\\)|(?:https?|file|vscode|cursor|mailto):\\/\\/[^\\s<)]+)/gi;\n\nexport interface MentionSegment {\n type: \"text\" | \"mention\";\n value: string;\n handle?: string;\n /** Role written after the handle (`@fox:style`), when role syntax is enabled. */\n role?: string;\n}\n\n\n/** A mention with its role (asset mentions: `@fox:style`, or `data-role` on a mention node). */\nexport interface MentionDetail {\n handle: string;\n role?: string;\n}\n\nexport interface ExtractMentionsOptions {\n /** Return `{ handle, role }` objects instead of handles. */\n details?: boolean;\n /** Read `@handle:role` suffixes in text (see {@link MentionRoleSyntax}). Mention nodes' `data-role` is always read in `details` mode. */\n roles?: MentionRoleSyntax;\n}\n\nexport interface PreprocessMarkdownMentionsOptions {\n /**\n * Known pool of mentionable entities (users, agents, teams, etc.).\n */\n mentionables?: MentionEntity[];\n /**\n * Default entity type assigned when a handle does not match any entry in mentionables.\n * Defaults to 'user'.\n */\n defaultType?: string;\n /**\n * Custom resolver callback to derive entity metadata for unmatched handles.\n */\n resolveMention?: (handle: string) => Partial<MentionEntity> | null | undefined;\n /**\n * Read `@handle:role` and emit the role as `data-role` (the `:role` text is\n * consumed). Off by default. See {@link MentionRoleSyntax}.\n */\n roles?: MentionRoleSyntax;\n}\n\n/**\n * Strips code blocks and inline code from markdown or HTML content:\n * - Fenced code blocks: ```...``` and ~~~...~~~\n * - Inline backtick code: `...`\n * - HTML code/pre tags: <pre>...</pre>, <code>...</code>\n * Used to avoid false-positive mention parsing and keyword analysis within code snippets, terminal logs, or stack traces.\n */\nexport function stripMarkdownCode(content: string): string {\n if (!content || typeof content !== \"string\") return \"\";\n // Linear scans instead of lazy `[\\s\\S]*?` regexes, which rescan to the end of the\n // input from every unclosed opener (see html-scan.ts).\n let text = replaceDelimited(content, /```/g, \"```\");\n text = replaceDelimited(text, /~~~/g, \"~~~\");\n text = replaceDelimited(text, /<pre/gi, \"</pre>\", undefined, true);\n text = replaceDelimited(text, /<code/gi, \"</code>\", undefined, true);\n return text.replace(/`[^`\\n]*`/g, \"\");\n}\n\n/** True for the attributes of a mention node: `data-type=\"mention\"` or the `pixerate-mention-node` class. */\nfunction isMentionNodeAttributes(attrs: string): boolean {\n if (/\\bdata-type=[\"']mention[\"']/i.test(attrs)) return true;\n const classAttr = /\\bclass=([\"'])/i.exec(attrs);\n if (!classAttr) return false;\n const valueStart = classAttr.index + classAttr[0].length;\n const valueEnd = attrs.indexOf(classAttr[1], valueStart);\n return valueEnd !== -1 && attrs.slice(valueStart, valueEnd).includes(\"pixerate-mention-node\");\n}\n\n/**\n * Extracts unique mention handles from a text, markdown, or HTML string,\n * ignoring trailing punctuation, code blocks, URLs, and pre-existing HTML mention attributes.\n *\n * With `{ details: true }` it returns `{ handle, role }` objects, unique per\n * handle and role: roles come from mention nodes' `data-role` and, when\n * `roles` is set, from `@handle:role` text. Without options the result is\n * unchanged.\n */\nexport function extractMentions(content: string, options?: ExtractMentionsOptions & { details?: false }): string[];\nexport function extractMentions(content: string, options: ExtractMentionsOptions & { details: true }): MentionDetail[];\nexport function extractMentions(content: string, options?: ExtractMentionsOptions): string[] | MentionDetail[];\nexport function extractMentions(content: string, options: ExtractMentionsOptions = {}): string[] | MentionDetail[] {\n if (!content || typeof content !== \"string\") return [];\n const details = options.details === true;\n\n // Normalize existing HTML mention nodes (e.g. from TipTap or rich text serializers)\n // so data-mention-suggestion-char=\"@\" does not trigger spurious quoted matches against attributes,\n // and ensure the actual mentioned label or ID is preserved cleanly.\n // A linear scan: the equivalent regex (`<span\\b[^>]*\\b(?:…)[^>]*>`) backtracks\n // cubically on malformed input without a `>` (see html-scan.ts).\n let normalizedMentionNodes = \"\";\n let last = 0;\n for (const span of findTagSpans(content, \"span\", isMentionNodeAttributes, true)) {\n const labelMatch = /\\bdata-label=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const idMatch = labelMatch ? null : /\\bdata-id=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const inner = content.slice(span.openEnd, span.end - \"</span>\".length);\n let replacement = labelMatch ? ` @${labelMatch[1]} ` : idMatch ? ` @${idMatch[1]} ` : ` ${inner} `;\n if (details && (labelMatch || idMatch)) {\n const roleMatch = /\\bdata-role=[\"']([^\"']+)[\"']/i.exec(span.attrs);\n const role = roleMatch && /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/.test(roleMatch[1]) ? roleMatch[1] : null;\n const label = (labelMatch ?? idMatch)![1];\n replacement = ` ${formatMentionHandle(label)}${role ? NODE_ROLE_MARK + role : \"\"} `;\n }\n normalizedMentionNodes += content.slice(last, span.start) + replacement;\n last = span.end;\n }\n normalizedMentionNodes += content.slice(last);\n\n const cleanContent = stripMarkdownCode(normalizedMentionNodes);\n // Strip URLs and markdown link destinations so @package or @handles in URLs are not extracted as mentions\n const withoutUrls = cleanContent\n .replace(/(?:https?|ftp|file|vscode|cursor|mailto):\\/\\/[^\\s<>()]+/gi, \"\");\n // Markdown link destinations: `](…)` → `]` (linear; `/\\]\\([^)]*\\)/g` is quadratic\n // when many `](` have no `)`).\n const withoutLinks = replaceDelimited(withoutUrls, /\\]\\(/g, \")\", () => \"]\");\n // Strip remaining HTML tags so attributes containing '@' or '>' aren't treated as mention triggers\n const textOnly = stripTags(withoutLinks, \" \");\n\n const mentions: string[] = [];\n const detailed: MentionDetail[] = [];\n const seen = new Set<string>();\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(textOnly)) !== null) {\n const handle = (match[1] ?? match[2] ?? match[3] ?? \"\").trim();\n if (details) {\n const suffix = readRoleSuffix(textOnly, regex.lastIndex, options.roles);\n if (suffix) regex.lastIndex = suffix.end;\n const key = `${handle}\\u0000${suffix?.role ?? \"\"}`;\n if (handle && !seen.has(key)) {\n seen.add(key);\n detailed.push(suffix ? { handle, role: suffix.role } : { handle });\n }\n continue;\n }\n if (handle && !seen.has(handle)) {\n seen.add(handle);\n mentions.push(handle);\n }\n }\n\n return details ? detailed : mentions;\n}\n\n/**\n * Segments a text string into plain text parts and mention tokens.\n * Correctly leaves trailing punctuation (like \".\") as part of the following text segment.\n */\nexport function parseMentionSegments(\n content: string,\n options: { roles?: MentionRoleSyntax } = {},\n): MentionSegment[] {\n if (!content) return [];\n\n const segments: MentionSegment[] = [];\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = regex.exec(content)) !== null) {\n const fullMatch = match[0];\n const atIndex = fullMatch.indexOf(\"@\");\n const prefix = atIndex > 0 ? fullMatch.slice(0, atIndex) : \"\";\n let mentionToken = fullMatch.slice(atIndex);\n const handle = match[1] ?? match[2] ?? match[3];\n const matchStart = match.index + prefix.length;\n const suffix =\n options.roles && content.charAt(regex.lastIndex) === \":\"\n ? readRoleSuffix(content, regex.lastIndex, options.roles)\n : null;\n if (suffix) {\n mentionToken = content.slice(matchStart, suffix.end);\n regex.lastIndex = suffix.end;\n }\n\n if (matchStart > lastIndex) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex, matchStart),\n });\n }\n\n segments.push({\n type: \"mention\",\n value: mentionToken,\n handle,\n ...(suffix ? { role: suffix.role } : {}),\n });\n\n lastIndex = matchStart + mentionToken.length;\n }\n\n if (lastIndex < content.length) {\n segments.push({\n type: \"text\",\n value: content.slice(lastIndex),\n });\n }\n\n return segments;\n}\n\n/**\n * Preprocesses markdown text by turning raw @mention handles into TipTap-compatible\n * mention HTML spans (<span class=\"pixerate-mention-node\" data-type=\"mention\" ...>),\n * ensuring code blocks, inline code, existing mention nodes, and URLs remain immune.\n */\nexport function preprocessMarkdownMentions(\n content: string,\n optionsOrMentionables: MentionEntity[] | PreprocessMarkdownMentionsOptions = []\n): string {\n if (!content || typeof content !== \"string\") return \"\";\n\n const options: PreprocessMarkdownMentionsOptions = Array.isArray(optionsOrMentionables)\n ? { mentionables: optionsOrMentionables }\n : optionsOrMentionables;\n\n const allMentionables = options.mentionables || [];\n const defaultType = options.defaultType || \"user\";\n const resolveMention = options.resolveMention;\n\n const parts = content.split(MARKDOWN_MENTION_SPLIT_REGEX);\n\n return parts\n .map((part) => {\n if (!part) return \"\";\n\n // Preserve code fences, code tags, inline backticks, existing mention spans,\n // HTML tags, markdown link targets, and raw URLs untouched.\n if (\n part.startsWith(\"```\") ||\n part.startsWith(\"~~~\") ||\n part.startsWith(\"`\") ||\n part.startsWith(\"](\") ||\n /^(?:https?|file|vscode|cursor|mailto):\\/\\//i.test(part) ||\n /^<pre[\\s>]/i.test(part) ||\n /^<code[\\s>]/i.test(part) ||\n /^<[^>]+>$/i.test(part) ||\n /^<span\\b[^>]*\\b(?:data-type=[\"']mention[\"']|class=[\"'][^\"']*pixerate-mention-node[^\"']*[\"']|data-mention=[\"'][^\"']*[\"'])/i.test(\n part\n )\n ) {\n return part;\n }\n\n const regex = new RegExp(MENTION_REGEX.source, \"g\");\n const render = (\n match: string,\n quotedHandle: string | undefined,\n escapedQuotedHandle: string | undefined,\n standardHandle: string | undefined,\n role?: string,\n ): string => {\n const atIndex = match.indexOf(\"@\");\n const prefix = atIndex > 0 ? match.slice(0, atIndex) : \"\";\n const rawHandle = (quotedHandle || escapedQuotedHandle || standardHandle || \"\").trim();\n if (!rawHandle) return match;\n\n const lowerHandle = rawHandle.toLowerCase();\n const entity = allMentionables.find((e) => {\n if (e.label?.toLowerCase() === lowerHandle) return true;\n if (e.handle?.toLowerCase() === lowerHandle) return true;\n if (e.name?.toLowerCase() === lowerHandle) return true;\n if (e.id?.toLowerCase() === lowerHandle) return true;\n if (e.type === \"agent\" && `agent${(e.handle || e.label || \"\").toLowerCase()}` === lowerHandle) return true;\n if (\n e.aliases?.some(\n (a: string) =>\n a.toLowerCase() === lowerHandle ||\n (e.type === \"agent\" && `agent${a.toLowerCase()}` === lowerHandle)\n )\n ) {\n return true;\n }\n return false;\n });\n\n let id = entity?.id;\n let label = entity?.label || entity?.handle || rawHandle;\n let type = entity?.type;\n let avatarUrl = entity?.avatarUrl;\n let color = entity?.color || entity?.hexColor;\n\n if (!entity) {\n const customResolved = resolveMention?.(rawHandle);\n if (customResolved) {\n id = customResolved.id ?? id;\n label = customResolved.label ?? customResolved.handle ?? label;\n type = customResolved.type ?? type;\n avatarUrl = customResolved.avatarUrl ?? avatarUrl;\n color = customResolved.color ?? customResolved.hexColor ?? color;\n } else {\n const stripped = lowerHandle.replace(/^agent[\\s\\-_]*/i, \"\");\n if (\n [\"supervisor\", \"coordinator\", \"planner\", \"validator\", \"executor\"].includes(stripped)\n ) {\n type = \"agent\";\n id = stripped;\n label = stripped;\n } else if (lowerHandle === \"agents\") {\n type = \"team\";\n id = \"agents\";\n label = \"agents\";\n } else {\n type = defaultType;\n id = rawHandle;\n label = rawHandle;\n }\n }\n }\n\n const avatarAttr = avatarUrl ? ` data-avatar-url=\"${escapeHtml(avatarUrl)}\"` : \"\";\n const colorAttr = color ? ` data-color=\"${escapeHtml(color)}\"` : \"\";\n\n return `${prefix}<span class=\"pixerate-mention-node\" data-type=\"mention\" data-id=\"${escapeHtml(\n id || label\n )}\" data-label=\"${escapeHtml(label)}\" data-mention-suggestion-char=\"@\" data-type-name=\"${escapeHtml(\n type || defaultType\n )}\"${avatarAttr}${colorAttr}${role ? ` data-role=\"${escapeHtml(role)}\"` : \"\"}>@${escapeHtml(label)}</span>`;\n };\n if (!options.roles) {\n return part.replace(regex, (match, quotedHandle, escapedQuotedHandle, standardHandle) =>\n render(match, quotedHandle, escapedQuotedHandle, standardHandle),\n );\n }\n // Role syntax: consume a `:role` suffix after each mention.\n let out = \"\";\n let last = 0;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(part)) !== null) {\n const suffix = readRoleSuffix(part, regex.lastIndex, options.roles);\n const rendered = render(match[0], match[1], match[2], match[3], suffix?.role);\n if (suffix && rendered !== match[0]) regex.lastIndex = suffix.end;\n out += part.slice(last, match.index) + rendered;\n last = regex.lastIndex;\n }\n return out + part.slice(last);\n })\n .join(\"\");\n}\n","import MarkdownIt from \"markdown-it\";\nimport taskLists from \"markdown-it-task-lists\";\nimport { escapeHtml, getEditorText, type PlainTextOptions } from \"./plain-text\";\nimport { resolveTrackedChanges } from \"../extensions/track-changes\";\n\nconst md = new MarkdownIt({\n html: true,\n linkify: true,\n breaks: true,\n}).use(taskLists);\n\nconst defaultValidateLink = md.validateLink;\nmd.validateLink = (url: string) => {\n if (\n url.startsWith(\"file://\") ||\n url.startsWith(\"vscode://\") ||\n url.startsWith(\"cursor://\")\n ) {\n return true;\n }\n return defaultValidateLink.call(md, url);\n};\n\n/**\n * Tags allowed through from raw HTML embedded in markdown (e.g. mention spans\n * and file links that tiptap-markdown serializes as HTML). Anything else is\n * rendered as escaped text. `input` is limited to checkboxes, which\n * markdown-it-task-lists emits as raw HTML.\n */\nconst ALLOWED_HTML_TAGS = new Set([\n \"a\", \"abbr\", \"b\", \"blockquote\", \"br\", \"code\", \"col\", \"colgroup\", \"del\", \"details\", \"div\", \"em\",\n \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"hr\", \"i\", \"img\", \"input\", \"ins\", \"kbd\", \"li\", \"mark\",\n \"ol\", \"p\", \"pre\", \"s\", \"span\", \"strong\", \"sub\", \"summary\", \"sup\", \"table\",\n \"tbody\", \"td\", \"tfoot\", \"th\", \"thead\", \"tr\", \"u\", \"ul\",\n]);\n\nconst ALLOWED_HTML_ATTRS = new Set([\n \"alt\", \"align\", \"checked\", \"class\", \"colspan\", \"colwidth\", \"disabled\", \"height\", \"href\",\n \"rel\", \"rowspan\", \"src\", \"start\", \"target\", \"title\", \"type\", \"width\",\n]);\n\nconst HTML_TAG_REGEX =\n /<(\\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\\s+[^\\s\"'>\\/=]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'=<>`]+))?)*)\\s*\\/?>/g;\nconst HTML_ATTR_REGEX =\n /([^\\s\"'>\\/=]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+)))?/g;\n\nfunction sanitizeTag(\n tagText: string,\n isClosing: string,\n rawTagName: string,\n rawAttrs: string,\n stripDisallowed: boolean,\n): string {\n const tagName = rawTagName.toLowerCase();\n const reject = () => (stripDisallowed ? \"\" : escapeHtml(tagText));\n if (!ALLOWED_HTML_TAGS.has(tagName)) return reject();\n if (isClosing) return `</${tagName}>`;\n if (tagName === \"input\" && !/\\stype\\s*=\\s*[\"']?checkbox[\"']?[\\s>/]/i.test(tagText)) {\n return reject();\n }\n\n let attrs = \"\";\n let attrMatch: RegExpExecArray | null;\n HTML_ATTR_REGEX.lastIndex = 0;\n while ((attrMatch = HTML_ATTR_REGEX.exec(rawAttrs)) !== null) {\n const name = attrMatch[1].toLowerCase();\n if (!ALLOWED_HTML_ATTRS.has(name) && !/^data-[a-z0-9_.-]+$/.test(name)) {\n continue;\n }\n const rawValue = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4];\n if (rawValue === undefined) {\n attrs += ` ${name}`;\n continue;\n }\n const value = md.utils.unescapeAll(rawValue);\n if (\n (name === \"href\" || name === \"src\") &&\n // Browsers ignore control characters and whitespace inside schemes.\n !md.validateLink(value.replace(/[\\u0000-\\u0020\\u007f]/g, \"\"))\n ) {\n continue;\n }\n attrs += ` ${name}=\"${escapeHtml(value)}\"`;\n }\n return `<${tagName}${attrs}>`;\n}\n\nexport interface SanitizeHtmlOptions {\n /**\n * What to do with tags outside the allowlist: `escape` (default) renders\n * them as literal text, `strip` removes the tag but keeps its text content.\n */\n disallowedTags?: \"escape\" | \"strip\";\n}\n\n/**\n * Sanitizes raw HTML with the same allowlist the markdown renderer applies to\n * embedded HTML: event handlers, `style` and unsafe URL schemes are dropped,\n * and disallowed tags are escaped (or removed with `disallowedTags: \"strip\"`).\n * It is string-based, so it works without a DOM and never runs handlers.\n */\nexport function sanitizeHtml(html: string, options: SanitizeHtmlOptions = {}): string {\n return sanitizeEmbeddedHtml(html, options.disallowedTags === \"strip\");\n}\n\nfunction sanitizeEmbeddedHtml(html: string, stripDisallowed = false): string {\n let result = \"\";\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n HTML_TAG_REGEX.lastIndex = 0;\n while ((match = HTML_TAG_REGEX.exec(html)) !== null) {\n result += html.slice(lastIndex, match.index).replace(/</g, \"&lt;\");\n result += sanitizeTag(match[0], match[1], match[2], match[3], stripDisallowed);\n lastIndex = match.index + match[0].length;\n }\n return result + html.slice(lastIndex).replace(/</g, \"&lt;\");\n}\n\nconst defaultHtmlInline = md.renderer.rules.html_inline;\nconst defaultHtmlBlock = md.renderer.rules.html_block;\nmd.renderer.rules.html_inline = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlInline!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\nmd.renderer.rules.html_block = (tokens, idx, options, env, self) =>\n env?.allowUnsafeHtml\n ? defaultHtmlBlock!(tokens, idx, options, env, self)\n : sanitizeEmbeddedHtml(tokens[idx].content);\n\nimport {\n preprocessMarkdownMentions,\n type PreprocessMarkdownMentionsOptions,\n} from \"./mentions\";\nimport type { MentionEntity } from \"../extensions/mention\";\n\n/**\n * Preprocesses file-protocol and editor-protocol links in markdown content:\n * converts [label](file://...), vscode://, and cursor:// links into anchor tags\n * annotated with data-file-link=\"true\", preserving code backticks in labels.\n */\nexport function preprocessMarkdownFileLinks(content: string): string {\n if (!content) return \"\";\n return content.replace(\n /\\[([^\\]]+)\\]\\(((?:file|vscode|cursor):\\/\\/[^)]+)\\)/g,\n (_match, rawLabel, href) => {\n const trimmed = rawLabel.trim();\n const codeMatch = trimmed.match(/^`([^`]+)`$/);\n const labelContent = codeMatch\n ? `<code>${escapeHtml(codeMatch[1])}</code>`\n : escapeHtml(trimmed);\n return `<a href=\"${escapeHtml(href)}\" data-file-link=\"true\" title=\"Click to copy file path\">${labelContent}</a>`;\n }\n );\n}\n\nexport interface MarkdownToHtmlOptions {\n /**\n * Preprocess file, vscode, and cursor links into clickable data-file-link tags.\n */\n preprocessFileLinks?: boolean;\n /**\n * Whether to preprocess @mentions into TipTap mention node HTML spans.\n */\n preprocessMentions?: boolean;\n /**\n * Pool of mentionables to pass to preprocessMarkdownMentions.\n */\n mentionables?: MentionEntity[];\n /**\n * Full options for preprocessMarkdownMentions.\n */\n preprocessOptions?: PreprocessMarkdownMentionsOptions;\n /**\n * Render raw HTML embedded in the markdown without sanitizing it. By default,\n * embedded HTML is restricted to an allowlist of tags and attributes (event\n * handlers, `style` and unsafe URL schemes are removed). Only enable this for\n * fully trusted input.\n */\n allowUnsafeHtml?: boolean;\n}\n\n/**\n * Converts a markdown string into HTML suitable for TipTap initial content or setContent.\n * Raw HTML embedded in the markdown is sanitized unless `allowUnsafeHtml` is set.\n */\nexport function markdownToTipTapHtml(\n markdown: string,\n options?: MarkdownToHtmlOptions\n): string {\n if (!markdown) return \"<p></p>\";\n let content = markdown;\n if (options?.preprocessFileLinks) {\n content = preprocessMarkdownFileLinks(content);\n }\n if (\n options?.preprocessMentions ||\n options?.mentionables ||\n options?.preprocessOptions\n ) {\n const mentionOpts = options.preprocessOptions || {\n mentionables: options.mentionables,\n };\n content = preprocessMarkdownMentions(content, mentionOpts);\n }\n return md.render(content, { allowUnsafeHtml: options?.allowUnsafeHtml });\n}\n\n/**\n * Extracts clean markdown from a TipTap editor instance.\n * If the editor has the Markdown extension configured, it uses editor.storage.markdown.getMarkdown().\n * Otherwise, it falls back to getEditorText(editor).\n * Tracked changes are exported as accepted unless `options.trackedChanges`\n * says otherwise (`\"all\"` renders deletions as `~~strikethrough~~`).\n */\nexport function getEditorMarkdown(editor: any, options: PlainTextOptions = {}): string {\n if (!editor) return \"\";\n const markdown = editor.storage?.markdown;\n if (typeof markdown?.getMarkdown === \"function\") {\n const doc = editor.state?.doc;\n if (doc && typeof markdown.serializer?.serialize === \"function\") {\n const resolved = resolveTrackedChanges(doc, options.trackedChanges ?? \"accepted\");\n if (resolved !== doc) return markdown.serializer.serialize(resolved);\n }\n return markdown.getMarkdown();\n }\n return getEditorText(editor, options);\n}\n"]}