rimecms 1.5.0 → 1.5.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/dist/core/auth/better-auth/config.server.d.ts +1 -1
- package/dist/core/auth/better-auth/instance.server.d.ts +2 -2
- package/dist/core/boot.server.d.ts +2 -2
- package/dist/core/i18n/en/common.d.ts +10 -4
- package/dist/core/i18n/en/common.js +12 -6
- package/dist/core/i18n/fr/common.d.ts +10 -4
- package/dist/core/i18n/fr/common.js +12 -7
- package/dist/core/prototype/shared/title/find-title.d.ts +9 -0
- package/dist/core/prototype/shared/title/find-title.js +20 -4
- package/dist/fields/group/component/Group.svelte +4 -3
- package/dist/fields/text/index.d.ts +11 -3
- package/dist/fields/text/index.js +11 -3
- package/dist/panel/components/fields/RenderFields.svelte +3 -2
- package/dist/panel/components/sections/collection/DropHint.svelte +41 -0
- package/dist/panel/components/sections/collection/DropHint.svelte.d.ts +7 -0
- package/dist/panel/components/sections/collection/grid/CollectionGrid.svelte +23 -3
- package/dist/panel/components/sections/collection/header/ButtonCreate.svelte +3 -3
- package/dist/panel/components/sections/collection/header/ButtonCreate.svelte.d.ts +1 -1
- package/dist/panel/components/sections/collection/list/CollectionList.svelte +8 -0
- package/dist/panel/components/sections/document/ButtonPublish.svelte +39 -0
- package/dist/panel/components/sections/document/ButtonPublish.svelte.d.ts +7 -0
- package/dist/panel/components/sections/document/ButtonSave.svelte +6 -3
- package/dist/panel/components/sections/document/ButtonSave.svelte.d.ts +3 -1
- package/dist/panel/components/sections/document/Header.svelte +116 -65
- package/dist/panel/components/sections/document/Settings.svelte +42 -125
- package/dist/panel/components/sections/document/VersionMenu.svelte +383 -0
- package/dist/panel/components/sections/document/VersionMenu.svelte.d.ts +8 -0
- package/dist/panel/components/sections/document/Versions.svelte +1 -1
- package/dist/panel/components/sections/document/Versions.svelte.d.ts +1 -1
- package/dist/panel/components/sections/document/version-status.d.ts +12 -0
- package/dist/panel/components/sections/document/version-status.js +33 -0
- package/dist/panel/components/sections/document/versions-list.d.ts +1 -1
- package/dist/panel/components/sections/document/versions-list.js +1 -1
- package/dist/panel/components/ui/calendar/calendar.svelte.d.ts +1 -1
- package/dist/panel/components/ui/checkbox/checkbox.svelte.d.ts +1 -1
- package/dist/panel/components/ui/page-header/PageHeader.svelte +36 -4
- package/dist/panel/components/ui/page-header/PageHeader.svelte.d.ts +4 -0
- package/dist/panel/components/ui/switch/switch.svelte.d.ts +1 -1
- package/dist/panel/context/collection.svelte.d.ts +2 -2
- package/dist/panel/context/documentForm.svelte.d.ts +2 -0
- package/dist/panel/context/documentForm.svelte.js +12 -0
- package/dist/panel/context/versions.svelte.js +1 -1
- package/dist/panel/pages/collection/CollectionPage.svelte +37 -27
- package/dist/panel/pages/collection/CollectionPage.svelte.d.ts +1 -1
- package/package.json +1 -1
- package/dist/panel/components/sections/document/ButtonStatus.svelte +0 -158
- package/dist/panel/components/sections/document/ButtonStatus.svelte.d.ts +0 -7
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
|
|
2
|
-
import type { ButtonSize } from '../../ui/button/index.js';
|
|
2
|
+
import type { ButtonSize, ButtonVariant } from '../../ui/button/index.js';
|
|
3
3
|
type Props = {
|
|
4
4
|
form: DocumentFormContext;
|
|
5
5
|
size?: ButtonSize;
|
|
6
|
+
/** `secondary` beside a Publish button, which is then the primary one. */
|
|
7
|
+
variant?: ButtonVariant;
|
|
6
8
|
};
|
|
7
9
|
declare const ButtonSave: import("svelte").Component<Props, {}, "">;
|
|
8
10
|
type ButtonSave = ReturnType<typeof ButtonSave>;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { BuiltArea, BuiltCollection } from '../../../../core/config/types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getFieldAtPath } from '../../../../core/fields/util.js';
|
|
4
4
|
import { t__ } from '../../../../core/i18n/index.js';
|
|
5
|
+
import { VERSIONS_STATUS } from '../../../../core/prototype/shared/versions/constant.js';
|
|
5
6
|
import { titleOrUntitled } from '../../../util/title.js';
|
|
6
7
|
import { getConfigContext } from '../../../context/config.svelte.js';
|
|
7
8
|
import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
|
|
8
9
|
import { getLocaleContext } from '../../../context/locale.svelte.js';
|
|
10
|
+
import { errorText } from '../../../util/error-text.js';
|
|
9
11
|
import { formatWhen, isRelative } from '../../../util/time.js';
|
|
10
12
|
import { capitalize } from '../../../../util/string.js';
|
|
11
|
-
import ExternalLink from '@lucide/svelte/icons/external-link';
|
|
12
|
-
import PencilRuler from '@lucide/svelte/icons/pencil-ruler';
|
|
13
13
|
import X from '@lucide/svelte/icons/x';
|
|
14
14
|
import { Button } from '../../ui/button';
|
|
15
15
|
import LanguageSwitcher from '../../ui/language-switcher/LanguageSwitcher.svelte';
|
|
16
16
|
import PageHeader from '../../ui/page-header/PageHeader.svelte';
|
|
17
17
|
import SpinLoader from '../../ui/spin-loader/SpinLoader.svelte';
|
|
18
|
+
import ButtonPublish from './ButtonPublish.svelte';
|
|
18
19
|
import ButtonSave from './ButtonSave.svelte';
|
|
19
|
-
import ButtonStatus from './ButtonStatus.svelte';
|
|
20
20
|
import DocumentUrl from './DocumentUrl.svelte';
|
|
21
21
|
import Settings from './Settings.svelte';
|
|
22
|
+
import VersionMenu from './VersionMenu.svelte';
|
|
22
23
|
|
|
23
24
|
// Props
|
|
24
25
|
type Props = {
|
|
@@ -49,6 +50,12 @@
|
|
|
49
50
|
const untitled = $derived(!form.title);
|
|
50
51
|
const heading = $derived(titleOrUntitled(form.title));
|
|
51
52
|
|
|
53
|
+
/** The title field the heading edits, `isTitle('inline')`; its label names the input. */
|
|
54
|
+
const titleField = $derived(form.inlineTitle ? form.useField<string>(form.inlineTitle) : null);
|
|
55
|
+
const titleLabel = $derived(
|
|
56
|
+
form.inlineTitle ? getFieldAtPath(form.inlineTitle, config.fields)?.get.label : undefined
|
|
57
|
+
);
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* The line under the heading: what the document is, then who edited it last, and when.
|
|
54
61
|
*
|
|
@@ -75,14 +82,10 @@
|
|
|
75
82
|
return capitalize(parts.join(' · '));
|
|
76
83
|
});
|
|
77
84
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const preview = new URL(url);
|
|
83
|
-
preview.searchParams.set(PARAMS.VERSION_ID, String(form.values.versionId));
|
|
84
|
-
return preview.href;
|
|
85
|
-
}
|
|
85
|
+
/** A saved draft gets Publish, the primary button, and Save steps back beside it. */
|
|
86
|
+
const canPublish = $derived(
|
|
87
|
+
!!config.versions?.draft && !!form.values.id && form.values.status !== VERSIONS_STATUS.PUBLISHED
|
|
88
|
+
);
|
|
86
89
|
</script>
|
|
87
90
|
|
|
88
91
|
{#snippet topLeft()}
|
|
@@ -90,26 +93,57 @@
|
|
|
90
93
|
{/snippet}
|
|
91
94
|
|
|
92
95
|
{#snippet title()}
|
|
93
|
-
|
|
96
|
+
{#if titleField}
|
|
97
|
+
<input
|
|
98
|
+
class="rz-document-title-input"
|
|
99
|
+
id={form.inlineTitle}
|
|
100
|
+
name={form.inlineTitle}
|
|
101
|
+
aria-label={titleLabel}
|
|
102
|
+
aria-invalid={titleField.error ? 'true' : undefined}
|
|
103
|
+
aria-describedby={titleField.error ? 'rz-document-title-error' : undefined}
|
|
104
|
+
placeholder={t__('common.untitled')}
|
|
105
|
+
autocomplete="off"
|
|
106
|
+
size={Math.max((titleField.value || t__('common.untitled')).length, 1)}
|
|
107
|
+
value={titleField.value ?? ''}
|
|
108
|
+
readonly={!titleField.editable}
|
|
109
|
+
oninput={(event) => (titleField.value = event.currentTarget.value)}
|
|
110
|
+
/>
|
|
111
|
+
{:else}
|
|
112
|
+
<span class="rz-document-title" data-empty={untitled ? '' : null}>{heading}</span>
|
|
113
|
+
{/if}
|
|
114
|
+
{/snippet}
|
|
115
|
+
|
|
116
|
+
{#snippet titleEnd()}
|
|
117
|
+
{/* @ts-ignore form doc is GenericDoc as form.values.id is defined */ null}
|
|
118
|
+
<Settings {form} />
|
|
94
119
|
{/snippet}
|
|
95
120
|
|
|
96
121
|
{#snippet metaLine()}
|
|
97
|
-
|
|
122
|
+
{#if titleField?.error}
|
|
123
|
+
<span id="rz-document-title-error" class="rz-document-title-error">
|
|
124
|
+
{errorText(titleField.error)}
|
|
125
|
+
</span>
|
|
126
|
+
{:else}
|
|
127
|
+
<span class="rz-document-meta">{meta}</span>
|
|
128
|
+
{/if}
|
|
98
129
|
{/snippet}
|
|
99
130
|
|
|
100
131
|
{#snippet urlLine()}
|
|
101
132
|
<DocumentUrl {form} {config} />
|
|
102
133
|
{/snippet}
|
|
103
134
|
|
|
104
|
-
<!--
|
|
135
|
+
<!--
|
|
136
|
+
The bar: the breadcrumb, then the language, the version menu and the save buttons. Under it, the
|
|
137
|
+
heading with the document's menu, the meta line and the url.
|
|
138
|
+
-->
|
|
105
139
|
<PageHeader
|
|
106
140
|
topLeft={onCloseIsDefined ? topLeft : undefined}
|
|
107
141
|
{title}
|
|
108
|
-
|
|
142
|
+
titleEnd={form.values.id ? titleEnd : undefined}
|
|
143
|
+
meta={meta || titleField?.error ? metaLine : undefined}
|
|
109
144
|
aside={form.values.url ? urlLine : undefined}
|
|
110
145
|
>
|
|
111
146
|
{#snippet topRight()}
|
|
112
|
-
<!-- Ghost buttons, then the primary one: open, language, status, menu, save. -->
|
|
113
147
|
<div class="rz-document-actions">
|
|
114
148
|
{#if showAutoSave}
|
|
115
149
|
<span class="rz-auto-save-state" data-auto-save-state={form.autoSaveState}>
|
|
@@ -126,45 +160,20 @@
|
|
|
126
160
|
</span>
|
|
127
161
|
{/if}
|
|
128
162
|
|
|
129
|
-
{#if form.values.url}
|
|
130
|
-
<Button
|
|
131
|
-
icon={ExternalLink}
|
|
132
|
-
target="_blank"
|
|
133
|
-
href={buildDocumentURL()}
|
|
134
|
-
size="icon-sm"
|
|
135
|
-
variant="ghost"
|
|
136
|
-
class="rz-document-actions__open"
|
|
137
|
-
aria-label={t__('common.view_page')}
|
|
138
|
-
/>
|
|
139
|
-
{/if}
|
|
140
|
-
|
|
141
|
-
{#if config.live && form.values._live}
|
|
142
|
-
<Button
|
|
143
|
-
size="icon-sm"
|
|
144
|
-
variant="ghost"
|
|
145
|
-
disabled={form.readOnly}
|
|
146
|
-
class="rz-button-live"
|
|
147
|
-
icon={PencilRuler}
|
|
148
|
-
href={form.values._live}
|
|
149
|
-
aria-label={t__('common.live_edit')}
|
|
150
|
-
title={t__('common.live_edit')}
|
|
151
|
-
></Button>
|
|
152
|
-
{/if}
|
|
153
|
-
|
|
154
163
|
{#if form.nestedLevel === 0}
|
|
155
164
|
<LanguageSwitcher onLocalClick={onLocaleSwitch} />
|
|
156
165
|
{/if}
|
|
157
166
|
|
|
158
|
-
{#if
|
|
159
|
-
<ButtonStatus {form} />
|
|
160
|
-
{/if}
|
|
161
|
-
|
|
162
|
-
{#if form.values.id}
|
|
167
|
+
{#if config.versions && form.values.id}
|
|
163
168
|
{/* @ts-ignore form doc is GenericDoc as form.values.id is defined */ null}
|
|
164
|
-
<
|
|
169
|
+
<VersionMenu {form} />
|
|
165
170
|
{/if}
|
|
166
171
|
|
|
167
|
-
<ButtonSave {form} size="sm" />
|
|
172
|
+
<ButtonSave {form} size="sm" variant={canPublish ? 'secondary' : 'default'} />
|
|
173
|
+
|
|
174
|
+
{#if canPublish}
|
|
175
|
+
<ButtonPublish {form} />
|
|
176
|
+
{/if}
|
|
168
177
|
</div>
|
|
169
178
|
{/snippet}
|
|
170
179
|
</PageHeader>
|
|
@@ -172,7 +181,7 @@
|
|
|
172
181
|
<style>
|
|
173
182
|
/*
|
|
174
183
|
* The bar's buttons, 28px high: ghost ones in the muted ink, their icons subtler, both
|
|
175
|
-
* darkening on hover or while their menu is open; the
|
|
184
|
+
* darkening on hover or while their menu is open; the save buttons last, a little apart.
|
|
176
185
|
*/
|
|
177
186
|
.rz-document-actions {
|
|
178
187
|
--rz-button-ghost-fg: var(--rz-fg-muted);
|
|
@@ -186,16 +195,6 @@
|
|
|
186
195
|
padding-inline: var(--rz-size-2-5);
|
|
187
196
|
}
|
|
188
197
|
|
|
189
|
-
:global(.rz-button--size-icon-sm) {
|
|
190
|
-
width: var(--rz-size-7);
|
|
191
|
-
padding: 0;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
:global(.rz-button__icon) {
|
|
195
|
-
width: auto;
|
|
196
|
-
height: auto;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
198
|
:global(.rz-button--ghost svg) {
|
|
200
199
|
color: var(--rz-fg-subtle);
|
|
201
200
|
transition: color 0.15s;
|
|
@@ -213,10 +212,13 @@
|
|
|
213
212
|
color: var(--rz-fg);
|
|
214
213
|
}
|
|
215
214
|
|
|
216
|
-
:global(.rz-button--default) {
|
|
217
|
-
margin-left: var(--rz-size-1-5);
|
|
215
|
+
:global(:is(.rz-button--default, .rz-button--secondary)) {
|
|
218
216
|
padding-inline: var(--rz-size-3);
|
|
219
217
|
}
|
|
218
|
+
|
|
219
|
+
:global([data-submit]) {
|
|
220
|
+
margin-left: var(--rz-size-1-5);
|
|
221
|
+
}
|
|
220
222
|
}
|
|
221
223
|
|
|
222
224
|
.rz-auto-save-state {
|
|
@@ -231,10 +233,9 @@
|
|
|
231
233
|
color: var(--rz-warn);
|
|
232
234
|
}
|
|
233
235
|
|
|
234
|
-
/* On a narrow page the auto-save note
|
|
236
|
+
/* On a narrow page the auto-save note goes. */
|
|
235
237
|
@container main (max-width: 30rem) {
|
|
236
|
-
.rz-auto-save-state
|
|
237
|
-
.rz-document-actions :global(.rz-document-actions__open) {
|
|
238
|
+
.rz-auto-save-state {
|
|
238
239
|
display: none;
|
|
239
240
|
}
|
|
240
241
|
}
|
|
@@ -243,6 +244,56 @@
|
|
|
243
244
|
color: var(--rz-fg-subtle);
|
|
244
245
|
}
|
|
245
246
|
|
|
247
|
+
/*
|
|
248
|
+
* The title field as the heading: the heading's type and no box, as wide as its text. A line
|
|
249
|
+
* under it on hover, the accent's while typing, the danger's on an error.
|
|
250
|
+
*/
|
|
251
|
+
.rz-document-title-input {
|
|
252
|
+
/* One line of the heading, empty with its placeholder or filled. */
|
|
253
|
+
display: block;
|
|
254
|
+
height: 1lh;
|
|
255
|
+
field-sizing: content;
|
|
256
|
+
max-width: 100%;
|
|
257
|
+
padding: 0;
|
|
258
|
+
border: 0;
|
|
259
|
+
background: transparent;
|
|
260
|
+
color: inherit;
|
|
261
|
+
font: inherit;
|
|
262
|
+
letter-spacing: inherit;
|
|
263
|
+
line-height: inherit;
|
|
264
|
+
outline: none;
|
|
265
|
+
transition: box-shadow 0.15s;
|
|
266
|
+
|
|
267
|
+
&::-moz-placeholder {
|
|
268
|
+
color: var(--rz-fg-subtle);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&::placeholder {
|
|
272
|
+
color: var(--rz-fg-subtle);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
&:hover:not(:-moz-read-only) {
|
|
276
|
+
box-shadow: inset 0 -1px 0 var(--rz-border-strong);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
&:hover:not(:read-only) {
|
|
280
|
+
box-shadow: inset 0 -1px 0 var(--rz-border-strong);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
&:focus-visible {
|
|
284
|
+
box-shadow: inset 0 -2px 0 var(--rz-accent);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
&[aria-invalid] {
|
|
288
|
+
box-shadow: inset 0 -2px 0 var(--rz-danger);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.rz-document-title-error {
|
|
293
|
+
color: var(--rz-danger);
|
|
294
|
+
font-size: var(--rz-text-sm);
|
|
295
|
+
}
|
|
296
|
+
|
|
246
297
|
.rz-document-meta {
|
|
247
298
|
font-size: var(--rz-text-sm);
|
|
248
299
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { documentSegments } from '../../../util/url.js';
|
|
3
2
|
import { goto } from '$app/navigation';
|
|
4
3
|
import { PARAMS } from '../../../../core/constants.js';
|
|
5
4
|
import { canDuplicate } from '../../../../core/prototype/collection/can-duplicate.js';
|
|
6
|
-
import { VERSIONS_STATUS } from '../../../../core/prototype/shared/versions/constant.js';
|
|
7
5
|
import { apiUrl, panelPath } from '../../../../core/routes/util.js';
|
|
8
6
|
import * as Dialog from '../../ui/dialog/index.js';
|
|
9
7
|
import * as DropdownMenu from '../../ui/dropdown-menu/index.js';
|
|
@@ -12,94 +10,31 @@
|
|
|
12
10
|
import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
|
|
13
11
|
import { getLocaleContext } from '../../../context/locale.svelte.js';
|
|
14
12
|
import { titleOrUntitled } from '../../../util/title.js';
|
|
15
|
-
import { getVersionsContext } from '../../../context/versions.svelte.js';
|
|
16
13
|
import type { GenericDoc } from '../../../../types.js';
|
|
17
14
|
import { trycatchFetch } from '../../../../util/function.js';
|
|
18
15
|
import Copy from '@lucide/svelte/icons/copy';
|
|
19
16
|
import Ellipsis from '@lucide/svelte/icons/ellipsis';
|
|
20
17
|
import Hash from '@lucide/svelte/icons/hash';
|
|
21
|
-
import History from '@lucide/svelte/icons/history';
|
|
22
18
|
import Import from '@lucide/svelte/icons/import';
|
|
23
|
-
import
|
|
19
|
+
import PencilRuler from '@lucide/svelte/icons/pencil-ruler';
|
|
24
20
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
|
25
21
|
import { toast } from 'svelte-sonner';
|
|
26
22
|
import { t__ } from '../../../../core/i18n/index.js';
|
|
27
23
|
import Button from '../../ui/button/button.svelte';
|
|
28
|
-
import { versionsApiUrl, versionsListUrl } from './versions-list.js';
|
|
29
24
|
|
|
30
25
|
type Props = { form: DocumentFormContext<GenericDoc> };
|
|
31
26
|
|
|
32
27
|
const { form }: Props = $props();
|
|
33
28
|
|
|
34
29
|
let deleteConfirmOpen = $state(false);
|
|
35
|
-
let deleteVersionConfirmOpen = $state(false);
|
|
36
30
|
let dupplicateConfirmOpen = $state(false);
|
|
37
31
|
const isCollection = $derived(form.config.type === 'collection');
|
|
38
32
|
const allowDuplicate = $derived(canDuplicate(form.config));
|
|
39
33
|
const locale = getLocaleContext();
|
|
40
34
|
const APIProxy = getAPIProxyContext();
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* How many versions the document has, off the same list the history shows. A document keeps at
|
|
46
|
-
* least one, so its last version cannot be deleted.
|
|
47
|
-
*/
|
|
48
|
-
const versionsResource = $derived(
|
|
49
|
-
form.config.versions && form.values.id
|
|
50
|
-
? APIProxy.getRessource<{ docs: unknown[] }>(versionsListUrl(form.values))
|
|
51
|
-
: null
|
|
52
|
-
);
|
|
53
|
-
const canDeleteVersion = $derived((versionsResource?.data?.docs.length ?? 0) > 1);
|
|
54
|
-
|
|
55
|
-
/** One version goes; the document and its other versions stay. */
|
|
56
|
-
async function handleDeleteVersion() {
|
|
57
|
-
const response = await fetch(`${versionsApiUrl(form.config.slug)}/${form.values.versionId}`, {
|
|
58
|
-
method: 'DELETE'
|
|
59
|
-
});
|
|
60
|
-
deleteVersionConfirmOpen = false;
|
|
61
|
-
if (!response.ok) {
|
|
62
|
-
toast.error(t__('common.generic_error'));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
toast.success(t__('common.version_deleted'));
|
|
66
|
-
// The version history drops the deleted row. `apiUrl(kebab)` reaches `/api/<kebab>--versions`
|
|
67
|
-
// because `invalidate` matches by substring (api-proxy.svelte.ts).
|
|
68
|
-
APIProxy.invalidate(apiUrl(form.config.kebab));
|
|
69
|
-
// The plain address may be the one loaded: the loads rerun so the page lands on the newest row,
|
|
70
|
-
// and the form, which was on the deleted row, is rebuilt on it.
|
|
71
|
-
await goto(documentPath, { refreshAll: true });
|
|
72
|
-
history?.rebuildForm();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Sets a `data-*` attribute, or removes it when the value is `undefined`. */
|
|
76
|
-
function setData(element: HTMLElement, key: string, value: string | undefined) {
|
|
77
|
-
if (value === undefined) {
|
|
78
|
-
delete element.dataset[key];
|
|
79
|
-
} else {
|
|
80
|
-
element.dataset[key] = value;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Submits through the Save button as a new draft, then gives the button its own attributes back.
|
|
86
|
-
* The submit listener reads them before its first `await`, so they are back once it has.
|
|
87
|
-
*/
|
|
88
|
-
function handleNewDraft() {
|
|
89
|
-
if (form.readOnly || !form.element) return;
|
|
90
|
-
const saveButton = form.element.querySelector<HTMLButtonElement>('button[data-submit]');
|
|
91
|
-
if (!saveButton) return;
|
|
92
|
-
|
|
93
|
-
const { fork, status } = saveButton.dataset;
|
|
94
|
-
setData(saveButton, 'fork', 'true');
|
|
95
|
-
setData(saveButton, 'status', VERSIONS_STATUS.DRAFT);
|
|
96
|
-
form.element.requestSubmit(saveButton);
|
|
97
|
-
setData(saveButton, 'fork', fork);
|
|
98
|
-
setData(saveButton, 'status', status);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** The history lives on the document page; `undefined` where a document is shown without one. */
|
|
102
|
-
const history = getVersionsContext();
|
|
36
|
+
/** The live editor, opened on the page at its url; a read-only form shows it greyed. */
|
|
37
|
+
const live = $derived(form.config.live && form.values._live ? form.values._live : null);
|
|
103
38
|
|
|
104
39
|
async function handleDuplicate() {
|
|
105
40
|
if (Object.keys(form.changes).length) {
|
|
@@ -158,36 +93,14 @@
|
|
|
158
93
|
type Action = {
|
|
159
94
|
id: string;
|
|
160
95
|
label: string;
|
|
161
|
-
icon: typeof
|
|
96
|
+
icon: typeof Copy;
|
|
162
97
|
run: () => unknown;
|
|
163
98
|
/** A deletion: last, under a separator, in red. */
|
|
164
99
|
danger?: boolean;
|
|
165
|
-
/** Shown greyed in the menu, left out of the palette. */
|
|
166
|
-
disabled?: boolean;
|
|
167
100
|
};
|
|
168
101
|
|
|
169
|
-
/** The document's actions, the
|
|
102
|
+
/** The document's actions, the deletion last: the menu's entries and the palette's lines. */
|
|
170
103
|
const actions = $derived<Action[]>([
|
|
171
|
-
...(form.config.versions && history
|
|
172
|
-
? [
|
|
173
|
-
{
|
|
174
|
-
id: 'document.versions',
|
|
175
|
-
label: t__('common.versions_history'),
|
|
176
|
-
icon: History,
|
|
177
|
-
run: () => (history.open = true)
|
|
178
|
-
}
|
|
179
|
-
]
|
|
180
|
-
: []),
|
|
181
|
-
...(form.config.versions?.draft && form.values.status === VERSIONS_STATUS.PUBLISHED
|
|
182
|
-
? [
|
|
183
|
-
{
|
|
184
|
-
id: 'document.new_draft',
|
|
185
|
-
label: t__('common.save_new_draft'),
|
|
186
|
-
icon: Pickaxe,
|
|
187
|
-
run: handleNewDraft
|
|
188
|
-
}
|
|
189
|
-
]
|
|
190
|
-
: []),
|
|
191
104
|
...(allowDuplicate
|
|
192
105
|
? [
|
|
193
106
|
{
|
|
@@ -214,18 +127,6 @@
|
|
|
214
127
|
}
|
|
215
128
|
]
|
|
216
129
|
: []),
|
|
217
|
-
...(form.config.versions && form.values.versionId
|
|
218
|
-
? [
|
|
219
|
-
{
|
|
220
|
-
id: 'document.delete_version',
|
|
221
|
-
label: t__('common.delete_version'),
|
|
222
|
-
icon: Trash2,
|
|
223
|
-
danger: true,
|
|
224
|
-
disabled: !canDeleteVersion,
|
|
225
|
-
run: () => (deleteVersionConfirmOpen = true)
|
|
226
|
-
}
|
|
227
|
-
]
|
|
228
|
-
: []),
|
|
229
130
|
...(isCollection
|
|
230
131
|
? [
|
|
231
132
|
{
|
|
@@ -240,13 +141,20 @@
|
|
|
240
141
|
]);
|
|
241
142
|
|
|
242
143
|
useCommands(() =>
|
|
243
|
-
actions
|
|
244
|
-
|
|
245
|
-
|
|
144
|
+
actions.map(({ id, label, icon, run }) => ({
|
|
145
|
+
id,
|
|
146
|
+
label,
|
|
147
|
+
icon,
|
|
148
|
+
run,
|
|
149
|
+
group: t__('common.document')
|
|
150
|
+
}))
|
|
246
151
|
);
|
|
247
152
|
</script>
|
|
248
153
|
|
|
249
|
-
<!--
|
|
154
|
+
<!--
|
|
155
|
+
A ghost "⋯" after the document's title: the live editor first, then the document's actions,
|
|
156
|
+
the deletion last and in red.
|
|
157
|
+
-->
|
|
250
158
|
<DropdownMenu.Root>
|
|
251
159
|
<DropdownMenu.Trigger>
|
|
252
160
|
{#snippet child({ props })}
|
|
@@ -256,12 +164,28 @@
|
|
|
256
164
|
variant="ghost"
|
|
257
165
|
aria-label={t__('common.document_actions')}
|
|
258
166
|
{...props}
|
|
167
|
+
class="{props.class} rz-document-menu__trigger"
|
|
259
168
|
/>
|
|
260
169
|
{/snippet}
|
|
261
170
|
</DropdownMenu.Trigger>
|
|
262
171
|
|
|
263
172
|
<DropdownMenu.Portal>
|
|
264
|
-
<DropdownMenu.Content align="
|
|
173
|
+
<DropdownMenu.Content align="start" sideOffset={6} class="rz-document-menu">
|
|
174
|
+
{#if live}
|
|
175
|
+
<DropdownMenu.Item disabled={form.readOnly}>
|
|
176
|
+
{#snippet child({ props })}
|
|
177
|
+
<a
|
|
178
|
+
{...props}
|
|
179
|
+
class="{props.class} rz-document-menu__live"
|
|
180
|
+
href={form.readOnly ? undefined : live}
|
|
181
|
+
>
|
|
182
|
+
<PencilRuler size="14" />
|
|
183
|
+
{t__('common.live_edit')}
|
|
184
|
+
</a>
|
|
185
|
+
{/snippet}
|
|
186
|
+
</DropdownMenu.Item>
|
|
187
|
+
<DropdownMenu.Separator />
|
|
188
|
+
{/if}
|
|
265
189
|
{#each actions as action, index (action.id)}
|
|
266
190
|
{@const Icon = action.icon}
|
|
267
191
|
{#if action.danger && !actions[index - 1]?.danger}
|
|
@@ -269,7 +193,6 @@
|
|
|
269
193
|
{/if}
|
|
270
194
|
<DropdownMenu.Item
|
|
271
195
|
class={action.danger ? 'rz-document-menu__danger' : undefined}
|
|
272
|
-
disabled={action.disabled}
|
|
273
196
|
onclick={action.run}
|
|
274
197
|
>
|
|
275
198
|
<Icon size="14" />
|
|
@@ -295,21 +218,6 @@
|
|
|
295
218
|
</Dialog.Content>
|
|
296
219
|
</Dialog.Root>
|
|
297
220
|
|
|
298
|
-
<Dialog.Root bind:open={deleteVersionConfirmOpen}>
|
|
299
|
-
<Dialog.Content>
|
|
300
|
-
<Dialog.Header>
|
|
301
|
-
{t__('common.delete_version_dialog_title')}
|
|
302
|
-
</Dialog.Header>
|
|
303
|
-
<p>{t__('common.delete_version_dialog_text')}</p>
|
|
304
|
-
<Dialog.Footer>
|
|
305
|
-
<Button onclick={handleDeleteVersion} kbd="enter">{t__('common.delete_confirm')}</Button>
|
|
306
|
-
<Button onclick={() => (deleteVersionConfirmOpen = false)} variant="secondary" kbd="escape">
|
|
307
|
-
{t__('common.cancel')}
|
|
308
|
-
</Button>
|
|
309
|
-
</Dialog.Footer>
|
|
310
|
-
</Dialog.Content>
|
|
311
|
-
</Dialog.Root>
|
|
312
|
-
|
|
313
221
|
<Dialog.Root bind:open={dupplicateConfirmOpen}>
|
|
314
222
|
<Dialog.Content>
|
|
315
223
|
<Dialog.Header>
|
|
@@ -326,6 +234,15 @@
|
|
|
326
234
|
</Dialog.Root>
|
|
327
235
|
|
|
328
236
|
<style>
|
|
237
|
+
/* The "⋯" in the heading's ink, quieter until hovered or open. */
|
|
238
|
+
:global(.rz-document-menu__trigger) {
|
|
239
|
+
color: var(--rz-fg-subtle);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
:global(.rz-document-menu__trigger:is(:hover, [data-state='open'])) {
|
|
243
|
+
color: var(--rz-fg);
|
|
244
|
+
}
|
|
245
|
+
|
|
329
246
|
/* A floating card of 28px rows, each with a subtle icon; a deletion in red. */
|
|
330
247
|
:global(.rz-document-menu.rz-dropdown-content) {
|
|
331
248
|
min-width: var(--rz-size-52);
|