@axium/office 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/common.d.ts +257 -0
- package/dist/common.js +71 -0
- package/dist/hooks.d.ts +4 -0
- package/dist/hooks.js +12 -0
- package/dist/server/api.d.ts +1 -0
- package/dist/server/api.js +60 -0
- package/dist/server/cli.d.ts +1 -0
- package/dist/server/cli.js +14 -0
- package/dist/server/documentserver.d.ts +14 -0
- package/dist/server/documentserver.js +211 -0
- package/dist/server/image.d.ts +17 -0
- package/dist/server/image.js +161 -0
- package/dist/server/jwt.d.ts +6 -0
- package/dist/server/jwt.js +37 -0
- package/dist/server/patches.json +57 -0
- package/dist/server/themes.d.ts +9 -0
- package/dist/server/themes.js +179 -0
- package/dist/web_hook.d.ts +1 -0
- package/dist/web_hook.js +7 -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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// The document server's Axium themes, one per Axium theme.
|
|
2
|
+
import { themeStyles } from '@axium/client/themes';
|
|
3
|
+
import { hslToHex } from 'utilium/color';
|
|
4
|
+
/** The defaults in `@axium/client/assets/theme.css`, which the `default` theme uses */
|
|
5
|
+
const defaults = {
|
|
6
|
+
'color-scheme': 'dark',
|
|
7
|
+
hue: '240',
|
|
8
|
+
'fg-light': '73%',
|
|
9
|
+
'bg-light': '13.3%',
|
|
10
|
+
'light-step': '6.6%',
|
|
11
|
+
};
|
|
12
|
+
/** `saturation` and `lightness` are percentages, `hue` is in degrees */
|
|
13
|
+
function hex(hue, saturation, lightness) {
|
|
14
|
+
const fraction = (value) => Math.min(100, Math.max(0, value)) / 100;
|
|
15
|
+
return '#' + hslToHex(hue / 360, fraction(saturation), fraction(lightness));
|
|
16
|
+
}
|
|
17
|
+
/** Axium's colors, using the formulas in `theme.css` */
|
|
18
|
+
function axiumColors(style) {
|
|
19
|
+
const hue = parseFloat(style.hue);
|
|
20
|
+
const foreground = parseFloat(style['fg-light']);
|
|
21
|
+
const background = parseFloat(style['bg-light']);
|
|
22
|
+
const step = parseFloat(style['light-step']);
|
|
23
|
+
return {
|
|
24
|
+
'bg-normal': hex(0, 0, background),
|
|
25
|
+
'bg-menu': hex(0, 0, background - step),
|
|
26
|
+
'bg-accent': hex(hue, 15, background + step * 2),
|
|
27
|
+
'bg-alt': hex(hue, 5, background + step),
|
|
28
|
+
'bg-strong': hex(hue, 20, background + step),
|
|
29
|
+
'fg-normal': hex(0, 0, foreground),
|
|
30
|
+
'fg-accent': hex(hue, 15, foreground),
|
|
31
|
+
'fg-disabled': hex(0, 0, foreground - step),
|
|
32
|
+
'border-accent': hex(hue, 10, background + step * 3),
|
|
33
|
+
'border-strong': hex(hue, 20, background + step * 3),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const perEditor = (token) => ['document', 'spreadsheet', 'presentation', 'pdf', 'visio'].map(editor => `${token}-${editor}`);
|
|
37
|
+
/**
|
|
38
|
+
* Editor color tokens by the Axium color they take.
|
|
39
|
+
* The base theme keeps status colors (alt key hints, badges, form filling, sheet views, red and green icons), overlays, shadows,
|
|
40
|
+
* the spreadsheet's fixed header shades and the page itself.
|
|
41
|
+
*/
|
|
42
|
+
function editorColors(axium) {
|
|
43
|
+
const mapping = {
|
|
44
|
+
'bg-normal': [
|
|
45
|
+
...perEditor('toolbar-header'),
|
|
46
|
+
...perEditor('text-toolbar-header-on-background'),
|
|
47
|
+
'background-normal',
|
|
48
|
+
'background-toolbar',
|
|
49
|
+
'background-toolbar-tab',
|
|
50
|
+
'border-toolbar-active-panel-top',
|
|
51
|
+
'canvas-ruler-background',
|
|
52
|
+
'canvas-cell-title-background',
|
|
53
|
+
'slider-thumb-border-normal',
|
|
54
|
+
'text-inverse',
|
|
55
|
+
],
|
|
56
|
+
'bg-menu': ['background-pane', 'background-contrast-popover', 'canvas-background'],
|
|
57
|
+
'bg-alt': [
|
|
58
|
+
'background-toolbar-additional',
|
|
59
|
+
'canvas-ruler-margins-background',
|
|
60
|
+
'canvas-cell-title-background-hover',
|
|
61
|
+
'canvas-scroll-thumb',
|
|
62
|
+
'highlight-comment-hover',
|
|
63
|
+
'highlight-category-button-hover',
|
|
64
|
+
],
|
|
65
|
+
'bg-strong': [
|
|
66
|
+
'background-notification-popover',
|
|
67
|
+
'highlight-button-pressed',
|
|
68
|
+
'highlight-header-button-pressed',
|
|
69
|
+
'highlight-comment-pressed',
|
|
70
|
+
'highlight-category-button-pressed',
|
|
71
|
+
'highlight-primary-dialog-button-pressed',
|
|
72
|
+
],
|
|
73
|
+
'bg-accent': [
|
|
74
|
+
'eo-app-accent',
|
|
75
|
+
'highlight-button-hover',
|
|
76
|
+
'highlight-button-pressed-hover',
|
|
77
|
+
'highlight-header-button-hover',
|
|
78
|
+
'chb-background-normal-hover',
|
|
79
|
+
'chb-background-checked-hover',
|
|
80
|
+
'rb-background-normal-hover',
|
|
81
|
+
'rb-background-checked-hover',
|
|
82
|
+
'canvas-cell-title-background-selected',
|
|
83
|
+
'canvas-scroll-thumb-hover',
|
|
84
|
+
'canvas-scroll-thumb-pressed',
|
|
85
|
+
'icon-blue-secondary',
|
|
86
|
+
],
|
|
87
|
+
'border-accent': [
|
|
88
|
+
'border-toolbar',
|
|
89
|
+
'border-divider',
|
|
90
|
+
'border-color-shading',
|
|
91
|
+
'border-contrast-popover',
|
|
92
|
+
'canvas-ruler-border',
|
|
93
|
+
'canvas-ruler-handle-border-disabled',
|
|
94
|
+
'canvas-cell-title-border',
|
|
95
|
+
'canvas-scroll-thumb-border',
|
|
96
|
+
'slider-track-background-normal',
|
|
97
|
+
],
|
|
98
|
+
'border-strong': [
|
|
99
|
+
'border-regular-control',
|
|
100
|
+
'border-preview-hover',
|
|
101
|
+
'chb-border-normal',
|
|
102
|
+
'chb-border-checked',
|
|
103
|
+
'rb-border-normal',
|
|
104
|
+
'rb-border-checked',
|
|
105
|
+
'canvas-cell-title-border-hover',
|
|
106
|
+
'canvas-high-contrast-disabled',
|
|
107
|
+
'canvas-scroll-thumb-border-hover',
|
|
108
|
+
],
|
|
109
|
+
'fg-normal': [
|
|
110
|
+
'text-normal',
|
|
111
|
+
'text-normal-pressed',
|
|
112
|
+
'text-toolbar-header',
|
|
113
|
+
'text-link-hover',
|
|
114
|
+
'text-link-active',
|
|
115
|
+
'icon-normal',
|
|
116
|
+
'icon-normal-pressed',
|
|
117
|
+
'icon-toolbar-header',
|
|
118
|
+
'icon-gray-primary',
|
|
119
|
+
'canvas-high-contrast',
|
|
120
|
+
'canvas-scroll-arrow',
|
|
121
|
+
'canvas-scroll-arrow-hover',
|
|
122
|
+
'canvas-scroll-arrow-pressed',
|
|
123
|
+
'canvas-scroll-thumb-target',
|
|
124
|
+
'canvas-scroll-thumb-target-hover',
|
|
125
|
+
'canvas-scroll-thumb-target-pressed',
|
|
126
|
+
'highlight-primary-dialog-button-hover',
|
|
127
|
+
'slider-thumb-background-hover',
|
|
128
|
+
],
|
|
129
|
+
'fg-accent': [
|
|
130
|
+
...perEditor('highlight-header-tab-underline'),
|
|
131
|
+
...perEditor('highlight-toolbar-tab-underline'),
|
|
132
|
+
'text-secondary',
|
|
133
|
+
'text-link',
|
|
134
|
+
'text-link-visited',
|
|
135
|
+
'icon-gray-secondary',
|
|
136
|
+
'icon-blue-primary',
|
|
137
|
+
'canvas-cell-title-text',
|
|
138
|
+
'background-primary-dialog-button',
|
|
139
|
+
'background-accent-button',
|
|
140
|
+
'highlight-text-select',
|
|
141
|
+
'border-preview-select',
|
|
142
|
+
'border-control-focus',
|
|
143
|
+
'border-button-pressed-focus',
|
|
144
|
+
'border-fill-input-focused',
|
|
145
|
+
'chb-border-normal-focus',
|
|
146
|
+
'chb-border-checked-focus',
|
|
147
|
+
'rb-border-normal-focus',
|
|
148
|
+
'rb-border-checked-focus',
|
|
149
|
+
'slider-track-background-filled',
|
|
150
|
+
'slider-thumb-background-normal',
|
|
151
|
+
'slider-thumb-background-active',
|
|
152
|
+
],
|
|
153
|
+
'fg-disabled': [
|
|
154
|
+
'text-tertiary',
|
|
155
|
+
'chb-border-normal-hover',
|
|
156
|
+
'chb-border-checked-hover',
|
|
157
|
+
'rb-border-normal-hover',
|
|
158
|
+
'rb-border-checked-hover',
|
|
159
|
+
'canvas-ruler-mark',
|
|
160
|
+
'canvas-ruler-handle-border',
|
|
161
|
+
'canvas-cell-title-border-selected',
|
|
162
|
+
'canvas-scroll-thumb-border-pressed',
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
return Object.fromEntries(Object.entries(mapping).flatMap(([color, tokens]) => tokens.map(token => [token, axium[color]])));
|
|
166
|
+
}
|
|
167
|
+
export function editorThemes() {
|
|
168
|
+
return [['default', {}], ...Object.entries(themeStyles)].map(([name, overrides]) => {
|
|
169
|
+
const style = { ...defaults, ...overrides };
|
|
170
|
+
const type = style['color-scheme'] == 'light' ? 'light' : 'dark';
|
|
171
|
+
return {
|
|
172
|
+
id: `theme-axium-${name}`,
|
|
173
|
+
name: name == 'default' ? 'Axium' : `Axium ${name}`,
|
|
174
|
+
type,
|
|
175
|
+
base: type == 'dark' ? 'theme-night' : 'theme-white',
|
|
176
|
+
colors: editorColors(axiumColors(style)),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/web_hook.js
ADDED
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.1.0",
|
|
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>
|