@stesura/react-prosemirror 3.2.11-stesura.1

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 (296) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +939 -0
  3. package/dist/cjs/AbstractEditorView.js +4 -0
  4. package/dist/cjs/ReactEditorView.js +194 -0
  5. package/dist/cjs/StaticEditorView.js +89 -0
  6. package/dist/cjs/browser.js +53 -0
  7. package/dist/cjs/commands/reorderSiblings.js +72 -0
  8. package/dist/cjs/components/ChildNodeViews.js +418 -0
  9. package/dist/cjs/components/CursorWrapper.js +84 -0
  10. package/dist/cjs/components/EditorStateSelectorsProvider.js +90 -0
  11. package/dist/cjs/components/LayoutGroup.js +112 -0
  12. package/dist/cjs/components/NativeWidgetView.js +108 -0
  13. package/dist/cjs/components/OutputSpec.js +121 -0
  14. package/dist/cjs/components/ProseMirror.js +146 -0
  15. package/dist/cjs/components/ProseMirrorDoc.js +74 -0
  16. package/dist/cjs/components/SeparatorHackView.js +99 -0
  17. package/dist/cjs/components/TextNodeView.js +113 -0
  18. package/dist/cjs/components/TrailingHackView.js +87 -0
  19. package/dist/cjs/components/WidgetView.js +94 -0
  20. package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
  21. package/dist/cjs/components/marks/DefaultMarkView.js +70 -0
  22. package/dist/cjs/components/marks/MarkView.js +85 -0
  23. package/dist/cjs/components/marks/MarkViewComponentProps.js +4 -0
  24. package/dist/cjs/components/marks/MarkViewConstructorView.js +116 -0
  25. package/dist/cjs/components/marks/ReactMarkView.js +109 -0
  26. package/dist/cjs/components/nodes/DefaultNodeView.js +68 -0
  27. package/dist/cjs/components/nodes/DocNodeView.js +97 -0
  28. package/dist/cjs/components/nodes/NodeView.js +129 -0
  29. package/dist/cjs/components/nodes/NodeViewComponentProps.js +4 -0
  30. package/dist/cjs/components/nodes/NodeViewConstructorView.js +145 -0
  31. package/dist/cjs/components/nodes/ReactNodeView.js +189 -0
  32. package/dist/cjs/constants.js +33 -0
  33. package/dist/cjs/contexts/ChildDescriptionsContext.js +19 -0
  34. package/dist/cjs/contexts/EditorContext.js +12 -0
  35. package/dist/cjs/contexts/EditorStateContext.js +12 -0
  36. package/dist/cjs/contexts/EditorStateStoreContext.js +45 -0
  37. package/dist/cjs/contexts/IgnoreMutationContext.js +12 -0
  38. package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
  39. package/dist/cjs/contexts/NodeViewContext.js +12 -0
  40. package/dist/cjs/contexts/RenderStoreContext.js +54 -0
  41. package/dist/cjs/contexts/SelectNodeContext.js +12 -0
  42. package/dist/cjs/contexts/StopEventContext.js +12 -0
  43. package/dist/cjs/decorations/ReactWidgetType.js +58 -0
  44. package/dist/cjs/decorations/computeDocDeco.js +44 -0
  45. package/dist/cjs/decorations/internalTypes.js +4 -0
  46. package/dist/cjs/decorations/iterDeco.js +91 -0
  47. package/dist/cjs/decorations/viewDecorations.js +155 -0
  48. package/dist/cjs/dom.js +147 -0
  49. package/dist/cjs/findDOMNode.js +46 -0
  50. package/dist/cjs/hooks/useClientLayoutEffect.js +19 -0
  51. package/dist/cjs/hooks/useComponentEventListeners.js +72 -0
  52. package/dist/cjs/hooks/useEditor.js +130 -0
  53. package/dist/cjs/hooks/useEditorEffect.js +39 -0
  54. package/dist/cjs/hooks/useEditorEventCallback.js +38 -0
  55. package/dist/cjs/hooks/useEditorEventListener.js +34 -0
  56. package/dist/cjs/hooks/useEditorState.js +18 -0
  57. package/dist/cjs/hooks/useEditorStateSelector.js +17 -0
  58. package/dist/cjs/hooks/useEffectEvent.js +34 -0
  59. package/dist/cjs/hooks/useForceUpdate.js +15 -0
  60. package/dist/cjs/hooks/useIgnoreMutation.js +24 -0
  61. package/dist/cjs/hooks/useIsComposingIn.js +25 -0
  62. package/dist/cjs/hooks/useIsEditorStatic.js +15 -0
  63. package/dist/cjs/hooks/useIsNodeSelected.js +21 -0
  64. package/dist/cjs/hooks/useLayoutGroupEffect.js +20 -0
  65. package/dist/cjs/hooks/useMarkViewDescription.js +134 -0
  66. package/dist/cjs/hooks/useNodePos.js +18 -0
  67. package/dist/cjs/hooks/useNodeViewDescription.js +154 -0
  68. package/dist/cjs/hooks/useReactKeys.js +17 -0
  69. package/dist/cjs/hooks/useSelectNode.js +30 -0
  70. package/dist/cjs/hooks/useSetDom.js +57 -0
  71. package/dist/cjs/hooks/useStopEvent.js +24 -0
  72. package/dist/cjs/index.js +85 -0
  73. package/dist/cjs/package.json +3 -0
  74. package/dist/cjs/plugins/beforeInputPlugin.js +356 -0
  75. package/dist/cjs/plugins/reactKeys.js +121 -0
  76. package/dist/cjs/props.js +283 -0
  77. package/dist/cjs/refs.js +28 -0
  78. package/dist/cjs/testing/editorViewTestHelpers.js +109 -0
  79. package/dist/cjs/testing/setupProseMirrorView.js +94 -0
  80. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +26 -0
  81. package/dist/cjs/tiptap/TiptapEditor.js +34 -0
  82. package/dist/cjs/tiptap/TiptapEditorContent.js +143 -0
  83. package/dist/cjs/tiptap/TiptapEditorView.js +130 -0
  84. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +12 -0
  85. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +40 -0
  86. package/dist/cjs/tiptap/extensions/ReactProseMirrorCommands.js +21 -0
  87. package/dist/cjs/tiptap/extensions/commands/updateAttributes.js +104 -0
  88. package/dist/cjs/tiptap/hooks/useEditor.js +318 -0
  89. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +15 -0
  90. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +35 -0
  91. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +35 -0
  92. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
  93. package/dist/cjs/tiptap/index.js +48 -0
  94. package/dist/cjs/tiptap/tiptapNodeView.js +245 -0
  95. package/dist/cjs/viewdesc.js +862 -0
  96. package/dist/esm/AbstractEditorView.js +1 -0
  97. package/dist/esm/ReactEditorView.js +194 -0
  98. package/dist/esm/StaticEditorView.js +79 -0
  99. package/dist/esm/browser.js +43 -0
  100. package/dist/esm/commands/reorderSiblings.js +63 -0
  101. package/dist/esm/components/ChildNodeViews.js +359 -0
  102. package/dist/esm/components/CursorWrapper.js +33 -0
  103. package/dist/esm/components/EditorStateSelectorsProvider.js +31 -0
  104. package/dist/esm/components/LayoutGroup.js +67 -0
  105. package/dist/esm/components/NativeWidgetView.js +57 -0
  106. package/dist/esm/components/OutputSpec.js +71 -0
  107. package/dist/esm/components/ProseMirror.js +95 -0
  108. package/dist/esm/components/ProseMirrorDoc.js +15 -0
  109. package/dist/esm/components/SeparatorHackView.js +48 -0
  110. package/dist/esm/components/TextNodeView.js +103 -0
  111. package/dist/esm/components/TrailingHackView.js +36 -0
  112. package/dist/esm/components/WidgetView.js +43 -0
  113. package/dist/esm/components/WidgetViewComponentProps.js +1 -0
  114. package/dist/esm/components/marks/DefaultMarkView.js +19 -0
  115. package/dist/esm/components/marks/MarkView.js +34 -0
  116. package/dist/esm/components/marks/MarkViewComponentProps.js +1 -0
  117. package/dist/esm/components/marks/MarkViewConstructorView.js +65 -0
  118. package/dist/esm/components/marks/ReactMarkView.js +58 -0
  119. package/dist/esm/components/nodes/DefaultNodeView.js +17 -0
  120. package/dist/esm/components/nodes/DocNodeView.js +46 -0
  121. package/dist/esm/components/nodes/NodeView.js +67 -0
  122. package/dist/esm/components/nodes/NodeViewComponentProps.js +1 -0
  123. package/dist/esm/components/nodes/NodeViewConstructorView.js +94 -0
  124. package/dist/esm/components/nodes/ReactNodeView.js +138 -0
  125. package/dist/esm/constants.js +15 -0
  126. package/dist/esm/contexts/ChildDescriptionsContext.js +9 -0
  127. package/dist/esm/contexts/EditorContext.js +7 -0
  128. package/dist/esm/contexts/EditorStateContext.js +2 -0
  129. package/dist/esm/contexts/EditorStateStoreContext.js +27 -0
  130. package/dist/esm/contexts/IgnoreMutationContext.js +2 -0
  131. package/dist/esm/contexts/LayoutGroupContext.js +2 -0
  132. package/dist/esm/contexts/NodeViewContext.js +2 -0
  133. package/dist/esm/contexts/RenderStoreContext.js +33 -0
  134. package/dist/esm/contexts/SelectNodeContext.js +2 -0
  135. package/dist/esm/contexts/StopEventContext.js +2 -0
  136. package/dist/esm/decorations/ReactWidgetType.js +40 -0
  137. package/dist/esm/decorations/computeDocDeco.js +44 -0
  138. package/dist/esm/decorations/internalTypes.js +1 -0
  139. package/dist/esm/decorations/iterDeco.js +85 -0
  140. package/dist/esm/decorations/viewDecorations.js +155 -0
  141. package/dist/esm/dom.js +110 -0
  142. package/dist/esm/findDOMNode.js +31 -0
  143. package/dist/esm/hooks/useClientLayoutEffect.js +9 -0
  144. package/dist/esm/hooks/useComponentEventListeners.js +87 -0
  145. package/dist/esm/hooks/useEditor.js +128 -0
  146. package/dist/esm/hooks/useEditorEffect.js +46 -0
  147. package/dist/esm/hooks/useEditorEventCallback.js +38 -0
  148. package/dist/esm/hooks/useEditorEventListener.js +28 -0
  149. package/dist/esm/hooks/useEditorState.js +10 -0
  150. package/dist/esm/hooks/useEditorStateSelector.js +14 -0
  151. package/dist/esm/hooks/useEffectEvent.js +24 -0
  152. package/dist/esm/hooks/useForceUpdate.js +8 -0
  153. package/dist/esm/hooks/useIgnoreMutation.js +14 -0
  154. package/dist/esm/hooks/useIsComposingIn.js +17 -0
  155. package/dist/esm/hooks/useIsEditorStatic.js +8 -0
  156. package/dist/esm/hooks/useIsNodeSelected.js +11 -0
  157. package/dist/esm/hooks/useLayoutGroupEffect.js +10 -0
  158. package/dist/esm/hooks/useMarkViewDescription.js +124 -0
  159. package/dist/esm/hooks/useNodePos.js +15 -0
  160. package/dist/esm/hooks/useNodeViewDescription.js +144 -0
  161. package/dist/esm/hooks/useReactKeys.js +7 -0
  162. package/dist/esm/hooks/useSelectNode.js +20 -0
  163. package/dist/esm/hooks/useSetDom.js +47 -0
  164. package/dist/esm/hooks/useStopEvent.js +14 -0
  165. package/dist/esm/index.js +19 -0
  166. package/dist/esm/plugins/beforeInputPlugin.js +346 -0
  167. package/dist/esm/plugins/reactKeys.js +106 -0
  168. package/dist/esm/props.js +267 -0
  169. package/dist/esm/refs.js +18 -0
  170. package/dist/esm/testing/editorViewTestHelpers.js +86 -0
  171. package/dist/esm/testing/setupProseMirrorView.js +76 -0
  172. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +22 -0
  173. package/dist/esm/tiptap/TiptapEditor.js +24 -0
  174. package/dist/esm/tiptap/TiptapEditorContent.js +99 -0
  175. package/dist/esm/tiptap/TiptapEditorView.js +76 -0
  176. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +2 -0
  177. package/dist/esm/tiptap/extensions/ReactProseMirror.js +30 -0
  178. package/dist/esm/tiptap/extensions/ReactProseMirrorCommands.js +11 -0
  179. package/dist/esm/tiptap/extensions/commands/updateAttributes.js +96 -0
  180. package/dist/esm/tiptap/hooks/useEditor.js +308 -0
  181. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +9 -0
  182. package/dist/esm/tiptap/hooks/useTiptapEditor.js +31 -0
  183. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +42 -0
  184. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +35 -0
  185. package/dist/esm/tiptap/index.js +9 -0
  186. package/dist/esm/tiptap/tiptapNodeView.js +211 -0
  187. package/dist/esm/viewdesc.js +844 -0
  188. package/dist/tsconfig.tsbuildinfo +1 -0
  189. package/dist/types/AbstractEditorView.d.ts +28 -0
  190. package/dist/types/ReactEditorView.d.ts +102 -0
  191. package/dist/types/StaticEditorView.d.ts +26 -0
  192. package/dist/types/__tests__/viewdesc.test.d.ts +1 -0
  193. package/dist/types/browser.d.ts +15 -0
  194. package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
  195. package/dist/types/commands/reorderSiblings.d.ts +14 -0
  196. package/dist/types/components/ChildNodeViews.d.ts +9 -0
  197. package/dist/types/components/CursorWrapper.d.ts +3 -0
  198. package/dist/types/components/EditorStateSelectorsProvider.d.ts +10 -0
  199. package/dist/types/components/LayoutGroup.d.ts +12 -0
  200. package/dist/types/components/NativeWidgetView.d.ts +8 -0
  201. package/dist/types/components/OutputSpec.d.ts +10 -0
  202. package/dist/types/components/ProseMirror.d.ts +14 -0
  203. package/dist/types/components/ProseMirrorDoc.d.ts +16 -0
  204. package/dist/types/components/SeparatorHackView.d.ts +6 -0
  205. package/dist/types/components/TextNodeView.d.ts +27 -0
  206. package/dist/types/components/TrailingHackView.d.ts +6 -0
  207. package/dist/types/components/WidgetView.d.ts +8 -0
  208. package/dist/types/components/WidgetViewComponentProps.d.ts +7 -0
  209. package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +17 -0
  210. package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
  211. package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
  212. package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
  213. package/dist/types/components/__tests__/ProseMirror.memory-leak.test.d.ts +6 -0
  214. package/dist/types/components/__tests__/ProseMirror.mobile.test.d.ts +1 -0
  215. package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
  216. package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
  217. package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
  218. package/dist/types/components/__tests__/stableContexts.test.d.ts +10 -0
  219. package/dist/types/components/marks/DefaultMarkView.d.ts +3 -0
  220. package/dist/types/components/marks/MarkView.d.ts +10 -0
  221. package/dist/types/components/marks/MarkViewComponentProps.d.ts +11 -0
  222. package/dist/types/components/marks/MarkViewConstructorView.d.ts +12 -0
  223. package/dist/types/components/marks/ReactMarkView.d.ts +12 -0
  224. package/dist/types/components/nodes/DefaultNodeView.d.ts +3 -0
  225. package/dist/types/components/nodes/DocNodeView.d.ts +12 -0
  226. package/dist/types/components/nodes/NodeView.d.ts +14 -0
  227. package/dist/types/components/nodes/NodeViewComponentProps.d.ts +13 -0
  228. package/dist/types/components/nodes/NodeViewConstructorView.d.ts +12 -0
  229. package/dist/types/components/nodes/ReactNodeView.d.ts +13 -0
  230. package/dist/types/constants.d.ts +4 -0
  231. package/dist/types/contexts/ChildDescriptionsContext.d.ts +7 -0
  232. package/dist/types/contexts/EditorContext.d.ts +18 -0
  233. package/dist/types/contexts/EditorStateContext.d.ts +2 -0
  234. package/dist/types/contexts/EditorStateStoreContext.d.ts +9 -0
  235. package/dist/types/contexts/IgnoreMutationContext.d.ts +5 -0
  236. package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
  237. package/dist/types/contexts/NodeViewContext.d.ts +9 -0
  238. package/dist/types/contexts/RenderStoreContext.d.ts +24 -0
  239. package/dist/types/contexts/SelectNodeContext.d.ts +5 -0
  240. package/dist/types/contexts/StopEventContext.d.ts +5 -0
  241. package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
  242. package/dist/types/decorations/ReactWidgetType.d.ts +40 -0
  243. package/dist/types/decorations/computeDocDeco.d.ts +14 -0
  244. package/dist/types/decorations/internalTypes.d.ts +20 -0
  245. package/dist/types/decorations/iterDeco.d.ts +3 -0
  246. package/dist/types/decorations/viewDecorations.d.ts +14 -0
  247. package/dist/types/dom.d.ts +22 -0
  248. package/dist/types/findDOMNode.d.ts +3 -0
  249. package/dist/types/hooks/__tests__/useEditorEffect.test.d.ts +1 -0
  250. package/dist/types/hooks/useClientLayoutEffect.d.ts +2 -0
  251. package/dist/types/hooks/useComponentEventListeners.d.ts +34 -0
  252. package/dist/types/hooks/useEditor.d.ts +37 -0
  253. package/dist/types/hooks/useEditorEffect.d.ts +21 -0
  254. package/dist/types/hooks/useEditorEventCallback.d.ts +13 -0
  255. package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
  256. package/dist/types/hooks/useEditorState.d.ts +5 -0
  257. package/dist/types/hooks/useEditorStateSelector.d.ts +10 -0
  258. package/dist/types/hooks/useEffectEvent.d.ts +1 -0
  259. package/dist/types/hooks/useForceUpdate.d.ts +5 -0
  260. package/dist/types/hooks/useIgnoreMutation.d.ts +2 -0
  261. package/dist/types/hooks/useIsComposingIn.d.ts +4 -0
  262. package/dist/types/hooks/useIsEditorStatic.d.ts +5 -0
  263. package/dist/types/hooks/useIsNodeSelected.d.ts +1 -0
  264. package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
  265. package/dist/types/hooks/useMarkViewDescription.d.ts +15 -0
  266. package/dist/types/hooks/useNodePos.d.ts +9 -0
  267. package/dist/types/hooks/useNodeViewDescription.d.ts +16 -0
  268. package/dist/types/hooks/useReactKeys.d.ts +2 -0
  269. package/dist/types/hooks/useSelectNode.d.ts +2 -0
  270. package/dist/types/hooks/useSetDom.d.ts +2 -0
  271. package/dist/types/hooks/useStopEvent.d.ts +2 -0
  272. package/dist/types/index.d.ts +21 -0
  273. package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
  274. package/dist/types/plugins/beforeInputPlugin.d.ts +2 -0
  275. package/dist/types/plugins/reactKeys.d.ts +23 -0
  276. package/dist/types/props.d.ts +1173 -0
  277. package/dist/types/refs.d.ts +2 -0
  278. package/dist/types/testing/editorViewTestHelpers.d.ts +24 -0
  279. package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
  280. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +15 -0
  281. package/dist/types/tiptap/TiptapEditor.d.ts +6 -0
  282. package/dist/types/tiptap/TiptapEditorContent.d.ts +28 -0
  283. package/dist/types/tiptap/TiptapEditorView.d.ts +16 -0
  284. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +6 -0
  285. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +9 -0
  286. package/dist/types/tiptap/extensions/ReactProseMirrorCommands.d.ts +2 -0
  287. package/dist/types/tiptap/extensions/commands/updateAttributes.d.ts +24 -0
  288. package/dist/types/tiptap/hooks/useEditor.d.ts +38 -0
  289. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +6 -0
  290. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +11 -0
  291. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +21 -0
  292. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +13 -0
  293. package/dist/types/tiptap/index.d.ts +9 -0
  294. package/dist/types/tiptap/tiptapNodeView.d.ts +50 -0
  295. package/dist/types/viewdesc.d.ts +179 -0
  296. package/package.json +167 -0
