@axium/office 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +157 -0
- package/README.md +50 -2
- package/assets/blank.docx +0 -0
- package/assets/blank.pptx +0 -0
- package/assets/blank.xlsx +0 -0
- package/assets/documentserver.json +11 -0
- package/dist/.locale.js +1 -0
- package/dist/common.js +71 -0
- package/dist/server/cli.js +14 -0
- package/dist/server/documentserver.js +211 -0
- package/locales/en.json +38 -0
- package/package.json +70 -5
- package/routes/office/+layout.svelte +10 -0
- package/routes/office/+layout.ts +16 -0
- package/routes/office/+page.svelte +90 -0
- package/routes/office/+page.ts +14 -0
- package/routes/office/DocumentCard.svelte +153 -0
- package/routes/office/[id]/+page.svelte +126 -0
- package/routes/office/[id]/+page.ts +6 -0
- package/routes/office/[id]/Editor.svelte +73 -0
- package/routes/tsconfig.json +14 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
6
|
+
<https://fsf.org/>
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
9
|
+
license document, but changing it is not allowed.
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
|
13
|
+
supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
## 0. Additional Definitions.
|
|
16
|
+
|
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
|
19
|
+
GNU General Public License.
|
|
20
|
+
|
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
|
22
|
+
than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
|
32
|
+
Version".
|
|
33
|
+
|
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
## 2. Conveying Modified Versions.
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
|
58
|
+
to ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from a
|
|
67
|
+
header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
|
74
|
+
the Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
|
77
|
+
license document.
|
|
78
|
+
|
|
79
|
+
## 4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
|
82
|
+
together, effectively do not restrict modification of the portions of
|
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
|
84
|
+
debugging such modifications, if you also do each of the following:
|
|
85
|
+
|
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
|
87
|
+
the Library is used in it and that the Library and its use are
|
|
88
|
+
covered by this License.
|
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
|
90
|
+
license document.
|
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
|
92
|
+
execution, include the copyright notice for the Library among
|
|
93
|
+
these notices, as well as a reference directing the user to the
|
|
94
|
+
copies of the GNU GPL and this license document.
|
|
95
|
+
- d) Do one of the following:
|
|
96
|
+
- 0) Convey the Minimal Corresponding Source under the terms of
|
|
97
|
+
this License, and the Corresponding Application Code in a form
|
|
98
|
+
suitable for, and under terms that permit, the user to
|
|
99
|
+
recombine or relink the Application with a modified version of
|
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
102
|
+
Corresponding Source.
|
|
103
|
+
- 1) Use a suitable shared library mechanism for linking with
|
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
|
105
|
+
time a copy of the Library already present on the user's
|
|
106
|
+
computer system, and (b) will operate properly with a modified
|
|
107
|
+
version of the Library that is interface-compatible with the
|
|
108
|
+
Linked Version.
|
|
109
|
+
- e) Provide Installation Information, but only if you would
|
|
110
|
+
otherwise be required to provide such information under section 6
|
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
|
112
|
+
necessary to install and execute a modified version of the
|
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
|
119
|
+
Corresponding Source.)
|
|
120
|
+
|
|
121
|
+
## 5. Combined Libraries.
|
|
122
|
+
|
|
123
|
+
You may place library facilities that are a work based on the Library
|
|
124
|
+
side by side in a single library together with other library
|
|
125
|
+
facilities that are not Applications and are not covered by this
|
|
126
|
+
License, and convey such a combined library under terms of your
|
|
127
|
+
choice, if you do both of the following:
|
|
128
|
+
|
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
|
130
|
+
based on the Library, uncombined with any other library
|
|
131
|
+
facilities, conveyed under the terms of this License.
|
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
|
133
|
+
is a work based on the Library, and explaining where to find the
|
|
134
|
+
accompanying uncombined form of the same work.
|
|
135
|
+
|
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
|
137
|
+
|
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
140
|
+
versions will be similar in spirit to the present version, but may
|
|
141
|
+
differ in detail to address new problems or concerns.
|
|
142
|
+
|
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
|
144
|
+
as you received it specifies that a certain numbered version of the
|
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
|
146
|
+
it, you have the option of following the terms and conditions either
|
|
147
|
+
of that published version or of any later version published by the
|
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
|
151
|
+
published by the Free Software Foundation.
|
|
152
|
+
|
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
156
|
+
permanent authorization for you to choose that version for the
|
|
157
|
+
Library.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Axium Office
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This is a plugin for editing office documents (docx, xlsx, pptx, odt, ods, odp) stored in Axium's Files, in the browser.
|
|
4
|
+
Editing happens using any document server which supports the OnlyOffice Docs API, like [Euro-Office](https://github.com/euro-office).
|
|
5
|
+
|
|
6
|
+
## Deploying the document server
|
|
7
|
+
|
|
8
|
+
Axium patches the document server for better theming and other UX:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
axium office patch-image # tags axium-documentserver
|
|
12
|
+
axium office patch-image --tag documents:9.3.8 ghcr.io/euro-office/documentserver:v9.3.8
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then run it. This example is for Docker Compose:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
services:
|
|
19
|
+
documentserver:
|
|
20
|
+
image: axium-documentserver
|
|
21
|
+
restart: unless-stopped
|
|
22
|
+
ports:
|
|
23
|
+
- 127.0.0.1:8080:80
|
|
24
|
+
environment:
|
|
25
|
+
JWT_SECRET: ${OFFICE_SECRET} # the plugin's `secret`
|
|
26
|
+
volumes:
|
|
27
|
+
- ./documentserver/data:/var/www/euro-office/Data
|
|
28
|
+
- ./documentserver/logs:/var/log/euro-office/documentserver
|
|
29
|
+
- ./documentserver/cache:/var/lib/euro-office/documentserver
|
|
30
|
+
- ./documentserver/database:/var/lib/postgresql
|
|
31
|
+
- ./fonts:/usr/share/fonts/truetype/custom:ro
|
|
32
|
+
# Only if `internal_url` points at this host rather than Axium's public origin
|
|
33
|
+
# extra_hosts:
|
|
34
|
+
# - host.docker.internal:host-gateway
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **Secret:** `JWT_SECRET` must equal the plugin's `secret`. Generate one with `openssl rand -hex 32`.
|
|
38
|
+
- **Volumes:**
|
|
39
|
+
- `Data` holds the server's generated secrets.
|
|
40
|
+
- `cache` holds the files of open sessions.
|
|
41
|
+
- `database` holds the session state that lets editing survive a restart.
|
|
42
|
+
- `logs` is for troubleshooting.
|
|
43
|
+
- **Fonts:** fonts in `/usr/share/fonts/truetype/custom` are indexed when the container starts. Documents whose fonts are missing are laid out with substitutes, so lines and pages break differently; e.g. Palatino Linotype is not included. Add the fonts your documents use (licensed copies, or metric-compatible ones such as TeX Gyre Pagella or URW P052 for Palatino).
|
|
44
|
+
- **Autosave:** the image saves open documents with changes every 5 minutes, not only when the last editor closes or someone presses Save.
|
|
45
|
+
|
|
46
|
+
### TLS and URLs
|
|
47
|
+
|
|
48
|
+
- **Cloudflare Tunnel:** route a hostname such as `documents.example.com` to `http://localhost:8080` and set `server_url` to `https://documents.example.com`. TLS ends at Cloudflare, and the container serves plain HTTP. The tunnel forwards `X-Forwarded-Proto: https` and the public `Host`, which the server uses for the absolute URLs it generates, so no setting is needed.
|
|
49
|
+
- **Other reverse proxies** must forward `Host` (or `X-Forwarded-Host`) and `X-Forwarded-Proto`. To serve the server under a path, the proxy strips the path and sends it as `X-Forwarded-Prefix`, and `server_url` includes it. A hostname of its own is simpler.
|
|
50
|
+
- **TLS in the container:** mount a certificate and key, set `SSL_CERTIFICATE_PATH` and `SSL_KEY_PATH` to their paths, and publish port 443, e.g. `8443:443` for the default `server_url`.
|
|
51
|
+
- **`internal_url`:** the container can reach Axium through its public origin, the default, which goes through the tunnel and needs no host mapping. Or it can use a local address, e.g. `https://host.docker.internal` with the `extra_hosts` entry above. That address needs a certificate the server trusts, or set `USE_UNAUTHORIZED_STORAGE=true`. Local Axium addresses also need `ALLOW_PRIVATE_IP_ADDRESS=true`.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/.locale.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { $API, serverConfigs } from '@axium/core';
|
|
2
|
+
import { StorageItemMetadata } from '@axium/storage/common';
|
|
3
|
+
import * as locales from '@james-pre/locales';
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
export const kinds = ['document', 'spreadsheet', 'presentation'];
|
|
6
|
+
export const Kind = z.literal(kinds);
|
|
7
|
+
export const formats = [
|
|
8
|
+
{ extension: 'docx', type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', kind: 'document' },
|
|
9
|
+
{ extension: 'xlsx', type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', kind: 'spreadsheet' },
|
|
10
|
+
{ extension: 'pptx', type: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', kind: 'presentation' },
|
|
11
|
+
{ extension: 'odt', type: 'application/vnd.oasis.opendocument.text', kind: 'document' },
|
|
12
|
+
{ extension: 'ods', type: 'application/vnd.oasis.opendocument.spreadsheet', kind: 'spreadsheet' },
|
|
13
|
+
{ extension: 'odp', type: 'application/vnd.oasis.opendocument.presentation', kind: 'presentation' },
|
|
14
|
+
];
|
|
15
|
+
/** The format new documents of each kind are created in */
|
|
16
|
+
export const newFormats = {
|
|
17
|
+
document: formats[0],
|
|
18
|
+
spreadsheet: formats[1],
|
|
19
|
+
presentation: formats[2],
|
|
20
|
+
};
|
|
21
|
+
export const icons = {
|
|
22
|
+
document: 'file-word',
|
|
23
|
+
spreadsheet: 'file-excel',
|
|
24
|
+
presentation: 'file-powerpoint',
|
|
25
|
+
};
|
|
26
|
+
/** Matches by MIME type first, since browsers set it on upload, then by extension */
|
|
27
|
+
export function formatOf(item) {
|
|
28
|
+
const name = item.name.toLowerCase();
|
|
29
|
+
return formats.find(format => format.type == item.type) ?? formats.find(format => name.endsWith('.' + format.extension));
|
|
30
|
+
}
|
|
31
|
+
export const Config = z
|
|
32
|
+
.object({
|
|
33
|
+
/** Where browsers reach the document server */
|
|
34
|
+
server_url: z.url().nullish(),
|
|
35
|
+
/** Where the document server reaches Axium */
|
|
36
|
+
internal_url: z.url().nullish(),
|
|
37
|
+
/** The document server's JWT secret */
|
|
38
|
+
secret: z.string().register(locales.zod, { secret: true }),
|
|
39
|
+
})
|
|
40
|
+
.register(locales.zod, { prefix: 'office.config' });
|
|
41
|
+
serverConfigs.set('@axium/office', Config);
|
|
42
|
+
export const EditorOptions = z.object({
|
|
43
|
+
mobile: z.boolean(),
|
|
44
|
+
});
|
|
45
|
+
export const Editor = z.object({
|
|
46
|
+
/** The document server */
|
|
47
|
+
url: z.url(),
|
|
48
|
+
/** The signed `DocsAPI.DocEditor` configuration */
|
|
49
|
+
config: z.record(z.string(), z.unknown()),
|
|
50
|
+
});
|
|
51
|
+
export const EditorSession = z.object({
|
|
52
|
+
item: StorageItemMetadata,
|
|
53
|
+
readOnly: z.boolean(),
|
|
54
|
+
canRename: z.boolean(),
|
|
55
|
+
editor: Editor,
|
|
56
|
+
});
|
|
57
|
+
export const NewDocument = z.object({
|
|
58
|
+
kind: Kind,
|
|
59
|
+
/** Without the extension, which is added */
|
|
60
|
+
name: z.string().trim().nonempty().max(250),
|
|
61
|
+
parentId: z.uuid().nullish(),
|
|
62
|
+
});
|
|
63
|
+
const OfficeAPI = {
|
|
64
|
+
office: {
|
|
65
|
+
PUT: [NewDocument, StorageItemMetadata],
|
|
66
|
+
},
|
|
67
|
+
'office/:id': {
|
|
68
|
+
GET: [EditorOptions, EditorSession],
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
Object.assign($API, OfficeAPI);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import * as io from 'ioium/node';
|
|
3
|
+
import { buildImage, defaultBase, detectEngine } from './image.js';
|
|
4
|
+
const cli = program.command('office').helpGroup('Plugins:').description('CLI integration for @axium/office');
|
|
5
|
+
cli.command('patch-image')
|
|
6
|
+
.description("Build the document server image: Euro-Office patched for Axium, with Axium's themes")
|
|
7
|
+
.argument('[base]', 'the Euro-Office image to patch', defaultBase)
|
|
8
|
+
.option('--engine <engine>', 'the container engine, docker or podman (default: whichever is installed)')
|
|
9
|
+
.option('--tag <tag>', 'the tag of the built image', 'axium-documentserver')
|
|
10
|
+
.option('--context <directory>', 'keep the build context in this directory, which is replaced (default: a temporary directory)')
|
|
11
|
+
.action((base, options) => {
|
|
12
|
+
const engine = options.engine ?? detectEngine();
|
|
13
|
+
io.track(`Building ${options.tag} from ${base} with ${engine}`, () => buildImage({ base, engine, tag: options.tag, context: options.context }));
|
|
14
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { getConfig } from '@axium/core';
|
|
2
|
+
import feature from '@axium/core/features';
|
|
3
|
+
import serverConfig from '@axium/server/config';
|
|
4
|
+
import { error, json, withError } from '@axium/server/requests';
|
|
5
|
+
import { addRoute } from '@axium/server/routes';
|
|
6
|
+
import { streamRead } from '@axium/storage/node';
|
|
7
|
+
import { getLimits } from '@axium/storage/server/config';
|
|
8
|
+
import { get, getUserStats } from '@axium/storage/server/db';
|
|
9
|
+
import { finishItemUpdate } from '@axium/storage/server/item';
|
|
10
|
+
import * as io from 'ioium';
|
|
11
|
+
import { createHash } from 'node:crypto';
|
|
12
|
+
import { writeFileSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import * as z from 'zod';
|
|
15
|
+
import * as jwt from './jwt.js';
|
|
16
|
+
const documentTypes = {
|
|
17
|
+
document: 'word',
|
|
18
|
+
spreadsheet: 'cell',
|
|
19
|
+
presentation: 'slide',
|
|
20
|
+
};
|
|
21
|
+
/** Where browsers reach the document server, which defaults to port 8443 on the host of Axium's origin */
|
|
22
|
+
function serverURL() {
|
|
23
|
+
const { server_url } = getConfig('@axium/office');
|
|
24
|
+
if (server_url)
|
|
25
|
+
return new URL(server_url);
|
|
26
|
+
const { protocol, hostname } = new URL(serverConfig.origin);
|
|
27
|
+
return new URL(`${protocol}//${hostname}:8443`);
|
|
28
|
+
}
|
|
29
|
+
/** Where the document server reaches Axium */
|
|
30
|
+
function internalURL() {
|
|
31
|
+
return getConfig('@axium/office').internal_url ?? serverConfig.origin;
|
|
32
|
+
}
|
|
33
|
+
function secret() {
|
|
34
|
+
const { secret } = getConfig('@axium/office');
|
|
35
|
+
if (!secret)
|
|
36
|
+
error(503, 'Office is not configured: set the document server secret');
|
|
37
|
+
return secret;
|
|
38
|
+
}
|
|
39
|
+
/** The document server signs its requests to Axium into the `Authorization` header, or the body if it is configured to */
|
|
40
|
+
function verifySignature(request, body) {
|
|
41
|
+
const header = request.headers.get('Authorization')?.replace(/^Bearer /i, '');
|
|
42
|
+
const token = typeof body?.token == 'string' ? body.token : header;
|
|
43
|
+
const claims = token && jwt.verify(token, secret());
|
|
44
|
+
if (!claims)
|
|
45
|
+
error(401, 'Invalid document server token');
|
|
46
|
+
return claims.payload ?? claims;
|
|
47
|
+
}
|
|
48
|
+
/** Route parameters are only parsed for API routes, so other routes check the ID themselves */
|
|
49
|
+
function itemIdFrom({ id }) {
|
|
50
|
+
const result = z.uuid().safeParse(id);
|
|
51
|
+
if (!result.success)
|
|
52
|
+
error(400, 'Invalid item ID');
|
|
53
|
+
return result.data;
|
|
54
|
+
}
|
|
55
|
+
/** An item the document server may open: it exists, is not trashed, and is not a directory */
|
|
56
|
+
export async function getItem(itemId) {
|
|
57
|
+
const item = await get(itemId).catch(withError('Could not find the item'));
|
|
58
|
+
if (item.trashedAt)
|
|
59
|
+
error(410, 'Trashed items can not be opened');
|
|
60
|
+
if (item.type == 'inode/directory')
|
|
61
|
+
error(409, 'Directories do not have content');
|
|
62
|
+
return item;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Co-editing sessions that have force-saved, by item ID.
|
|
66
|
+
* A force save changes the item but not the session, so new editors must still get the session's key.
|
|
67
|
+
* This is held in memory, so a restart during such a session gives new editors a separate session.
|
|
68
|
+
*/
|
|
69
|
+
const sessions = new Map();
|
|
70
|
+
/** Unique per item version, and at most 128 characters of `[0-9a-zA-Z.=_-]` */
|
|
71
|
+
function versionKey(item) {
|
|
72
|
+
const version = createHash('sha256').update(`${item.hash}:${item.modifiedAt.getTime()}`).digest('hex');
|
|
73
|
+
return `${item.id}-${version.slice(0, 32)}`;
|
|
74
|
+
}
|
|
75
|
+
function documentKey(item) {
|
|
76
|
+
const session = sessions.get(item.id);
|
|
77
|
+
return session && session.hash == item.hash ? session.key : versionKey(item);
|
|
78
|
+
}
|
|
79
|
+
/** Everything the browser needs to open `item` in the document server's editor */
|
|
80
|
+
export function editorFor({ item, format, user, canWrite, options }) {
|
|
81
|
+
const theme = feature('themes') ? user.preferences.theme : 'default';
|
|
82
|
+
const config = {
|
|
83
|
+
type: options.mobile ? 'mobile' : 'desktop',
|
|
84
|
+
documentType: documentTypes[format.kind],
|
|
85
|
+
document: {
|
|
86
|
+
fileType: format.extension,
|
|
87
|
+
key: documentKey(item),
|
|
88
|
+
title: item.name,
|
|
89
|
+
url: new URL(`/raw/office/${item.id}/content`, internalURL()).href,
|
|
90
|
+
permissions: { edit: canWrite },
|
|
91
|
+
},
|
|
92
|
+
editorConfig: {
|
|
93
|
+
mode: canWrite ? 'edit' : 'view',
|
|
94
|
+
callbackUrl: new URL(`/raw/office/${item.id}/callback`, internalURL()).href,
|
|
95
|
+
user: { id: user.id, name: user.name },
|
|
96
|
+
customization: {
|
|
97
|
+
compactHeader: true,
|
|
98
|
+
toolbarHideFileName: true,
|
|
99
|
+
forcesave: true,
|
|
100
|
+
uiTheme: `theme-axium-${theme}`,
|
|
101
|
+
logo: { visible: false },
|
|
102
|
+
layout: { header: { user: false } },
|
|
103
|
+
feedback: false,
|
|
104
|
+
suggestFeature: false,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
return { url: serverURL().href, config: { ...config, token: jwt.sign(config, secret()) } };
|
|
109
|
+
}
|
|
110
|
+
const ContentRequest = z.looseObject({ url: z.url() });
|
|
111
|
+
addRoute({
|
|
112
|
+
path: '/raw/office/:id/content',
|
|
113
|
+
params: { id: z.uuid() },
|
|
114
|
+
async GET(request, params) {
|
|
115
|
+
const itemId = itemIdFrom(params);
|
|
116
|
+
const signed = ContentRequest.safeParse(verifySignature(request));
|
|
117
|
+
if (!signed.success || new URL(signed.data.url).pathname != new URL(request.url).pathname)
|
|
118
|
+
error(403, 'This token is for another document');
|
|
119
|
+
const item = await getItem(itemId);
|
|
120
|
+
if (!item.size)
|
|
121
|
+
return null;
|
|
122
|
+
return new Response(streamRead(join(getConfig('@axium/storage').data, item.id)), {
|
|
123
|
+
headers: { 'Content-Type': 'application/octet-stream', 'Content-Length': String(item.size) },
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
/** The document server only offers saved documents from itself, so this refuses to download from anywhere else */
|
|
128
|
+
async function save(itemId, location) {
|
|
129
|
+
const url = new URL(location);
|
|
130
|
+
const server = serverURL();
|
|
131
|
+
url.protocol = server.protocol;
|
|
132
|
+
url.host = server.host;
|
|
133
|
+
const response = await fetch(url);
|
|
134
|
+
if (!response.ok)
|
|
135
|
+
throw new Error(`${url.origin} responded with ${response.status}`);
|
|
136
|
+
const content = await response.bytes();
|
|
137
|
+
const item = await getItem(itemId);
|
|
138
|
+
if (item.immutable)
|
|
139
|
+
error(405, 'Item is immutable');
|
|
140
|
+
const size = BigInt(content.byteLength);
|
|
141
|
+
const [usage, limits] = await Promise.all([getUserStats(item.userId), getLimits(item.userId)]).catch(withError('Could not fetch usage and/or limits'));
|
|
142
|
+
if (limits.user_size && (usage.usedBytes + size - item.size) / 1000000n >= limits.user_size)
|
|
143
|
+
error(413, 'Not enough space');
|
|
144
|
+
if (limits.item_size && content.byteLength > limits.item_size * 1_000_000)
|
|
145
|
+
error(413, 'File size exceeds maximum size');
|
|
146
|
+
const hash = createHash('BLAKE2b512').update(content).digest();
|
|
147
|
+
return await finishItemUpdate(itemId, size, hash, path => writeFileSync(path, content));
|
|
148
|
+
}
|
|
149
|
+
function endSession(itemId, key) {
|
|
150
|
+
if (sessions.get(itemId)?.key == key)
|
|
151
|
+
sessions.delete(itemId);
|
|
152
|
+
}
|
|
153
|
+
const Callback = z.looseObject({
|
|
154
|
+
key: z.string(),
|
|
155
|
+
status: z.int(),
|
|
156
|
+
url: z.url().optional(),
|
|
157
|
+
});
|
|
158
|
+
var Status;
|
|
159
|
+
(function (Status) {
|
|
160
|
+
Status[Status["ReadyForSaving"] = 2] = "ReadyForSaving";
|
|
161
|
+
Status[Status["SaveFailed"] = 3] = "SaveFailed";
|
|
162
|
+
Status[Status["ClosedUnchanged"] = 4] = "ClosedUnchanged";
|
|
163
|
+
Status[Status["ForceSaved"] = 6] = "ForceSaved";
|
|
164
|
+
Status[Status["ForceSaveFailed"] = 7] = "ForceSaveFailed";
|
|
165
|
+
})(Status || (Status = {}));
|
|
166
|
+
async function handleCallback(itemId, callback) {
|
|
167
|
+
switch (callback.status) {
|
|
168
|
+
case Status.ReadyForSaving:
|
|
169
|
+
if (!callback.url)
|
|
170
|
+
error(400, 'Missing document URL');
|
|
171
|
+
await save(itemId, callback.url);
|
|
172
|
+
endSession(itemId, callback.key);
|
|
173
|
+
return;
|
|
174
|
+
case Status.ForceSaved: {
|
|
175
|
+
if (!callback.url)
|
|
176
|
+
error(400, 'Missing document URL');
|
|
177
|
+
const saved = await save(itemId, callback.url);
|
|
178
|
+
sessions.set(itemId, { key: callback.key, hash: saved.hash });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
case Status.ClosedUnchanged:
|
|
182
|
+
endSession(itemId, callback.key);
|
|
183
|
+
return;
|
|
184
|
+
case Status.SaveFailed:
|
|
185
|
+
case Status.ForceSaveFailed:
|
|
186
|
+
io.warn(`The document server could not save ${itemId} (status ${callback.status})`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
addRoute({
|
|
191
|
+
path: '/raw/office/:id/callback',
|
|
192
|
+
params: { id: z.uuid() },
|
|
193
|
+
async POST(request, params) {
|
|
194
|
+
const itemId = itemIdFrom(params);
|
|
195
|
+
const body = await request.json().catch(() => error(400, 'Invalid JSON in request body'));
|
|
196
|
+
const parsed = Callback.safeParse(verifySignature(request, body));
|
|
197
|
+
if (!parsed.success)
|
|
198
|
+
error(400, 'Invalid callback');
|
|
199
|
+
const callback = parsed.data;
|
|
200
|
+
if (!callback.key.startsWith(itemId + '-'))
|
|
201
|
+
error(403, 'This callback is for another document');
|
|
202
|
+
try {
|
|
203
|
+
await handleCallback(itemId, callback);
|
|
204
|
+
return json({ error: 0 });
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
io.error(`Document server callback for ${itemId} failed: ${io.errorText(e)}`);
|
|
208
|
+
return json({ error: 1 });
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
});
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app_name": {
|
|
3
|
+
"office": "Office"
|
|
4
|
+
},
|
|
5
|
+
"office": {
|
|
6
|
+
"config": {
|
|
7
|
+
"server_url": "Document server URL for browsers",
|
|
8
|
+
"internal_url": "Axium URL for the document server",
|
|
9
|
+
"secret": "Document server JWT secret"
|
|
10
|
+
},
|
|
11
|
+
"new": "New",
|
|
12
|
+
"kind": {
|
|
13
|
+
"document": "Document",
|
|
14
|
+
"spreadsheet": "Spreadsheet",
|
|
15
|
+
"presentation": "Presentation"
|
|
16
|
+
},
|
|
17
|
+
"untitled": {
|
|
18
|
+
"document": "Untitled document",
|
|
19
|
+
"spreadsheet": "Untitled spreadsheet",
|
|
20
|
+
"presentation": "Untitled presentation"
|
|
21
|
+
},
|
|
22
|
+
"empty": "No documents yet. Create one with New, or upload a .docx, .xlsx or .pptx file in Files.",
|
|
23
|
+
"shared": "Shared with you",
|
|
24
|
+
"modified": "Modified {date}",
|
|
25
|
+
"actions": "Actions for {name}",
|
|
26
|
+
"open": "Open",
|
|
27
|
+
"open_new_tab": "Open in new tab",
|
|
28
|
+
"download": "Download",
|
|
29
|
+
"trash": "Move to trash",
|
|
30
|
+
"renamed": "Renamed",
|
|
31
|
+
"trashed": "Moved to trash",
|
|
32
|
+
"read_only": "Read only",
|
|
33
|
+
"opening": "Opening {name}",
|
|
34
|
+
"failed": "The editor could not open this document.",
|
|
35
|
+
"back": "Back to documents",
|
|
36
|
+
"trust_hint": "If the document server uses a self-signed certificate, open it once and accept the certificate:"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@axium/office",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "James Prevett <axium@jamespre.dev>",
|
|
5
|
+
"description": "Office documents for Axium, edited with Euro-Office or OnlyOffice",
|
|
6
|
+
"funding": {
|
|
7
|
+
"type": "individual",
|
|
8
|
+
"url": "https://github.com/sponsors/james-pre"
|
|
9
|
+
},
|
|
10
|
+
"license": "LGPL-3.0-or-later",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/james-pre/axium.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/james-pre/axium#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/james-pre/axium/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./dist/index.js",
|
|
24
|
+
"./*": "./dist/*.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"assets",
|
|
28
|
+
"dist",
|
|
29
|
+
"routes",
|
|
30
|
+
"locales"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@axium/client": ">=0.43.0",
|
|
37
|
+
"@axium/core": ">=0.46.0",
|
|
38
|
+
"@axium/server": ">=0.60.0",
|
|
39
|
+
"@axium/storage": ">=0.34.0",
|
|
40
|
+
"@james-pre/locales": "^1.0.0",
|
|
41
|
+
"@sveltejs/kit": "^3.0.0",
|
|
42
|
+
"commander": "^15.0.0",
|
|
43
|
+
"ioium": "^1.7.0",
|
|
44
|
+
"utilium": "^3.13.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"zod": "^4.0.5"
|
|
48
|
+
},
|
|
49
|
+
"axium": {
|
|
50
|
+
"locales": "locales",
|
|
51
|
+
"server": {
|
|
52
|
+
"routes": "routes",
|
|
53
|
+
"hooks": "./dist/hooks.js",
|
|
54
|
+
"cli": "./dist/server/cli.js",
|
|
55
|
+
"web_client_hooks": "./dist/web_hook.js"
|
|
56
|
+
},
|
|
57
|
+
"apps": [
|
|
58
|
+
{
|
|
59
|
+
"id": "office",
|
|
60
|
+
"name": "Office",
|
|
61
|
+
"icon": "file-pen"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"config": {
|
|
65
|
+
"server_url": null,
|
|
66
|
+
"internal_url": null,
|
|
67
|
+
"secret": ""
|
|
68
|
+
},
|
|
69
|
+
"update_checks": false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { text } from '@axium/client';
|
|
3
|
+
import { TopBarContent } from '@axium/client/components';
|
|
4
|
+
|
|
5
|
+
const { children } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<TopBarContent name={text('app_name.office')} icon="file-pen" href="/office" />
|
|
9
|
+
|
|
10
|
+
{@render children()}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import '@axium/office/common';
|
|
2
|
+
import { currentSession } from '@axium/client/user';
|
|
3
|
+
import type { Session, UserPublic } from '@axium/core';
|
|
4
|
+
import { redirect } from '@sveltejs/kit';
|
|
5
|
+
|
|
6
|
+
export const ssr = false;
|
|
7
|
+
|
|
8
|
+
export async function load({ parent, url }) {
|
|
9
|
+
let { session }: { session?: (Session & { user: UserPublic }) | null } = await parent();
|
|
10
|
+
|
|
11
|
+
session ||= await currentSession();
|
|
12
|
+
|
|
13
|
+
if (!session) redirect(307, `/login?after=${url.pathname}`);
|
|
14
|
+
|
|
15
|
+
return { session };
|
|
16
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { goto } from '$app/navigation';
|
|
3
|
+
import { fetchAPI, text } from '@axium/client';
|
|
4
|
+
import { Icon, Popover } from '@axium/client/components';
|
|
5
|
+
import { toast } from '@axium/client/toast';
|
|
6
|
+
import { icons, kinds, newFormats, type Kind } from '@axium/office/common';
|
|
7
|
+
import DocumentCard from './DocumentCard.svelte';
|
|
8
|
+
|
|
9
|
+
const { data } = $props();
|
|
10
|
+
|
|
11
|
+
let items = $state(data.items);
|
|
12
|
+
|
|
13
|
+
/** The localized "Untitled" name, numbered when the user already has one */
|
|
14
|
+
function untitledName(kind: Kind): string {
|
|
15
|
+
const base = text(`office.untitled.${kind}`);
|
|
16
|
+
const names = new Set(items.map(item => item.name));
|
|
17
|
+
|
|
18
|
+
for (let number = 1; ; number++) {
|
|
19
|
+
const name = number == 1 ? base : `${base} ${number}`;
|
|
20
|
+
if (!names.has(`${name}.${newFormats[kind].extension}`)) return name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function create(kind: Kind) {
|
|
25
|
+
try {
|
|
26
|
+
const item = await fetchAPI('PUT', 'office', { kind, name: untitledName(kind) });
|
|
27
|
+
await goto(`/office/${item.id}`);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
toast('error', error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<svelte:head>
|
|
35
|
+
<title>{text('app_name.office')}</title>
|
|
36
|
+
</svelte:head>
|
|
37
|
+
|
|
38
|
+
<div id="office-main">
|
|
39
|
+
<Popover>
|
|
40
|
+
{#snippet toggle()}
|
|
41
|
+
<button class="icon-text new">
|
|
42
|
+
<Icon i="plus" />
|
|
43
|
+
<span>{text('office.new')}</span>
|
|
44
|
+
</button>
|
|
45
|
+
{/snippet}
|
|
46
|
+
{#each kinds as kind}
|
|
47
|
+
<button class="reset menu-item" onclick={() => create(kind)}>
|
|
48
|
+
<Icon i={icons[kind]} />
|
|
49
|
+
<span>{text(`office.kind.${kind}`)}</span>
|
|
50
|
+
</button>
|
|
51
|
+
{/each}
|
|
52
|
+
</Popover>
|
|
53
|
+
|
|
54
|
+
{#if items.length}
|
|
55
|
+
<div class="documents">
|
|
56
|
+
{#each items as item, i (item.id)}
|
|
57
|
+
<DocumentCard
|
|
58
|
+
bind:item={items[i]}
|
|
59
|
+
user={data.session.user}
|
|
60
|
+
ontrash={() => (items = items.filter(other => other.id != item.id))}
|
|
61
|
+
/>
|
|
62
|
+
{/each}
|
|
63
|
+
</div>
|
|
64
|
+
{:else}
|
|
65
|
+
<p class="subtle">{text('office.empty')}</p>
|
|
66
|
+
{/if}
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<style>
|
|
70
|
+
#office-main {
|
|
71
|
+
padding: 2em;
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
align-items: start;
|
|
75
|
+
gap: 1.5em;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.documents {
|
|
79
|
+
align-self: stretch;
|
|
80
|
+
display: grid;
|
|
81
|
+
grid-template-columns: repeat(auto-fill, minmax(16em, 1fr));
|
|
82
|
+
gap: 1em;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (width < 700px) {
|
|
86
|
+
#office-main {
|
|
87
|
+
padding: 1em;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatOf } from '@axium/office/common';
|
|
2
|
+
import { getUserStorage, itemsSharedWith } from '@axium/storage/client';
|
|
3
|
+
|
|
4
|
+
export async function load({ parent }) {
|
|
5
|
+
const { session } = await parent();
|
|
6
|
+
|
|
7
|
+
const [owned, shared] = await Promise.all([getUserStorage(session.userId), itemsSharedWith(session.userId)]);
|
|
8
|
+
|
|
9
|
+
const items = [...owned.items, ...shared]
|
|
10
|
+
.filter(item => !item.trashedAt && item.type != 'inode/directory' && formatOf(item))
|
|
11
|
+
.sort((first, second) => second.modifiedAt.getTime() - first.modifiedAt.getTime());
|
|
12
|
+
|
|
13
|
+
return { items };
|
|
14
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { text } from '@axium/client';
|
|
3
|
+
import { contextMenu, type ContextMenuItem } from '@axium/client/attachments';
|
|
4
|
+
import { AccessControlDialog, Icon, InlineEdit, Popover } from '@axium/client/components';
|
|
5
|
+
import { toastStatus } from '@axium/client/toast';
|
|
6
|
+
import { checkAndMatchACL, type UserPublic } from '@axium/core';
|
|
7
|
+
import { formatOf, icons } from '@axium/office/common';
|
|
8
|
+
import { updateItemMetadata } from '@axium/storage/client';
|
|
9
|
+
import { _downloadItem } from '@axium/storage/client/frontend';
|
|
10
|
+
import type { StorageItemMetadata } from '@axium/storage/common';
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
item = $bindable(),
|
|
14
|
+
user,
|
|
15
|
+
ontrash,
|
|
16
|
+
}: {
|
|
17
|
+
item: StorageItemMetadata;
|
|
18
|
+
user: UserPublic;
|
|
19
|
+
ontrash(): void;
|
|
20
|
+
} = $props();
|
|
21
|
+
|
|
22
|
+
const href = $derived(`/office/${item.id}`);
|
|
23
|
+
const format = $derived(formatOf(item));
|
|
24
|
+
const isShared = $derived(item.userId != user.id);
|
|
25
|
+
const canManage = $derived(!isShared || (!!item.acl && !checkAndMatchACL(item.acl, user, { manage: true }).size));
|
|
26
|
+
|
|
27
|
+
let renaming = $state(false),
|
|
28
|
+
sharing = $state(false),
|
|
29
|
+
shareDialog = $state<HTMLDialogElement>();
|
|
30
|
+
|
|
31
|
+
$effect(() => shareDialog?.showModal());
|
|
32
|
+
|
|
33
|
+
function rename(name: string) {
|
|
34
|
+
toastStatus(
|
|
35
|
+
updateItemMetadata(item.id, { name }).then(() => (item.name = name)),
|
|
36
|
+
text('office.renamed')
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function trash() {
|
|
41
|
+
toastStatus(updateItemMetadata(item.id, { trash: true }).then(ontrash), text('office.trashed'));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const entries = $derived<(ContextMenuItem | false)[]>([
|
|
45
|
+
{ i: 'arrow-up-right-from-square', text: text('office.open_new_tab'), action: () => open(href) },
|
|
46
|
+
canManage && { i: 'pencil', text: text('generic.rename'), action: () => (renaming = true) },
|
|
47
|
+
{ i: 'download', text: text('office.download'), action: () => _downloadItem(item) },
|
|
48
|
+
canManage && { i: 'user-group', text: text('generic.share'), action: () => (sharing = true) },
|
|
49
|
+
canManage && { i: 'trash', text: text('office.trash'), action: trash, danger: true },
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const actions = $derived(entries.filter(entry => entry !== false));
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
{#snippet details()}
|
|
56
|
+
<Icon i={icons[format?.kind ?? 'document']} --size="2em" />
|
|
57
|
+
{#if renaming}
|
|
58
|
+
{const dot = $derived(item.name.lastIndexOf('.'))}
|
|
59
|
+
<span class="name editing">
|
|
60
|
+
<InlineEdit
|
|
61
|
+
value={item.name}
|
|
62
|
+
selectionRange={[0, dot > 0 ? dot : item.name.length]}
|
|
63
|
+
confirmLabel={text('generic.rename')}
|
|
64
|
+
commit={rename}
|
|
65
|
+
close={() => (renaming = false)}
|
|
66
|
+
/>
|
|
67
|
+
</span>
|
|
68
|
+
{:else}
|
|
69
|
+
<span class="name" title={item.name}>{item.name}</span>
|
|
70
|
+
{/if}
|
|
71
|
+
<span class="subtle">
|
|
72
|
+
{isShared
|
|
73
|
+
? text('office.shared')
|
|
74
|
+
: text('office.modified', { date: item.modifiedAt.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }) })}
|
|
75
|
+
</span>
|
|
76
|
+
{/snippet}
|
|
77
|
+
|
|
78
|
+
<div class="DocumentCard" {@attach contextMenu(() => entries)}>
|
|
79
|
+
{#if renaming}
|
|
80
|
+
<div class="details">{@render details()}</div>
|
|
81
|
+
{:else}
|
|
82
|
+
<a class="details" {href}>{@render details()}</a>
|
|
83
|
+
{/if}
|
|
84
|
+
|
|
85
|
+
<Popover>
|
|
86
|
+
{#snippet toggle()}
|
|
87
|
+
<button class="reset toggle" aria-label={text('office.actions', { name: item.name })}>
|
|
88
|
+
<Icon i="ellipsis-vertical" />
|
|
89
|
+
</button>
|
|
90
|
+
{/snippet}
|
|
91
|
+
{#each actions as action (action.text)}
|
|
92
|
+
<button class={['reset', 'menu-item', action.danger && 'danger']} onclick={() => action.action()}>
|
|
93
|
+
<Icon i={action.i!} />
|
|
94
|
+
<span>{action.text}</span>
|
|
95
|
+
</button>
|
|
96
|
+
{/each}
|
|
97
|
+
</Popover>
|
|
98
|
+
|
|
99
|
+
{#if sharing}
|
|
100
|
+
<AccessControlDialog bind:dialog={shareDialog} {item} itemType="storage" {user} onclose={() => (sharing = false)} />
|
|
101
|
+
{/if}
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<style>
|
|
105
|
+
.DocumentCard {
|
|
106
|
+
position: relative;
|
|
107
|
+
border-radius: 1em;
|
|
108
|
+
border: var(--border-alt);
|
|
109
|
+
background-color: var(--bg-alt);
|
|
110
|
+
|
|
111
|
+
&:hover {
|
|
112
|
+
background-color: var(--bg-accent);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.details {
|
|
117
|
+
display: grid;
|
|
118
|
+
justify-items: start;
|
|
119
|
+
gap: 0.25em;
|
|
120
|
+
padding: 1em;
|
|
121
|
+
padding-right: 2.5em;
|
|
122
|
+
color: inherit;
|
|
123
|
+
text-decoration: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.name {
|
|
127
|
+
max-width: 100%;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
text-overflow: ellipsis;
|
|
130
|
+
white-space: nowrap;
|
|
131
|
+
font-weight: bold;
|
|
132
|
+
|
|
133
|
+
&.editing {
|
|
134
|
+
overflow: visible;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.subtle {
|
|
139
|
+
font-size: 0.85em;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.toggle {
|
|
143
|
+
position: absolute;
|
|
144
|
+
top: 0.75em;
|
|
145
|
+
right: 0.75em;
|
|
146
|
+
padding: 0.25em 0.5em;
|
|
147
|
+
border-radius: 0.5em;
|
|
148
|
+
|
|
149
|
+
&:hover {
|
|
150
|
+
background-color: var(--bg-strong);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
</style>
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { text } from '@axium/client';
|
|
3
|
+
import { Icon, InlineEdit, TopBarContent } from '@axium/client/components';
|
|
4
|
+
import { toastStatus } from '@axium/client/toast';
|
|
5
|
+
import { updateItemMetadata } from '@axium/storage/client';
|
|
6
|
+
import Editor, { type EditorStatus } from './Editor.svelte';
|
|
7
|
+
|
|
8
|
+
const { data } = $props();
|
|
9
|
+
|
|
10
|
+
const { editor, readOnly, canRename } = $derived(data);
|
|
11
|
+
|
|
12
|
+
let item = $derived(data.item),
|
|
13
|
+
renaming = $state(false),
|
|
14
|
+
status = $state<EditorStatus>('loading');
|
|
15
|
+
|
|
16
|
+
function rename(name: string) {
|
|
17
|
+
toastStatus(
|
|
18
|
+
updateItemMetadata(item.id, { name }).then(() => (item = { ...item, name })),
|
|
19
|
+
text('office.renamed')
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const onstatus = (next: EditorStatus) => (status = next);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<svelte:head>
|
|
27
|
+
<title>{item.name}</title>
|
|
28
|
+
</svelte:head>
|
|
29
|
+
|
|
30
|
+
<TopBarContent name={text('app_name.office')} icon="file-pen" href="/office" align="left">
|
|
31
|
+
<div class="document-name">
|
|
32
|
+
{#if renaming}
|
|
33
|
+
{const dot = $derived(item.name.lastIndexOf('.'))}
|
|
34
|
+
<InlineEdit
|
|
35
|
+
value={item.name}
|
|
36
|
+
selectionRange={[0, dot > 0 ? dot : item.name.length]}
|
|
37
|
+
confirmLabel={text('generic.rename')}
|
|
38
|
+
commit={rename}
|
|
39
|
+
close={() => (renaming = false)}
|
|
40
|
+
/>
|
|
41
|
+
{:else if canRename}
|
|
42
|
+
<button class="reset name" title={text('generic.rename')} onclick={() => (renaming = true)}>{item.name}</button>
|
|
43
|
+
{:else}
|
|
44
|
+
<span class="name">{item.name}</span>
|
|
45
|
+
{/if}
|
|
46
|
+
{#if readOnly}
|
|
47
|
+
<span class="read-only icon-text"><Icon i="lock" />{text('office.read_only')}</span>
|
|
48
|
+
{/if}
|
|
49
|
+
</div>
|
|
50
|
+
</TopBarContent>
|
|
51
|
+
|
|
52
|
+
<div class="editor">
|
|
53
|
+
<Editor {editor} {onstatus} />
|
|
54
|
+
|
|
55
|
+
{#if status != 'ready'}
|
|
56
|
+
<div class="status" role="status">
|
|
57
|
+
{#if status == 'loading'}
|
|
58
|
+
<span>{text('office.opening', { name: item.name })}</span>
|
|
59
|
+
{:else}
|
|
60
|
+
<span>{text('office.failed')}</span>
|
|
61
|
+
{#if status == 'unreachable'}
|
|
62
|
+
{const origin = $derived(new URL(editor.url).origin)}
|
|
63
|
+
<span>
|
|
64
|
+
{text('office.trust_hint')}
|
|
65
|
+
<a href={origin} target="_blank">{origin}</a>
|
|
66
|
+
</span>
|
|
67
|
+
{/if}
|
|
68
|
+
<a href="/office">{text('office.back')}</a>
|
|
69
|
+
{/if}
|
|
70
|
+
</div>
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<style>
|
|
75
|
+
.document-name {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
gap: 1em;
|
|
79
|
+
min-width: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.name {
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
text-overflow: ellipsis;
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
font-size: 1.1em;
|
|
87
|
+
padding: 0.25em 0.5em;
|
|
88
|
+
border-radius: 0.5em;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
button.name:hover {
|
|
92
|
+
background-color: var(--bg-strong);
|
|
93
|
+
cursor: text;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.read-only {
|
|
97
|
+
flex-shrink: 0;
|
|
98
|
+
gap: 0.5em;
|
|
99
|
+
font-size: 0.85em;
|
|
100
|
+
color: var(--fg-accent);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.editor {
|
|
104
|
+
position: fixed;
|
|
105
|
+
inset: var(--top-bar-height) 0 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.status {
|
|
109
|
+
position: absolute;
|
|
110
|
+
inset: 0;
|
|
111
|
+
margin: auto;
|
|
112
|
+
width: fit-content;
|
|
113
|
+
height: fit-content;
|
|
114
|
+
max-width: min(32em, calc(100% - 2em));
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
align-items: center;
|
|
118
|
+
gap: 0.75em;
|
|
119
|
+
padding: 1.5em 2em;
|
|
120
|
+
text-align: center;
|
|
121
|
+
overflow-wrap: anywhere;
|
|
122
|
+
border-radius: 1em;
|
|
123
|
+
border: var(--border-elevated);
|
|
124
|
+
background-color: var(--bg-elevated);
|
|
125
|
+
}
|
|
126
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
/** `unreachable` means the browser could not load the editor at all, usually because of the document server's certificate */
|
|
3
|
+
export type EditorStatus = 'loading' | 'ready' | 'failed' | 'unreachable';
|
|
4
|
+
|
|
5
|
+
interface DocEditor {
|
|
6
|
+
destroyEditor(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface DocsAPI {
|
|
10
|
+
DocEditor: new (elementId: string, config: object) => DocEditor;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
DocsAPI?: DocsAPI;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Loads the editor API from the document server, once per page */
|
|
20
|
+
async function loadAPI(serverURL: string): Promise<DocsAPI> {
|
|
21
|
+
if (window.DocsAPI) return window.DocsAPI;
|
|
22
|
+
|
|
23
|
+
const script = document.createElement('script');
|
|
24
|
+
script.src = serverURL.replace(/\/$/, '') + '/web-apps/apps/api/documents/api.js';
|
|
25
|
+
|
|
26
|
+
const { promise, resolve, reject } = Promise.withResolvers<void>();
|
|
27
|
+
script.onload = () => resolve();
|
|
28
|
+
script.onerror = () => reject(new Error('Could not load the document server API'));
|
|
29
|
+
document.head.append(script);
|
|
30
|
+
await promise;
|
|
31
|
+
|
|
32
|
+
return window.DocsAPI!;
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
import type { Editor } from '@axium/office/common';
|
|
38
|
+
|
|
39
|
+
const { editor, onstatus }: { editor: Editor; onstatus(status: EditorStatus): void } = $props();
|
|
40
|
+
|
|
41
|
+
/** The document server replaces this element with its frame */
|
|
42
|
+
const elementId = 'document-editor';
|
|
43
|
+
|
|
44
|
+
async function mount(): Promise<DocEditor | undefined> {
|
|
45
|
+
const api = await loadAPI(editor.url).catch(() => onstatus('unreachable'));
|
|
46
|
+
if (!api) return;
|
|
47
|
+
|
|
48
|
+
return new api.DocEditor(elementId, {
|
|
49
|
+
...editor.config,
|
|
50
|
+
width: '100%',
|
|
51
|
+
height: '100%',
|
|
52
|
+
events: {
|
|
53
|
+
onDocumentReady: () => onstatus('ready'),
|
|
54
|
+
onError: () => onstatus('failed'),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
$effect(() => {
|
|
60
|
+
const mounting = mount();
|
|
61
|
+
return () => void mounting.then(docEditor => docEditor?.destroyEditor());
|
|
62
|
+
});
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<div class="host">
|
|
66
|
+
<div id={elementId}></div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<style>
|
|
70
|
+
.host {
|
|
71
|
+
height: 100%;
|
|
72
|
+
}
|
|
73
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../tsconfig.json", "$app/tsconfig"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"typeRoots": null,
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"target": "esnext",
|
|
9
|
+
"rootDir": "..",
|
|
10
|
+
"types": ["@sveltejs/kit"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["**/*", "../lib/*", "../src/.*.ts", "../../client/dist/.*.ts"],
|
|
13
|
+
"references": [{ "path": ".." }]
|
|
14
|
+
}
|