@onereach/ui-components 4.3.12 → 4.4.0-beta.2673.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 (419) hide show
  1. package/dist/bundled/v2/components/OrCode/OrCode.js +6 -3792
  2. package/dist/bundled/v2/components/OrCode/index.js +6 -2
  3. package/dist/bundled/v2/components/OrCode/lang.js +3941 -3
  4. package/dist/bundled/v2/components/OrCode/theme.js +2 -1
  5. package/dist/bundled/v2/components/OrConfirm/OrConfirm.js +2 -1
  6. package/dist/bundled/v2/components/OrConfirm/index.js +2 -1
  7. package/dist/bundled/v2/components/OrConfirmV3/OrConfirm.js +1 -1
  8. package/dist/bundled/v2/components/OrConfirmV3/index.js +1 -1
  9. package/dist/bundled/v2/components/OrModal/OrModal.js +3 -1346
  10. package/dist/bundled/v2/components/OrModal/index.js +1 -0
  11. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.js +2136 -0
  12. package/dist/bundled/v2/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +209 -0
  13. package/dist/bundled/v2/components/OrRichTextEditorV3/index.d.ts +1 -0
  14. package/dist/bundled/v2/components/OrRichTextEditorV3/index.js +69 -0
  15. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.d.ts +6 -0
  16. package/dist/bundled/v2/components/OrRichTextEditorV3/styles.js +38 -0
  17. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.d.ts +3 -0
  18. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +46 -0
  19. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.d.ts +27 -0
  20. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +184 -0
  21. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/index.d.ts +1 -0
  22. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/index.js +5 -0
  23. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/theme.d.ts +24 -0
  24. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/theme.js +190 -0
  25. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/types.d.ts +19 -0
  26. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/codemirror/types.js +1 -0
  27. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/markdown.d.ts +3 -0
  28. package/dist/bundled/v2/components/OrRichTextEditorV3/utils/markdown.js +5 -0
  29. package/dist/bundled/v2/components/OrSelectV3/OrSelect.js +1 -2
  30. package/dist/bundled/v2/components/OrTextV3/OrText.vue.d.ts +2 -2
  31. package/dist/bundled/v2/components/OrTextarea/OrTextarea.vue.d.ts +2 -2
  32. package/dist/bundled/v2/components/OrTextareaV3/OrTextarea.vue.d.ts +2 -2
  33. package/dist/bundled/v2/components/OrTextbox/OrTextbox.vue.d.ts +2 -2
  34. package/dist/bundled/v2/components/OrTimePickerV3/OrTimePicker.vue.d.ts +2 -2
  35. package/dist/bundled/v2/components/OrToast/OrToast.vue.d.ts +2 -2
  36. package/dist/bundled/v2/components/OrToastV3/OrToast.vue.d.ts +2 -2
  37. package/dist/bundled/v2/components/OrTooltip/OrTooltip.vue.d.ts +2 -2
  38. package/dist/bundled/v2/components/OrTooltipV3/OrTooltip.vue.d.ts +2 -2
  39. package/dist/bundled/v2/components/index.d.ts +1 -0
  40. package/dist/bundled/v2/components/index.js +16 -3
  41. package/dist/bundled/{v3/index-cf2c3c27.js → v2/index-0d224ae5.js} +3 -115
  42. package/dist/bundled/v2/index-1182caa8.js +9633 -0
  43. package/dist/bundled/v2/index-85c2efe8.js +7122 -0
  44. package/dist/bundled/{v3/OrCode.vue_vue_type_script_lang-74060519.js → v2/index-d92d0b48.js} +14 -235
  45. package/dist/bundled/{v3/lang-0fb8f78b.js → v2/index-e9f6b2d8.js} +73 -4009
  46. package/dist/bundled/v2/index.es-3f39f316.js +115 -0
  47. package/dist/bundled/v2/index.js +19 -6
  48. package/dist/bundled/v2/markdown-d704b3a8.js +17975 -0
  49. package/dist/bundled/{v3/OrModal.vue_vue_type_script_lang-ae842e5b.js → v2/useFocusTrap-48767a70.js} +3 -106
  50. package/dist/bundled/v3/OrCode.vue_vue_type_script_lang-7e29b3d0.js +237 -0
  51. package/dist/bundled/v3/{OrConfirm.vue_vue_type_script_lang-e5a8f92a.js → OrConfirm.vue_vue_type_script_lang-4eaa8470.js} +2 -2
  52. package/dist/bundled/v3/{OrConfirm.vue_vue_type_script_lang-23e4ce08.js → OrConfirm.vue_vue_type_script_lang-dca252a7.js} +1 -1
  53. package/dist/bundled/v3/OrModal.vue_vue_type_script_lang-2c009ee0.js +108 -0
  54. package/dist/bundled/v3/OrRichTextEditor.vue_vue_type_script_lang-55afeb38.js +1861 -0
  55. package/dist/bundled/v3/components/OrAvatar/OrAvatar.vue.d.ts +26 -11
  56. package/dist/bundled/v3/components/OrAvatarV3/OrAvatar.vue.d.ts +24 -8
  57. package/dist/bundled/v3/components/OrBottomSheetV3/OrBottomSheet.vue.d.ts +33 -20
  58. package/dist/bundled/v3/components/OrButton/OrButton.vue.d.ts +51 -16
  59. package/dist/bundled/v3/components/OrButtonV2/OrButton.vue.d.ts +57 -20
  60. package/dist/bundled/v3/components/OrButtonV3/OrButton.vue.d.ts +35 -15
  61. package/dist/bundled/v3/components/OrCard/OrCard.vue.d.ts +15 -7
  62. package/dist/bundled/v3/components/OrCardCollection/OrCardCollection.vue.d.ts +47 -21
  63. package/dist/bundled/v3/components/OrCardCollectionV3/OrCardCollection.vue.d.ts +70 -22
  64. package/dist/bundled/v3/components/OrCardV3/OrCard.vue.d.ts +7 -4
  65. package/dist/bundled/v3/components/OrCarousel/OrCarousel.vue.d.ts +676 -126
  66. package/dist/bundled/v3/components/OrCarouselItem/OrCarouselItem.vue.d.ts +1 -1
  67. package/dist/bundled/v3/components/OrCheckbox/OrCheckbox.vue.d.ts +35 -15
  68. package/dist/bundled/v3/components/OrCheckboxGroupV3/OrCheckboxGroup.vue.d.ts +24 -6
  69. package/dist/bundled/v3/components/OrCheckboxTreeV3/OrCheckboxTree.vue.d.ts +43 -17
  70. package/dist/bundled/v3/components/OrCheckboxV3/OrCheckbox.vue.d.ts +53 -23
  71. package/dist/bundled/v3/components/OrChip/OrChip.vue.d.ts +25 -9
  72. package/dist/bundled/v3/components/OrChips/OrChips.vue.d.ts +51 -24
  73. package/dist/bundled/v3/components/OrCode/OrCode.js +10 -6
  74. package/dist/bundled/v3/components/OrCode/OrCode.vue.d.ts +69 -24
  75. package/dist/bundled/v3/components/OrCode/index.js +8 -4
  76. package/dist/bundled/v3/components/OrCode/lang.js +3941 -3
  77. package/dist/bundled/v3/components/OrCode/theme.js +2 -1
  78. package/dist/bundled/v3/components/OrCollapse/OrCollapse.vue.d.ts +39 -17
  79. package/dist/bundled/v3/components/OrColorPicker/OrColorPicker.vue.d.ts +31 -13
  80. package/dist/bundled/v3/components/OrCombinedInputV3/OrCombinedInput.vue.d.ts +30 -8
  81. package/dist/bundled/v3/components/OrConfirm/OrConfirm.js +5 -4
  82. package/dist/bundled/v3/components/OrConfirm/OrConfirm.vue.d.ts +84 -23
  83. package/dist/bundled/v3/components/OrConfirm/index.js +4 -3
  84. package/dist/bundled/v3/components/OrConfirmV3/OrConfirm.js +3 -3
  85. package/dist/bundled/v3/components/OrConfirmV3/OrConfirm.vue.d.ts +91 -29
  86. package/dist/bundled/v3/components/OrConfirmV3/index.js +2 -2
  87. package/dist/bundled/v3/components/OrDatePickerV3/OrDatePicker.vue.d.ts +81 -25
  88. package/dist/bundled/v3/components/OrDateTimePicker/OrDateTimePicker.vue.d.ts +177 -68
  89. package/dist/bundled/v3/components/OrDateTimePickerV3/OrDateTimePicker.vue.d.ts +105 -31
  90. package/dist/bundled/v3/components/OrEmptyStateV3/OrEmptyState.vue.d.ts +28 -11
  91. package/dist/bundled/v3/components/OrError/OrError.vue.d.ts +8 -4
  92. package/dist/bundled/v3/components/OrErrorTagV3/OrErrorTag.vue.d.ts +7 -4
  93. package/dist/bundled/v3/components/OrErrorV3/OrError.vue.d.ts +18 -9
  94. package/dist/bundled/v3/components/OrExpansionPanelV3/OrExpansionPanel.vue.d.ts +35 -14
  95. package/dist/bundled/v3/components/OrFabV3/OrFab.vue.d.ts +20 -8
  96. package/dist/bundled/v3/components/OrFloating/OrFloating.vue.d.ts +46 -15
  97. package/dist/bundled/v3/components/OrFormGroupV3/OrFormGroup.vue.d.ts +30 -10
  98. package/dist/bundled/v3/components/OrHint/OrHint.vue.d.ts +8 -4
  99. package/dist/bundled/v3/components/OrHintV3/OrHint.vue.d.ts +18 -9
  100. package/dist/bundled/v3/components/OrIcon/OrIcon.vue.d.ts +44 -16
  101. package/dist/bundled/v3/components/OrIconButtonV2/OrIconButton.vue.d.ts +43 -13
  102. package/dist/bundled/v3/components/OrIconButtonV3/OrIconButton.vue.d.ts +52 -16
  103. package/dist/bundled/v3/components/OrIconV3/OrIcon.vue.d.ts +18 -7
  104. package/dist/bundled/v3/components/OrInlineInputBoxV3/OrInlineInputBox.vue.d.ts +16 -7
  105. package/dist/bundled/v3/components/OrInlineInputV3/OrInlineInput.vue.d.ts +83 -39
  106. package/dist/bundled/v3/components/OrInlineTextEdit/OrInlineTextEdit.vue.d.ts +95 -43
  107. package/dist/bundled/v3/components/OrInlineTextareaV3/OrInlineTextarea.vue.d.ts +79 -39
  108. package/dist/bundled/v3/components/OrInput/OrInput.vue.d.ts +87 -36
  109. package/dist/bundled/v3/components/OrInputBoxV3/OrInputBox.vue.d.ts +22 -7
  110. package/dist/bundled/v3/components/OrInputV3/OrInput.vue.d.ts +85 -34
  111. package/dist/bundled/v3/components/OrLabel/OrLabel.vue.d.ts +20 -9
  112. package/dist/bundled/v3/components/OrLabelV3/OrLabel.vue.d.ts +24 -9
  113. package/dist/bundled/v3/components/OrLinkV3/OrLink.vue.d.ts +24 -7
  114. package/dist/bundled/v3/components/OrList/OrList.vue.d.ts +47 -21
  115. package/dist/bundled/v3/components/OrListOfInputs/OrListOfInputs.vue.d.ts +27 -11
  116. package/dist/bundled/v3/components/OrLoader/OrLoader.vue.d.ts +26 -10
  117. package/dist/bundled/v3/components/OrLoaderV3/OrLoader.vue.d.ts +34 -13
  118. package/dist/bundled/v3/components/OrMenuItemV3/OrMenuItem.vue.d.ts +34 -13
  119. package/dist/bundled/v3/components/OrMenuV3/OrMenu.vue.d.ts +43 -16
  120. package/dist/bundled/v3/components/OrModal/OrModal.js +3 -2
  121. package/dist/bundled/v3/components/OrModal/OrModal.vue.d.ts +38 -14
  122. package/dist/bundled/v3/components/OrModal/index.js +2 -1
  123. package/dist/bundled/v3/components/OrModalV3/OrModal.vue.d.ts +31 -15
  124. package/dist/bundled/v3/components/OrNotification/OrNotification.vue.d.ts +27 -9
  125. package/dist/bundled/v3/components/OrNotificationV3/OrNotification.vue.d.ts +20 -9
  126. package/dist/bundled/v3/components/OrNumberInput/OrNumberInput.vue.d.ts +70 -24
  127. package/dist/bundled/v3/components/OrOverflowMenu/OrOverflowMenu.vue.d.ts +31 -13
  128. package/dist/bundled/v3/components/OrOverlay/OrOverlay.vue.d.ts +16 -6
  129. package/dist/bundled/v3/components/OrOverlayV3/OrOverlay.vue.d.ts +14 -7
  130. package/dist/bundled/v3/components/OrPaginationV3/OrPagination.vue.d.ts +75 -27
  131. package/dist/bundled/v3/components/OrPassword/OrPassword.vue.d.ts +63 -22
  132. package/dist/bundled/v3/components/OrPopoverV3/OrPopover.vue.d.ts +74 -27
  133. package/dist/bundled/v3/components/OrProgress/OrProgress.vue.d.ts +56 -20
  134. package/dist/bundled/v3/components/OrProgressV3/OrProgress.vue.d.ts +62 -25
  135. package/dist/bundled/v3/components/OrRadio/OrRadio.vue.d.ts +35 -13
  136. package/dist/bundled/v3/components/OrRadioGroup/OrRadioGroup.vue.d.ts +26 -9
  137. package/dist/bundled/v3/components/OrRadioGroupV3/OrRadioGroup.vue.d.ts +32 -6
  138. package/dist/bundled/v3/components/OrRadioV3/OrRadio.vue.d.ts +49 -21
  139. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.js +273 -0
  140. package/dist/bundled/v3/components/OrRichTextEditorV3/OrRichTextEditor.vue.d.ts +209 -0
  141. package/dist/bundled/v3/components/OrRichTextEditorV3/index.d.ts +1 -0
  142. package/dist/bundled/v3/components/OrRichTextEditorV3/index.js +85 -0
  143. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.d.ts +6 -0
  144. package/dist/bundled/v3/components/OrRichTextEditorV3/styles.js +38 -0
  145. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.d.ts +3 -0
  146. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorNode.js +46 -0
  147. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.d.ts +27 -0
  148. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/codemirrorView.js +184 -0
  149. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/index.d.ts +1 -0
  150. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/index.js +5 -0
  151. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/theme.d.ts +24 -0
  152. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/theme.js +190 -0
  153. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/types.d.ts +19 -0
  154. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/codemirror/types.js +1 -0
  155. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/markdown.d.ts +3 -0
  156. package/dist/bundled/v3/components/OrRichTextEditorV3/utils/markdown.js +5 -0
  157. package/dist/bundled/v3/components/OrSearch/OrSearch.vue.d.ts +65 -23
  158. package/dist/bundled/v3/components/OrSearchV3/OrSearch.vue.d.ts +41 -17
  159. package/dist/bundled/v3/components/OrSegmentedControlV3/OrSegmentedControl.vue.d.ts +25 -9
  160. package/dist/bundled/v3/components/OrSelect/OrSelect.vue.d.ts +77 -28
  161. package/dist/bundled/v3/components/OrSelectV3/OrSelect.js +1 -2
  162. package/dist/bundled/v3/components/OrSelectV3/OrSelect.vue.d.ts +115 -37
  163. package/dist/bundled/v3/components/OrSidebar/OrSidebar.vue.d.ts +33 -14
  164. package/dist/bundled/v3/components/OrSidebarV3/OrSidebar.vue.d.ts +63 -28
  165. package/dist/bundled/v3/components/OrSkeletonCircle/OrSkeletonCircle.vue.d.ts +20 -9
  166. package/dist/bundled/v3/components/OrSkeletonCircleV3/OrSkeletonCircle.vue.d.ts +28 -13
  167. package/dist/bundled/v3/components/OrSkeletonRect/OrSkeletonRect.vue.d.ts +22 -9
  168. package/dist/bundled/v3/components/OrSkeletonRectV3/OrSkeletonRect.vue.d.ts +26 -11
  169. package/dist/bundled/v3/components/OrSkeletonText/OrSkeletonText.vue.d.ts +26 -10
  170. package/dist/bundled/v3/components/OrSkeletonTextV3/OrSkeletonText.vue.d.ts +40 -16
  171. package/dist/bundled/v3/components/OrSlider/OrSlider.vue.d.ts +91 -35
  172. package/dist/bundled/v3/components/OrSortHeaderV3/OrSortHeader.vue.d.ts +25 -13
  173. package/dist/bundled/v3/components/OrStepper/OrStepper.vue.d.ts +43 -16
  174. package/dist/bundled/v3/components/OrSwitch/OrSwitch.vue.d.ts +33 -12
  175. package/dist/bundled/v3/components/OrSwitchV3/OrSwitch.vue.d.ts +53 -22
  176. package/dist/bundled/v3/components/OrTab/OrTab.vue.d.ts +22 -9
  177. package/dist/bundled/v3/components/OrTabHeaderItem/OrTabHeaderItem.vue.d.ts +29 -13
  178. package/dist/bundled/v3/components/OrTabV3/OrTab.vue.d.ts +17 -10
  179. package/dist/bundled/v3/components/OrTabs/OrTabs.vue.d.ts +17 -4
  180. package/dist/bundled/v3/components/OrTabsV3/OrTabs.vue.d.ts +69 -24
  181. package/dist/bundled/v3/components/OrTag/OrTag.vue.d.ts +27 -10
  182. package/dist/bundled/v3/components/OrTagV3/OrTag.vue.d.ts +23 -12
  183. package/dist/bundled/v3/components/OrTeleport/OrTeleport.vue3.vue.d.ts +10 -4
  184. package/dist/bundled/v3/components/OrTeleportV3/OrTeleport.vue3.vue.d.ts +10 -4
  185. package/dist/bundled/v3/components/OrTextV3/OrText.vue.d.ts +24 -11
  186. package/dist/bundled/v3/components/OrTextarea/OrTextarea.vue.d.ts +85 -37
  187. package/dist/bundled/v3/components/OrTextareaV3/OrTextarea.vue.d.ts +73 -32
  188. package/dist/bundled/v3/components/OrTextbox/OrTextbox.vue.d.ts +137 -55
  189. package/dist/bundled/v3/components/OrTimePickerV3/OrTimePicker.vue.d.ts +79 -25
  190. package/dist/bundled/v3/components/OrToast/OrToast.vue.d.ts +31 -11
  191. package/dist/bundled/v3/components/OrToastContainer/OrToastContainer.vue.d.ts +55 -25
  192. package/dist/bundled/v3/components/OrToastContainerV3/OrToastContainer.vue.d.ts +54 -24
  193. package/dist/bundled/v3/components/OrToastV3/OrToast.vue.d.ts +38 -16
  194. package/dist/bundled/v3/components/OrTooltip/OrTooltip.vue.d.ts +33 -14
  195. package/dist/bundled/v3/components/OrTooltipContent/OrTooltipContent.vue.d.ts +10 -4
  196. package/dist/bundled/v3/components/OrTooltipV3/OrTooltip.vue.d.ts +37 -13
  197. package/dist/bundled/v3/components/index.d.ts +1 -0
  198. package/dist/bundled/v3/components/index.js +21 -7
  199. package/dist/bundled/v3/directives/dropdown-close.d.ts +1 -3
  200. package/dist/bundled/v3/directives/dropdown-open.d.ts +1 -3
  201. package/dist/bundled/v3/hooks/useResponsive/useResponsive.d.ts +2 -2
  202. package/dist/bundled/{v2/index-cf2c3c27.js → v3/index-0d224ae5.js} +3 -115
  203. package/dist/bundled/v3/index-1182caa8.js +9633 -0
  204. package/dist/bundled/v3/index-85c2efe8.js +7122 -0
  205. package/dist/bundled/v3/index-d92d0b48.js +3805 -0
  206. package/dist/bundled/{v2/lang-0fb8f78b.js → v3/index-e9f6b2d8.js} +73 -4009
  207. package/dist/bundled/v3/index.es-3f39f316.js +115 -0
  208. package/dist/bundled/v3/index.js +25 -11
  209. package/dist/bundled/v3/markdown-d704b3a8.js +17975 -0
  210. package/dist/bundled/v3/useFocusTrap-48767a70.js +1348 -0
  211. package/dist/esm/v2/OrRichTextEditor-3a078ea0.js +849 -0
  212. package/dist/esm/v2/{OrSelect-9d6b3363.js → OrSelect-9c8f96b2.js} +1 -2
  213. package/dist/esm/v2/codemirrorView-be2c7423.js +353 -0
  214. package/dist/esm/v2/components/index.d.ts +1 -0
  215. package/dist/esm/v2/components/index.js +25 -1
  216. package/dist/esm/v2/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +209 -0
  217. package/dist/esm/v2/components/or-rich-text-editor-v3/index.d.ts +1 -0
  218. package/dist/esm/v2/components/or-rich-text-editor-v3/index.js +59 -0
  219. package/dist/esm/v2/components/or-rich-text-editor-v3/styles.d.ts +6 -0
  220. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.d.ts +3 -0
  221. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.d.ts +27 -0
  222. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/index.d.ts +1 -0
  223. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/index.js +7 -0
  224. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/theme.d.ts +24 -0
  225. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/codemirror/types.d.ts +19 -0
  226. package/dist/esm/v2/components/or-rich-text-editor-v3/utils/markdown.d.ts +3 -0
  227. package/dist/esm/v2/components/or-select-v3/index.js +1 -1
  228. package/dist/esm/v2/components/or-text-v3/OrText.vue.d.ts +2 -2
  229. package/dist/esm/v2/components/or-textarea/OrTextarea.vue.d.ts +2 -2
  230. package/dist/esm/v2/components/or-textarea-v3/OrTextarea.vue.d.ts +2 -2
  231. package/dist/esm/v2/components/or-textbox/OrTextbox.vue.d.ts +2 -2
  232. package/dist/esm/v2/components/or-time-picker-v3/OrTimePicker.vue.d.ts +2 -2
  233. package/dist/esm/v2/components/or-toast/OrToast.vue.d.ts +2 -2
  234. package/dist/esm/v2/components/or-toast/or-toast-container/OrToastContainer.vue.d.ts +2 -2
  235. package/dist/esm/v2/components/or-toast-v3/OrToast.vue.d.ts +2 -2
  236. package/dist/esm/v2/components/or-toast-v3/or-toast-container-v3/OrToastContainer.vue.d.ts +2 -2
  237. package/dist/esm/v2/components/or-tooltip/OrTooltip.vue.d.ts +2 -2
  238. package/dist/esm/v2/components/or-tooltip/or-tooltip-content/OrTooltipContent.vue.d.ts +2 -2
  239. package/dist/esm/v2/components/or-tooltip-v3/OrTooltip.vue.d.ts +2 -2
  240. package/dist/esm/v2/index.js +25 -1
  241. package/dist/esm/v3/OrRichTextEditor-7264ad21.js +807 -0
  242. package/dist/esm/v3/{OrSelect-3dbddc6b.js → OrSelect-b1d7651a.js} +1 -2
  243. package/dist/esm/v3/codemirrorView-be2c7423.js +353 -0
  244. package/dist/esm/v3/components/index.d.ts +1 -0
  245. package/dist/esm/v3/components/index.js +25 -1
  246. package/dist/esm/v3/components/or-avatar/OrAvatar.vue.d.ts +26 -11
  247. package/dist/esm/v3/components/or-avatar-v3/OrAvatar.vue.d.ts +24 -8
  248. package/dist/esm/v3/components/or-bottom-sheet-v3/OrBottomSheet.vue.d.ts +33 -20
  249. package/dist/esm/v3/components/or-button/OrButton.vue.d.ts +51 -16
  250. package/dist/esm/v3/components/or-button-v2/OrButton.vue.d.ts +57 -20
  251. package/dist/esm/v3/components/or-button-v3/OrButton.vue.d.ts +35 -15
  252. package/dist/esm/v3/components/or-card/OrCard.vue.d.ts +15 -7
  253. package/dist/esm/v3/components/or-card-collection/OrCardCollection.vue.d.ts +47 -21
  254. package/dist/esm/v3/components/or-card-collection-v3/OrCardCollection.vue.d.ts +70 -22
  255. package/dist/esm/v3/components/or-card-collection-v3/partials/OrCardCollectionView.vue3.vue.d.ts +14 -6
  256. package/dist/esm/v3/components/or-card-v3/OrCard.vue.d.ts +7 -4
  257. package/dist/esm/v3/components/or-carousel/OrCarousel.vue.d.ts +676 -126
  258. package/dist/esm/v3/components/or-carousel/or-carousel-item/OrCarouselItem.vue.d.ts +1 -1
  259. package/dist/esm/v3/components/or-checkbox/OrCheckbox.vue.d.ts +35 -15
  260. package/dist/esm/v3/components/or-checkbox-group-v3/OrCheckboxGroup.vue.d.ts +24 -6
  261. package/dist/esm/v3/components/or-checkbox-tree-v3/OrCheckboxTree.vue.d.ts +43 -17
  262. package/dist/esm/v3/components/or-checkbox-v3/OrCheckbox.vue.d.ts +53 -23
  263. package/dist/esm/v3/components/or-chips/OrChips.vue.d.ts +51 -24
  264. package/dist/esm/v3/components/or-chips/or-chip/OrChip.vue.d.ts +25 -9
  265. package/dist/esm/v3/components/or-chips/partials/OrChipsInput.vue.d.ts +37 -17
  266. package/dist/esm/v3/components/or-code/OrCode.vue.d.ts +69 -24
  267. package/dist/esm/v3/components/or-collapse/OrCollapse.vue.d.ts +39 -17
  268. package/dist/esm/v3/components/or-color-picker/OrColorPicker.vue.d.ts +31 -13
  269. package/dist/esm/v3/components/or-combined-input-v3/OrCombinedInput.vue.d.ts +30 -8
  270. package/dist/esm/v3/components/or-confirm/OrConfirm.vue.d.ts +84 -23
  271. package/dist/esm/v3/components/or-confirm-v3/OrConfirm.vue.d.ts +91 -29
  272. package/dist/esm/v3/components/or-date-picker-v3/OrDatePicker.vue.d.ts +81 -25
  273. package/dist/esm/v3/components/or-date-time-picker/OrDateTimePicker.vue.d.ts +177 -68
  274. package/dist/esm/v3/components/or-date-time-picker/partials/OrDateTimePickerCalendarItem.vue.d.ts +33 -12
  275. package/dist/esm/v3/components/or-date-time-picker-v3/OrDateTimePicker.vue.d.ts +105 -31
  276. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-date-control/OrDateTimePickerDateControl.vue.d.ts +28 -11
  277. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-date-select/OrDateTimePickerDateSelect.vue.d.ts +39 -17
  278. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-mobile-control/OrDateTimePickerMobileControl.vue.d.ts +15 -7
  279. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-month-select/OrDateTimePickerMonthSelect.vue.d.ts +85 -23
  280. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-popover-footer/OrDateTimePickerPopoverFooter.vue.d.ts +11 -7
  281. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-popover-header/OrDateTimePickerPopoverHeader.vue.d.ts +7 -4
  282. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-time-control/OrDateTimePickerTimeControl.vue.d.ts +28 -11
  283. package/dist/esm/v3/components/or-date-time-picker-v3/partials/or-date-time-picker-time-select/OrDateTimePickerTimeSelect.vue.d.ts +37 -15
  284. package/dist/esm/v3/components/or-empty-state-v3/OrEmptyState.vue.d.ts +28 -11
  285. package/dist/esm/v3/components/or-error/OrError.vue.d.ts +8 -4
  286. package/dist/esm/v3/components/or-error-tag-v3/OrErrorTag.vue.d.ts +7 -4
  287. package/dist/esm/v3/components/or-error-v3/OrError.vue.d.ts +18 -9
  288. package/dist/esm/v3/components/or-expansion-panel-v3/OrExpansionPanel.vue.d.ts +35 -14
  289. package/dist/esm/v3/components/or-fab-v3/OrFab.vue.d.ts +20 -8
  290. package/dist/esm/v3/components/or-floating/OrFloating.vue.d.ts +46 -15
  291. package/dist/esm/v3/components/or-form-group-v3/OrFormGroup.vue.d.ts +30 -10
  292. package/dist/esm/v3/components/or-hint/OrHint.vue.d.ts +8 -4
  293. package/dist/esm/v3/components/or-hint-v3/OrHint.vue.d.ts +18 -9
  294. package/dist/esm/v3/components/or-icon/OrIcon.vue.d.ts +44 -16
  295. package/dist/esm/v3/components/or-icon-button-v2/OrIconButton.vue.d.ts +43 -13
  296. package/dist/esm/v3/components/or-icon-button-v2/partials/OrTooltipWrapper.vue.d.ts +10 -8
  297. package/dist/esm/v3/components/or-icon-button-v3/OrIconButton.vue.d.ts +52 -16
  298. package/dist/esm/v3/components/or-icon-v3/OrIcon.vue.d.ts +18 -7
  299. package/dist/esm/v3/components/or-inline-input-box-v3/OrInlineInputBox.vue.d.ts +16 -7
  300. package/dist/esm/v3/components/or-inline-input-v3/OrInlineInput.vue.d.ts +83 -39
  301. package/dist/esm/v3/components/or-inline-text-edit/OrInlineTextEdit.vue.d.ts +95 -43
  302. package/dist/esm/v3/components/or-inline-textarea-v3/OrInlineTextarea.vue.d.ts +79 -39
  303. package/dist/esm/v3/components/or-input/OrInput.vue.d.ts +87 -36
  304. package/dist/esm/v3/components/or-input-box-v3/OrInputBox.vue.d.ts +22 -7
  305. package/dist/esm/v3/components/or-input-v3/OrInput.vue.d.ts +85 -34
  306. package/dist/esm/v3/components/or-label/OrLabel.vue.d.ts +20 -9
  307. package/dist/esm/v3/components/or-label-v3/OrLabel.vue.d.ts +24 -9
  308. package/dist/esm/v3/components/or-link-v3/OrLink.vue.d.ts +24 -7
  309. package/dist/esm/v3/components/or-list/OrList.vue.d.ts +47 -21
  310. package/dist/esm/v3/components/or-list-of-inputs/OrListOfInputs.vue.d.ts +27 -11
  311. package/dist/esm/v3/components/or-loader/OrLoader.vue.d.ts +26 -10
  312. package/dist/esm/v3/components/or-loader-v3/OrLoader.vue.d.ts +34 -13
  313. package/dist/esm/v3/components/or-menu-item-v3/OrMenuItem.vue.d.ts +34 -13
  314. package/dist/esm/v3/components/or-menu-v3/OrMenu.vue.d.ts +43 -16
  315. package/dist/esm/v3/components/or-modal/OrModal.vue.d.ts +38 -14
  316. package/dist/esm/v3/components/or-modal-v3/OrModal.vue.d.ts +31 -15
  317. package/dist/esm/v3/components/or-notification/OrNotification.vue.d.ts +27 -9
  318. package/dist/esm/v3/components/or-notification-v3/OrNotification.vue.d.ts +20 -9
  319. package/dist/esm/v3/components/or-number-input/OrNumberInput.vue.d.ts +70 -24
  320. package/dist/esm/v3/components/or-overflow-menu/OrOverflowMenu.vue.d.ts +31 -13
  321. package/dist/esm/v3/components/or-overflow-menu/partials/OrOverflowMenuItem.vue.d.ts +23 -7
  322. package/dist/esm/v3/components/or-overlay/OrOverlay.vue.d.ts +16 -6
  323. package/dist/esm/v3/components/or-overlay-v3/OrOverlay.vue.d.ts +14 -7
  324. package/dist/esm/v3/components/or-pagination-v3/OrPagination.vue.d.ts +75 -27
  325. package/dist/esm/v3/components/or-password/OrPassword.vue.d.ts +63 -22
  326. package/dist/esm/v3/components/or-popover-v3/OrPopover.vue.d.ts +74 -27
  327. package/dist/esm/v3/components/or-progress/OrProgress.vue.d.ts +56 -20
  328. package/dist/esm/v3/components/or-progress-v3/OrProgress.vue.d.ts +62 -25
  329. package/dist/esm/v3/components/or-radio/OrRadio.vue.d.ts +35 -13
  330. package/dist/esm/v3/components/or-radio-group/OrRadioGroup.vue.d.ts +26 -9
  331. package/dist/esm/v3/components/or-radio-group-v3/OrRadioGroup.vue.d.ts +32 -6
  332. package/dist/esm/v3/components/or-radio-v3/OrRadio.vue.d.ts +49 -21
  333. package/dist/esm/v3/components/or-rich-text-editor-v3/OrRichTextEditor.vue.d.ts +209 -0
  334. package/dist/esm/v3/components/or-rich-text-editor-v3/index.d.ts +1 -0
  335. package/dist/esm/v3/components/or-rich-text-editor-v3/index.js +57 -0
  336. package/dist/esm/v3/components/or-rich-text-editor-v3/styles.d.ts +6 -0
  337. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.d.ts +3 -0
  338. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.d.ts +27 -0
  339. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/index.d.ts +1 -0
  340. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/index.js +7 -0
  341. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/theme.d.ts +24 -0
  342. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/codemirror/types.d.ts +19 -0
  343. package/dist/esm/v3/components/or-rich-text-editor-v3/utils/markdown.d.ts +3 -0
  344. package/dist/esm/v3/components/or-search/OrSearch.vue.d.ts +65 -23
  345. package/dist/esm/v3/components/or-search-v3/OrSearch.vue.d.ts +41 -17
  346. package/dist/esm/v3/components/or-segmented-control-v3/OrSegmentedControl.vue.d.ts +25 -9
  347. package/dist/esm/v3/components/or-segmented-control-v3/partials/or-segmented-control-item/OrSegmentedControlItem.vue.d.ts +20 -8
  348. package/dist/esm/v3/components/or-select/OrSelect.vue.d.ts +77 -28
  349. package/dist/esm/v3/components/or-select/partials/OrSelectContent.vue.d.ts +49 -18
  350. package/dist/esm/v3/components/or-select/partials/OrSelectContentEmpty.vue.d.ts +16 -4
  351. package/dist/esm/v3/components/or-select/partials/OrSelectContentOptions.vue.d.ts +67 -13
  352. package/dist/esm/v3/components/or-select/partials/OrSelectInput.vue.d.ts +41 -16
  353. package/dist/esm/v3/components/or-select/partials/OrSelectInputValue.vue.d.ts +35 -16
  354. package/dist/esm/v3/components/or-select/partials/OrSelectMain.vue.d.ts +71 -24
  355. package/dist/esm/v3/components/or-select/partials/OrSelectOption.vue.d.ts +19 -7
  356. package/dist/esm/v3/components/or-select/partials/OrSelectSearchOptions.vue.d.ts +24 -11
  357. package/dist/esm/v3/components/or-select-v3/OrSelect.vue.d.ts +115 -37
  358. package/dist/esm/v3/components/or-select-v3/index.js +1 -1
  359. package/dist/esm/v3/components/or-sidebar/OrSidebar.vue.d.ts +33 -14
  360. package/dist/esm/v3/components/or-sidebar-v3/OrSidebar.vue.d.ts +63 -28
  361. package/dist/esm/v3/components/or-sidebar-v3/partials/or-sidebar-collapse-button/OrSidebarCollapseButton.vue.d.ts +23 -10
  362. package/dist/esm/v3/components/or-skeleton/or-skeleton-circle/OrSkeletonCircle.vue.d.ts +20 -9
  363. package/dist/esm/v3/components/or-skeleton/or-skeleton-rect/OrSkeletonRect.vue.d.ts +22 -9
  364. package/dist/esm/v3/components/or-skeleton/or-skeleton-text/OrSkeletonText.vue.d.ts +26 -10
  365. package/dist/esm/v3/components/or-skeleton-v3/or-skeleton-circle-v3/OrSkeletonCircle.vue.d.ts +28 -13
  366. package/dist/esm/v3/components/or-skeleton-v3/or-skeleton-rect-v3/OrSkeletonRect.vue.d.ts +26 -11
  367. package/dist/esm/v3/components/or-skeleton-v3/or-skeleton-text-v3/OrSkeletonText.vue.d.ts +40 -16
  368. package/dist/esm/v3/components/or-slider/OrSlider.vue.d.ts +91 -35
  369. package/dist/esm/v3/components/or-sort-header-v3/OrSortHeader.vue.d.ts +25 -13
  370. package/dist/esm/v3/components/or-stepper/OrStepper.vue.d.ts +43 -16
  371. package/dist/esm/v3/components/or-stepper/partials/OrStepperButtonOptions.vue.d.ts +20 -4
  372. package/dist/esm/v3/components/or-stepper/partials/OrStepperOptionHorizontal.vue.d.ts +26 -4
  373. package/dist/esm/v3/components/or-stepper/partials/OrStepperOptionVertical.vue.d.ts +26 -4
  374. package/dist/esm/v3/components/or-stepper/partials/OrStepperTitle.vue.d.ts +22 -6
  375. package/dist/esm/v3/components/or-stepper/partials/StatusIcon.vue.d.ts +12 -6
  376. package/dist/esm/v3/components/or-switch/OrSwitch.vue.d.ts +33 -12
  377. package/dist/esm/v3/components/or-switch-v3/OrSwitch.vue.d.ts +53 -22
  378. package/dist/esm/v3/components/or-tab/OrTab.vue.d.ts +22 -9
  379. package/dist/esm/v3/components/or-tab-header-item/OrTabHeaderItem.vue.d.ts +29 -13
  380. package/dist/esm/v3/components/or-tab-v3/OrTab.vue.d.ts +17 -10
  381. package/dist/esm/v3/components/or-tabs/OrTabs.vue.d.ts +17 -4
  382. package/dist/esm/v3/components/or-tabs-v3/OrTabs.vue.d.ts +69 -24
  383. package/dist/esm/v3/components/or-tag/OrTag.vue.d.ts +27 -10
  384. package/dist/esm/v3/components/or-tag-v3/OrTag.vue.d.ts +23 -12
  385. package/dist/esm/v3/components/or-teleport/OrTeleport.vue3.vue.d.ts +10 -4
  386. package/dist/esm/v3/components/or-teleport-v3/OrTeleport.vue3.vue.d.ts +10 -4
  387. package/dist/esm/v3/components/or-text-v3/OrText.vue.d.ts +24 -11
  388. package/dist/esm/v3/components/or-textarea/OrTextarea.vue.d.ts +85 -37
  389. package/dist/esm/v3/components/or-textarea-v3/OrTextarea.vue.d.ts +73 -32
  390. package/dist/esm/v3/components/or-textbox/OrTextbox.vue.d.ts +137 -55
  391. package/dist/esm/v3/components/or-time-picker-v3/OrTimePicker.vue.d.ts +79 -25
  392. package/dist/esm/v3/components/or-toast/OrToast.vue.d.ts +31 -11
  393. package/dist/esm/v3/components/or-toast/or-toast-container/OrToastContainer.vue.d.ts +55 -25
  394. package/dist/esm/v3/components/or-toast-v3/OrToast.vue.d.ts +38 -16
  395. package/dist/esm/v3/components/or-toast-v3/or-toast-container-v3/OrToastContainer.vue.d.ts +54 -24
  396. package/dist/esm/v3/components/or-tooltip/OrTooltip.vue.d.ts +33 -14
  397. package/dist/esm/v3/components/or-tooltip/or-tooltip-content/OrTooltipContent.vue.d.ts +10 -4
  398. package/dist/esm/v3/components/or-tooltip-v3/OrTooltip.vue.d.ts +37 -13
  399. package/dist/esm/v3/directives/dropdown-close.d.ts +1 -3
  400. package/dist/esm/v3/directives/dropdown-open.d.ts +1 -3
  401. package/dist/esm/v3/hooks/useResponsive/useResponsive.d.ts +2 -2
  402. package/dist/esm/v3/index.js +25 -1
  403. package/package.json +25 -5
  404. package/src/components/index.ts +1 -0
  405. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.docs.mdx +7 -0
  406. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.stories3.ts +123 -0
  407. package/src/components/or-rich-text-editor-v3/OrRichTextEditor.vue +722 -0
  408. package/src/components/or-rich-text-editor-v3/index.ts +1 -0
  409. package/src/components/or-rich-text-editor-v3/styles.ts +55 -0
  410. package/src/components/or-rich-text-editor-v3/utils/codemirror/codemirrorNode.ts +40 -0
  411. package/src/components/or-rich-text-editor-v3/utils/codemirror/codemirrorView.ts +254 -0
  412. package/src/components/or-rich-text-editor-v3/utils/codemirror/index.ts +1 -0
  413. package/src/components/or-rich-text-editor-v3/utils/codemirror/theme.ts +213 -0
  414. package/src/components/or-rich-text-editor-v3/utils/codemirror/types.ts +22 -0
  415. package/src/components/or-rich-text-editor-v3/utils/markdown.ts +117 -0
  416. package/src/components/or-select-v3/OrSelect.stories3.ts +1 -39
  417. package/src/components/or-select-v3/OrSelect.vue +0 -1
  418. /package/dist/bundled/v2/{index-968c331a.js → index-f6664cb1.js} +0 -0
  419. /package/dist/bundled/v3/{index-968c331a.js → index-f6664cb1.js} +0 -0
