@fiduswriter/frontend 0.1.9

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 (359) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +66 -0
  3. package/dist/admin_console/index.d.ts +8 -0
  4. package/dist/admin_console/index.d.ts.map +1 -0
  5. package/dist/admin_console/index.js +54 -0
  6. package/dist/admin_console/index.js.map +1 -0
  7. package/dist/api/index.d.ts +193 -0
  8. package/dist/api/index.d.ts.map +1 -0
  9. package/dist/api/index.js +6 -0
  10. package/dist/api/index.js.map +1 -0
  11. package/dist/app/index.d.ts +74 -0
  12. package/dist/app/index.d.ts.map +1 -0
  13. package/dist/app/index.js +471 -0
  14. package/dist/app/index.js.map +1 -0
  15. package/dist/common/index.d.ts +3 -0
  16. package/dist/common/index.d.ts.map +1 -0
  17. package/dist/common/index.js +3 -0
  18. package/dist/common/index.js.map +1 -0
  19. package/dist/common/templates.d.ts +3 -0
  20. package/dist/common/templates.d.ts.map +1 -0
  21. package/dist/common/templates.js +42 -0
  22. package/dist/common/templates.js.map +1 -0
  23. package/dist/common/user_util.d.ts +6 -0
  24. package/dist/common/user_util.d.ts.map +1 -0
  25. package/dist/common/user_util.js +16 -0
  26. package/dist/common/user_util.js.map +1 -0
  27. package/dist/document_templates/actions.d.ts +11 -0
  28. package/dist/document_templates/actions.d.ts.map +1 -0
  29. package/dist/document_templates/actions.js +141 -0
  30. package/dist/document_templates/actions.js.map +1 -0
  31. package/dist/document_templates/editor.d.ts +28 -0
  32. package/dist/document_templates/editor.d.ts.map +1 -0
  33. package/dist/document_templates/editor.js +139 -0
  34. package/dist/document_templates/editor.js.map +1 -0
  35. package/dist/document_templates/index.d.ts +3 -0
  36. package/dist/document_templates/index.d.ts.map +1 -0
  37. package/dist/document_templates/index.js +3 -0
  38. package/dist/document_templates/index.js.map +1 -0
  39. package/dist/document_templates/menu.d.ts +7 -0
  40. package/dist/document_templates/menu.d.ts.map +1 -0
  41. package/dist/document_templates/menu.js +62 -0
  42. package/dist/document_templates/menu.js.map +1 -0
  43. package/dist/document_templates/overview.d.ts +52 -0
  44. package/dist/document_templates/overview.d.ts.map +1 -0
  45. package/dist/document_templates/overview.js +274 -0
  46. package/dist/document_templates/overview.js.map +1 -0
  47. package/dist/document_templates/templates.d.ts +3 -0
  48. package/dist/document_templates/templates.d.ts.map +1 -0
  49. package/dist/document_templates/templates.js +9 -0
  50. package/dist/document_templates/templates.js.map +1 -0
  51. package/dist/documents/importer/docx/import.d.ts +5 -0
  52. package/dist/documents/importer/docx/import.d.ts.map +1 -0
  53. package/dist/documents/importer/docx/import.js +15 -0
  54. package/dist/documents/importer/docx/import.js.map +1 -0
  55. package/dist/documents/importer/docx/index.d.ts +2 -0
  56. package/dist/documents/importer/docx/index.d.ts.map +1 -0
  57. package/dist/documents/importer/docx/index.js +2 -0
  58. package/dist/documents/importer/docx/index.js.map +1 -0
  59. package/dist/documents/importer/native/file.d.ts +7 -0
  60. package/dist/documents/importer/native/file.d.ts.map +1 -0
  61. package/dist/documents/importer/native/file.js +60 -0
  62. package/dist/documents/importer/native/file.js.map +1 -0
  63. package/dist/documents/importer/native/import.d.ts +41 -0
  64. package/dist/documents/importer/native/import.d.ts.map +1 -0
  65. package/dist/documents/importer/native/import.js +126 -0
  66. package/dist/documents/importer/native/import.js.map +1 -0
  67. package/dist/documents/importer/native/index.d.ts +3 -0
  68. package/dist/documents/importer/native/index.d.ts.map +1 -0
  69. package/dist/documents/importer/native/index.js +3 -0
  70. package/dist/documents/importer/native/index.js.map +1 -0
  71. package/dist/documents/importer/odt/import.d.ts +5 -0
  72. package/dist/documents/importer/odt/import.d.ts.map +1 -0
  73. package/dist/documents/importer/odt/import.js +16 -0
  74. package/dist/documents/importer/odt/import.js.map +1 -0
  75. package/dist/documents/importer/odt/index.d.ts +2 -0
  76. package/dist/documents/importer/odt/index.d.ts.map +1 -0
  77. package/dist/documents/importer/odt/index.js +2 -0
  78. package/dist/documents/importer/odt/index.js.map +1 -0
  79. package/dist/documents/importer/pandoc/import.d.ts +5 -0
  80. package/dist/documents/importer/pandoc/import.d.ts.map +1 -0
  81. package/dist/documents/importer/pandoc/import.js +37 -0
  82. package/dist/documents/importer/pandoc/import.js.map +1 -0
  83. package/dist/documents/importer/pandoc/index.d.ts +2 -0
  84. package/dist/documents/importer/pandoc/index.d.ts.map +1 -0
  85. package/dist/documents/importer/pandoc/index.js +2 -0
  86. package/dist/documents/importer/pandoc/index.js.map +1 -0
  87. package/dist/documents/importer/register.d.ts +4 -0
  88. package/dist/documents/importer/register.d.ts.map +1 -0
  89. package/dist/documents/importer/register.js +4 -0
  90. package/dist/documents/importer/register.js.map +1 -0
  91. package/dist/documents/overview/actions.d.ts +32 -0
  92. package/dist/documents/overview/actions.d.ts.map +1 -0
  93. package/dist/documents/overview/actions.js +725 -0
  94. package/dist/documents/overview/actions.js.map +1 -0
  95. package/dist/documents/overview/index.d.ts +98 -0
  96. package/dist/documents/overview/index.d.ts.map +1 -0
  97. package/dist/documents/overview/index.js +814 -0
  98. package/dist/documents/overview/index.js.map +1 -0
  99. package/dist/documents/overview/menu.d.ts +28 -0
  100. package/dist/documents/overview/menu.d.ts.map +1 -0
  101. package/dist/documents/overview/menu.js +222 -0
  102. package/dist/documents/overview/menu.js.map +1 -0
  103. package/dist/documents/overview/templates.d.ts +31 -0
  104. package/dist/documents/overview/templates.d.ts.map +1 -0
  105. package/dist/documents/overview/templates.js +39 -0
  106. package/dist/documents/overview/templates.js.map +1 -0
  107. package/dist/documents/revisions/index.d.ts +14 -0
  108. package/dist/documents/revisions/index.d.ts.map +1 -0
  109. package/dist/documents/revisions/index.js +143 -0
  110. package/dist/documents/revisions/index.js.map +1 -0
  111. package/dist/documents/revisions/templates.d.ts +4 -0
  112. package/dist/documents/revisions/templates.d.ts.map +1 -0
  113. package/dist/documents/revisions/templates.js +36 -0
  114. package/dist/documents/revisions/templates.js.map +1 -0
  115. package/dist/documents/tools.d.ts +16 -0
  116. package/dist/documents/tools.d.ts.map +1 -0
  117. package/dist/documents/tools.js +69 -0
  118. package/dist/documents/tools.js.map +1 -0
  119. package/dist/error_hook/index.d.ts +19 -0
  120. package/dist/error_hook/index.d.ts.map +1 -0
  121. package/dist/error_hook/index.js +75 -0
  122. package/dist/error_hook/index.js.map +1 -0
  123. package/dist/feedback/index.d.ts +12 -0
  124. package/dist/feedback/index.d.ts.map +1 -0
  125. package/dist/feedback/index.js +125 -0
  126. package/dist/feedback/index.js.map +1 -0
  127. package/dist/index.d.ts +42 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +48 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/indexed_db/index.d.ts +24 -0
  132. package/dist/indexed_db/index.d.ts.map +1 -0
  133. package/dist/indexed_db/index.js +175 -0
  134. package/dist/indexed_db/index.js.map +1 -0
  135. package/dist/maintenance/index.d.ts +19 -0
  136. package/dist/maintenance/index.d.ts.map +1 -0
  137. package/dist/maintenance/index.js +223 -0
  138. package/dist/maintenance/index.js.map +1 -0
  139. package/dist/menu/index.d.ts +25 -0
  140. package/dist/menu/index.d.ts.map +1 -0
  141. package/dist/menu/index.js +229 -0
  142. package/dist/menu/index.js.map +1 -0
  143. package/dist/menu/templates.d.ts +6 -0
  144. package/dist/menu/templates.d.ts.map +1 -0
  145. package/dist/menu/templates.js +10 -0
  146. package/dist/menu/templates.js.map +1 -0
  147. package/dist/pages/404.d.ts +9 -0
  148. package/dist/pages/404.d.ts.map +1 -0
  149. package/dist/pages/404.js +12 -0
  150. package/dist/pages/404.js.map +1 -0
  151. package/dist/pages/flatpage.d.ts +12 -0
  152. package/dist/pages/flatpage.d.ts.map +1 -0
  153. package/dist/pages/flatpage.js +39 -0
  154. package/dist/pages/flatpage.js.map +1 -0
  155. package/dist/pages/offline.d.ts +10 -0
  156. package/dist/pages/offline.d.ts.map +1 -0
  157. package/dist/pages/offline.js +27 -0
  158. package/dist/pages/offline.js.map +1 -0
  159. package/dist/pages/setup.d.ts +10 -0
  160. package/dist/pages/setup.d.ts.map +1 -0
  161. package/dist/pages/setup.js +22 -0
  162. package/dist/pages/setup.js.map +1 -0
  163. package/dist/plugins/menu/index.d.ts +3 -0
  164. package/dist/plugins/menu/index.d.ts.map +1 -0
  165. package/dist/plugins/menu/index.js +2 -0
  166. package/dist/plugins/menu/index.js.map +1 -0
  167. package/dist/prelogin/index.d.ts +51 -0
  168. package/dist/prelogin/index.d.ts.map +1 -0
  169. package/dist/prelogin/index.js +131 -0
  170. package/dist/prelogin/index.js.map +1 -0
  171. package/dist/prelogin/templates.d.ts +20 -0
  172. package/dist/prelogin/templates.d.ts.map +1 -0
  173. package/dist/prelogin/templates.js +50 -0
  174. package/dist/prelogin/templates.js.map +1 -0
  175. package/dist/state_plugins/contributor_input/add_button.d.ts +22 -0
  176. package/dist/state_plugins/contributor_input/add_button.d.ts.map +1 -0
  177. package/dist/state_plugins/contributor_input/add_button.js +106 -0
  178. package/dist/state_plugins/contributor_input/add_button.js.map +1 -0
  179. package/dist/state_plugins/contributor_input/helpers.d.ts +3 -0
  180. package/dist/state_plugins/contributor_input/helpers.d.ts.map +1 -0
  181. package/dist/state_plugins/contributor_input/helpers.js +23 -0
  182. package/dist/state_plugins/contributor_input/helpers.js.map +1 -0
  183. package/dist/state_plugins/contributor_input/index.d.ts +4 -0
  184. package/dist/state_plugins/contributor_input/index.d.ts.map +1 -0
  185. package/dist/state_plugins/contributor_input/index.js +4 -0
  186. package/dist/state_plugins/contributor_input/index.js.map +1 -0
  187. package/dist/state_plugins/contributor_input/node_view.d.ts +20 -0
  188. package/dist/state_plugins/contributor_input/node_view.d.ts.map +1 -0
  189. package/dist/state_plugins/contributor_input/node_view.js +85 -0
  190. package/dist/state_plugins/contributor_input/node_view.js.map +1 -0
  191. package/dist/state_plugins/index.d.ts +3 -0
  192. package/dist/state_plugins/index.d.ts.map +1 -0
  193. package/dist/state_plugins/index.js +3 -0
  194. package/dist/state_plugins/index.js.map +1 -0
  195. package/dist/state_plugins/tag_input/helpers.d.ts +5 -0
  196. package/dist/state_plugins/tag_input/helpers.d.ts.map +1 -0
  197. package/dist/state_plugins/tag_input/helpers.js +55 -0
  198. package/dist/state_plugins/tag_input/helpers.js.map +1 -0
  199. package/dist/state_plugins/tag_input/index.d.ts +5 -0
  200. package/dist/state_plugins/tag_input/index.d.ts.map +1 -0
  201. package/dist/state_plugins/tag_input/index.js +5 -0
  202. package/dist/state_plugins/tag_input/index.js.map +1 -0
  203. package/dist/state_plugins/tag_input/node_view.d.ts +19 -0
  204. package/dist/state_plugins/tag_input/node_view.d.ts.map +1 -0
  205. package/dist/state_plugins/tag_input/node_view.js +85 -0
  206. package/dist/state_plugins/tag_input/node_view.js.map +1 -0
  207. package/dist/state_plugins/tag_input/tag_editor.d.ts +4 -0
  208. package/dist/state_plugins/tag_input/tag_editor.d.ts.map +1 -0
  209. package/dist/state_plugins/tag_input/tag_editor.js +160 -0
  210. package/dist/state_plugins/tag_input/tag_editor.js.map +1 -0
  211. package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts +5 -0
  212. package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts.map +1 -0
  213. package/dist/state_plugins/tag_input/tag_editor_plugins.js +64 -0
  214. package/dist/state_plugins/tag_input/tag_editor_plugins.js.map +1 -0
  215. package/dist/types.d.ts +53 -0
  216. package/dist/types.d.ts.map +1 -0
  217. package/dist/types.js +2 -0
  218. package/dist/types.js.map +1 -0
  219. package/dist/user/auth/email_confirm.d.ts +23 -0
  220. package/dist/user/auth/email_confirm.d.ts.map +1 -0
  221. package/dist/user/auth/email_confirm.js +123 -0
  222. package/dist/user/auth/email_confirm.js.map +1 -0
  223. package/dist/user/auth/email_confirm_templates.d.ts +12 -0
  224. package/dist/user/auth/email_confirm_templates.d.ts.map +1 -0
  225. package/dist/user/auth/email_confirm_templates.js +30 -0
  226. package/dist/user/auth/email_confirm_templates.js.map +1 -0
  227. package/dist/user/auth/login.d.ts +13 -0
  228. package/dist/user/auth/login.d.ts.map +1 -0
  229. package/dist/user/auth/login.js +186 -0
  230. package/dist/user/auth/login.js.map +1 -0
  231. package/dist/user/auth/password_reset_change.d.ts +11 -0
  232. package/dist/user/auth/password_reset_change.d.ts.map +1 -0
  233. package/dist/user/auth/password_reset_change.js +101 -0
  234. package/dist/user/auth/password_reset_change.js.map +1 -0
  235. package/dist/user/auth/password_reset_request.d.ts +10 -0
  236. package/dist/user/auth/password_reset_request.d.ts.map +1 -0
  237. package/dist/user/auth/password_reset_request.js +82 -0
  238. package/dist/user/auth/password_reset_request.js.map +1 -0
  239. package/dist/user/auth/signup.d.ts +9 -0
  240. package/dist/user/auth/signup.d.ts.map +1 -0
  241. package/dist/user/auth/signup.js +148 -0
  242. package/dist/user/auth/signup.js.map +1 -0
  243. package/dist/user/auth/two_factor.d.ts +10 -0
  244. package/dist/user/auth/two_factor.d.ts.map +1 -0
  245. package/dist/user/auth/two_factor.js +201 -0
  246. package/dist/user/auth/two_factor.js.map +1 -0
  247. package/dist/user/contacts/add_dialog.d.ts +7 -0
  248. package/dist/user/contacts/add_dialog.d.ts.map +1 -0
  249. package/dist/user/contacts/add_dialog.js +84 -0
  250. package/dist/user/contacts/add_dialog.js.map +1 -0
  251. package/dist/user/contacts/delete_dialog.d.ts +6 -0
  252. package/dist/user/contacts/delete_dialog.d.ts.map +1 -0
  253. package/dist/user/contacts/delete_dialog.js +38 -0
  254. package/dist/user/contacts/delete_dialog.js.map +1 -0
  255. package/dist/user/contacts/index.d.ts +35 -0
  256. package/dist/user/contacts/index.d.ts.map +1 -0
  257. package/dist/user/contacts/index.js +234 -0
  258. package/dist/user/contacts/index.js.map +1 -0
  259. package/dist/user/contacts/invite.d.ts +9 -0
  260. package/dist/user/contacts/invite.d.ts.map +1 -0
  261. package/dist/user/contacts/invite.js +21 -0
  262. package/dist/user/contacts/invite.js.map +1 -0
  263. package/dist/user/contacts/menu.d.ts +7 -0
  264. package/dist/user/contacts/menu.d.ts.map +1 -0
  265. package/dist/user/contacts/menu.js +62 -0
  266. package/dist/user/contacts/menu.js.map +1 -0
  267. package/dist/user/contacts/respond_invite.d.ts +9 -0
  268. package/dist/user/contacts/respond_invite.d.ts.map +1 -0
  269. package/dist/user/contacts/respond_invite.js +65 -0
  270. package/dist/user/contacts/respond_invite.js.map +1 -0
  271. package/dist/user/contacts/templates.d.ts +7 -0
  272. package/dist/user/contacts/templates.d.ts.map +1 -0
  273. package/dist/user/contacts/templates.js +24 -0
  274. package/dist/user/contacts/templates.js.map +1 -0
  275. package/dist/user/profile/delete_user.d.ts +8 -0
  276. package/dist/user/profile/delete_user.d.ts.map +1 -0
  277. package/dist/user/profile/delete_user.js +56 -0
  278. package/dist/user/profile/delete_user.js.map +1 -0
  279. package/dist/user/profile/dialogs.d.ts +10 -0
  280. package/dist/user/profile/dialogs.d.ts.map +1 -0
  281. package/dist/user/profile/dialogs.js +311 -0
  282. package/dist/user/profile/dialogs.js.map +1 -0
  283. package/dist/user/profile/index.d.ts +27 -0
  284. package/dist/user/profile/index.d.ts.map +1 -0
  285. package/dist/user/profile/index.js +254 -0
  286. package/dist/user/profile/index.js.map +1 -0
  287. package/dist/user/profile/templates.d.ts +22 -0
  288. package/dist/user/profile/templates.d.ts.map +1 -0
  289. package/dist/user/profile/templates.js +261 -0
  290. package/dist/user/profile/templates.js.map +1 -0
  291. package/dist/workers/adjust_doc_to_template.d.ts +11 -0
  292. package/dist/workers/adjust_doc_to_template.d.ts.map +1 -0
  293. package/dist/workers/adjust_doc_to_template.js +26 -0
  294. package/dist/workers/adjust_doc_to_template.js.map +1 -0
  295. package/package.json +225 -0
  296. package/src/admin_console/index.ts +84 -0
  297. package/src/api/index.ts +149 -0
  298. package/src/app/index.ts +605 -0
  299. package/src/common/index.ts +2 -0
  300. package/src/common/templates.ts +49 -0
  301. package/src/common/user_util.ts +16 -0
  302. package/src/document_templates/actions.ts +179 -0
  303. package/src/document_templates/editor.ts +177 -0
  304. package/src/document_templates/index.ts +2 -0
  305. package/src/document_templates/menu.ts +74 -0
  306. package/src/document_templates/overview.ts +335 -0
  307. package/src/document_templates/templates.ts +9 -0
  308. package/src/documents/importer/docx/import.ts +25 -0
  309. package/src/documents/importer/docx/index.ts +1 -0
  310. package/src/documents/importer/native/file.ts +112 -0
  311. package/src/documents/importer/native/import.ts +219 -0
  312. package/src/documents/importer/native/index.ts +2 -0
  313. package/src/documents/importer/odt/import.ts +26 -0
  314. package/src/documents/importer/odt/index.ts +1 -0
  315. package/src/documents/importer/pandoc/import.ts +57 -0
  316. package/src/documents/importer/pandoc/index.ts +1 -0
  317. package/src/documents/importer/register.ts +8 -0
  318. package/src/documents/overview/actions.ts +1031 -0
  319. package/src/documents/overview/index.ts +1006 -0
  320. package/src/documents/overview/menu.ts +311 -0
  321. package/src/documents/overview/templates.ts +64 -0
  322. package/src/documents/revisions/index.ts +183 -0
  323. package/src/documents/revisions/templates.ts +42 -0
  324. package/src/documents/tools.ts +107 -0
  325. package/src/error_hook/index.ts +129 -0
  326. package/src/feedback/index.ts +185 -0
  327. package/src/global.d.ts +22 -0
  328. package/src/index.ts +95 -0
  329. package/src/indexed_db/index.ts +217 -0
  330. package/src/maintenance/index.ts +258 -0
  331. package/src/menu/index.ts +267 -0
  332. package/src/menu/templates.ts +21 -0
  333. package/src/pages/404.ts +13 -0
  334. package/src/pages/flatpage.ts +43 -0
  335. package/src/pages/offline.ts +39 -0
  336. package/src/pages/setup.ts +34 -0
  337. package/src/plugins/menu/index.ts +3 -0
  338. package/src/prelogin/index.ts +175 -0
  339. package/src/prelogin/templates.ts +86 -0
  340. package/src/types.ts +63 -0
  341. package/src/user/auth/email_confirm.ts +153 -0
  342. package/src/user/auth/email_confirm_templates.ts +76 -0
  343. package/src/user/auth/login.ts +221 -0
  344. package/src/user/auth/password_reset_change.ts +120 -0
  345. package/src/user/auth/password_reset_request.ts +107 -0
  346. package/src/user/auth/signup.ts +182 -0
  347. package/src/user/auth/two_factor.ts +244 -0
  348. package/src/user/contacts/add_dialog.ts +104 -0
  349. package/src/user/contacts/delete_dialog.ts +40 -0
  350. package/src/user/contacts/index.ts +289 -0
  351. package/src/user/contacts/invite.ts +24 -0
  352. package/src/user/contacts/menu.ts +70 -0
  353. package/src/user/contacts/respond_invite.ts +76 -0
  354. package/src/user/contacts/templates.ts +29 -0
  355. package/src/user/profile/delete_user.ts +71 -0
  356. package/src/user/profile/dialogs.ts +363 -0
  357. package/src/user/profile/index.ts +359 -0
  358. package/src/user/profile/templates.ts +299 -0
  359. package/src/workers/adjust_doc_to_template.ts +41 -0
