@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,1065 @@
1
+ import {BIBLIOGRAPHY_HEADERS} from "@fiduswriter/document/schema/i18n"
2
+ import {
3
+ Dialog,
4
+ activateWait,
5
+ deactivateWait,
6
+ ensureCSS,
7
+ faqDialog,
8
+ showSystemMessage
9
+ } from "fwtoolkit"
10
+ import {collab} from "prosemirror-collab"
11
+ import {baseKeymap} from "prosemirror-commands"
12
+ import {dropCursor} from "prosemirror-dropcursor"
13
+ import {buildKeymap} from "prosemirror-example-setup"
14
+ import {gapCursor} from "prosemirror-gapcursor"
15
+ import {keymap} from "prosemirror-keymap"
16
+ import {EditorState} from "prosemirror-state"
17
+ import {
18
+ AddMarkStep,
19
+ Mapping,
20
+ RemoveMarkStep,
21
+ ReplaceAroundStep,
22
+ ReplaceStep
23
+ } from "prosemirror-transform"
24
+ import {EditorView} from "prosemirror-view"
25
+ import {RenderCitations} from "../../../citations/render"
26
+ import {buildEditorKeymap} from "../../keymap"
27
+ import {jumpHiddenNodesPlugin, searchPlugin} from "../../state_plugins"
28
+ import {trackedTransaction} from "../../track"
29
+ import {changeSet} from "./changeset"
30
+ import {FootnoteView} from "./footnotes"
31
+ import {recreateTransform} from "./recreate_transform"
32
+ import {createDiffSchema} from "./schema"
33
+ import {clipboardPlugin, diffPlugin} from "./state_plugins"
34
+ import {
35
+ checkPresenceOfdiffdata,
36
+ dispatchRemoveDiffdata,
37
+ removeDiffFromJson,
38
+ simplifyTransform
39
+ } from "./tools"
40
+
41
+ export class MergeEditor {
42
+ constructor(editor, cpDoc, offlineDoc, onlineDoc, offlineTr, onlineTr, db) {
43
+ this.editor = editor
44
+ this.schema = createDiffSchema(editor.schema)
45
+ this.cpDoc = this.schema.nodeFromJSON(cpDoc.toJSON())
46
+ this.offlineDoc = this.schema.nodeFromJSON(offlineDoc.toJSON())
47
+ this.onlineDoc = this.schema.nodeFromJSON(onlineDoc.toJSON())
48
+ this.offlineTr = simplifyTransform(offlineTr) // The offline transaction
49
+ this.onlineTr = simplifyTransform(onlineTr) // The online Transaction
50
+ this.mergeDialog = this.createMergeDialog(
51
+ this.offlineTr,
52
+ this.onlineDoc
53
+ )
54
+ this.warningDialog = false
55
+ this.db = db
56
+ this.mergedDocMap = this.onlineTr.mapping // the maps of the middle editor, used for applying steps automatically
57
+
58
+ this.mergeView1 = false
59
+ this.mergeView2 = false
60
+ this.mergeView3 = false
61
+ this.imageDataModified = {} // To hold data related to re-uploaded images.
62
+
63
+ this.offlineTrackedSteps = []
64
+
65
+ this.diffEditorPlugins = [
66
+ [diffPlugin, () => ({merge: this})],
67
+ [keymap, () => buildEditorKeymap(this.schema)],
68
+ [keymap, () => buildKeymap(this.schema)],
69
+ [keymap, () => baseKeymap],
70
+ [collab, () => ({clientID: this.editor.client_id})],
71
+ // [history],
72
+ [dropCursor],
73
+ [gapCursor],
74
+ // [tableEditing],
75
+ [jumpHiddenNodesPlugin],
76
+ [searchPlugin],
77
+ [clipboardPlugin, () => ({editor: this.editor})]
78
+ ]
79
+
80
+ // assign image DB & BibDB to be used in document schema.
81
+ this.schema.cached.bibDB = this.editor.mod.db.bibDB
82
+ this.schema.cached.imageDB = this.editor.mod.db.imageDB
83
+ // Carry over the encrypted-image decryption handler.
84
+ this.schema.cached.decryptImage = this.editor.schema.cached.decryptImage
85
+ }
86
+
87
+ init() {
88
+ /* Create the diff editors */
89
+ ensureCSS([staticUrl("css/merge.css")])
90
+ // Activate wait overlay
91
+ activateWait()
92
+
93
+ this.mergeDialog.open()
94
+
95
+ // Create multiple editor views
96
+ this.mergeView1 = this.bindEditorView("editor-diff-common", this.cpDoc)
97
+ this.mergeView2 = this.bindEditorView(
98
+ "editor-diff-online",
99
+ this.onlineDoc
100
+ )
101
+ this.mergeView3 = this.bindEditorView(
102
+ "editor-diff-offline",
103
+ this.offlineDoc
104
+ )
105
+
106
+ const offlineChangeset = new changeSet(this.offlineTr).getChangeSet()
107
+ const onlineChangeset = new changeSet(this.onlineTr).getChangeSet()
108
+
109
+ // Unhide All Sections in All the 3 views
110
+ this.unHideSectionsinAllDoc()
111
+
112
+ const offlineTrackedSteps = this.markChangesinDiffEditor(
113
+ offlineChangeset,
114
+ this.mergeView3,
115
+ "offline-inserted",
116
+ this.offlineTr
117
+ )
118
+ this.markChangesinDiffEditor(
119
+ onlineChangeset,
120
+ this.mergeView2,
121
+ "online-inserted",
122
+ this.onlineTr
123
+ )
124
+ this.offlineTrackedSteps =
125
+ this.offlineTrackedSteps.concat(offlineTrackedSteps)
126
+
127
+ if (
128
+ this.mergeView2.state.doc.attrs.tracked ||
129
+ this.mergeView3.state.doc.attrs.tracked
130
+ ) {
131
+ this.mergeView2.dispatch(
132
+ this.mergeView2.state.tr
133
+ .setDocAttribute("tracked", true)
134
+ .setMeta("notrack", true)
135
+ .setMeta("mapAppended", true)
136
+ )
137
+ }
138
+
139
+ this.renderCitation(this.mergeView1, "editor-diff-common")
140
+ this.renderCitation(this.mergeView2, "editor-diff-online")
141
+ this.renderCitation(this.mergeView3, "editor-diff-offline")
142
+
143
+ this.offStepsNotTracked = this.findNotTrackedSteps(
144
+ this.offlineTr,
145
+ this.offlineTrackedSteps
146
+ )
147
+
148
+ deactivateWait()
149
+
150
+ // Update the Bib and image DB before hand with the data from the offline document and the socket data.
151
+ this.updateDB(this.offlineDoc, this.db) // Updating the editor DB is one-time operation.
152
+ }
153
+
154
+ createMergeDialog(offlineTr, onlineDoc) {
155
+ const buttons = [
156
+ {
157
+ text: gettext("Merge Complete"),
158
+ classes: "fw-dark",
159
+ click: () => {
160
+ if (!this.checkResolution()) {
161
+ this.startMerge(offlineTr, onlineDoc)
162
+ } else {
163
+ this.warningDialog = new Dialog({
164
+ id: "merge-res-warning",
165
+ title: gettext("Merge Resolution warning"),
166
+ body: gettext(
167
+ "Not all changes have been resolved. Please make sure to review all the changes to before proceeding."
168
+ ),
169
+ buttons: [
170
+ {
171
+ text: gettext("Proceed to Merge"),
172
+ classes: "fw-dark",
173
+ click: () => {
174
+ this.startMerge(offlineTr, onlineDoc)
175
+ this.warningDialog.close()
176
+ }
177
+ }
178
+ ]
179
+ })
180
+ this.warningDialog.open()
181
+ }
182
+ }
183
+ }
184
+ ]
185
+ const dialog = new Dialog({
186
+ id: "editor-merge-view",
187
+ title: gettext("Merging Offline Document"),
188
+ body: `<div style="display:flex"><div class="offline-heading">${gettext("Common Document")}</div><div class="merged-heading">${gettext("Online Document")}</div> <div class="online-heading">${gettext("Offline Document")}</div></div><div class="user-contents" style="display:flex;"><div id="editor-diff-common" style="float:left;padding:15px;"></div><div id="editor-diff-online" class="merged-view" style="padding:15px;"></div><div id="editor-diff-offline" style="float:right;padding:15px;"></div></div>`,
189
+ fullScreen: true,
190
+ canClose: false,
191
+ help: () => {
192
+ const helpDialog = new faqDialog({
193
+ title: gettext("Merge Dialog Frequent Questions"),
194
+ questions: [
195
+ [
196
+ gettext("Why am I seeing this merge dialog?"),
197
+ gettext(
198
+ "You are seeing this merge dialog because you were offline for a long time, and the changes you made to the document while you were offline conflicted with the changes made by other users. So it was not possible to merge your edits in automatically."
199
+ )
200
+ ],
201
+ [
202
+ gettext("Am I the only one seeing this dialog?"),
203
+ gettext(
204
+ "Yes, you are the only one who can see this dialog. Therefore it would be great if you could ask your collaborators to stop editing the document, so that once you are finished with the merge, it will not lead to more conflicts."
205
+ )
206
+ ],
207
+ [
208
+ gettext(
209
+ "What if my collaborators continue working on the document while I am merging?"
210
+ ),
211
+ gettext(
212
+ "Do not worry, we can handle such a situation as we will simply show you another merge dialog."
213
+ )
214
+ ],
215
+ [
216
+ gettext("Why am I seeing three editors?"),
217
+ gettext(
218
+ "The editor on the left will show the last common version of the document. It is shown for reference only. The editor in the middle is the merge editor and it initially contains the document resulting from other users' edits. The editor on the right is the offline editor and it contains the document resulting from your changes while you were offline."
219
+ )
220
+ ],
221
+ [
222
+ gettext(
223
+ "What are the green and red highlights in the editors?"
224
+ ),
225
+ gettext(
226
+ "The editors in the middle and on the right will show content that is highlighted in green. They also contain text that is highlighted in red. The text marked in green corresponds to the text that was edited (added) by you or other users. The text marked in red corresponds to text that was deleted by either you or other users. The insertions and deletions made by other users will be marked in the merge editor. The insertions and deletions made by you will be marked in the offline editor on the right."
227
+ )
228
+ ],
229
+ [
230
+ gettext(
231
+ "How do I accept or reject a particular change?"
232
+ ),
233
+ // Add images in dictionary.They'd be interpolated later.
234
+ gettext(
235
+ "Accepting or rejecting a change in the merge editor in the middle or the offline editor on the right causes a change in the merge editor. You can accept a change by directly clicking on the highlighted text. A dropdown menu will appear and you can then either accept or reject the change. When you click on the highlighted text, it also highlights the changes that will get accepted. %(mergeImage)s As shown in the above image one can click on a highlighted change, and click on accept change. On accepting a change it will be reflected in the merged document editor in the middle. Rejecting a change works in the same way except on reject a change the highlight of the change will be lost, with it the ability to accept, reject or copy a change."
236
+ ),
237
+ {
238
+ mergeImage: `<img src="${staticUrl("img/accept_change.avif")}" class="merge-img">`
239
+ },
240
+ {hasImage: true}
241
+ ],
242
+ [
243
+ gettext(
244
+ "I cannot accept a particular change. What do I do?"
245
+ ),
246
+ gettext(
247
+ "If you cannot automatically accept a change into the merge editor, do not worry. You can choose to copy the change either by clicking on the copy button or manually copy the change and then paste it in the merge editor in the middle. It is as simple as that!"
248
+ )
249
+ ],
250
+ [
251
+ gettext("Can I edit content in all three editors?"),
252
+ gettext(
253
+ "You can edit the content only in the merge editor in the middle. You cannot edit content in the other two editors."
254
+ )
255
+ ],
256
+ [
257
+ gettext(
258
+ "Does the order in which I work on merging the changes matter?"
259
+ ),
260
+ gettext(
261
+ "It is always better to try to accept the changes in a linear fashion."
262
+ )
263
+ ],
264
+ [
265
+ gettext("What do I do after completing the merge?"),
266
+ gettext(
267
+ "After the merge is completed, you can click on the button 'Merge Complete' which in turn will move your changes from the merge editor in the middle to the main editor. Do note if other users made significant changes to the document while you were merging the document, you might have to merge the documents together again."
268
+ )
269
+ ],
270
+ [
271
+ gettext(
272
+ "What happens if I try to complete merge without resolving all the changes?"
273
+ ),
274
+ gettext(
275
+ "You will receive a warning when you try to complete a merge without accepting or rejecting all the changes. You can still proceed to merge the document. If you do that, all the insertions and deletions in the merge editor in the middle will be accepted automatically, and all the insertions and deletions in the offline editor on the right will be ignored."
276
+ )
277
+ ]
278
+ ]
279
+ })
280
+ helpDialog.open()
281
+ },
282
+ buttons
283
+ })
284
+ return dialog
285
+ }
286
+
287
+ checkResolution() {
288
+ /* To Check if all the diffs are resolved */
289
+ const offlineVersionDoc = this.mergeView3.state.doc,
290
+ mergedVersionDoc = this.mergeView2.state.doc
291
+ let diffAttrPresent = false
292
+ if (
293
+ offlineVersionDoc.rangeHasMark(
294
+ 0,
295
+ offlineVersionDoc.content.size,
296
+ this.schema.marks.diffdata
297
+ ) ||
298
+ mergedVersionDoc.rangeHasMark(
299
+ 0,
300
+ mergedVersionDoc.content.size,
301
+ this.schema.marks.diffdata
302
+ )
303
+ ) {
304
+ return true
305
+ }
306
+ offlineVersionDoc.nodesBetween(
307
+ 0,
308
+ offlineVersionDoc.content.size,
309
+ (node, _pos) => {
310
+ if (node.attrs.diffdata && node.attrs.diffdata.length > 0) {
311
+ diffAttrPresent = true
312
+ }
313
+ }
314
+ )
315
+ mergedVersionDoc.nodesBetween(
316
+ 0,
317
+ mergedVersionDoc.content.size,
318
+ (node, _pos) => {
319
+ if (node.attrs.diffdata && node.attrs.diffdata.length > 0) {
320
+ diffAttrPresent = true
321
+ }
322
+ }
323
+ )
324
+ if (
325
+ this.mergeView2.dom.querySelector(".deletion-decoration") ||
326
+ this.mergeView3.dom.querySelector(".deletion-decoration")
327
+ ) {
328
+ diffAttrPresent = true
329
+ }
330
+ if (diffAttrPresent) {
331
+ return true
332
+ }
333
+ return false
334
+ }
335
+
336
+ markChangesinDiffEditor(changeset, view, insertionClass, tr) {
337
+ /* This marks all the changes in the diff editor */
338
+ // Mark the insertions in insertion View & deletions in deletionView
339
+ const insertionMarksTr = view.state.tr
340
+ let stepsTrackedByChangeset = []
341
+ // Use the changeset to create the marks
342
+ changeset.changes.forEach(change => {
343
+ if (change.inserted.length > 0) {
344
+ let stepsInvolved = []
345
+ change.inserted.forEach(insertion =>
346
+ stepsInvolved.push(Number.parseInt(insertion.data.step))
347
+ )
348
+ const stepsSet = new Set(stepsInvolved)
349
+ stepsInvolved = Array.from(stepsSet)
350
+
351
+ // Add the footnote related steps because the changeset tracks change but misses some steps related to insertion of footnote node!
352
+ tr.steps.forEach((step, index) => {
353
+ if (
354
+ step.from >= change.fromB &&
355
+ step.to <= change.toB &&
356
+ step instanceof ReplaceStep &&
357
+ !stepsInvolved.includes(index)
358
+ ) {
359
+ const stepOne = step.toJSON()
360
+ if (
361
+ stepOne.slice &&
362
+ stepOne.from !== stepOne.to &&
363
+ stepOne.slice.content.length == 1 &&
364
+ (stepOne.slice.content[0].type === "footnote" ||
365
+ stepOne.slice.content[0].type === "citation")
366
+ ) {
367
+ stepsInvolved.push(index)
368
+ }
369
+ } else if (
370
+ step.from >= change.fromB &&
371
+ step.to <= change.toB &&
372
+ step instanceof AddMarkStep &&
373
+ !stepsInvolved.includes(index)
374
+ ) {
375
+ const stepOne = step.toJSON()
376
+ if (
377
+ stepOne.mark &&
378
+ [
379
+ "strong",
380
+ "em",
381
+ "underline",
382
+ "link",
383
+ "deletion",
384
+ "insertion",
385
+ "comment"
386
+ ].includes(stepOne.mark.type)
387
+ ) {
388
+ stepsInvolved.push(index)
389
+ }
390
+ }
391
+ })
392
+
393
+ stepsInvolved.sort((a, b) => a - b)
394
+ const insertionMark = this.schema.marks.diffdata.create({
395
+ diff: insertionClass,
396
+ steps: JSON.stringify(stepsInvolved),
397
+ from: change.fromB,
398
+ to: change.toB,
399
+ markOnly: false
400
+ })
401
+ insertionMarksTr.addMark(
402
+ change.fromB,
403
+ change.toB,
404
+ insertionMark
405
+ )
406
+ this.markBlockDiffs(
407
+ insertionMarksTr,
408
+ change.fromB,
409
+ change.toB,
410
+ insertionClass,
411
+ stepsInvolved
412
+ )
413
+ if (
414
+ checkPresenceOfdiffdata(
415
+ insertionMarksTr.doc,
416
+ change.fromB,
417
+ change.toB
418
+ )
419
+ ) {
420
+ stepsTrackedByChangeset =
421
+ stepsTrackedByChangeset.concat(stepsInvolved)
422
+ }
423
+ }
424
+ })
425
+
426
+ // Add all the footnote/mark/citation related steps that are not tracked by changeset.
427
+ tr.steps.forEach((step, index) => {
428
+ const from = tr.mapping.slice(index).map(step.from)
429
+ const to = tr.mapping.slice(index).map(step.to, -1)
430
+ if (
431
+ step instanceof ReplaceStep &&
432
+ !stepsTrackedByChangeset.includes(index)
433
+ ) {
434
+ const stepOne = step.toJSON()
435
+ if (
436
+ stepOne.slice &&
437
+ stepOne.slice.content.length == 1 &&
438
+ stepOne.slice.content[0].type === "footnote"
439
+ ) {
440
+ const insertionMark = this.schema.marks.diffdata.create({
441
+ diff: insertionClass,
442
+ steps: JSON.stringify([index]),
443
+ from: from,
444
+ to: to,
445
+ markOnly: false
446
+ })
447
+ insertionMarksTr.addMark(from, to, insertionMark)
448
+ stepsTrackedByChangeset.push(index)
449
+ } else if (
450
+ stepOne.slice &&
451
+ stepOne.slice.content.length == 1 &&
452
+ stepOne.slice.content[0].type === "citation"
453
+ ) {
454
+ const insertionMark = this.schema.marks.diffdata.create({
455
+ diff: insertionClass,
456
+ steps: JSON.stringify([index]),
457
+ from: from,
458
+ to: to,
459
+ markOnly: false
460
+ })
461
+ insertionMarksTr.addMark(from, to, insertionMark)
462
+ stepsTrackedByChangeset.push(index)
463
+ } else if (
464
+ stepOne.slice &&
465
+ stepOne.slice.content[0].type === "figure"
466
+ ) {
467
+ if (stepOne.from == stepOne.to) {
468
+ this.markBlockDiffs(
469
+ insertionMarksTr,
470
+ stepOne.from,
471
+ stepOne.to + 1,
472
+ insertionClass,
473
+ [index]
474
+ )
475
+ } else {
476
+ this.markBlockDiffs(
477
+ insertionMarksTr,
478
+ stepOne.from,
479
+ stepOne.to,
480
+ insertionClass,
481
+ [index]
482
+ )
483
+ }
484
+ stepsTrackedByChangeset.push(index)
485
+ }
486
+ } else if (
487
+ (step instanceof AddMarkStep ||
488
+ step instanceof RemoveMarkStep) &&
489
+ !stepsTrackedByChangeset.includes(index)
490
+ ) {
491
+ const stepOne = step.toJSON(),
492
+ stepsInvolved = []
493
+ stepsInvolved.push(index)
494
+ if (
495
+ stepOne.mark &&
496
+ ["strong", "em", "underline", "link", "deletion"].includes(
497
+ stepOne.mark.type
498
+ )
499
+ ) {
500
+ tr.steps.forEach((trStep, trIndex) => {
501
+ // Check for other format changes within this range.
502
+ if (
503
+ (trStep instanceof AddMarkStep ||
504
+ trStep instanceof RemoveMarkStep) &&
505
+ !stepsTrackedByChangeset.includes(trIndex)
506
+ ) {
507
+ const mapFrom = tr.mapping
508
+ .slice(trIndex)
509
+ .map(trStep.from)
510
+ const mapTo = tr.mapping
511
+ .slice(trIndex)
512
+ .map(trStep.to)
513
+ if (
514
+ mapFrom >= from &&
515
+ mapTo <= to &&
516
+ !stepsInvolved.includes(trIndex)
517
+ ) {
518
+ const stepTwo = trStep.toJSON()
519
+ if (
520
+ stepTwo.mark &&
521
+ [
522
+ "strong",
523
+ "em",
524
+ "underline",
525
+ "link",
526
+ "deletion"
527
+ ].includes(stepTwo.mark.type)
528
+ ) {
529
+ stepsInvolved.push(trIndex)
530
+ }
531
+ }
532
+ }
533
+ })
534
+ const insertionMark = this.schema.marks.diffdata.create({
535
+ diff: insertionClass,
536
+ steps: JSON.stringify(stepsInvolved),
537
+ from: from,
538
+ to: to,
539
+ markOnly: true
540
+ })
541
+ stepsTrackedByChangeset =
542
+ stepsTrackedByChangeset.concat(stepsInvolved)
543
+ insertionMarksTr.addMark(from, to, insertionMark)
544
+ }
545
+ } else if (
546
+ step instanceof ReplaceAroundStep &&
547
+ !stepsTrackedByChangeset.includes(index)
548
+ ) {
549
+ const stepOne = step.toJSON()
550
+ if (
551
+ stepOne.slice &&
552
+ stepOne.slice.content[0].type === "figure"
553
+ ) {
554
+ this.markBlockDiffs(
555
+ insertionMarksTr,
556
+ stepOne.from,
557
+ stepOne.to,
558
+ insertionClass,
559
+ [index]
560
+ )
561
+ stepsTrackedByChangeset.push(index)
562
+ }
563
+ }
564
+ })
565
+
566
+ // Dispatch the transactions
567
+ insertionMarksTr
568
+ .setMeta("initialDiffMap", true)
569
+ .setMeta("mapAppended", true)
570
+ .setMeta("notrack", true)
571
+ view.dispatch(insertionMarksTr)
572
+
573
+ //Return steps that are tracked in the diff editor
574
+ return stepsTrackedByChangeset
575
+ }
576
+
577
+ bindEditorView(elementId, doc) {
578
+ /* Binds the editor view */
579
+ const plugins = this.diffEditorPlugins.map(plugin => {
580
+ if (plugin[1]) {
581
+ return plugin[0](plugin[1](doc))
582
+ } else {
583
+ return plugin[0]()
584
+ }
585
+ })
586
+ let editorView
587
+ const mainEditor = this.editor
588
+ if (elementId == "editor-diff-online") {
589
+ editorView = new EditorView(document.getElementById(elementId), {
590
+ state: EditorState.create({
591
+ schema: this.schema,
592
+ doc: doc,
593
+ plugins: plugins
594
+ }),
595
+ dispatchTransaction: tr => {
596
+ let mapTr = tr
597
+ if (tr.docChanged) {
598
+ const mapAppended = tr.getMeta("mapAppended")
599
+ const noTrack = tr.getMeta("notrack")
600
+ if (!mapAppended) {
601
+ this.mergedDocMap.appendMapping(tr.mapping)
602
+ }
603
+ if (!noTrack) {
604
+ // Track only manual insertions
605
+ mapTr = trackedTransaction(
606
+ mapTr,
607
+ this.mergeView2.state,
608
+ this.editor.user,
609
+ !this.mergeView2.state.doc.attrs.tracked &&
610
+ ![
611
+ "write-tracked",
612
+ "review-tracked"
613
+ ].includes(
614
+ this.editor.docInfo.access_rights
615
+ ),
616
+ Date.now() - this.editor.clientTimeAdjustment
617
+ )
618
+ }
619
+ }
620
+ const newState = editorView.state.apply(mapTr)
621
+ editorView.updateState(newState)
622
+ this.renderCitation(editorView, elementId)
623
+ },
624
+ nodeViews: {
625
+ footnote(node, view, getPos) {
626
+ return new FootnoteView(node, view, getPos, mainEditor)
627
+ }
628
+ }
629
+ })
630
+ } else {
631
+ editorView = new EditorView(document.getElementById(elementId), {
632
+ state: EditorState.create({
633
+ schema: this.schema,
634
+ doc: doc,
635
+ plugins: plugins
636
+ }),
637
+ dispatchTransaction: tr => {
638
+ const newState = editorView.state.apply(tr)
639
+ editorView.updateState(newState)
640
+ this.renderCitation(editorView, elementId)
641
+ },
642
+ editable: () => false,
643
+ nodeViews: {
644
+ footnote(node, view, getPos) {
645
+ return new FootnoteView(node, view, getPos, mainEditor)
646
+ }
647
+ }
648
+ })
649
+ }
650
+ return editorView
651
+ }
652
+
653
+ renderCitation(view, elementId) {
654
+ const settings = view.state.doc.attrs,
655
+ bibliographyHeader =
656
+ settings.bibliography_header[settings.language] ||
657
+ BIBLIOGRAPHY_HEADERS[settings.language]
658
+ const citRenderer = new RenderCitations(
659
+ document.getElementById(elementId),
660
+ settings.citationstyle,
661
+ bibliographyHeader,
662
+ this.editor.mod.db.bibDB,
663
+ this.editor.app.csl
664
+ )
665
+ citRenderer.init()
666
+ }
667
+
668
+ startMerge(offlineTr, onlineDoc) {
669
+ try {
670
+ /* start the merge process of moving changes to the editor */
671
+ // Remove all diff related marks
672
+ dispatchRemoveDiffdata(
673
+ this.mergeView2,
674
+ 0,
675
+ this.mergeView2.state.doc.content.size
676
+ )
677
+
678
+ // Apply all the marks that are not handled by recreate steps!
679
+ const markTr = this.mergeView2.state.tr
680
+ const offlineRebaseMapping = new Mapping()
681
+ offlineRebaseMapping.appendMappingInverted(offlineTr.mapping)
682
+ offlineRebaseMapping.appendMapping(this.mergedDocMap)
683
+ this.offStepsNotTracked.forEach(markstep => {
684
+ const stepIndex = offlineTr.steps.indexOf(markstep)
685
+ const offlineRebaseMap = offlineRebaseMapping.slice(
686
+ offlineTr.steps.length - stepIndex
687
+ )
688
+ const mappedMarkStep = markstep.map(offlineRebaseMap)
689
+ if (
690
+ mappedMarkStep &&
691
+ !markTr.maybeStep(mappedMarkStep).failed
692
+ ) {
693
+ this.mergedDocMap.appendMap(mappedMarkStep.getMap())
694
+ offlineRebaseMapping.appendMap(mappedMarkStep.getMap())
695
+ offlineRebaseMapping.setMirror(
696
+ offlineTr.steps.length - stepIndex - 1,
697
+ offlineTr.steps.length +
698
+ this.mergedDocMap.maps.length -
699
+ 1
700
+ )
701
+ }
702
+ })
703
+ this.mergeView2.dispatch(markTr)
704
+ this.mergeDialog.close()
705
+
706
+ const mergedDoc = this.mergeView2.state.doc
707
+ //CleanUp
708
+ this.mergeView1.destroy()
709
+ this.mergeView2.destroy()
710
+ this.mergeView3.destroy()
711
+
712
+ this.applyChangesToMainEditor(onlineDoc, mergedDoc)
713
+ } catch (error) {
714
+ // Convert the doc to main editor schema
715
+ const onlineDoc = this.editor.schema.nodeFromJSON(
716
+ removeDiffFromJson(this.onlineDoc.toJSON())
717
+ )
718
+ const offlineDoc = this.editor.schema.nodeFromJSON(
719
+ removeDiffFromJson(this.offlineDoc.toJSON())
720
+ )
721
+
722
+ // Handle merge failure
723
+ this.editor.mod.collab.doc.merge.handleMergeFailure(
724
+ error,
725
+ offlineDoc,
726
+ onlineDoc,
727
+ this
728
+ )
729
+ }
730
+ }
731
+
732
+ unHideSections(view) {
733
+ const unHideSectionTr = view.state.tr
734
+ view.state.doc.forEach((child, offset, _index) => {
735
+ if (child.attrs.optional) {
736
+ const attrs = Object.assign({}, child.attrs, {hidden: false})
737
+ unHideSectionTr.setNodeMarkup(offset, false, attrs)
738
+ }
739
+ })
740
+ unHideSectionTr.setMeta("notrack", true).setMeta("mapAppended", true)
741
+ view.dispatch(unHideSectionTr)
742
+ }
743
+
744
+ unHideSectionsinAllDoc() {
745
+ /* Unhide all the optional sections */
746
+ this.unHideSections(this.mergeView1)
747
+ this.unHideSections(this.mergeView2)
748
+ this.unHideSections(this.mergeView3)
749
+ }
750
+
751
+ applyChangesToMainEditor(onlineDoc, mergedDoc) {
752
+ /* Applies the change from diff editor to main editor */
753
+ onlineDoc = this.editor.schema.nodeFromJSON(
754
+ removeDiffFromJson(onlineDoc.toJSON())
755
+ )
756
+ mergedDoc = this.editor.schema.nodeFromJSON(
757
+ removeDiffFromJson(mergedDoc.toJSON())
758
+ )
759
+ const tr = simplifyTransform(recreateTransform(onlineDoc, mergedDoc))
760
+ const OnlineStepsLost = recreateTransform(
761
+ onlineDoc,
762
+ this.editor.view.state.doc
763
+ )
764
+ const onlineStepsLostChangeset = new changeSet(OnlineStepsLost)
765
+ const conflicts = onlineStepsLostChangeset.findConflicts(
766
+ tr,
767
+ OnlineStepsLost
768
+ )
769
+ if (conflicts.length > 0) {
770
+ const editor = new MergeEditor(
771
+ this.editor,
772
+ onlineDoc,
773
+ tr.doc,
774
+ OnlineStepsLost.doc,
775
+ tr,
776
+ OnlineStepsLost,
777
+ this.db
778
+ )
779
+ editor.init()
780
+ } else {
781
+ const newTr = this.editor.view.state.tr
782
+ const maps = new Mapping(
783
+ []
784
+ .concat(
785
+ tr.mapping.maps
786
+ .slice()
787
+ .reverse()
788
+ .map(map => map.invert())
789
+ )
790
+ .concat(OnlineStepsLost.mapping.maps)
791
+ )
792
+ tr.steps.forEach((step, index) => {
793
+ const mapped = step.map(maps.slice(tr.steps.length - index))
794
+ if (mapped && !newTr.maybeStep(mapped).failed) {
795
+ maps.appendMap(mapped.getMap())
796
+ maps.setMirror(
797
+ tr.steps.length - index - 1,
798
+ tr.steps.length +
799
+ OnlineStepsLost.steps.length +
800
+ newTr.steps.length -
801
+ 1
802
+ )
803
+ }
804
+ })
805
+ newTr.setMeta("remote", true)
806
+
807
+ // Re-render the fn editor for all the users.
808
+ this.editor.mod.collab.doc.footnoteRender = true
809
+
810
+ this.editor.view.dispatch(newTr)
811
+ this.editor.mod.footnotes.fnEditor.renderAllFootnotes()
812
+ }
813
+ }
814
+
815
+ findNotTrackedSteps(tr, trackedSteps) {
816
+ /* Find steps not tracked by PM, usually steps that cause change of attrs */
817
+ const nonTrackedSteps = []
818
+ tr.steps.forEach((step, index) => {
819
+ // mark steps other than replace steps as not tracked if not tracked by changeset
820
+ // these steps should effectively only be the node attrs change steps.
821
+ if (
822
+ !trackedSteps.includes(index) &&
823
+ (step instanceof ReplaceAroundStep ||
824
+ step instanceof AddMarkStep ||
825
+ step instanceof RemoveMarkStep)
826
+ ) {
827
+ nonTrackedSteps.push(step)
828
+ }
829
+ })
830
+ return nonTrackedSteps
831
+ }
832
+
833
+ markBlockDiffs(tr, from, to, difftype, stepsInvolved) {
834
+ /* This Function is used to add diff data to Block Elements. */
835
+ tr.doc.nodesBetween(from, to, (node, pos) => {
836
+ if (
837
+ pos < from ||
838
+ ["bullet_list", "ordered_list"].includes(node.type.name)
839
+ ) {
840
+ return true
841
+ } else if (node.isInline) {
842
+ return false
843
+ }
844
+ if (node.attrs.diffdata) {
845
+ const diffdata = []
846
+ diffdata.push({
847
+ type: difftype,
848
+ from: from,
849
+ to: to,
850
+ steps: stepsInvolved
851
+ })
852
+ tr.setNodeMarkup(
853
+ pos,
854
+ null,
855
+ Object.assign({}, node.attrs, {diffdata}),
856
+ node.marks
857
+ )
858
+ }
859
+ })
860
+ }
861
+
862
+ updateDB(offlineDoc, db) {
863
+ /* Used to update the image,bib DB and update the doc in case if missing/lost images
864
+ (update the image data with re-uploaded images) */
865
+ let usedImages = []
866
+ const usedBibs = []
867
+ const footnoteFind = (node, usedImages, usedBibs) => {
868
+ if (node.name === "citation") {
869
+ node.attrs.references.forEach(ref =>
870
+ usedBibs.push(Number.parseInt(ref.id))
871
+ )
872
+ } else if (node.name === "image" && node.attrs.image) {
873
+ usedImages.push(node.attrs.image)
874
+ } else if (node.content) {
875
+ node.content.forEach(subNode =>
876
+ footnoteFind(subNode, usedImages, usedBibs)
877
+ )
878
+ }
879
+ }
880
+
881
+ // Looking at rebased doc so that it contains the merged document !!!
882
+ offlineDoc.descendants(node => {
883
+ if (node.type.name === "citation") {
884
+ node.attrs.references.forEach(ref =>
885
+ usedBibs.push(Number.parseInt(ref.id))
886
+ )
887
+ } else if (node.type.name === "image" && node.attrs.image) {
888
+ usedImages.push(node.attrs.image)
889
+ } else if (node.type.name === "footnote" && node.attrs.footnote) {
890
+ node.attrs.footnote.forEach(subNode =>
891
+ footnoteFind(subNode, usedImages, usedBibs)
892
+ )
893
+ }
894
+ })
895
+
896
+ const oldBibDB = this.editor.mod.db.bibDB.db
897
+ this.editor.mod.db.bibDB.setDB(db.bibliography)
898
+ usedBibs.forEach(id => {
899
+ if (!this.editor.mod.db.bibDB.db[id] && oldBibDB[id]) {
900
+ this.editor.mod.db.bibDB.updateReference(id, oldBibDB[id])
901
+ }
902
+ })
903
+ const oldImageDB = this.editor.mod.db.imageDB.db
904
+ let imageUploadFailDialogShown = false
905
+ this.editor.mod.db.imageDB.setDB(db.images)
906
+ usedImages = new Set(usedImages)
907
+ usedImages = Array.from(usedImages)
908
+ usedImages.forEach(id => {
909
+ if (!this.editor.mod.db.imageDB.db[id] && oldImageDB[id]) {
910
+ // If the image was uploaded by the offline user we know that he may not have deleted it so we can resend it normally
911
+ if (
912
+ Object.keys(this.editor.app.imageDB.db).includes(String(id))
913
+ ) {
914
+ this.editor.mod.db.imageDB.setImage(id, oldImageDB[id])
915
+ } else {
916
+ // If the image was uploaded by someone else, to set the image we have to reupload it again as there is backend check to associate who can add an image with the image owner.
917
+ this.editor.mod.db.imageDB
918
+ .reUploadImage(
919
+ id,
920
+ oldImageDB[id].image,
921
+ oldImageDB[id].title,
922
+ oldImageDB[id].copyright
923
+ )
924
+ .then(
925
+ ({id, newId}) => {
926
+ this.imageDataModified[id] = newId
927
+ // Update the image node if there are any re uploaded images.
928
+ this.mergeView1.state.doc.descendants(
929
+ (node, pos) => {
930
+ if (
931
+ node.type.name === "image" &&
932
+ node.attrs.image == id
933
+ ) {
934
+ const attrs = Object.assign(
935
+ {},
936
+ node.attrs
937
+ )
938
+ attrs["image"] = newId
939
+ const nodeType =
940
+ this.mergeView1.state.schema
941
+ .nodes["image"]
942
+ const transaction =
943
+ this.mergeView1.state.tr.setNodeMarkup(
944
+ pos,
945
+ nodeType,
946
+ attrs
947
+ )
948
+ transaction.setMeta(
949
+ "mapAppended",
950
+ true
951
+ )
952
+ this.mergeView1.dispatch(
953
+ transaction
954
+ )
955
+ }
956
+ }
957
+ )
958
+ this.mergeView3.state.doc.descendants(
959
+ (node, pos) => {
960
+ if (
961
+ node.type.name === "image" &&
962
+ node.attrs.image == id
963
+ ) {
964
+ const attrs = Object.assign(
965
+ {},
966
+ node.attrs
967
+ )
968
+ attrs["image"] = newId
969
+ const nodeType =
970
+ this.mergeView3.state.schema
971
+ .nodes["image"]
972
+ const transaction =
973
+ this.mergeView3.state.tr.setNodeMarkup(
974
+ pos,
975
+ nodeType,
976
+ attrs
977
+ )
978
+ transaction.setMeta(
979
+ "mapAppended",
980
+ true
981
+ )
982
+ this.mergeView3.dispatch(
983
+ transaction
984
+ )
985
+ }
986
+ }
987
+ )
988
+ },
989
+ id => {
990
+ // In case of failure make the id as false so the failed upload image is empty for the offline user too!
991
+ this.mergeView1.state.doc.descendants(
992
+ (node, pos) => {
993
+ if (
994
+ node.type.name === "image" &&
995
+ node.attrs.image == id
996
+ ) {
997
+ const attrs = Object.assign(
998
+ {},
999
+ node.attrs
1000
+ )
1001
+ attrs["image"] = false
1002
+ const nodeType =
1003
+ this.mergeView1.state.schema
1004
+ .nodes["image"]
1005
+ const transaction =
1006
+ this.mergeView1.state.tr.setNodeMarkup(
1007
+ pos,
1008
+ nodeType,
1009
+ attrs
1010
+ )
1011
+ transaction.setMeta(
1012
+ "mapAppended",
1013
+ true
1014
+ )
1015
+ this.mergeView1.dispatch(
1016
+ transaction
1017
+ )
1018
+ }
1019
+ }
1020
+ )
1021
+ this.mergeView3.state.doc.descendants(
1022
+ (node, pos) => {
1023
+ if (
1024
+ node.type.name === "image" &&
1025
+ node.attrs.image == id
1026
+ ) {
1027
+ const attrs = Object.assign(
1028
+ {},
1029
+ node.attrs
1030
+ )
1031
+ attrs["image"] = false
1032
+ const nodeType =
1033
+ this.mergeView3.state.schema
1034
+ .nodes["image"]
1035
+ const transaction =
1036
+ this.mergeView3.state.tr.setNodeMarkup(
1037
+ pos,
1038
+ nodeType,
1039
+ attrs
1040
+ )
1041
+ transaction.setMeta(
1042
+ "mapAppended",
1043
+ true
1044
+ )
1045
+ this.mergeView3.dispatch(
1046
+ transaction
1047
+ )
1048
+ }
1049
+ }
1050
+ )
1051
+ if (!imageUploadFailDialogShown) {
1052
+ imageUploadFailDialogShown = true
1053
+ showSystemMessage(
1054
+ gettext(
1055
+ "One or more of the image(s) you copied could not be found on the server. Consider re-uploading them once the document is merged."
1056
+ )
1057
+ )
1058
+ }
1059
+ }
1060
+ )
1061
+ }
1062
+ }
1063
+ })
1064
+ }
1065
+ }