@@ -0,0 +1,3805 @@
1
+ import { E as EditorView, F as Facet, c as combineConfig, S as StateField, b as EditorSelection, T as Transaction, C as ChangeSet, d as ChangeDesc, I as IndentContext, g as getIndentation, i as indentString, e as Text, f as indentUnit, h as countColumn, j as getIndentUnit, A as Annotation, l as StateEffect, m as matchBrackets, s as syntaxTree, N as NodeProp, D as Direction, n as findClusterBreak, V as ViewPlugin, o as Decoration, p as codePointAt, q as codePointSize, r as getPanel, t as CharCategory, P as Prec, u as fromCodePoint, v as showPanel, R as RangeSetBuilder, a as EditorState, w as runScopeHandlers, x as hoverTooltip, W as WidgetType, y as logException, z as lineNumbers, B as highlightActiveLineGutter, G as highlightSpecialChars, H as foldGutter, J as drawSelection, K as dropCursor, L as indentOnInput, M as syntaxHighlighting, O as defaultHighlightStyle, Q as bracketMatching, U as rectangularSelection, X as crosshairCursor, Y as highlightActiveLine, k as keymap, Z as foldKeymap } from './index-0d224ae5.js';
2
+ import { c as closeBrackets, a as autocompletion, b as closeBracketsKeymap, d as completionKeymap } from './index-e9f6b2d8.js';
3
+
4
+ /**
5
+ Comment or uncomment the current selection. Will use line comments
6
+ if available, otherwise falling back to block comments.
7
+ */
8
+ const toggleComment = target => {
9
+ let {
10
+ state
11
+ } = target,
12
+ line = state.doc.lineAt(state.selection.main.from),
13
+ config = getConfig(target.state, line.from);
14
+ return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
15
+ };
16
+ function command(f, option) {
17
+ return _ref => {
18
+ let {
19
+ state,
20
+ dispatch
21
+ } = _ref;
22
+ if (state.readOnly) return false;
23
+ let tr = f(option, state);
24
+ if (!tr) return false;
25
+ dispatch(state.update(tr));
26
+ return true;
27
+ };
28
+ }
29
+ /**
30
+ Comment or uncomment the current selection using line comments.
31
+ The line comment syntax is taken from the
32
+ [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
33
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
34
+ */
35
+ const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */);
36
+ /**
37
+ Comment or uncomment the current selection using block comments.
38
+ The block comment syntax is taken from the
39
+ [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
40
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
41
+ */
42
+ const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */);
43
+ /**
44
+ Comment or uncomment the lines around the current selection using
45
+ block comments.
46
+ */
47
+ const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
48
+ function getConfig(state, pos) {
49
+ let data = state.languageDataAt("commentTokens", pos);
50
+ return data.length ? data[0] : {};
51
+ }
52
+ const SearchMargin = 50;
53
+ /**
54
+ Determines if the given range is block-commented in the given
55
+ state.
56
+ */
57
+ function findBlockComment(state, _ref2, from, to) {
58
+ let {
59
+ open,
60
+ close
61
+ } = _ref2;
62
+ let textBefore = state.sliceDoc(from - SearchMargin, from);
63
+ let textAfter = state.sliceDoc(to, to + SearchMargin);
64
+ let spaceBefore = /\s*$/.exec(textBefore)[0].length,
65
+ spaceAfter = /^\s*/.exec(textAfter)[0].length;
66
+ let beforeOff = textBefore.length - spaceBefore;
67
+ if (textBefore.slice(beforeOff - open.length, beforeOff) == open && textAfter.slice(spaceAfter, spaceAfter + close.length) == close) {
68
+ return {
69
+ open: {
70
+ pos: from - spaceBefore,
71
+ margin: spaceBefore && 1
72
+ },
73
+ close: {
74
+ pos: to + spaceAfter,
75
+ margin: spaceAfter && 1
76
+ }
77
+ };
78
+ }
79
+ let startText, endText;
80
+ if (to - from <= 2 * SearchMargin) {
81
+ startText = endText = state.sliceDoc(from, to);
82
+ } else {
83
+ startText = state.sliceDoc(from, from + SearchMargin);
84
+ endText = state.sliceDoc(to - SearchMargin, to);
85
+ }
86
+ let startSpace = /^\s*/.exec(startText)[0].length,
87
+ endSpace = /\s*$/.exec(endText)[0].length;
88
+ let endOff = endText.length - endSpace - close.length;
89
+ if (startText.slice(startSpace, startSpace + open.length) == open && endText.slice(endOff, endOff + close.length) == close) {
90
+ return {
91
+ open: {
92
+ pos: from + startSpace + open.length,
93
+ margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0
94
+ },
95
+ close: {
96
+ pos: to - endSpace - close.length,
97
+ margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0
98
+ }
99
+ };
100
+ }
101
+ return null;
102
+ }
103
+ function selectedLineRanges(state) {
104
+ let ranges = [];
105
+ for (let r of state.selection.ranges) {
106
+ let fromLine = state.doc.lineAt(r.from);
107
+ let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
108
+ let last = ranges.length - 1;
109
+ if (last >= 0 && ranges[last].to > fromLine.from) ranges[last].to = toLine.to;else ranges.push({
110
+ from: fromLine.from,
111
+ to: toLine.to
112
+ });
113
+ }
114
+ return ranges;
115
+ }
116
+ // Performs toggle, comment and uncomment of block comments in
117
+ // languages that support them.
118
+ function changeBlockComment(option, state) {
119
+ let ranges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : state.selection.ranges;
120
+ let tokens = ranges.map(r => getConfig(state, r.from).block);
121
+ if (!tokens.every(c => c)) return null;
122
+ let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
123
+ if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) {
124
+ return {
125
+ changes: state.changes(ranges.map((range, i) => {
126
+ if (comments[i]) return [];
127
+ return [{
128
+ from: range.from,
129
+ insert: tokens[i].open + " "
130
+ }, {
131
+ from: range.to,
132
+ insert: " " + tokens[i].close
133
+ }];
134
+ }))
135
+ };
136
+ } else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) {
137
+ let changes = [];
138
+ for (let i = 0, comment; i < comments.length; i++) if (comment = comments[i]) {
139
+ let token = tokens[i],
140
+ {
141
+ open,
142
+ close
143
+ } = comment;
144
+ changes.push({
145
+ from: open.pos - token.open.length,
146
+ to: open.pos + open.margin
147
+ }, {
148
+ from: close.pos - close.margin,
149
+ to: close.pos + token.close.length
150
+ });
151
+ }
152
+ return {
153
+ changes
154
+ };
155
+ }
156
+ return null;
157
+ }
158
+ // Performs toggle, comment and uncomment of line comments.
159
+ function changeLineComment(option, state) {
160
+ let ranges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : state.selection.ranges;
161
+ let lines = [];
162
+ let prevLine = -1;
163
+ for (let {
164
+ from,
165
+ to
166
+ } of ranges) {
167
+ let startI = lines.length,
168
+ minIndent = 1e9;
169
+ let token = getConfig(state, from).line;
170
+ if (!token) continue;
171
+ for (let pos = from; pos <= to;) {
172
+ let line = state.doc.lineAt(pos);
173
+ if (line.from > prevLine && (from == to || to > line.from)) {
174
+ prevLine = line.from;
175
+ let indent = /^\s*/.exec(line.text)[0].length;
176
+ let empty = indent == line.length;
177
+ let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
178
+ if (indent < line.text.length && indent < minIndent) minIndent = indent;
179
+ lines.push({
180
+ line,
181
+ comment,
182
+ token,
183
+ indent,
184
+ empty,
185
+ single: false
186
+ });
187
+ }
188
+ pos = line.to + 1;
189
+ }
190
+ if (minIndent < 1e9) for (let i = startI; i < lines.length; i++) if (lines[i].indent < lines[i].line.text.length) lines[i].indent = minIndent;
191
+ if (lines.length == startI + 1) lines[startI].single = true;
192
+ }
193
+ if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
194
+ let changes = [];
195
+ for (let {
196
+ line,
197
+ token,
198
+ indent,
199
+ empty,
200
+ single
201
+ } of lines) if (single || !empty) changes.push({
202
+ from: line.from + indent,
203
+ insert: token + " "
204
+ });
205
+ let changeSet = state.changes(changes);
206
+ return {
207
+ changes: changeSet,
208
+ selection: state.selection.map(changeSet, 1)
209
+ };
210
+ } else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) {
211
+ let changes = [];
212
+ for (let {
213
+ line,
214
+ comment,
215
+ token
216
+ } of lines) if (comment >= 0) {
217
+ let from = line.from + comment,
218
+ to = from + token.length;
219
+ if (line.text[to - line.from] == " ") to++;
220
+ changes.push({
221
+ from,
222
+ to
223
+ });
224
+ }
225
+ return {
226
+ changes
227
+ };
228
+ }
229
+ return null;
230
+ }
231
+ const fromHistory = /*@__PURE__*/Annotation.define();
232
+ /**
233
+ Transaction annotation that will prevent that transaction from
234
+ being combined with other transactions in the undo history. Given
235
+ `"before"`, it'll prevent merging with previous transactions. With
236
+ `"after"`, subsequent transactions won't be combined with this
237
+ one. With `"full"`, the transaction is isolated on both sides.
238
+ */
239
+ const isolateHistory = /*@__PURE__*/Annotation.define();
240
+ /**
241
+ This facet provides a way to register functions that, given a
242
+ transaction, provide a set of effects that the history should
243
+ store when inverting the transaction. This can be used to
244
+ integrate some kinds of effects in the history, so that they can
245
+ be undone (and redone again).
246
+ */
247
+ const invertedEffects = /*@__PURE__*/Facet.define();
248
+ const historyConfig = /*@__PURE__*/Facet.define({
249
+ combine(configs) {
250
+ return combineConfig(configs, {
251
+ minDepth: 100,
252
+ newGroupDelay: 500,
253
+ joinToEvent: (_t, isAdjacent) => isAdjacent
254
+ }, {
255
+ minDepth: Math.max,
256
+ newGroupDelay: Math.min,
257
+ joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
258
+ });
259
+ }
260
+ });
261
+ function changeEnd(changes) {
262
+ let end = 0;
263
+ changes.iterChangedRanges((_, to) => end = to);
264
+ return end;
265
+ }
266
+ const historyField_ = /*@__PURE__*/StateField.define({
267
+ create() {
268
+ return HistoryState.empty;
269
+ },
270
+ update(state, tr) {
271
+ let config = tr.state.facet(historyConfig);
272
+ let fromHist = tr.annotation(fromHistory);
273
+ if (fromHist) {
274
+ let selection = tr.docChanged ? EditorSelection.single(changeEnd(tr.changes)) : undefined;
275
+ let item = HistEvent.fromTransaction(tr, selection),
276
+ from = fromHist.side;
277
+ let other = from == 0 /* BranchName.Done */ ? state.undone : state.done;
278
+ if (item) other = updateBranch(other, other.length, config.minDepth, item);else other = addSelection(other, tr.startState.selection);
279
+ return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest);
280
+ }
281
+ let isolate = tr.annotation(isolateHistory);
282
+ if (isolate == "full" || isolate == "before") state = state.isolate();
283
+ if (tr.annotation(Transaction.addToHistory) === false) return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state;
284
+ let event = HistEvent.fromTransaction(tr);
285
+ let time = tr.annotation(Transaction.time),
286
+ userEvent = tr.annotation(Transaction.userEvent);
287
+ if (event) state = state.addChanges(event, time, userEvent, config, tr);else if (tr.selection) state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
288
+ if (isolate == "full" || isolate == "after") state = state.isolate();
289
+ return state;
290
+ },
291
+ toJSON(value) {
292
+ return {
293
+ done: value.done.map(e => e.toJSON()),
294
+ undone: value.undone.map(e => e.toJSON())
295
+ };
296
+ },
297
+ fromJSON(json) {
298
+ return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
299
+ }
300
+ });
301
+ /**
302
+ Create a history extension with the given configuration.
303
+ */
304
+ function history() {
305
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
306
+ return [historyField_, historyConfig.of(config), EditorView.domEventHandlers({
307
+ beforeinput(e, view) {
308
+ let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null;
309
+ if (!command) return false;
310
+ e.preventDefault();
311
+ return command(view);
312
+ }
313
+ })];
314
+ }
315
+ function cmd(side, selection) {
316
+ return function (_ref3) {
317
+ let {
318
+ state,
319
+ dispatch
320
+ } = _ref3;
321
+ if (!selection && state.readOnly) return false;
322
+ let historyState = state.field(historyField_, false);
323
+ if (!historyState) return false;
324
+ let tr = historyState.pop(side, state, selection);
325
+ if (!tr) return false;
326
+ dispatch(tr);
327
+ return true;
328
+ };
329
+ }
330
+ /**
331
+ Undo a single group of history events. Returns false if no group
332
+ was available.
333
+ */
334
+ const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false);
335
+ /**
336
+ Redo a group of history events. Returns false if no group was
337
+ available.
338
+ */
339
+ const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false);
340
+ /**
341
+ Undo a change or selection change.
342
+ */
343
+ const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true);
344
+ /**
345
+ Redo a change or selection change.
346
+ */
347
+ const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true);
348
+ // History events store groups of changes or effects that need to be
349
+ // undone/redone together.
350
+ class HistEvent {
351
+ constructor(
352
+ // The changes in this event. Normal events hold at least one
353
+ // change or effect. But it may be necessary to store selection
354
+ // events before the first change, in which case a special type of
355
+ // instance is created which doesn't hold any changes, with
356
+ // changes == startSelection == undefined
357
+ changes,
358
+ // The effects associated with this event
359
+ effects,
360
+ // Accumulated mapping (from addToHistory==false) that should be
361
+ // applied to events below this one.
362
+ mapped,
363
+ // The selection before this event
364
+ startSelection,
365
+ // Stores selection changes after this event, to be used for
366
+ // selection undo/redo.
367
+ selectionsAfter) {
368
+ this.changes = changes;
369
+ this.effects = effects;
370
+ this.mapped = mapped;
371
+ this.startSelection = startSelection;
372
+ this.selectionsAfter = selectionsAfter;
373
+ }
374
+ setSelAfter(after) {
375
+ return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after);
376
+ }
377
+ toJSON() {
378
+ var _a, _b, _c;
379
+ return {
380
+ changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
381
+ mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
382
+ startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
383
+ selectionsAfter: this.selectionsAfter.map(s => s.toJSON())
384
+ };
385
+ }
386
+ static fromJSON(json) {
387
+ return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
388
+ }
389
+ // This does not check `addToHistory` and such, it assumes the
390
+ // transaction needs to be converted to an item. Returns null when
391
+ // there are no changes or effects in the transaction.
392
+ static fromTransaction(tr, selection) {
393
+ let effects = none;
394
+ for (let invert of tr.startState.facet(invertedEffects)) {
395
+ let result = invert(tr);
396
+ if (result.length) effects = effects.concat(result);
397
+ }
398
+ if (!effects.length && tr.changes.empty) return null;
399
+ return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none);
400
+ }
401
+ static selection(selections) {
402
+ return new HistEvent(undefined, none, undefined, undefined, selections);
403
+ }
404
+ }
405
+ function updateBranch(branch, to, maxLen, newEvent) {
406
+ let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0;
407
+ let newBranch = branch.slice(start, to);
408
+ newBranch.push(newEvent);
409
+ return newBranch;
410
+ }
411
+ function isAdjacent(a, b) {
412
+ let ranges = [],
413
+ isAdjacent = false;
414
+ a.iterChangedRanges((f, t) => ranges.push(f, t));
415
+ b.iterChangedRanges((_f, _t, f, t) => {
416
+ for (let i = 0; i < ranges.length;) {
417
+ let from = ranges[i++],
418
+ to = ranges[i++];
419
+ if (t >= from && f <= to) isAdjacent = true;
420
+ }
421
+ });
422
+ return isAdjacent;
423
+ }
424
+ function eqSelectionShape(a, b) {
425
+ return a.ranges.length == b.ranges.length && a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0;
426
+ }
427
+ function conc(a, b) {
428
+ return !a.length ? b : !b.length ? a : a.concat(b);
429
+ }
430
+ const none = [];
431
+ const MaxSelectionsPerEvent = 200;
432
+ function addSelection(branch, selection) {
433
+ if (!branch.length) {
434
+ return [HistEvent.selection([selection])];
435
+ } else {
436
+ let lastEvent = branch[branch.length - 1];
437
+ let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent));
438
+ if (sels.length && sels[sels.length - 1].eq(selection)) return branch;
439
+ sels.push(selection);
440
+ return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels));
441
+ }
442
+ }
443
+ // Assumes the top item has one or more selectionAfter values
444
+ function popSelection(branch) {
445
+ let last = branch[branch.length - 1];
446
+ let newBranch = branch.slice();
447
+ newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1));
448
+ return newBranch;
449
+ }
450
+ // Add a mapping to the top event in the given branch. If this maps
451
+ // away all the changes and effects in that item, drop it and
452
+ // propagate the mapping to the next item.
453
+ function addMappingToBranch(branch, mapping) {
454
+ if (!branch.length) return branch;
455
+ let length = branch.length,
456
+ selections = none;
457
+ while (length) {
458
+ let event = mapEvent(branch[length - 1], mapping, selections);
459
+ if (event.changes && !event.changes.empty || event.effects.length) {
460
+ // Event survived mapping
461
+ let result = branch.slice(0, length);
462
+ result[length - 1] = event;
463
+ return result;
464
+ } else {
465
+ // Drop this event, since there's no changes or effects left
466
+ mapping = event.mapped;
467
+ length--;
468
+ selections = event.selectionsAfter;
469
+ }
470
+ }
471
+ return selections.length ? [HistEvent.selection(selections)] : none;
472
+ }
473
+ function mapEvent(event, mapping, extraSelections) {
474
+ let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections);
475
+ // Change-less events don't store mappings (they are always the last event in a branch)
476
+ if (!event.changes) return HistEvent.selection(selections);
477
+ let mappedChanges = event.changes.map(mapping),
478
+ before = mapping.mapDesc(event.changes, true);
479
+ let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before;
480
+ return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections);
481
+ }
482
+ const joinableUserEvent = /^(input\.type|delete)($|\.)/;
483
+ class HistoryState {
484
+ constructor(done, undone) {
485
+ let prevTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
486
+ let prevUserEvent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
487
+ this.done = done;
488
+ this.undone = undone;
489
+ this.prevTime = prevTime;
490
+ this.prevUserEvent = prevUserEvent;
491
+ }
492
+ isolate() {
493
+ return this.prevTime ? new HistoryState(this.done, this.undone) : this;
494
+ }
495
+ addChanges(event, time, userEvent, config, tr) {
496
+ let done = this.done,
497
+ lastEvent = done[done.length - 1];
498
+ if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes && (!userEvent || joinableUserEvent.test(userEvent)) && (!lastEvent.selectionsAfter.length && time - this.prevTime < config.newGroupDelay && config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes)) ||
499
+ // For compose (but not compose.start) events, always join with previous event
500
+ userEvent == "input.type.compose")) {
501
+ done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
502
+ } else {
503
+ done = updateBranch(done, done.length, config.minDepth, event);
504
+ }
505
+ return new HistoryState(done, none, time, userEvent);
506
+ }
507
+ addSelection(selection, time, userEvent, newGroupDelay) {
508
+ let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none;
509
+ if (last.length > 0 && time - this.prevTime < newGroupDelay && userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) && eqSelectionShape(last[last.length - 1], selection)) return this;
510
+ return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent);
511
+ }
512
+ addMapping(mapping) {
513
+ return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
514
+ }
515
+ pop(side, state, selection) {
516
+ let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone;
517
+ if (branch.length == 0) return null;
518
+ let event = branch[branch.length - 1];
519
+ if (selection && event.selectionsAfter.length) {
520
+ return state.update({
521
+ selection: event.selectionsAfter[event.selectionsAfter.length - 1],
522
+ annotations: fromHistory.of({
523
+ side,
524
+ rest: popSelection(branch)
525
+ }),
526
+ userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo",
527
+ scrollIntoView: true
528
+ });
529
+ } else if (!event.changes) {
530
+ return null;
531
+ } else {
532
+ let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1);
533
+ if (event.mapped) rest = addMappingToBranch(rest, event.mapped);
534
+ return state.update({
535
+ changes: event.changes,
536
+ selection: event.startSelection,
537
+ effects: event.effects,
538
+ annotations: fromHistory.of({
539
+ side,
540
+ rest
541
+ }),
542
+ filter: false,
543
+ userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo",
544
+ scrollIntoView: true
545
+ });
546
+ }
547
+ }
548
+ }
549
+ HistoryState.empty = /*@__PURE__*/new HistoryState(none, none);
550
+ /**
551
+ Default key bindings for the undo history.
552
+
553
+ - Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo).
554
+ - Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
555
+ - Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection).
556
+ - Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection).
557
+ */
558
+ const historyKeymap = [{
559
+ key: "Mod-z",
560
+ run: undo,
561
+ preventDefault: true
562
+ }, {
563
+ key: "Mod-y",
564
+ mac: "Mod-Shift-z",
565
+ run: redo,
566
+ preventDefault: true
567
+ }, {
568
+ linux: "Ctrl-Shift-z",
569
+ run: redo,
570
+ preventDefault: true
571
+ }, {
572
+ key: "Mod-u",
573
+ run: undoSelection,
574
+ preventDefault: true
575
+ }, {
576
+ key: "Alt-u",
577
+ mac: "Mod-Shift-u",
578
+ run: redoSelection,
579
+ preventDefault: true
580
+ }];
581
+ function updateSel(sel, by) {
582
+ return EditorSelection.create(sel.ranges.map(by), sel.mainIndex);
583
+ }
584
+ function setSel(state, selection) {
585
+ return state.update({
586
+ selection,
587
+ scrollIntoView: true,
588
+ userEvent: "select"
589
+ });
590
+ }
591
+ function moveSel(_ref4, how) {
592
+ let {
593
+ state,
594
+ dispatch
595
+ } = _ref4;
596
+ let selection = updateSel(state.selection, how);
597
+ if (selection.eq(state.selection)) return false;
598
+ dispatch(setSel(state, selection));
599
+ return true;
600
+ }
601
+ function rangeEnd(range, forward) {
602
+ return EditorSelection.cursor(forward ? range.to : range.from);
603
+ }
604
+ function cursorByChar(view, forward) {
605
+ return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward));
606
+ }
607
+ function ltrAtCursor(view) {
608
+ return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR;
609
+ }
610
+ /**
611
+ Move the selection one character to the left (which is backward in
612
+ left-to-right text, forward in right-to-left text).
613
+ */
614
+ const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view));
615
+ /**
616
+ Move the selection one character to the right.
617
+ */
618
+ const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view));
619
+ function cursorByGroup(view, forward) {
620
+ return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
621
+ }
622
+ /**
623
+ Move the selection to the left across one group of word or
624
+ non-word (but also non-space) characters.
625
+ */
626
+ const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view));
627
+ /**
628
+ Move the selection one group to the right.
629
+ */
630
+ const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view));
631
+ function interestingNode(state, node, bracketProp) {
632
+ if (node.type.prop(bracketProp)) return true;
633
+ let len = node.to - node.from;
634
+ return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild;
635
+ }
636
+ function moveBySyntax(state, start, forward) {
637
+ let pos = syntaxTree(state).resolveInner(start.head);
638
+ let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy;
639
+ // Scan forward through child nodes to see if there's an interesting
640
+ // node ahead.
641
+ for (let at = start.head;;) {
642
+ let next = forward ? pos.childAfter(at) : pos.childBefore(at);
643
+ if (!next) break;
644
+ if (interestingNode(state, next, bracketProp)) pos = next;else at = forward ? next.to : next.from;
645
+ }
646
+ let bracket = pos.type.prop(bracketProp),
647
+ match,
648
+ newPos;
649
+ if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched) newPos = forward ? match.end.to : match.end.from;else newPos = forward ? pos.to : pos.from;
650
+ return EditorSelection.cursor(newPos, forward ? -1 : 1);
651
+ }
652
+ /**
653
+ Move the cursor over the next syntactic element to the left.
654
+ */
655
+ const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
656
+ /**
657
+ Move the cursor over the next syntactic element to the right.
658
+ */
659
+ const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
660
+ function cursorByLine(view, forward) {
661
+ return moveSel(view, range => {
662
+ if (!range.empty) return rangeEnd(range, forward);
663
+ let moved = view.moveVertically(range, forward);
664
+ return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward);
665
+ });
666
+ }
667
+ /**
668
+ Move the selection one line up.
669
+ */
670
+ const cursorLineUp = view => cursorByLine(view, false);
671
+ /**
672
+ Move the selection one line down.
673
+ */
674
+ const cursorLineDown = view => cursorByLine(view, true);
675
+ function pageInfo(view) {
676
+ let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2;
677
+ let marginTop = 0,
678
+ marginBottom = 0,
679
+ height;
680
+ if (selfScroll) {
681
+ for (let source of view.state.facet(EditorView.scrollMargins)) {
682
+ let margins = source(view);
683
+ if (margins === null || margins === void 0 ? void 0 : margins.top) marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop);
684
+ if (margins === null || margins === void 0 ? void 0 : margins.bottom) marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom);
685
+ }
686
+ height = view.scrollDOM.clientHeight - marginTop - marginBottom;
687
+ } else {
688
+ height = (view.dom.ownerDocument.defaultView || window).innerHeight;
689
+ }
690
+ return {
691
+ marginTop,
692
+ marginBottom,
693
+ selfScroll,
694
+ height: Math.max(view.defaultLineHeight, height - 5)
695
+ };
696
+ }
697
+ function cursorByPage(view, forward) {
698
+ let page = pageInfo(view);
699
+ let {
700
+ state
701
+ } = view,
702
+ selection = updateSel(state.selection, range => {
703
+ return range.empty ? view.moveVertically(range, forward, page.height) : rangeEnd(range, forward);
704
+ });
705
+ if (selection.eq(state.selection)) return false;
706
+ let effect;
707
+ if (page.selfScroll) {
708
+ let startPos = view.coordsAtPos(state.selection.main.head);
709
+ let scrollRect = view.scrollDOM.getBoundingClientRect();
710
+ let scrollTop = scrollRect.top + page.marginTop,
711
+ scrollBottom = scrollRect.bottom - page.marginBottom;
712
+ if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom) effect = EditorView.scrollIntoView(selection.main.head, {
713
+ y: "start",
714
+ yMargin: startPos.top - scrollTop
715
+ });
716
+ }
717
+ view.dispatch(setSel(state, selection), {
718
+ effects: effect
719
+ });
720
+ return true;
721
+ }
722
+ /**
723
+ Move the selection one page up.
724
+ */
725
+ const cursorPageUp = view => cursorByPage(view, false);
726
+ /**
727
+ Move the selection one page down.
728
+ */
729
+ const cursorPageDown = view => cursorByPage(view, true);
730
+ function moveByLineBoundary(view, start, forward) {
731
+ let line = view.lineBlockAt(start.head),
732
+ moved = view.moveToLineBoundary(start, forward);
733
+ if (moved.head == start.head && moved.head != (forward ? line.to : line.from)) moved = view.moveToLineBoundary(start, forward, false);
734
+ if (!forward && moved.head == line.from && line.length) {
735
+ let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
736
+ if (space && start.head != line.from + space) moved = EditorSelection.cursor(line.from + space);
737
+ }
738
+ return moved;
739
+ }
740
+ /**
741
+ Move the selection to the next line wrap point, or to the end of
742
+ the line if there isn't one left on this line.
743
+ */
744
+ const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true));
745
+ /**
746
+ Move the selection to previous line wrap point, or failing that to
747
+ the start of the line. If the line is indented, and the cursor
748
+ isn't already at the end of the indentation, this will move to the
749
+ end of the indentation instead of the start of the line.
750
+ */
751
+ const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
752
+ /**
753
+ Move the selection one line wrap point to the left.
754
+ */
755
+ const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
756
+ /**
757
+ Move the selection one line wrap point to the right.
758
+ */
759
+ const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
760
+ /**
761
+ Move the selection to the start of the line.
762
+ */
763
+ const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
764
+ /**
765
+ Move the selection to the end of the line.
766
+ */
767
+ const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
768
+ function toMatchingBracket(state, dispatch, extend) {
769
+ let found = false,
770
+ selection = updateSel(state.selection, range => {
771
+ let matching = matchBrackets(state, range.head, -1) || matchBrackets(state, range.head, 1) || range.head > 0 && matchBrackets(state, range.head - 1, 1) || range.head < state.doc.length && matchBrackets(state, range.head + 1, -1);
772
+ if (!matching || !matching.end) return range;
773
+ found = true;
774
+ let head = matching.start.from == range.head ? matching.end.to : matching.end.from;
775
+ return extend ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
776
+ });
777
+ if (!found) return false;
778
+ dispatch(setSel(state, selection));
779
+ return true;
780
+ }
781
+ /**
782
+ Move the selection to the bracket matching the one it is currently
783
+ on, if any.
784
+ */
785
+ const cursorMatchingBracket = _ref5 => {
786
+ let {
787
+ state,
788
+ dispatch
789
+ } = _ref5;
790
+ return toMatchingBracket(state, dispatch, false);
791
+ };
792
+ function extendSel(view, how) {
793
+ let selection = updateSel(view.state.selection, range => {
794
+ let head = how(range);
795
+ return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined);
796
+ });
797
+ if (selection.eq(view.state.selection)) return false;
798
+ view.dispatch(setSel(view.state, selection));
799
+ return true;
800
+ }
801
+ function selectByChar(view, forward) {
802
+ return extendSel(view, range => view.moveByChar(range, forward));
803
+ }
804
+ /**
805
+ Move the selection head one character to the left, while leaving
806
+ the anchor in place.
807
+ */
808
+ const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view));
809
+ /**
810
+ Move the selection head one character to the right.
811
+ */
812
+ const selectCharRight = view => selectByChar(view, ltrAtCursor(view));
813
+ function selectByGroup(view, forward) {
814
+ return extendSel(view, range => view.moveByGroup(range, forward));
815
+ }
816
+ /**
817
+ Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to
818
+ the left.
819
+ */
820
+ const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view));
821
+ /**
822
+ Move the selection head one group to the right.
823
+ */
824
+ const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view));
825
+ /**
826
+ Move the selection head over the next syntactic element to the left.
827
+ */
828
+ const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
829
+ /**
830
+ Move the selection head over the next syntactic element to the right.
831
+ */
832
+ const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
833
+ function selectByLine(view, forward) {
834
+ return extendSel(view, range => view.moveVertically(range, forward));
835
+ }
836
+ /**
837
+ Move the selection head one line up.
838
+ */
839
+ const selectLineUp = view => selectByLine(view, false);
840
+ /**
841
+ Move the selection head one line down.
842
+ */
843
+ const selectLineDown = view => selectByLine(view, true);
844
+ function selectByPage(view, forward) {
845
+ return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height));
846
+ }
847
+ /**
848
+ Move the selection head one page up.
849
+ */
850
+ const selectPageUp = view => selectByPage(view, false);
851
+ /**
852
+ Move the selection head one page down.
853
+ */
854
+ const selectPageDown = view => selectByPage(view, true);
855
+ /**
856
+ Move the selection head to the next line boundary.
857
+ */
858
+ const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true));
859
+ /**
860
+ Move the selection head to the previous line boundary.
861
+ */
862
+ const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
863
+ /**
864
+ Move the selection head one line boundary to the left.
865
+ */
866
+ const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
867
+ /**
868
+ Move the selection head one line boundary to the right.
869
+ */
870
+ const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
871
+ /**
872
+ Move the selection head to the start of the line.
873
+ */
874
+ const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from));
875
+ /**
876
+ Move the selection head to the end of the line.
877
+ */
878
+ const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to));
879
+ /**
880
+ Move the selection to the start of the document.
881
+ */
882
+ const cursorDocStart = _ref7 => {
883
+ let {
884
+ state,
885
+ dispatch
886
+ } = _ref7;
887
+ dispatch(setSel(state, {
888
+ anchor: 0
889
+ }));
890
+ return true;
891
+ };
892
+ /**
893
+ Move the selection to the end of the document.
894
+ */
895
+ const cursorDocEnd = _ref8 => {
896
+ let {
897
+ state,
898
+ dispatch
899
+ } = _ref8;
900
+ dispatch(setSel(state, {
901
+ anchor: state.doc.length
902
+ }));
903
+ return true;
904
+ };
905
+ /**
906
+ Move the selection head to the start of the document.
907
+ */
908
+ const selectDocStart = _ref9 => {
909
+ let {
910
+ state,
911
+ dispatch
912
+ } = _ref9;
913
+ dispatch(setSel(state, {
914
+ anchor: state.selection.main.anchor,
915
+ head: 0
916
+ }));
917
+ return true;
918
+ };
919
+ /**
920
+ Move the selection head to the end of the document.
921
+ */
922
+ const selectDocEnd = _ref10 => {
923
+ let {
924
+ state,
925
+ dispatch
926
+ } = _ref10;
927
+ dispatch(setSel(state, {
928
+ anchor: state.selection.main.anchor,
929
+ head: state.doc.length
930
+ }));
931
+ return true;
932
+ };
933
+ /**
934
+ Select the entire document.
935
+ */
936
+ const selectAll = _ref11 => {
937
+ let {
938
+ state,
939
+ dispatch
940
+ } = _ref11;
941
+ dispatch(state.update({
942
+ selection: {
943
+ anchor: 0,
944
+ head: state.doc.length
945
+ },
946
+ userEvent: "select"
947
+ }));
948
+ return true;
949
+ };
950
+ /**
951
+ Expand the selection to cover entire lines.
952
+ */
953
+ const selectLine = _ref12 => {
954
+ let {
955
+ state,
956
+ dispatch
957
+ } = _ref12;
958
+ let ranges = selectedLineBlocks(state).map(_ref13 => {
959
+ let {
960
+ from,
961
+ to
962
+ } = _ref13;
963
+ return EditorSelection.range(from, Math.min(to + 1, state.doc.length));
964
+ });
965
+ dispatch(state.update({
966
+ selection: EditorSelection.create(ranges),
967
+ userEvent: "select"
968
+ }));
969
+ return true;
970
+ };
971
+ /**
972
+ Select the next syntactic construct that is larger than the
973
+ selection. Note that this will only work insofar as the language
974
+ [provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full
975
+ syntax tree.
976
+ */
977
+ const selectParentSyntax = _ref14 => {
978
+ let {
979
+ state,
980
+ dispatch
981
+ } = _ref14;
982
+ let selection = updateSel(state.selection, range => {
983
+ var _a;
984
+ let context = syntaxTree(state).resolveInner(range.head, 1);
985
+ while (!(context.from < range.from && context.to >= range.to || context.to > range.to && context.from <= range.from || !((_a = context.parent) === null || _a === void 0 ? void 0 : _a.parent))) context = context.parent;
986
+ return EditorSelection.range(context.to, context.from);
987
+ });
988
+ dispatch(setSel(state, selection));
989
+ return true;
990
+ };
991
+ /**
992
+ Simplify the current selection. When multiple ranges are selected,
993
+ reduce it to its main range. Otherwise, if the selection is
994
+ non-empty, convert it to a cursor selection.
995
+ */
996
+ const simplifySelection = _ref15 => {
997
+ let {
998
+ state,
999
+ dispatch
1000
+ } = _ref15;
1001
+ let cur = state.selection,
1002
+ selection = null;
1003
+ if (cur.ranges.length > 1) selection = EditorSelection.create([cur.main]);else if (!cur.main.empty) selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]);
1004
+ if (!selection) return false;
1005
+ dispatch(setSel(state, selection));
1006
+ return true;
1007
+ };
1008
+ function deleteBy(target, by) {
1009
+ if (target.state.readOnly) return false;
1010
+ let event = "delete.selection",
1011
+ {
1012
+ state
1013
+ } = target;
1014
+ let changes = state.changeByRange(range => {
1015
+ let {
1016
+ from,
1017
+ to
1018
+ } = range;
1019
+ if (from == to) {
1020
+ let towards = by(from);
1021
+ if (towards < from) {
1022
+ event = "delete.backward";
1023
+ towards = skipAtomic(target, towards, false);
1024
+ } else if (towards > from) {
1025
+ event = "delete.forward";
1026
+ towards = skipAtomic(target, towards, true);
1027
+ }
1028
+ from = Math.min(from, towards);
1029
+ to = Math.max(to, towards);
1030
+ } else {
1031
+ from = skipAtomic(target, from, false);
1032
+ to = skipAtomic(target, to, true);
1033
+ }
1034
+ return from == to ? {
1035
+ range
1036
+ } : {
1037
+ changes: {
1038
+ from,
1039
+ to
1040
+ },
1041
+ range: EditorSelection.cursor(from)
1042
+ };
1043
+ });
1044
+ if (changes.changes.empty) return false;
1045
+ target.dispatch(state.update(changes, {
1046
+ scrollIntoView: true,
1047
+ userEvent: event,
1048
+ effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined
1049
+ }));
1050
+ return true;
1051
+ }
1052
+ function skipAtomic(target, pos, forward) {
1053
+ if (target instanceof EditorView) for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target))) ranges.between(pos, pos, (from, to) => {
1054
+ if (from < pos && to > pos) pos = forward ? to : from;
1055
+ });
1056
+ return pos;
1057
+ }
1058
+ const deleteByChar = (target, forward) => deleteBy(target, pos => {
1059
+ let {
1060
+ state
1061
+ } = target,
1062
+ line = state.doc.lineAt(pos),
1063
+ before,
1064
+ targetPos;
1065
+ if (!forward && pos > line.from && pos < line.from + 200 && !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
1066
+ if (before[before.length - 1] == "\t") return pos - 1;
1067
+ let col = countColumn(before, state.tabSize),
1068
+ drop = col % getIndentUnit(state) || getIndentUnit(state);
1069
+ for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++) pos--;
1070
+ targetPos = pos;
1071
+ } else {
1072
+ targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from;
1073
+ if (targetPos == pos && line.number != (forward ? state.doc.lines : 1)) targetPos += forward ? 1 : -1;
1074
+ }
1075
+ return targetPos;
1076
+ });
1077
+ /**
1078
+ Delete the selection, or, for cursor selections, the character
1079
+ before the cursor.
1080
+ */
1081
+ const deleteCharBackward = view => deleteByChar(view, false);
1082
+ /**
1083
+ Delete the selection or the character after the cursor.
1084
+ */
1085
+ const deleteCharForward = view => deleteByChar(view, true);
1086
+ const deleteByGroup = (target, forward) => deleteBy(target, start => {
1087
+ let pos = start,
1088
+ {
1089
+ state
1090
+ } = target,
1091
+ line = state.doc.lineAt(pos);
1092
+ let categorize = state.charCategorizer(pos);
1093
+ for (let cat = null;;) {
1094
+ if (pos == (forward ? line.to : line.from)) {
1095
+ if (pos == start && line.number != (forward ? state.doc.lines : 1)) pos += forward ? 1 : -1;
1096
+ break;
1097
+ }
1098
+ let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
1099
+ let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
1100
+ let nextCat = categorize(nextChar);
1101
+ if (cat != null && nextCat != cat) break;
1102
+ if (nextChar != " " || pos != start) cat = nextCat;
1103
+ pos = next;
1104
+ }
1105
+ return pos;
1106
+ });
1107
+ /**
1108
+ Delete the selection or backward until the end of the next
1109
+ [group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of
1110
+ whitespace when they consist of a single space.
1111
+ */
1112
+ const deleteGroupBackward = target => deleteByGroup(target, false);
1113
+ /**
1114
+ Delete the selection or forward until the end of the next group.
1115
+ */
1116
+ const deleteGroupForward = target => deleteByGroup(target, true);
1117
+ /**
1118
+ Delete the selection, or, if it is a cursor selection, delete to
1119
+ the end of the line. If the cursor is directly at the end of the
1120
+ line, delete the line break after it.
1121
+ */
1122
+ const deleteToLineEnd = view => deleteBy(view, pos => {
1123
+ let lineEnd = view.lineBlockAt(pos).to;
1124
+ return pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1);
1125
+ });
1126
+ /**
1127
+ Delete the selection, or, if it is a cursor selection, delete to
1128
+ the start of the line. If the cursor is directly at the start of the
1129
+ line, delete the line break before it.
1130
+ */
1131
+ const deleteToLineStart = view => deleteBy(view, pos => {
1132
+ let lineStart = view.lineBlockAt(pos).from;
1133
+ return pos > lineStart ? lineStart : Math.max(0, pos - 1);
1134
+ });
1135
+ /**
1136
+ Replace each selection range with a line break, leaving the cursor
1137
+ on the line before the break.
1138
+ */
1139
+ const splitLine = _ref17 => {
1140
+ let {
1141
+ state,
1142
+ dispatch
1143
+ } = _ref17;
1144
+ if (state.readOnly) return false;
1145
+ let changes = state.changeByRange(range => {
1146
+ return {
1147
+ changes: {
1148
+ from: range.from,
1149
+ to: range.to,
1150
+ insert: Text.of(["", ""])
1151
+ },
1152
+ range: EditorSelection.cursor(range.from)
1153
+ };
1154
+ });
1155
+ dispatch(state.update(changes, {
1156
+ scrollIntoView: true,
1157
+ userEvent: "input"
1158
+ }));
1159
+ return true;
1160
+ };
1161
+ /**
1162
+ Flip the characters before and after the cursor(s).
1163
+ */
1164
+ const transposeChars = _ref18 => {
1165
+ let {
1166
+ state,
1167
+ dispatch
1168
+ } = _ref18;
1169
+ if (state.readOnly) return false;
1170
+ let changes = state.changeByRange(range => {
1171
+ if (!range.empty || range.from == 0 || range.from == state.doc.length) return {
1172
+ range
1173
+ };
1174
+ let pos = range.from,
1175
+ line = state.doc.lineAt(pos);
1176
+ let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from;
1177
+ let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from;
1178
+ return {
1179
+ changes: {
1180
+ from,
1181
+ to,
1182
+ insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos))
1183
+ },
1184
+ range: EditorSelection.cursor(to)
1185
+ };
1186
+ });
1187
+ if (changes.changes.empty) return false;
1188
+ dispatch(state.update(changes, {
1189
+ scrollIntoView: true,
1190
+ userEvent: "move.character"
1191
+ }));
1192
+ return true;
1193
+ };
1194
+ function selectedLineBlocks(state) {
1195
+ let blocks = [],
1196
+ upto = -1;
1197
+ for (let range of state.selection.ranges) {
1198
+ let startLine = state.doc.lineAt(range.from),
1199
+ endLine = state.doc.lineAt(range.to);
1200
+ if (!range.empty && range.to == endLine.from) endLine = state.doc.lineAt(range.to - 1);
1201
+ if (upto >= startLine.number) {
1202
+ let prev = blocks[blocks.length - 1];
1203
+ prev.to = endLine.to;
1204
+ prev.ranges.push(range);
1205
+ } else {
1206
+ blocks.push({
1207
+ from: startLine.from,
1208
+ to: endLine.to,
1209
+ ranges: [range]
1210
+ });
1211
+ }
1212
+ upto = endLine.number + 1;
1213
+ }
1214
+ return blocks;
1215
+ }
1216
+ function moveLine(state, dispatch, forward) {
1217
+ if (state.readOnly) return false;
1218
+ let changes = [],
1219
+ ranges = [];
1220
+ for (let block of selectedLineBlocks(state)) {
1221
+ if (forward ? block.to == state.doc.length : block.from == 0) continue;
1222
+ let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1);
1223
+ let size = nextLine.length + 1;
1224
+ if (forward) {
1225
+ changes.push({
1226
+ from: block.to,
1227
+ to: nextLine.to
1228
+ }, {
1229
+ from: block.from,
1230
+ insert: nextLine.text + state.lineBreak
1231
+ });
1232
+ for (let r of block.ranges) ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size)));
1233
+ } else {
1234
+ changes.push({
1235
+ from: nextLine.from,
1236
+ to: block.from
1237
+ }, {
1238
+ from: block.to,
1239
+ insert: state.lineBreak + nextLine.text
1240
+ });
1241
+ for (let r of block.ranges) ranges.push(EditorSelection.range(r.anchor - size, r.head - size));
1242
+ }
1243
+ }
1244
+ if (!changes.length) return false;
1245
+ dispatch(state.update({
1246
+ changes,
1247
+ scrollIntoView: true,
1248
+ selection: EditorSelection.create(ranges, state.selection.mainIndex),
1249
+ userEvent: "move.line"
1250
+ }));
1251
+ return true;
1252
+ }
1253
+ /**
1254
+ Move the selected lines up one line.
1255
+ */
1256
+ const moveLineUp = _ref19 => {
1257
+ let {
1258
+ state,
1259
+ dispatch
1260
+ } = _ref19;
1261
+ return moveLine(state, dispatch, false);
1262
+ };
1263
+ /**
1264
+ Move the selected lines down one line.
1265
+ */
1266
+ const moveLineDown = _ref20 => {
1267
+ let {
1268
+ state,
1269
+ dispatch
1270
+ } = _ref20;
1271
+ return moveLine(state, dispatch, true);
1272
+ };
1273
+ function copyLine(state, dispatch, forward) {
1274
+ if (state.readOnly) return false;
1275
+ let changes = [];
1276
+ for (let block of selectedLineBlocks(state)) {
1277
+ if (forward) changes.push({
1278
+ from: block.from,
1279
+ insert: state.doc.slice(block.from, block.to) + state.lineBreak
1280
+ });else changes.push({
1281
+ from: block.to,
1282
+ insert: state.lineBreak + state.doc.slice(block.from, block.to)
1283
+ });
1284
+ }
1285
+ dispatch(state.update({
1286
+ changes,
1287
+ scrollIntoView: true,
1288
+ userEvent: "input.copyline"
1289
+ }));
1290
+ return true;
1291
+ }
1292
+ /**
1293
+ Create a copy of the selected lines. Keep the selection in the top copy.
1294
+ */
1295
+ const copyLineUp = _ref21 => {
1296
+ let {
1297
+ state,
1298
+ dispatch
1299
+ } = _ref21;
1300
+ return copyLine(state, dispatch, false);
1301
+ };
1302
+ /**
1303
+ Create a copy of the selected lines. Keep the selection in the bottom copy.
1304
+ */
1305
+ const copyLineDown = _ref22 => {
1306
+ let {
1307
+ state,
1308
+ dispatch
1309
+ } = _ref22;
1310
+ return copyLine(state, dispatch, true);
1311
+ };
1312
+ /**
1313
+ Delete selected lines.
1314
+ */
1315
+ const deleteLine = view => {
1316
+ if (view.state.readOnly) return false;
1317
+ let {
1318
+ state
1319
+ } = view,
1320
+ changes = state.changes(selectedLineBlocks(state).map(_ref23 => {
1321
+ let {
1322
+ from,
1323
+ to
1324
+ } = _ref23;
1325
+ if (from > 0) from--;else if (to < state.doc.length) to++;
1326
+ return {
1327
+ from,
1328
+ to
1329
+ };
1330
+ }));
1331
+ let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes);
1332
+ view.dispatch({
1333
+ changes,
1334
+ selection,
1335
+ scrollIntoView: true,
1336
+ userEvent: "delete.line"
1337
+ });
1338
+ return true;
1339
+ };
1340
+ function isBetweenBrackets(state, pos) {
1341
+ if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1))) return {
1342
+ from: pos,
1343
+ to: pos
1344
+ };
1345
+ let context = syntaxTree(state).resolveInner(pos);
1346
+ let before = context.childBefore(pos),
1347
+ after = context.childAfter(pos),
1348
+ closedBy;
1349
+ if (before && after && before.to <= pos && after.from >= pos && (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 && state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from) return {
1350
+ from: before.to,
1351
+ to: after.from
1352
+ };
1353
+ return null;
1354
+ }
1355
+ /**
1356
+ Replace the selection with a newline and indent the newly created
1357
+ line(s). If the current line consists only of whitespace, this
1358
+ will also delete that whitespace. When the cursor is between
1359
+ matching brackets, an additional newline will be inserted after
1360
+ the cursor.
1361
+ */
1362
+ const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false);
1363
+ /**
1364
+ Create a blank, indented line below the current line.
1365
+ */
1366
+ const insertBlankLine = /*@__PURE__*/newlineAndIndent(true);
1367
+ function newlineAndIndent(atEof) {
1368
+ return _ref25 => {
1369
+ let {
1370
+ state,
1371
+ dispatch
1372
+ } = _ref25;
1373
+ if (state.readOnly) return false;
1374
+ let changes = state.changeByRange(range => {
1375
+ let {
1376
+ from,
1377
+ to
1378
+ } = range,
1379
+ line = state.doc.lineAt(from);
1380
+ let explode = !atEof && from == to && isBetweenBrackets(state, from);
1381
+ if (atEof) from = to = (to <= line.to ? line : state.doc.lineAt(to)).to;
1382
+ let cx = new IndentContext(state, {
1383
+ simulateBreak: from,
1384
+ simulateDoubleBreak: !!explode
1385
+ });
1386
+ let indent = getIndentation(cx, from);
1387
+ if (indent == null) indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length;
1388
+ while (to < line.to && /\s/.test(line.text[to - line.from])) to++;
1389
+ if (explode) ({
1390
+ from,
1391
+ to
1392
+ } = explode);else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) from = line.from;
1393
+ let insert = ["", indentString(state, indent)];
1394
+ if (explode) insert.push(indentString(state, cx.lineIndent(line.from, -1)));
1395
+ return {
1396
+ changes: {
1397
+ from,
1398
+ to,
1399
+ insert: Text.of(insert)
1400
+ },
1401
+ range: EditorSelection.cursor(from + 1 + insert[1].length)
1402
+ };
1403
+ });
1404
+ dispatch(state.update(changes, {
1405
+ scrollIntoView: true,
1406
+ userEvent: "input"
1407
+ }));
1408
+ return true;
1409
+ };
1410
+ }
1411
+ function changeBySelectedLine(state, f) {
1412
+ let atLine = -1;
1413
+ return state.changeByRange(range => {
1414
+ let changes = [];
1415
+ for (let pos = range.from; pos <= range.to;) {
1416
+ let line = state.doc.lineAt(pos);
1417
+ if (line.number > atLine && (range.empty || range.to > line.from)) {
1418
+ f(line, changes, range);
1419
+ atLine = line.number;
1420
+ }
1421
+ pos = line.to + 1;
1422
+ }
1423
+ let changeSet = state.changes(changes);
1424
+ return {
1425
+ changes,
1426
+ range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1))
1427
+ };
1428
+ });
1429
+ }
1430
+ /**
1431
+ Auto-indent the selected lines. This uses the [indentation service
1432
+ facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent
1433
+ information.
1434
+ */
1435
+ const indentSelection = _ref26 => {
1436
+ let {
1437
+ state,
1438
+ dispatch
1439
+ } = _ref26;
1440
+ if (state.readOnly) return false;
1441
+ let updated = Object.create(null);
1442
+ let context = new IndentContext(state, {
1443
+ overrideIndentation: start => {
1444
+ let found = updated[start];
1445
+ return found == null ? -1 : found;
1446
+ }
1447
+ });
1448
+ let changes = changeBySelectedLine(state, (line, changes, range) => {
1449
+ let indent = getIndentation(context, line.from);
1450
+ if (indent == null) return;
1451
+ if (!/\S/.test(line.text)) indent = 0;
1452
+ let cur = /^\s*/.exec(line.text)[0];
1453
+ let norm = indentString(state, indent);
1454
+ if (cur != norm || range.from < line.from + cur.length) {
1455
+ updated[line.from] = indent;
1456
+ changes.push({
1457
+ from: line.from,
1458
+ to: line.from + cur.length,
1459
+ insert: norm
1460
+ });
1461
+ }
1462
+ });
1463
+ if (!changes.changes.empty) dispatch(state.update(changes, {
1464
+ userEvent: "indent"
1465
+ }));
1466
+ return true;
1467
+ };
1468
+ /**
1469
+ Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected
1470
+ lines.
1471
+ */
1472
+ const indentMore = _ref27 => {
1473
+ let {
1474
+ state,
1475
+ dispatch
1476
+ } = _ref27;
1477
+ if (state.readOnly) return false;
1478
+ dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
1479
+ changes.push({
1480
+ from: line.from,
1481
+ insert: state.facet(indentUnit)
1482
+ });
1483
+ }), {
1484
+ userEvent: "input.indent"
1485
+ }));
1486
+ return true;
1487
+ };
1488
+ /**
1489
+ Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all
1490
+ selected lines.
1491
+ */
1492
+ const indentLess = _ref28 => {
1493
+ let {
1494
+ state,
1495
+ dispatch
1496
+ } = _ref28;
1497
+ if (state.readOnly) return false;
1498
+ dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
1499
+ let space = /^\s*/.exec(line.text)[0];
1500
+ if (!space) return;
1501
+ let col = countColumn(space, state.tabSize),
1502
+ keep = 0;
1503
+ let insert = indentString(state, Math.max(0, col - getIndentUnit(state)));
1504
+ while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep)) keep++;
1505
+ changes.push({
1506
+ from: line.from + keep,
1507
+ to: line.from + space.length,
1508
+ insert: insert.slice(keep)
1509
+ });
1510
+ }), {
1511
+ userEvent: "delete.dedent"
1512
+ }));
1513
+ return true;
1514
+ };
1515
+ /**
1516
+ Array of key bindings containing the Emacs-style bindings that are
1517
+ available on macOS by default.
1518
+
1519
+ - Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
1520
+ - Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
1521
+ - Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
1522
+ - Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
1523
+ - Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
1524
+ - Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
1525
+ - Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
1526
+ - Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
1527
+ - Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd)
1528
+ - Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
1529
+ - Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine)
1530
+ - Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars)
1531
+ - Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown)
1532
+ - Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp)
1533
+ */
1534
+ const emacsStyleKeymap = [{
1535
+ key: "Ctrl-b",
1536
+ run: cursorCharLeft,
1537
+ shift: selectCharLeft,
1538
+ preventDefault: true
1539
+ }, {
1540
+ key: "Ctrl-f",
1541
+ run: cursorCharRight,
1542
+ shift: selectCharRight
1543
+ }, {
1544
+ key: "Ctrl-p",
1545
+ run: cursorLineUp,
1546
+ shift: selectLineUp
1547
+ }, {
1548
+ key: "Ctrl-n",
1549
+ run: cursorLineDown,
1550
+ shift: selectLineDown
1551
+ }, {
1552
+ key: "Ctrl-a",
1553
+ run: cursorLineStart,
1554
+ shift: selectLineStart
1555
+ }, {
1556
+ key: "Ctrl-e",
1557
+ run: cursorLineEnd,
1558
+ shift: selectLineEnd
1559
+ }, {
1560
+ key: "Ctrl-d",
1561
+ run: deleteCharForward
1562
+ }, {
1563
+ key: "Ctrl-h",
1564
+ run: deleteCharBackward
1565
+ }, {
1566
+ key: "Ctrl-k",
1567
+ run: deleteToLineEnd
1568
+ }, {
1569
+ key: "Ctrl-Alt-h",
1570
+ run: deleteGroupBackward
1571
+ }, {
1572
+ key: "Ctrl-o",
1573
+ run: splitLine
1574
+ }, {
1575
+ key: "Ctrl-t",
1576
+ run: transposeChars
1577
+ }, {
1578
+ key: "Ctrl-v",
1579
+ run: cursorPageDown
1580
+ }];
1581
+ /**
1582
+ An array of key bindings closely sticking to platform-standard or
1583
+ widely used bindings. (This includes the bindings from
1584
+ [`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key`
1585
+ property changed to `mac`.)
1586
+
1587
+ - ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
1588
+ - ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
1589
+ - Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift)
1590
+ - Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift)
1591
+ - Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
1592
+ - Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
1593
+ - ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
1594
+ - ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
1595
+ - Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
1596
+ - Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
1597
+ - Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
1598
+ - Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
1599
+ - PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
1600
+ - PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
1601
+ - Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift)
1602
+ - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift)
1603
+ - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
1604
+ - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
1605
+ - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
1606
+ - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll)
1607
+ - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
1608
+ - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
1609
+ - Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
1610
+ - Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward)
1611
+ - Cmd-Backspace (macOS): [`deleteToLineStart`](https://codemirror.net/6/docs/ref/#commands.deleteToLineStart).
1612
+ - Cmd-Delete (macOS): [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd).
1613
+ */
1614
+ const standardKeymap = /*@__PURE__*/[{
1615
+ key: "ArrowLeft",
1616
+ run: cursorCharLeft,
1617
+ shift: selectCharLeft,
1618
+ preventDefault: true
1619
+ }, {
1620
+ key: "Mod-ArrowLeft",
1621
+ mac: "Alt-ArrowLeft",
1622
+ run: cursorGroupLeft,
1623
+ shift: selectGroupLeft,
1624
+ preventDefault: true
1625
+ }, {
1626
+ mac: "Cmd-ArrowLeft",
1627
+ run: cursorLineBoundaryLeft,
1628
+ shift: selectLineBoundaryLeft,
1629
+ preventDefault: true
1630
+ }, {
1631
+ key: "ArrowRight",
1632
+ run: cursorCharRight,
1633
+ shift: selectCharRight,
1634
+ preventDefault: true
1635
+ }, {
1636
+ key: "Mod-ArrowRight",
1637
+ mac: "Alt-ArrowRight",
1638
+ run: cursorGroupRight,
1639
+ shift: selectGroupRight,
1640
+ preventDefault: true
1641
+ }, {
1642
+ mac: "Cmd-ArrowRight",
1643
+ run: cursorLineBoundaryRight,
1644
+ shift: selectLineBoundaryRight,
1645
+ preventDefault: true
1646
+ }, {
1647
+ key: "ArrowUp",
1648
+ run: cursorLineUp,
1649
+ shift: selectLineUp,
1650
+ preventDefault: true
1651
+ }, {
1652
+ mac: "Cmd-ArrowUp",
1653
+ run: cursorDocStart,
1654
+ shift: selectDocStart
1655
+ }, {
1656
+ mac: "Ctrl-ArrowUp",
1657
+ run: cursorPageUp,
1658
+ shift: selectPageUp
1659
+ }, {
1660
+ key: "ArrowDown",
1661
+ run: cursorLineDown,
1662
+ shift: selectLineDown,
1663
+ preventDefault: true
1664
+ }, {
1665
+ mac: "Cmd-ArrowDown",
1666
+ run: cursorDocEnd,
1667
+ shift: selectDocEnd
1668
+ }, {
1669
+ mac: "Ctrl-ArrowDown",
1670
+ run: cursorPageDown,
1671
+ shift: selectPageDown
1672
+ }, {
1673
+ key: "PageUp",
1674
+ run: cursorPageUp,
1675
+ shift: selectPageUp
1676
+ }, {
1677
+ key: "PageDown",
1678
+ run: cursorPageDown,
1679
+ shift: selectPageDown
1680
+ }, {
1681
+ key: "Home",
1682
+ run: cursorLineBoundaryBackward,
1683
+ shift: selectLineBoundaryBackward,
1684
+ preventDefault: true
1685
+ }, {
1686
+ key: "Mod-Home",
1687
+ run: cursorDocStart,
1688
+ shift: selectDocStart
1689
+ }, {
1690
+ key: "End",
1691
+ run: cursorLineBoundaryForward,
1692
+ shift: selectLineBoundaryForward,
1693
+ preventDefault: true
1694
+ }, {
1695
+ key: "Mod-End",
1696
+ run: cursorDocEnd,
1697
+ shift: selectDocEnd
1698
+ }, {
1699
+ key: "Enter",
1700
+ run: insertNewlineAndIndent
1701
+ }, {
1702
+ key: "Mod-a",
1703
+ run: selectAll
1704
+ }, {
1705
+ key: "Backspace",
1706
+ run: deleteCharBackward,
1707
+ shift: deleteCharBackward
1708
+ }, {
1709
+ key: "Delete",
1710
+ run: deleteCharForward
1711
+ }, {
1712
+ key: "Mod-Backspace",
1713
+ mac: "Alt-Backspace",
1714
+ run: deleteGroupBackward
1715
+ }, {
1716
+ key: "Mod-Delete",
1717
+ mac: "Alt-Delete",
1718
+ run: deleteGroupForward
1719
+ }, {
1720
+ mac: "Mod-Backspace",
1721
+ run: deleteToLineStart
1722
+ }, {
1723
+ mac: "Mod-Delete",
1724
+ run: deleteToLineEnd
1725
+ }].concat( /*@__PURE__*/emacsStyleKeymap.map(b => ({
1726
+ mac: b.key,
1727
+ run: b.run,
1728
+ shift: b.shift
1729
+ })));
1730
+ /**
1731
+ The default keymap. Includes all bindings from
1732
+ [`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following:
1733
+
1734
+ - Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift)
1735
+ - Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift)
1736
+ - Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp)
1737
+ - Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown)
1738
+ - Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp)
1739
+ - Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown)
1740
+ - Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection)
1741
+ - Ctrl-Enter (Comd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine)
1742
+ - Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine)
1743
+ - Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax)
1744
+ - Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess)
1745
+ - Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore)
1746
+ - Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection)
1747
+ - Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine)
1748
+ - Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket)
1749
+ - Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment).
1750
+ - Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment).
1751
+ */
1752
+ const defaultKeymap = /*@__PURE__*/[{
1753
+ key: "Alt-ArrowLeft",
1754
+ mac: "Ctrl-ArrowLeft",
1755
+ run: cursorSyntaxLeft,
1756
+ shift: selectSyntaxLeft
1757
+ }, {
1758
+ key: "Alt-ArrowRight",
1759
+ mac: "Ctrl-ArrowRight",
1760
+ run: cursorSyntaxRight,
1761
+ shift: selectSyntaxRight
1762
+ }, {
1763
+ key: "Alt-ArrowUp",
1764
+ run: moveLineUp
1765
+ }, {
1766
+ key: "Shift-Alt-ArrowUp",
1767
+ run: copyLineUp
1768
+ }, {
1769
+ key: "Alt-ArrowDown",
1770
+ run: moveLineDown
1771
+ }, {
1772
+ key: "Shift-Alt-ArrowDown",
1773
+ run: copyLineDown
1774
+ }, {
1775
+ key: "Escape",
1776
+ run: simplifySelection
1777
+ }, {
1778
+ key: "Mod-Enter",
1779
+ run: insertBlankLine
1780
+ }, {
1781
+ key: "Alt-l",
1782
+ mac: "Ctrl-l",
1783
+ run: selectLine
1784
+ }, {
1785
+ key: "Mod-i",
1786
+ run: selectParentSyntax,
1787
+ preventDefault: true
1788
+ }, {
1789
+ key: "Mod-[",
1790
+ run: indentLess
1791
+ }, {
1792
+ key: "Mod-]",
1793
+ run: indentMore
1794
+ }, {
1795
+ key: "Mod-Alt-\\",
1796
+ run: indentSelection
1797
+ }, {
1798
+ key: "Shift-Mod-k",
1799
+ run: deleteLine
1800
+ }, {
1801
+ key: "Shift-Mod-\\",
1802
+ run: cursorMatchingBracket
1803
+ }, {
1804
+ key: "Mod-/",
1805
+ run: toggleComment
1806
+ }, {
1807
+ key: "Alt-A",
1808
+ run: toggleBlockComment
1809
+ }].concat(standardKeymap);
1810
+ /**
1811
+ A binding that binds Tab to [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) and
1812
+ Shift-Tab to [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess).
1813
+ Please see the [Tab example](../../examples/tab/) before using
1814
+ this.
1815
+ */
1816
+ const indentWithTab = {
1817
+ key: "Tab",
1818
+ run: indentMore,
1819
+ shift: indentLess
1820
+ };
1821
+
1822
+ function crelt() {
1823
+ var elt = arguments[0];
1824
+ if (typeof elt == "string") elt = document.createElement(elt);
1825
+ var i = 1,
1826
+ next = arguments[1];
1827
+ if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
1828
+ for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
1829
+ var value = next[name];
1830
+ if (typeof value == "string") elt.setAttribute(name, value);else if (value != null) elt[name] = value;
1831
+ }
1832
+ i++;
1833
+ }
1834
+ for (; i < arguments.length; i++) add(elt, arguments[i]);
1835
+ return elt;
1836
+ }
1837
+ function add(elt, child) {
1838
+ if (typeof child == "string") {
1839
+ elt.appendChild(document.createTextNode(child));
1840
+ } else if (child == null) ; else if (child.nodeType != null) {
1841
+ elt.appendChild(child);
1842
+ } else if (Array.isArray(child)) {
1843
+ for (var i = 0; i < child.length; i++) add(elt, child[i]);
1844
+ } else {
1845
+ throw new RangeError("Unsupported child node: " + child);
1846
+ }
1847
+ }
1848
+
1849
+ const basicNormalize = typeof String.prototype.normalize == "function" ? x => x.normalize("NFKD") : x => x;
1850
+ /**
1851
+ A search cursor provides an iterator over text matches in a
1852
+ document.
1853
+ */
1854
+ class SearchCursor {
1855
+ /**
1856
+ Create a text cursor. The query is the search string, `from` to
1857
+ `to` provides the region to search.
1858
+
1859
+ When `normalize` is given, it will be called, on both the query
1860
+ string and the content it is matched against, before comparing.
1861
+ You can, for example, create a case-insensitive search by
1862
+ passing `s => s.toLowerCase()`.
1863
+
1864
+ Text is always normalized with
1865
+ [`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
1866
+ (when supported).
1867
+ */
1868
+ constructor(text, query) {
1869
+ let from = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1870
+ let to = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : text.length;
1871
+ let normalize = arguments.length > 4 ? arguments[4] : undefined;
1872
+ let test = arguments.length > 5 ? arguments[5] : undefined;
1873
+ this.test = test;
1874
+ /**
1875
+ The current match (only holds a meaningful value after
1876
+ [`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when
1877
+ `done` is false).
1878
+ */
1879
+ this.value = {
1880
+ from: 0,
1881
+ to: 0
1882
+ };
1883
+ /**
1884
+ Whether the end of the iterated region has been reached.
1885
+ */
1886
+ this.done = false;
1887
+ this.matches = [];
1888
+ this.buffer = "";
1889
+ this.bufferPos = 0;
1890
+ this.iter = text.iterRange(from, to);
1891
+ this.bufferStart = from;
1892
+ this.normalize = normalize ? x => normalize(basicNormalize(x)) : basicNormalize;
1893
+ this.query = this.normalize(query);
1894
+ }
1895
+ peek() {
1896
+ if (this.bufferPos == this.buffer.length) {
1897
+ this.bufferStart += this.buffer.length;
1898
+ this.iter.next();
1899
+ if (this.iter.done) return -1;
1900
+ this.bufferPos = 0;
1901
+ this.buffer = this.iter.value;
1902
+ }
1903
+ return codePointAt(this.buffer, this.bufferPos);
1904
+ }
1905
+ /**
1906
+ Look for the next match. Updates the iterator's
1907
+ [`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and
1908
+ [`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called
1909
+ at least once before using the cursor.
1910
+ */
1911
+ next() {
1912
+ while (this.matches.length) this.matches.pop();
1913
+ return this.nextOverlapping();
1914
+ }
1915
+ /**
1916
+ The `next` method will ignore matches that partially overlap a
1917
+ previous match. This method behaves like `next`, but includes
1918
+ such matches.
1919
+ */
1920
+ nextOverlapping() {
1921
+ for (;;) {
1922
+ let next = this.peek();
1923
+ if (next < 0) {
1924
+ this.done = true;
1925
+ return this;
1926
+ }
1927
+ let str = fromCodePoint(next),
1928
+ start = this.bufferStart + this.bufferPos;
1929
+ this.bufferPos += codePointSize(next);
1930
+ let norm = this.normalize(str);
1931
+ for (let i = 0, pos = start;; i++) {
1932
+ let code = norm.charCodeAt(i);
1933
+ let match = this.match(code, pos);
1934
+ if (match) {
1935
+ this.value = match;
1936
+ return this;
1937
+ }
1938
+ if (i == norm.length - 1) break;
1939
+ if (pos == start && i < str.length && str.charCodeAt(i) == code) pos++;
1940
+ }
1941
+ }
1942
+ }
1943
+ match(code, pos) {
1944
+ let match = null;
1945
+ for (let i = 0; i < this.matches.length; i += 2) {
1946
+ let index = this.matches[i],
1947
+ keep = false;
1948
+ if (this.query.charCodeAt(index) == code) {
1949
+ if (index == this.query.length - 1) {
1950
+ match = {
1951
+ from: this.matches[i + 1],
1952
+ to: pos + 1
1953
+ };
1954
+ } else {
1955
+ this.matches[i]++;
1956
+ keep = true;
1957
+ }
1958
+ }
1959
+ if (!keep) {
1960
+ this.matches.splice(i, 2);
1961
+ i -= 2;
1962
+ }
1963
+ }
1964
+ if (this.query.charCodeAt(0) == code) {
1965
+ if (this.query.length == 1) match = {
1966
+ from: pos,
1967
+ to: pos + 1
1968
+ };else this.matches.push(1, pos);
1969
+ }
1970
+ if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos)) match = null;
1971
+ return match;
1972
+ }
1973
+ }
1974
+ if (typeof Symbol != "undefined") SearchCursor.prototype[Symbol.iterator] = function () {
1975
+ return this;
1976
+ };
1977
+ const empty = {
1978
+ from: -1,
1979
+ to: -1,
1980
+ match: /*@__PURE__*/ /.*/.exec("")
1981
+ };
1982
+ const baseFlags = "gm" + (/x/.unicode == null ? "" : "u");
1983
+ /**
1984
+ This class is similar to [`SearchCursor`](https://codemirror.net/6/docs/ref/#search.SearchCursor)
1985
+ but searches for a regular expression pattern instead of a plain
1986
+ string.
1987
+ */
1988
+ class RegExpCursor {
1989
+ /**
1990
+ Create a cursor that will search the given range in the given
1991
+ document. `query` should be the raw pattern (as you'd pass it to
1992
+ `new RegExp`).
1993
+ */
1994
+ constructor(text, query, options) {
1995
+ let from = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1996
+ let to = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : text.length;
1997
+ this.text = text;
1998
+ this.to = to;
1999
+ this.curLine = "";
2000
+ /**
2001
+ Set to `true` when the cursor has reached the end of the search
2002
+ range.
2003
+ */
2004
+ this.done = false;
2005
+ /**
2006
+ Will contain an object with the extent of the match and the
2007
+ match object when [`next`](https://codemirror.net/6/docs/ref/#search.RegExpCursor.next)
2008
+ sucessfully finds a match.
2009
+ */
2010
+ this.value = empty;
2011
+ if (/\\[sWDnr]|\n|\r|\[\^/.test(query)) return new MultilineRegExpCursor(text, query, options, from, to);
2012
+ this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
2013
+ this.test = options === null || options === void 0 ? void 0 : options.test;
2014
+ this.iter = text.iter();
2015
+ let startLine = text.lineAt(from);
2016
+ this.curLineStart = startLine.from;
2017
+ this.matchPos = toCharEnd(text, from);
2018
+ this.getLine(this.curLineStart);
2019
+ }
2020
+ getLine(skip) {
2021
+ this.iter.next(skip);
2022
+ if (this.iter.lineBreak) {
2023
+ this.curLine = "";
2024
+ } else {
2025
+ this.curLine = this.iter.value;
2026
+ if (this.curLineStart + this.curLine.length > this.to) this.curLine = this.curLine.slice(0, this.to - this.curLineStart);
2027
+ this.iter.next();
2028
+ }
2029
+ }
2030
+ nextLine() {
2031
+ this.curLineStart = this.curLineStart + this.curLine.length + 1;
2032
+ if (this.curLineStart > this.to) this.curLine = "";else this.getLine(0);
2033
+ }
2034
+ /**
2035
+ Move to the next match, if there is one.
2036
+ */
2037
+ next() {
2038
+ for (let off = this.matchPos - this.curLineStart;;) {
2039
+ this.re.lastIndex = off;
2040
+ let match = this.matchPos <= this.to && this.re.exec(this.curLine);
2041
+ if (match) {
2042
+ let from = this.curLineStart + match.index,
2043
+ to = from + match[0].length;
2044
+ this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
2045
+ if (from == this.curLineStart + this.curLine.length) this.nextLine();
2046
+ if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) {
2047
+ this.value = {
2048
+ from,
2049
+ to,
2050
+ match
2051
+ };
2052
+ return this;
2053
+ }
2054
+ off = this.matchPos - this.curLineStart;
2055
+ } else if (this.curLineStart + this.curLine.length < this.to) {
2056
+ this.nextLine();
2057
+ off = 0;
2058
+ } else {
2059
+ this.done = true;
2060
+ return this;
2061
+ }
2062
+ }
2063
+ }
2064
+ }
2065
+ const flattened = /*@__PURE__*/new WeakMap();
2066
+ // Reusable (partially) flattened document strings
2067
+ class FlattenedDoc {
2068
+ constructor(from, text) {
2069
+ this.from = from;
2070
+ this.text = text;
2071
+ }
2072
+ get to() {
2073
+ return this.from + this.text.length;
2074
+ }
2075
+ static get(doc, from, to) {
2076
+ let cached = flattened.get(doc);
2077
+ if (!cached || cached.from >= to || cached.to <= from) {
2078
+ let flat = new FlattenedDoc(from, doc.sliceString(from, to));
2079
+ flattened.set(doc, flat);
2080
+ return flat;
2081
+ }
2082
+ if (cached.from == from && cached.to == to) return cached;
2083
+ let {
2084
+ text,
2085
+ from: cachedFrom
2086
+ } = cached;
2087
+ if (cachedFrom > from) {
2088
+ text = doc.sliceString(from, cachedFrom) + text;
2089
+ cachedFrom = from;
2090
+ }
2091
+ if (cached.to < to) text += doc.sliceString(cached.to, to);
2092
+ flattened.set(doc, new FlattenedDoc(cachedFrom, text));
2093
+ return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom));
2094
+ }
2095
+ }
2096
+ class MultilineRegExpCursor {
2097
+ constructor(text, query, options, from, to) {
2098
+ this.text = text;
2099
+ this.to = to;
2100
+ this.done = false;
2101
+ this.value = empty;
2102
+ this.matchPos = toCharEnd(text, from);
2103
+ this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
2104
+ this.test = options === null || options === void 0 ? void 0 : options.test;
2105
+ this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Chunk.Base */));
2106
+ }
2107
+
2108
+ chunkEnd(pos) {
2109
+ return pos >= this.to ? this.to : this.text.lineAt(pos).to;
2110
+ }
2111
+ next() {
2112
+ for (;;) {
2113
+ let off = this.re.lastIndex = this.matchPos - this.flat.from;
2114
+ let match = this.re.exec(this.flat.text);
2115
+ // Skip empty matches directly after the last match
2116
+ if (match && !match[0] && match.index == off) {
2117
+ this.re.lastIndex = off + 1;
2118
+ match = this.re.exec(this.flat.text);
2119
+ }
2120
+ if (match) {
2121
+ let from = this.flat.from + match.index,
2122
+ to = from + match[0].length;
2123
+ // If a match goes almost to the end of a noncomplete chunk, try
2124
+ // again, since it'll likely be able to match more
2125
+ if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) && (!this.test || this.test(from, to, match))) {
2126
+ this.value = {
2127
+ from,
2128
+ to,
2129
+ match
2130
+ };
2131
+ this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
2132
+ return this;
2133
+ }
2134
+ }
2135
+ if (this.flat.to == this.to) {
2136
+ this.done = true;
2137
+ return this;
2138
+ }
2139
+ // Grow the flattened doc
2140
+ this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
2141
+ }
2142
+ }
2143
+ }
2144
+ if (typeof Symbol != "undefined") {
2145
+ RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = function () {
2146
+ return this;
2147
+ };
2148
+ }
2149
+ function validRegExp(source) {
2150
+ try {
2151
+ new RegExp(source, baseFlags);
2152
+ return true;
2153
+ } catch (_a) {
2154
+ return false;
2155
+ }
2156
+ }
2157
+ function toCharEnd(text, pos) {
2158
+ if (pos >= text.length) return pos;
2159
+ let line = text.lineAt(pos),
2160
+ next;
2161
+ while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000) pos++;
2162
+ return pos;
2163
+ }
2164
+ function createLineDialog(view) {
2165
+ let input = crelt("input", {
2166
+ class: "cm-textfield",
2167
+ name: "line"
2168
+ });
2169
+ let dom = crelt("form", {
2170
+ class: "cm-gotoLine",
2171
+ onkeydown: event => {
2172
+ if (event.keyCode == 27) {
2173
+ // Escape
2174
+ event.preventDefault();
2175
+ view.dispatch({
2176
+ effects: dialogEffect.of(false)
2177
+ });
2178
+ view.focus();
2179
+ } else if (event.keyCode == 13) {
2180
+ // Enter
2181
+ event.preventDefault();
2182
+ go();
2183
+ }
2184
+ },
2185
+ onsubmit: event => {
2186
+ event.preventDefault();
2187
+ go();
2188
+ }
2189
+ }, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", {
2190
+ class: "cm-button",
2191
+ type: "submit"
2192
+ }, view.state.phrase("go")));
2193
+ function go() {
2194
+ let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value);
2195
+ if (!match) return;
2196
+ let {
2197
+ state
2198
+ } = view,
2199
+ startLine = state.doc.lineAt(state.selection.main.head);
2200
+ let [, sign, ln, cl, percent] = match;
2201
+ let col = cl ? +cl.slice(1) : 0;
2202
+ let line = ln ? +ln : startLine.number;
2203
+ if (ln && percent) {
2204
+ let pc = line / 100;
2205
+ if (sign) pc = pc * (sign == "-" ? -1 : 1) + startLine.number / state.doc.lines;
2206
+ line = Math.round(state.doc.lines * pc);
2207
+ } else if (ln && sign) {
2208
+ line = line * (sign == "-" ? -1 : 1) + startLine.number;
2209
+ }
2210
+ let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line)));
2211
+ view.dispatch({
2212
+ effects: dialogEffect.of(false),
2213
+ selection: EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))),
2214
+ scrollIntoView: true
2215
+ });
2216
+ view.focus();
2217
+ }
2218
+ return {
2219
+ dom
2220
+ };
2221
+ }
2222
+ const dialogEffect = /*@__PURE__*/StateEffect.define();
2223
+ const dialogField = /*@__PURE__*/StateField.define({
2224
+ create() {
2225
+ return true;
2226
+ },
2227
+ update(value, tr) {
2228
+ for (let e of tr.effects) if (e.is(dialogEffect)) value = e.value;
2229
+ return value;
2230
+ },
2231
+ provide: f => showPanel.from(f, val => val ? createLineDialog : null)
2232
+ });
2233
+ /**
2234
+ Command that shows a dialog asking the user for a line number, and
2235
+ when a valid position is provided, moves the cursor to that line.
2236
+
2237
+ Supports line numbers, relative line offsets prefixed with `+` or
2238
+ `-`, document percentages suffixed with `%`, and an optional
2239
+ column position by adding `:` and a second number after the line
2240
+ number.
2241
+ */
2242
+ const gotoLine = view => {
2243
+ let panel = getPanel(view, createLineDialog);
2244
+ if (!panel) {
2245
+ let effects = [dialogEffect.of(true)];
2246
+ if (view.state.field(dialogField, false) == null) effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1]));
2247
+ view.dispatch({
2248
+ effects
2249
+ });
2250
+ panel = getPanel(view, createLineDialog);
2251
+ }
2252
+ if (panel) panel.dom.querySelector("input").focus();
2253
+ return true;
2254
+ };
2255
+ const baseTheme$1 = /*@__PURE__*/EditorView.baseTheme({
2256
+ ".cm-panel.cm-gotoLine": {
2257
+ padding: "2px 6px 4px",
2258
+ "& label": {
2259
+ fontSize: "80%"
2260
+ }
2261
+ }
2262
+ });
2263
+ const defaultHighlightOptions = {
2264
+ highlightWordAroundCursor: false,
2265
+ minSelectionLength: 1,
2266
+ maxMatches: 100,
2267
+ wholeWords: false
2268
+ };
2269
+ const highlightConfig = /*@__PURE__*/Facet.define({
2270
+ combine(options) {
2271
+ return combineConfig(options, defaultHighlightOptions, {
2272
+ highlightWordAroundCursor: (a, b) => a || b,
2273
+ minSelectionLength: Math.min,
2274
+ maxMatches: Math.min
2275
+ });
2276
+ }
2277
+ });
2278
+ /**
2279
+ This extension highlights text that matches the selection. It uses
2280
+ the `"cm-selectionMatch"` class for the highlighting. When
2281
+ `highlightWordAroundCursor` is enabled, the word at the cursor
2282
+ itself will be highlighted with `"cm-selectionMatch-main"`.
2283
+ */
2284
+ function highlightSelectionMatches(options) {
2285
+ let ext = [defaultTheme, matchHighlighter];
2286
+ if (options) ext.push(highlightConfig.of(options));
2287
+ return ext;
2288
+ }
2289
+ const matchDeco = /*@__PURE__*/Decoration.mark({
2290
+ class: "cm-selectionMatch"
2291
+ });
2292
+ const mainMatchDeco = /*@__PURE__*/Decoration.mark({
2293
+ class: "cm-selectionMatch cm-selectionMatch-main"
2294
+ });
2295
+ // Whether the characters directly outside the given positions are non-word characters
2296
+ function insideWordBoundaries(check, state, from, to) {
2297
+ return (from == 0 || check(state.sliceDoc(from - 1, from)) != CharCategory.Word) && (to == state.doc.length || check(state.sliceDoc(to, to + 1)) != CharCategory.Word);
2298
+ }
2299
+ // Whether the characters directly at the given positions are word characters
2300
+ function insideWord(check, state, from, to) {
2301
+ return check(state.sliceDoc(from, from + 1)) == CharCategory.Word && check(state.sliceDoc(to - 1, to)) == CharCategory.Word;
2302
+ }
2303
+ const matchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class {
2304
+ constructor(view) {
2305
+ this.decorations = this.getDeco(view);
2306
+ }
2307
+ update(update) {
2308
+ if (update.selectionSet || update.docChanged || update.viewportChanged) this.decorations = this.getDeco(update.view);
2309
+ }
2310
+ getDeco(view) {
2311
+ let conf = view.state.facet(highlightConfig);
2312
+ let {
2313
+ state
2314
+ } = view,
2315
+ sel = state.selection;
2316
+ if (sel.ranges.length > 1) return Decoration.none;
2317
+ let range = sel.main,
2318
+ query,
2319
+ check = null;
2320
+ if (range.empty) {
2321
+ if (!conf.highlightWordAroundCursor) return Decoration.none;
2322
+ let word = state.wordAt(range.head);
2323
+ if (!word) return Decoration.none;
2324
+ check = state.charCategorizer(range.head);
2325
+ query = state.sliceDoc(word.from, word.to);
2326
+ } else {
2327
+ let len = range.to - range.from;
2328
+ if (len < conf.minSelectionLength || len > 200) return Decoration.none;
2329
+ if (conf.wholeWords) {
2330
+ query = state.sliceDoc(range.from, range.to); // TODO: allow and include leading/trailing space?
2331
+ check = state.charCategorizer(range.head);
2332
+ if (!(insideWordBoundaries(check, state, range.from, range.to) && insideWord(check, state, range.from, range.to))) return Decoration.none;
2333
+ } else {
2334
+ query = state.sliceDoc(range.from, range.to).trim();
2335
+ if (!query) return Decoration.none;
2336
+ }
2337
+ }
2338
+ let deco = [];
2339
+ for (let part of view.visibleRanges) {
2340
+ let cursor = new SearchCursor(state.doc, query, part.from, part.to);
2341
+ while (!cursor.next().done) {
2342
+ let {
2343
+ from,
2344
+ to
2345
+ } = cursor.value;
2346
+ if (!check || insideWordBoundaries(check, state, from, to)) {
2347
+ if (range.empty && from <= range.from && to >= range.to) deco.push(mainMatchDeco.range(from, to));else if (from >= range.to || to <= range.from) deco.push(matchDeco.range(from, to));
2348
+ if (deco.length > conf.maxMatches) return Decoration.none;
2349
+ }
2350
+ }
2351
+ }
2352
+ return Decoration.set(deco);
2353
+ }
2354
+ }, {
2355
+ decorations: v => v.decorations
2356
+ });
2357
+ const defaultTheme = /*@__PURE__*/EditorView.baseTheme({
2358
+ ".cm-selectionMatch": {
2359
+ backgroundColor: "#99ff7780"
2360
+ },
2361
+ ".cm-searchMatch .cm-selectionMatch": {
2362
+ backgroundColor: "transparent"
2363
+ }
2364
+ });
2365
+ // Select the words around the cursors.
2366
+ const selectWord = _ref => {
2367
+ let {
2368
+ state,
2369
+ dispatch
2370
+ } = _ref;
2371
+ let {
2372
+ selection
2373
+ } = state;
2374
+ let newSel = EditorSelection.create(selection.ranges.map(range => state.wordAt(range.head) || EditorSelection.cursor(range.head)), selection.mainIndex);
2375
+ if (newSel.eq(selection)) return false;
2376
+ dispatch(state.update({
2377
+ selection: newSel
2378
+ }));
2379
+ return true;
2380
+ };
2381
+ // Find next occurrence of query relative to last cursor. Wrap around
2382
+ // the document if there are no more matches.
2383
+ function findNextOccurrence(state, query) {
2384
+ let {
2385
+ main,
2386
+ ranges
2387
+ } = state.selection;
2388
+ let word = state.wordAt(main.head),
2389
+ fullWord = word && word.from == main.from && word.to == main.to;
2390
+ for (let cycled = false, cursor = new SearchCursor(state.doc, query, ranges[ranges.length - 1].to);;) {
2391
+ cursor.next();
2392
+ if (cursor.done) {
2393
+ if (cycled) return null;
2394
+ cursor = new SearchCursor(state.doc, query, 0, Math.max(0, ranges[ranges.length - 1].from - 1));
2395
+ cycled = true;
2396
+ } else {
2397
+ if (cycled && ranges.some(r => r.from == cursor.value.from)) continue;
2398
+ if (fullWord) {
2399
+ let word = state.wordAt(cursor.value.from);
2400
+ if (!word || word.from != cursor.value.from || word.to != cursor.value.to) continue;
2401
+ }
2402
+ return cursor.value;
2403
+ }
2404
+ }
2405
+ }
2406
+ /**
2407
+ Select next occurrence of the current selection. Expand selection
2408
+ to the surrounding word when the selection is empty.
2409
+ */
2410
+ const selectNextOccurrence = _ref2 => {
2411
+ let {
2412
+ state,
2413
+ dispatch
2414
+ } = _ref2;
2415
+ let {
2416
+ ranges
2417
+ } = state.selection;
2418
+ if (ranges.some(sel => sel.from === sel.to)) return selectWord({
2419
+ state,
2420
+ dispatch
2421
+ });
2422
+ let searchedText = state.sliceDoc(ranges[0].from, ranges[0].to);
2423
+ if (state.selection.ranges.some(r => state.sliceDoc(r.from, r.to) != searchedText)) return false;
2424
+ let range = findNextOccurrence(state, searchedText);
2425
+ if (!range) return false;
2426
+ dispatch(state.update({
2427
+ selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false),
2428
+ effects: EditorView.scrollIntoView(range.to)
2429
+ }));
2430
+ return true;
2431
+ };
2432
+ const searchConfigFacet = /*@__PURE__*/Facet.define({
2433
+ combine(configs) {
2434
+ return combineConfig(configs, {
2435
+ top: false,
2436
+ caseSensitive: false,
2437
+ literal: false,
2438
+ wholeWord: false,
2439
+ createPanel: view => new SearchPanel(view),
2440
+ scrollToMatch: range => EditorView.scrollIntoView(range)
2441
+ });
2442
+ }
2443
+ });
2444
+ /**
2445
+ A search query. Part of the editor's search state.
2446
+ */
2447
+ class SearchQuery {
2448
+ /**
2449
+ Create a query object.
2450
+ */
2451
+ constructor(config) {
2452
+ this.search = config.search;
2453
+ this.caseSensitive = !!config.caseSensitive;
2454
+ this.literal = !!config.literal;
2455
+ this.regexp = !!config.regexp;
2456
+ this.replace = config.replace || "";
2457
+ this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
2458
+ this.unquoted = this.unquote(this.search);
2459
+ this.wholeWord = !!config.wholeWord;
2460
+ }
2461
+ /**
2462
+ @internal
2463
+ */
2464
+ unquote(text) {
2465
+ return this.literal ? text : text.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\");
2466
+ }
2467
+ /**
2468
+ Compare this query to another query.
2469
+ */
2470
+ eq(other) {
2471
+ return this.search == other.search && this.replace == other.replace && this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && this.wholeWord == other.wholeWord;
2472
+ }
2473
+ /**
2474
+ @internal
2475
+ */
2476
+ create() {
2477
+ return this.regexp ? new RegExpQuery(this) : new StringQuery(this);
2478
+ }
2479
+ /**
2480
+ Get a search cursor for this query, searching through the given
2481
+ range in the given state.
2482
+ */
2483
+ getCursor(state) {
2484
+ let from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2485
+ let to = arguments.length > 2 ? arguments[2] : undefined;
2486
+ let st = state.doc ? state : EditorState.create({
2487
+ doc: state
2488
+ });
2489
+ if (to == null) to = st.doc.length;
2490
+ return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to);
2491
+ }
2492
+ }
2493
+ class QueryType {
2494
+ constructor(spec) {
2495
+ this.spec = spec;
2496
+ }
2497
+ }
2498
+ function stringCursor(spec, state, from, to) {
2499
+ return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
2500
+ }
2501
+ function stringWordTest(doc, categorizer) {
2502
+ return (from, to, buf, bufPos) => {
2503
+ if (bufPos > from || bufPos + buf.length < to) {
2504
+ bufPos = Math.max(0, from - 2);
2505
+ buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2));
2506
+ }
2507
+ return (categorizer(charBefore(buf, from - bufPos)) != CharCategory.Word || categorizer(charAfter(buf, from - bufPos)) != CharCategory.Word) && (categorizer(charAfter(buf, to - bufPos)) != CharCategory.Word || categorizer(charBefore(buf, to - bufPos)) != CharCategory.Word);
2508
+ };
2509
+ }
2510
+ class StringQuery extends QueryType {
2511
+ constructor(spec) {
2512
+ super(spec);
2513
+ }
2514
+ nextMatch(state, curFrom, curTo) {
2515
+ let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
2516
+ if (cursor.done) cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
2517
+ return cursor.done ? null : cursor.value;
2518
+ }
2519
+ // Searching in reverse is, rather than implementing inverted search
2520
+ // cursor, done by scanning chunk after chunk forward.
2521
+ prevMatchInRange(state, from, to) {
2522
+ for (let pos = to;;) {
2523
+ let start = Math.max(from, pos - 10000 /* FindPrev.ChunkSize */ - this.spec.unquoted.length);
2524
+ let cursor = stringCursor(this.spec, state, start, pos),
2525
+ range = null;
2526
+ while (!cursor.nextOverlapping().done) range = cursor.value;
2527
+ if (range) return range;
2528
+ if (start == from) return null;
2529
+ pos -= 10000 /* FindPrev.ChunkSize */;
2530
+ }
2531
+ }
2532
+
2533
+ prevMatch(state, curFrom, curTo) {
2534
+ return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
2535
+ }
2536
+ getReplacement(_result) {
2537
+ return this.spec.unquote(this.spec.replace);
2538
+ }
2539
+ matchAll(state, limit) {
2540
+ let cursor = stringCursor(this.spec, state, 0, state.doc.length),
2541
+ ranges = [];
2542
+ while (!cursor.next().done) {
2543
+ if (ranges.length >= limit) return null;
2544
+ ranges.push(cursor.value);
2545
+ }
2546
+ return ranges;
2547
+ }
2548
+ highlight(state, from, to, add) {
2549
+ let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length));
2550
+ while (!cursor.next().done) add(cursor.value.from, cursor.value.to);
2551
+ }
2552
+ }
2553
+ function regexpCursor(spec, state, from, to) {
2554
+ return new RegExpCursor(state.doc, spec.search, {
2555
+ ignoreCase: !spec.caseSensitive,
2556
+ test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
2557
+ }, from, to);
2558
+ }
2559
+ function charBefore(str, index) {
2560
+ return str.slice(findClusterBreak(str, index, false), index);
2561
+ }
2562
+ function charAfter(str, index) {
2563
+ return str.slice(index, findClusterBreak(str, index));
2564
+ }
2565
+ function regexpWordTest(categorizer) {
2566
+ return (_from, _to, match) => !match[0].length || (categorizer(charBefore(match.input, match.index)) != CharCategory.Word || categorizer(charAfter(match.input, match.index)) != CharCategory.Word) && (categorizer(charAfter(match.input, match.index + match[0].length)) != CharCategory.Word || categorizer(charBefore(match.input, match.index + match[0].length)) != CharCategory.Word);
2567
+ }
2568
+ class RegExpQuery extends QueryType {
2569
+ nextMatch(state, curFrom, curTo) {
2570
+ let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next();
2571
+ if (cursor.done) cursor = regexpCursor(this.spec, state, 0, curFrom).next();
2572
+ return cursor.done ? null : cursor.value;
2573
+ }
2574
+ prevMatchInRange(state, from, to) {
2575
+ for (let size = 1;; size++) {
2576
+ let start = Math.max(from, to - size * 10000 /* FindPrev.ChunkSize */);
2577
+ let cursor = regexpCursor(this.spec, state, start, to),
2578
+ range = null;
2579
+ while (!cursor.next().done) range = cursor.value;
2580
+ if (range && (start == from || range.from > start + 10)) return range;
2581
+ if (start == from) return null;
2582
+ }
2583
+ }
2584
+ prevMatch(state, curFrom, curTo) {
2585
+ return this.prevMatchInRange(state, 0, curFrom) || this.prevMatchInRange(state, curTo, state.doc.length);
2586
+ }
2587
+ getReplacement(result) {
2588
+ return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" : i == "&" ? result.match[0] : i != "0" && +i < result.match.length ? result.match[i] : m));
2589
+ }
2590
+ matchAll(state, limit) {
2591
+ let cursor = regexpCursor(this.spec, state, 0, state.doc.length),
2592
+ ranges = [];
2593
+ while (!cursor.next().done) {
2594
+ if (ranges.length >= limit) return null;
2595
+ ranges.push(cursor.value);
2596
+ }
2597
+ return ranges;
2598
+ }
2599
+ highlight(state, from, to, add) {
2600
+ let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* RegExp.HighlightMargin */), Math.min(to + 250 /* RegExp.HighlightMargin */, state.doc.length));
2601
+ while (!cursor.next().done) add(cursor.value.from, cursor.value.to);
2602
+ }
2603
+ }
2604
+ /**
2605
+ A state effect that updates the current search query. Note that
2606
+ this only has an effect if the search state has been initialized
2607
+ (by including [`search`](https://codemirror.net/6/docs/ref/#search.search) in your configuration or
2608
+ by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) at least
2609
+ once).
2610
+ */
2611
+ const setSearchQuery = /*@__PURE__*/StateEffect.define();
2612
+ const togglePanel$1 = /*@__PURE__*/StateEffect.define();
2613
+ const searchState = /*@__PURE__*/StateField.define({
2614
+ create(state) {
2615
+ return new SearchState(defaultQuery(state).create(), null);
2616
+ },
2617
+ update(value, tr) {
2618
+ for (let effect of tr.effects) {
2619
+ if (effect.is(setSearchQuery)) value = new SearchState(effect.value.create(), value.panel);else if (effect.is(togglePanel$1)) value = new SearchState(value.query, effect.value ? createSearchPanel : null);
2620
+ }
2621
+ return value;
2622
+ },
2623
+ provide: f => showPanel.from(f, val => val.panel)
2624
+ });
2625
+ class SearchState {
2626
+ constructor(query, panel) {
2627
+ this.query = query;
2628
+ this.panel = panel;
2629
+ }
2630
+ }
2631
+ const matchMark = /*@__PURE__*/Decoration.mark({
2632
+ class: "cm-searchMatch"
2633
+ }),
2634
+ selectedMatchMark = /*@__PURE__*/Decoration.mark({
2635
+ class: "cm-searchMatch cm-searchMatch-selected"
2636
+ });
2637
+ const searchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class {
2638
+ constructor(view) {
2639
+ this.view = view;
2640
+ this.decorations = this.highlight(view.state.field(searchState));
2641
+ }
2642
+ update(update) {
2643
+ let state = update.state.field(searchState);
2644
+ if (state != update.startState.field(searchState) || update.docChanged || update.selectionSet || update.viewportChanged) this.decorations = this.highlight(state);
2645
+ }
2646
+ highlight(_ref3) {
2647
+ let {
2648
+ query,
2649
+ panel
2650
+ } = _ref3;
2651
+ if (!panel || !query.spec.valid) return Decoration.none;
2652
+ let {
2653
+ view
2654
+ } = this;
2655
+ let builder = new RangeSetBuilder();
2656
+ for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) {
2657
+ let {
2658
+ from,
2659
+ to
2660
+ } = ranges[i];
2661
+ while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* RegExp.HighlightMargin */) to = ranges[++i].to;
2662
+ query.highlight(view.state, from, to, (from, to) => {
2663
+ let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to);
2664
+ builder.add(from, to, selected ? selectedMatchMark : matchMark);
2665
+ });
2666
+ }
2667
+ return builder.finish();
2668
+ }
2669
+ }, {
2670
+ decorations: v => v.decorations
2671
+ });
2672
+ function searchCommand(f) {
2673
+ return view => {
2674
+ let state = view.state.field(searchState, false);
2675
+ return state && state.query.spec.valid ? f(view, state) : openSearchPanel(view);
2676
+ };
2677
+ }
2678
+ /**
2679
+ Open the search panel if it isn't already open, and move the
2680
+ selection to the first match after the current main selection.
2681
+ Will wrap around to the start of the document when it reaches the
2682
+ end.
2683
+ */
2684
+ const findNext = /*@__PURE__*/searchCommand((view, _ref4) => {
2685
+ let {
2686
+ query
2687
+ } = _ref4;
2688
+ let {
2689
+ to
2690
+ } = view.state.selection.main;
2691
+ let next = query.nextMatch(view.state, to, to);
2692
+ if (!next) return false;
2693
+ let selection = EditorSelection.single(next.from, next.to);
2694
+ let config = view.state.facet(searchConfigFacet);
2695
+ view.dispatch({
2696
+ selection,
2697
+ effects: [announceMatch(view, next), config.scrollToMatch(selection.main)],
2698
+ userEvent: "select.search"
2699
+ });
2700
+ return true;
2701
+ });
2702
+ /**
2703
+ Move the selection to the previous instance of the search query,
2704
+ before the current main selection. Will wrap past the start
2705
+ of the document to start searching at the end again.
2706
+ */
2707
+ const findPrevious = /*@__PURE__*/searchCommand((view, _ref5) => {
2708
+ let {
2709
+ query
2710
+ } = _ref5;
2711
+ let {
2712
+ state
2713
+ } = view,
2714
+ {
2715
+ from
2716
+ } = state.selection.main;
2717
+ let prev = query.prevMatch(state, from, from);
2718
+ if (!prev) return false;
2719
+ let selection = EditorSelection.single(prev.from, prev.to);
2720
+ let config = view.state.facet(searchConfigFacet);
2721
+ view.dispatch({
2722
+ selection,
2723
+ effects: [announceMatch(view, prev), config.scrollToMatch(selection.main)],
2724
+ userEvent: "select.search"
2725
+ });
2726
+ return true;
2727
+ });
2728
+ /**
2729
+ Select all instances of the search query.
2730
+ */
2731
+ const selectMatches = /*@__PURE__*/searchCommand((view, _ref6) => {
2732
+ let {
2733
+ query
2734
+ } = _ref6;
2735
+ let ranges = query.matchAll(view.state, 1000);
2736
+ if (!ranges || !ranges.length) return false;
2737
+ view.dispatch({
2738
+ selection: EditorSelection.create(ranges.map(r => EditorSelection.range(r.from, r.to))),
2739
+ userEvent: "select.search.matches"
2740
+ });
2741
+ return true;
2742
+ });
2743
+ /**
2744
+ Select all instances of the currently selected text.
2745
+ */
2746
+ const selectSelectionMatches = _ref7 => {
2747
+ let {
2748
+ state,
2749
+ dispatch
2750
+ } = _ref7;
2751
+ let sel = state.selection;
2752
+ if (sel.ranges.length > 1 || sel.main.empty) return false;
2753
+ let {
2754
+ from,
2755
+ to
2756
+ } = sel.main;
2757
+ let ranges = [],
2758
+ main = 0;
2759
+ for (let cur = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur.next().done;) {
2760
+ if (ranges.length > 1000) return false;
2761
+ if (cur.value.from == from) main = ranges.length;
2762
+ ranges.push(EditorSelection.range(cur.value.from, cur.value.to));
2763
+ }
2764
+ dispatch(state.update({
2765
+ selection: EditorSelection.create(ranges, main),
2766
+ userEvent: "select.search.matches"
2767
+ }));
2768
+ return true;
2769
+ };
2770
+ /**
2771
+ Replace the current match of the search query.
2772
+ */
2773
+ const replaceNext = /*@__PURE__*/searchCommand((view, _ref8) => {
2774
+ let {
2775
+ query
2776
+ } = _ref8;
2777
+ let {
2778
+ state
2779
+ } = view,
2780
+ {
2781
+ from,
2782
+ to
2783
+ } = state.selection.main;
2784
+ if (state.readOnly) return false;
2785
+ let next = query.nextMatch(state, from, from);
2786
+ if (!next) return false;
2787
+ let changes = [],
2788
+ selection,
2789
+ replacement;
2790
+ let effects = [];
2791
+ if (next.from == from && next.to == to) {
2792
+ replacement = state.toText(query.getReplacement(next));
2793
+ changes.push({
2794
+ from: next.from,
2795
+ to: next.to,
2796
+ insert: replacement
2797
+ });
2798
+ next = query.nextMatch(state, next.from, next.to);
2799
+ effects.push(EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
2800
+ }
2801
+ if (next) {
2802
+ let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length;
2803
+ selection = EditorSelection.single(next.from - off, next.to - off);
2804
+ effects.push(announceMatch(view, next));
2805
+ effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main));
2806
+ }
2807
+ view.dispatch({
2808
+ changes,
2809
+ selection,
2810
+ effects,
2811
+ userEvent: "input.replace"
2812
+ });
2813
+ return true;
2814
+ });
2815
+ /**
2816
+ Replace all instances of the search query with the given
2817
+ replacement.
2818
+ */
2819
+ const replaceAll = /*@__PURE__*/searchCommand((view, _ref9) => {
2820
+ let {
2821
+ query
2822
+ } = _ref9;
2823
+ if (view.state.readOnly) return false;
2824
+ let changes = query.matchAll(view.state, 1e9).map(match => {
2825
+ let {
2826
+ from,
2827
+ to
2828
+ } = match;
2829
+ return {
2830
+ from,
2831
+ to,
2832
+ insert: query.getReplacement(match)
2833
+ };
2834
+ });
2835
+ if (!changes.length) return false;
2836
+ let announceText = view.state.phrase("replaced $ matches", changes.length) + ".";
2837
+ view.dispatch({
2838
+ changes,
2839
+ effects: EditorView.announce.of(announceText),
2840
+ userEvent: "input.replace.all"
2841
+ });
2842
+ return true;
2843
+ });
2844
+ function createSearchPanel(view) {
2845
+ return view.state.facet(searchConfigFacet).createPanel(view);
2846
+ }
2847
+ function defaultQuery(state, fallback) {
2848
+ var _a, _b, _c, _d;
2849
+ let sel = state.selection.main;
2850
+ let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
2851
+ if (fallback && !selText) return fallback;
2852
+ let config = state.facet(searchConfigFacet);
2853
+ return new SearchQuery({
2854
+ search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"),
2855
+ caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive,
2856
+ literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal,
2857
+ wholeWord: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _d !== void 0 ? _d : config.wholeWord
2858
+ });
2859
+ }
2860
+ /**
2861
+ Make sure the search panel is open and focused.
2862
+ */
2863
+ const openSearchPanel = view => {
2864
+ let state = view.state.field(searchState, false);
2865
+ if (state && state.panel) {
2866
+ let panel = getPanel(view, createSearchPanel);
2867
+ if (!panel) return false;
2868
+ let searchInput = panel.dom.querySelector("[main-field]");
2869
+ if (searchInput && searchInput != view.root.activeElement) {
2870
+ let query = defaultQuery(view.state, state.query.spec);
2871
+ if (query.valid) view.dispatch({
2872
+ effects: setSearchQuery.of(query)
2873
+ });
2874
+ searchInput.focus();
2875
+ searchInput.select();
2876
+ }
2877
+ } else {
2878
+ view.dispatch({
2879
+ effects: [togglePanel$1.of(true), state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions)]
2880
+ });
2881
+ }
2882
+ return true;
2883
+ };
2884
+ /**
2885
+ Close the search panel.
2886
+ */
2887
+ const closeSearchPanel = view => {
2888
+ let state = view.state.field(searchState, false);
2889
+ if (!state || !state.panel) return false;
2890
+ let panel = getPanel(view, createSearchPanel);
2891
+ if (panel && panel.dom.contains(view.root.activeElement)) view.focus();
2892
+ view.dispatch({
2893
+ effects: togglePanel$1.of(false)
2894
+ });
2895
+ return true;
2896
+ };
2897
+ /**
2898
+ Default search-related key bindings.
2899
+
2900
+ - Mod-f: [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel)
2901
+ - F3, Mod-g: [`findNext`](https://codemirror.net/6/docs/ref/#search.findNext)
2902
+ - Shift-F3, Shift-Mod-g: [`findPrevious`](https://codemirror.net/6/docs/ref/#search.findPrevious)
2903
+ - Alt-g: [`gotoLine`](https://codemirror.net/6/docs/ref/#search.gotoLine)
2904
+ - Mod-d: [`selectNextOccurrence`](https://codemirror.net/6/docs/ref/#search.selectNextOccurrence)
2905
+ */
2906
+ const searchKeymap = [{
2907
+ key: "Mod-f",
2908
+ run: openSearchPanel,
2909
+ scope: "editor search-panel"
2910
+ }, {
2911
+ key: "F3",
2912
+ run: findNext,
2913
+ shift: findPrevious,
2914
+ scope: "editor search-panel",
2915
+ preventDefault: true
2916
+ }, {
2917
+ key: "Mod-g",
2918
+ run: findNext,
2919
+ shift: findPrevious,
2920
+ scope: "editor search-panel",
2921
+ preventDefault: true
2922
+ }, {
2923
+ key: "Escape",
2924
+ run: closeSearchPanel,
2925
+ scope: "editor search-panel"
2926
+ }, {
2927
+ key: "Mod-Shift-l",
2928
+ run: selectSelectionMatches
2929
+ }, {
2930
+ key: "Alt-g",
2931
+ run: gotoLine
2932
+ }, {
2933
+ key: "Mod-d",
2934
+ run: selectNextOccurrence,
2935
+ preventDefault: true
2936
+ }];
2937
+ class SearchPanel {
2938
+ constructor(view) {
2939
+ this.view = view;
2940
+ let query = this.query = view.state.field(searchState).query.spec;
2941
+ this.commit = this.commit.bind(this);
2942
+ this.searchField = crelt("input", {
2943
+ value: query.search,
2944
+ placeholder: phrase(view, "Find"),
2945
+ "aria-label": phrase(view, "Find"),
2946
+ class: "cm-textfield",
2947
+ name: "search",
2948
+ form: "",
2949
+ "main-field": "true",
2950
+ onchange: this.commit,
2951
+ onkeyup: this.commit
2952
+ });
2953
+ this.replaceField = crelt("input", {
2954
+ value: query.replace,
2955
+ placeholder: phrase(view, "Replace"),
2956
+ "aria-label": phrase(view, "Replace"),
2957
+ class: "cm-textfield",
2958
+ name: "replace",
2959
+ form: "",
2960
+ onchange: this.commit,
2961
+ onkeyup: this.commit
2962
+ });
2963
+ this.caseField = crelt("input", {
2964
+ type: "checkbox",
2965
+ name: "case",
2966
+ form: "",
2967
+ checked: query.caseSensitive,
2968
+ onchange: this.commit
2969
+ });
2970
+ this.reField = crelt("input", {
2971
+ type: "checkbox",
2972
+ name: "re",
2973
+ form: "",
2974
+ checked: query.regexp,
2975
+ onchange: this.commit
2976
+ });
2977
+ this.wordField = crelt("input", {
2978
+ type: "checkbox",
2979
+ name: "word",
2980
+ form: "",
2981
+ checked: query.wholeWord,
2982
+ onchange: this.commit
2983
+ });
2984
+ function button(name, onclick, content) {
2985
+ return crelt("button", {
2986
+ class: "cm-button",
2987
+ name,
2988
+ onclick,
2989
+ type: "button"
2990
+ }, content);
2991
+ }
2992
+ this.dom = crelt("div", {
2993
+ onkeydown: e => this.keydown(e),
2994
+ class: "cm-search"
2995
+ }, [this.searchField, button("next", () => findNext(view), [phrase(view, "next")]), button("prev", () => findPrevious(view), [phrase(view, "previous")]), button("select", () => selectMatches(view), [phrase(view, "all")]), crelt("label", null, [this.caseField, phrase(view, "match case")]), crelt("label", null, [this.reField, phrase(view, "regexp")]), crelt("label", null, [this.wordField, phrase(view, "by word")]), ...(view.state.readOnly ? [] : [crelt("br"), this.replaceField, button("replace", () => replaceNext(view), [phrase(view, "replace")]), button("replaceAll", () => replaceAll(view), [phrase(view, "replace all")])]), crelt("button", {
2996
+ name: "close",
2997
+ onclick: () => closeSearchPanel(view),
2998
+ "aria-label": phrase(view, "close"),
2999
+ type: "button"
3000
+ }, ["×"])]);
3001
+ }
3002
+ commit() {
3003
+ let query = new SearchQuery({
3004
+ search: this.searchField.value,
3005
+ caseSensitive: this.caseField.checked,
3006
+ regexp: this.reField.checked,
3007
+ wholeWord: this.wordField.checked,
3008
+ replace: this.replaceField.value
3009
+ });
3010
+ if (!query.eq(this.query)) {
3011
+ this.query = query;
3012
+ this.view.dispatch({
3013
+ effects: setSearchQuery.of(query)
3014
+ });
3015
+ }
3016
+ }
3017
+ keydown(e) {
3018
+ if (runScopeHandlers(this.view, e, "search-panel")) {
3019
+ e.preventDefault();
3020
+ } else if (e.keyCode == 13 && e.target == this.searchField) {
3021
+ e.preventDefault();
3022
+ (e.shiftKey ? findPrevious : findNext)(this.view);
3023
+ } else if (e.keyCode == 13 && e.target == this.replaceField) {
3024
+ e.preventDefault();
3025
+ replaceNext(this.view);
3026
+ }
3027
+ }
3028
+ update(update) {
3029
+ for (let tr of update.transactions) for (let effect of tr.effects) {
3030
+ if (effect.is(setSearchQuery) && !effect.value.eq(this.query)) this.setQuery(effect.value);
3031
+ }
3032
+ }
3033
+ setQuery(query) {
3034
+ this.query = query;
3035
+ this.searchField.value = query.search;
3036
+ this.replaceField.value = query.replace;
3037
+ this.caseField.checked = query.caseSensitive;
3038
+ this.reField.checked = query.regexp;
3039
+ this.wordField.checked = query.wholeWord;
3040
+ }
3041
+ mount() {
3042
+ this.searchField.select();
3043
+ }
3044
+ get pos() {
3045
+ return 80;
3046
+ }
3047
+ get top() {
3048
+ return this.view.state.facet(searchConfigFacet).top;
3049
+ }
3050
+ }
3051
+ function phrase(view, phrase) {
3052
+ return view.state.phrase(phrase);
3053
+ }
3054
+ const AnnounceMargin = 30;
3055
+ const Break = /[\s\.,:;?!]/;
3056
+ function announceMatch(view, _ref10) {
3057
+ let {
3058
+ from,
3059
+ to
3060
+ } = _ref10;
3061
+ let line = view.state.doc.lineAt(from),
3062
+ lineEnd = view.state.doc.lineAt(to).to;
3063
+ let start = Math.max(line.from, from - AnnounceMargin),
3064
+ end = Math.min(lineEnd, to + AnnounceMargin);
3065
+ let text = view.state.sliceDoc(start, end);
3066
+ if (start != line.from) {
3067
+ for (let i = 0; i < AnnounceMargin; i++) if (!Break.test(text[i + 1]) && Break.test(text[i])) {
3068
+ text = text.slice(i);
3069
+ break;
3070
+ }
3071
+ }
3072
+ if (end != lineEnd) {
3073
+ for (let i = text.length - 1; i > text.length - AnnounceMargin; i--) if (!Break.test(text[i - 1]) && Break.test(text[i])) {
3074
+ text = text.slice(0, i);
3075
+ break;
3076
+ }
3077
+ }
3078
+ return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`);
3079
+ }
3080
+ const baseTheme$2 = /*@__PURE__*/EditorView.baseTheme({
3081
+ ".cm-panel.cm-search": {
3082
+ padding: "2px 6px 4px",
3083
+ position: "relative",
3084
+ "& [name=close]": {
3085
+ position: "absolute",
3086
+ top: "0",
3087
+ right: "4px",
3088
+ backgroundColor: "inherit",
3089
+ border: "none",
3090
+ font: "inherit",
3091
+ padding: 0,
3092
+ margin: 0
3093
+ },
3094
+ "& input, & button, & label": {
3095
+ margin: ".2em .6em .2em 0"
3096
+ },
3097
+ "& input[type=checkbox]": {
3098
+ marginRight: ".2em"
3099
+ },
3100
+ "& label": {
3101
+ fontSize: "80%",
3102
+ whiteSpace: "pre"
3103
+ }
3104
+ },
3105
+ "&light .cm-searchMatch": {
3106
+ backgroundColor: "#ffff0054"
3107
+ },
3108
+ "&dark .cm-searchMatch": {
3109
+ backgroundColor: "#00ffff8a"
3110
+ },
3111
+ "&light .cm-searchMatch-selected": {
3112
+ backgroundColor: "#ff6a0054"
3113
+ },
3114
+ "&dark .cm-searchMatch-selected": {
3115
+ backgroundColor: "#ff00ff8a"
3116
+ }
3117
+ });
3118
+ const searchExtensions = [searchState, /*@__PURE__*/Prec.lowest(searchHighlighter), baseTheme$2];
3119
+
3120
+ class SelectedDiagnostic {
3121
+ constructor(from, to, diagnostic) {
3122
+ this.from = from;
3123
+ this.to = to;
3124
+ this.diagnostic = diagnostic;
3125
+ }
3126
+ }
3127
+ class LintState {
3128
+ constructor(diagnostics, panel, selected) {
3129
+ this.diagnostics = diagnostics;
3130
+ this.panel = panel;
3131
+ this.selected = selected;
3132
+ }
3133
+ static init(diagnostics, panel, state) {
3134
+ // Filter the list of diagnostics for which to create markers
3135
+ let markedDiagnostics = diagnostics;
3136
+ let diagnosticFilter = state.facet(lintConfig).markerFilter;
3137
+ if (diagnosticFilter) markedDiagnostics = diagnosticFilter(markedDiagnostics);
3138
+ let ranges = Decoration.set(markedDiagnostics.map(d => {
3139
+ // For zero-length ranges or ranges covering only a line break, create a widget
3140
+ return d.from == d.to || d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from ? Decoration.widget({
3141
+ widget: new DiagnosticWidget(d),
3142
+ diagnostic: d
3143
+ }).range(d.from) : Decoration.mark({
3144
+ attributes: {
3145
+ class: "cm-lintRange cm-lintRange-" + d.severity
3146
+ },
3147
+ diagnostic: d
3148
+ }).range(d.from, d.to);
3149
+ }), true);
3150
+ return new LintState(ranges, panel, findDiagnostic(ranges));
3151
+ }
3152
+ }
3153
+ function findDiagnostic(diagnostics) {
3154
+ let diagnostic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
3155
+ let after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
3156
+ let found = null;
3157
+ diagnostics.between(after, 1e9, (from, to, _ref) => {
3158
+ let {
3159
+ spec
3160
+ } = _ref;
3161
+ if (diagnostic && spec.diagnostic != diagnostic) return;
3162
+ found = new SelectedDiagnostic(from, to, spec.diagnostic);
3163
+ return false;
3164
+ });
3165
+ return found;
3166
+ }
3167
+ function hideTooltip(tr, tooltip) {
3168
+ return !!(tr.effects.some(e => e.is(setDiagnosticsEffect)) || tr.changes.touchesRange(tooltip.pos));
3169
+ }
3170
+ function maybeEnableLint(state, effects) {
3171
+ return state.field(lintState, false) ? effects : effects.concat(StateEffect.appendConfig.of([lintState, EditorView.decorations.compute([lintState], state => {
3172
+ let {
3173
+ selected,
3174
+ panel
3175
+ } = state.field(lintState);
3176
+ return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([activeMark.range(selected.from, selected.to)]);
3177
+ }), hoverTooltip(lintTooltip, {
3178
+ hideOn: hideTooltip
3179
+ }), baseTheme]));
3180
+ }
3181
+ /**
3182
+ Returns a transaction spec which updates the current set of
3183
+ diagnostics, and enables the lint extension if if wasn't already
3184
+ active.
3185
+ */
3186
+ function setDiagnostics(state, diagnostics) {
3187
+ return {
3188
+ effects: maybeEnableLint(state, [setDiagnosticsEffect.of(diagnostics)])
3189
+ };
3190
+ }
3191
+ /**
3192
+ The state effect that updates the set of active diagnostics. Can
3193
+ be useful when writing an extension that needs to track these.
3194
+ */
3195
+ const setDiagnosticsEffect = /*@__PURE__*/StateEffect.define();
3196
+ const togglePanel = /*@__PURE__*/StateEffect.define();
3197
+ const movePanelSelection = /*@__PURE__*/StateEffect.define();
3198
+ const lintState = /*@__PURE__*/StateField.define({
3199
+ create() {
3200
+ return new LintState(Decoration.none, null, null);
3201
+ },
3202
+ update(value, tr) {
3203
+ if (tr.docChanged) {
3204
+ let mapped = value.diagnostics.map(tr.changes),
3205
+ selected = null;
3206
+ if (value.selected) {
3207
+ let selPos = tr.changes.mapPos(value.selected.from, 1);
3208
+ selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
3209
+ }
3210
+ value = new LintState(mapped, value.panel, selected);
3211
+ }
3212
+ for (let effect of tr.effects) {
3213
+ if (effect.is(setDiagnosticsEffect)) {
3214
+ value = LintState.init(effect.value, value.panel, tr.state);
3215
+ } else if (effect.is(togglePanel)) {
3216
+ value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
3217
+ } else if (effect.is(movePanelSelection)) {
3218
+ value = new LintState(value.diagnostics, value.panel, effect.value);
3219
+ }
3220
+ }
3221
+ return value;
3222
+ },
3223
+ provide: f => [showPanel.from(f, val => val.panel), EditorView.decorations.from(f, s => s.diagnostics)]
3224
+ });
3225
+ const activeMark = /*@__PURE__*/Decoration.mark({
3226
+ class: "cm-lintRange cm-lintRange-active"
3227
+ });
3228
+ function lintTooltip(view, pos, side) {
3229
+ let {
3230
+ diagnostics
3231
+ } = view.state.field(lintState);
3232
+ let found = [],
3233
+ stackStart = 2e8,
3234
+ stackEnd = 0;
3235
+ diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, _ref2) => {
3236
+ let {
3237
+ spec
3238
+ } = _ref2;
3239
+ if (pos >= from && pos <= to && (from == to || (pos > from || side > 0) && (pos < to || side < 0))) {
3240
+ found.push(spec.diagnostic);
3241
+ stackStart = Math.min(from, stackStart);
3242
+ stackEnd = Math.max(to, stackEnd);
3243
+ }
3244
+ });
3245
+ let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
3246
+ if (diagnosticFilter) found = diagnosticFilter(found);
3247
+ if (!found.length) return null;
3248
+ return {
3249
+ pos: stackStart,
3250
+ end: stackEnd,
3251
+ above: view.state.doc.lineAt(stackStart).to < stackEnd,
3252
+ create() {
3253
+ return {
3254
+ dom: diagnosticsTooltip(view, found)
3255
+ };
3256
+ }
3257
+ };
3258
+ }
3259
+ function diagnosticsTooltip(view, diagnostics) {
3260
+ return crelt("ul", {
3261
+ class: "cm-tooltip-lint"
3262
+ }, diagnostics.map(d => renderDiagnostic(view, d, false)));
3263
+ }
3264
+ /**
3265
+ Command to open and focus the lint panel.
3266
+ */
3267
+ const openLintPanel = view => {
3268
+ let field = view.state.field(lintState, false);
3269
+ if (!field || !field.panel) view.dispatch({
3270
+ effects: maybeEnableLint(view.state, [togglePanel.of(true)])
3271
+ });
3272
+ let panel = getPanel(view, LintPanel.open);
3273
+ if (panel) panel.dom.querySelector(".cm-panel-lint ul").focus();
3274
+ return true;
3275
+ };
3276
+ /**
3277
+ Command to close the lint panel, when open.
3278
+ */
3279
+ const closeLintPanel = view => {
3280
+ let field = view.state.field(lintState, false);
3281
+ if (!field || !field.panel) return false;
3282
+ view.dispatch({
3283
+ effects: togglePanel.of(false)
3284
+ });
3285
+ return true;
3286
+ };
3287
+ /**
3288
+ Move the selection to the next diagnostic.
3289
+ */
3290
+ const nextDiagnostic = view => {
3291
+ let field = view.state.field(lintState, false);
3292
+ if (!field) return false;
3293
+ let sel = view.state.selection.main,
3294
+ next = field.diagnostics.iter(sel.to + 1);
3295
+ if (!next.value) {
3296
+ next = field.diagnostics.iter(0);
3297
+ if (!next.value || next.from == sel.from && next.to == sel.to) return false;
3298
+ }
3299
+ view.dispatch({
3300
+ selection: {
3301
+ anchor: next.from,
3302
+ head: next.to
3303
+ },
3304
+ scrollIntoView: true
3305
+ });
3306
+ return true;
3307
+ };
3308
+ /**
3309
+ A set of default key bindings for the lint functionality.
3310
+
3311
+ - Ctrl-Shift-m (Cmd-Shift-m on macOS): [`openLintPanel`](https://codemirror.net/6/docs/ref/#lint.openLintPanel)
3312
+ - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
3313
+ */
3314
+ const lintKeymap = [{
3315
+ key: "Mod-Shift-m",
3316
+ run: openLintPanel,
3317
+ preventDefault: true
3318
+ }, {
3319
+ key: "F8",
3320
+ run: nextDiagnostic
3321
+ }];
3322
+ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
3323
+ constructor(view) {
3324
+ this.view = view;
3325
+ this.timeout = -1;
3326
+ this.set = true;
3327
+ let {
3328
+ delay
3329
+ } = view.state.facet(lintConfig);
3330
+ this.lintTime = Date.now() + delay;
3331
+ this.run = this.run.bind(this);
3332
+ this.timeout = setTimeout(this.run, delay);
3333
+ }
3334
+ run() {
3335
+ let now = Date.now();
3336
+ if (now < this.lintTime - 10) {
3337
+ setTimeout(this.run, this.lintTime - now);
3338
+ } else {
3339
+ this.set = false;
3340
+ let {
3341
+ state
3342
+ } = this.view,
3343
+ {
3344
+ sources
3345
+ } = state.facet(lintConfig);
3346
+ Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
3347
+ let all = annotations.reduce((a, b) => a.concat(b));
3348
+ if (this.view.state.doc == state.doc) this.view.dispatch(setDiagnostics(this.view.state, all));
3349
+ }, error => {
3350
+ logException(this.view.state, error);
3351
+ });
3352
+ }
3353
+ }
3354
+ update(update) {
3355
+ let config = update.state.facet(lintConfig);
3356
+ if (update.docChanged || config != update.startState.facet(lintConfig) || config.needsRefresh && config.needsRefresh(update)) {
3357
+ this.lintTime = Date.now() + config.delay;
3358
+ if (!this.set) {
3359
+ this.set = true;
3360
+ this.timeout = setTimeout(this.run, config.delay);
3361
+ }
3362
+ }
3363
+ }
3364
+ force() {
3365
+ if (this.set) {
3366
+ this.lintTime = Date.now();
3367
+ this.run();
3368
+ }
3369
+ }
3370
+ destroy() {
3371
+ clearTimeout(this.timeout);
3372
+ }
3373
+ });
3374
+ const lintConfig = /*@__PURE__*/Facet.define({
3375
+ combine(input) {
3376
+ return Object.assign({
3377
+ sources: input.map(i => i.source)
3378
+ }, combineConfig(input.map(i => i.config), {
3379
+ delay: 750,
3380
+ markerFilter: null,
3381
+ tooltipFilter: null,
3382
+ needsRefresh: null
3383
+ }, {
3384
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
3385
+ }));
3386
+ },
3387
+ enables: lintPlugin
3388
+ });
3389
+ function assignKeys(actions) {
3390
+ let assigned = [];
3391
+ if (actions) actions: for (let {
3392
+ name
3393
+ } of actions) {
3394
+ for (let i = 0; i < name.length; i++) {
3395
+ let ch = name[i];
3396
+ if (/[a-zA-Z]/.test(ch) && !assigned.some(c => c.toLowerCase() == ch.toLowerCase())) {
3397
+ assigned.push(ch);
3398
+ continue actions;
3399
+ }
3400
+ }
3401
+ assigned.push("");
3402
+ }
3403
+ return assigned;
3404
+ }
3405
+ function renderDiagnostic(view, diagnostic, inPanel) {
3406
+ var _a;
3407
+ let keys = inPanel ? assignKeys(diagnostic.actions) : [];
3408
+ return crelt("li", {
3409
+ class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity
3410
+ }, crelt("span", {
3411
+ class: "cm-diagnosticText"
3412
+ }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
3413
+ let fired = false,
3414
+ click = e => {
3415
+ e.preventDefault();
3416
+ if (fired) return;
3417
+ fired = true;
3418
+ let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
3419
+ if (found) action.apply(view, found.from, found.to);
3420
+ };
3421
+ let {
3422
+ name
3423
+ } = action,
3424
+ keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
3425
+ let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex), crelt("u", name.slice(keyIndex, keyIndex + 1)), name.slice(keyIndex + 1)];
3426
+ return crelt("button", {
3427
+ type: "button",
3428
+ class: "cm-diagnosticAction",
3429
+ onclick: click,
3430
+ onmousedown: click,
3431
+ "aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
3432
+ }, nameElt);
3433
+ }), diagnostic.source && crelt("div", {
3434
+ class: "cm-diagnosticSource"
3435
+ }, diagnostic.source));
3436
+ }
3437
+ class DiagnosticWidget extends WidgetType {
3438
+ constructor(diagnostic) {
3439
+ super();
3440
+ this.diagnostic = diagnostic;
3441
+ }
3442
+ eq(other) {
3443
+ return other.diagnostic == this.diagnostic;
3444
+ }
3445
+ toDOM() {
3446
+ return crelt("span", {
3447
+ class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity
3448
+ });
3449
+ }
3450
+ }
3451
+ class PanelItem {
3452
+ constructor(view, diagnostic) {
3453
+ this.diagnostic = diagnostic;
3454
+ this.id = "item_" + Math.floor(Math.random() * 0xffffffff).toString(16);
3455
+ this.dom = renderDiagnostic(view, diagnostic, true);
3456
+ this.dom.id = this.id;
3457
+ this.dom.setAttribute("role", "option");
3458
+ }
3459
+ }
3460
+ class LintPanel {
3461
+ constructor(view) {
3462
+ this.view = view;
3463
+ this.items = [];
3464
+ let onkeydown = event => {
3465
+ if (event.keyCode == 27) {
3466
+ // Escape
3467
+ closeLintPanel(this.view);
3468
+ this.view.focus();
3469
+ } else if (event.keyCode == 38 || event.keyCode == 33) {
3470
+ // ArrowUp, PageUp
3471
+ this.moveSelection((this.selectedIndex - 1 + this.items.length) % this.items.length);
3472
+ } else if (event.keyCode == 40 || event.keyCode == 34) {
3473
+ // ArrowDown, PageDown
3474
+ this.moveSelection((this.selectedIndex + 1) % this.items.length);
3475
+ } else if (event.keyCode == 36) {
3476
+ // Home
3477
+ this.moveSelection(0);
3478
+ } else if (event.keyCode == 35) {
3479
+ // End
3480
+ this.moveSelection(this.items.length - 1);
3481
+ } else if (event.keyCode == 13) {
3482
+ // Enter
3483
+ this.view.focus();
3484
+ } else if (event.keyCode >= 65 && event.keyCode <= 90 && this.selectedIndex >= 0) {
3485
+ // A-Z
3486
+ let {
3487
+ diagnostic
3488
+ } = this.items[this.selectedIndex],
3489
+ keys = assignKeys(diagnostic.actions);
3490
+ for (let i = 0; i < keys.length; i++) if (keys[i].toUpperCase().charCodeAt(0) == event.keyCode) {
3491
+ let found = findDiagnostic(this.view.state.field(lintState).diagnostics, diagnostic);
3492
+ if (found) diagnostic.actions[i].apply(view, found.from, found.to);
3493
+ }
3494
+ } else {
3495
+ return;
3496
+ }
3497
+ event.preventDefault();
3498
+ };
3499
+ let onclick = event => {
3500
+ for (let i = 0; i < this.items.length; i++) {
3501
+ if (this.items[i].dom.contains(event.target)) this.moveSelection(i);
3502
+ }
3503
+ };
3504
+ this.list = crelt("ul", {
3505
+ tabIndex: 0,
3506
+ role: "listbox",
3507
+ "aria-label": this.view.state.phrase("Diagnostics"),
3508
+ onkeydown,
3509
+ onclick
3510
+ });
3511
+ this.dom = crelt("div", {
3512
+ class: "cm-panel-lint"
3513
+ }, this.list, crelt("button", {
3514
+ type: "button",
3515
+ name: "close",
3516
+ "aria-label": this.view.state.phrase("close"),
3517
+ onclick: () => closeLintPanel(this.view)
3518
+ }, "×"));
3519
+ this.update();
3520
+ }
3521
+ get selectedIndex() {
3522
+ let selected = this.view.state.field(lintState).selected;
3523
+ if (!selected) return -1;
3524
+ for (let i = 0; i < this.items.length; i++) if (this.items[i].diagnostic == selected.diagnostic) return i;
3525
+ return -1;
3526
+ }
3527
+ update() {
3528
+ let {
3529
+ diagnostics,
3530
+ selected
3531
+ } = this.view.state.field(lintState);
3532
+ let i = 0,
3533
+ needsSync = false,
3534
+ newSelectedItem = null;
3535
+ diagnostics.between(0, this.view.state.doc.length, (_start, _end, _ref3) => {
3536
+ let {
3537
+ spec
3538
+ } = _ref3;
3539
+ let found = -1,
3540
+ item;
3541
+ for (let j = i; j < this.items.length; j++) if (this.items[j].diagnostic == spec.diagnostic) {
3542
+ found = j;
3543
+ break;
3544
+ }
3545
+ if (found < 0) {
3546
+ item = new PanelItem(this.view, spec.diagnostic);
3547
+ this.items.splice(i, 0, item);
3548
+ needsSync = true;
3549
+ } else {
3550
+ item = this.items[found];
3551
+ if (found > i) {
3552
+ this.items.splice(i, found - i);
3553
+ needsSync = true;
3554
+ }
3555
+ }
3556
+ if (selected && item.diagnostic == selected.diagnostic) {
3557
+ if (!item.dom.hasAttribute("aria-selected")) {
3558
+ item.dom.setAttribute("aria-selected", "true");
3559
+ newSelectedItem = item;
3560
+ }
3561
+ } else if (item.dom.hasAttribute("aria-selected")) {
3562
+ item.dom.removeAttribute("aria-selected");
3563
+ }
3564
+ i++;
3565
+ });
3566
+ while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
3567
+ needsSync = true;
3568
+ this.items.pop();
3569
+ }
3570
+ if (this.items.length == 0) {
3571
+ this.items.push(new PanelItem(this.view, {
3572
+ from: -1,
3573
+ to: -1,
3574
+ severity: "info",
3575
+ message: this.view.state.phrase("No diagnostics")
3576
+ }));
3577
+ needsSync = true;
3578
+ }
3579
+ if (newSelectedItem) {
3580
+ this.list.setAttribute("aria-activedescendant", newSelectedItem.id);
3581
+ this.view.requestMeasure({
3582
+ key: this,
3583
+ read: () => ({
3584
+ sel: newSelectedItem.dom.getBoundingClientRect(),
3585
+ panel: this.list.getBoundingClientRect()
3586
+ }),
3587
+ write: _ref4 => {
3588
+ let {
3589
+ sel,
3590
+ panel
3591
+ } = _ref4;
3592
+ if (sel.top < panel.top) this.list.scrollTop -= panel.top - sel.top;else if (sel.bottom > panel.bottom) this.list.scrollTop += sel.bottom - panel.bottom;
3593
+ }
3594
+ });
3595
+ } else if (this.selectedIndex < 0) {
3596
+ this.list.removeAttribute("aria-activedescendant");
3597
+ }
3598
+ if (needsSync) this.sync();
3599
+ }
3600
+ sync() {
3601
+ let domPos = this.list.firstChild;
3602
+ function rm() {
3603
+ let prev = domPos;
3604
+ domPos = prev.nextSibling;
3605
+ prev.remove();
3606
+ }
3607
+ for (let item of this.items) {
3608
+ if (item.dom.parentNode == this.list) {
3609
+ while (domPos != item.dom) rm();
3610
+ domPos = item.dom.nextSibling;
3611
+ } else {
3612
+ this.list.insertBefore(item.dom, domPos);
3613
+ }
3614
+ }
3615
+ while (domPos) rm();
3616
+ }
3617
+ moveSelection(selectedIndex) {
3618
+ if (this.selectedIndex < 0) return;
3619
+ let field = this.view.state.field(lintState);
3620
+ let selection = findDiagnostic(field.diagnostics, this.items[selectedIndex].diagnostic);
3621
+ if (!selection) return;
3622
+ this.view.dispatch({
3623
+ selection: {
3624
+ anchor: selection.from,
3625
+ head: selection.to
3626
+ },
3627
+ scrollIntoView: true,
3628
+ effects: movePanelSelection.of(selection)
3629
+ });
3630
+ }
3631
+ static open(view) {
3632
+ return new LintPanel(view);
3633
+ }
3634
+ }
3635
+ function svg(content) {
3636
+ let attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `viewBox="0 0 40 40"`;
3637
+ return `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${attrs}>${encodeURIComponent(content)}</svg>')`;
3638
+ }
3639
+ function underline(color) {
3640
+ return svg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${color}" fill="none" stroke-width=".7"/>`, `width="6" height="3"`);
3641
+ }
3642
+ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
3643
+ ".cm-diagnostic": {
3644
+ padding: "3px 6px 3px 8px",
3645
+ marginLeft: "-1px",
3646
+ display: "block",
3647
+ whiteSpace: "pre-wrap"
3648
+ },
3649
+ ".cm-diagnostic-error": {
3650
+ borderLeft: "5px solid #d11"
3651
+ },
3652
+ ".cm-diagnostic-warning": {
3653
+ borderLeft: "5px solid orange"
3654
+ },
3655
+ ".cm-diagnostic-info": {
3656
+ borderLeft: "5px solid #999"
3657
+ },
3658
+ ".cm-diagnosticAction": {
3659
+ font: "inherit",
3660
+ border: "none",
3661
+ padding: "2px 4px",
3662
+ backgroundColor: "#444",
3663
+ color: "white",
3664
+ borderRadius: "3px",
3665
+ marginLeft: "8px",
3666
+ cursor: "pointer"
3667
+ },
3668
+ ".cm-diagnosticSource": {
3669
+ fontSize: "70%",
3670
+ opacity: .7
3671
+ },
3672
+ ".cm-lintRange": {
3673
+ backgroundPosition: "left bottom",
3674
+ backgroundRepeat: "repeat-x",
3675
+ paddingBottom: "0.7px"
3676
+ },
3677
+ ".cm-lintRange-error": {
3678
+ backgroundImage: /*@__PURE__*/underline("#d11")
3679
+ },
3680
+ ".cm-lintRange-warning": {
3681
+ backgroundImage: /*@__PURE__*/underline("orange")
3682
+ },
3683
+ ".cm-lintRange-info": {
3684
+ backgroundImage: /*@__PURE__*/underline("#999")
3685
+ },
3686
+ ".cm-lintRange-active": {
3687
+ backgroundColor: "#ffdd9980"
3688
+ },
3689
+ ".cm-tooltip-lint": {
3690
+ padding: 0,
3691
+ margin: 0
3692
+ },
3693
+ ".cm-lintPoint": {
3694
+ position: "relative",
3695
+ "&:after": {
3696
+ content: '""',
3697
+ position: "absolute",
3698
+ bottom: 0,
3699
+ left: "-2px",
3700
+ borderLeft: "3px solid transparent",
3701
+ borderRight: "3px solid transparent",
3702
+ borderBottom: "4px solid #d11"
3703
+ }
3704
+ },
3705
+ ".cm-lintPoint-warning": {
3706
+ "&:after": {
3707
+ borderBottomColor: "orange"
3708
+ }
3709
+ },
3710
+ ".cm-lintPoint-info": {
3711
+ "&:after": {
3712
+ borderBottomColor: "#999"
3713
+ }
3714
+ },
3715
+ ".cm-panel.cm-panel-lint": {
3716
+ position: "relative",
3717
+ "& ul": {
3718
+ maxHeight: "100px",
3719
+ overflowY: "auto",
3720
+ "& [aria-selected]": {
3721
+ backgroundColor: "#ddd",
3722
+ "& u": {
3723
+ textDecoration: "underline"
3724
+ }
3725
+ },
3726
+ "&:focus [aria-selected]": {
3727
+ background_fallback: "#bdf",
3728
+ backgroundColor: "Highlight",
3729
+ color_fallback: "white",
3730
+ color: "HighlightText"
3731
+ },
3732
+ "& u": {
3733
+ textDecoration: "none"
3734
+ },
3735
+ padding: 0,
3736
+ margin: 0
3737
+ },
3738
+ "& [name=close]": {
3739
+ position: "absolute",
3740
+ top: "0",
3741
+ right: "2px",
3742
+ background: "inherit",
3743
+ border: "none",
3744
+ font: "inherit",
3745
+ padding: 0,
3746
+ margin: 0
3747
+ }
3748
+ }
3749
+ });
3750
+
3751
+ // (The superfluous function calls around the list of extensions work
3752
+ // around current limitations in tree-shaking software.)
3753
+ /**
3754
+ This is an extension value that just pulls together a number of
3755
+ extensions that you might want in a basic editor. It is meant as a
3756
+ convenient helper to quickly set up CodeMirror without installing
3757
+ and importing a lot of separate packages.
3758
+
3759
+ Specifically, it includes...
3760
+
3761
+ - [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
3762
+ - [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
3763
+ - [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
3764
+ - [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
3765
+ - [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
3766
+ - [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
3767
+ - [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
3768
+ - [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
3769
+ - [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
3770
+ - [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
3771
+ - [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
3772
+ - [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
3773
+ - [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
3774
+ - [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
3775
+ - [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
3776
+ - [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
3777
+ - [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
3778
+ - [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
3779
+ - [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
3780
+
3781
+ (You'll probably want to add some language package to your setup
3782
+ too.)
3783
+
3784
+ This extension does not allow customization. The idea is that,
3785
+ once you decide you want to configure your editor more precisely,
3786
+ you take this package's source (which is just a bunch of imports
3787
+ and an array literal), copy it into your own code, and adjust it
3788
+ as desired.
3789
+ */
3790
+ const basicSetup = /*@__PURE__*/(() => [lineNumbers(), highlightActiveLineGutter(), highlightSpecialChars(), history(), foldGutter(), drawSelection(), dropCursor(), EditorState.allowMultipleSelections.of(true), indentOnInput(), syntaxHighlighting(defaultHighlightStyle, {
3791
+ fallback: true
3792
+ }), bracketMatching(), closeBrackets(), autocompletion(), rectangularSelection(), crosshairCursor(), highlightActiveLine(), highlightSelectionMatches(), keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, ...foldKeymap, ...completionKeymap, ...lintKeymap])])();
3793
+ /**
3794
+ A minimal set of extensions to create a functional editor. Only
3795
+ includes [the default keymap](https://codemirror.net/6/docs/ref/#commands.defaultKeymap), [undo
3796
+ history](https://codemirror.net/6/docs/ref/#commands.history), [special character
3797
+ highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars), [custom selection
3798
+ drawing](https://codemirror.net/6/docs/ref/#view.drawSelection), and [default highlight
3799
+ style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle).
3800
+ */
3801
+ const minimalSetup = /*@__PURE__*/(() => [highlightSpecialChars(), history(), drawSelection(), syntaxHighlighting(defaultHighlightStyle, {
3802
+ fallback: true
3803
+ }), keymap.of([...defaultKeymap, ...historyKeymap])])();
3804
+
3805
+ export { basicSetup as b, indentWithTab as i, minimalSetup as m };