@fiduswriter/editor 0.1.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 (525) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +22 -0
  3. package/dist/bibliography/tools.js +53 -0
  4. package/dist/bibliography/tools.js.map +1 -0
  5. package/dist/citations/index.js +339 -0
  6. package/dist/citations/index.js.map +1 -0
  7. package/dist/citations/render.js +47 -0
  8. package/dist/citations/render.js.map +1 -0
  9. package/dist/clipboard/copy/index.js +2 -0
  10. package/dist/clipboard/copy/index.js.map +1 -0
  11. package/dist/clipboard/copy/schema.js +54 -0
  12. package/dist/clipboard/copy/schema.js.map +1 -0
  13. package/dist/clipboard/copy/serializers.js +132 -0
  14. package/dist/clipboard/copy/serializers.js.map +1 -0
  15. package/dist/clipboard/paste/fidus_writer.js +45 -0
  16. package/dist/clipboard/paste/fidus_writer.js.map +1 -0
  17. package/dist/clipboard/paste/general.js +76 -0
  18. package/dist/clipboard/paste/general.js.map +1 -0
  19. package/dist/clipboard/paste/google_docs.js +24 -0
  20. package/dist/clipboard/paste/google_docs.js.map +1 -0
  21. package/dist/clipboard/paste/html.js +68 -0
  22. package/dist/clipboard/paste/html.js.map +1 -0
  23. package/dist/clipboard/paste/index.js +3 -0
  24. package/dist/clipboard/paste/index.js.map +1 -0
  25. package/dist/clipboard/paste/libreoffice_writer.js +27 -0
  26. package/dist/clipboard/paste/libreoffice_writer.js.map +1 -0
  27. package/dist/clipboard/paste/microsoft_word.js +79 -0
  28. package/dist/clipboard/paste/microsoft_word.js.map +1 -0
  29. package/dist/clipboard/paste/text.js +41 -0
  30. package/dist/clipboard/paste/text.js.map +1 -0
  31. package/dist/collab/chat.js +154 -0
  32. package/dist/collab/chat.js.map +1 -0
  33. package/dist/collab/colors.js +62 -0
  34. package/dist/collab/colors.js.map +1 -0
  35. package/dist/collab/doc.js +1090 -0
  36. package/dist/collab/doc.js.map +1 -0
  37. package/dist/collab/index.js +75 -0
  38. package/dist/collab/index.js.map +1 -0
  39. package/dist/collab/merge/changeset.js +90 -0
  40. package/dist/collab/merge/changeset.js.map +1 -0
  41. package/dist/collab/merge/editor.js +708 -0
  42. package/dist/collab/merge/editor.js.map +1 -0
  43. package/dist/collab/merge/footnotes.js +149 -0
  44. package/dist/collab/merge/footnotes.js.map +1 -0
  45. package/dist/collab/merge/index.js +270 -0
  46. package/dist/collab/merge/index.js.map +1 -0
  47. package/dist/collab/merge/recreate_transform.js +259 -0
  48. package/dist/collab/merge/recreate_transform.js.map +1 -0
  49. package/dist/collab/merge/schema.js +117 -0
  50. package/dist/collab/merge/schema.js.map +1 -0
  51. package/dist/collab/merge/state_plugins/action.js +138 -0
  52. package/dist/collab/merge/state_plugins/action.js.map +1 -0
  53. package/dist/collab/merge/state_plugins/clipboard.js +32 -0
  54. package/dist/collab/merge/state_plugins/clipboard.js.map +1 -0
  55. package/dist/collab/merge/state_plugins/diff.js +541 -0
  56. package/dist/collab/merge/state_plugins/diff.js.map +1 -0
  57. package/dist/collab/merge/state_plugins/index.js +3 -0
  58. package/dist/collab/merge/state_plugins/index.js.map +1 -0
  59. package/dist/collab/merge/tools.js +175 -0
  60. package/dist/collab/merge/tools.js.map +1 -0
  61. package/dist/collab/templates.js +10 -0
  62. package/dist/collab/templates.js.map +1 -0
  63. package/dist/comments/comment.js +17 -0
  64. package/dist/comments/comment.js.map +1 -0
  65. package/dist/comments/editors/answer.js +43 -0
  66. package/dist/comments/editors/answer.js.map +1 -0
  67. package/dist/comments/editors/comment.js +278 -0
  68. package/dist/comments/editors/comment.js.map +1 -0
  69. package/dist/comments/editors/index.js +4 -0
  70. package/dist/comments/editors/index.js.map +1 -0
  71. package/dist/comments/editors/notify.js +13 -0
  72. package/dist/comments/editors/notify.js.map +1 -0
  73. package/dist/comments/editors/schema.js +60 -0
  74. package/dist/comments/editors/schema.js.map +1 -0
  75. package/dist/comments/index.js +11 -0
  76. package/dist/comments/index.js.map +1 -0
  77. package/dist/comments/interactions.js +379 -0
  78. package/dist/comments/interactions.js.map +1 -0
  79. package/dist/comments/store.js +438 -0
  80. package/dist/comments/store.js.map +1 -0
  81. package/dist/contacts/add_dialog.js +88 -0
  82. package/dist/contacts/add_dialog.js.map +1 -0
  83. package/dist/contacts/templates.js +23 -0
  84. package/dist/contacts/templates.js.map +1 -0
  85. package/dist/copyright_dialog/index.js +148 -0
  86. package/dist/copyright_dialog/index.js.map +1 -0
  87. package/dist/copyright_dialog/templates.js +48 -0
  88. package/dist/copyright_dialog/templates.js.map +1 -0
  89. package/dist/databases/bibliography.js +162 -0
  90. package/dist/databases/bibliography.js.map +1 -0
  91. package/dist/databases/images.js +260 -0
  92. package/dist/databases/images.js.map +1 -0
  93. package/dist/databases/index.js +55 -0
  94. package/dist/databases/index.js.map +1 -0
  95. package/dist/dialogs/citation.js +321 -0
  96. package/dist/dialogs/citation.js.map +1 -0
  97. package/dist/dialogs/code_block.js +192 -0
  98. package/dist/dialogs/code_block.js.map +1 -0
  99. package/dist/dialogs/contributor.js +132 -0
  100. package/dist/dialogs/contributor.js.map +1 -0
  101. package/dist/dialogs/figure.js +378 -0
  102. package/dist/dialogs/figure.js.map +1 -0
  103. package/dist/dialogs/index.js +11 -0
  104. package/dist/dialogs/index.js.map +1 -0
  105. package/dist/dialogs/language.js +47 -0
  106. package/dist/dialogs/language.js.map +1 -0
  107. package/dist/dialogs/link.js +243 -0
  108. package/dist/dialogs/link.js.map +1 -0
  109. package/dist/dialogs/math.js +121 -0
  110. package/dist/dialogs/math.js.map +1 -0
  111. package/dist/dialogs/ordered_list.js +67 -0
  112. package/dist/dialogs/ordered_list.js.map +1 -0
  113. package/dist/dialogs/revision.js +36 -0
  114. package/dist/dialogs/revision.js.map +1 -0
  115. package/dist/dialogs/subsup.js +109 -0
  116. package/dist/dialogs/subsup.js.map +1 -0
  117. package/dist/dialogs/table.js +217 -0
  118. package/dist/dialogs/table.js.map +1 -0
  119. package/dist/dialogs/templates.js +366 -0
  120. package/dist/dialogs/templates.js.map +1 -0
  121. package/dist/document_template/exporter.js +83 -0
  122. package/dist/document_template/exporter.js.map +1 -0
  123. package/dist/document_template/index.js +327 -0
  124. package/dist/document_template/index.js.map +1 -0
  125. package/dist/documents/access_rights/index.js +532 -0
  126. package/dist/documents/access_rights/index.js.map +1 -0
  127. package/dist/documents/access_rights/templates.js +150 -0
  128. package/dist/documents/access_rights/templates.js.map +1 -0
  129. package/dist/e2ee/encryptor.js +201 -0
  130. package/dist/e2ee/encryptor.js.map +1 -0
  131. package/dist/e2ee/key-manager.js +171 -0
  132. package/dist/e2ee/key-manager.js.map +1 -0
  133. package/dist/e2ee/passphrase-crypto.js +365 -0
  134. package/dist/e2ee/passphrase-crypto.js.map +1 -0
  135. package/dist/e2ee/passphrase-dialog.js +548 -0
  136. package/dist/e2ee/passphrase-dialog.js.map +1 -0
  137. package/dist/e2ee/passphrase-manager.js +350 -0
  138. package/dist/e2ee/passphrase-manager.js.map +1 -0
  139. package/dist/e2ee/password-dialog.js +552 -0
  140. package/dist/e2ee/password-dialog.js.map +1 -0
  141. package/dist/e2ee/snapshot-manager.js +238 -0
  142. package/dist/e2ee/snapshot-manager.js.map +1 -0
  143. package/dist/exporter/native/copy.js +29 -0
  144. package/dist/exporter/native/copy.js.map +1 -0
  145. package/dist/exporter/native/file.js +19 -0
  146. package/dist/exporter/native/file.js.map +1 -0
  147. package/dist/exporter/native/index.js +4 -0
  148. package/dist/exporter/native/index.js.map +1 -0
  149. package/dist/exporter/native/revision.js +54 -0
  150. package/dist/exporter/native/revision.js.map +1 -0
  151. package/dist/exporter/native/zip.js +2 -0
  152. package/dist/exporter/native/zip.js.map +1 -0
  153. package/dist/footnotes/editor.js +180 -0
  154. package/dist/footnotes/editor.js.map +1 -0
  155. package/dist/footnotes/index.js +15 -0
  156. package/dist/footnotes/index.js.map +1 -0
  157. package/dist/footnotes/layout.js +125 -0
  158. package/dist/footnotes/layout.js.map +1 -0
  159. package/dist/footnotes/state_plugins/access_rights.js +25 -0
  160. package/dist/footnotes/state_plugins/access_rights.js.map +1 -0
  161. package/dist/footnotes/state_plugins/index.js +2 -0
  162. package/dist/footnotes/state_plugins/index.js.map +1 -0
  163. package/dist/images/edit_dialog/edit_dialog/index.js +186 -0
  164. package/dist/images/edit_dialog/edit_dialog/index.js.map +1 -0
  165. package/dist/images/edit_dialog/edit_dialog/model.js +152 -0
  166. package/dist/images/edit_dialog/edit_dialog/model.js.map +1 -0
  167. package/dist/images/edit_dialog/edit_dialog/templates.js +33 -0
  168. package/dist/images/edit_dialog/edit_dialog/templates.js.map +1 -0
  169. package/dist/images/edit_dialog/model.js +6 -0
  170. package/dist/images/edit_dialog/model.js.map +1 -0
  171. package/dist/images/selection_dialog/index.js +149 -0
  172. package/dist/images/selection_dialog/index.js.map +1 -0
  173. package/dist/index.js +1002 -0
  174. package/dist/index.js.map +1 -0
  175. package/dist/keymap.js +73 -0
  176. package/dist/keymap.js.map +1 -0
  177. package/dist/marginboxes/index.js +674 -0
  178. package/dist/marginboxes/index.js.map +1 -0
  179. package/dist/marginboxes/templates.js +447 -0
  180. package/dist/marginboxes/templates.js.map +1 -0
  181. package/dist/menus/code_block/index.js +2 -0
  182. package/dist/menus/code_block/index.js.map +1 -0
  183. package/dist/menus/code_block/model.js +49 -0
  184. package/dist/menus/code_block/model.js.map +1 -0
  185. package/dist/menus/figure/index.js +3 -0
  186. package/dist/menus/figure/index.js.map +1 -0
  187. package/dist/menus/figure/model.js +80 -0
  188. package/dist/menus/figure/model.js.map +1 -0
  189. package/dist/menus/figure/utils.js +6 -0
  190. package/dist/menus/figure/utils.js.map +1 -0
  191. package/dist/menus/headerbar/index.js +3 -0
  192. package/dist/menus/headerbar/index.js.map +1 -0
  193. package/dist/menus/headerbar/model.js +743 -0
  194. package/dist/menus/headerbar/model.js.map +1 -0
  195. package/dist/menus/headerbar/view.js +579 -0
  196. package/dist/menus/headerbar/view.js.map +1 -0
  197. package/dist/menus/image/index.js +2 -0
  198. package/dist/menus/image/index.js.map +1 -0
  199. package/dist/menus/image/model.js +32 -0
  200. package/dist/menus/image/model.js.map +1 -0
  201. package/dist/menus/index.js +10 -0
  202. package/dist/menus/index.js.map +1 -0
  203. package/dist/menus/navigator/index.js +2 -0
  204. package/dist/menus/navigator/index.js.map +1 -0
  205. package/dist/menus/navigator/model.js +29 -0
  206. package/dist/menus/navigator/model.js.map +1 -0
  207. package/dist/menus/ordered_list/index.js +2 -0
  208. package/dist/menus/ordered_list/index.js.map +1 -0
  209. package/dist/menus/ordered_list/model.js +17 -0
  210. package/dist/menus/ordered_list/model.js.map +1 -0
  211. package/dist/menus/selection/index.js +3 -0
  212. package/dist/menus/selection/index.js.map +1 -0
  213. package/dist/menus/selection/model.js +108 -0
  214. package/dist/menus/selection/model.js.map +1 -0
  215. package/dist/menus/selection/view.js +125 -0
  216. package/dist/menus/selection/view.js.map +1 -0
  217. package/dist/menus/table/index.js +2 -0
  218. package/dist/menus/table/index.js.map +1 -0
  219. package/dist/menus/table/model.js +319 -0
  220. package/dist/menus/table/model.js.map +1 -0
  221. package/dist/menus/toolbar/index.js +3 -0
  222. package/dist/menus/toolbar/index.js.map +1 -0
  223. package/dist/menus/toolbar/model.js +747 -0
  224. package/dist/menus/toolbar/model.js.map +1 -0
  225. package/dist/menus/toolbar/view.js +314 -0
  226. package/dist/menus/toolbar/view.js.map +1 -0
  227. package/dist/navigator/index.js +435 -0
  228. package/dist/navigator/index.js.map +1 -0
  229. package/dist/no_collab_save/index.js +169 -0
  230. package/dist/no_collab_save/index.js.map +1 -0
  231. package/dist/plugins/citation_dialog/index.js +2 -0
  232. package/dist/plugins/citation_dialog/index.js.map +1 -0
  233. package/dist/plugins/editor/index.js +2 -0
  234. package/dist/plugins/editor/index.js.map +1 -0
  235. package/dist/state_plugins/access_rights.js +30 -0
  236. package/dist/state_plugins/access_rights.js.map +1 -0
  237. package/dist/state_plugins/citation_render.js +78 -0
  238. package/dist/state_plugins/citation_render.js.map +1 -0
  239. package/dist/state_plugins/clipboard.js +217 -0
  240. package/dist/state_plugins/clipboard.js.map +1 -0
  241. package/dist/state_plugins/code_block.js +165 -0
  242. package/dist/state_plugins/code_block.js.map +1 -0
  243. package/dist/state_plugins/collab_carets.js +115 -0
  244. package/dist/state_plugins/collab_carets.js.map +1 -0
  245. package/dist/state_plugins/comments.js +197 -0
  246. package/dist/state_plugins/comments.js.map +1 -0
  247. package/dist/state_plugins/contributor_input/add_button.js +101 -0
  248. package/dist/state_plugins/contributor_input/add_button.js.map +1 -0
  249. package/dist/state_plugins/contributor_input/dropup.js +273 -0
  250. package/dist/state_plugins/contributor_input/dropup.js.map +1 -0
  251. package/dist/state_plugins/contributor_input/helpers.js +23 -0
  252. package/dist/state_plugins/contributor_input/helpers.js.map +1 -0
  253. package/dist/state_plugins/contributor_input/index.js +3 -0
  254. package/dist/state_plugins/contributor_input/index.js.map +1 -0
  255. package/dist/state_plugins/contributor_input/node_view.js +76 -0
  256. package/dist/state_plugins/contributor_input/node_view.js.map +1 -0
  257. package/dist/state_plugins/contributor_input/plugin.js +236 -0
  258. package/dist/state_plugins/contributor_input/plugin.js.map +1 -0
  259. package/dist/state_plugins/document_template.js +213 -0
  260. package/dist/state_plugins/document_template.js.map +1 -0
  261. package/dist/state_plugins/figure.js +90 -0
  262. package/dist/state_plugins/figure.js.map +1 -0
  263. package/dist/state_plugins/footnote_markers.js +187 -0
  264. package/dist/state_plugins/footnote_markers.js.map +1 -0
  265. package/dist/state_plugins/headerbar.js +10 -0
  266. package/dist/state_plugins/headerbar.js.map +1 -0
  267. package/dist/state_plugins/index.js +27 -0
  268. package/dist/state_plugins/index.js.map +1 -0
  269. package/dist/state_plugins/inline_math.js +719 -0
  270. package/dist/state_plugins/inline_math.js.map +1 -0
  271. package/dist/state_plugins/inline_reference/dropup.js +182 -0
  272. package/dist/state_plugins/inline_reference/dropup.js.map +1 -0
  273. package/dist/state_plugins/inline_reference/index.js +2 -0
  274. package/dist/state_plugins/inline_reference/index.js.map +1 -0
  275. package/dist/state_plugins/inline_reference/plugin.js +1134 -0
  276. package/dist/state_plugins/inline_reference/plugin.js.map +1 -0
  277. package/dist/state_plugins/jump_hidden_nodes.js +47 -0
  278. package/dist/state_plugins/jump_hidden_nodes.js.map +1 -0
  279. package/dist/state_plugins/links.js +622 -0
  280. package/dist/state_plugins/links.js.map +1 -0
  281. package/dist/state_plugins/marginboxes.js +13 -0
  282. package/dist/state_plugins/marginboxes.js.map +1 -0
  283. package/dist/state_plugins/ordered_list_menu.js +72 -0
  284. package/dist/state_plugins/ordered_list_menu.js.map +1 -0
  285. package/dist/state_plugins/placeholders.js +98 -0
  286. package/dist/state_plugins/placeholders.js.map +1 -0
  287. package/dist/state_plugins/search.js +212 -0
  288. package/dist/state_plugins/search.js.map +1 -0
  289. package/dist/state_plugins/selection_menu.js +10 -0
  290. package/dist/state_plugins/selection_menu.js.map +1 -0
  291. package/dist/state_plugins/settings.js +191 -0
  292. package/dist/state_plugins/settings.js.map +1 -0
  293. package/dist/state_plugins/table.js +104 -0
  294. package/dist/state_plugins/table.js.map +1 -0
  295. package/dist/state_plugins/tag_input/helpers.js +55 -0
  296. package/dist/state_plugins/tag_input/helpers.js.map +1 -0
  297. package/dist/state_plugins/tag_input/index.js +3 -0
  298. package/dist/state_plugins/tag_input/index.js.map +1 -0
  299. package/dist/state_plugins/tag_input/node_view.js +77 -0
  300. package/dist/state_plugins/tag_input/node_view.js.map +1 -0
  301. package/dist/state_plugins/tag_input/plugin.js +199 -0
  302. package/dist/state_plugins/tag_input/plugin.js.map +1 -0
  303. package/dist/state_plugins/tag_input/tag_editor.js +159 -0
  304. package/dist/state_plugins/tag_input/tag_editor.js.map +1 -0
  305. package/dist/state_plugins/tag_input/tag_editor_plugins.js +61 -0
  306. package/dist/state_plugins/tag_input/tag_editor_plugins.js.map +1 -0
  307. package/dist/state_plugins/toc_render.js +142 -0
  308. package/dist/state_plugins/toc_render.js.map +1 -0
  309. package/dist/state_plugins/toolbar.js +10 -0
  310. package/dist/state_plugins/toolbar.js.map +1 -0
  311. package/dist/state_plugins/track/find_selected_changes.js +82 -0
  312. package/dist/state_plugins/track/find_selected_changes.js.map +1 -0
  313. package/dist/state_plugins/track/helpers.js +67 -0
  314. package/dist/state_plugins/track/helpers.js.map +1 -0
  315. package/dist/state_plugins/track/index.js +3 -0
  316. package/dist/state_plugins/track/index.js.map +1 -0
  317. package/dist/state_plugins/track/plugin.js +114 -0
  318. package/dist/state_plugins/track/plugin.js.map +1 -0
  319. package/dist/tools/index.js +4 -0
  320. package/dist/tools/index.js.map +1 -0
  321. package/dist/tools/key_bindings/index.js +20 -0
  322. package/dist/tools/key_bindings/index.js.map +1 -0
  323. package/dist/tools/key_bindings/templates.js +68 -0
  324. package/dist/tools/key_bindings/templates.js.map +1 -0
  325. package/dist/tools/search_replace/index.js +275 -0
  326. package/dist/tools/search_replace/index.js.map +1 -0
  327. package/dist/tools/search_replace/templates.js +18 -0
  328. package/dist/tools/search_replace/templates.js.map +1 -0
  329. package/dist/tools/word_count/index.js +40 -0
  330. package/dist/tools/word_count/index.js.map +1 -0
  331. package/dist/tools/word_count/templates.js +27 -0
  332. package/dist/tools/word_count/templates.js.map +1 -0
  333. package/dist/track/accept.js +66 -0
  334. package/dist/track/accept.js.map +1 -0
  335. package/dist/track/accept_all.js +51 -0
  336. package/dist/track/accept_all.js.map +1 -0
  337. package/dist/track/accept_all_no_insertions.js +63 -0
  338. package/dist/track/accept_all_no_insertions.js.map +1 -0
  339. package/dist/track/amend_transaction.js +390 -0
  340. package/dist/track/amend_transaction.js.map +1 -0
  341. package/dist/track/delete.js +62 -0
  342. package/dist/track/delete.js.map +1 -0
  343. package/dist/track/index.js +6 -0
  344. package/dist/track/index.js.map +1 -0
  345. package/dist/track/mod.js +86 -0
  346. package/dist/track/mod.js.map +1 -0
  347. package/dist/track/reject.js +67 -0
  348. package/dist/track/reject.js.map +1 -0
  349. package/dist/track/reject_all.js +56 -0
  350. package/dist/track/reject_all.js.map +1 -0
  351. package/package.json +80 -0
  352. package/src/bibliography/tools.js +58 -0
  353. package/src/citations/index.js +443 -0
  354. package/src/citations/render.js +68 -0
  355. package/src/clipboard/copy/index.js +1 -0
  356. package/src/clipboard/copy/schema.js +62 -0
  357. package/src/clipboard/copy/serializers.js +179 -0
  358. package/src/clipboard/paste/fidus_writer.js +55 -0
  359. package/src/clipboard/paste/general.js +80 -0
  360. package/src/clipboard/paste/google_docs.js +26 -0
  361. package/src/clipboard/paste/html.js +76 -0
  362. package/src/clipboard/paste/index.js +2 -0
  363. package/src/clipboard/paste/libreoffice_writer.js +32 -0
  364. package/src/clipboard/paste/microsoft_word.js +87 -0
  365. package/src/clipboard/paste/text.js +58 -0
  366. package/src/collab/chat.js +195 -0
  367. package/src/collab/colors.js +67 -0
  368. package/src/collab/doc.js +1436 -0
  369. package/src/collab/index.js +81 -0
  370. package/src/collab/merge/changeset.js +103 -0
  371. package/src/collab/merge/editor.js +1065 -0
  372. package/src/collab/merge/footnotes.js +175 -0
  373. package/src/collab/merge/index.js +401 -0
  374. package/src/collab/merge/recreate_transform.js +326 -0
  375. package/src/collab/merge/schema.js +135 -0
  376. package/src/collab/merge/state_plugins/action.js +171 -0
  377. package/src/collab/merge/state_plugins/clipboard.js +32 -0
  378. package/src/collab/merge/state_plugins/diff.js +780 -0
  379. package/src/collab/merge/state_plugins/index.js +2 -0
  380. package/src/collab/merge/tools.js +217 -0
  381. package/src/collab/templates.js +10 -0
  382. package/src/comments/comment.js +29 -0
  383. package/src/comments/editors/answer.js +55 -0
  384. package/src/comments/editors/comment.js +318 -0
  385. package/src/comments/editors/index.js +4 -0
  386. package/src/comments/editors/notify.js +13 -0
  387. package/src/comments/editors/schema.js +65 -0
  388. package/src/comments/index.js +11 -0
  389. package/src/comments/interactions.js +465 -0
  390. package/src/comments/store.js +513 -0
  391. package/src/contacts/add_dialog.js +110 -0
  392. package/src/contacts/templates.js +28 -0
  393. package/src/copyright_dialog/index.js +179 -0
  394. package/src/copyright_dialog/templates.js +56 -0
  395. package/src/databases/bibliography.js +179 -0
  396. package/src/databases/images.js +320 -0
  397. package/src/databases/index.js +69 -0
  398. package/src/dialogs/citation.js +428 -0
  399. package/src/dialogs/code_block.js +242 -0
  400. package/src/dialogs/contributor.js +173 -0
  401. package/src/dialogs/figure.js +479 -0
  402. package/src/dialogs/index.js +10 -0
  403. package/src/dialogs/language.js +58 -0
  404. package/src/dialogs/link.js +358 -0
  405. package/src/dialogs/math.js +148 -0
  406. package/src/dialogs/ordered_list.js +84 -0
  407. package/src/dialogs/revision.js +43 -0
  408. package/src/dialogs/subsup.js +116 -0
  409. package/src/dialogs/table.js +258 -0
  410. package/src/dialogs/templates.js +426 -0
  411. package/src/document_template/exporter.js +97 -0
  412. package/src/document_template/index.js +483 -0
  413. package/src/documents/access_rights/index.js +693 -0
  414. package/src/documents/access_rights/templates.js +178 -0
  415. package/src/e2ee/encryptor.js +228 -0
  416. package/src/e2ee/key-manager.js +202 -0
  417. package/src/e2ee/passphrase-crypto.js +606 -0
  418. package/src/e2ee/passphrase-dialog.js +655 -0
  419. package/src/e2ee/passphrase-manager.js +502 -0
  420. package/src/e2ee/password-dialog.js +652 -0
  421. package/src/e2ee/snapshot-manager.js +305 -0
  422. package/src/exporter/native/copy.js +54 -0
  423. package/src/exporter/native/file.js +37 -0
  424. package/src/exporter/native/index.js +3 -0
  425. package/src/exporter/native/revision.js +86 -0
  426. package/src/exporter/native/zip.js +1 -0
  427. package/src/footnotes/editor.js +227 -0
  428. package/src/footnotes/index.js +16 -0
  429. package/src/footnotes/layout.js +190 -0
  430. package/src/footnotes/state_plugins/access_rights.js +39 -0
  431. package/src/footnotes/state_plugins/index.js +1 -0
  432. package/src/images/edit_dialog/edit_dialog/index.js +222 -0
  433. package/src/images/edit_dialog/edit_dialog/model.js +183 -0
  434. package/src/images/edit_dialog/edit_dialog/templates.js +41 -0
  435. package/src/images/edit_dialog/model.js +5 -0
  436. package/src/images/selection_dialog/index.js +176 -0
  437. package/src/index.js +1252 -0
  438. package/src/keymap.js +102 -0
  439. package/src/marginboxes/index.js +946 -0
  440. package/src/marginboxes/templates.js +573 -0
  441. package/src/menus/code_block/index.js +1 -0
  442. package/src/menus/code_block/model.js +52 -0
  443. package/src/menus/figure/index.js +2 -0
  444. package/src/menus/figure/model.js +91 -0
  445. package/src/menus/figure/utils.js +5 -0
  446. package/src/menus/headerbar/index.js +2 -0
  447. package/src/menus/headerbar/model.js +1077 -0
  448. package/src/menus/headerbar/view.js +675 -0
  449. package/src/menus/image/index.js +1 -0
  450. package/src/menus/image/model.js +32 -0
  451. package/src/menus/index.js +9 -0
  452. package/src/menus/navigator/index.js +1 -0
  453. package/src/menus/navigator/model.js +28 -0
  454. package/src/menus/ordered_list/index.js +1 -0
  455. package/src/menus/ordered_list/model.js +19 -0
  456. package/src/menus/selection/index.js +2 -0
  457. package/src/menus/selection/model.js +134 -0
  458. package/src/menus/selection/view.js +154 -0
  459. package/src/menus/table/index.js +1 -0
  460. package/src/menus/table/model.js +414 -0
  461. package/src/menus/toolbar/index.js +2 -0
  462. package/src/menus/toolbar/model.js +920 -0
  463. package/src/menus/toolbar/view.js +354 -0
  464. package/src/navigator/index.js +515 -0
  465. package/src/no_collab_save/index.js +209 -0
  466. package/src/plugins/citation_dialog/index.js +1 -0
  467. package/src/plugins/editor/index.js +1 -0
  468. package/src/state_plugins/access_rights.js +47 -0
  469. package/src/state_plugins/citation_render.js +88 -0
  470. package/src/state_plugins/clipboard.js +289 -0
  471. package/src/state_plugins/code_block.js +201 -0
  472. package/src/state_plugins/collab_carets.js +152 -0
  473. package/src/state_plugins/comments.js +259 -0
  474. package/src/state_plugins/contributor_input/add_button.js +134 -0
  475. package/src/state_plugins/contributor_input/dropup.js +318 -0
  476. package/src/state_plugins/contributor_input/helpers.js +24 -0
  477. package/src/state_plugins/contributor_input/index.js +2 -0
  478. package/src/state_plugins/contributor_input/node_view.js +86 -0
  479. package/src/state_plugins/contributor_input/plugin.js +318 -0
  480. package/src/state_plugins/document_template.js +315 -0
  481. package/src/state_plugins/figure.js +108 -0
  482. package/src/state_plugins/footnote_markers.js +238 -0
  483. package/src/state_plugins/headerbar.js +12 -0
  484. package/src/state_plugins/index.js +73 -0
  485. package/src/state_plugins/inline_math.js +918 -0
  486. package/src/state_plugins/inline_reference/dropup.js +208 -0
  487. package/src/state_plugins/inline_reference/index.js +5 -0
  488. package/src/state_plugins/inline_reference/plugin.js +1429 -0
  489. package/src/state_plugins/jump_hidden_nodes.js +58 -0
  490. package/src/state_plugins/links.js +830 -0
  491. package/src/state_plugins/marginboxes.js +14 -0
  492. package/src/state_plugins/ordered_list_menu.js +84 -0
  493. package/src/state_plugins/placeholders.js +123 -0
  494. package/src/state_plugins/search.js +251 -0
  495. package/src/state_plugins/selection_menu.js +12 -0
  496. package/src/state_plugins/settings.js +223 -0
  497. package/src/state_plugins/table.js +127 -0
  498. package/src/state_plugins/tag_input/helpers.js +69 -0
  499. package/src/state_plugins/tag_input/index.js +2 -0
  500. package/src/state_plugins/tag_input/node_view.js +85 -0
  501. package/src/state_plugins/tag_input/plugin.js +278 -0
  502. package/src/state_plugins/tag_input/tag_editor.js +202 -0
  503. package/src/state_plugins/tag_input/tag_editor_plugins.js +74 -0
  504. package/src/state_plugins/toc_render.js +160 -0
  505. package/src/state_plugins/toolbar.js +12 -0
  506. package/src/state_plugins/track/find_selected_changes.js +107 -0
  507. package/src/state_plugins/track/helpers.js +108 -0
  508. package/src/state_plugins/track/index.js +6 -0
  509. package/src/state_plugins/track/plugin.js +140 -0
  510. package/src/tools/index.js +3 -0
  511. package/src/tools/key_bindings/index.js +21 -0
  512. package/src/tools/key_bindings/templates.js +68 -0
  513. package/src/tools/search_replace/index.js +421 -0
  514. package/src/tools/search_replace/templates.js +19 -0
  515. package/src/tools/word_count/index.js +59 -0
  516. package/src/tools/word_count/templates.js +34 -0
  517. package/src/track/accept.js +102 -0
  518. package/src/track/accept_all.js +103 -0
  519. package/src/track/accept_all_no_insertions.js +102 -0
  520. package/src/track/amend_transaction.js +562 -0
  521. package/src/track/delete.js +92 -0
  522. package/src/track/index.js +8 -0
  523. package/src/track/mod.js +116 -0
  524. package/src/track/reject.js +116 -0
  525. package/src/track/reject_all.js +121 -0
