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