@gravity-ui/markdown-editor 15.36.0 → 15.37.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 (121) hide show
  1. package/README.md +87 -0
  2. package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js +1 -0
  3. package/build/cjs/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js.map +1 -1
  4. package/build/cjs/extensions/behavior/Clipboard/clipboard.js +2 -13
  5. package/build/cjs/extensions/behavior/Clipboard/clipboard.js.map +1 -1
  6. package/build/cjs/extensions/behavior/Clipboard/selection-content.d.ts +1 -0
  7. package/build/cjs/extensions/behavior/Clipboard/selection-content.js +35 -0
  8. package/build/cjs/extensions/behavior/Clipboard/selection-content.js.map +1 -0
  9. package/build/cjs/extensions/behavior/Selection/commands.d.ts +2 -1
  10. package/build/cjs/extensions/behavior/Selection/commands.js +47 -1
  11. package/build/cjs/extensions/behavior/Selection/commands.js.map +1 -1
  12. package/build/cjs/extensions/behavior/Selection/selection.d.ts +15 -0
  13. package/build/cjs/extensions/behavior/Selection/selection.js +1 -0
  14. package/build/cjs/extensions/behavior/Selection/selection.js.map +1 -1
  15. package/build/cjs/extensions/markdown/Blockquote/BlockquoteSpecs/index.js +1 -0
  16. package/build/cjs/extensions/markdown/Blockquote/BlockquoteSpecs/index.js.map +1 -1
  17. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.d.ts +2 -2
  18. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js +17 -75
  19. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js.map +1 -1
  20. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.d.ts +14 -0
  21. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.js +117 -0
  22. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.js.map +1 -0
  23. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.d.ts +9 -0
  24. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.js +22 -0
  25. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.js.map +1 -0
  26. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.d.ts +2 -3
  27. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.js +5 -93
  28. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.js.map +1 -1
  29. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.d.ts +23 -0
  30. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.js +88 -0
  31. package/build/cjs/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.js.map +1 -0
  32. package/build/cjs/extensions/markdown/Deflist/DeflistSpecs/schema.js +2 -0
  33. package/build/cjs/extensions/markdown/Deflist/DeflistSpecs/schema.js.map +1 -1
  34. package/build/cjs/extensions/markdown/Table/TableSpecs/schema.js +1 -0
  35. package/build/cjs/extensions/markdown/Table/TableSpecs/schema.js.map +1 -1
  36. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +2 -0
  37. package/build/cjs/extensions/yfm/YfmCut/YfmCutSpecs/schema.js.map +1 -1
  38. package/build/cjs/extensions/yfm/YfmNote/YfmNoteSpecs/schema.js +2 -0
  39. package/build/cjs/extensions/yfm/YfmNote/YfmNoteSpecs/schema.js.map +1 -1
  40. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.css +20 -0
  41. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.d.ts +9 -0
  42. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.js +77 -0
  43. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.js.map +1 -0
  44. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.d.ts +1 -2
  45. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.js +5 -65
  46. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.js.map +1 -1
  47. package/build/cjs/extensions/yfm/YfmTable/YfmTableSpecs/schema.js +2 -0
  48. package/build/cjs/extensions/yfm/YfmTable/YfmTableSpecs/schema.js.map +1 -1
  49. package/build/cjs/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js +3 -0
  50. package/build/cjs/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js.map +1 -1
  51. package/build/cjs/plugins/BaseTooltip/index.d.ts +1 -0
  52. package/build/cjs/plugins/BaseTooltip/index.js +4 -3
  53. package/build/cjs/plugins/BaseTooltip/index.js.map +1 -1
  54. package/build/cjs/toolbar/ToolbarGroup.js +4 -3
  55. package/build/cjs/toolbar/ToolbarGroup.js.map +1 -1
  56. package/build/cjs/toolbar/types.d.ts +2 -0
  57. package/build/cjs/toolbar/types.js.map +1 -1
  58. package/build/cjs/version.js +1 -1
  59. package/build/cjs/version.js.map +1 -1
  60. package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js +1 -0
  61. package/build/esm/extensions/additional/QuoteLink/QuoteLinkSpecs/index.js.map +1 -1
  62. package/build/esm/extensions/behavior/Clipboard/clipboard.js +1 -12
  63. package/build/esm/extensions/behavior/Clipboard/clipboard.js.map +1 -1
  64. package/build/esm/extensions/behavior/Clipboard/selection-content.d.ts +1 -0
  65. package/build/esm/extensions/behavior/Clipboard/selection-content.js +32 -0
  66. package/build/esm/extensions/behavior/Clipboard/selection-content.js.map +1 -0
  67. package/build/esm/extensions/behavior/Selection/commands.d.ts +2 -1
  68. package/build/esm/extensions/behavior/Selection/commands.js +47 -2
  69. package/build/esm/extensions/behavior/Selection/commands.js.map +1 -1
  70. package/build/esm/extensions/behavior/Selection/selection.d.ts +15 -0
  71. package/build/esm/extensions/behavior/Selection/selection.js +2 -1
  72. package/build/esm/extensions/behavior/Selection/selection.js.map +1 -1
  73. package/build/esm/extensions/markdown/Blockquote/BlockquoteSpecs/index.js +1 -0
  74. package/build/esm/extensions/markdown/Blockquote/BlockquoteSpecs/index.js.map +1 -1
  75. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.d.ts +2 -2
  76. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js +17 -75
  77. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.js.map +1 -1
  78. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.d.ts +14 -0
  79. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.js +114 -0
  80. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.js.map +1 -0
  81. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.d.ts +9 -0
  82. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.js +19 -0
  83. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.js.map +1 -0
  84. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.d.ts +2 -3
  85. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.js +6 -94
  86. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/index.js.map +1 -1
  87. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.d.ts +23 -0
  88. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.js +83 -0
  89. package/build/esm/extensions/markdown/CodeBlock/CodeBlockHighlight/plugins/codeBlockLangsPlugin.js.map +1 -0
  90. package/build/esm/extensions/markdown/Deflist/DeflistSpecs/schema.js +2 -0
  91. package/build/esm/extensions/markdown/Deflist/DeflistSpecs/schema.js.map +1 -1
  92. package/build/esm/extensions/markdown/Table/TableSpecs/schema.js +1 -0
  93. package/build/esm/extensions/markdown/Table/TableSpecs/schema.js.map +1 -1
  94. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js +2 -0
  95. package/build/esm/extensions/yfm/YfmCut/YfmCutSpecs/schema.js.map +1 -1
  96. package/build/esm/extensions/yfm/YfmNote/YfmNoteSpecs/schema.js +2 -0
  97. package/build/esm/extensions/yfm/YfmNote/YfmNoteSpecs/schema.js.map +1 -1
  98. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.css +20 -0
  99. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.d.ts +9 -0
  100. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.js +74 -0
  101. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/YfmNoteToolbar.js.map +1 -0
  102. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.d.ts +1 -2
  103. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.js +4 -64
  104. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.js.map +1 -1
  105. package/build/esm/extensions/yfm/YfmTable/YfmTableSpecs/schema.js +2 -0
  106. package/build/esm/extensions/yfm/YfmTable/YfmTableSpecs/schema.js.map +1 -1
  107. package/build/esm/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js +3 -0
  108. package/build/esm/extensions/yfm/YfmTabs/YfmTabsSpecs/schema.js.map +1 -1
  109. package/build/esm/plugins/BaseTooltip/index.d.ts +1 -0
  110. package/build/esm/plugins/BaseTooltip/index.js +4 -3
  111. package/build/esm/plugins/BaseTooltip/index.js.map +1 -1
  112. package/build/esm/toolbar/ToolbarGroup.js +4 -3
  113. package/build/esm/toolbar/ToolbarGroup.js.map +1 -1
  114. package/build/esm/toolbar/types.d.ts +2 -0
  115. package/build/esm/toolbar/types.js.map +1 -1
  116. package/build/esm/version.js +1 -1
  117. package/build/esm/version.js.map +1 -1
  118. package/build/styles.css +9 -5
  119. package/package.json +4 -3
  120. package/build/cjs/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.css +0 -16
  121. package/build/esm/extensions/yfm/YfmNote/plugins/YfmNoteTooltipPlugin/index.css +0 -16
