rimecms 1.4.3 → 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.
Files changed (63) hide show
  1. package/dist/core/auth/better-auth/config.server.d.ts +1 -1
  2. package/dist/core/auth/better-auth/instance.server.d.ts +2 -2
  3. package/dist/core/boot.server.d.ts +2 -2
  4. package/dist/core/i18n/en/common.d.ts +10 -4
  5. package/dist/core/i18n/en/common.js +12 -6
  6. package/dist/core/i18n/fr/common.d.ts +10 -4
  7. package/dist/core/i18n/fr/common.js +12 -7
  8. package/dist/core/prototype/shared/title/find-title.d.ts +9 -0
  9. package/dist/core/prototype/shared/title/find-title.js +20 -4
  10. package/dist/fields/group/component/Group.svelte +4 -3
  11. package/dist/fields/radio/component/Radio.svelte +19 -1
  12. package/dist/fields/radio/index.d.ts +23 -6
  13. package/dist/fields/radio/index.js +13 -1
  14. package/dist/fields/text/index.d.ts +11 -3
  15. package/dist/fields/text/index.js +11 -3
  16. package/dist/panel/components/fields/RenderFields.svelte +3 -2
  17. package/dist/panel/components/sections/collection/DropHint.svelte +41 -0
  18. package/dist/panel/components/sections/collection/DropHint.svelte.d.ts +7 -0
  19. package/dist/panel/components/sections/collection/grid/CollectionGrid.svelte +23 -3
  20. package/dist/panel/components/sections/collection/header/ButtonCreate.svelte +3 -3
  21. package/dist/panel/components/sections/collection/header/ButtonCreate.svelte.d.ts +1 -1
  22. package/dist/panel/components/sections/collection/list/CollectionList.svelte +8 -0
  23. package/dist/panel/components/sections/document/AutoSaveBanner.svelte +1 -1
  24. package/dist/panel/components/sections/document/ButtonPublish.svelte +39 -0
  25. package/dist/panel/components/sections/document/ButtonPublish.svelte.d.ts +7 -0
  26. package/dist/panel/components/sections/document/ButtonSave.svelte +6 -3
  27. package/dist/panel/components/sections/document/ButtonSave.svelte.d.ts +3 -1
  28. package/dist/panel/components/sections/document/Document.svelte +4 -13
  29. package/dist/panel/components/sections/document/DocumentChildren.svelte +1 -1
  30. package/dist/panel/components/sections/document/Header.svelte +116 -65
  31. package/dist/panel/components/sections/document/Settings.svelte +42 -125
  32. package/dist/panel/components/sections/document/VersionMenu.svelte +383 -0
  33. package/dist/panel/components/sections/document/VersionMenu.svelte.d.ts +8 -0
  34. package/dist/panel/components/sections/document/Versions.svelte +1 -1
  35. package/dist/panel/components/sections/document/Versions.svelte.d.ts +1 -1
  36. package/dist/panel/components/sections/document/version-status.d.ts +12 -0
  37. package/dist/panel/components/sections/document/version-status.js +33 -0
  38. package/dist/panel/components/sections/document/versions-list.d.ts +1 -1
  39. package/dist/panel/components/sections/document/versions-list.js +1 -1
  40. package/dist/panel/components/ui/calendar/calendar.svelte.d.ts +1 -1
  41. package/dist/panel/components/ui/checkbox/checkbox.svelte.d.ts +1 -1
  42. package/dist/panel/components/ui/page-header/PageHeader.svelte +39 -13
  43. package/dist/panel/components/ui/page-header/PageHeader.svelte.d.ts +4 -0
  44. package/dist/panel/components/ui/radio-card-group/index.d.ts +3 -0
  45. package/dist/panel/components/ui/radio-card-group/index.js +3 -0
  46. package/dist/panel/components/ui/radio-card-group/radio-card-group-item.svelte +30 -0
  47. package/dist/panel/components/ui/radio-card-group/radio-card-group-item.svelte.d.ts +9 -0
  48. package/dist/panel/components/ui/radio-card-group/radio-card-group.css +80 -0
  49. package/dist/panel/components/ui/radio-card-group/radio-card-group.svelte +18 -0
  50. package/dist/panel/components/ui/radio-card-group/radio-card-group.svelte.d.ts +5 -0
  51. package/dist/panel/components/ui/radio-row-group/radio-row-group.css +5 -3
  52. package/dist/panel/components/ui/switch/switch.svelte.d.ts +1 -1
  53. package/dist/panel/context/collection.svelte.d.ts +2 -2
  54. package/dist/panel/context/documentForm.svelte.d.ts +2 -0
  55. package/dist/panel/context/documentForm.svelte.js +12 -0
  56. package/dist/panel/context/versions.svelte.js +1 -1
  57. package/dist/panel/pages/collection/CollectionPage.svelte +37 -27
  58. package/dist/panel/pages/collection/CollectionPage.svelte.d.ts +1 -1
  59. package/dist/panel/style/index.css +0 -12
  60. package/dist/panel/style/scheme.css +0 -12
  61. package/package.json +1 -1
  62. package/dist/panel/components/sections/document/ButtonStatus.svelte +0 -158
  63. package/dist/panel/components/sections/document/ButtonStatus.svelte.d.ts +0 -7