@@ -0,0 +1,830 @@
1
+ import {NodeSelection, Plugin, PluginKey} from "prosemirror-state"
2
+ import {RemoveMarkStep} from "prosemirror-transform"
3
+ import {Decoration, DecorationSet} from "prosemirror-view"
4
+
5
+ import {
6
+ randomFigureId,
7
+ randomHeadingId,
8
+ randomListId,
9
+ randomTableId
10
+ } from "@fiduswriter/document/schema/common/index"
11
+ import {CATS} from "@fiduswriter/document/schema/i18n"
12
+ import {addAlert, noSpaceTmp} from "fwtoolkit"
13
+ import {CitationDialog, LinkDialog} from "../dialogs"
14
+
15
+ const key = new PluginKey("links")
16
+
17
+ const copyLink = href => {
18
+ const textarea = document.createElement("textarea")
19
+ textarea.textContent = href
20
+ textarea.style.position = "fixed" // Prevent scrolling to bottom of page in MS Edge.
21
+ document.body.appendChild(textarea)
22
+ textarea.select()
23
+ try {
24
+ document.execCommand("copy") // Security exception may be thrown by some browsers.
25
+ document.body.removeChild(textarea)
26
+ addAlert("info", gettext("Link copied to clipboard"))
27
+ } catch (_ex) {
28
+ addAlert(
29
+ "info",
30
+ gettext("Copy to clipboard failed. Please copy manually.")
31
+ )
32
+ }
33
+ }
34
+
35
+ const nonDeletedTextContent = node => {
36
+ let text = ""
37
+ node.descendants(subNode => {
38
+ if (
39
+ subNode.isText &&
40
+ !subNode.marks.find(mark => mark.type.name === "deletion")
41
+ ) {
42
+ text += subNode.text
43
+ }
44
+ })
45
+ return text
46
+ }
47
+
48
+ export const getInternalTargets = (state, language, editor) => {
49
+ const internalTargets = []
50
+ const anchors = {}
51
+ const categories = {}
52
+
53
+ state.doc.descendants(node => {
54
+ if (node.attrs.track?.find(track => track.type === "deletion")) {
55
+ return true
56
+ }
57
+ if (node.type.groups.includes("heading")) {
58
+ const textContent = nonDeletedTextContent(node)
59
+ if (textContent.length) {
60
+ internalTargets.push({
61
+ id: node.attrs.id,
62
+ text: textContent
63
+ })
64
+ }
65
+ return true
66
+ }
67
+
68
+ if (
69
+ ["figure", "table"].includes(node.type.name) &&
70
+ node.attrs.category &&
71
+ node.attrs.category !== "none"
72
+ ) {
73
+ if (!categories[node.attrs.category]) {
74
+ categories[node.attrs.category] = 0
75
+ }
76
+ categories[node.attrs.category]++
77
+
78
+ internalTargets.push({
79
+ id: node.attrs.id,
80
+ text:
81
+ editor === "main"
82
+ ? `${CATS[node.attrs.category][language]} ${categories[node.attrs.category]}`
83
+ : `${CATS[node.attrs.category][language]} ${categories[node.attrs.category]}A`
84
+ })
85
+ return true
86
+ }
87
+
88
+ if (
89
+ node.type.name === "code_block" &&
90
+ node.attrs.category &&
91
+ node.attrs.id
92
+ ) {
93
+ if (!categories[node.attrs.category]) {
94
+ categories[node.attrs.category] = 0
95
+ }
96
+ categories[node.attrs.category]++
97
+
98
+ const categoryLabel =
99
+ CATS[node.attrs.category]?.[language] || node.attrs.category
100
+ const text = node.attrs.title
101
+ ? `${categoryLabel} ${categories[node.attrs.category]}: ${node.attrs.title}`
102
+ : `${categoryLabel} ${categories[node.attrs.category]}`
103
+
104
+ internalTargets.push({
105
+ id: node.attrs.id,
106
+ text: editor === "main" ? text : `${text}A`
107
+ })
108
+ return true
109
+ }
110
+
111
+ if (node.type.name === "text") {
112
+ const anchor = node.marks.find(mark => mark.type.name === "anchor")
113
+ if (anchor) {
114
+ anchors[anchor.attrs.id] =
115
+ (anchors[anchor.attrs.id] || "") + node.text
116
+ }
117
+ }
118
+ })
119
+ Object.entries(anchors).forEach(([id, text]) =>
120
+ internalTargets.push({id, text})
121
+ )
122
+
123
+ return internalTargets
124
+ }
125
+
126
+ export const linksPlugin = options => {
127
+ // Holds the action functions for every visible <li> in the current dropup,
128
+ // ordered exactly as they appear in the DOM. Populated by createDropUp()
129
+ // and consumed by the handleKeyDown prop.
130
+ let currentDropUpActions = []
131
+
132
+ function getUrl(state, oldState, oldUrl) {
133
+ const id = state.selection.$head.parent.attrs.id,
134
+ mark = state.selection.$head
135
+ .marks()
136
+ .find(mark => mark.type.name === "anchor")
137
+ let newUrl = oldUrl.split("#")[0]
138
+ if (mark) {
139
+ newUrl += `#${mark.attrs.id}`
140
+ } else if (id) {
141
+ newUrl += `#${id}`
142
+ }
143
+ const changed = oldUrl === newUrl ? false : true
144
+ // TODO: Should the following be moved to a view?
145
+ // Not sure if this counts as a DOM update.
146
+ if (changed && options.editor.currentView.state === oldState) {
147
+ window.history.replaceState("", "", newUrl)
148
+ }
149
+ return newUrl
150
+ }
151
+
152
+ function getLinkMark(state) {
153
+ return state.selection.$head
154
+ .marks()
155
+ .find(mark => mark.type.name === "link")
156
+ }
157
+
158
+ function getAnchorMark(state) {
159
+ return state.selection.$head
160
+ .marks()
161
+ .find(mark => mark.type.name === "anchor")
162
+ }
163
+
164
+ function getCrossReference(state) {
165
+ // When inline_references is enabled the inline reference editor
166
+ // handles cross-references; don't show the links dropup for them.
167
+ if (
168
+ options.editor?.app?.config?.user?.preferences
169
+ ?.inline_references === true
170
+ ) {
171
+ return undefined
172
+ }
173
+ return state.selection instanceof NodeSelection
174
+ ? state.selection.node.type.name == "cross_reference"
175
+ ? state.selection.node
176
+ : undefined
177
+ : undefined
178
+ }
179
+
180
+ function getCitation(state) {
181
+ // Only surface a citation in the links dropup when inline_references
182
+ // is disabled (otherwise the inline reference editor handles it).
183
+ if (
184
+ options.editor?.app?.config?.user?.preferences
185
+ ?.inline_references === true
186
+ ) {
187
+ return undefined
188
+ }
189
+ return state.selection instanceof NodeSelection
190
+ ? state.selection.node.type.name === "citation"
191
+ ? state.selection.node
192
+ : undefined
193
+ : undefined
194
+ }
195
+
196
+ function getDecos(state, selectedIndex = -1) {
197
+ const $head = state.selection.$head
198
+ const currentMarks = [],
199
+ linkMark = $head.marks().find(mark => mark.type.name === "link"),
200
+ anchorMark = $head.marks().find(mark => mark.type.name === "anchor")
201
+ const crossRef = getCrossReference(state)
202
+ const citation = getCitation(state)
203
+
204
+ if (linkMark) {
205
+ currentMarks.push(linkMark)
206
+ }
207
+ if (anchorMark) {
208
+ currentMarks.push(anchorMark)
209
+ }
210
+ if (crossRef) {
211
+ currentMarks.push(crossRef)
212
+ }
213
+ if (citation) {
214
+ currentMarks.push(citation)
215
+ }
216
+ if (!currentMarks.length) {
217
+ return DecorationSet.empty
218
+ }
219
+
220
+ let startPos = $head.start() // position of block start.
221
+ if (crossRef || citation) {
222
+ // For inline nodes, place dropup after the node
223
+ startPos = state.selection.from + (crossRef || citation).nodeSize
224
+ } else {
225
+ let index = $head.index()
226
+ while (
227
+ index < $head.parent.childCount - 1 &&
228
+ currentMarks.some(mark =>
229
+ mark.isInSet($head.parent.child(index + 1).marks)
230
+ )
231
+ ) {
232
+ index++
233
+ }
234
+ for (let i = 0; i <= index; i++) {
235
+ startPos += $head.parent.child(i).nodeSize
236
+ }
237
+ }
238
+ const dom = createDropUp(
239
+ linkMark,
240
+ anchorMark,
241
+ crossRef,
242
+ $head,
243
+ citation,
244
+ selectedIndex
245
+ ),
246
+ deco = Decoration.widget(startPos, dom)
247
+ return DecorationSet.create(state.doc, [deco])
248
+ }
249
+
250
+ function createDropUp(
251
+ linkMark,
252
+ anchorMark,
253
+ crossRef,
254
+ $head,
255
+ citation = null,
256
+ selectedIndex = -1
257
+ ) {
258
+ const dropUp = document.createElement("span"),
259
+ editor = options.editor,
260
+ writeAccess =
261
+ editor.docInfo.access_rights === "write" ? true : false,
262
+ editAccess = ["write", "write-tracked", "review-tracked"].includes(
263
+ editor.docInfo.access_rights
264
+ )
265
+ ? true
266
+ : false
267
+ let linkType,
268
+ linkHref,
269
+ anchorHref,
270
+ requiredPx = 10
271
+
272
+ if (linkMark) {
273
+ linkType = linkMark.attrs.href[0] === "#" ? "internal" : "external"
274
+ linkHref =
275
+ linkType === "internal"
276
+ ? window.location.href.split("#")[0] + linkMark.attrs.href
277
+ : linkMark.attrs.href
278
+ requiredPx += 120
279
+ }
280
+
281
+ if (anchorMark) {
282
+ anchorHref =
283
+ window.location.href.split("#")[0] + "#" + anchorMark.attrs.id
284
+ requiredPx += 92
285
+ }
286
+
287
+ if (citation) {
288
+ requiredPx += 92
289
+ }
290
+
291
+ dropUp.classList.add("drop-up-outer")
292
+
293
+ dropUp.innerHTML = noSpaceTmp`
294
+ <div class="link drop-up-inner" style="top: -${requiredPx}px;">
295
+ ${
296
+ linkMark
297
+ ? `<div class="drop-up-head">
298
+ ${
299
+ linkMark.attrs.title
300
+ ? `<div class="link-title">${gettext("Title")}:&nbsp;${linkMark.attrs.title}</div>`
301
+ : ""
302
+ }
303
+ <div class="link-href">
304
+ <a class="href${linkType === "internal" ? " internal" : ""}" ${linkType === "external" ? 'target="_blank"' : ""} href="${linkHref}">
305
+ ${linkHref}
306
+ </a>
307
+ </div>
308
+ </div>
309
+ <ul class="drop-up-options">
310
+ <li class="copy-link" title="${gettext("Copy link")}">
311
+ ${gettext("Copy link")}
312
+ </li>
313
+ ${
314
+ writeAccess
315
+ ? `<li class="edit-link" title="${gettext("Edit link")}">
316
+ ${gettext("Edit")}
317
+ </li>
318
+ <li class="remove-link" title="${gettext("Remove link")}">
319
+ ${gettext("Remove")}
320
+ </li>`
321
+ : ""
322
+ }
323
+ </ul>`
324
+ : ""
325
+ }
326
+ ${
327
+ anchorMark
328
+ ? `<div class="drop-up-head">
329
+ <div class="link-title">${gettext("Anchor")}</div>
330
+ <div class="link-href">
331
+ <a class="href" target="_blank" href="${anchorHref}">
332
+ ${anchorHref}
333
+ </a>
334
+ </div>
335
+ </div>
336
+ <ul class="drop-up-options">
337
+ <li class="copy-anchor" title="${gettext("Copy anchor")}">
338
+ ${gettext("Copy anchor")}
339
+ </li>
340
+ ${
341
+ writeAccess
342
+ ? `<li class="remove-anchor" title="${gettext("Remove anchor")}">
343
+ ${gettext("Remove")}
344
+ </li>`
345
+ : ""
346
+ }
347
+ </ul>`
348
+ : ""
349
+ }
350
+ ${
351
+ crossRef
352
+ ? `<div class="drop-up-head" ${editAccess ? "" : 'style="border-radius:6px;"'}>
353
+ <div class="link-title">${gettext("Cross Reference")}</div>
354
+ <div class="link-href">
355
+ <span>
356
+ ${crossRef.attrs.title ? crossRef.attrs.title : "Target Lost"}
357
+ </a>
358
+ </div>
359
+ </div>
360
+ ${
361
+ editAccess
362
+ ? `<ul class="drop-up-options">
363
+ <li class="edit-crossRef" title="${gettext("Edit cross reference")}">
364
+ ${gettext("Edit")}
365
+ </li>
366
+ <li class="remove-crossRef" title="${gettext("Remove cross reference")}">
367
+ ${gettext("Remove")}
368
+ </li>
369
+ </ul>`
370
+ : ""
371
+ }
372
+ `
373
+ : ""
374
+ }
375
+ ${
376
+ citation
377
+ ? `<div class="drop-up-head" ${editAccess ? "" : 'style="border-radius:6px;"'}>
378
+ <div class="link-title">${gettext("Citation")}</div>
379
+ <div class="link-href">
380
+ <span>${citation.attrs.format}</span>
381
+ </div>
382
+ </div>
383
+ ${
384
+ editAccess
385
+ ? `<ul class="drop-up-options">
386
+ <li class="edit-citation" title="${gettext("Edit citation")}">
387
+ ${gettext("Edit")}
388
+ </li>
389
+ <li class="remove-citation" title="${gettext("Remove citation")}">
390
+ ${gettext("Remove")}
391
+ </li>
392
+ </ul>`
393
+ : ""
394
+ }
395
+ `
396
+ : ""
397
+ }
398
+ </div>`
399
+
400
+ if (linkType === "internal") {
401
+ const el = dropUp.querySelector("a.internal")
402
+ el.addEventListener("click", event => {
403
+ event.preventDefault()
404
+ event.stopImmediatePropagation()
405
+ options.editor.scrollIdIntoView(linkMark.attrs.href.slice(1))
406
+ })
407
+ }
408
+
409
+ // Rebuild the actions array so handleKeyDown always has the current
410
+ // set of handlers in the same order the <li> items appear in the DOM.
411
+ currentDropUpActions = []
412
+ const setupAction = (selector, action) => {
413
+ const el = dropUp.querySelector(selector)
414
+ if (!el) {
415
+ return
416
+ }
417
+ currentDropUpActions.push(action)
418
+ el.addEventListener("mousedown", event => {
419
+ event.preventDefault()
420
+ event.stopImmediatePropagation()
421
+ action()
422
+ })
423
+ }
424
+
425
+ // Actions must be registered in the same order they appear in the HTML
426
+ // template so that selectedIndex maps to the correct <li> element.
427
+ setupAction(".copy-link", () => copyLink(linkHref))
428
+ setupAction(".edit-link", () => {
429
+ const dialog = new LinkDialog(editor)
430
+ dialog.init()
431
+ })
432
+ setupAction(".remove-link", () => {
433
+ editor.view.dispatch(
434
+ editor.view.state.tr.removeMark(
435
+ $head.start(),
436
+ $head.end(),
437
+ linkMark
438
+ )
439
+ )
440
+ })
441
+ setupAction(".copy-anchor", () => copyLink(anchorHref))
442
+ setupAction(".remove-anchor", () => {
443
+ editor.view.dispatch(
444
+ editor.view.state.tr.removeMark(
445
+ $head.start(),
446
+ $head.end(),
447
+ anchorMark
448
+ )
449
+ )
450
+ })
451
+ setupAction(".edit-crossRef", () => {
452
+ const dialog = new LinkDialog(editor)
453
+ dialog.init()
454
+ })
455
+ setupAction(".remove-crossRef", () => {
456
+ editor.view.dispatch(
457
+ editor.view.state.tr.delete($head.pos - 1, $head.pos)
458
+ )
459
+ })
460
+ setupAction(".edit-citation", () => {
461
+ const dialog = new CitationDialog(editor)
462
+ dialog.init()
463
+ })
464
+ setupAction(".remove-citation", () => {
465
+ editor.view.dispatch(
466
+ editor.view.state.tr.delete($head.pos - 1, $head.pos)
467
+ )
468
+ })
469
+
470
+ // Apply keyboard-focus highlight to the currently selected item.
471
+ if (selectedIndex >= 0 && selectedIndex < currentDropUpActions.length) {
472
+ const items = Array.from(
473
+ dropUp.querySelectorAll(".drop-up-options li")
474
+ )
475
+ if (items[selectedIndex]) {
476
+ items[selectedIndex].classList.add("fw-focused")
477
+ }
478
+ }
479
+
480
+ return dropUp
481
+ }
482
+
483
+ return new Plugin({
484
+ key,
485
+ state: {
486
+ init() {
487
+ return {
488
+ url: window.location.href,
489
+ decos: DecorationSet.empty,
490
+ linkMark: false,
491
+ citation: undefined,
492
+ selectedIndex: -1
493
+ }
494
+ },
495
+ apply(tr, _prev, oldState, state) {
496
+ let {
497
+ url,
498
+ decos,
499
+ linkMark,
500
+ anchorMark,
501
+ crossReference,
502
+ citation,
503
+ selectedIndex
504
+ } = this.getState(oldState)
505
+ url = getUrl(state, oldState, url)
506
+ const newLinkMark = getLinkMark(state)
507
+ const newAnchorMark = getAnchorMark(state)
508
+ const newCrossReference = getCrossReference(state)
509
+ const newCitation = getCitation(state)
510
+ const meta = tr.getMeta(key)
511
+ if (meta?.action === "navigate") {
512
+ // Keyboard navigation: only selectedIndex changes; rebuild
513
+ // the decoration so the focused class is applied correctly.
514
+ selectedIndex = meta.index
515
+ decos = getDecos(state, selectedIndex)
516
+ } else if (
517
+ newLinkMark === linkMark &&
518
+ newAnchorMark === anchorMark &&
519
+ newCrossReference === crossReference &&
520
+ newCitation === citation
521
+ ) {
522
+ decos = decos.map(tr.mapping, tr.doc)
523
+ } else {
524
+ // The cursor moved to a different mark — reset selection.
525
+ selectedIndex = -1
526
+ decos = getDecos(state, selectedIndex)
527
+ linkMark = newLinkMark
528
+ anchorMark = newAnchorMark
529
+ crossReference = newCrossReference
530
+ citation = newCitation
531
+ }
532
+ if (!tr.getMeta("remote")) {
533
+ // We look for changes to figures or headings.
534
+ let foundIdElement = false // found heading or figure
535
+ let ranges = []
536
+ tr.steps.forEach((step, index) => {
537
+ ranges.push([step.from, step.to])
538
+ tr.docs[index].nodesBetween(
539
+ step.from,
540
+ step.to,
541
+ node => {
542
+ if (
543
+ node.type.groups.includes("heading") ||
544
+ node.type.name === "figure"
545
+ ) {
546
+ foundIdElement = true
547
+ }
548
+ }
549
+ )
550
+ ranges = ranges.map(range => {
551
+ return [
552
+ tr.mapping.maps[index].map(range[0], -1),
553
+ tr.mapping.maps[index].map(range[1], 1)
554
+ ]
555
+ })
556
+ })
557
+ let foundAnchorWithoutId = false // found an anchor without an ID
558
+ ranges.forEach(range => {
559
+ state.doc.nodesBetween(range[0], range[1], node => {
560
+ if (
561
+ !foundIdElement &&
562
+ (node.type.groups.includes("heading") ||
563
+ [
564
+ "figure",
565
+ "table",
566
+ "bullet_list",
567
+ "ordered_list"
568
+ ].includes(node.type.name))
569
+ ) {
570
+ foundIdElement = true
571
+ }
572
+ if (!foundAnchorWithoutId) {
573
+ node.marks.forEach(mark => {
574
+ if (
575
+ mark.type.name === "anchor" &&
576
+ !mark.attrs.id
577
+ ) {
578
+ foundAnchorWithoutId = true
579
+ }
580
+ })
581
+ }
582
+ })
583
+ })
584
+
585
+ if (foundIdElement || foundAnchorWithoutId) {
586
+ const linkUpdate = {foundAnchorWithoutId}
587
+ tr.setMeta("linkUpdate", linkUpdate)
588
+ if (
589
+ oldState.schema === options.editor.view.state.schema
590
+ ) {
591
+ tr.setMeta("toFoot", {linkUpdate: true})
592
+ } else {
593
+ tr.setMeta("toMain", {linkUpdate: true})
594
+ }
595
+ }
596
+ }
597
+
598
+ return {
599
+ url,
600
+ decos,
601
+ linkMark,
602
+ anchorMark,
603
+ crossReference,
604
+ citation,
605
+ selectedIndex
606
+ }
607
+ }
608
+ },
609
+ appendTransaction: (trs, oldState, newState) => {
610
+ // Check if any of the transactions are local.
611
+ if (trs.every(tr => !tr.getMeta("linkUpdate"))) {
612
+ // All transactions are remote or don't change anything. Give up.
613
+ return
614
+ }
615
+
616
+ const foundAnchorWithoutId = trs.find(tr => {
617
+ const linkUpdate = tr.getMeta("linkUpdate")
618
+ return linkUpdate && linkUpdate.foundAnchorWithoutId
619
+ })
620
+ // ID should not be found in the other pm either. So we look through
621
+ // those as well.
622
+ let otherState, language
623
+ if (oldState.schema === options.editor.view.state.schema) {
624
+ otherState = options.editor.mod.footnotes.fnEditor.view.state
625
+ language = newState.doc.attrs.language
626
+ } else {
627
+ otherState = options.editor.view.state
628
+ language = options.editor.view.state.doc.attrs.language
629
+ }
630
+
631
+ const internalTargets = getInternalTargets(
632
+ newState,
633
+ language,
634
+ oldState.schema === options.editor.view.state.schema
635
+ ? "main"
636
+ : "foot"
637
+ ).concat(
638
+ getInternalTargets(
639
+ otherState,
640
+ language,
641
+ oldState.schema === options.editor.view.state.schema
642
+ ? "foot"
643
+ : "main"
644
+ )
645
+ )
646
+
647
+ // Check if there are any headings or figures in the affected range.
648
+ // Otherwise, skip.
649
+
650
+ // Check that unique IDs only exist once in the document and that the
651
+ // text values are up to date for all IDs if they are referenced.
652
+ //
653
+ // If an ID is used more than once, add steps to change the ID of all
654
+ // but the first occurence.
655
+ const ids = []
656
+
657
+ otherState.doc.descendants(node => {
658
+ if (
659
+ node.type.groups.includes("heading") ||
660
+ ["figure", "table", "bullet_list", "ordered_list"].includes(
661
+ node.type.name
662
+ )
663
+ ) {
664
+ ids.push(node.attrs.id)
665
+ }
666
+ })
667
+
668
+ const newTr = newState.tr.setMeta("fixIds", true)
669
+
670
+ newState.doc.descendants((node, pos) => {
671
+ if (
672
+ node.type.groups.includes("heading") ||
673
+ ["figure", "table", "bullet_list", "ordered_list"].includes(
674
+ node.type.name
675
+ )
676
+ ) {
677
+ if (ids.includes(node.attrs.id) || !node.attrs.id) {
678
+ // Add node if the id is false (default) or it is present twice
679
+ const randomIdGenerator = node.type.groups.includes(
680
+ "heading"
681
+ )
682
+ ? randomHeadingId
683
+ : node.type.name === "figure"
684
+ ? randomFigureId
685
+ : node.type.name === "table"
686
+ ? randomTableId
687
+ : randomListId
688
+ let id
689
+
690
+ while (!id || ids.includes(id)) {
691
+ id = randomIdGenerator()
692
+ }
693
+
694
+ const attrs = Object.assign({}, node.attrs, {id})
695
+
696
+ // Because we only change attributes, positions should stay the
697
+ // the same throughout all our extra steps. We therefore do no
698
+ // mapping of positions through these steps.
699
+ newTr.setNodeMarkup(pos, null, attrs)
700
+
701
+ ids.push(id)
702
+ } else {
703
+ ids.push(node.attrs.id)
704
+ }
705
+ } else if (
706
+ node.type.name === "cross_reference" &&
707
+ !internalTargets.find(
708
+ it =>
709
+ it.id === node.attrs.id &&
710
+ it.text === node.attrs.title
711
+ )
712
+ ) {
713
+ const iTarget = internalTargets.find(
714
+ it => it.id === node.attrs.id
715
+ )
716
+ const attrs = Object.assign({}, node.attrs, {
717
+ title: iTarget ? iTarget.text : null
718
+ })
719
+ newTr.setNodeMarkup(pos, null, attrs)
720
+ }
721
+ node.marks.forEach(mark => {
722
+ if (
723
+ mark.type.name === "link" &&
724
+ mark.attrs.href[0] === "#" &&
725
+ !internalTargets.find(
726
+ it =>
727
+ it.id === mark.attrs.href.slice(1) &&
728
+ it.text === node.attrs.title
729
+ )
730
+ ) {
731
+ const iTarget = internalTargets.find(
732
+ it => it.id === mark.attrs.href.slice(1)
733
+ )
734
+ const attrs = Object.assign({}, mark.attrs, {
735
+ title: iTarget ? iTarget.text : null
736
+ })
737
+ newTr.addMark(
738
+ pos,
739
+ pos + node.nodeSize,
740
+ newState.schema.marks.link.create(attrs)
741
+ )
742
+ }
743
+ })
744
+ })
745
+
746
+ // Remove anchor marks without ID
747
+ if (foundAnchorWithoutId) {
748
+ const markType = newState.schema.marks.anchor.create({
749
+ id: false
750
+ })
751
+ newTr.step(
752
+ new RemoveMarkStep(0, newState.doc.content.size, markType)
753
+ )
754
+ }
755
+
756
+ return newTr
757
+ },
758
+ props: {
759
+ handleDOMEvents: {
760
+ focus: (view, _event) => {
761
+ const {url} = key.getState(view.state)
762
+ window.history.replaceState("", "", url)
763
+ }
764
+ },
765
+ handleKeyDown(view, event) {
766
+ const pluginState = key.getState(view.state)
767
+ if (!pluginState) {
768
+ return false
769
+ }
770
+ const {
771
+ linkMark,
772
+ anchorMark,
773
+ crossReference,
774
+ citation,
775
+ selectedIndex
776
+ } = pluginState
777
+ // Only intercept arrow/enter keys when a dropup is visible.
778
+ if (!linkMark && !anchorMark && !crossReference && !citation) {
779
+ return false
780
+ }
781
+ const totalItems = currentDropUpActions.length
782
+ if (totalItems === 0) {
783
+ return false
784
+ }
785
+
786
+ if (event.key === "ArrowDown") {
787
+ event.preventDefault()
788
+ const newIndex =
789
+ selectedIndex < totalItems - 1 ? selectedIndex + 1 : 0
790
+ view.dispatch(
791
+ view.state.tr.setMeta(key, {
792
+ action: "navigate",
793
+ index: newIndex
794
+ })
795
+ )
796
+ return true
797
+ }
798
+
799
+ if (event.key === "ArrowUp") {
800
+ event.preventDefault()
801
+ const newIndex =
802
+ selectedIndex <= 0 ? totalItems - 1 : selectedIndex - 1
803
+ view.dispatch(
804
+ view.state.tr.setMeta(key, {
805
+ action: "navigate",
806
+ index: newIndex
807
+ })
808
+ )
809
+ return true
810
+ }
811
+
812
+ if (
813
+ event.key === "Enter" &&
814
+ selectedIndex >= 0 &&
815
+ selectedIndex < totalItems
816
+ ) {
817
+ event.preventDefault()
818
+ currentDropUpActions[selectedIndex]()
819
+ return true
820
+ }
821
+
822
+ return false
823
+ },
824
+ decorations(state) {
825
+ const {decos} = this.getState(state)
826
+ return decos
827
+ }
828
+ }
829
+ })
830
+ }