@@ -1 +1 @@
1
- {"version":3,"file":"commands.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Selection/commands.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAC,WAAW,EAAC,gCAA6B;AACjD,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,oCAAiC;AAC1E,OAAO,EAAC,kBAAkB,EAAE,oBAAoB,EAAC,wCAAqC;AActF,MAAM,IAAI,GAAG,CAAC,GAAmB,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,IAAI,CAAC;AAErE,SAAS,WAAW,CAAC,IAAU;IAC3B,OAAO,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,eAAe,CAAC,OAAoB,EAAE,GAAc;IACzD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK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CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAEzC,MAAM,CAAC,MAAM,SAAS,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IAClD,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC;IAC5B,IAAI,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAChD,IAAI,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import type {Node, ResolvedPos} from 'prosemirror-model';\nimport type {Command, NodeSelection, TextSelection, Transaction} from 'prosemirror-state';\nimport {Selection} from 'prosemirror-state';\n\nimport {isCodeBlock} from '../../../utils/nodes';\nimport {isNodeSelection, isTextSelection} from '../../../utils/selection';\nimport {GapCursorSelection, isGapCursorSelection} from '../Cursor/GapCursorSelection';\n\nexport type Direction = 'before' | 'after';\ntype ArrowDirection = 'up' | 'right' | 'down' | 'left';\n\ntype TextSelectionFinder = (selection: TextSelection, dir: Direction) => ResolvedPos | null;\ntype NodeSelectionFinder = (selection: NodeSelection, dir: Direction) => ResolvedPos | null;\ntype GapCursorSelectionFinder = (\n selection: GapCursorSelection,\n dir: Direction,\n) => ResolvedPos | null;\n\ntype GapCursorMeta = {direction: Direction};\n\nconst isUp = (dir: ArrowDirection) => dir === 'left' || dir === 'up';\n\nfunction isTextblock(node: Node): boolean {\n return node.isTextblock && !isCodeBlock(node);\n}\n\nfunction isEdgeTextblock($cursor: ResolvedPos, dir: Direction): boolean {\n const index = $cursor.index($cursor.depth - 1);\n if (dir === 'before') return index === 0;\n if (dir === 'after') return index === $cursor.node($cursor.depth - 1).childCount - 1;\n return false;\n}\n\nexport const findNextFakeParaPosForGapCursorSelection: GapCursorSelectionFinder = ({$pos}, dir) => {\n if ($pos.pos !== $pos.start() && $pos.pos !== $pos.end()) return null;\n return findFakeParaPosClosestToPos($pos, $pos.depth, dir);\n};\n\nexport const findFakeParaPosForNodeSelection: NodeSelectionFinder = (selection, dir) => {\n const selectedNode = selection.node;\n if (selectedNode.isInline || isTextblock(selectedNode)) return null;\n\n const {$from} = selection;\n const index = $from.index();\n const parentNode = $from.parent;\n if (dir === 'before') {\n if (parentNode.firstChild === selectedNode || !isTextblock(parentNode.child(index - 1))) {\n return $from;\n }\n } else if (dir === 'after') {\n if (parentNode.lastChild === selectedNode || !isTextblock(parentNode.child(index + 1))) {\n return selection.$to;\n }\n }\n\n return null;\n};\n\nexport const findFakeParaPosForCodeBlock = ($cursor: ResolvedPos, dir: Direction) => {\n if (!isCodeBlock($cursor.parent)) return null;\n\n let foundPos = -1;\n const index = $cursor.index($cursor.depth - 1);\n const parent = $cursor.node($cursor.depth - 1);\n if (dir === 'before') {\n if (index === 0 || !isTextblock(parent.child(index - 1))) {\n foundPos = $cursor.before();\n }\n } else if (dir === 'after') {\n if (index === parent.childCount - 1 || !isTextblock(parent.child(index + 1))) {\n foundPos = $cursor.after();\n }\n }\n\n return foundPos !== -1 ? $cursor.doc.resolve(foundPos) : null;\n};\n\nexport const findFakeParaPosForTextSelection: TextSelectionFinder = (selection, dir) => {\n const $cursor = dir === 'before' ? selection.$from : selection.$to;\n if ($cursor.parent.isInline) return null;\n\n const $pos = findFakeParaPosForCodeBlock($cursor, dir);\n if ($pos) return $pos;\n\n if (!isEdgeTextblock($cursor, dir)) return null;\n\n return findFakeParaPosClosestToPos($cursor, $cursor.depth - 1, dir);\n};\n\nexport function findFakeParaPosClosestToPos(\n $pos: ResolvedPos,\n depth: number,\n dir: Direction,\n): ResolvedPos | null {\n depth++;\n while (--depth > 0) {\n const node = $pos.node(depth);\n const index = $pos.index(depth - 1);\n const parent = $pos.node(depth - 1);\n\n const isFirstChild = index === 0;\n const isLastChild = index === parent.childCount - 1;\n\n const isComplexChild =\n node.type.spec.complex === 'inner' || node.type.spec.complex === 'leaf';\n\n const disabledGapCursor = parent.type.spec.gapcursor === false;\n\n if (isComplexChild || disabledGapCursor) {\n if (dir === 'before' && isFirstChild) continue;\n if (dir === 'after' && isLastChild) continue;\n return null;\n }\n\n if (dir === 'before') {\n if (isFirstChild || !isTextblock(parent.child(index - 1))) {\n return $pos.doc.resolve($pos.before(depth));\n }\n } else if (dir === 'after') {\n if (isLastChild || !isTextblock(parent.child(index + 1))) {\n return $pos.doc.resolve($pos.after(depth));\n }\n }\n\n return null;\n }\n return null;\n}\n\nconst arrow =\n (dir: ArrowDirection): Command =>\n (state, dispatch, view) => {\n const {selection} = state;\n const direction: Direction = isUp(dir) ? 'before' : 'after';\n let $pos: ResolvedPos | null = null;\n\n if (isGapCursorSelection<GapCursorMeta>(selection)) {\n if (selection.meta?.direction !== direction) {\n return false;\n }\n\n // if gap selection is at start or end of doc\n if (dir === 'up' && selection.pos === 0) return true;\n if (dir === 'down' && selection.pos === state.doc.nodeSize - 2) return true;\n\n $pos = findNextFakeParaPosForGapCursorSelection(selection, direction);\n }\n\n if (isNodeSelection(selection)) {\n $pos = findFakeParaPosForNodeSelection(selection, direction);\n }\n\n if (isTextSelection(selection) && view?.endOfTextblock(dir)) {\n $pos = findFakeParaPosForTextSelection(selection, direction);\n }\n\n if ($pos) {\n dispatch?.(createFakeParagraph(state.tr, $pos, direction).scrollIntoView());\n return true;\n }\n\n return false;\n };\n\nexport function createFakeParagraph(\n tr: Transaction,\n $pos: ResolvedPos,\n direction: Direction,\n): Transaction {\n return tr.setSelection(new GapCursorSelection<GapCursorMeta>($pos, {meta: {direction}}));\n}\n\nexport const arrowLeft = arrow('left');\nexport const arrowDown = arrow('down');\nexport const arrowUp = arrow('up');\nexport const arrowRight = arrow('right');\n\nexport const backspace: Command = (state, dispatch) => {\n const sel = state.selection;\n if (isGapCursorSelection(sel)) {\n const newSel = Selection.findFrom(sel.$pos, -1);\n if (newSel) {\n dispatch?.(state.tr.setSelection(newSel).scrollIntoView());\n return true;\n }\n }\n return false;\n};\n"]}
1
+ {"version":3,"file":"commands.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Selection/commands.ts"],"names":[],"mappings":"AACA,OAAO,EAGH,SAAS,EACT,aAAa,IAAI,OAAO,EACxB,aAAa,GAEhB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,gCAA6B;AAC9D,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,oCAAiC;AAC1E,OAAO,EAAC,kBAAkB,EAAE,oBAAoB,EAAC,wCAAqC;AACtF,OAAO,EAAC,iBAAiB,EAAC,qCAA4B;AActD,MAAM,IAAI,GAAG,CAAC,GAAmB,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,IAAI,CAAC;AAErE,SAAS,WAAW,CAAC,IAAU;IAC3B,OAAO,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,eAAe,CAAC,OAAoB,EAAE,GAAc;IACzD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/C,IAAI,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,KAAK,CAAC,CAAC;IACzC,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC;IACr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AK,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import type {Node, ResolvedPos} from 'prosemirror-model';\nimport {\n type Command,\n type NodeSelection,\n Selection,\n TextSelection as TextSel,\n TextSelection,\n type Transaction,\n} from 'prosemirror-state';\n\nimport {isCodeBlock, isNodeEmpty} from '../../../utils/nodes';\nimport {isNodeSelection, isTextSelection} from '../../../utils/selection';\nimport {GapCursorSelection, isGapCursorSelection} from '../Cursor/GapCursorSelection';\nimport {hideSelectionMenu} from '../SelectionContext';\n\nexport type Direction = 'before' | 'after';\ntype ArrowDirection = 'up' | 'right' | 'down' | 'left';\n\ntype TextSelectionFinder = (selection: TextSelection, dir: Direction) => ResolvedPos | null;\ntype NodeSelectionFinder = (selection: NodeSelection, dir: Direction) => ResolvedPos | null;\ntype GapCursorSelectionFinder = (\n selection: GapCursorSelection,\n dir: Direction,\n) => ResolvedPos | null;\n\ntype GapCursorMeta = {direction: Direction};\n\nconst isUp = (dir: ArrowDirection) => dir === 'left' || dir === 'up';\n\nfunction isTextblock(node: Node): boolean {\n return node.isTextblock && !isCodeBlock(node);\n}\n\nfunction isEdgeTextblock($cursor: ResolvedPos, dir: Direction): boolean {\n const index = $cursor.index($cursor.depth - 1);\n if (dir === 'before') return index === 0;\n if (dir === 'after') return index === $cursor.node($cursor.depth - 1).childCount - 1;\n return false;\n}\n\nexport const findNextFakeParaPosForGapCursorSelection: GapCursorSelectionFinder = ({$pos}, dir) => {\n if ($pos.pos !== $pos.start() && $pos.pos !== $pos.end()) return null;\n return findFakeParaPosClosestToPos($pos, $pos.depth, dir);\n};\n\nexport const findFakeParaPosForNodeSelection: NodeSelectionFinder = (selection, dir) => {\n const selectedNode = selection.node;\n if (selectedNode.isInline || isTextblock(selectedNode)) return null;\n\n const {$from} = selection;\n const index = $from.index();\n const parentNode = $from.parent;\n if (dir === 'before') {\n if (parentNode.firstChild === selectedNode || !isTextblock(parentNode.child(index - 1))) {\n return $from;\n }\n } else if (dir === 'after') {\n if (parentNode.lastChild === selectedNode || !isTextblock(parentNode.child(index + 1))) {\n return selection.$to;\n }\n }\n\n return null;\n};\n\nexport const findFakeParaPosForCodeBlock = ($cursor: ResolvedPos, dir: Direction) => {\n if (!isCodeBlock($cursor.parent)) return null;\n\n let foundPos = -1;\n const index = $cursor.index($cursor.depth - 1);\n const parent = $cursor.node($cursor.depth - 1);\n if (dir === 'before') {\n if (index === 0 || !isTextblock(parent.child(index - 1))) {\n foundPos = $cursor.before();\n }\n } else if (dir === 'after') {\n if (index === parent.childCount - 1 || !isTextblock(parent.child(index + 1))) {\n foundPos = $cursor.after();\n }\n }\n\n return foundPos !== -1 ? $cursor.doc.resolve(foundPos) : null;\n};\n\nexport const findFakeParaPosForTextSelection: TextSelectionFinder = (selection, dir) => {\n const $cursor = dir === 'before' ? selection.$from : selection.$to;\n if ($cursor.parent.isInline) return null;\n\n const $pos = findFakeParaPosForCodeBlock($cursor, dir);\n if ($pos) return $pos;\n\n if (!isEdgeTextblock($cursor, dir)) return null;\n\n return findFakeParaPosClosestToPos($cursor, $cursor.depth - 1, dir);\n};\n\nexport function findFakeParaPosClosestToPos(\n $pos: ResolvedPos,\n depth: number,\n dir: Direction,\n): ResolvedPos | null {\n depth++;\n while (--depth > 0) {\n const node = $pos.node(depth);\n const index = $pos.index(depth - 1);\n const parent = $pos.node(depth - 1);\n\n const isFirstChild = index === 0;\n const isLastChild = index === parent.childCount - 1;\n\n const isComplexChild =\n node.type.spec.complex === 'inner' || node.type.spec.complex === 'leaf';\n\n const disabledGapCursor = parent.type.spec.gapcursor === false;\n\n if (isComplexChild || disabledGapCursor) {\n if (dir === 'before' && isFirstChild) continue;\n if (dir === 'after' && isLastChild) continue;\n return null;\n }\n\n if (dir === 'before') {\n if (isFirstChild || !isTextblock(parent.child(index - 1))) {\n return $pos.doc.resolve($pos.before(depth));\n }\n } else if (dir === 'after') {\n if (isLastChild || !isTextblock(parent.child(index + 1))) {\n return $pos.doc.resolve($pos.after(depth));\n }\n }\n\n return null;\n }\n return null;\n}\n\nconst arrow =\n (dir: ArrowDirection): Command =>\n (state, dispatch, view) => {\n const {selection} = state;\n const direction: Direction = isUp(dir) ? 'before' : 'after';\n let $pos: ResolvedPos | null = null;\n\n if (isGapCursorSelection<GapCursorMeta>(selection)) {\n if (selection.meta?.direction !== direction) {\n return false;\n }\n\n // if gap selection is at start or end of doc\n if (dir === 'up' && selection.pos === 0) return true;\n if (dir === 'down' && selection.pos === state.doc.nodeSize - 2) return true;\n\n $pos = findNextFakeParaPosForGapCursorSelection(selection, direction);\n }\n\n if (isNodeSelection(selection)) {\n $pos = findFakeParaPosForNodeSelection(selection, direction);\n }\n\n if (isTextSelection(selection) && view?.endOfTextblock(dir)) {\n $pos = findFakeParaPosForTextSelection(selection, direction);\n }\n\n if ($pos) {\n dispatch?.(createFakeParagraph(state.tr, $pos, direction).scrollIntoView());\n return true;\n }\n\n return false;\n };\n\nexport function createFakeParagraph(\n tr: Transaction,\n $pos: ResolvedPos,\n direction: Direction,\n): Transaction {\n return tr.setSelection(new GapCursorSelection<GapCursorMeta>($pos, {meta: {direction}}));\n}\n\nexport const arrowLeft = arrow('left');\nexport const arrowDown = arrow('down');\nexport const arrowUp = arrow('up');\nexport const arrowRight = arrow('right');\n\nexport const backspace: Command = (state, dispatch) => {\n const sel = state.selection;\n if (isGapCursorSelection(sel)) {\n const newSel = Selection.findFrom(sel.$pos, -1);\n if (newSel) {\n dispatch?.(state.tr.setSelection(newSel).scrollIntoView());\n return true;\n }\n }\n return false;\n};\n\nfunction hasContentToSelect(node: Node): boolean {\n if (node.isTextblock) return node.content.size > 0;\n return !isNodeEmpty(node);\n}\n\nexport const selectAll: Command = (state, dispatch) => {\n const {selection} = state;\n const {$from, $to} = selection;\n const sharedDepth = $from.sharedDepth($to.pos);\n\n for (let depth = sharedDepth; depth > 0; depth--) {\n const node = $from.node(depth);\n const {spec} = node.type;\n\n if (spec.selectAll === false) continue;\n\n let mode: 'content' | 'node';\n if (spec.selectAll) mode = spec.selectAll;\n else if (node.isTextblock || spec.code) mode = 'content';\n else continue;\n\n if (!hasContentToSelect(node)) continue;\n\n if (mode === 'node') {\n const selAroundNode = TextSelection.create(\n state.doc,\n $from.before(depth),\n $from.after(depth),\n );\n\n if (selection.from <= selAroundNode.from && selection.to >= selAroundNode.to) continue;\n\n dispatch?.(hideSelectionMenu(state.tr.setSelection(selAroundNode)));\n return true;\n }\n\n const start = $from.start(depth);\n const end = start + node.content.size;\n\n const startCursor = Selection.findFrom(state.doc.resolve(start), 1);\n const endCursor = Selection.findFrom(state.doc.resolve(end), -1);\n\n if (\n startCursor &&\n endCursor &&\n selection.from <= startCursor.from &&\n selection.to >= endCursor.to\n )\n continue;\n\n dispatch?.(state.tr.setSelection(TextSel.create(state.doc, start, end)));\n return true;\n }\n\n return false;\n};\n"]}
@@ -3,6 +3,21 @@ import "./selection.css";
3
3
  export declare const selection: () => Plugin<any>;