@@ -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 Pickaxe from '@lucide/svelte/icons/pickaxe';
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
- const documentPath = $derived(panelPath(...documentSegments(form.config.kebab, form.values)));
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 History;
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 deletions last: the menu's entries and the palette's lines. */
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
- .filter((action) => !action.disabled)
245
- .map(({ id, label, icon, run }) => ({ id, label, icon, run, group: t__('common.document') }))
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
- <!-- A ghost "⋯": the document's actions, the deletions last and in red. -->
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="end" sideOffset={6} class="rz-document-menu">
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);
@@ -0,0 +1,383 @@
1
+ <script lang="ts">
2
+ import { goto } from '$app/navigation';
3
+ import { resolve } from '$app/paths';
4
+ import { PARAMS } from '../../../../core/constants.js';
5
+ import { t__ } from '../../../../core/i18n/index.js';
6
+ import { VERSIONS_STATUS } from '../../../../core/prototype/shared/versions/constant.js';
7
+ import { apiUrl, panelPath } from '../../../../core/routes/util.js';
8
+ import * as Dialog from '../../ui/dialog/index.js';
9
+ import * as DropdownMenu from '../../ui/dropdown-menu/index.js';
10
+ import { getAPIProxyContext } from '../../../context/api-proxy.svelte.js';
11
+ import { useCommands } from '../../../context/commands.svelte.js';
12
+ import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
13
+ import { getLocaleContext } from '../../../context/locale.svelte.js';
14
+ import { getUserContext } from '../../../context/user.svelte.js';
15
+ import { getVersionsContext } from '../../../context/versions.svelte.js';
16
+ import type { DocVersion } from '../../../index.js';
17
+ import { documentSegments } from '../../../util/url.js';
18
+ import type { GenericDoc } from '../../../../types.js';
19
+ import ChevronDown from '@lucide/svelte/icons/chevron-down';
20
+ import Eye from '@lucide/svelte/icons/eye';
21
+ import EyeOff from '@lucide/svelte/icons/eye-off';
22
+ import ExternalLink from '@lucide/svelte/icons/external-link';
23
+ import FilePlus from '@lucide/svelte/icons/file-plus';
24
+ import History from '@lucide/svelte/icons/history';
25
+ import Trash2 from '@lucide/svelte/icons/trash-2';
26
+ import { toast } from 'svelte-sonner';
27
+ import Button from '../../ui/button/button.svelte';
28
+ import StatusDot from '../collection/StatusDot.svelte';
29
+ import { setVersionStatus } from './version-status.js';
30
+ import { versionsApiUrl, versionsListUrl } from './versions-list.js';
31
+
32
+ type Props = { form: DocumentFormContext<GenericDoc> };
33
+ const { form }: Props = $props();
34
+
35
+ const APIProxy = getAPIProxyContext();
36
+ const locale = getLocaleContext();
37
+ const user = getUserContext();
38
+ /** The history lives on the document page; `undefined` where a document is shown without one. */
39
+ const history = getVersionsContext();
40
+
41
+ const drafts = $derived(!!form.config.versions?.draft);
42
+ const published = $derived(form.values.status === VERSIONS_STATUS.PUBLISHED);
43
+
44
+ const resource = $derived(
45
+ APIProxy.getRessource<{ docs: DocVersion[] }>(versionsListUrl(form.values))
46
+ );
47
+ const list = $derived(resource.data?.docs ?? []);
48
+ /** The newest rows; "All versions" opens the whole history. */
49
+ const recent = $derived(list.slice(0, 3));
50
+ /** A document keeps at least one version, so its last one cannot be deleted. */
51
+ const canDeleteVersion = $derived(list.length > 1);
52
+
53
+ /** The row the site shows: the newest published one with drafts, else the newest. */
54
+ const live = $derived(
55
+ list.find(
56
+ (version) => !version.isAutoSave && (!drafts || version.status === VERSIONS_STATUS.PUBLISHED)
57
+ )
58
+ );
59
+
60
+ /**
61
+ * The row on screen at its url, when the site shows another one:
62
+ * `https://site.com/news/hello?versionId=v2`.
63
+ */
64
+ const preview = $derived.by(() => {
65
+ const url = form.values.url;
66
+ if (!url || !form.values.versionId || live?.id === form.values.versionId) return null;
67
+ const href = new URL(url);
68
+ href.searchParams.set(PARAMS.VERSION_ID, String(form.values.versionId));
69
+ return href.href;
70
+ });
71
+
72
+ const documentPath = $derived(panelPath(...documentSegments(form.config.kebab, form.values)));
73
+ const versionPath = (versionId: string) => `${documentPath}?${PARAMS.VERSION_ID}=${versionId}`;
74
+
75
+ const who = (version: DocVersion) =>
76
+ version.updatedBy?.name || version.updatedBy?.email || t__('common.someone');
77
+ const when = (version: DocVersion) =>
78
+ locale.dateFormat(version.updatedAt, { short: true, withTime: true });
79
+
80
+ /**
81
+ * A row's two sides: an auto-save by whose typing it is, a version by its status with drafts,
82
+ * else by its date.
83
+ *
84
+ * ```
85
+ * Your auto-save 19 Nov 14:02
86
+ * Draft Admin · 19 Nov 14:02
87
+ * 19 Nov 14:02 Admin
88
+ * ```
89
+ */
90
+ function describe(version: DocVersion) {
91
+ if (version.isAutoSave) {
92
+ const label =
93
+ version.updatedBy?.id === user.attributes.id
94
+ ? t__('common.your_auto_save')
95
+ : t__('common.auto_save_by', who(version));
96
+ return { label, meta: when(version) };
97
+ }
98
+ if (drafts) {
99
+ return { label: t__(`common.${version.status}`), meta: `${who(version)} · ${when(version)}` };
100
+ }
101
+ return { label: when(version), meta: who(version) };
102
+ }
103
+
104
+ let deleteConfirmOpen = $state(false);
105
+
106
+ /** One version goes; the document and its other versions stay. */
107
+ async function deleteVersion() {
108
+ const response = await fetch(`${versionsApiUrl(form.config.slug)}/${form.values.versionId}`, {
109
+ method: 'DELETE'
110
+ });
111
+ deleteConfirmOpen = false;
112
+ if (!response.ok) {
113
+ toast.error(t__('common.generic_error'));
114
+ return;
115
+ }
116
+ toast.success(t__('common.version_deleted'));
117
+ // The version history drops the deleted row. `apiUrl(kebab)` reaches `/api/<kebab>--versions`
118
+ // because `invalidate` matches by substring (api-proxy.svelte.ts).
119
+ APIProxy.invalidate(apiUrl(form.config.kebab));
120
+ // The plain address may be the one loaded: the loads rerun so the page lands on the newest row,
121
+ // and the form, which was on the deleted row, is rebuilt on it.
122
+ await goto(documentPath, { refreshAll: true });
123
+ history?.rebuildForm();
124
+ }
125
+
126
+ /** Sets a `data-*` attribute, or removes it when the value is `undefined`. */
127
+ function setData(element: HTMLElement, key: string, value: string | undefined) {
128
+ if (value === undefined) {
129
+ delete element.dataset[key];
130
+ } else {
131
+ element.dataset[key] = value;
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Submits through the Save button as a new draft, then gives the button its own attributes back.
137
+ * The submit listener reads them before its first `await`, so they are back once it has.
138
+ */
139
+ function saveAsNewDraft() {
140
+ if (form.readOnly || !form.element) return;
141
+ const saveButton = form.element.querySelector<HTMLButtonElement>('button[data-submit]');
142
+ if (!saveButton) return;
143
+
144
+ const { fork, status } = saveButton.dataset;
145
+ setData(saveButton, 'fork', 'true');
146
+ setData(saveButton, 'status', VERSIONS_STATUS.DRAFT);
147
+ form.element.requestSubmit(saveButton);
148
+ setData(saveButton, 'fork', fork);
149
+ setData(saveButton, 'status', status);
150
+ }
151
+
152
+ const openHistory = () => {
153
+ if (history) history.open = true;
154
+ };
155
+
156
+ /** The version actions in the palette: the history, a new draft, the other status, a deletion. */
157
+ useCommands(() => [
158
+ ...(history
159
+ ? [
160
+ {
161
+ id: 'document.versions',
162
+ label: t__('common.versions_history'),
163
+ icon: History,
164
+ group: t__('common.document'),
165
+ run: openHistory
166
+ }
167
+ ]
168
+ : []),
169
+ ...(drafts && published
170
+ ? [
171
+ {
172
+ id: 'document.new_draft',
173
+ label: t__('common.save_new_draft'),
174
+ icon: FilePlus,
175
+ group: t__('common.document'),
176
+ run: saveAsNewDraft
177
+ }
178
+ ]
179
+ : []),
180
+ ...(drafts
181
+ ? Object.values(VERSIONS_STATUS)
182
+ .filter((status) => status !== form.values.status)
183
+ .map((status) => ({
184
+ id: `document.status.${status}`,
185
+ label: t__('common.mark_as', t__(`common.${status}`)),
186
+ group: t__('common.document'),
187
+ run: () => setVersionStatus(form, APIProxy, status)
188
+ }))
189
+ : []),
190
+ ...(form.values.versionId && canDeleteVersion
191
+ ? [
192
+ {
193
+ id: 'document.delete_version',
194
+ label: t__('common.delete_version'),
195
+ icon: Trash2,
196
+ group: t__('common.document'),
197
+ run: () => (deleteConfirmOpen = true)
198
+ }
199
+ ]
200
+ : [])
201
+ ]);
202
+ </script>
203
+
204
+ <!--
205
+ The row on screen and its history: with drafts its status, else "History". Opens on a preview of
206
+ the row when the site shows another, the newest versions, then what can be done with the row.
207
+ -->
208
+ <DropdownMenu.Root>
209
+ <DropdownMenu.Trigger>
210
+ {#snippet child({ props })}
211
+ <Button size="sm" variant="ghost" {...props} class="{props.class} rz-version-menu__trigger">
212
+ {#if drafts}
213
+ <StatusDot status={form.values.status} />
214
+ <span class="rz-version-menu__status">{t__(`common.${form.values.status}`)}</span>
215
+ {:else}
216
+ <History size="14" />
217
+ {t__('common.history')}
218
+ {/if}
219
+ <ChevronDown size="14" />
220
+ </Button>
221
+ {/snippet}
222
+ </DropdownMenu.Trigger>
223
+
224
+ <DropdownMenu.Portal>
225
+ <DropdownMenu.Content align="end" sideOffset={6} class="rz-document-menu rz-version-menu">
226
+ {#if preview}
227
+ <DropdownMenu.Item>
228
+ {#snippet child({ props })}
229
+ <a {...props} href={preview} target="_blank" rel="noreferrer">
230
+ <Eye size="14" />
231
+ <span class="rz-version-menu__grow">
232
+ {published ? t__('common.preview_version') : t__('common.preview_draft')}
233
+ </span>
234
+ <ExternalLink size="14" />
235
+ </a>
236
+ {/snippet}
237
+ </DropdownMenu.Item>
238
+ <DropdownMenu.Separator />
239
+ {/if}
240
+
241
+ <div class="rz-version-menu__heading">
242
+ <span>{t__('common.versions')}</span>
243
+ {#if history}
244
+ <DropdownMenu.Item class="rz-version-menu__all" onclick={openHistory}>
245
+ {t__('common.all_versions')}
246
+ </DropdownMenu.Item>
247
+ {/if}
248
+ </div>
249
+
250
+ {#each recent as version (version.id)}
251
+ {@const { label, meta } = describe(version)}
252
+ <DropdownMenu.Item>
253
+ {#snippet child({ props })}
254
+ <a
255
+ {...props}
256
+ href={resolve(versionPath(version.id))}
257
+ class="{props.class} rz-version-menu__row"
258
+ aria-current={version.id === form.values.versionId ? 'true' : undefined}
259
+ >
260
+ {#if drafts && !version.isAutoSave}
261
+ <StatusDot status={version.status} />
262
+ {/if}
263
+ <span class="rz-version-menu__grow">{label}</span>
264
+ {#if version.id === live?.id}
265
+ <span class="rz-version-menu__live">{t__('common.live')}</span>
266
+ {/if}
267
+ <span class="rz-version-menu__meta">{meta}</span>
268
+ </a>
269
+ {/snippet}
270
+ </DropdownMenu.Item>
271
+ {/each}
272
+
273
+ {#if drafts && !published && live}
274
+ <p class="rz-version-menu__note">
275
+ {t__('common.publish_replaces', locale.dateFormat(live.updatedAt, { short: true }))}
276
+ </p>
277
+ {/if}
278
+
279
+ {#if drafts && published}
280
+ <DropdownMenu.Separator />
281
+ <DropdownMenu.Item disabled={form.readOnly} onclick={saveAsNewDraft}>
282
+ <FilePlus size="14" />
283
+ {t__('common.save_new_draft')}
284
+ </DropdownMenu.Item>
285
+ <DropdownMenu.Item
286
+ disabled={form.readOnly}
287
+ onclick={() => setVersionStatus(form, APIProxy, VERSIONS_STATUS.DRAFT)}
288
+ >
289
+ <EyeOff size="14" />
290
+ {t__('common.unpublish')}
291
+ </DropdownMenu.Item>
292
+ {/if}
293
+
294
+ {#if form.values.versionId}
295
+ <DropdownMenu.Separator />
296
+ <DropdownMenu.Item
297
+ class="rz-document-menu__danger"
298
+ disabled={!canDeleteVersion || form.readOnly}
299
+ onclick={() => (deleteConfirmOpen = true)}
300
+ >
301
+ <Trash2 size="14" />
302
+ {drafts && !published ? t__('common.delete_draft') : t__('common.delete_version')}
303
+ </DropdownMenu.Item>
304
+ {/if}
305
+ </DropdownMenu.Content>
306
+ </DropdownMenu.Portal>
307
+ </DropdownMenu.Root>
308
+
309
+ <Dialog.Root bind:open={deleteConfirmOpen}>
310
+ <Dialog.Content>
311
+ <Dialog.Header>
312
+ {t__('common.delete_version_dialog_title')}
313
+ </Dialog.Header>
314
+ <p>{t__('common.delete_version_dialog_text')}</p>
315
+ <Dialog.Footer>
316
+ <Button onclick={deleteVersion} kbd="enter">{t__('common.delete_confirm')}</Button>
317
+ <Button onclick={() => (deleteConfirmOpen = false)} variant="secondary" kbd="escape">
318
+ {t__('common.cancel')}
319
+ </Button>
320
+ </Dialog.Footer>
321
+ </Dialog.Content>
322
+ </Dialog.Root>
323
+
324
+ <style>
325
+ /* The status as a ghost button: a small dot, its name, then a chevron. */
326
+ :global(.rz-version-menu__trigger) {
327
+ --rz-dot-size: var(--rz-size-1-5);
328
+ }
329
+
330
+ /* The document menu's card, wider: a row holds a name, a "Live" mark and who saved it, when. */
331
+ :global(.rz-version-menu.rz-dropdown-content) {
332
+ --rz-dot-size: var(--rz-size-1-5);
333
+ width: var(--rz-size-80);
334
+ }
335
+
336
+ :global(.rz-version-menu .rz-version-menu__grow) {
337
+ flex: 1;
338
+ min-width: 0;
339
+ overflow: hidden;
340
+ text-overflow: ellipsis;
341
+ }
342
+
343
+ /* "Versions", then "All versions" as a link at the end of the line. */
344
+ .rz-version-menu__heading {
345
+ display: flex;
346
+ align-items: center;
347
+ justify-content: space-between;
348
+ padding: var(--rz-size-1) var(--rz-size-1) var(--rz-size-1) var(--rz-size-2);
349
+ color: var(--rz-fg-muted);
350
+ font-size: var(--rz-text-xs);
351
+ }
352
+
353
+ :global(.rz-version-menu .rz-dropdown-item.rz-version-menu__all) {
354
+ height: var(--rz-size-6);
355
+ padding-inline: var(--rz-size-1-5);
356
+ color: var(--rz-accent-text);
357
+ font-size: var(--rz-text-xs);
358
+ }
359
+
360
+ :global(.rz-version-menu .rz-version-menu__row[aria-current='true']) {
361
+ background-color: var(--rz-bg-active);
362
+ }
363
+
364
+ .rz-version-menu__live {
365
+ padding: 0 var(--rz-size-1-5);
366
+ border-radius: var(--rz-radius-sm);
367
+ background-color: color-mix(in oklch, var(--rz-success) 14%, transparent);
368
+ color: var(--rz-success);
369
+ font-size: var(--rz-text-xs);
370
+ }
371
+
372
+ .rz-version-menu__meta {
373
+ color: var(--rz-fg-subtle);
374
+ font-size: var(--rz-text-xs);
375
+ font-variant-numeric: tabular-nums;
376
+ }
377
+
378
+ .rz-version-menu__note {
379
+ padding: var(--rz-size-1) var(--rz-size-2);
380
+ color: var(--rz-fg-subtle);
381
+ font-size: var(--rz-text-xs);
382
+ }
383
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
2
+ import type { GenericDoc } from '../../../../types.js';
3
+ type Props = {
4
+ form: DocumentFormContext<GenericDoc>;
5
+ };
6
+ declare const VersionMenu: import("svelte").Component<Props, {}, "">;
7
+ type VersionMenu = ReturnType<typeof VersionMenu>;
8
+ export default VersionMenu;
@@ -22,7 +22,7 @@
22
22
  import { versionsApiUrl, versionsListUrl } from './versions-list.js';
23
23
 
24
24
  /**
25
- * The document's version history, opened from the settings menu.
25
+ * The document's version history, opened from the version menu.
26
26
  *
27
27
  * `doc` is the row on screen: its `versionId` marks the active entry, and picking another entry
28
28
  * loads that row into the same page by `?versionId=`. The list comes from the API proxy, so an
@@ -1,6 +1,6 @@
1
1
  import type { GenericDoc } from '../../../../core/prototype/types.js';
2
2
  /**
3
- * The document's version history, opened from the settings menu.
3
+ * The document's version history, opened from the version menu.
4
4
  *
5
5
  * `doc` is the row on screen: its `versionId` marks the active entry, and picking another entry
6
6
  * loads that row into the same page by `?versionId=`. The list comes from the API proxy, so an
@@ -0,0 +1,12 @@
1
+ import type { VersionsStatus } from '../../../../core/prototype/shared/versions/constant.js';
2
+ import type { getAPIProxyContext } from '../../../context/api-proxy.svelte.js';
3
+ import type { DocumentFormContext } from '../../../context/documentForm.svelte.js';
4
+ /**
5
+ * Sets the status of the row on screen, without a save, then takes it into the form without
6
+ * dirtying it and reloads the page data and the version history.
7
+ *
8
+ * ```
9
+ * PATCH /api/news/n1?versionId=v2 { status: 'published' }
10
+ * ```
11
+ */
12
+ export declare function setVersionStatus(form: DocumentFormContext, APIProxy: ReturnType<typeof getAPIProxyContext>, next: VersionsStatus): Promise<void>;