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