4
4
  declare module 'prosemirror-model' {
5
5
  interface NodeSpec {
6
+ /**
7
+ * Whether clicking directly on this node creates a NodeSelection for it.
8
+ * Typically `true` for root complex nodes (tables, cuts, notes)
9
+ * and `false` for their inner parts and leaf elements.
10
+ */
6
11
  allowSelection?: boolean | undefined;
12
+ /**
13
+ * Controls how this node participates in hierarchical select-all (Cmd+A / Ctrl+A).
14
+ * Each press of select-all walks up the node tree and selects the nearest matching ancestor.
15
+ *
16
+ * - `'content'` — select the node's content (TextSelection over inner content range)
17
+ * - `'node'` — select the node itself (NodeSelection)
18
+ * - `false` — skip this node during select-all traversal
19
+ * - `undefined` — default: textblocks and code nodes select their content, others are skipped
20
+ */
21
+ selectAll?: false | 'node' | 'content' | undefined;
7
22
  }
8
23
  }
@@ -4,7 +4,7 @@ import { AllSelection, NodeSelection, Plugin, TextSelection, } from 'prosemirror
4
4
  import { Decoration, DecorationSet } from 'prosemirror-view';
5
5
  import { isSelectableNode } from "../../../utils/nodes.js";
6
6
  import { isNodeSelection } from "../../../utils/selection.js";
7
- import { arrowDown, arrowLeft, arrowRight, arrowUp, backspace } from "./commands.js";
7
+ import { arrowDown, arrowLeft, arrowRight, arrowUp, backspace, selectAll } from "./commands.js";
8
8
  import "./selection.css";
