@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.
- package/LICENSE +661 -0
- package/README.md +66 -0
- package/dist/admin_console/index.d.ts +8 -0
- package/dist/admin_console/index.d.ts.map +1 -0
- package/dist/admin_console/index.js +54 -0
- package/dist/admin_console/index.js.map +1 -0
- package/dist/api/index.d.ts +193 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/app/index.d.ts +74 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +471 -0
- package/dist/app/index.js.map +1 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +3 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/templates.d.ts +3 -0
- package/dist/common/templates.d.ts.map +1 -0
- package/dist/common/templates.js +42 -0
- package/dist/common/templates.js.map +1 -0
- package/dist/common/user_util.d.ts +6 -0
- package/dist/common/user_util.d.ts.map +1 -0
- package/dist/common/user_util.js +16 -0
- package/dist/common/user_util.js.map +1 -0
- package/dist/document_templates/actions.d.ts +11 -0
- package/dist/document_templates/actions.d.ts.map +1 -0
- package/dist/document_templates/actions.js +141 -0
- package/dist/document_templates/actions.js.map +1 -0
- package/dist/document_templates/editor.d.ts +28 -0
- package/dist/document_templates/editor.d.ts.map +1 -0
- package/dist/document_templates/editor.js +139 -0
- package/dist/document_templates/editor.js.map +1 -0
- package/dist/document_templates/index.d.ts +3 -0
- package/dist/document_templates/index.d.ts.map +1 -0
- package/dist/document_templates/index.js +3 -0
- package/dist/document_templates/index.js.map +1 -0
- package/dist/document_templates/menu.d.ts +7 -0
- package/dist/document_templates/menu.d.ts.map +1 -0
- package/dist/document_templates/menu.js +62 -0
- package/dist/document_templates/menu.js.map +1 -0
- package/dist/document_templates/overview.d.ts +52 -0
- package/dist/document_templates/overview.d.ts.map +1 -0
- package/dist/document_templates/overview.js +274 -0
- package/dist/document_templates/overview.js.map +1 -0
- package/dist/document_templates/templates.d.ts +3 -0
- package/dist/document_templates/templates.d.ts.map +1 -0
- package/dist/document_templates/templates.js +9 -0
- package/dist/document_templates/templates.js.map +1 -0
- package/dist/documents/importer/docx/import.d.ts +5 -0
- package/dist/documents/importer/docx/import.d.ts.map +1 -0
- package/dist/documents/importer/docx/import.js +15 -0
- package/dist/documents/importer/docx/import.js.map +1 -0
- package/dist/documents/importer/docx/index.d.ts +2 -0
- package/dist/documents/importer/docx/index.d.ts.map +1 -0
- package/dist/documents/importer/docx/index.js +2 -0
- package/dist/documents/importer/docx/index.js.map +1 -0
- package/dist/documents/importer/native/file.d.ts +7 -0
- package/dist/documents/importer/native/file.d.ts.map +1 -0
- package/dist/documents/importer/native/file.js +60 -0
- package/dist/documents/importer/native/file.js.map +1 -0
- package/dist/documents/importer/native/import.d.ts +41 -0
- package/dist/documents/importer/native/import.d.ts.map +1 -0
- package/dist/documents/importer/native/import.js +126 -0
- package/dist/documents/importer/native/import.js.map +1 -0
- package/dist/documents/importer/native/index.d.ts +3 -0
- package/dist/documents/importer/native/index.d.ts.map +1 -0
- package/dist/documents/importer/native/index.js +3 -0
- package/dist/documents/importer/native/index.js.map +1 -0
- package/dist/documents/importer/odt/import.d.ts +5 -0
- package/dist/documents/importer/odt/import.d.ts.map +1 -0
- package/dist/documents/importer/odt/import.js +16 -0
- package/dist/documents/importer/odt/import.js.map +1 -0
- package/dist/documents/importer/odt/index.d.ts +2 -0
- package/dist/documents/importer/odt/index.d.ts.map +1 -0
- package/dist/documents/importer/odt/index.js +2 -0
- package/dist/documents/importer/odt/index.js.map +1 -0
- package/dist/documents/importer/pandoc/import.d.ts +5 -0
- package/dist/documents/importer/pandoc/import.d.ts.map +1 -0
- package/dist/documents/importer/pandoc/import.js +37 -0
- package/dist/documents/importer/pandoc/import.js.map +1 -0
- package/dist/documents/importer/pandoc/index.d.ts +2 -0
- package/dist/documents/importer/pandoc/index.d.ts.map +1 -0
- package/dist/documents/importer/pandoc/index.js +2 -0
- package/dist/documents/importer/pandoc/index.js.map +1 -0
- package/dist/documents/importer/register.d.ts +4 -0
- package/dist/documents/importer/register.d.ts.map +1 -0
- package/dist/documents/importer/register.js +4 -0
- package/dist/documents/importer/register.js.map +1 -0
- package/dist/documents/overview/actions.d.ts +32 -0
- package/dist/documents/overview/actions.d.ts.map +1 -0
- package/dist/documents/overview/actions.js +725 -0
- package/dist/documents/overview/actions.js.map +1 -0
- package/dist/documents/overview/index.d.ts +98 -0
- package/dist/documents/overview/index.d.ts.map +1 -0
- package/dist/documents/overview/index.js +814 -0
- package/dist/documents/overview/index.js.map +1 -0
- package/dist/documents/overview/menu.d.ts +28 -0
- package/dist/documents/overview/menu.d.ts.map +1 -0
- package/dist/documents/overview/menu.js +222 -0
- package/dist/documents/overview/menu.js.map +1 -0
- package/dist/documents/overview/templates.d.ts +31 -0
- package/dist/documents/overview/templates.d.ts.map +1 -0
- package/dist/documents/overview/templates.js +39 -0
- package/dist/documents/overview/templates.js.map +1 -0
- package/dist/documents/revisions/index.d.ts +14 -0
- package/dist/documents/revisions/index.d.ts.map +1 -0
- package/dist/documents/revisions/index.js +143 -0
- package/dist/documents/revisions/index.js.map +1 -0
- package/dist/documents/revisions/templates.d.ts +4 -0
- package/dist/documents/revisions/templates.d.ts.map +1 -0
- package/dist/documents/revisions/templates.js +36 -0
- package/dist/documents/revisions/templates.js.map +1 -0
- package/dist/documents/tools.d.ts +16 -0
- package/dist/documents/tools.d.ts.map +1 -0
- package/dist/documents/tools.js +69 -0
- package/dist/documents/tools.js.map +1 -0
- package/dist/error_hook/index.d.ts +19 -0
- package/dist/error_hook/index.d.ts.map +1 -0
- package/dist/error_hook/index.js +75 -0
- package/dist/error_hook/index.js.map +1 -0
- package/dist/feedback/index.d.ts +12 -0
- package/dist/feedback/index.d.ts.map +1 -0
- package/dist/feedback/index.js +125 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/indexed_db/index.d.ts +24 -0
- package/dist/indexed_db/index.d.ts.map +1 -0
- package/dist/indexed_db/index.js +175 -0
- package/dist/indexed_db/index.js.map +1 -0
- package/dist/maintenance/index.d.ts +19 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +223 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/menu/index.d.ts +25 -0
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/menu/index.js +229 -0
- package/dist/menu/index.js.map +1 -0
- package/dist/menu/templates.d.ts +6 -0
- package/dist/menu/templates.d.ts.map +1 -0
- package/dist/menu/templates.js +10 -0
- package/dist/menu/templates.js.map +1 -0
- package/dist/pages/404.d.ts +9 -0
- package/dist/pages/404.d.ts.map +1 -0
- package/dist/pages/404.js +12 -0
- package/dist/pages/404.js.map +1 -0
- package/dist/pages/flatpage.d.ts +12 -0
- package/dist/pages/flatpage.d.ts.map +1 -0
- package/dist/pages/flatpage.js +39 -0
- package/dist/pages/flatpage.js.map +1 -0
- package/dist/pages/offline.d.ts +10 -0
- package/dist/pages/offline.d.ts.map +1 -0
- package/dist/pages/offline.js +27 -0
- package/dist/pages/offline.js.map +1 -0
- package/dist/pages/setup.d.ts +10 -0
- package/dist/pages/setup.d.ts.map +1 -0
- package/dist/pages/setup.js +22 -0
- package/dist/pages/setup.js.map +1 -0
- package/dist/plugins/menu/index.d.ts +3 -0
- package/dist/plugins/menu/index.d.ts.map +1 -0
- package/dist/plugins/menu/index.js +2 -0
- package/dist/plugins/menu/index.js.map +1 -0
- package/dist/prelogin/index.d.ts +51 -0
- package/dist/prelogin/index.d.ts.map +1 -0
- package/dist/prelogin/index.js +131 -0
- package/dist/prelogin/index.js.map +1 -0
- package/dist/prelogin/templates.d.ts +20 -0
- package/dist/prelogin/templates.d.ts.map +1 -0
- package/dist/prelogin/templates.js +50 -0
- package/dist/prelogin/templates.js.map +1 -0
- package/dist/state_plugins/contributor_input/add_button.d.ts +22 -0
- package/dist/state_plugins/contributor_input/add_button.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/add_button.js +106 -0
- package/dist/state_plugins/contributor_input/add_button.js.map +1 -0
- package/dist/state_plugins/contributor_input/helpers.d.ts +3 -0
- package/dist/state_plugins/contributor_input/helpers.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/helpers.js +23 -0
- package/dist/state_plugins/contributor_input/helpers.js.map +1 -0
- package/dist/state_plugins/contributor_input/index.d.ts +4 -0
- package/dist/state_plugins/contributor_input/index.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/index.js +4 -0
- package/dist/state_plugins/contributor_input/index.js.map +1 -0
- package/dist/state_plugins/contributor_input/node_view.d.ts +20 -0
- package/dist/state_plugins/contributor_input/node_view.d.ts.map +1 -0
- package/dist/state_plugins/contributor_input/node_view.js +85 -0
- package/dist/state_plugins/contributor_input/node_view.js.map +1 -0
- package/dist/state_plugins/index.d.ts +3 -0
- package/dist/state_plugins/index.d.ts.map +1 -0
- package/dist/state_plugins/index.js +3 -0
- package/dist/state_plugins/index.js.map +1 -0
- package/dist/state_plugins/tag_input/helpers.d.ts +5 -0
- package/dist/state_plugins/tag_input/helpers.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/helpers.js +55 -0
- package/dist/state_plugins/tag_input/helpers.js.map +1 -0
- package/dist/state_plugins/tag_input/index.d.ts +5 -0
- package/dist/state_plugins/tag_input/index.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/index.js +5 -0
- package/dist/state_plugins/tag_input/index.js.map +1 -0
- package/dist/state_plugins/tag_input/node_view.d.ts +19 -0
- package/dist/state_plugins/tag_input/node_view.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/node_view.js +85 -0
- package/dist/state_plugins/tag_input/node_view.js.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor.d.ts +4 -0
- package/dist/state_plugins/tag_input/tag_editor.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor.js +160 -0
- package/dist/state_plugins/tag_input/tag_editor.js.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts +5 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.d.ts.map +1 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.js +64 -0
- package/dist/state_plugins/tag_input/tag_editor_plugins.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/user/auth/email_confirm.d.ts +23 -0
- package/dist/user/auth/email_confirm.d.ts.map +1 -0
- package/dist/user/auth/email_confirm.js +123 -0
- package/dist/user/auth/email_confirm.js.map +1 -0
- package/dist/user/auth/email_confirm_templates.d.ts +12 -0
- package/dist/user/auth/email_confirm_templates.d.ts.map +1 -0
- package/dist/user/auth/email_confirm_templates.js +30 -0
- package/dist/user/auth/email_confirm_templates.js.map +1 -0
- package/dist/user/auth/login.d.ts +13 -0
- package/dist/user/auth/login.d.ts.map +1 -0
- package/dist/user/auth/login.js +186 -0
- package/dist/user/auth/login.js.map +1 -0
- package/dist/user/auth/password_reset_change.d.ts +11 -0
- package/dist/user/auth/password_reset_change.d.ts.map +1 -0
- package/dist/user/auth/password_reset_change.js +101 -0
- package/dist/user/auth/password_reset_change.js.map +1 -0
- package/dist/user/auth/password_reset_request.d.ts +10 -0
- package/dist/user/auth/password_reset_request.d.ts.map +1 -0
- package/dist/user/auth/password_reset_request.js +82 -0
- package/dist/user/auth/password_reset_request.js.map +1 -0
- package/dist/user/auth/signup.d.ts +9 -0
- package/dist/user/auth/signup.d.ts.map +1 -0
- package/dist/user/auth/signup.js +148 -0
- package/dist/user/auth/signup.js.map +1 -0
- package/dist/user/auth/two_factor.d.ts +10 -0
- package/dist/user/auth/two_factor.d.ts.map +1 -0
- package/dist/user/auth/two_factor.js +201 -0
- package/dist/user/auth/two_factor.js.map +1 -0
- package/dist/user/contacts/add_dialog.d.ts +7 -0
- package/dist/user/contacts/add_dialog.d.ts.map +1 -0
- package/dist/user/contacts/add_dialog.js +84 -0
- package/dist/user/contacts/add_dialog.js.map +1 -0
- package/dist/user/contacts/delete_dialog.d.ts +6 -0
- package/dist/user/contacts/delete_dialog.d.ts.map +1 -0
- package/dist/user/contacts/delete_dialog.js +38 -0
- package/dist/user/contacts/delete_dialog.js.map +1 -0
- package/dist/user/contacts/index.d.ts +35 -0
- package/dist/user/contacts/index.d.ts.map +1 -0
- package/dist/user/contacts/index.js +234 -0
- package/dist/user/contacts/index.js.map +1 -0
- package/dist/user/contacts/invite.d.ts +9 -0
- package/dist/user/contacts/invite.d.ts.map +1 -0
- package/dist/user/contacts/invite.js +21 -0
- package/dist/user/contacts/invite.js.map +1 -0
- package/dist/user/contacts/menu.d.ts +7 -0
- package/dist/user/contacts/menu.d.ts.map +1 -0
- package/dist/user/contacts/menu.js +62 -0
- package/dist/user/contacts/menu.js.map +1 -0
- package/dist/user/contacts/respond_invite.d.ts +9 -0
- package/dist/user/contacts/respond_invite.d.ts.map +1 -0
- package/dist/user/contacts/respond_invite.js +65 -0
- package/dist/user/contacts/respond_invite.js.map +1 -0
- package/dist/user/contacts/templates.d.ts +7 -0
- package/dist/user/contacts/templates.d.ts.map +1 -0
- package/dist/user/contacts/templates.js +24 -0
- package/dist/user/contacts/templates.js.map +1 -0
- package/dist/user/profile/delete_user.d.ts +8 -0
- package/dist/user/profile/delete_user.d.ts.map +1 -0
- package/dist/user/profile/delete_user.js +56 -0
- package/dist/user/profile/delete_user.js.map +1 -0
- package/dist/user/profile/dialogs.d.ts +10 -0
- package/dist/user/profile/dialogs.d.ts.map +1 -0
- package/dist/user/profile/dialogs.js +311 -0
- package/dist/user/profile/dialogs.js.map +1 -0
- package/dist/user/profile/index.d.ts +27 -0
- package/dist/user/profile/index.d.ts.map +1 -0
- package/dist/user/profile/index.js +254 -0
- package/dist/user/profile/index.js.map +1 -0
- package/dist/user/profile/templates.d.ts +22 -0
- package/dist/user/profile/templates.d.ts.map +1 -0
- package/dist/user/profile/templates.js +261 -0
- package/dist/user/profile/templates.js.map +1 -0
- package/dist/workers/adjust_doc_to_template.d.ts +11 -0
- package/dist/workers/adjust_doc_to_template.d.ts.map +1 -0
- package/dist/workers/adjust_doc_to_template.js +26 -0
- package/dist/workers/adjust_doc_to_template.js.map +1 -0
- package/package.json +225 -0
- package/src/admin_console/index.ts +84 -0
- package/src/api/index.ts +149 -0
- package/src/app/index.ts +605 -0
- package/src/common/index.ts +2 -0
- package/src/common/templates.ts +49 -0
- package/src/common/user_util.ts +16 -0
- package/src/document_templates/actions.ts +179 -0
- package/src/document_templates/editor.ts +177 -0
- package/src/document_templates/index.ts +2 -0
- package/src/document_templates/menu.ts +74 -0
- package/src/document_templates/overview.ts +335 -0
- package/src/document_templates/templates.ts +9 -0
- package/src/documents/importer/docx/import.ts +25 -0
- package/src/documents/importer/docx/index.ts +1 -0
- package/src/documents/importer/native/file.ts +112 -0
- package/src/documents/importer/native/import.ts +219 -0
- package/src/documents/importer/native/index.ts +2 -0
- package/src/documents/importer/odt/import.ts +26 -0
- package/src/documents/importer/odt/index.ts +1 -0
- package/src/documents/importer/pandoc/import.ts +57 -0
- package/src/documents/importer/pandoc/index.ts +1 -0
- package/src/documents/importer/register.ts +8 -0
- package/src/documents/overview/actions.ts +1031 -0
- package/src/documents/overview/index.ts +1006 -0
- package/src/documents/overview/menu.ts +311 -0
- package/src/documents/overview/templates.ts +64 -0
- package/src/documents/revisions/index.ts +183 -0
- package/src/documents/revisions/templates.ts +42 -0
- package/src/documents/tools.ts +107 -0
- package/src/error_hook/index.ts +129 -0
- package/src/feedback/index.ts +185 -0
- package/src/global.d.ts +22 -0
- package/src/index.ts +95 -0
- package/src/indexed_db/index.ts +217 -0
- package/src/maintenance/index.ts +258 -0
- package/src/menu/index.ts +267 -0
- package/src/menu/templates.ts +21 -0
- package/src/pages/404.ts +13 -0
- package/src/pages/flatpage.ts +43 -0
- package/src/pages/offline.ts +39 -0
- package/src/pages/setup.ts +34 -0
- package/src/plugins/menu/index.ts +3 -0
- package/src/prelogin/index.ts +175 -0
- package/src/prelogin/templates.ts +86 -0
- package/src/types.ts +63 -0
- package/src/user/auth/email_confirm.ts +153 -0
- package/src/user/auth/email_confirm_templates.ts +76 -0
- package/src/user/auth/login.ts +221 -0
- package/src/user/auth/password_reset_change.ts +120 -0
- package/src/user/auth/password_reset_request.ts +107 -0
- package/src/user/auth/signup.ts +182 -0
- package/src/user/auth/two_factor.ts +244 -0
- package/src/user/contacts/add_dialog.ts +104 -0
- package/src/user/contacts/delete_dialog.ts +40 -0
- package/src/user/contacts/index.ts +289 -0
- package/src/user/contacts/invite.ts +24 -0
- package/src/user/contacts/menu.ts +70 -0
- package/src/user/contacts/respond_invite.ts +76 -0
- package/src/user/contacts/templates.ts +29 -0
- package/src/user/profile/delete_user.ts +71 -0
- package/src/user/profile/dialogs.ts +363 -0
- package/src/user/profile/index.ts +359 -0
- package/src/user/profile/templates.ts +299 -0
- package/src/workers/adjust_doc_to_template.ts +41 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import {baseBodyTemplate} from "../common/index.js"
|
|
2
|
+
import {FeedbackTab} from "../feedback/index.js"
|
|
3
|
+
import {SiteMenu} from "../menu/index.js"
|
|
4
|
+
import {
|
|
5
|
+
OverviewDataTable,
|
|
6
|
+
OverviewMenuView,
|
|
7
|
+
addAlert,
|
|
8
|
+
ensureCSS,
|
|
9
|
+
escapeText,
|
|
10
|
+
findTarget,
|
|
11
|
+
getJson,
|
|
12
|
+
setDocTitle,
|
|
13
|
+
whenReady
|
|
14
|
+
} from "fwtoolkit"
|
|
15
|
+
|
|
16
|
+
import {DocTemplatesActions} from "./actions.js"
|
|
17
|
+
import {bulkMenuModel, menuModel} from "./menu.js"
|
|
18
|
+
|
|
19
|
+
interface AppLike {
|
|
20
|
+
isOffline: () => boolean
|
|
21
|
+
goTo: (url: string) => void
|
|
22
|
+
indexedDB: {
|
|
23
|
+
readAllData: (store: string) => Promise<Array<Record<string, unknown>>>
|
|
24
|
+
clearData: (store: string) => Promise<void>
|
|
25
|
+
insertData: (store: string, data: Array<Record<string, unknown>>) => Promise<void>
|
|
26
|
+
}
|
|
27
|
+
settings: Record<string, unknown>
|
|
28
|
+
page: unknown
|
|
29
|
+
[key: string]: unknown
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class DocTemplatesOverview {
|
|
33
|
+
app: AppLike
|
|
34
|
+
user: Record<string, unknown>
|
|
35
|
+
mod: {actions?: DocTemplatesActions}
|
|
36
|
+
templateList: Array<Record<string, unknown>>
|
|
37
|
+
styles: any
|
|
38
|
+
lastSort: {column: number; dir: string}
|
|
39
|
+
dom!: HTMLElement
|
|
40
|
+
table: any
|
|
41
|
+
overviewTable: any
|
|
42
|
+
dtBulk: any
|
|
43
|
+
menu: any
|
|
44
|
+
|
|
45
|
+
constructor({app, user}: {app: AppLike; user: Record<string, unknown>}) {
|
|
46
|
+
this.app = app
|
|
47
|
+
this.user = user
|
|
48
|
+
this.mod = {}
|
|
49
|
+
this.templateList = []
|
|
50
|
+
this.styles = false
|
|
51
|
+
|
|
52
|
+
this.lastSort = {column: 0, dir: "asc"}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
init(): Promise<void> {
|
|
56
|
+
return whenReady().then(() => {
|
|
57
|
+
this.render()
|
|
58
|
+
const smenu = new SiteMenu(this.app as any, "templates")
|
|
59
|
+
smenu.init()
|
|
60
|
+
new DocTemplatesActions(this)
|
|
61
|
+
this.menu = new OverviewMenuView(this, menuModel as any)
|
|
62
|
+
this.menu.init()
|
|
63
|
+
this.bind()
|
|
64
|
+
return this.getTemplateListData()
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
render(): void {
|
|
69
|
+
this.dom = document.createElement("body")
|
|
70
|
+
this.dom.innerHTML = baseBodyTemplate({
|
|
71
|
+
contents: "",
|
|
72
|
+
user: this.user as any,
|
|
73
|
+
hasOverview: true,
|
|
74
|
+
app: this.app as any
|
|
75
|
+
})
|
|
76
|
+
document.body = this.dom
|
|
77
|
+
ensureCSS([
|
|
78
|
+
staticUrl("css/add_remove_dialog.css"),
|
|
79
|
+
staticUrl("css/access_rights_dialog.css")
|
|
80
|
+
])
|
|
81
|
+
setDocTitle(gettext("Document Templates Overview"), this.app as any)
|
|
82
|
+
const feedbackTab = new FeedbackTab()
|
|
83
|
+
feedbackTab.init()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
onResize(): void {
|
|
87
|
+
if (!this.table) {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
this.initTable()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
initTable(): void {
|
|
94
|
+
if (this.overviewTable) {
|
|
95
|
+
this.overviewTable.destroy()
|
|
96
|
+
this.overviewTable = null
|
|
97
|
+
}
|
|
98
|
+
this.table = null
|
|
99
|
+
this.dtBulk = null
|
|
100
|
+
|
|
101
|
+
const contentsEl = this.dom.querySelector(".fw-contents") as HTMLElement
|
|
102
|
+
contentsEl.innerHTML = ""
|
|
103
|
+
|
|
104
|
+
const hiddenCols = [0]
|
|
105
|
+
|
|
106
|
+
if (window.innerWidth < 500) {
|
|
107
|
+
hiddenCols.push(1)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.overviewTable = new OverviewDataTable({
|
|
111
|
+
dom: contentsEl,
|
|
112
|
+
classes: ["fw-data-table", "fw-large"],
|
|
113
|
+
columns: [
|
|
114
|
+
{select: 0, type: "number"},
|
|
115
|
+
{select: 1, sortable: false, type: "boolean"},
|
|
116
|
+
{select: hiddenCols, hidden: true},
|
|
117
|
+
{select: 5, sortable: false},
|
|
118
|
+
{select: [this.lastSort.column], sort: this.lastSort.dir}
|
|
119
|
+
],
|
|
120
|
+
data: this.templateList.map(docTemplate =>
|
|
121
|
+
this.createTableRow(docTemplate)
|
|
122
|
+
),
|
|
123
|
+
idColumn: 0,
|
|
124
|
+
checkboxColumn: 1,
|
|
125
|
+
bulkMenu: bulkMenuModel(),
|
|
126
|
+
bulkMenuPage: this,
|
|
127
|
+
searchable: true,
|
|
128
|
+
scrollY: `${Math.max(window.innerHeight - 360, 100)}px`,
|
|
129
|
+
tabIndex: 1,
|
|
130
|
+
labels: {
|
|
131
|
+
noRows: gettext("No document templates available"),
|
|
132
|
+
noResults: gettext("No document templates found")
|
|
133
|
+
},
|
|
134
|
+
headings: [
|
|
135
|
+
"", "",
|
|
136
|
+
gettext("Title"),
|
|
137
|
+
gettext("Created"),
|
|
138
|
+
gettext("Last changed"),
|
|
139
|
+
""
|
|
140
|
+
],
|
|
141
|
+
template: (options: any, _dom: any) =>
|
|
142
|
+
`<div class='${options.classes.container}'${options.scrollY.length ? ` style='height: ${options.scrollY}; overflow-Y: auto;'` : ""}></div>
|
|
143
|
+
<div class='${options.classes.bottom}'>
|
|
144
|
+
<nav class='${options.classes.pagination}'></nav>
|
|
145
|
+
</div>`,
|
|
146
|
+
rowRender: (row: any, tr: any, _index: number) => {
|
|
147
|
+
const id = row.cells[0].data
|
|
148
|
+
const inputNode: any = {
|
|
149
|
+
nodeName: "input",
|
|
150
|
+
attributes: {
|
|
151
|
+
type: "checkbox",
|
|
152
|
+
class: "entry-select fw-check",
|
|
153
|
+
"data-id": String(id),
|
|
154
|
+
id: `template-${id}`
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (row.cells[1].data) {
|
|
158
|
+
inputNode.attributes.checked = true
|
|
159
|
+
}
|
|
160
|
+
tr.childNodes[0].childNodes = [
|
|
161
|
+
inputNode,
|
|
162
|
+
{
|
|
163
|
+
nodeName: "label",
|
|
164
|
+
attributes: {for: `template-${id}`}
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
onEnter: (row: any, _event: any) => {
|
|
169
|
+
if (this.getSelected().length > 0) {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
const rowIndex = this.table.data.data.indexOf(row)
|
|
173
|
+
const link = this.table.dom.querySelector(
|
|
174
|
+
`tr[data-index="${rowIndex}"] a`
|
|
175
|
+
)
|
|
176
|
+
if (link) {
|
|
177
|
+
link.click()
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
onDelete: (row: any) => {
|
|
181
|
+
const templateId = row.cells[0].data
|
|
182
|
+
this.mod.actions!.deleteDocTemplatesDialog([templateId])
|
|
183
|
+
}
|
|
184
|
+
} as any)
|
|
185
|
+
this.overviewTable.init()
|
|
186
|
+
this.table = this.overviewTable.table
|
|
187
|
+
this.dtBulk = this.overviewTable.dtBulk
|
|
188
|
+
|
|
189
|
+
this.table.on("datatable.sort", (column: number, dir: string) => {
|
|
190
|
+
this.lastSort = {column, dir}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
this.table.dom.focus()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
createTableRow(docTemplate: Record<string, unknown>): Array<any> {
|
|
197
|
+
return [
|
|
198
|
+
docTemplate.id,
|
|
199
|
+
false,
|
|
200
|
+
`<span class="${docTemplate.is_owner ? "fw-data-table-title " : ""}fw-inline">
|
|
201
|
+
<i class="far fa-file"></i>
|
|
202
|
+
${
|
|
203
|
+
docTemplate.is_owner
|
|
204
|
+
? `<a href='/templates/${docTemplate.id}/'>
|
|
205
|
+
${
|
|
206
|
+
(docTemplate.title as string)?.length
|
|
207
|
+
? escapeText(docTemplate.title as string)
|
|
208
|
+
: gettext("Untitled")
|
|
209
|
+
}
|
|
210
|
+
</a>`
|
|
211
|
+
: (docTemplate.title as string)?.length
|
|
212
|
+
? escapeText(docTemplate.title as string)
|
|
213
|
+
: gettext("Untitled")
|
|
214
|
+
}
|
|
215
|
+
</span>`,
|
|
216
|
+
docTemplate.added,
|
|
217
|
+
docTemplate.updated,
|
|
218
|
+
`<span class="delete-doc-template fw-inline fw-link-text" data-id="${docTemplate.id}" data-title="${escapeText((docTemplate.title as string) || "")}">
|
|
219
|
+
${docTemplate.is_owner ? '<i class="fa fa-trash-can"></i>' : ""}
|
|
220
|
+
</span>`
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
removeTableRows(ids: number[]): void {
|
|
225
|
+
const existingRows = this.table.data.data
|
|
226
|
+
.map((row: any, index: number) => {
|
|
227
|
+
const id = row.cells[0].data
|
|
228
|
+
if (ids.includes(id)) {
|
|
229
|
+
return index
|
|
230
|
+
} else {
|
|
231
|
+
return false
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
.filter((rowIndex: number | false) => rowIndex !== false)
|
|
235
|
+
|
|
236
|
+
if (existingRows.length) {
|
|
237
|
+
this.table.rows.remove(existingRows)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
addDocTemplateToTable(docTemplate: Record<string, unknown>): void {
|
|
242
|
+
this.table.insert({data: [this.createTableRow(docTemplate)]})
|
|
243
|
+
this.table.columns.sort(this.lastSort.column, this.lastSort.dir)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
getTemplateListData(): Promise<void> {
|
|
247
|
+
if (this.app.isOffline()) {
|
|
248
|
+
return this.showCached()
|
|
249
|
+
}
|
|
250
|
+
return getJson("/api/user_template_manager/list/")
|
|
251
|
+
.then((json: any) => {
|
|
252
|
+
this.updateIndexedDB(json)
|
|
253
|
+
this.initializeView(json)
|
|
254
|
+
})
|
|
255
|
+
.catch((error: Error) => {
|
|
256
|
+
if (this.app.isOffline()) {
|
|
257
|
+
return this.showCached()
|
|
258
|
+
} else {
|
|
259
|
+
addAlert("error", gettext("Document templates loading failed."))
|
|
260
|
+
throw error
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
initializeView(json: any): void {
|
|
266
|
+
if (this.app.page === this) {
|
|
267
|
+
this.templateList = json.document_templates
|
|
268
|
+
this.initTable()
|
|
269
|
+
window.scrollTo(0, 0)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
showCached(): Promise<void> {
|
|
274
|
+
return this.loaddatafromIndexedDB().then(json =>
|
|
275
|
+
this.initializeView(json)
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
loaddatafromIndexedDB(): Promise<any> {
|
|
280
|
+
return this.app.indexedDB
|
|
281
|
+
.readAllData("templates_list")
|
|
282
|
+
.then(response => ({document_templates: response}))
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
updateIndexedDB(json: any): void {
|
|
286
|
+
this.app.indexedDB.clearData("templates_list").then(() => {
|
|
287
|
+
this.app.indexedDB.insertData("templates_list", json.document_templates)
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
bind(): void {
|
|
292
|
+
this.dom.addEventListener("click", (event: Event) => {
|
|
293
|
+
const el: Record<string, any> = {}
|
|
294
|
+
switch (true) {
|
|
295
|
+
case findTarget(event, ".delete-doc-template", el): {
|
|
296
|
+
const docTemplateId = Number.parseInt(el.target.dataset.id)
|
|
297
|
+
this.mod.actions!.deleteDocTemplatesDialog([docTemplateId])
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
case findTarget(event, "a", el):
|
|
301
|
+
if (
|
|
302
|
+
el.target.hostname === window.location.hostname &&
|
|
303
|
+
(el.target.getAttribute("href") as string)[0] === "/"
|
|
304
|
+
) {
|
|
305
|
+
event.preventDefault()
|
|
306
|
+
this.app.goTo(el.target.href)
|
|
307
|
+
}
|
|
308
|
+
break
|
|
309
|
+
default:
|
|
310
|
+
break
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
getSelected(): number[] {
|
|
316
|
+
return Array.from(
|
|
317
|
+
this.dom.querySelectorAll(".entry-select:checked:not(:disabled)")
|
|
318
|
+
).map(el => Number.parseInt((el as HTMLElement).getAttribute("data-id")!))
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
close(): void {
|
|
322
|
+
if (this.table) {
|
|
323
|
+
this.table.destroy()
|
|
324
|
+
this.table = null
|
|
325
|
+
}
|
|
326
|
+
if (this.dtBulk) {
|
|
327
|
+
this.dtBulk.destroy()
|
|
328
|
+
this.dtBulk = null
|
|
329
|
+
}
|
|
330
|
+
if (this.menu) {
|
|
331
|
+
this.menu.destroy()
|
|
332
|
+
this.menu = null
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A template for the Fidus Writer document import dialog */
|
|
2
|
+
export const importFidusTemplateTemplate = (): string =>
|
|
3
|
+
`<form id="import-fidus-form" method="post" enctype="multipart/form-data" class="ajax-upload">
|
|
4
|
+
<input type="file" id="fidus-template-uploader" name="fidustemplate" accept=".fidustemplate" required />
|
|
5
|
+
<button id="import-fidus-template-btn" class="fw-button fw-light fw-large">
|
|
6
|
+
${gettext("Select a file")}
|
|
7
|
+
</button>
|
|
8
|
+
<label id="import-fidus-template-name" class="ajax-upload-label"></label>
|
|
9
|
+
</form>`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {DocxImporter as GenericDocxImporter} from "@fiduswriter/document/importer/docx"
|
|
2
|
+
import {postJson} from "fwtoolkit"
|
|
3
|
+
import {createNativeImporterBackend} from "../native/import.js"
|
|
4
|
+
|
|
5
|
+
export class DocxImporter extends GenericDocxImporter {
|
|
6
|
+
constructor(
|
|
7
|
+
file: File,
|
|
8
|
+
user: Record<string, unknown>,
|
|
9
|
+
path: string,
|
|
10
|
+
importId: string,
|
|
11
|
+
options: Record<string, unknown> = {}
|
|
12
|
+
) {
|
|
13
|
+
super(file, user as any, path, importId, {
|
|
14
|
+
getTemplate: (id: string) =>
|
|
15
|
+
postJson("/api/document/get_template/", {
|
|
16
|
+
import_id: id
|
|
17
|
+
}).then(({json}: any) => json.template),
|
|
18
|
+
nativeBackend: createNativeImporterBackend(
|
|
19
|
+
user,
|
|
20
|
+
options.e2eeOptions as any
|
|
21
|
+
),
|
|
22
|
+
e2eeOptions: options.e2eeOptions
|
|
23
|
+
} as any)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {DocxImporter} from "./import.js"
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_FW_DOCUMENT_VERSION as GENERIC_MAX_FW_DOCUMENT_VERSION,
|
|
3
|
+
MIN_FW_DOCUMENT_VERSION as GENERIC_MIN_FW_DOCUMENT_VERSION,
|
|
4
|
+
FidusFileImporter as GenericFidusFileImporter
|
|
5
|
+
} from "@fiduswriter/document/importer/native"
|
|
6
|
+
import {createNativeImporterBackend} from "./import.js"
|
|
7
|
+
|
|
8
|
+
export const MIN_FW_DOCUMENT_VERSION = GENERIC_MIN_FW_DOCUMENT_VERSION
|
|
9
|
+
export const MAX_FW_DOCUMENT_VERSION = GENERIC_MAX_FW_DOCUMENT_VERSION
|
|
10
|
+
|
|
11
|
+
export class FidusFileImporter extends GenericFidusFileImporter {
|
|
12
|
+
constructor(
|
|
13
|
+
file: File | Blob,
|
|
14
|
+
user: Record<string, unknown>,
|
|
15
|
+
path = "",
|
|
16
|
+
check = false,
|
|
17
|
+
contacts: Array<Record<string, unknown>> = [],
|
|
18
|
+
e2eeOptions: any = null
|
|
19
|
+
) {
|
|
20
|
+
super(file, user as any, path, createNativeImporterBackend(user, e2eeOptions) as any, {
|
|
21
|
+
check,
|
|
22
|
+
contacts,
|
|
23
|
+
e2eeOptions,
|
|
24
|
+
checkDocUsers: check ? checkDocUsers : undefined
|
|
25
|
+
} as any)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function checkDocUsers(
|
|
30
|
+
doc: any,
|
|
31
|
+
user: Record<string, unknown>,
|
|
32
|
+
contacts: Array<Record<string, unknown>>
|
|
33
|
+
): any {
|
|
34
|
+
Object.values(doc.comments as Record<string, any>).forEach((comment: any) => {
|
|
35
|
+
if (
|
|
36
|
+
!(
|
|
37
|
+
contacts.find(
|
|
38
|
+
(member: any) =>
|
|
39
|
+
member.id === comment.user &&
|
|
40
|
+
member.username === comment.username
|
|
41
|
+
) ||
|
|
42
|
+
(user.id === comment.user && user.username === comment.username)
|
|
43
|
+
)
|
|
44
|
+
) {
|
|
45
|
+
comment.user = 0
|
|
46
|
+
}
|
|
47
|
+
if (
|
|
48
|
+
!(
|
|
49
|
+
!comment.assignedUser ||
|
|
50
|
+
contacts.find(
|
|
51
|
+
(member: any) =>
|
|
52
|
+
member.id === comment.assignedUser &&
|
|
53
|
+
member.username === comment.assignedUsername
|
|
54
|
+
) ||
|
|
55
|
+
(user.id === comment.assignedUser &&
|
|
56
|
+
user.username === comment.assignedUsername)
|
|
57
|
+
)
|
|
58
|
+
) {
|
|
59
|
+
comment.assignedUser = 0
|
|
60
|
+
}
|
|
61
|
+
if (comment.answers) {
|
|
62
|
+
comment.answers.forEach((answer: any) => {
|
|
63
|
+
if (
|
|
64
|
+
!(
|
|
65
|
+
contacts.find(
|
|
66
|
+
(member: any) =>
|
|
67
|
+
member.id === answer.user &&
|
|
68
|
+
member.username === answer.username
|
|
69
|
+
) ||
|
|
70
|
+
(user.id === answer.user &&
|
|
71
|
+
user.username === answer.username)
|
|
72
|
+
)
|
|
73
|
+
) {
|
|
74
|
+
answer.user = 0
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
checkDocUsersNode(doc.content, user, contacts)
|
|
80
|
+
return doc
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function checkDocUsersNode(
|
|
84
|
+
node: any,
|
|
85
|
+
user: Record<string, unknown>,
|
|
86
|
+
contacts: Array<Record<string, unknown>>
|
|
87
|
+
): void {
|
|
88
|
+
if (node.marks) {
|
|
89
|
+
node.marks.forEach((mark: any) => {
|
|
90
|
+
if (["insertion", "deletion"].includes(mark.type)) {
|
|
91
|
+
if (
|
|
92
|
+
!(
|
|
93
|
+
contacts.find(
|
|
94
|
+
(member: any) =>
|
|
95
|
+
member.id === mark.attrs.user &&
|
|
96
|
+
member.username === mark.attrs.username
|
|
97
|
+
) ||
|
|
98
|
+
(user.id === mark.attrs.user &&
|
|
99
|
+
user.username === mark.attrs.username)
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
mark.attrs.user = 0
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
if (node.content) {
|
|
108
|
+
node.content.forEach((childNode: any) =>
|
|
109
|
+
checkDocUsersNode(childNode, user, contacts)
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {extractTemplate} from "@fiduswriter/document-template-editor"
|
|
2
|
+
import {NativeImporter as GenericNativeImporter} from "@fiduswriter/document/importer/native"
|
|
3
|
+
import {addAlert, postJson, shortFileTitle} from "fwtoolkit"
|
|
4
|
+
import {E2EEEncryptor} from "fwtoolkit/e2ee/encryptor"
|
|
5
|
+
import {E2EEKeyManager} from "fwtoolkit/e2ee/key-manager"
|
|
6
|
+
|
|
7
|
+
interface E2EEOptions {
|
|
8
|
+
enabled: boolean
|
|
9
|
+
key?: CryptoKey
|
|
10
|
+
salt?: string
|
|
11
|
+
iterations?: number
|
|
12
|
+
sourceKey?: CryptoKey
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface CreateDocResult {
|
|
16
|
+
id: number
|
|
17
|
+
path: string
|
|
18
|
+
e2ee: boolean
|
|
19
|
+
template: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface SaveDataResult {
|
|
23
|
+
added: number
|
|
24
|
+
updated: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ImageTranslationTable {
|
|
28
|
+
[oldId: string]: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createNativeImporterBackend(
|
|
32
|
+
_user: Record<string, unknown>,
|
|
33
|
+
_e2eeOptions: E2EEOptions | null
|
|
34
|
+
): {
|
|
35
|
+
createDoc: (
|
|
36
|
+
template: any,
|
|
37
|
+
importId: string | null,
|
|
38
|
+
path: string,
|
|
39
|
+
e2ee: E2EEOptions | null,
|
|
40
|
+
files: Record<string, unknown>
|
|
41
|
+
) => Promise<CreateDocResult>
|
|
42
|
+
saveImages: (
|
|
43
|
+
images: {db: Record<string, any>},
|
|
44
|
+
docId: number,
|
|
45
|
+
e2ee: E2EEOptions | null
|
|
46
|
+
) => Promise<ImageTranslationTable>
|
|
47
|
+
saveDocument: (saveData: any, e2ee: E2EEOptions | null) => Promise<SaveDataResult>
|
|
48
|
+
extractTemplate: typeof extractTemplate
|
|
49
|
+
encryptImage: typeof E2EEEncryptor.encryptImage
|
|
50
|
+
encryptObject: typeof E2EEEncryptor.encryptObject
|
|
51
|
+
encrypt: typeof E2EEEncryptor.encrypt
|
|
52
|
+
storeKeyInSession: typeof E2EEKeyManager.storeKeyInSession
|
|
53
|
+
} {
|
|
54
|
+
return {
|
|
55
|
+
createDoc: (template, importId, path, e2ee, files) => {
|
|
56
|
+
const jsonData: Record<string, unknown> = {
|
|
57
|
+
template: template.content,
|
|
58
|
+
export_templates: template.exportTemplates,
|
|
59
|
+
document_styles: template.documentStyles,
|
|
60
|
+
import_id: importId
|
|
61
|
+
? importId
|
|
62
|
+
: template.content.attrs.import_id,
|
|
63
|
+
template_title: template.content.attrs.template,
|
|
64
|
+
path
|
|
65
|
+
}
|
|
66
|
+
if (e2ee?.enabled) {
|
|
67
|
+
jsonData.e2ee = true
|
|
68
|
+
if (e2ee.salt) {
|
|
69
|
+
jsonData.e2ee_salt = e2ee.salt
|
|
70
|
+
}
|
|
71
|
+
if (e2ee.iterations) {
|
|
72
|
+
jsonData.e2ee_iterations = e2ee.iterations
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return postJson("/api/document/import/create/", jsonData, files as any)
|
|
76
|
+
.then(({json}: any) => ({
|
|
77
|
+
id: json.id,
|
|
78
|
+
path: json.path,
|
|
79
|
+
e2ee: json.e2ee,
|
|
80
|
+
template: json.template
|
|
81
|
+
}))
|
|
82
|
+
.catch((error: Error) => {
|
|
83
|
+
addAlert("error", gettext("Could not create document"))
|
|
84
|
+
throw error
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
saveImages: async (images, docId, e2ee) => {
|
|
88
|
+
const isE2EE = e2ee?.enabled
|
|
89
|
+
const endpoint = isE2EE
|
|
90
|
+
? "/api/document/e2ee_image/"
|
|
91
|
+
: "/api/document/import/image/"
|
|
92
|
+
const ImageTranslationTable: ImageTranslationTable = {}
|
|
93
|
+
await Promise.all(
|
|
94
|
+
Object.values(images.db as Record<string, any>).map(async (imageEntry: any) => {
|
|
95
|
+
await maybeDecryptImage(imageEntry, e2ee?.sourceKey)
|
|
96
|
+
const encryptedFile =
|
|
97
|
+
e2ee?.enabled && e2ee.key
|
|
98
|
+
? await E2EEEncryptor.encryptImage(
|
|
99
|
+
imageEntry.file,
|
|
100
|
+
e2ee.key
|
|
101
|
+
)
|
|
102
|
+
: imageEntry.file
|
|
103
|
+
const jsonData = {
|
|
104
|
+
doc_id: docId,
|
|
105
|
+
title: imageEntry.title,
|
|
106
|
+
copyright: imageEntry.copyright,
|
|
107
|
+
checksum: imageEntry.checksum
|
|
108
|
+
}
|
|
109
|
+
const files = {
|
|
110
|
+
image: {
|
|
111
|
+
file: encryptedFile,
|
|
112
|
+
filename: imageEntry.image.split("/").pop()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const {json}: any = await postJson(endpoint, jsonData, files as any)
|
|
116
|
+
ImageTranslationTable[imageEntry.id] = json.id
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
return ImageTranslationTable
|
|
120
|
+
},
|
|
121
|
+
saveDocument: async (saveData, e2ee) => {
|
|
122
|
+
if (e2ee?.enabled && e2ee.key) {
|
|
123
|
+
saveData.content = await E2EEEncryptor.encryptObject(
|
|
124
|
+
saveData.content,
|
|
125
|
+
e2ee.key
|
|
126
|
+
)
|
|
127
|
+
saveData.comments = await E2EEEncryptor.encryptObject(
|
|
128
|
+
saveData.comments || {},
|
|
129
|
+
e2ee.key
|
|
130
|
+
)
|
|
131
|
+
saveData.bibliography = await E2EEEncryptor.encryptObject(
|
|
132
|
+
saveData.bibliography,
|
|
133
|
+
e2ee.key
|
|
134
|
+
)
|
|
135
|
+
saveData.title = await E2EEEncryptor.encrypt(
|
|
136
|
+
saveData.title,
|
|
137
|
+
e2ee.key
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
return postJson("/api/document/import/", saveData)
|
|
141
|
+
.then(({json}: any) => ({added: json.added, updated: json.updated}))
|
|
142
|
+
.catch((error: Error) => {
|
|
143
|
+
addAlert(
|
|
144
|
+
"error",
|
|
145
|
+
`${gettext("Could not save ")} ${shortFileTitle(
|
|
146
|
+
saveData.title,
|
|
147
|
+
""
|
|
148
|
+
)}`
|
|
149
|
+
)
|
|
150
|
+
throw error
|
|
151
|
+
})
|
|
152
|
+
},
|
|
153
|
+
extractTemplate,
|
|
154
|
+
encryptImage: E2EEEncryptor.encryptImage.bind(E2EEEncryptor),
|
|
155
|
+
encryptObject: E2EEEncryptor.encryptObject.bind(E2EEEncryptor),
|
|
156
|
+
encrypt: E2EEEncryptor.encrypt.bind(E2EEEncryptor),
|
|
157
|
+
storeKeyInSession: E2EEKeyManager.storeKeyInSession.bind(E2EEKeyManager)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export class NativeImporter extends GenericNativeImporter {
|
|
162
|
+
constructor(
|
|
163
|
+
doc: any,
|
|
164
|
+
bibliography: any,
|
|
165
|
+
images: any,
|
|
166
|
+
otherFiles: any,
|
|
167
|
+
user: Record<string, unknown>,
|
|
168
|
+
importId: string | null = null,
|
|
169
|
+
requestedPath = "",
|
|
170
|
+
template: any = null,
|
|
171
|
+
e2eeOptions: E2EEOptions | null = null
|
|
172
|
+
) {
|
|
173
|
+
super(
|
|
174
|
+
doc,
|
|
175
|
+
bibliography,
|
|
176
|
+
images,
|
|
177
|
+
otherFiles,
|
|
178
|
+
user as any,
|
|
179
|
+
createNativeImporterBackend(user, e2eeOptions) as any,
|
|
180
|
+
{
|
|
181
|
+
importId,
|
|
182
|
+
requestedPath,
|
|
183
|
+
template,
|
|
184
|
+
e2eeOptions
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function maybeDecryptImage(
|
|
191
|
+
imageEntry: any,
|
|
192
|
+
sourceKey: CryptoKey | undefined
|
|
193
|
+
): Promise<void> {
|
|
194
|
+
if (!sourceKey || !imageEntry.file) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
if (imageEntry.file_type !== "application/octet-stream") {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
const fileBuffer = await imageEntry.file.arrayBuffer()
|
|
201
|
+
const bytes = new Uint8Array(fileBuffer)
|
|
202
|
+
let binary = ""
|
|
203
|
+
const chunkSize = 65536
|
|
204
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
205
|
+
const chunk = bytes.subarray(i, i + chunkSize)
|
|
206
|
+
binary += String.fromCharCode.apply(null, Array.from(chunk))
|
|
207
|
+
}
|
|
208
|
+
const base64 = btoa(binary)
|
|
209
|
+
const decrypted = await E2EEEncryptor.decryptBufferToBase64(base64, sourceKey)
|
|
210
|
+
const mime = imageEntry.original_file_type || "image/png"
|
|
211
|
+
const byteCharacters = atob(decrypted)
|
|
212
|
+
const byteNumbers = new Array(byteCharacters.length)
|
|
213
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
214
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i)
|
|
215
|
+
}
|
|
216
|
+
const byteArray = new Uint8Array(byteNumbers)
|
|
217
|
+
imageEntry.file = new Blob([byteArray], {type: mime})
|
|
218
|
+
imageEntry.file_type = mime
|
|
219
|
+
}
|