@@ -0,0 +1,605 @@
1
+ import {CSL} from "citeproc-plus"
2
+
3
+ import {BibliographyDB} from "@fiduswriter/bibliography-manager/database"
4
+ import {ImageDB, ImageOverview} from "@fiduswriter/image-manager"
5
+ import {
6
+ WebSocketConnector,
7
+ addAlert,
8
+ ensureCSS,
9
+ findTarget,
10
+ getJson,
11
+ showSystemMessage
12
+ } from "fwtoolkit"
13
+ import {getSettings, initSettings} from "fwtoolkit/settings"
14
+
15
+ import {ContactInvite} from "../user/contacts/invite.js"
16
+ import {EmailConfirm} from "../user/auth/email_confirm.js"
17
+ import {LoginPage} from "../user/auth/login.js"
18
+ import {PasswordResetChangePassword} from "../user/auth/password_reset_change.js"
19
+ import {PasswordResetRequest} from "../user/auth/password_reset_request.js"
20
+ import {Signup} from "../user/auth/signup.js"
21
+ import {DocTemplatesEditor, DocTemplatesOverview} from "../document_templates/index.js"
22
+ import {DocumentOverview} from "../documents/overview/index.js"
23
+ import {IndexedDB} from "../indexed_db/index.js"
24
+ import {Page404} from "../pages/404.js"
25
+ import {FlatPage} from "../pages/flatpage.js"
26
+ import {OfflinePage} from "../pages/offline.js"
27
+ import {SetupPage} from "../pages/setup.js"
28
+ import {ContactsOverview} from "../user/contacts/index.js"
29
+ import {Profile} from "../user/profile/index.js"
30
+
31
+ import type {ApiConnectors} from "../api/index.js"
32
+
33
+ // ---- Plugin types ----
34
+
35
+ interface PluginConstructor {
36
+ new (...args: any[]): {init(): () => void}
37
+ }
38
+
39
+ type PluginModule = Record<string, PluginConstructor>
40
+ type PluginList = Array<[string, PluginModule]>
41
+
42
+ export interface AppPluginOptions {
43
+ appPlugins?: PluginList
44
+ menuPlugins?: PluginList
45
+ editorPlugins?: PluginList
46
+ citationDialogPlugins?: PluginList
47
+ bibliographyOverviewPlugins?: PluginList
48
+ }
49
+
50
+ // ---- Route types ----
51
+
52
+ interface DbTableProperties {
53
+ keyPath?: string
54
+ autoIncrement?: boolean
55
+ }
56
+
57
+ interface RouteEntry {
58
+ app: string
59
+ requireLogin?: boolean
60
+ open: (pathnameParts: string[]) => any
61
+ dbTables?: Record<string, DbTableProperties>
62
+ [key: string]: unknown
63
+ }
64
+
65
+ type RouteMap = Record<string, RouteEntry>
66
+
67
+ // ---- Page interface ----
68
+
69
+ interface Page {
70
+ init: () => Promise<void>
71
+ close?: () => void
72
+ onResize?: () => void
73
+ onBeforeUnload?: () => boolean
74
+ }
75
+
76
+ // ---- App class ----
77
+
78
+ export class App {
79
+ apiConnectors: ApiConnectors
80
+ settings: Record<string, any>
81
+ config: Record<string, any>
82
+ name: string
83
+ menuPlugins: PluginList
84
+ appPlugins: PluginList
85
+ editorPlugins: PluginList
86
+ citationDialogPlugins: PluginList
87
+ bibliographyOverviewPlugins: PluginList
88
+ routes: RouteMap
89
+
90
+ openLoginPage: () => Page
91
+ openOfflinePage: () => Page
92
+ openSetupPage: () => Page
93
+ open404Page: () => Page
94
+ handleSWUpdate: () => void
95
+
96
+ page?: Page
97
+ ws?: any
98
+ csl?: any
99
+ bibDB?: any
100
+ imageDB?: any
101
+ indexedDB?: IndexedDB
102
+ plugins?: Record<string, any>
103
+ inviteKey?: string
104
+
105
+ constructor(
106
+ apiConnectors: ApiConnectors,
107
+ settings: Record<string, any> = {},
108
+ pluginOpts: AppPluginOptions = {}
109
+ ) {
110
+ this.apiConnectors = apiConnectors
111
+
112
+ settings.gettext = (window as any).gettext
113
+ settings.staticUrl = (window as any).staticUrl
114
+ settings.interpolate = (window as any).interpolate
115
+ initSettings(settings as any)
116
+ this.settings = getSettings() as Record<string, any>
117
+ this.config = {}
118
+ this.name = "Fidus Writer"
119
+ this.config.app = this
120
+
121
+ this.appPlugins = pluginOpts.appPlugins ?? []
122
+ this.menuPlugins = pluginOpts.menuPlugins ?? []
123
+ this.editorPlugins = pluginOpts.editorPlugins ?? []
124
+ this.citationDialogPlugins = pluginOpts.citationDialogPlugins ?? []
125
+ this.bibliographyOverviewPlugins =
126
+ pluginOpts.bibliographyOverviewPlugins ?? []
127
+
128
+ this.routes = {
129
+ "": {
130
+ app: "document",
131
+ requireLogin: true,
132
+ open: () => {
133
+ const overview = new DocumentOverview(this.config as any, "/")
134
+ return Promise.resolve(overview)
135
+ }
136
+ },
137
+ account: {
138
+ app: "user",
139
+ requireLogin: false,
140
+ open: (pathnameParts: string[]) => {
141
+ let returnValue: any
142
+ switch (pathnameParts[2]) {
143
+ case "confirm-email": {
144
+ const key = pathnameParts[3]
145
+ returnValue = new EmailConfirm(this.config as any, key)
146
+ break
147
+ }
148
+ case "password-reset":
149
+ returnValue = new PasswordResetRequest(this.config as any)
150
+ break
151
+ case "change-password": {
152
+ const key = pathnameParts[3]
153
+ returnValue = new PasswordResetChangePassword(
154
+ this.config as any,
155
+ key
156
+ )
157
+ break
158
+ }
159
+ case "sign-up":
160
+ returnValue = new Signup(this.config as any)
161
+ break
162
+ default:
163
+ returnValue = false
164
+ }
165
+ return returnValue
166
+ }
167
+ },
168
+ bibliography: {
169
+ app: "bibliography",
170
+ requireLogin: true,
171
+ open: () =>
172
+ import("@fiduswriter/bibliography-manager/overview").then(
173
+ ({BibliographyOverview}: any) =>
174
+ new BibliographyOverview(
175
+ this.config as any,
176
+ this.bibliographyOverviewPlugins as any
177
+ )
178
+ )
179
+ },
180
+ document: {
181
+ app: "document",
182
+ requireLogin: true,
183
+ open: (pathnameParts: string[]) => {
184
+ let id = pathnameParts.pop()!
185
+ if (!id.length) {
186
+ id = pathnameParts.pop()!
187
+ }
188
+ const path = (
189
+ "/" + pathnameParts.slice(2).join("/")
190
+ ).replace(/\/?$/, "/")
191
+ return import(
192
+ /* webpackPrefetch: true */ /* webpackChunkName: "editor" */ "@fiduswriter/editor"
193
+ ).then(
194
+ ({Editor}: any) =>
195
+ new Editor(
196
+ this.config as any,
197
+ path,
198
+ id,
199
+ this.editorPlugins as any,
200
+ this.citationDialogPlugins as any
201
+ )
202
+ )
203
+ },
204
+ dbTables: {
205
+ data: {
206
+ keyPath: "id"
207
+ }
208
+ }
209
+ },
210
+ share: {
211
+ // Document shared via document link
212
+ app: "document",
213
+ requireLogin: false,
214
+ open: (pathnameParts: string[]) => {
215
+ let token = pathnameParts.pop()!
216
+ if (!token.length) {
217
+ token = pathnameParts.pop()!
218
+ }
219
+ const path = "/"
220
+ return import(
221
+ /* webpackPrefetch: true */ /* webpackChunkName: "editor" */ "@fiduswriter/editor"
222
+ ).then(
223
+ ({Editor}: any) =>
224
+ new Editor(
225
+ this.config as any,
226
+ path,
227
+ token,
228
+ this.editorPlugins as any,
229
+ this.citationDialogPlugins as any
230
+ )
231
+ )
232
+ }
233
+ },
234
+ documents: {
235
+ app: "document",
236
+ requireLogin: true,
237
+ open: (pathnameParts: string[]) => {
238
+ const path = (
239
+ "/" + pathnameParts.slice(2).join("/")
240
+ ).replace(/\/?$/, "/")
241
+ const overview = new DocumentOverview(this.config as any, path)
242
+ return Promise.resolve(overview)
243
+ }
244
+ },
245
+ pages: {
246
+ app: "base",
247
+ open: (pathnameParts: string[]) => {
248
+ const url = `/${pathnameParts[2]}/`
249
+ return new FlatPage(this.config as any, url)
250
+ }
251
+ },
252
+ user: {
253
+ app: "user",
254
+ requireLogin: true,
255
+ open: (pathnameParts: string[]) => {
256
+ let returnValue: any
257
+ switch (pathnameParts[2]) {
258
+ case "profile":
259
+ returnValue = new Profile(this.config as any)
260
+ break
261
+ case "contacts":
262
+ returnValue = new ContactsOverview(this.config as any)
263
+ break
264
+ default:
265
+ returnValue = false
266
+ }
267
+ return returnValue
268
+ },
269
+ dbTables: {
270
+ data: {
271
+ keyPath: "id"
272
+ }
273
+ }
274
+ },
275
+ invite: {
276
+ app: "user",
277
+ open: (pathnameParts: string[]) => {
278
+ const id = pathnameParts[2]
279
+ return new ContactInvite(this.config as any, id)
280
+ }
281
+ },
282
+ usermedia: {
283
+ app: "usermedia",
284
+ requireLogin: true,
285
+ open: () => new ImageOverview(this.config as any)
286
+ },
287
+ templates: {
288
+ app: "user_template_manager",
289
+ requireLogin: true,
290
+ open: (pathnameParts: string[]) => {
291
+ const id = pathnameParts[2]
292
+ if (id) {
293
+ const editor = new DocTemplatesEditor(this.config as any, id)
294
+ return Promise.resolve(editor)
295
+ }
296
+ const overview = new DocTemplatesOverview(this.config as any)
297
+ return Promise.resolve(overview)
298
+ }
299
+ }
300
+ }
301
+ this.openLoginPage = () => new LoginPage(this.config as any)
302
+ this.openOfflinePage = () => new OfflinePage(this.config as any)
303
+ this.openSetupPage = () => new SetupPage(this.config as any)
304
+ this.open404Page = () => new Page404(this.config as any)
305
+ this.handleSWUpdate = () => window.location.reload()
306
+ }
307
+
308
+ isOffline(): boolean {
309
+ return (
310
+ !navigator.onLine ||
311
+ (this.ws?.connectionCount > 0 && !this.ws?.connected)
312
+ )
313
+ }
314
+
315
+ alertCached(): void {
316
+ addAlert(
317
+ "info",
318
+ gettext("You are viewing a cached version of this page.")
319
+ )
320
+ }
321
+
322
+ installServiceWorker(): void {
323
+ /* This function is used for testing SW with Django tests */
324
+ if ("serviceWorker" in navigator) {
325
+ navigator.serviceWorker
326
+ .register("/sw.js")
327
+ .then(registration => {
328
+ console.log("SW registered: ", registration)
329
+ })
330
+ .catch(registrationError => {
331
+ console.log("SW registration failed: ", registrationError)
332
+ })
333
+ }
334
+ }
335
+
336
+ init(): Promise<any> {
337
+ if (
338
+ !this.settings.DEBUG &&
339
+ this.settings.USE_SERVICE_WORKER &&
340
+ "serviceWorker" in navigator
341
+ ) {
342
+ navigator.serviceWorker
343
+ .register("/sw.js")
344
+ .then(registration => {
345
+ console.log("SW registered: ", registration)
346
+ })
347
+ .catch(registrationError => {
348
+ console.log("SW registration failed: ", registrationError)
349
+ })
350
+ }
351
+ ensureCSS([staticUrl("css/fontawesome/css/all.css")])
352
+ // Disable automatic scroll restoration to prevent Safari from
353
+ // auto-scrolling to focused elements (like the document table)
354
+ // which causes the header/menu to be hidden on page load
355
+ if ("scrollRestoration" in history) {
356
+ history.scrollRestoration = "manual"
357
+ }
358
+ // Ensure we start at the top of the page
359
+ window.scrollTo(0, 0)
360
+ if (this.isOffline()) {
361
+ this.page = this.openOfflinePage()
362
+ return this.page.init()
363
+ } else {
364
+ return this.getConfiguration()
365
+ .catch(error => {
366
+ if (error instanceof TypeError) {
367
+ // We could not fetch user info from server, so let's
368
+ // assume we are disconnected.
369
+ this.page = this.openOfflinePage()
370
+ this.page.init()
371
+ } else if (error.status === 405) {
372
+ // 405 indicates that the server is running but the
373
+ // method is not allowed. This must be the setup server.
374
+ // We show a setup message instead.
375
+ this.page = this.openSetupPage()
376
+ this.page.init()
377
+ } else if (this.settings.DEBUG) {
378
+ throw error
379
+ } else {
380
+ // We don't know what is going on, but we are in production
381
+ // mode. Hopefully the app will update soon.
382
+ this.page = this.openOfflinePage()
383
+ this.page.init()
384
+ }
385
+ return Promise.reject(false)
386
+ })
387
+ .then(() => this.setup())
388
+ .catch(error => {
389
+ if (error === false) {
390
+ return
391
+ }
392
+ throw error
393
+ })
394
+ }
395
+ }
396
+
397
+ setup(): Promise<any> {
398
+ this.csl = new CSL()
399
+ if (!this.config.user.is_authenticated) {
400
+ this.activateFidusPlugins()
401
+ return this.selectPage().then(() => this.bind())
402
+ }
403
+ this.bibDB = new BibliographyDB(this as any)
404
+ this.imageDB = new ImageDB(this as any)
405
+ this.connectWs()
406
+ return Promise.all([this.bibDB.getDB(), this.imageDB.getDB()])
407
+ .then(() => {
408
+ this.activateFidusPlugins()
409
+ // Initialize the indexedDB after the plugins have loaded.
410
+ this.indexedDB = new IndexedDB(
411
+ this.config.user.username,
412
+ this.routes as any
413
+ )
414
+ return this.indexedDB.init()
415
+ })
416
+ .then(() => this.selectPage())
417
+ .then(() => this.bind())
418
+ .then(() => this.showNews())
419
+ }
420
+
421
+ bind(): void {
422
+ window.onpopstate = () => this.selectPage()
423
+ document.addEventListener("click", event => {
424
+ const el: Record<string, any> = {}
425
+ switch (true) {
426
+ case findTarget(event, "a", el):
427
+ if (
428
+ el.target.hostname === window.location.hostname &&
429
+ el.target.getAttribute("href")[0] === "/" &&
430
+ el.target.getAttribute("href").slice(0, 7) !==
431
+ "/media/" &&
432
+ el.target.getAttribute("href").slice(0, 5) !== "/api/"
433
+ ) {
434
+ event.preventDefault()
435
+ event.stopImmediatePropagation()
436
+ this.goTo(decodeURI(el.target.href))
437
+ }
438
+ break
439
+ }
440
+ })
441
+ let resizeDone: ReturnType<typeof setTimeout>
442
+ window.addEventListener("resize", () => {
443
+ clearTimeout(resizeDone)
444
+ resizeDone = setTimeout(() => {
445
+ if (this.page && this.page.onResize) {
446
+ this.page.onResize()
447
+ }
448
+ }, 250)
449
+ })
450
+ window.addEventListener("beforeunload", event => {
451
+ if (this.page && this.page.onBeforeUnload) {
452
+ if (this.page.onBeforeUnload()) {
453
+ event.preventDefault()
454
+ // To stop the event for chrome and safari
455
+ ;(event as any).returnValue = ""
456
+ return ""
457
+ }
458
+ }
459
+ return undefined
460
+ })
461
+ }
462
+
463
+ showNews(): void {
464
+ if (
465
+ window.location.pathname !== "/user/contacts/" &&
466
+ this.config.user.waiting_invites
467
+ ) {
468
+ showSystemMessage(
469
+ gettext(
470
+ "Other users have requested to connect with you. Go to the contacts page to accept their invites."
471
+ ),
472
+ [
473
+ {
474
+ text: gettext("Go to contacts"),
475
+ classes: "fw-dark",
476
+ click: (_event: any) => {
477
+ return this.goTo("/user/contacts/")
478
+ }
479
+ },
480
+ {type: "close"}
481
+ ] as any
482
+ )
483
+ }
484
+ }
485
+
486
+ connectWs(): void {
487
+ if (!this.config.ws_url_base) {
488
+ return
489
+ }
490
+ this.ws = new (WebSocketConnector as any)({
491
+ base: this.config.ws_url_base,
492
+ path: "/base/",
493
+ appLoaded: () => true,
494
+ receiveData: (data: any) => {
495
+ switch (data.type) {
496
+ case "system_message":
497
+ showSystemMessage(data.message)
498
+ break
499
+ default:
500
+ break
501
+ }
502
+ }
503
+ })
504
+ this.ws.init()
505
+ }
506
+
507
+ activateFidusPlugins(): void {
508
+ if (this.plugins) {
509
+ // Plugins have been activated already
510
+ return
511
+ }
512
+ // Add plugins.
513
+ this.plugins = {}
514
+
515
+ this.appPlugins.forEach(([app, plugin]) => {
516
+ if (!this.settings.APPS.includes(app)) {
517
+ return
518
+ }
519
+ Object.values(plugin).forEach((pluginExport: any) => {
520
+ if (typeof pluginExport === "function") {
521
+ this.plugins![pluginExport.name] = new pluginExport(this)
522
+ this.plugins![pluginExport.name].init()
523
+ }
524
+ })
525
+ })
526
+ }
527
+
528
+ selectPage(): Promise<void> {
529
+ if (this.page && this.page.close) {
530
+ this.page.close()
531
+ }
532
+ // Disable automatic scroll restoration to prevent Safari from
533
+ // auto-scrolling to focused elements (like the document table)
534
+ // which causes the header/menu to be hidden on page load
535
+ if ("scrollRestoration" in history) {
536
+ history.scrollRestoration = "manual"
537
+ }
538
+ // Ensure we start at the top of the page
539
+ window.scrollTo(0, 0)
540
+ const pathnameParts = decodeURI(window.location.pathname).split("/")
541
+ const route = this.routes[pathnameParts[1]]
542
+ if (route) {
543
+ if (
544
+ route.requireLogin &&
545
+ !(this.config.user || {}).is_authenticated
546
+ ) {
547
+ this.page = this.openLoginPage()
548
+ return this.page.init()
549
+ }
550
+ const page = route.open(pathnameParts)
551
+ if (page.then) {
552
+ return page.then((thisPage: Page) => {
553
+ this.page = thisPage
554
+ return this.page.init().then(() => {
555
+ if (this.isOffline()) {
556
+ this.alertCached()
557
+ }
558
+ })
559
+ })
560
+ } else if (page) {
561
+ this.page = page
562
+ return page.init().then(() => {
563
+ if (this.isOffline()) {
564
+ this.alertCached()
565
+ }
566
+ })
567
+ }
568
+ }
569
+ this.page = this.open404Page()
570
+ return this.page.init()
571
+ }
572
+
573
+ getConfiguration(): Promise<void> {
574
+ return (getJson as any)("/api/base/configuration/")
575
+ .then((json: Record<string, any>) =>
576
+ Object.entries(json).forEach(
577
+ ([key, value]) => (this.config[key] = value)
578
+ )
579
+ )
580
+ .catch((error: any) => {
581
+ if (error instanceof Response && error.status === 403) {
582
+ // We could not fetch user info from server, so let's
583
+ // assume we are disconnected and delete all cookies.
584
+ // This will force the user to log in again.
585
+ //
586
+ // This is a bit of a hack, but it is the only way to make sure
587
+ // that the user is logged out when the server is not reachable.
588
+ document.cookie.split(";").forEach(cookie => {
589
+ const eqPos = cookie.indexOf("=")
590
+ const name =
591
+ eqPos > -1 ? cookie.substring(0, eqPos) : cookie
592
+ document.cookie =
593
+ name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"
594
+ })
595
+ return Promise.reject(error)
596
+ }
597
+ throw error
598
+ })
599
+ }
600
+
601
+ goTo(url: string): Promise<void> {
602
+ window.history.pushState({}, "", encodeURI(url))
603
+ return this.selectPage()
604
+ }
605
+ }
@@ -0,0 +1,2 @@
1
+ export {baseBodyTemplate} from "./templates.js"
2
+ export {filterPrimaryEmail} from "./user_util.js"
@@ -0,0 +1,49 @@
1
+ import {avatarTemplate} from "fwtoolkit/user"
2
+
3
+ import {filterPrimaryEmail} from "./user_util.js"
4
+ import type {BaseBodyTemplateOptions} from "../types.js"
5
+
6
+ export const baseBodyTemplate = ({
7
+ user,
8
+ contents,
9
+ hasOverview,
10
+ app
11
+ }: BaseBodyTemplateOptions): string => `
12
+ <div id="fw-wait">
13
+ <i class="fa fa-spinner fa-pulse"></i>
14
+ </div>
15
+ <header class="fw-header" role="banner">
16
+ <div class="fw-container">
17
+ <a href="${app && app.routes[""].app === "document" ? "/" : "/documents/"}">
18
+ <h1 class="fw-logo">
19
+ <span class="fw-logo-text"></span>
20
+ <img src="${staticUrl("svg/icon.svg")}" alt="Logo" />
21
+ </h1>
22
+ </a>
23
+ <nav id="header-nav" role="navigation" aria-label="${gettext("Site navigation")}"></nav>
24
+ <div id="user-preferences" class="fw-user-preferences fw-header-text">
25
+ <div id="preferences-btn" class="fw-button">
26
+ ${avatarTemplate({user})}
27
+ </div>
28
+ <div id="user-preferences-pulldown" class="fw-pulldown fw-right">
29
+ <div data-value="profile">
30
+ <span class='fw-avatar-card'>
31
+ <span class='fw-avatar-card-avatar'>${avatarTemplate({user})}</span>
32
+ <span class='fw-avatar-card-name'>
33
+ ${user.username}
34
+ <span class='fw-avatar-card-email'>${filterPrimaryEmail(user.emails)}</span>
35
+ </span>
36
+ </span>
37
+ </div>
38
+ <div data-value="contacts">${gettext("Contacts")}</div>
39
+ <div data-value="logout">${gettext("Log out")}</div>
40
+ </div>
41
+ </div><!-- end user preference -->
42
+ </div><!-- end container -->
43
+ </header>
44
+ <div class="fw-contents-outer">
45
+ ${hasOverview ? '<div class="fw-overview-menu-wrapper"><ul id="fw-overview-menu"></ul></div>' : ""}
46
+ <div class="fw-contents">
47
+ ${contents}
48
+ </div>
49
+ </div>`
@@ -0,0 +1,16 @@
1
+ import type {Email} from "../types.js"
2
+
3
+ /** Pick the primary email address from a list of email objects.
4
+ * Falls back to the first address if no primary is marked.
5
+ */
6
+ export const filterPrimaryEmail = (emails: Email[]): string => {
7
+ const primaryEmails = emails.filter(email => email.primary)
8
+ if (!primaryEmails.length) {
9
+ if (emails.length) {
10
+ return emails[0].address
11
+ } else {
12
+ return ""
13
+ }
14
+ }
15
+ return primaryEmails[0].address
16
+ }