9
9
  export const selection = () => new Plugin({
10
10
  props: {
@@ -14,6 +14,7 @@ export const selection = () => new Plugin({
14
14
  ArrowUp: arrowUp,
15
15
  ArrowDown: arrowDown,
16
16
  Backspace: backspace,
17
+ 'Mod-a': selectAll,
17
18
  }),
18
19
  decorations(state) {
19
20
  return getDecorations(state.tr);
@@ -1 +1 @@
1
- {"version":3,"file":"selection.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Selection/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,OAAO,EACH,YAAY,EAEZ,aAAa,EACb,MAAM,EAEN,aAAa,GAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,UAAU,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAC,gBAAgB,EAAC,gCAA6B;AACtD,OAAO,EAAC,eAAe,EAAC,oCAAiC;AAEzD,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAC,sBAAmB;AAEhF,yBAA0B;AAE1B,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAC1B,IAAI,MAAM,CAAC;IACP,KAAK,EAAE;QACH,aAAa,EAAE,cAAc,CAAC;YAC1B,SAAS,EAAE,SAAS;YACpB,UAAU,EAAE,UAAU;YACtB,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,SAAS;YACpB,SAAS,EAAE,SAAS;SACvB,CAAC;QACF,WAAW,CAAC,KAAK;YACb,OAAO,cA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,eAAe,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;YAEjE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,KAAK,IAAI,eAAe,EAAE,CAAC;gBACjF,KAAK,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,GAAG,EAAC,CAAC,CAAC;gBAExB,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {selectParentNode} from 'prosemirror-commands';\nimport {keydownHandler} from 'prosemirror-keymap';\nimport type {Node} from 'prosemirror-model';\nimport {\n AllSelection,\n type Command,\n NodeSelection,\n Plugin,\n type Selection,\n TextSelection,\n type Transaction,\n} from 'prosemirror-state';\nimport {Decoration, DecorationSet, type EditorView} from 'prosemirror-view';\n\nimport {isSelectableNode} from '../../../utils/nodes';\nimport {isNodeSelection} from '../../../utils/selection';\n\nimport {arrowDown, arrowLeft, arrowRight, arrowUp, backspace} from './commands';\n\nimport './selection.scss';\n\nexport const selection = () =>\n new Plugin({\n props: {\n handleKeyDown: keydownHandler({\n ArrowLeft: arrowLeft,\n ArrowRight: arrowRight,\n ArrowUp: arrowUp,\n ArrowDown: arrowDown,\n Backspace: backspace,\n }),\n decorations(state) {\n return getDecorations(state.tr);\n },\n handleClickOn(view, _pos, node, nodePos, _event, direct) {\n if (direct && node.type.spec.allowSelection) {\n return selectNode(nodePos)(view.state, view.dispatch);\n }\n\n return false;\n },\n },\n view(view) {\n reselect(view);\n return {\n update(view) {\n reselect(view);\n },\n };\n },\n });\n\ndeclare module 'prosemirror-model' {\n interface NodeSpec {\n allowSelection?: boolean | undefined;\n }\n}\n\nconst reselect = (view: EditorView) => {\n const {selection: sel} = view.state;\n if (!sel.empty && isNodeSelection(sel) && !isSelectableNode(sel.node)) {\n return selectParentNode(view.state, view.dispatch);\n }\n return false;\n};\n\nconst selectNode =\n (pos: number): Command =>\n (state, dispatch) => {\n if (dispatch) {\n dispatch(state.tr.setSelection(new NodeSelection(state.doc.resolve(pos))));\n }\n return true;\n };\n\nconst getDecorations = (tr: Transaction): DecorationSet => {\n if (tr.selection instanceof NodeSelection) {\n return DecorationSet.create(tr.doc, [\n Decoration.node(tr.selection.from, tr.selection.to, {\n class: 'pm-node-selected',\n }),\n ]);\n }\n\n if (tr.selection instanceof TextSelection || tr.selection instanceof AllSelection) {\n const decorations = getTopLevelNodesFromSelection(tr.selection, tr.doc).map(\n ({node, pos}) => {\n return Decoration.node(pos, pos + node.nodeSize, {\n class: 'pm-node-selected',\n });\n },\n );\n return DecorationSet.create(tr.doc, decorations);\n }\n return DecorationSet.empty;\n};\n\nconst getTopLevelNodesFromSelection = (selection: Selection, doc: Node) => {\n const nodes: {node: Node; pos: number}[] = [];\n if (selection.from !== selection.to) {\n const {from, to} = selection;\n\n doc.nodesBetween(from, to, (node, pos) => {\n const withinSelection = from <= pos && pos + node.nodeSize <= to;\n\n if (node && !node.isText && node.type.spec.selectable !== false && withinSelection) {\n nodes.push({node, pos});\n\n return false;\n }\n\n return true;\n });\n }\n return nodes;\n};\n"]}
1
+ {"version":3,"file":"selection.js","sourceRoot":"../../../../../src","sources":["extensions/behavior/Selection/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAElD,OAAO,EACH,YAAY,EAEZ,aAAa,EACb,MAAM,EAEN,aAAa,GAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,UAAU,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAC,gBAAgB,EAAC,gCAA6B;AACtD,OAAO,EAAC,eAAe,EAAC,oCAA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,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,6BAA6B,GAAG,CAAC,SAAoB,EAAE,GAAS,EAAE,EAAE;IACtE,MAAM,KAAK,GAAgC,EAAE,CAAC;IAC9C,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,EAAC,IAAI,EAAE,EAAE,EAAC,GAAG,SAAS,CAAC;QAE7B,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACrC,MAAM,eAAe,GAAG,IAAI,IAAI,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;YAEjE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,KAAK,IAAI,eAAe,EAAE,CAAC;gBACjF,KAAK,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,GAAG,EAAC,CAAC,CAAC;gBAExB,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {selectParentNode} from 'prosemirror-commands';\nimport {keydownHandler} from 'prosemirror-keymap';\nimport type {Node} from 'prosemirror-model';\nimport {\n AllSelection,\n type Command,\n NodeSelection,\n Plugin,\n type Selection,\n TextSelection,\n type Transaction,\n} from 'prosemirror-state';\nimport {Decoration, DecorationSet, type EditorView} from 'prosemirror-view';\n\nimport {isSelectableNode} from '../../../utils/nodes';\nimport {isNodeSelection} from '../../../utils/selection';\n\nimport {arrowDown, arrowLeft, arrowRight, arrowUp, backspace, selectAll} from './commands';\n\nimport './selection.scss';\n\nexport const selection = () =>\n new Plugin({\n props: {\n handleKeyDown: keydownHandler({\n ArrowLeft: arrowLeft,\n ArrowRight: arrowRight,\n ArrowUp: arrowUp,\n ArrowDown: arrowDown,\n Backspace: backspace,\n 'Mod-a': selectAll,\n }),\n decorations(state) {\n return getDecorations(state.tr);\n },\n handleClickOn(view, _pos, node, nodePos, _event, direct) {\n if (direct && node.type.spec.allowSelection) {\n return selectNode(nodePos)(view.state, view.dispatch);\n }\n\n return false;\n },\n },\n view(view) {\n reselect(view);\n return {\n update(view) {\n reselect(view);\n },\n };\n },\n });\n\ndeclare module 'prosemirror-model' {\n interface NodeSpec {\n /**\n * Whether clicking directly on this node creates a NodeSelection for it.\n * Typically `true` for root complex nodes (tables, cuts, notes)\n * and `false` for their inner parts and leaf elements.\n */\n allowSelection?: boolean | undefined;\n /**\n * Controls how this node participates in hierarchical select-all (Cmd+A / Ctrl+A).\n * Each press of select-all walks up the node tree and selects the nearest matching ancestor.\n *\n * - `'content'` — select the node's content (TextSelection over inner content range)\n * - `'node'` — select the node itself (NodeSelection)\n * - `false` — skip this node during select-all traversal\n * - `undefined` — default: textblocks and code nodes select their content, others are skipped\n */\n selectAll?: false | 'node' | 'content' | undefined;\n }\n}\n\nconst reselect = (view: EditorView) => {\n const {selection: sel} = view.state;\n if (!sel.empty && isNodeSelection(sel) && !isSelectableNode(sel.node)) {\n return selectParentNode(view.state, view.dispatch);\n }\n return false;\n};\n\nconst selectNode =\n (pos: number): Command =>\n (state, dispatch) => {\n if (dispatch) {\n dispatch(state.tr.setSelection(new NodeSelection(state.doc.resolve(pos))));\n }\n return true;\n };\n\nconst getDecorations = (tr: Transaction): DecorationSet => {\n if (tr.selection instanceof NodeSelection) {\n return DecorationSet.create(tr.doc, [\n Decoration.node(tr.selection.from, tr.selection.to, {\n class: 'pm-node-selected',\n }),\n ]);\n }\n\n if (tr.selection instanceof TextSelection || tr.selection instanceof AllSelection) {\n const decorations = getTopLevelNodesFromSelection(tr.selection, tr.doc).map(\n ({node, pos}) => {\n return Decoration.node(pos, pos + node.nodeSize, {\n class: 'pm-node-selected',\n });\n },\n );\n return DecorationSet.create(tr.doc, decorations);\n }\n return DecorationSet.empty;\n};\n\nconst getTopLevelNodesFromSelection = (selection: Selection, doc: Node) => {\n const nodes: {node: Node; pos: number}[] = [];\n if (selection.from !== selection.to) {\n const {from, to} = selection;\n\n doc.nodesBetween(from, to, (node, pos) => {\n const withinSelection = from <= pos && pos + node.nodeSize <= to;\n\n if (node && !node.isText && node.type.spec.selectable !== false && withinSelection) {\n nodes.push({node, pos});\n\n return false;\n }\n\n return true;\n });\n }\n return nodes;\n};\n"]}
@@ -13,6 +13,7 @@ export const BlockquoteSpecs = (builder) => {
13
13
  return ['blockquote', 0];
14
14
  },
15
15
  selectable: true,
16
+ selectAll: 'node',
16
17
  },
17
18
  fromMd: { tokenSpec: { name: blockquoteNodeName, type: 'block' } },
18
19
  toMd: (state, node) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Blockquote/BlockquoteSpecs/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,oCAAiC;AAEzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAEtF,MAAM,CAAC,MAAM,eAAe,GAAkB,CAAC,OAAO,EAAE,EAAE;IACtD,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;QACvC,IAAI,EAAE;YACF,OAAO,EAAE,QAAQ;YACjB,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,CAAC,EAAC,GAAG,EAAE,YAAY,EAAC,CAAC;YAC/B,KAAK;gBACD,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;YAC7B,CAAC;YACD,UAAU,EAAE,IAAI;SACnB;QACD,MAAM,EAAE,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAC,EAAC;QAC9D,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAClB,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACvE,CAAC;KACJ,CAAC,CAAC,CAAC;AACR,CAAC,CAAC","sourcesContent":["import type {Node} from 'prosemirror-model';\n\nimport type {ExtensionAuto} from '../../../../core';\nimport {nodeTypeFactory} from '../../../../utils/schema';\n\nexport const blockquoteNodeName = 'blockquote';\nexport const blockquoteType = nodeTypeFactory(blockquoteNodeName);\nexport const isBlockqouteNode = (node: Node) => node.type.name === blockquoteNodeName;\n\nexport const BlockquoteSpecs: ExtensionAuto = (builder) => {\n builder.addNode(blockquoteNodeName, () => ({\n spec: {\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [{tag: 'blockquote'}],\n toDOM() {\n return ['blockquote', 0];\n },\n selectable: true,\n },\n fromMd: {tokenSpec: {name: blockquoteNodeName, type: 'block'}},\n toMd: (state, node) => {\n state.wrapBlock('> ', null, node, () => state.renderContent(node));\n },\n }));\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/Blockquote/BlockquoteSpecs/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,oCAAiC;AAEzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAEtF,MAAM,CAAC,MAAM,eAAe,GAAkB,CAAC,OAAO,EAAE,EAAE;IACtD,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;QACvC,IAAI,EAAE;YACF,OAAO,EAAE,QAAQ;YACjB,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,CAAC,EAAC,GAAG,EAAE,YAAY,EAAC,CAAC;YAC/B,KAAK;gBACD,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;YAC7B,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAC,SAAS,EAAE,EAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAC,EAAC;QAC9D,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAClB,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACvE,CAAC;KACJ,CAAC,CAAC,CAAC;AACR,CAAC,CAAC","sourcesContent":["import type {Node} from 'prosemirror-model';\n\nimport type {ExtensionAuto} from '../../../../core';\nimport {nodeTypeFactory} from '../../../../utils/schema';\n\nexport const blockquoteNodeName = 'blockquote';\nexport const blockquoteType = nodeTypeFactory(blockquoteNodeName);\nexport const isBlockqouteNode = (node: Node) => node.type.name === blockquoteNodeName;\n\nexport const BlockquoteSpecs: ExtensionAuto = (builder) => {\n builder.addNode(blockquoteNodeName, () => ({\n spec: {\n content: 'block+',\n group: 'block',\n defining: true,\n parseDOM: [{tag: 'blockquote'}],\n toDOM() {\n return ['blockquote', 0];\n },\n selectable: true,\n selectAll: 'node',\n },\n fromMd: {tokenSpec: {name: blockquoteNodeName, type: 'block'}},\n toMd: (state, node) => {\n state.wrapBlock('> ', null, node, () => state.renderContent(node));\n },\n }));\n};\n"]}
@@ -1,8 +1,8 @@
1
- import type { Options } from '@diplodoc/transform';
2
1
  import type { ExtensionAuto } from "../../../../core/index.js";
3
2
  import { type LineNumbersOptions } from "../CodeBlockSpecs/index.js";
3
+ import { type HighlightLangMap } from "./plugins/codeBlockLangsPlugin.js";
4
4
  import "./CodeBlockHighlight.css";
5
- export type HighlightLangMap = Options['highlightLangs'];
5
+ export type { HighlightLangMap };
6
6
  export type CodeBlockHighlightOptions = {
7
7
  lineWrapping?: {
8
8
  enabled?: boolean;
@@ -2,88 +2,42 @@ import { Plugin, PluginKey } from 'prosemirror-state';
2
2
  // @ts-ignore // TODO: fix cjs build
3
3
  import { findChildrenByType } from 'prosemirror-utils';
4
4
  import { Decoration, DecorationSet } from 'prosemirror-view';
5
- import { capitalize } from "../../../../lodash.js";
6
- import { globalLogger } from "../../../../logger.js";
7
5
  import { CodeBlockNodeAttr, codeBlockNodeName, codeBlockType, } from "../CodeBlockSpecs/index.js";
8
6
  import { CodeBlockNodeView } from "./CodeBlockNodeView.js";
9
7
  import { codeLangSelectTooltipViewCreator } from "./TooltipPlugin/index.js";
10
- import { PlainTextLang } from "./const.js";
8
+ import { codeBlockLangsPlugin, codeBlockLangsPluginKey, getCodeBlockLangsState, } from "./plugins/codeBlockLangsPlugin.js";
11
9
  import { codeBlockLineNumbersPlugin } from "./plugins/codeBlockLineNumbersPlugin.js";
12
10
  import { codeBlockLineWrappingPlugin } from "./plugins/codeBlockLineWrappingPlugin.js";
13
11
  import { processChangedCodeBlocks } from "./utils.js";
14
12
  import "./CodeBlockHighlight.css";
15
13
  const pluginKey = new PluginKey('code_block_highlight');
16
14
  export const CodeBlockHighlight = (builder, opts) => {
17
- let langs;
18
- let lowlight;
19
- let hljs;
20
- const loadModules = async () => {
21
- try {
22
- hljs = (await import('highlight.js/lib/core')).default;
23
- const low = await import('lowlight');
24
- const all = low.all;
25
- const create = low.createLowlight;
26
- langs = { ...all, ...opts.langs };
27
- lowlight = create(langs);
28
- return true;
29
- }
30
- catch (e) {
31
- globalLogger.info('Skip code_block highlighting');
32
- builder.logger.log('Skip code_block highlighting');
33
- return false;
34
- }
35
- };
36
15
  if (opts.lineWrapping?.enabled)
37
16
  builder.addPlugin(codeBlockLineWrappingPlugin);
38
17
  if (opts.lineNumbers?.enabled)
39
18
  builder.addPlugin(codeBlockLineNumbersPlugin);
19
+ builder.addPlugin(() => codeBlockLangsPlugin(opts.langs, builder.logger));
40
20
  builder.addPlugin(() => {
41
- let modulesLoaded = false;
42
- let view = null;
43
- // empty array by default, but is filled after loading modules
44
- const selectItems = [];
45
- const mapping = {};
46
21
  // TODO: add TAB key handler
47
22
  // TODO: Remove constant selection of block
48
23
  return new Plugin({
49
24
  key: pluginKey,
50
25
  state: {
51
- init: (_, state) => {
52
- loadModules().then((loaded) => {
53
- modulesLoaded = loaded;
54
- if (modulesLoaded) {
55
- for (const lang of Object.keys(langs)) {
56
- const defs = langs[lang](hljs);
57
- selectItems.push({
58
- value: lang,
59
- content: defs.name || capitalize(lang),
60
- });
61
- if (defs.aliases) {
62
- for (const alias of defs.aliases) {
63
- mapping[alias] = lang;
64
- }
65
- }
66
- }
67
- selectItems.sort(sortLangs);
68
- if (view && !view.isDestroyed) {
69
- view.dispatch(view.state.tr.setMeta(pluginKey, { modulesLoaded }));
70
- }
71
- }
72
- });
26
+ init: (_config, _state) => {
73
27
  const cache = new WeakMap();
74
- return {
75
- cache,
76
- decoSet: modulesLoaded
77
- ? DecorationSet.empty
78
- : getDecorations(state.doc, cache),
79
- };
28
+ return { cache, decoSet: DecorationSet.empty };
80
29
  },
81
- apply: (tr, { cache, decoSet }) => {
82
- if (!modulesLoaded) {
83
- return { cache, decoSet: DecorationSet.empty };
30
+ apply: (tr, { cache, decoSet }, _oldState, newState) => {
31
+ const langsUpdate = tr.getMeta(codeBlockLangsPluginKey);
32
+ if (langsUpdate?.loaded && langsUpdate.lowlight) {
33
+ return {
34
+ cache,
35
+ decoSet: getDecorations(tr.doc, cache, langsUpdate.lowlight),
36
+ };
84
37
  }
85
- if (tr.getMeta(pluginKey)?.modulesLoaded) {
86
- return { cache, decoSet: getDecorations(tr.doc, cache) };
38
+ const { lowlight } = getCodeBlockLangsState(newState);
39
+ if (!lowlight) {
40
+ return { cache, decoSet: DecorationSet.empty };
87
41
  }
88
42
  if (!tr.docChanged)
89
43
  return { cache, decoSet };
@@ -109,9 +63,8 @@ export const CodeBlockHighlight = (builder, opts) => {
109
63
  return { cache, decoSet };
110
64
  },
111
65
  },
112
- view: (v) => {
113
- view = v;
114
- return codeLangSelectTooltipViewCreator(view, selectItems, mapping, {
66
+ view: (view) => {
67
+ return codeLangSelectTooltipViewCreator(view, {
115
68
  showCodeWrapping: Boolean(opts.lineWrapping?.enabled),
116
69
  showLineNumbers: Boolean(opts.lineNumbers?.enabled),
117
70
  });
@@ -126,10 +79,7 @@ export const CodeBlockHighlight = (builder, opts) => {
126
79
  },
127
80
  });
128
81
  });
129
- function getDecorations(doc, cache) {
130
- if (!lowlight) {
131
- return DecorationSet.empty;
132
- }
82
+ function getDecorations(doc, cache, lowlight) {
133
83
  const decos = [];
134
84
  for (const { node, pos } of findChildrenByType(doc, codeBlockType(doc.type.schema), true)) {
135
85
  const lang = node.attrs[CodeBlockNodeAttr.Lang];
@@ -181,12 +131,4 @@ function collectNodes(nodes, className, result) {
181
131
  }
182
132
  }
183
133
  }
184
- function sortLangs(a, b) {
185
- // plaintext always goes first
186
- if (a.value === PlainTextLang)
187
- return -1;
188
- if (b.value === PlainTextLang)
189
- return 1;
190
- return 0;
191
- }
192
134
  //# sourceMappingURL=CodeBlockHighlight.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeBlockHighlight.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,M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AA2B;IAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAE,IAAI,CAAC,UAAU,CAAC,SAAsB,IAAI,EAAE,CAAC,CAAC;YAChF,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACvE,OAAO,EAAE,SAAS;aACrB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AACL,CAAC;AAED,SAAS,SAAS,CAAC,CAAiB,EAAE,CAAiB;IACnD,8BAA8B;IAC9B,IAAI,CAAC,CAAC,KAAK,KAAK,aAAa;QAAE,OAAO,CAAC,CAAC,CAAC;IACzC,IAAI,CAAC,CAAC,KAAK,KAAK,aAAa;QAAE,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC;AACb,CAAC","sourcesContent":["import type {Options} from '@diplodoc/transform';\n// importing only type, because lowlight and highlight.js is optional deps\nimport type HLJS from 'highlight.js/lib/core';\nimport type {createLowlight} from 'lowlight' with {'resolution-mode': 'import'};\nimport type {Node} from 'prosemirror-model';\nimport {Plugin, PluginKey} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildrenByType} from 'prosemirror-utils';\nimport {Decoration, DecorationSet, type EditorView} from 'prosemirror-view';\n\nimport type {ExtensionAuto} from '../../../../core';\nimport {capitalize} from '../../../../lodash';\nimport {globalLogger} from '../../../../logger';\nimport {\n CodeBlockNodeAttr,\n type LineNumbersOptions,\n codeBlockNodeName,\n codeBlockType,\n} from '../CodeBlockSpecs';\n\nimport {CodeBlockNodeView} from './CodeBlockNodeView';\nimport {codeLangSelectTooltipViewCreator} from './TooltipPlugin';\nimport {PlainTextLang} from './const';\nimport {codeBlockLineNumbersPlugin} from './plugins/codeBlockLineNumbersPlugin';\nimport {codeBlockLineWrappingPlugin} from './plugins/codeBlockLineWrappingPlugin';\nimport {processChangedCodeBlocks} from './utils';\n\nimport './CodeBlockHighlight.scss';\n\nexport type HighlightLangMap = Options['highlightLangs'];\n\ntype Lowlight = ReturnType<typeof createLowlight>;\ntype Root = ReturnType<Lowlight['highlight']>;\n\ntype LangSelectItem = {\n value: string;\n content: string;\n};\n\nconst pluginKey = new PluginKey<PluginState>('code_block_highlight');\n\n// Cache for parsed highlight results, using ProseMirror nodes as keys\ntype HighlightCache = WeakMap<Node, HighlightParsedTree>;\n\ntype HighlightParsedTree = {text: string; classes: readonly string[]}[];\n\ntype PluginState = {\n cache: HighlightCache;\n decoSet: DecorationSet;\n};\n\nexport type CodeBlockHighlightOptions = {\n lineWrapping?: {\n enabled?: boolean;\n };\n lineNumbers?: LineNumbersOptions;\n langs?: HighlightLangMap;\n};\n\nexport const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (builder, opts) => {\n let langs: NonNullable<HighlightLangMap>;\n let lowlight: Lowlight;\n let hljs: typeof HLJS;\n\n const loadModules = async () => {\n try {\n hljs = (await import('highlight.js/lib/core')).default;\n const low = await import('lowlight');\n\n const all: HighlightLangMap = low.all;\n const create: typeof createLowlight = low.createLowlight;\n langs = {...all, ...opts.langs};\n lowlight = create(langs);\n return true;\n } catch (e) {\n globalLogger.info('Skip code_block highlighting');\n builder.logger.log('Skip code_block highlighting');\n return false;\n }\n };\n\n if (opts.lineWrapping?.enabled) builder.addPlugin(codeBlockLineWrappingPlugin);\n if (opts.lineNumbers?.enabled) builder.addPlugin(codeBlockLineNumbersPlugin);\n\n builder.addPlugin(() => {\n let modulesLoaded = false;\n let view: EditorView | null = null;\n\n // empty array by default, but is filled after loading modules\n const selectItems: LangSelectItem[] = [];\n const mapping: Record<string, string> = {};\n\n // TODO: add TAB key handler\n // TODO: Remove constant selection of block\n return new Plugin<PluginState>({\n key: pluginKey,\n state: {\n init: (_, state) => {\n loadModules().then((loaded) => {\n modulesLoaded = loaded;\n\n if (modulesLoaded) {\n for (const lang of Object.keys(langs)) {\n const defs = langs[lang](hljs);\n selectItems.push({\n value: lang,\n content: defs.name || capitalize(lang),\n });\n if (defs.aliases) {\n for (const alias of defs.aliases) {\n mapping[alias] = lang;\n }\n }\n }\n\n selectItems.sort(sortLangs);\n\n if (view && !view.isDestroyed) {\n view.dispatch(view.state.tr.setMeta(pluginKey, {modulesLoaded}));\n }\n }\n });\n\n const cache: HighlightCache = new WeakMap();\n\n return {\n cache,\n decoSet: modulesLoaded\n ? DecorationSet.empty\n : getDecorations(state.doc, cache),\n };\n },\n apply: (tr, {cache, decoSet}) => {\n if (!modulesLoaded) {\n return {cache, decoSet: DecorationSet.empty};\n }\n\n if (tr.getMeta(pluginKey)?.modulesLoaded) {\n return {cache, decoSet: getDecorations(tr.doc, cache)};\n }\n\n if (!tr.docChanged) return {cache, decoSet};\n\n decoSet = processChangedCodeBlocks(tr, decoSet, (node, pos, decoSet) => {\n const lang: string | undefined = node.attrs[CodeBlockNodeAttr.Lang];\n\n if (!lang || !lowlight.registered(lang)) {\n return decoSet.remove(decoSet.find(pos, pos + node.nodeSize));\n }\n\n const cached = cache.get(node);\n if (cached) {\n // node is in cache, but decorations may be missing (for example, after undo)\n if (!decoSet.find(pos, pos + node.nodeSize).length) {\n return decoSet.add(tr.doc, renderTree(cached, pos + 1));\n }\n return decoSet;\n }\n\n decoSet = decoSet.remove(decoSet.find(pos, pos + node.nodeSize));\n const ast = lowlight.highlight(lang, node.textContent);\n const parsed = parseNodes(ast.children);\n cache.set(node, parsed);\n return decoSet.add(tr.doc, renderTree(parsed, pos + 1));\n });\n\n return {cache, decoSet};\n },\n },\n view: (v) => {\n view = v;\n return codeLangSelectTooltipViewCreator(view, selectItems, mapping, {\n showCodeWrapping: Boolean(opts.lineWrapping?.enabled),\n showLineNumbers: Boolean(opts.lineNumbers?.enabled),\n });\n },\n props: {\n decorations(state) {\n return pluginKey.getState(state)?.decoSet;\n },\n nodeViews: {\n [codeBlockNodeName]: CodeBlockNodeView.withOpts(opts),\n },\n },\n });\n });\n\n function getDecorations(doc: Node, cache: HighlightCache) {\n if (!lowlight) {\n return DecorationSet.empty;\n }\n\n const decos: Decoration[] = [];\n\n for (const {node, pos} of findChildrenByType(doc, codeBlockType(doc.type.schema), true)) {\n const lang: string | undefined = node.attrs[CodeBlockNodeAttr.Lang];\n if (!lang || !lowlight.registered(lang)) {\n continue;\n }\n\n // Try to get parsed result from cache using node as key\n let parsedNodes = cache.get(node);\n if (!parsedNodes) {\n // Compute, parse and cache using the node itself as key\n const nodes = lowlight.highlight(lang, node.textContent).children;\n parsedNodes = parseNodes(nodes);\n cache.set(node, parsedNodes);\n }\n\n decos.push(...renderTree(parsedNodes, pos + 1));\n }\n\n return DecorationSet.create(doc, decos);\n }\n};\n\nfunction renderTree(parsedNodes: HighlightParsedTree, from: number): Decoration[] {\n const decos: Decoration[] = [];\n\n for (const {text, classes} of parsedNodes) {\n const to = from + text.length;\n if (classes.length) {\n decos.push(\n Decoration.inline(from, to, {\n class: classes.join(' '),\n }),\n );\n }\n from = to;\n }\n\n return decos;\n}\n\nfunction parseNodes(\n nodes: Root['children'],\n className: readonly string[] = [],\n): HighlightParsedTree {\n const result: HighlightParsedTree = [];\n collectNodes(nodes, className, result);\n return result;\n}\n\nfunction collectNodes(\n nodes: Root['children'],\n className: readonly string[],\n result: HighlightParsedTree,\n): void {\n for (const node of nodes) {\n if (node.type === 'element') {\n const classes = className.concat((node.properties.className as string[]) ?? []);\n collectNodes(node.children, classes, result);\n } else {\n result.push({\n text: node.type === 'comment' || node.type === 'text' ? node.value : '',\n classes: className,\n });\n }\n }\n}\n\nfunction sortLangs(a: LangSelectItem, b: LangSelectItem): number {\n // plaintext always goes first\n if (a.value === PlainTextLang) return -1;\n if (b.value === PlainTextLang) return 1;\n return 0;\n}\n"]}
1
+ {"version":3,"file":"CodeBlockHighlight.js","sourceRoot":"../../../../../../src","sources":["extensions/markdown/CodeBlock/CodeBlockHighlight/CodeBlockHighlight.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACpD,oCAAoC;AACpC,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAI3D,OAAO,EACH,iBAAiB,EAEjB,iBAAiB,EACjB,aAAa,GAChB,mCAA0B;AAE3B,OAAO,EAAC,iBAAiB,EAAC,+BAA4B;AACtD,OAAO,EAAC,gCAAgC,EAAC,iCAAwB;AACjE,OAAO,EAIH,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACzB,0CAAuC;AACxC,OAAO,EAAC,0BAA0B,EAAC,gDAA6C;AAChF,OAAO,EAAC,2BAA2B,EAAC,iDAA8C;AAClF,OAAO,EAAC,wBAAwB,EAAC,mBAAgB;AAEjD,kCAAmC;AAInC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAc,sBAAsB,CAAC,CAAC;AAoBrE,MAAM,CAAC,MAAM,kBAAkB,GAA6C,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IAC1F,IAAI,IAAI,CAAC,YAAY,EAAE,OAAO;QAAE,OAAO,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAC/E,IAAI,IAAI,CAAC,WAAW,EAAE,OAAO;QAAE,OAAO,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAE7E,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1E,OAAO,CAAC,SAAS,CAAC,G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;YACJ,MAAM,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACvE,OAAO,EAAE,SAAS;aACrB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type {Node} from 'prosemirror-model';\nimport {Plugin, PluginKey} from 'prosemirror-state';\n// @ts-ignore // TODO: fix cjs build\nimport {findChildrenByType} from 'prosemirror-utils';\nimport {Decoration, DecorationSet} from 'prosemirror-view';\n\nimport type {ExtensionAuto} from '#core';\n\nimport {\n CodeBlockNodeAttr,\n type LineNumbersOptions,\n codeBlockNodeName,\n codeBlockType,\n} from '../CodeBlockSpecs';\n\nimport {CodeBlockNodeView} from './CodeBlockNodeView';\nimport {codeLangSelectTooltipViewCreator} from './TooltipPlugin';\nimport {\n type HighlightLangMap,\n type LLRoot,\n type Lowlight,\n codeBlockLangsPlugin,\n codeBlockLangsPluginKey,\n getCodeBlockLangsState,\n} from './plugins/codeBlockLangsPlugin';\nimport {codeBlockLineNumbersPlugin} from './plugins/codeBlockLineNumbersPlugin';\nimport {codeBlockLineWrappingPlugin} from './plugins/codeBlockLineWrappingPlugin';\nimport {processChangedCodeBlocks} from './utils';\n\nimport './CodeBlockHighlight.scss';\n\nexport type {HighlightLangMap};\n\nconst pluginKey = new PluginKey<PluginState>('code_block_highlight');\n\n// Cache for parsed highlight results, using ProseMirror nodes as keys\ntype HighlightCache = WeakMap<Node, HighlightParsedTree>;\n\ntype HighlightParsedTree = {text: string; classes: readonly string[]}[];\n\ntype PluginState = {\n cache: HighlightCache;\n decoSet: DecorationSet;\n};\n\nexport type CodeBlockHighlightOptions = {\n lineWrapping?: {\n enabled?: boolean;\n };\n lineNumbers?: LineNumbersOptions;\n langs?: HighlightLangMap;\n};\n\nexport const CodeBlockHighlight: ExtensionAuto<CodeBlockHighlightOptions> = (builder, opts) => {\n if (opts.lineWrapping?.enabled) builder.addPlugin(codeBlockLineWrappingPlugin);\n if (opts.lineNumbers?.enabled) builder.addPlugin(codeBlockLineNumbersPlugin);\n\n builder.addPlugin(() => codeBlockLangsPlugin(opts.langs, builder.logger));\n\n builder.addPlugin(() => {\n // TODO: add TAB key handler\n // TODO: Remove constant selection of block\n return new Plugin<PluginState>({\n key: pluginKey,\n state: {\n init: (_config, _state) => {\n const cache: HighlightCache = new WeakMap();\n return {cache, decoSet: DecorationSet.empty};\n },\n apply: (tr, {cache, decoSet}, _oldState, newState) => {\n const langsUpdate = tr.getMeta(codeBlockLangsPluginKey);\n if (langsUpdate?.loaded && langsUpdate.lowlight) {\n return {\n cache,\n decoSet: getDecorations(tr.doc, cache, langsUpdate.lowlight),\n };\n }\n\n const {lowlight} = getCodeBlockLangsState(newState);\n\n if (!lowlight) {\n return {cache, decoSet: DecorationSet.empty};\n }\n\n if (!tr.docChanged) return {cache, decoSet};\n\n decoSet = processChangedCodeBlocks(tr, decoSet, (node, pos, decoSet) => {\n const lang: string | undefined = node.attrs[CodeBlockNodeAttr.Lang];\n\n if (!lang || !lowlight.registered(lang)) {\n return decoSet.remove(decoSet.find(pos, pos + node.nodeSize));\n }\n\n const cached = cache.get(node);\n if (cached) {\n // node is in cache, but decorations may be missing (for example, after undo)\n if (!decoSet.find(pos, pos + node.nodeSize).length) {\n return decoSet.add(tr.doc, renderTree(cached, pos + 1));\n }\n return decoSet;\n }\n\n decoSet = decoSet.remove(decoSet.find(pos, pos + node.nodeSize));\n const ast = lowlight.highlight(lang, node.textContent);\n const parsed = parseNodes(ast.children);\n cache.set(node, parsed);\n return decoSet.add(tr.doc, renderTree(parsed, pos + 1));\n });\n\n return {cache, decoSet};\n },\n },\n view: (view) => {\n return codeLangSelectTooltipViewCreator(view, {\n showCodeWrapping: Boolean(opts.lineWrapping?.enabled),\n showLineNumbers: Boolean(opts.lineNumbers?.enabled),\n });\n },\n props: {\n decorations(state) {\n return pluginKey.getState(state)?.decoSet;\n },\n nodeViews: {\n [codeBlockNodeName]: CodeBlockNodeView.withOpts(opts),\n },\n },\n });\n });\n\n function getDecorations(doc: Node, cache: HighlightCache, lowlight: Lowlight) {\n const decos: Decoration[] = [];\n\n for (const {node, pos} of findChildrenByType(doc, codeBlockType(doc.type.schema), true)) {\n const lang: string | undefined = node.attrs[CodeBlockNodeAttr.Lang];\n if (!lang || !lowlight.registered(lang)) {\n continue;\n }\n\n // Try to get parsed result from cache using node as key\n let parsedNodes = cache.get(node);\n if (!parsedNodes) {\n // Compute, parse and cache using the node itself as key\n const nodes = lowlight.highlight(lang, node.textContent).children;\n parsedNodes = parseNodes(nodes);\n cache.set(node, parsedNodes);\n }\n\n decos.push(...renderTree(parsedNodes, pos + 1));\n }\n\n return DecorationSet.create(doc, decos);\n }\n};\n\nfunction renderTree(parsedNodes: HighlightParsedTree, from: number): Decoration[] {\n const decos: Decoration[] = [];\n\n for (const {text, classes} of parsedNodes) {\n const to = from + text.length;\n if (classes.length) {\n decos.push(\n Decoration.inline(from, to, {\n class: classes.join(' '),\n }),\n );\n }\n from = to;\n }\n\n return decos;\n}\n\nfunction parseNodes(\n nodes: LLRoot['children'],\n className: readonly string[] = [],\n): HighlightParsedTree {\n const result: HighlightParsedTree = [];\n collectNodes(nodes, className, result);\n return result;\n}\n\nfunction collectNodes(\n nodes: LLRoot['children'],\n className: readonly string[],\n result: HighlightParsedTree,\n): void {\n for (const node of nodes) {\n if (node.type === 'element') {\n const classes = className.concat((node.properties.className as string[]) ?? []);\n collectNodes(node.children, classes, result);\n } else {\n result.push({\n text: node.type === 'comment' || node.type === 'text' ? node.value : '',\n classes: className,\n });\n }\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { type SelectOption } from '@gravity-ui/uikit';
2
+ import type { Node } from "../../../../../pm/model.js";
3
+ import type { EditorView } from "../../../../../pm/view.js";
4
+ export type CodeBlockToolbarProps = {
5
+ node: Node;
6
+ pos: number;
7
+ editorView: EditorView;
8
+ langItems: SelectOption[];
9
+ mapping: Record<string, string>;
10
+ showCodeWrapping: boolean;
11
+ showLineNumbers: boolean;
12
+ rerenderTooltip?: () => void;
13
+ };
14
+ export declare function CodeBlockToolbar({ node, pos, editorView, langItems, mapping, showCodeWrapping, showLineNumbers, rerenderTooltip, }: CodeBlockToolbarProps): JSX.Element;
@@ -0,0 +1,114 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from 'react';
3
+ import { ListOl as LineNumbersIcon, TrashBin as RemoveIcon, ArrowUturnCwLeft as WrappingIcon, } from '@gravity-ui/icons';
4
+ import { ClipboardButton } from '@gravity-ui/uikit';
5
+ import { useLatest } from 'react-use';
6
+ import { cn } from "../../../../../classname.js";
7
+ import { i18n } from "../../../../../i18n/codeblock/index.js";
8
+ import { typedMemo } from "../../../../../react-utils/memo.js";
9
+ import { Toolbar, ToolbarDataType } from "../../../../../toolbar/index.js";
10
+ import { ToolbarWrapToContext } from "../../../../../toolbar/ToolbarRerender.js";
11
+ import { removeNode } from "../../../../../utils/remove-node.js";
12
+ import { isTruthy } from "../../../../../utils/truthy.js";
13
+ import { CodeBlockNodeAttr } from "../../CodeBlockSpecs/index.js";
14
+ import { isNodeHasLineWrapping } from "../plugins/codeBlockLineWrappingPlugin.js";
15
+ import { CodeLangSelect } from "./CodeLangSelect.js";
16
+ import { isLineNumbersVisible, toggleLineNumbers, toggleLineWrapping } from "./utils.js";
17
+ const bToolbar = cn('code-block-toolbar');
18
+ const ToolbarMemoized = typedMemo(Toolbar);
19
+ export function CodeBlockToolbar({ node, pos, editorView, langItems, mapping, showCodeWrapping, showLineNumbers, rerenderTooltip, }) {
20
+ const posRef = useLatest(pos);
21
+ const nodeRef = useLatest(node);
22
+ const onFocus = useCallback(() => {
23
+ editorView.focus();
24
+ }, [editorView]);
25
+ const toolbarData = useMemo(() => {
26
+ const copyText = () => nodeRef.current.textContent;
27
+ const focus = () => editorView.focus();
28
+ const onLangChange = (value) => {
29
+ editorView.dispatch(editorView.state.tr.setNodeAttribute(posRef.current, CodeBlockNodeAttr.Lang, value));
30
+ };
31
+ return [
32
+ [
33
+ langItems.length > 0 &&
34
+ {
35
+ id: 'code-block-type',
36
+ type: ToolbarDataType.ReactComponent,
37
+ component: () => (_jsx(CodeLangSelect, { focus: focus, onChange: onLangChange, lang: nodeRef.current.attrs[CodeBlockNodeAttr.Lang], selectItems: langItems, mapping: mapping })),
38
+ width: 28,
39
+ },
40
+ showCodeWrapping &&
41
+ {
42
+ id: 'code-block-wrapping',
43
+ icon: { data: WrappingIcon },
44
+ title: i18n('code_wrapping'),
45
+ type: ToolbarDataType.SingleButton,
46
+ isActive: (view) => isNodeHasLineWrapping(view.state, posRef.current),
47
+ isEnable: () => true,
48
+ exec: (view) => {
49
+ toggleLineWrapping({
50
+ pos: posRef.current,
51
+ node: nodeRef.current,
52
+ state: view.state,
53
+ dispatch: view.dispatch,
54
+ });
55
+ // forcing rerender because editor's toolbar isn't updated when the decorations change
56
+ rerenderTooltip?.();
57
+ },
58
+ },
59
+ showLineNumbers &&
60
+ {
61
+ id: 'code-block-linenumbers',
62
+ icon: { data: LineNumbersIcon },
63
+ title: i18n('show_line_numbers'),
64
+ type: ToolbarDataType.SingleButton,
65
+ isActive: () => isLineNumbersVisible(nodeRef.current),
66
+ isEnable: () => true,
67
+ exec: (view) => {
68
+ toggleLineNumbers({
69
+ pos: posRef.current,
70
+ node: nodeRef.current,
71
+ state: view.state,
72
+ dispatch: view.dispatch,
73
+ });
74
+ },
75
+ },
76
+ {
77
+ id: 'code-block-copy',
78
+ type: ToolbarDataType.ReactNodeFn,
79
+ width: 28,
80
+ content: () => _jsx(ClipboardButton, { text: copyText }),
81
+ noRerenderOnUpdate: true,
82
+ },
83
+ ].filter(isTruthy),
84
+ [
85
+ {
86
+ id: 'code-block-remove',
87
+ icon: { data: RemoveIcon },
88
+ title: i18n('remove'),
89
+ theme: 'danger',
90
+ type: ToolbarDataType.SingleButton,
91
+ isActive: () => false,
92
+ isEnable: () => true,
93
+ exec: (view) => removeNode({
94
+ pos: posRef.current,
95
+ node: nodeRef.current,
96
+ tr: view.state.tr,
97
+ dispatch: view.dispatch,
98
+ }),
99
+ },
100
+ ],
101
+ ];
102
+ }, [
103
+ editorView,
104
+ langItems,
105
+ mapping,
106
+ nodeRef,
107
+ posRef,
108
+ rerenderTooltip,
109
+ showCodeWrapping,
110
+ showLineNumbers,
111
+ ]);
112
+ return (_jsx(ToolbarWrapToContext, { editor: editorView, children: _jsx(ToolbarMemoized, { editor: editorView, focus: onFocus, className: bToolbar(), data: toolbarData }) }));
113
+ }
114
+ //# sourceMappingURL=CodeBlockToolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeBlockToolbar.js","sourceRoot":"../../../../../../../src","sources":["extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeBlockToolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAE3C,OAAO,EACH,MAAM,IAAI,eAAe,EACzB,QAAQ,IAAI,UAAU,EACtB,gBAAgB,IAAI,YAAY,GACnC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAC,EAAE,EAAC,oCAAsB;AACjC,OAAO,EAAC,IAAI,EAAC,+CAA2B;AACxC,OAAO,EAAC,SAAS,EAAC,2CAA6B;AAC/C,OAAO,EAAC,OAAO,EAAoB,eAAe,EAA4B,wCAAoB;AAClG,OAAO,EAAC,oBAAoB,EAAC,kDAAoC;AACjE,OAAO,EAAC,UAAU,EAAC,4CAA8B;AACjD,OAAO,EAAC,QAAQ,EAAC,uCAAyB;AAE1C,OAAO,EAAC,iBAAiB,EAAC,sCAA6B;AACvD,OAAO,EAAC,qBAAqB,EAAC,kDAA+C;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EAAE,WAAW,GACnB,GACiB,CAC1B,CAAC;AACN,CAAC","sourcesContent":["import {useCallback, useMemo} from 'react';\n\nimport {\n ListOl as LineNumbersIcon,\n TrashBin as RemoveIcon,\n ArrowUturnCwLeft as WrappingIcon,\n} from '@gravity-ui/icons';\nimport {ClipboardButton, type SelectOption} from '@gravity-ui/uikit';\nimport {useLatest} from 'react-use';\n\nimport type {Node} from '#pm/model';\nimport type {EditorView} from '#pm/view';\nimport {cn} from 'src/classname';\nimport {i18n} from 'src/i18n/codeblock';\nimport {typedMemo} from 'src/react-utils/memo';\nimport {Toolbar, type ToolbarData, ToolbarDataType, type ToolbarGroupItemData} from 'src/toolbar';\nimport {ToolbarWrapToContext} from 'src/toolbar/ToolbarRerender';\nimport {removeNode} from 'src/utils/remove-node';\nimport {isTruthy} from 'src/utils/truthy';\n\nimport {CodeBlockNodeAttr} from '../../CodeBlockSpecs';\nimport {isNodeHasLineWrapping} from '../plugins/codeBlockLineWrappingPlugin';\n\nimport {CodeLangSelect} from './CodeLangSelect';\nimport {isLineNumbersVisible, toggleLineNumbers, toggleLineWrapping} from './utils';\n\nconst bToolbar = cn('code-block-toolbar');\nconst ToolbarMemoized = typedMemo(Toolbar);\n\nexport type CodeBlockToolbarProps = {\n node: Node;\n pos: number;\n editorView: EditorView;\n langItems: SelectOption[];\n mapping: Record<string, string>;\n showCodeWrapping: boolean;\n showLineNumbers: boolean;\n rerenderTooltip?: () => void;\n};\n\nexport function CodeBlockToolbar({\n node,\n pos,\n editorView,\n langItems,\n mapping,\n showCodeWrapping,\n showLineNumbers,\n rerenderTooltip,\n}: CodeBlockToolbarProps) {\n const posRef = useLatest(pos);\n const nodeRef = useLatest(node);\n\n const onFocus = useCallback(() => {\n editorView.focus();\n }, [editorView]);\n\n const toolbarData = useMemo<ToolbarData<EditorView>>(() => {\n const copyText = () => nodeRef.current.textContent;\n const focus = () => editorView.focus();\n const onLangChange = (value: string) => {\n editorView.dispatch(\n editorView.state.tr.setNodeAttribute(posRef.current, CodeBlockNodeAttr.Lang, value),\n );\n };\n\n return [\n [\n langItems.length > 0 &&\n ({\n id: 'code-block-type',\n type: ToolbarDataType.ReactComponent,\n component: () => (\n <CodeLangSelect\n focus={focus}\n onChange={onLangChange}\n lang={nodeRef.current.attrs[CodeBlockNodeAttr.Lang]}\n selectItems={langItems}\n mapping={mapping}\n />\n ),\n width: 28,\n } satisfies ToolbarGroupItemData<EditorView>),\n showCodeWrapping &&\n ({\n id: 'code-block-wrapping',\n icon: {data: WrappingIcon},\n title: i18n('code_wrapping'),\n type: ToolbarDataType.SingleButton,\n isActive: (view) => isNodeHasLineWrapping(view.state, posRef.current),\n isEnable: () => true,\n exec: (view) => {\n toggleLineWrapping({\n pos: posRef.current,\n node: nodeRef.current,\n state: view.state,\n dispatch: view.dispatch,\n });\n // forcing rerender because editor's toolbar isn't updated when the decorations change\n rerenderTooltip?.();\n },\n } satisfies ToolbarGroupItemData<EditorView>),\n showLineNumbers &&\n ({\n id: 'code-block-linenumbers',\n icon: {data: LineNumbersIcon},\n title: i18n('show_line_numbers'),\n type: ToolbarDataType.SingleButton,\n isActive: () => isLineNumbersVisible(nodeRef.current),\n isEnable: () => true,\n exec: (view) => {\n toggleLineNumbers({\n pos: posRef.current,\n node: nodeRef.current,\n state: view.state,\n dispatch: view.dispatch,\n });\n },\n } satisfies ToolbarGroupItemData<EditorView>),\n {\n id: 'code-block-copy',\n type: ToolbarDataType.ReactNodeFn,\n width: 28,\n content: () => <ClipboardButton text={copyText} />,\n noRerenderOnUpdate: true,\n } satisfies ToolbarGroupItemData<EditorView>,\n ].filter(isTruthy),\n [\n {\n id: 'code-block-remove',\n icon: {data: RemoveIcon},\n title: i18n('remove'),\n theme: 'danger',\n type: ToolbarDataType.SingleButton,\n isActive: () => false,\n isEnable: () => true,\n exec: (view) =>\n removeNode({\n pos: posRef.current,\n node: nodeRef.current,\n tr: view.state.tr,\n dispatch: view.dispatch,\n }),\n },\n ],\n ];\n }, [\n editorView,\n langItems,\n mapping,\n nodeRef,\n posRef,\n rerenderTooltip,\n showCodeWrapping,\n showLineNumbers,\n ]);\n\n return (\n <ToolbarWrapToContext editor={editorView}>\n <ToolbarMemoized\n editor={editorView}\n focus={onFocus}\n className={bToolbar()}\n data={toolbarData}\n />\n </ToolbarWrapToContext>\n );\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { type SelectOption } from '@gravity-ui/uikit';
2
+ export type CodeLangSelectProps = {
3
+ lang: string;
4
+ selectItems: SelectOption[];
5
+ mapping: Record<string, string>;
6
+ focus: () => void;
7
+ onChange: (value: string) => void;
8
+ };
9
+ export declare const CodeLangSelect: React.FC<CodeLangSelectProps>;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Select } from '@gravity-ui/uikit';
4
+ import { cn } from "../../../../../classname.js";
5
+ import { i18n } from "../../../../../i18n/codeblock/index.js";
6
+ import { i18n as i18nPlaceholder } from "../../../../../i18n/placeholder/index.js";
7
+ import { PlainTextLang } from "../const.js";
8
+ const bCodeBlock = cn('code-block');
9
+ export const CodeLangSelect = memo(function CodeLangSelect({ lang, focus, onChange, selectItems, mapping }) {
10
+ const value = mapping[lang] || lang || PlainTextLang;
11
+ const handleClick = (type) => {
12
+ focus();
13
+ if (type === value)
14
+ return;
15
+ onChange(type);
16
+ };
17
+ return (_jsx(Select, { size: "m", width: "max", disablePortal: true, value: [value], onUpdate: (v) => handleClick(v[0]), options: selectItems, filterable: true, filterPlaceholder: i18nPlaceholder('select_filter'), popupClassName: bCodeBlock('select-popup'), className: bCodeBlock('select-button'), renderEmptyOptions: () => (_jsx("div", { className: bCodeBlock('select-empty'), children: i18n('empty_option') })) }));
18
+ });
19
+ //# sourceMappingURL=CodeLangSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeLangSelect.js","sourceRoot":"../../../../../../../src","sources":["extensions/markdown/CodeBlock/CodeBlockHighlight/TooltipPlugin/CodeLangSelect.ts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GAGH,CACL,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import {memo} from 'react';\n\nimport {Select, type SelectOption} from '@gravity-ui/uikit';\n\nimport {cn} from 'src/classname';\nimport {i18n} from 'src/i18n/codeblock';\nimport {i18n as i18nPlaceholder} from 'src/i18n/placeholder';\n\nimport {PlainTextLang} from '../const';\n\nconst bCodeBlock = cn('code-block');\n\nexport type CodeLangSelectProps = {\n lang: string;\n selectItems: SelectOption[];\n mapping: Record<string, string>;\n focus: () => void;\n onChange: (value: string) => void;\n};\n\nexport const CodeLangSelect: React.FC<CodeLangSelectProps> = memo<CodeLangSelectProps>(\n function CodeLangSelect({lang, focus, onChange, selectItems, mapping}) {\n const value = mapping[lang] || lang || PlainTextLang;\n\n const handleClick = (type: string) => {\n focus();\n if (type === value) return;\n onChange(type);\n };\n\n return (\n <Select\n size=\"m\"\n width=\"max\"\n disablePortal\n value={[value]}\n onUpdate={(v) => handleClick(v[0])}\n options={selectItems}\n filterable\n filterPlaceholder={i18nPlaceholder('select_filter')}\n popupClassName={bCodeBlock('select-popup')}\n className={bCodeBlock('select-button')}\n renderEmptyOptions={() => (\n <div className={bCodeBlock('select-empty')}>{i18n('empty_option')}</div>\n )}\n // TODO: in onOpenChange return focus to view.dom after press Esc in Select\n // after https://github.com/gravity-ui/uikit/issues/2075\n />\n );\n },\n);\n"]}
@@ -1,10 +1,9 @@
1
- import { type SelectOption } from '@gravity-ui/uikit';
2
- import type { EditorView } from 'prosemirror-view';
1
+ import type { EditorView } from "../../../../../pm/view.js";
3
2
  import { BaseTooltipPluginView } from "../../../../../plugins/BaseTooltip/index.js";
4
3
  import "./TooltipView.css";
5
4
  type Options = {
6
5
  showCodeWrapping: boolean;
7
6
  showLineNumbers: boolean;
8
7
  };
9
- export declare const codeLangSelectTooltipViewCreator: (view: EditorView, langItems: SelectOption[], mapping: Record<string, string> | undefined, { showCodeWrapping, showLineNumbers }: Options) => BaseTooltipPluginView;
8
+ export declare const codeLangSelectTooltipViewCreator: (view: EditorView, { showCodeWrapping, showLineNumbers }: Options) => BaseTooltipPluginView;
10
9
  export {};