@@ -0,0 +1,862 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ CompositionViewDesc: function() {
13
+ return CompositionViewDesc;
14
+ },
15
+ MarkViewDesc: function() {
16
+ return MarkViewDesc;
17
+ },
18
+ NodeViewDesc: function() {
19
+ return NodeViewDesc;
20
+ },
21
+ ReactMarkViewDesc: function() {
22
+ return ReactMarkViewDesc;
23
+ },
24
+ ReactNodeViewDesc: function() {
25
+ return ReactNodeViewDesc;
26
+ },
27
+ TextViewDesc: function() {
28
+ return TextViewDesc;
29
+ },
30
+ TrailingHackViewDesc: function() {
31
+ return TrailingHackViewDesc;
32
+ },
33
+ ViewDesc: function() {
34
+ return ViewDesc;
35
+ },
36
+ WidgetViewDesc: function() {
37
+ return WidgetViewDesc;
38
+ },
39
+ findTextInFragment: function() {
40
+ return findTextInFragment;
41
+ },
42
+ placeViewDesc: function() {
43
+ return placeViewDesc;
44
+ },
45
+ sameOuterDeco: function() {
46
+ return sameOuterDeco;
47
+ },
48
+ sortViewDescs: function() {
49
+ return sortViewDescs;
50
+ }
51
+ });
52
+ const _prosemirrormodel = require("prosemirror-model");
53
+ const _browser = require("./browser.js");
54
+ const _dom = require("./dom.js");
55
+ function sortViewDescs(a, b) {
56
+ if (a instanceof TrailingHackViewDesc) return 1;
57
+ if (b instanceof TrailingHackViewDesc) return -1;
58
+ const posDiff = a.getPos() - b.getPos();
59
+ if (posDiff !== 0) return posDiff;
60
+ // When two descs share the same PM position (e.g. a zero-width widget
61
+ // and a text node that starts at the same position), fall back to DOM
62
+ // order so that the viewdesc children match the actual DOM layout.
63
+ // Without this, position computations like `posBeforeChild` can return
64
+ // the wrong PM position for the widget's container.
65
+ const cmp = a.dom.compareDocumentPosition(b.dom);
66
+ if (cmp & 4 /* DOCUMENT_POSITION_FOLLOWING */ ) return -1;
67
+ if (cmp & 2 /* DOCUMENT_POSITION_PRECEDING */ ) return 1;
68
+ return 0;
69
+ }
70
+ const placeViewDesc = (siblings, desc)=>{
71
+ let index = siblings.lastIndexOf(desc);
72
+ if (index === -1) index = siblings.push(desc) - 1;
73
+ const prev = siblings[index - 1];
74
+ const next = siblings[index + 1];
75
+ if ((!prev || sortViewDescs(prev, desc) <= 0) && (!next || sortViewDescs(desc, next) <= 0)) {
76
+ return;
77
+ }
78
+ siblings.splice(index, 1);
79
+ let low = 0;
80
+ let high = siblings.length;
81
+ while(low < high){
82
+ const mid = low + high >> 1;
83
+ const sibling = siblings[mid];
84
+ if (sibling && sortViewDescs(sibling, desc) <= 0) low = mid + 1;
85
+ else high = mid;
86
+ }
87
+ siblings.splice(low, 0, desc);
88
+ };
89
+ const NOT_DIRTY = 0, CHILD_DIRTY = 1, CONTENT_DIRTY = 2, NODE_DIRTY = 3;
90
+ let ViewDesc = class ViewDesc {
91
+ parent;
92
+ children;
93
+ getPos;
94
+ dom;
95
+ contentDOM;
96
+ dirty;
97
+ node;
98
+ constructor(parent, children, getPos, dom, // This is the node that holds the child views. It may be null for
99
+ // descs that don't have children.
100
+ contentDOM){
101
+ this.parent = parent;
102
+ this.children = children;
103
+ this.getPos = getPos;
104
+ this.dom = dom;
105
+ this.contentDOM = contentDOM;
106
+ this.dirty = NOT_DIRTY;
107
+ // An expando property on the DOM node provides a link back to its
108
+ // description.
109
+ dom.pmViewDesc = this;
110
+ }
111
+ // Used to check whether a given description corresponds to a
112
+ // widget/mark/node.
113
+ matchesWidget(_widget) {
114
+ return false;
115
+ }
116
+ matchesMark(_mark) {
117
+ return false;
118
+ }
119
+ matchesNode(_node, _outerDeco, _innerDeco) {
120
+ return false;
121
+ }
122
+ // @ts-expect-error ...
123
+ matchesHack(nodeName) {
124
+ return false;
125
+ }
126
+ // When parsing in-editor content (in domchange.js), we allow
127
+ // descriptions to determine the parse rules that should be used to
128
+ // parse them.
129
+ parseRule() {
130
+ return null;
131
+ }
132
+ // Used by the editor's event handler to ignore events that come
133
+ // from certain descs.
134
+ // @ts-expect-error ...
135
+ stopEvent(event) {
136
+ return false;
137
+ }
138
+ // The size of the content represented by this desc.
139
+ get size() {
140
+ let size = 0;
141
+ for(let i = 0; i < this.children.length; i++)// @ts-expect-error ...
142
+ size += this.children[i].size;
143
+ return size;
144
+ }
145
+ // For block nodes, this represents the space taken up by their
146
+ // start/end tokens.
147
+ get border() {
148
+ return 0;
149
+ }
150
+ destroy() {
151
+ this.parent = undefined;
152
+ if (this.dom.pmViewDesc == this) this.dom.pmViewDesc = undefined;
153
+ for(let i = 0; i < this.children.length; i++)this.children[i].destroy();
154
+ }
155
+ posBeforeChild(child) {
156
+ for(let i = 0, pos = this.posAtStart;; i++){
157
+ const cur = this.children[i];
158
+ if (cur == child) return pos;
159
+ // @ts-expect-error ...
160
+ pos += cur.size;
161
+ }
162
+ }
163
+ get posBefore() {
164
+ return this.parent.posBeforeChild(this);
165
+ }
166
+ get posAtStart() {
167
+ return this.parent ? this.parent.posBeforeChild(this) + this.border : 0;
168
+ }
169
+ get posAfter() {
170
+ return this.posBefore + this.size;
171
+ }
172
+ get posAtEnd() {
173
+ return this.posAtStart + this.size - 2 * this.border;
174
+ }
175
+ localPosFromDOM(dom, offset, bias) {
176
+ // If the DOM position is in the content, use the child desc after
177
+ // it to figure out a position.
178
+ if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) {
179
+ if (bias < 0) {
180
+ let domBefore, desc;
181
+ if (dom == this.contentDOM) {
182
+ domBefore = dom.childNodes[offset - 1];
183
+ } else {
184
+ while(dom.parentNode != this.contentDOM)dom = dom.parentNode;
185
+ domBefore = dom.previousSibling;
186
+ }
187
+ while(domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this))domBefore = domBefore.previousSibling;
188
+ return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart;
189
+ } else {
190
+ let domAfter, desc;
191
+ if (dom == this.contentDOM) {
192
+ domAfter = dom.childNodes[offset];
193
+ } else {
194
+ while(dom.parentNode != this.contentDOM)dom = dom.parentNode;
195
+ domAfter = dom.nextSibling;
196
+ }
197
+ while(domAfter && !((desc = domAfter.pmViewDesc) && desc.parent == this))domAfter = domAfter.nextSibling;
198
+ return domAfter ? this.posBeforeChild(desc) : this.posAtEnd;
199
+ }
200
+ }
201
+ // Otherwise, use various heuristics, falling back on the bias
202
+ // parameter, to determine whether to return the position at the
203
+ // start or at the end of this view desc.
204
+ let atEnd;
205
+ if (dom == this.dom && this.contentDOM) {
206
+ atEnd = offset > (0, _dom.domIndex)(this.contentDOM);
207
+ } else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) {
208
+ atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
209
+ } else if (this.dom.firstChild) {
210
+ if (offset == 0) for(let search = dom;; search = search.parentNode){
211
+ if (search == this.dom) {
212
+ atEnd = false;
213
+ break;
214
+ }
215
+ if (search.previousSibling) break;
216
+ }
217
+ if (atEnd == null && offset == dom.childNodes.length) for(let search = dom;; search = search.parentNode){
218
+ if (search == this.dom) {
219
+ atEnd = true;
220
+ break;
221
+ }
222
+ if (search.nextSibling) break;
223
+ }
224
+ }
225
+ return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart;
226
+ }
227
+ nearestDesc(dom) {
228
+ let onlyNodes = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
229
+ for(let first = true, cur = dom; cur; cur = cur.parentNode){
230
+ const desc = this.getDesc(cur);
231
+ let nodeDOM;
232
+ if (desc && (!onlyNodes || desc.node)) {
233
+ // If dom is outside of this desc's nodeDOM, don't count it.
234
+ if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first = false;
235
+ else return desc;
236
+ }
237
+ }
238
+ return;
239
+ }
240
+ getDesc(dom) {
241
+ const desc = dom.pmViewDesc;
242
+ for(let cur = desc; cur; cur = cur.parent)if (cur == this) return desc;
243
+ return;
244
+ }
245
+ posFromDOM(dom, offset, bias) {
246
+ for(let scan = dom; scan; scan = scan.parentNode){
247
+ const desc = this.getDesc(scan);
248
+ if (desc) return desc.localPosFromDOM(dom, offset, bias);
249
+ }
250
+ return -1;
251
+ }
252
+ // Find the desc for the node after the given pos, if any. (When a
253
+ // parent node overrode rendering, there might not be one.)
254
+ descAt(pos) {
255
+ for(let i = 0, offset = 0; i < this.children.length; i++){
256
+ let child = this.children[i];
257
+ const end = offset + child.size;
258
+ if (offset == pos && end != offset) {
259
+ while(!child.border && child.children.length){
260
+ for(let i = 0; i < child.children.length; i++){
261
+ const inner = child.children[i];
262
+ if (inner.size) {
263
+ child = inner;
264
+ break;
265
+ }
266
+ }
267
+ }
268
+ return child;
269
+ }
270
+ if (pos < end) return child.descAt(pos - offset - child.border);
271
+ offset = end;
272
+ }
273
+ return;
274
+ }
275
+ domFromPos(pos, side) {
276
+ if (!this.contentDOM) return {
277
+ node: this.dom,
278
+ offset: 0,
279
+ atom: pos + 1
280
+ };
281
+ // First find the position in the child array
282
+ let i = 0, offset = 0;
283
+ for(let curPos = 0; i < this.children.length; i++){
284
+ const child = this.children[i], end = curPos + child.size;
285
+ if (end > pos || child instanceof TrailingHackViewDesc) {
286
+ offset = pos - curPos;
287
+ break;
288
+ }
289
+ curPos = end;
290
+ }
291
+ // If this points into the middle of a child, call through
292
+ if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side);
293
+ // Go back if there were any zero-length widgets with side >= 0 before this point
294
+ for(let prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--){
295
+ // ...
296
+ }
297
+ // Scan towards the first useable node
298
+ if (side <= 0) {
299
+ let prev, enter = true;
300
+ for(;; i--, enter = false){
301
+ prev = i ? this.children[i - 1] : null;
302
+ if (!prev || prev.dom.parentNode == this.contentDOM) break;
303
+ }
304
+ if (prev && side && enter && !prev.border && !prev.domAtom) {
305
+ return prev.domFromPos(prev.size, side);
306
+ }
307
+ return {
308
+ node: this.contentDOM,
309
+ offset: prev ? (0, _dom.domIndex)(prev.dom) + 1 : 0
310
+ };
311
+ } else {
312
+ let next, enter = true;
313
+ for(;; i++, enter = false){
314
+ next = i < this.children.length ? this.children[i] : null;
315
+ if (!next || next.dom.parentNode == this.contentDOM) break;
316
+ }
317
+ if (next && enter && !next.border && !next.domAtom) return next.domFromPos(0, side);
318
+ return {
319
+ node: this.contentDOM,
320
+ offset: next ? (0, _dom.domIndex)(next.dom) : this.contentDOM.childNodes.length
321
+ };
322
+ }
323
+ }
324
+ // Used to find a DOM range in a single parent for a given changed
325
+ // range.
326
+ parseRange(from, to) {
327
+ let base = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
328
+ if (this.children.length == 0) return {
329
+ node: this.contentDOM,
330
+ from,
331
+ to,
332
+ fromOffset: 0,
333
+ toOffset: this.contentDOM.childNodes.length
334
+ };
335
+ let fromOffset = -1, toOffset = -1;
336
+ for(let offset = base, i = 0;; i++){
337
+ const child = this.children[i], end = offset + child.size;
338
+ if (fromOffset == -1 && from <= end) {
339
+ const childBase = offset + child.border;
340
+ // FIXME maybe descend mark views to parse a narrower range?
341
+ if (from >= childBase && to <= end - child.border && child.node && child.contentDOM && this.contentDOM.contains(child.contentDOM)) return child.parseRange(from, to, childBase);
342
+ from = offset;
343
+ for(let j = i; j > 0; j--){
344
+ const prev = this.children[j - 1];
345
+ if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) {
346
+ fromOffset = (0, _dom.domIndex)(prev.dom) + 1;
347
+ break;
348
+ }
349
+ from -= prev.size;
350
+ }
351
+ if (fromOffset == -1) fromOffset = 0;
352
+ }
353
+ if (fromOffset > -1 && (end > to || i == this.children.length - 1)) {
354
+ to = end;
355
+ for(let j = i + 1; j < this.children.length; j++){
356
+ const next = this.children[j];
357
+ if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) {
358
+ toOffset = (0, _dom.domIndex)(next.dom);
359
+ break;
360
+ }
361
+ to += next.size;
362
+ }
363
+ if (toOffset == -1) toOffset = this.contentDOM.childNodes.length;
364
+ break;
365
+ }
366
+ offset = end;
367
+ }
368
+ return {
369
+ node: this.contentDOM,
370
+ from,
371
+ to,
372
+ fromOffset,
373
+ toOffset
374
+ };
375
+ }
376
+ emptyChildAt(side) {
377
+ if (this.border || !this.contentDOM || !this.children.length) return false;
378
+ const child = this.children[side < 0 ? 0 : this.children.length - 1];
379
+ // @ts-expect-error ...
380
+ return child.size == 0 || child.emptyChildAt(side);
381
+ }
382
+ domAfterPos(pos) {
383
+ const { node, offset } = this.domFromPos(pos, 0);
384
+ if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
385
+ // @ts-expect-error ...
386
+ return node.childNodes[offset];
387
+ }
388
+ // View descs are responsible for setting any selection that falls
389
+ // entirely inside of them, so that custom implementations can do
390
+ // custom things with the selection. Note that this falls apart when
391
+ // a selection starts in such a node and ends in another, in which
392
+ // case we just use whatever domFromPos produces as a best effort.
393
+ setSelection(anchor, head, view) {
394
+ let force = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
395
+ if (view.composing) return;
396
+ // If the selection falls entirely in a child, give it to that child
397
+ const from = Math.min(anchor, head), to = Math.max(anchor, head);
398
+ for(let i = 0, offset = 0; i < this.children.length; i++){
399
+ const child = this.children[i], end = offset + child.size;
400
+ if (from > offset && to < end) return child.setSelection(anchor - offset - child.border, head - offset - child.border, view, force);
401
+ offset = end;
402
+ }
403
+ let anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1);
404
+ let headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1);
405
+ const domSel = view.root.getSelection();
406
+ const selRange = view.domSelectionRange();
407
+ let brKludge = false;
408
+ // On Firefox, using Selection.collapse to put the cursor after a
409
+ // BR node for some reason doesn't always work (#1073). On Safari,
410
+ // the cursor sometimes inexplicable visually lags behind its
411
+ // reported position in such situations (#1092).
412
+ if ((_browser.browser.gecko || _browser.browser.safari) && anchor == head) {
413
+ const { node, offset } = anchorDOM;
414
+ if (node.nodeType == 3) {
415
+ brKludge = !!(offset && node.nodeValue?.[offset - 1] == "\n");
416
+ // Issue #1128
417
+ if (brKludge && offset == node.nodeValue.length) {
418
+ for(let scan = node, after; scan; scan = scan.parentNode){
419
+ if (after = scan.nextSibling) {
420
+ if (after.nodeName == "BR") anchorDOM = headDOM = {
421
+ node: after.parentNode,
422
+ offset: (0, _dom.domIndex)(after) + 1
423
+ };
424
+ break;
425
+ }
426
+ const desc = scan.pmViewDesc;
427
+ if (desc && desc.node && desc.node.isBlock) break;
428
+ }
429
+ }
430
+ } else {
431
+ const prev = node.childNodes[offset - 1];
432
+ // @ts-expect-error ...
433
+ brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
434
+ }
435
+ }
436
+ // Firefox can act strangely when the selection is in front of an
437
+ // uneditable node. See #1163 and https://bugzilla.mozilla.org/show_bug.cgi?id=1709536
438
+ if (_browser.browser.gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) {
439
+ const after = selRange.focusNode.childNodes[selRange.focusOffset];
440
+ if (after && after.contentEditable == "false") force = true;
441
+ }
442
+ if (view.cursorWrapped || !(force || brKludge && _browser.browser.safari) && (0, _dom.isEquivalentPosition)(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && (0, _dom.isEquivalentPosition)(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) {
443
+ return;
444
+ }
445
+ // Selection.extend can be used to create an 'inverted' selection
446
+ // (one where the focus is before the anchor), but not all
447
+ // browsers support it yet.
448
+ let domSelExtended = false;
449
+ if ((domSel.extend || anchor == head) && !brKludge) {
450
+ domSel.collapse(anchorDOM.node, anchorDOM.offset);
451
+ try {
452
+ if (anchor != head) domSel.extend(headDOM.node, headDOM.offset);
453
+ domSelExtended = true;
454
+ } catch (_) {
455
+ // In some cases with Chrome the selection is empty after calling
456
+ // collapse, even when it should be valid. This appears to be a bug, but
457
+ // it is difficult to isolate. If this happens fallback to the old path
458
+ // without using extend.
459
+ // Similarly, this could crash on Safari if the editor is hidden, and
460
+ // there was no selection.
461
+ }
462
+ }
463
+ if (!domSelExtended) {
464
+ if (anchor > head) {
465
+ const tmp = anchorDOM;
466
+ anchorDOM = headDOM;
467
+ headDOM = tmp;
468
+ }
469
+ const range = document.createRange();
470
+ range.setEnd(headDOM.node, headDOM.offset);
471
+ range.setStart(anchorDOM.node, anchorDOM.offset);
472
+ domSel.removeAllRanges();
473
+ domSel.addRange(range);
474
+ }
475
+ }
476
+ ignoreMutation(mutation) {
477
+ return !this.contentDOM && mutation.type != "selection";
478
+ }
479
+ get contentLost() {
480
+ return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM);
481
+ }
482
+ // Remove a subtree of the element tree that has been touched
483
+ // by a DOM change, so that the next update will redraw it.
484
+ markDirty(from, to) {
485
+ for(let offset = 0, i = 0; i < this.children.length; i++){
486
+ const child = this.children[i], end = offset + child.size;
487
+ if (offset == end ? from <= end && to >= offset : from < end && to > offset) {
488
+ const startInside = offset + child.border, endInside = end - child.border;
489
+ if (from >= startInside && to <= endInside) {
490
+ this.dirty = from == offset || to == end ? CONTENT_DIRTY : CHILD_DIRTY;
491
+ if (from == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY;
492
+ else child.markDirty(from - startInside, to - startInside);
493
+ return;
494
+ } else {
495
+ child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY;
496
+ }
497
+ }
498
+ offset = end;
499
+ }
500
+ this.dirty = CONTENT_DIRTY;
501
+ }
502
+ markParentsDirty() {
503
+ let level = 1;
504
+ for(let node = this.parent; node; node = node.parent, level++){
505
+ const dirty = level == 1 ? CONTENT_DIRTY : CHILD_DIRTY;
506
+ if (node.dirty < dirty) node.dirty = dirty;
507
+ }
508
+ }
509
+ get domAtom() {
510
+ return false;
511
+ }
512
+ get ignoreForCoords() {
513
+ return false;
514
+ }
515
+ get ignoreForSelection() {
516
+ return false;
517
+ }
518
+ isText(_text) {
519
+ return false;
520
+ }
521
+ };
522
+ let WidgetViewDesc = class WidgetViewDesc extends ViewDesc {
523
+ widget;
524
+ constructor(parent, getPos, widget, dom){
525
+ super(parent, [], getPos, dom, null), this.widget = widget;
526
+ this.widget = widget;
527
+ }
528
+ matchesWidget(widget) {
529
+ return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type);
530
+ }
531
+ parseRule() {
532
+ return {
533
+ ignore: true
534
+ };
535
+ }
536
+ stopEvent(event) {
537
+ const stop = this.widget.spec.stopEvent;
538
+ return stop ? stop(event) : false;
539
+ }
540
+ ignoreMutation(mutation) {
541
+ return mutation.type != "selection" || this.widget.spec.ignoreSelection;
542
+ }
543
+ get domAtom() {
544
+ return true;
545
+ }
546
+ get ignoreForSelection() {
547
+ return !!this.widget.type.spec.relaxedSide;
548
+ }
549
+ get side() {
550
+ return this.widget.type.side;
551
+ }
552
+ };
553
+ let CompositionViewDesc = class CompositionViewDesc extends ViewDesc {
554
+ textDOM;
555
+ text;
556
+ constructor(parent, getPos, dom, textDOM, text){
557
+ super(parent, [], getPos, dom, null), this.textDOM = textDOM, this.text = text;
558
+ }
559
+ get size() {
560
+ return this.text.length;
561
+ }
562
+ localPosFromDOM(dom, offset) {
563
+ if (dom != this.textDOM) return this.posAtStart + (offset ? this.size : 0);
564
+ return this.posAtStart + offset;
565
+ }
566
+ domFromPos(pos) {
567
+ return {
568
+ node: this.textDOM,
569
+ offset: pos
570
+ };
571
+ }
572
+ ignoreMutation(mut) {
573
+ return mut.type === "characterData" && mut.target.nodeValue == mut.oldValue;
574
+ }
575
+ };
576
+ let MarkViewDesc = class MarkViewDesc extends ViewDesc {
577
+ mark;
578
+ spec;
579
+ constructor(parent, children, getPos, mark, dom, contentDOM, spec){
580
+ super(parent, children, getPos, dom, contentDOM), this.mark = mark, this.spec = spec;
581
+ }
582
+ parseRule() {
583
+ if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null;
584
+ return {
585
+ mark: this.mark.type.name,
586
+ attrs: this.mark.attrs,
587
+ contentElement: this.contentDOM
588
+ };
589
+ }
590
+ matchesMark(mark) {
591
+ return this.dirty != NODE_DIRTY && this.mark.eq(mark);
592
+ }
593
+ markDirty(from, to) {
594
+ super.markDirty(from, to);
595
+ // Move dirty info to nearest node view
596
+ if (this.dirty != NOT_DIRTY) {
597
+ let parent = this.parent;
598
+ while(!parent.node)parent = parent.parent;
599
+ if (parent.dirty < this.dirty) parent.dirty = this.dirty;
600
+ this.dirty = NOT_DIRTY;
601
+ }
602
+ }
603
+ ignoreMutation(mutation) {
604
+ return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
605
+ }
606
+ destroy() {
607
+ if (this.spec.destroy) this.spec.destroy();
608
+ super.destroy();
609
+ }
610
+ };
611
+ let NodeViewDesc = class NodeViewDesc extends ViewDesc {
612
+ node;
613
+ outerDeco;
614
+ innerDeco;
615
+ nodeDOM;
616
+ constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM){
617
+ super(parent, children, getPos, dom, contentDOM), this.node = node, this.outerDeco = outerDeco, this.innerDeco = innerDeco, this.nodeDOM = nodeDOM;
618
+ }
619
+ parseRule(addedNodes) {
620
+ // Experimental kludge to allow opt-in re-parsing of nodes
621
+ if (this.node.type.spec.reparseInView) return null;
622
+ // FIXME the assumption that this can always return the current
623
+ // attrs means that if the user somehow manages to change the
624
+ // attrs in the dom, that won't be picked up. Not entirely sure
625
+ // whether this is a problem
626
+ const rule = {
627
+ node: this.node.type.name,
628
+ attrs: this.node.attrs
629
+ };
630
+ if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full";
631
+ if (!this.contentDOM) {
632
+ rule.getContent = ()=>this.node.content;
633
+ } else if (!this.contentLost) {
634
+ rule.contentElement = this.contentDOM;
635
+ } else {
636
+ // Chrome likes to randomly recreate parent nodes when
637
+ // backspacing things. When that happens, this tries to find the
638
+ // new parent.
639
+ for(let i = this.children.length - 1; i >= 0; i--){
640
+ const child = this.children[i];
641
+ // @ts-expect-error ...
642
+ if (this.dom.contains(child.dom.parentNode)) {
643
+ // @ts-expect-error ...
644
+ rule.contentElement = child.dom.parentNode;
645
+ break;
646
+ }
647
+ }
648
+ if (!rule.contentElement) {
649
+ const found = addedNodes && addedNodes.find((n)=>n.nodeType == 1 && addedNodes.indexOf(n.parentNode) < 0 && this.dom.contains(n));
650
+ if (found) rule.contentElement = found;
651
+ else rule.getContent = ()=>_prosemirrormodel.Fragment.empty;
652
+ }
653
+ }
654
+ return rule;
655
+ }
656
+ matchesNode(node, outerDeco, innerDeco) {
657
+ return this.dirty == NOT_DIRTY && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco);
658
+ }
659
+ get size() {
660
+ return this.node.nodeSize;
661
+ }
662
+ get border() {
663
+ return this.node.isLeaf ? 0 : 1;
664
+ }
665
+ updateChildren(_view, _pos) {
666
+ // Omitted to avoid reproducing lots of unused code.
667
+ // Overidden elsewhere in case this is ever vendored.
668
+ }
669
+ // If this desc must be updated to match the given node decoration,
670
+ // do so and return true.
671
+ update(node, outerDeco, innerDeco, view) {
672
+ if (this.dirty == NODE_DIRTY || !node.sameMarkup(this.node)) return false;
673
+ this.updateInner(node, outerDeco, innerDeco, view);
674
+ return true;
675
+ }
676
+ updateInner(node, outerDeco, innerDeco, view) {
677
+ this.updateOuterDeco(outerDeco);
678
+ this.node = node;
679
+ this.innerDeco = innerDeco;
680
+ if (this.contentDOM) this.updateChildren(view, this.posAtStart);
681
+ this.dirty = NOT_DIRTY;
682
+ }
683
+ updateOuterDeco(outerDeco) {
684
+ this.outerDeco = outerDeco;
685
+ }
686
+ // Mark this node as being the selected node.
687
+ selectNode() {
688
+ if (this.nodeDOM.nodeType == 1) this.nodeDOM.classList.add("ProseMirror-selectednode");
689
+ if (this.contentDOM || !this.node.type.spec.draggable) this.dom.draggable = true;
690
+ }
691
+ // Remove selected node marking from this node.
692
+ deselectNode() {
693
+ if (this.nodeDOM.nodeType == 1) {
694
+ this.nodeDOM.classList.remove("ProseMirror-selectednode");
695
+ if (this.contentDOM || !this.node.type.spec.draggable) this.dom.removeAttribute("draggable");
696
+ }
697
+ }
698
+ get domAtom() {
699
+ return this.node.isAtom;
700
+ }
701
+ };
702
+ let TextViewDesc = class TextViewDesc extends NodeViewDesc {
703
+ constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, nodeDOM){
704
+ super(parent, children, getPos, node, outerDeco, innerDeco, dom, null, nodeDOM);
705
+ }
706
+ parseRule() {
707
+ let skip = this.nodeDOM.parentNode;
708
+ while(skip && skip != this.dom && !skip.pmIsDeco)skip = skip.parentNode;
709
+ return {
710
+ skip: skip || true
711
+ };
712
+ }
713
+ update(node, outerDeco, _innerDeco, _view) {
714
+ if (this.dirty == NODE_DIRTY || this.dirty != NOT_DIRTY && !this.inParent() || !node.sameMarkup(this.node)) return false;
715
+ this.updateOuterDeco(outerDeco);
716
+ this.node = node;
717
+ this.dirty = NOT_DIRTY;
718
+ return true;
719
+ }
720
+ inParent() {
721
+ const parentDOM = this.parent.contentDOM;
722
+ for(let n = this.nodeDOM; n; n = n.parentNode)if (n == parentDOM) return true;
723
+ return false;
724
+ }
725
+ domFromPos(pos) {
726
+ return {
727
+ node: this.nodeDOM,
728
+ offset: pos
729
+ };
730
+ }
731
+ localPosFromDOM(dom, offset, bias) {
732
+ if (dom == this.nodeDOM) return this.posAtStart + Math.min(offset, this.node.text.length);
733
+ return super.localPosFromDOM(dom, offset, bias);
734
+ }
735
+ markDirty(from, to) {
736
+ super.markDirty(from, to);
737
+ if (this.dom != this.nodeDOM && (from == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY;
738
+ }
739
+ get domAtom() {
740
+ return false;
741
+ }
742
+ isText(text) {
743
+ return this.node.text == text;
744
+ }
745
+ ignoreMutation(mutation) {
746
+ return mutation.type !== "characterData" && mutation.type !== "selection";
747
+ }
748
+ };
749
+ let TrailingHackViewDesc = class TrailingHackViewDesc extends ViewDesc {
750
+ parseRule() {
751
+ return {
752
+ ignore: true
753
+ };
754
+ }
755
+ matchesHack(nodeName) {
756
+ return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName;
757
+ }
758
+ get domAtom() {
759
+ return true;
760
+ }
761
+ get ignoreForCoords() {
762
+ return this.dom.nodeName == "IMG";
763
+ }
764
+ };
765
+ // A separate subclass is used for customized node views, so that the
766
+ // extra checks only have to be made for nodes that are actually
767
+ // customized.
768
+ let CustomNodeViewDesc = class CustomNodeViewDesc extends NodeViewDesc {
769
+ spec;
770
+ constructor(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec){
771
+ super(parent, children, getPos, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM), this.spec = spec;
772
+ }
773
+ // A custom `update` method gets to decide whether the update goes
774
+ // through. If it does, and there's a `contentDOM` node, our logic
775
+ // updates the children.
776
+ update(node, outerDeco, innerDeco, view) {
777
+ if (this.dirty == NODE_DIRTY) return false;
778
+ if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
779
+ const result = this.spec.update(node, outerDeco, innerDeco);
780
+ if (result) this.updateInner(node, outerDeco, innerDeco, view);
781
+ return result;
782
+ } else if (!this.contentDOM && !node.isLeaf) {
783
+ return false;
784
+ } else {
785
+ return super.update(node, outerDeco, innerDeco, view);
786
+ }
787
+ }
788
+ selectNode() {
789
+ this.spec.selectNode ? this.spec.selectNode.call(this) : super.selectNode();
790
+ }
791
+ deselectNode() {
792
+ this.spec.deselectNode ? this.spec.deselectNode.call(this) : super.deselectNode();
793
+ }
794
+ setSelection(anchor, head, view, force) {
795
+ this.spec.setSelection ? this.spec.setSelection.call(this, anchor, head, view.root) : super.setSelection(anchor, head, view, force);
796
+ }
797
+ destroy() {
798
+ if (this.spec.destroy) this.spec.destroy();
799
+ super.destroy();
800
+ }
801
+ stopEvent(event) {
802
+ return this.spec.stopEvent ? this.spec.stopEvent(event) : false;
803
+ }
804
+ ignoreMutation(mutation) {
805
+ return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation);
806
+ }
807
+ };
808
+ let ReactMarkViewDesc = class ReactMarkViewDesc extends MarkViewDesc {
809
+ destroy() {
810
+ // React has already destroyed the children (if needed).
811
+ this.children = [];
812
+ super.destroy();
813
+ }
814
+ };
815
+ let ReactNodeViewDesc = class ReactNodeViewDesc extends CustomNodeViewDesc {
816
+ updateChildren(_view, _pos) {
817
+ // React has already updated the children.
818
+ }
819
+ updateOuterDeco(outerDeco) {
820
+ // React has already updated the decorations.
821
+ this.outerDeco = outerDeco;
822
+ }
823
+ destroy() {
824
+ // React has already destroyed the children (if needed).
825
+ this.children = [];
826
+ super.destroy();
827
+ }
828
+ };
829
+ function sameOuterDeco(a, b) {
830
+ if (a.length != b.length) return false;
831
+ // @ts-expect-error ...
832
+ for(let i = 0; i < a.length; i++)if (!a[i].type.eq(b[i].type)) return false;
833
+ return true;
834
+ }
835
+ function findTextInFragment(frag, text, from, to) {
836
+ for(let i = 0, pos = 0; i < frag.childCount && pos <= to;){
837
+ const child = frag.child(i++);
838
+ const childStart = pos;
839
+ pos += child.nodeSize;
840
+ if (!child.isText) continue;
841
+ let str = child.text;
842
+ while(i < frag.childCount){
843
+ const next = frag.child(i++);
844
+ pos += next.nodeSize;
845
+ if (!next.isText) break;
846
+ str += next.text;
847
+ }
848
+ if (pos >= from) {
849
+ if (pos >= to && str.slice(to - text.length - childStart, to - childStart) === text) {
850
+ return to - text.length;
851
+ }
852
+ const found = childStart < to ? str.lastIndexOf(text, to - childStart - 1) : -1;
853
+ if (found >= 0 && found + text.length + childStart >= from) {
854
+ return childStart + found;
855
+ }
856
+ if (from === to && str.length >= to + text.length - childStart && str.slice(to - childStart, to - childStart + text.length) === text) {
857
+ return to;
858
+ }
859
+ }
860
+ }
861
+ return -1;
862
+ }