pagescms 3.0.0 → 3.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/dist/package/reference/docs/configuration/content/view.md +2 -0
- package/dist/package/reference/docs/guides/editing.md +1 -1
- package/dist/package/reference/manifest.json +3 -3
- package/dist/types/features/content/unavailable-entry.d.ts +6 -0
- package/dist/types/features/drafts/draft-discard-dialog.d.ts +4 -1
- package/dist/types/features/drafts/draft-store.d.ts +1 -1
- package/dist/types/features/drafts/saved-draft-menu.d.ts +6 -0
- package/dist/types/features/repository/overview-draft-actions.d.ts +5 -0
- package/dist/types/features/repository/repository-route-state.d.ts +6 -2
- package/dist/types/lib/actions.d.ts +1 -0
- package/dist/types/server/access/repository.d.ts +4 -7
- package/dist/types/server/context-cloudflare.d.ts +4 -7
- package/dist/types/server/context-node.d.ts +4 -7
- package/dist/types/server/context.d.ts +4 -7
- package/dist/types/server/github/api.d.ts +4 -7
- package/dist/types/server/repository/provider.d.ts +1 -7
- package/docs/public/configuration/content/view.md +2 -0
- package/docs/public/guides/editing.md +1 -1
- package/package.json +1 -1
- package/public/reference/docs/configuration/content/view.md +2 -0
- package/public/reference/docs/guides/editing.md +1 -1
- package/public/reference/manifest.json +3 -3
- package/src/features/admin/action-run-status.tsx +4 -0
- package/src/features/collections/collection-table.tsx +6 -8
- package/src/features/content/unavailable-entry.tsx +64 -0
- package/src/features/drafts/draft-discard-dialog.tsx +6 -1
- package/src/features/drafts/draft-store.ts +7 -1
- package/src/features/drafts/saved-draft-menu.tsx +108 -0
- package/src/features/repository/overview-draft-actions.tsx +28 -0
- package/src/features/repository/overview-file-item.tsx +2 -0
- package/src/features/repository/overview-loading.tsx +1 -0
- package/src/features/repository/repository-route-state.tsx +18 -3
- package/src/i18n/known-errors.ts +12 -0
- package/src/lib/action-run-tracking.ts +1 -0
- package/src/lib/actions.ts +2 -0
- package/src/lib/configuration-reference.mjs +1 -1
- package/src/locales/de/messages.po +32 -0
- package/src/locales/en/messages.po +32 -0
- package/src/locales/es/messages.po +32 -0
- package/src/locales/fr/messages.po +32 -0
- package/src/locales/ja/messages.po +32 -0
- package/src/locales/pt-BR/messages.po +32 -0
- package/src/locales/zh-CN/messages.po +32 -0
- package/src/routes/github.$owner.$repo.$branch.collection.$name_.entry.$.tsx +10 -5
- package/src/server/actions/actions.ts +115 -128
- package/src/server/github/api.ts +15 -26
- package/src/server/repository/provider.ts +1 -7
- package/src/server/services/actions.ts +9 -2
|
@@ -34,6 +34,8 @@ description: Choose the columns, sorting, search and layout of a collection list
|
|
|
34
34
|
| `layout` | `list` (default) or `tree`. |
|
|
35
35
|
| `node` | Tree layout settings; see below. |
|
|
36
36
|
|
|
37
|
+
If you include `name` in `view.fields`, it shows the entry’s `name` field if you define one. Otherwise it shows the filename.
|
|
38
|
+
|
|
37
39
|
## Tree layout
|
|
38
40
|
|
|
39
41
|
For content organized as nested folders, such as documentation, `layout: tree` shows entries as an expandable tree. Each folder is represented by a node file inside it:
|
|
@@ -25,7 +25,7 @@ If something is missing, ask whoever manages the project.
|
|
|
25
25
|
|
|
26
26
|
Each save is a commit. When it reaches the live site depends on how the site is deployed.
|
|
27
27
|
|
|
28
|
-
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back.
|
|
28
|
+
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back. Open the editor’s **Draft** badge or the draft’s menu in **Overview → Drafts** to download or discard it. If the entry has moved or been deleted, **Page not found** also offers these actions when it finds a matching draft in this browser. Drafts don't sync to your other devices.
|
|
29
29
|
- **Conflicts.** If someone else saved the same file while you were editing, Pages CMS shows the conflicting fields. Pick a version for each, then save.
|
|
30
30
|
- **Rich text.** Switch between **Editor** and **Source**; both edit the same content. Type `/` to insert blocks and snippets.
|
|
31
31
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.
|
|
2
|
+
"version": "3.0.1",
|
|
3
3
|
"reference": "/reference.md",
|
|
4
4
|
"files": [
|
|
5
5
|
{
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"path": "docs/configuration/content/view.md",
|
|
27
|
-
"sha256": "
|
|
27
|
+
"sha256": "cd8928fe49eb95ca761fccc1b5c9b3f5ec31d622cc499007a31579f96dc944a8"
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"path": "docs/configuration/fields/block.md",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"path": "docs/guides/editing.md",
|
|
127
|
-
"sha256": "
|
|
127
|
+
"sha256": "f160b4ec6790c68250051cd12a9252c01bf53167ca0b82a361be928cec7b5d71"
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
"path": "docs/guides/media.md",
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
2
|
+
import { AlertDialogContent } from '../../components/ui/alert-dialog';
|
|
3
|
+
export declare function DraftDiscardDialog({ open, onOpenChange, onDiscard, onCloseAutoFocus, }: {
|
|
2
4
|
open: boolean;
|
|
3
5
|
onOpenChange: (open: boolean) => void;
|
|
4
6
|
onDiscard: () => Promise<void>;
|
|
7
|
+
onCloseAutoFocus?: ComponentProps<typeof AlertDialogContent>['onCloseAutoFocus'];
|
|
5
8
|
}): import("react").JSX.Element;
|
|
@@ -36,7 +36,7 @@ export interface ContentDraft<T = unknown> {
|
|
|
36
36
|
}
|
|
37
37
|
export declare function readDraft<T>(key: string): Promise<ContentDraft<T> | undefined>;
|
|
38
38
|
export declare function writeDraft<T>(draft: Omit<ContentDraft<T>, 'revision'>, revision: number): Promise<number>;
|
|
39
|
-
export declare function discardDraft(key: string, revision: number): Promise<void>;
|
|
39
|
+
export declare function discardDraft(key: string, revision: number, updatedAt?: number): Promise<void>;
|
|
40
40
|
export declare function listOverviewEntries(store: 'summaries' | 'recent', account: string, target: Pick<DraftTarget, 'repoId' | 'owner' | 'repo' | 'branch'>, source: string): Promise<EntrySummary[]>;
|
|
41
41
|
export declare function recordOpened(entry: EntrySummary): Promise<void>;
|
|
42
42
|
export declare function contentDraftKey(account: string, source: string, target: DraftTarget, creationId?: string): string;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ErrorComponentProps, NotFoundRouteProps } from '@tanstack/react-router';
|
|
3
|
+
export declare function RepositoryNotFound({ descriptionSuffix, actions, }?: Partial<NotFoundRouteProps> & {
|
|
4
|
+
descriptionSuffix?: ReactNode;
|
|
5
|
+
actions?: ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
3
7
|
export declare function RepositoryError({ reset }: ErrorComponentProps): import("react").JSX.Element;
|
|
4
8
|
export declare function RepositoryAccessDenied(): import("react").JSX.Element;
|
|
@@ -214,13 +214,10 @@ export declare function createRepositoryAccessService(input: {
|
|
|
214
214
|
workflow: string;
|
|
215
215
|
ref: string;
|
|
216
216
|
inputs: Record<string, string>;
|
|
217
|
-
}): Promise<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
workflow: string;
|
|
222
|
-
ref: string;
|
|
223
|
-
}): Promise<import("../github/api").GitHubWorkflowRun[]>;
|
|
217
|
+
}): Promise<{
|
|
218
|
+
id: number;
|
|
219
|
+
htmlUrl: string | null;
|
|
220
|
+
} | null>;
|
|
224
221
|
getWorkflowRun(owner: string, repo: string, runId: number): Promise<import("../github/api").GitHubWorkflowRun>;
|
|
225
222
|
cancelWorkflowRun(owner: string, repo: string, runId: number): Promise<void>;
|
|
226
223
|
listFileCommits(owner: string, repo: string, branch: string, path: string, page?: number): Promise<import("../repository/provider").RepositoryCommitSummary[]>;
|
|
@@ -292,13 +292,10 @@ export declare function createRequestServicesForRequest(request: Request, respon
|
|
|
292
292
|
workflow: string;
|
|
293
293
|
ref: string;
|
|
294
294
|
inputs: Record<string, string>;
|
|
295
|
-
}): Promise<
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
workflow: string;
|
|
300
|
-
ref: string;
|
|
301
|
-
}): Promise<import("./github/api").GitHubWorkflowRun[]>;
|
|
295
|
+
}): Promise<{
|
|
296
|
+
id: number;
|
|
297
|
+
htmlUrl: string | null;
|
|
298
|
+
} | null>;
|
|
302
299
|
getWorkflowRun(owner: string, repo: string, runId: number): Promise<import("./github/api").GitHubWorkflowRun>;
|
|
303
300
|
cancelWorkflowRun(owner: string, repo: string, runId: number): Promise<void>;
|
|
304
301
|
listFileCommits(owner: string, repo: string, branch: string, path: string, page?: number): Promise<import("./repository/provider").RepositoryCommitSummary[]>;
|
|
@@ -294,13 +294,10 @@ export declare function createRequestServicesForRequest(request: Request, respon
|
|
|
294
294
|
workflow: string;
|
|
295
295
|
ref: string;
|
|
296
296
|
inputs: Record<string, string>;
|
|
297
|
-
}): Promise<
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
workflow: string;
|
|
302
|
-
ref: string;
|
|
303
|
-
}): Promise<import("./github/api").GitHubWorkflowRun[]>;
|
|
297
|
+
}): Promise<{
|
|
298
|
+
id: number;
|
|
299
|
+
htmlUrl: string | null;
|
|
300
|
+
} | null>;
|
|
304
301
|
getWorkflowRun(owner: string, repo: string, runId: number): Promise<import("./github/api").GitHubWorkflowRun>;
|
|
305
302
|
cancelWorkflowRun(owner: string, repo: string, runId: number): Promise<void>;
|
|
306
303
|
listFileCommits(owner: string, repo: string, branch: string, path: string, page?: number): Promise<import("./repository/provider").RepositoryCommitSummary[]>;
|
|
@@ -336,13 +336,10 @@ export declare function createRequestServices(environment: unknown, requestHeade
|
|
|
336
336
|
workflow: string;
|
|
337
337
|
ref: string;
|
|
338
338
|
inputs: Record<string, string>;
|
|
339
|
-
}): Promise<
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
workflow: string;
|
|
344
|
-
ref: string;
|
|
345
|
-
}): Promise<import("./github/api").GitHubWorkflowRun[]>;
|
|
339
|
+
}): Promise<{
|
|
340
|
+
id: number;
|
|
341
|
+
htmlUrl: string | null;
|
|
342
|
+
} | null>;
|
|
346
343
|
getWorkflowRun(owner: string, repo: string, runId: number): Promise<import("./github/api").GitHubWorkflowRun>;
|
|
347
344
|
cancelWorkflowRun(owner: string, repo: string, runId: number): Promise<void>;
|
|
348
345
|
listFileCommits(owner: string, repo: string, branch: string, path: string, page?: number): Promise<import("./repository/provider").RepositoryCommitSummary[]>;
|
|
@@ -193,13 +193,10 @@ export declare function createGitHubApi(token: string, fetcher?: typeof fetch, r
|
|
|
193
193
|
workflow: string;
|
|
194
194
|
ref: string;
|
|
195
195
|
inputs: Record<string, string>;
|
|
196
|
-
}): Promise<
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
workflow: string;
|
|
201
|
-
ref: string;
|
|
202
|
-
}): Promise<GitHubWorkflowRun[]>;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
id: number;
|
|
198
|
+
htmlUrl: string | null;
|
|
199
|
+
} | null>;
|
|
203
200
|
getWorkflowRun(owner: string, repo: string, runId: number): Promise<GitHubWorkflowRun>;
|
|
204
201
|
cancelWorkflowRun(owner: string, repo: string, runId: number): Promise<void>;
|
|
205
202
|
listFileCommits(owner: string, repo: string, branch: string, path: string, page?: number): Promise<RepositoryCommitSummary[]>;
|
|
@@ -136,13 +136,7 @@ export interface RepositoryApi {
|
|
|
136
136
|
workflow: string;
|
|
137
137
|
ref: string;
|
|
138
138
|
inputs: Record<string, string>;
|
|
139
|
-
}) => Promise<
|
|
140
|
-
listWorkflowRuns: (input: {
|
|
141
|
-
owner: string;
|
|
142
|
-
repo: string;
|
|
143
|
-
workflow: string;
|
|
144
|
-
ref: string;
|
|
145
|
-
}) => Promise<RepositoryWorkflowRun[]>;
|
|
139
|
+
}) => Promise<Pick<RepositoryWorkflowRun, 'id' | 'htmlUrl'> | null>;
|
|
146
140
|
getWorkflowRun: (owner: string, repo: string, runId: number) => Promise<RepositoryWorkflowRun>;
|
|
147
141
|
cancelWorkflowRun: (owner: string, repo: string, runId: number) => Promise<void>;
|
|
148
142
|
}
|
|
@@ -34,6 +34,8 @@ description: Choose the columns, sorting, search and layout of a collection list
|
|
|
34
34
|
| `layout` | `list` (default) or `tree`. |
|
|
35
35
|
| `node` | Tree layout settings; see below. |
|
|
36
36
|
|
|
37
|
+
If you include `name` in `view.fields`, it shows the entry’s `name` field if you define one. Otherwise it shows the filename.
|
|
38
|
+
|
|
37
39
|
## Tree layout
|
|
38
40
|
|
|
39
41
|
For content organized as nested folders, such as documentation, `layout: tree` shows entries as an expandable tree. Each folder is represented by a node file inside it:
|
|
@@ -25,7 +25,7 @@ If something is missing, ask whoever manages the project.
|
|
|
25
25
|
|
|
26
26
|
Each save is a commit. When it reaches the live site depends on how the site is deployed.
|
|
27
27
|
|
|
28
|
-
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back.
|
|
28
|
+
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back. Open the editor’s **Draft** badge or the draft’s menu in **Overview → Drafts** to download or discard it. If the entry has moved or been deleted, **Page not found** also offers these actions when it finds a matching draft in this browser. Drafts don't sync to your other devices.
|
|
29
29
|
- **Conflicts.** If someone else saved the same file while you were editing, Pages CMS shows the conflicting fields. Pick a version for each, then save.
|
|
30
30
|
- **Rich text.** Switch between **Editor** and **Source**; both edit the same content. Type `/` to insert blocks and snippets.
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -34,6 +34,8 @@ description: Choose the columns, sorting, search and layout of a collection list
|
|
|
34
34
|
| `layout` | `list` (default) or `tree`. |
|
|
35
35
|
| `node` | Tree layout settings; see below. |
|
|
36
36
|
|
|
37
|
+
If you include `name` in `view.fields`, it shows the entry’s `name` field if you define one. Otherwise it shows the filename.
|
|
38
|
+
|
|
37
39
|
## Tree layout
|
|
38
40
|
|
|
39
41
|
For content organized as nested folders, such as documentation, `layout: tree` shows entries as an expandable tree. Each folder is represented by a node file inside it:
|
|
@@ -25,7 +25,7 @@ If something is missing, ask whoever manages the project.
|
|
|
25
25
|
|
|
26
26
|
Each save is a commit. When it reaches the live site depends on how the site is deployed.
|
|
27
27
|
|
|
28
|
-
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back.
|
|
28
|
+
- **Drafts.** Unsaved changes stay in your browser, so you can close the tab and come back. Open the editor’s **Draft** badge or the draft’s menu in **Overview → Drafts** to download or discard it. If the entry has moved or been deleted, **Page not found** also offers these actions when it finds a matching draft in this browser. Drafts don't sync to your other devices.
|
|
29
29
|
- **Conflicts.** If someone else saved the same file while you were editing, Pages CMS shows the conflicting fields. Pick a version for each, then save.
|
|
30
30
|
- **Rich text.** Switch between **Editor** and **Source**; both edit the same content. Type `/` to insert blocks and snippets.
|
|
31
31
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.
|
|
2
|
+
"version": "3.0.1",
|
|
3
3
|
"reference": "/reference.md",
|
|
4
4
|
"files": [
|
|
5
5
|
{
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"path": "docs/configuration/content/view.md",
|
|
27
|
-
"sha256": "
|
|
27
|
+
"sha256": "cd8928fe49eb95ca761fccc1b5c9b3f5ec31d622cc499007a31579f96dc944a8"
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"path": "docs/configuration/fields/block.md",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"path": "docs/guides/editing.md",
|
|
127
|
-
"sha256": "
|
|
127
|
+
"sha256": "f160b4ec6790c68250051cd12a9252c01bf53167ca0b82a361be928cec7b5d71"
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
"path": "docs/guides/media.md",
|
|
@@ -29,6 +29,10 @@ const statuses = {
|
|
|
29
29
|
icon: CircleAlert,
|
|
30
30
|
},
|
|
31
31
|
stale: { label: msg({ message: 'Stale' }), icon: CircleAlert },
|
|
32
|
+
tracking_unavailable: {
|
|
33
|
+
label: msg({ message: 'Run status unavailable' }),
|
|
34
|
+
icon: CircleAlert,
|
|
35
|
+
},
|
|
32
36
|
startup_failure: {
|
|
33
37
|
label: msg({ message: 'Startup failure' }),
|
|
34
38
|
icon: CircleX,
|
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
rowSearchValue,
|
|
85
85
|
} from './collection-model'
|
|
86
86
|
|
|
87
|
-
import type { CollectionViewModel } from './collection-model'
|
|
87
|
+
import type { CollectionColumn, CollectionViewModel } from './collection-model'
|
|
88
88
|
|
|
89
89
|
type CollectionData = Awaited<ReturnType<typeof getCollection>>
|
|
90
90
|
export type CollectionItem = CollectionData['contents'][number]
|
|
@@ -140,10 +140,10 @@ function batches<T>(values: T[], size: number) {
|
|
|
140
140
|
)
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function entryValue(entry: CollectionItem,
|
|
143
|
+
function entryValue(entry: CollectionItem, column: CollectionColumn) {
|
|
144
144
|
if (entry.type === 'dir') return
|
|
145
|
-
if (
|
|
146
|
-
return collectionValue(entry.fields, path)
|
|
145
|
+
if (column.systemLabel === 'name') return entry.name
|
|
146
|
+
return collectionValue(entry.fields, column.path)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function pageOptions(current: number, count: number) {
|
|
@@ -294,7 +294,7 @@ export function CollectionTable({
|
|
|
294
294
|
const fluidColumn = collectionFluidColumn(model)
|
|
295
295
|
const columns = useMemo(() => {
|
|
296
296
|
const valueColumns = model.columns.map((column, index) =>
|
|
297
|
-
helper.accessor((entry) => entryValue(entry, column
|
|
297
|
+
helper.accessor((entry) => entryValue(entry, column), {
|
|
298
298
|
id: column.path,
|
|
299
299
|
enableGlobalFilter: false,
|
|
300
300
|
enableSorting: model.sortFields.includes(column.path),
|
|
@@ -617,9 +617,7 @@ export function CollectionTable({
|
|
|
617
617
|
if (!settings) return []
|
|
618
618
|
const values = new Set<string>()
|
|
619
619
|
for (const { original: entry } of rows) {
|
|
620
|
-
const [first] = collectionReferenceValues(
|
|
621
|
-
entryValue(entry, column.path),
|
|
622
|
-
)
|
|
620
|
+
const [first] = collectionReferenceValues(entryValue(entry, column))
|
|
623
621
|
if (first) values.add(first)
|
|
624
622
|
}
|
|
625
623
|
return batches([...values].sort(), 100).map((selectedValues) => ({
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Trans as UiTrans } from '@lingui/react/macro'
|
|
2
|
+
import ChevronDown from '@hugeicons/core-free-icons/ArrowDown01Icon'
|
|
3
|
+
import { HugeiconsIcon } from '@hugeicons/react'
|
|
4
|
+
import { useQuery } from '@tanstack/react-query'
|
|
5
|
+
import { useEffect } from 'react'
|
|
6
|
+
import { authenticationQueryOptions } from '#/client/queries/session'
|
|
7
|
+
import { Button } from '#/components/ui/button'
|
|
8
|
+
import { contentDraftKey, readDraft } from '#/features/drafts/draft-store'
|
|
9
|
+
import type { DraftTarget } from '#/features/drafts/draft-store'
|
|
10
|
+
import { SavedDraftMenu } from '#/features/drafts/saved-draft-menu'
|
|
11
|
+
import { RepositoryNotFound } from '#/features/repository/repository-route-state'
|
|
12
|
+
|
|
13
|
+
export function UnavailableEntry({
|
|
14
|
+
coordinates,
|
|
15
|
+
}: {
|
|
16
|
+
coordinates: DraftTarget & { source?: string }
|
|
17
|
+
}) {
|
|
18
|
+
const { data: auth } = useQuery({
|
|
19
|
+
...authenticationQueryOptions(),
|
|
20
|
+
enabled: false,
|
|
21
|
+
})
|
|
22
|
+
const account = auth?.user?.id
|
|
23
|
+
const key =
|
|
24
|
+
account && coordinates.source && coordinates.repoId && coordinates.path
|
|
25
|
+
? contentDraftKey(account, coordinates.source, coordinates)
|
|
26
|
+
: undefined
|
|
27
|
+
const { data: hasDraft, refetch } = useQuery({
|
|
28
|
+
queryKey: ['pagescms', 'unavailable-entry-draft', key],
|
|
29
|
+
queryFn: async () => (key ? Boolean(await readDraft(key)) : false),
|
|
30
|
+
enabled: key !== undefined,
|
|
31
|
+
retry: false,
|
|
32
|
+
refetchOnWindowFocus: false,
|
|
33
|
+
})
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!key) return
|
|
36
|
+
const refresh = () => void refetch()
|
|
37
|
+
window.addEventListener('pagescms:drafts', refresh)
|
|
38
|
+
window.addEventListener('focus', refresh)
|
|
39
|
+
return () => {
|
|
40
|
+
window.removeEventListener('pagescms:drafts', refresh)
|
|
41
|
+
window.removeEventListener('focus', refresh)
|
|
42
|
+
}
|
|
43
|
+
}, [key, refetch])
|
|
44
|
+
if (!account || !key || !hasDraft) return <RepositoryNotFound />
|
|
45
|
+
return (
|
|
46
|
+
<RepositoryNotFound
|
|
47
|
+
descriptionSuffix={
|
|
48
|
+
<UiTrans>You still have a draft in this browser.</UiTrans>
|
|
49
|
+
}
|
|
50
|
+
actions={
|
|
51
|
+
<SavedDraftMenu key={key} account={account} draftKey={key}>
|
|
52
|
+
<Button type="button" size="sm" variant="outline">
|
|
53
|
+
<UiTrans>Manage draft</UiTrans>
|
|
54
|
+
<HugeiconsIcon
|
|
55
|
+
aria-hidden="true"
|
|
56
|
+
data-icon="inline-end"
|
|
57
|
+
icon={ChevronDown}
|
|
58
|
+
/>
|
|
59
|
+
</Button>
|
|
60
|
+
</SavedDraftMenu>
|
|
61
|
+
}
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Trans as UiTrans, useLingui } from '@lingui/react/macro'
|
|
2
2
|
import { Spinner } from '#/components/ui/spinner'
|
|
3
3
|
import { useState } from 'react'
|
|
4
|
+
import type { ComponentProps } from 'react'
|
|
4
5
|
import { withErrorNotification } from '#/lib/notifications'
|
|
5
6
|
import {
|
|
6
7
|
AlertDialog,
|
|
@@ -17,10 +18,14 @@ export function DraftDiscardDialog({
|
|
|
17
18
|
open,
|
|
18
19
|
onOpenChange,
|
|
19
20
|
onDiscard,
|
|
21
|
+
onCloseAutoFocus,
|
|
20
22
|
}: {
|
|
21
23
|
open: boolean
|
|
22
24
|
onOpenChange: (open: boolean) => void
|
|
23
25
|
onDiscard: () => Promise<void>
|
|
26
|
+
onCloseAutoFocus?: ComponentProps<
|
|
27
|
+
typeof AlertDialogContent
|
|
28
|
+
>['onCloseAutoFocus']
|
|
24
29
|
}) {
|
|
25
30
|
const { t: _t } = useLingui()
|
|
26
31
|
const [busy, setBusy] = useState(false)
|
|
@@ -49,7 +54,7 @@ export function DraftDiscardDialog({
|
|
|
49
54
|
|
|
50
55
|
return (
|
|
51
56
|
<AlertDialog open={open} onOpenChange={close}>
|
|
52
|
-
<AlertDialogContent>
|
|
57
|
+
<AlertDialogContent onCloseAutoFocus={onCloseAutoFocus}>
|
|
53
58
|
<AlertDialogHeader>
|
|
54
59
|
<AlertDialogTitle>
|
|
55
60
|
<UiTrans>Discard local draft?</UiTrans>
|
|
@@ -197,6 +197,7 @@ export async function writeDraft<T>(
|
|
|
197
197
|
export async function discardDraft(
|
|
198
198
|
key: string,
|
|
199
199
|
revision: number,
|
|
200
|
+
updatedAt?: number,
|
|
200
201
|
): Promise<void> {
|
|
201
202
|
const db = await openDatabase()
|
|
202
203
|
return new Promise((resolve, reject) => {
|
|
@@ -206,7 +207,12 @@ export async function discardDraft(
|
|
|
206
207
|
let conflict = false
|
|
207
208
|
request.onsuccess = () => {
|
|
208
209
|
const existing = request.result as ContentDraft | undefined
|
|
209
|
-
if (
|
|
210
|
+
if (
|
|
211
|
+
existing &&
|
|
212
|
+
(existing.revision !== revision ||
|
|
213
|
+
(updatedAt !== undefined &&
|
|
214
|
+
existing.summary?.updatedAt !== updatedAt))
|
|
215
|
+
) {
|
|
210
216
|
conflict = true
|
|
211
217
|
transaction.abort()
|
|
212
218
|
return
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Trans as UiTrans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { useRef, useState } from 'react'
|
|
4
|
+
import type { ReactElement } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
DropdownMenuContent,
|
|
8
|
+
DropdownMenuItem,
|
|
9
|
+
DropdownMenuTrigger,
|
|
10
|
+
} from '#/components/ui/dropdown-menu'
|
|
11
|
+
import {
|
|
12
|
+
accountIsActive,
|
|
13
|
+
assertOperationAccount,
|
|
14
|
+
} from '#/features/pending-writes/account-operation'
|
|
15
|
+
import { withErrorNotification } from '#/lib/notifications'
|
|
16
|
+
import { DraftDiscardDialog } from './draft-discard-dialog'
|
|
17
|
+
import { downloadDraft } from './draft-session'
|
|
18
|
+
import { discardDraft, readDraft } from './draft-store'
|
|
19
|
+
|
|
20
|
+
export function SavedDraftMenu({
|
|
21
|
+
account,
|
|
22
|
+
draftKey,
|
|
23
|
+
children,
|
|
24
|
+
}: {
|
|
25
|
+
account: string
|
|
26
|
+
draftKey: string
|
|
27
|
+
children: ReactElement
|
|
28
|
+
}) {
|
|
29
|
+
const { t: _t } = useLingui()
|
|
30
|
+
const client = useQueryClient()
|
|
31
|
+
const active = accountIsActive(client, account)
|
|
32
|
+
const trigger = useRef<HTMLButtonElement>(null)
|
|
33
|
+
const [confirmation, setConfirmation] = useState<{
|
|
34
|
+
revision: number
|
|
35
|
+
updatedAt?: number
|
|
36
|
+
} | null>(null)
|
|
37
|
+
|
|
38
|
+
async function savedDraft() {
|
|
39
|
+
assertOperationAccount(client, account)
|
|
40
|
+
const draft = await readDraft(draftKey)
|
|
41
|
+
assertOperationAccount(client, account)
|
|
42
|
+
return draft
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function download() {
|
|
46
|
+
const failure = _t({ message: 'Could not download this draft.' })
|
|
47
|
+
void withErrorNotification(
|
|
48
|
+
async () => {
|
|
49
|
+
const draft = await savedDraft()
|
|
50
|
+
if (!draft) throw new Error(failure)
|
|
51
|
+
downloadDraft(draft)
|
|
52
|
+
},
|
|
53
|
+
failure,
|
|
54
|
+
{ active },
|
|
55
|
+
).catch(() => {})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function confirmDiscard() {
|
|
59
|
+
void withErrorNotification(
|
|
60
|
+
async () => {
|
|
61
|
+
const draft = await savedDraft()
|
|
62
|
+
setConfirmation({
|
|
63
|
+
revision: draft?.revision ?? 0,
|
|
64
|
+
updatedAt: draft?.summary?.updatedAt,
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
_t({ message: 'Could not discard this draft.' }),
|
|
68
|
+
{ active },
|
|
69
|
+
).catch(() => {})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<DropdownMenu modal={false}>
|
|
75
|
+
<DropdownMenuTrigger asChild ref={trigger}>
|
|
76
|
+
{children}
|
|
77
|
+
</DropdownMenuTrigger>
|
|
78
|
+
<DropdownMenuContent align="end">
|
|
79
|
+
<DropdownMenuItem onSelect={download}>
|
|
80
|
+
<UiTrans>Download draft</UiTrans>
|
|
81
|
+
</DropdownMenuItem>
|
|
82
|
+
<DropdownMenuItem variant="destructive" onSelect={confirmDiscard}>
|
|
83
|
+
<UiTrans>Discard draft</UiTrans>
|
|
84
|
+
</DropdownMenuItem>
|
|
85
|
+
</DropdownMenuContent>
|
|
86
|
+
</DropdownMenu>
|
|
87
|
+
<DraftDiscardDialog
|
|
88
|
+
open={confirmation !== null}
|
|
89
|
+
onOpenChange={(open) => {
|
|
90
|
+
if (!open) setConfirmation(null)
|
|
91
|
+
}}
|
|
92
|
+
onCloseAutoFocus={(event) => {
|
|
93
|
+
event.preventDefault()
|
|
94
|
+
trigger.current?.focus()
|
|
95
|
+
}}
|
|
96
|
+
onDiscard={async () => {
|
|
97
|
+
if (!confirmation) return
|
|
98
|
+
assertOperationAccount(client, account)
|
|
99
|
+
await discardDraft(
|
|
100
|
+
draftKey,
|
|
101
|
+
confirmation.revision,
|
|
102
|
+
confirmation.updatedAt,
|
|
103
|
+
)
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
</>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useLingui as useUiMessages } from '@lingui/react/macro'
|
|
2
|
+
import { HugeiconsIcon } from '@hugeicons/react'
|
|
3
|
+
import EllipsisVertical from '@hugeicons/core-free-icons/EllipsisVerticalIcon'
|
|
4
|
+
import { Button } from '#/components/ui/button'
|
|
5
|
+
import type { EntrySummary } from '#/features/drafts/draft-store'
|
|
6
|
+
import { SavedDraftMenu } from '#/features/drafts/saved-draft-menu'
|
|
7
|
+
|
|
8
|
+
export function OverviewDraftActions({
|
|
9
|
+
entry,
|
|
10
|
+
title,
|
|
11
|
+
}: {
|
|
12
|
+
entry: EntrySummary
|
|
13
|
+
title: string
|
|
14
|
+
}) {
|
|
15
|
+
const { t: _t } = useUiMessages()
|
|
16
|
+
return (
|
|
17
|
+
<SavedDraftMenu account={entry.account} draftKey={entry.key}>
|
|
18
|
+
<Button
|
|
19
|
+
type="button"
|
|
20
|
+
size="icon-sm"
|
|
21
|
+
variant="ghost"
|
|
22
|
+
aria-label={_t({ message: `Actions for ${title}` })}
|
|
23
|
+
>
|
|
24
|
+
<HugeiconsIcon aria-hidden="true" icon={EllipsisVertical} />
|
|
25
|
+
</Button>
|
|
26
|
+
</SavedDraftMenu>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '#/components/ui/tooltip'
|
|
15
15
|
import { relativeAge } from '#/features/drafts/relative-age'
|
|
16
16
|
import type { EntrySummary } from '#/features/drafts/draft-store'
|
|
17
|
+
import { OverviewDraftActions } from './overview-draft-actions'
|
|
17
18
|
import {
|
|
18
19
|
overviewBreadcrumbLabel,
|
|
19
20
|
overviewEntryBreadcrumb,
|
|
@@ -108,6 +109,7 @@ export function OverviewFileItem({
|
|
|
108
109
|
</TooltipTrigger>
|
|
109
110
|
<TooltipContent>{detail}</TooltipContent>
|
|
110
111
|
</Tooltip>
|
|
112
|
+
{draft ? <OverviewDraftActions entry={entry} title={title} /> : null}
|
|
111
113
|
</li>
|
|
112
114
|
)
|
|
113
115
|
}
|
|
@@ -86,6 +86,7 @@ export function OverviewFilesSkeleton({ draft = false }: { draft?: boolean }) {
|
|
|
86
86
|
<Skeleton className="hidden h-5 w-24 shrink-0 rounded-full sm:block" />
|
|
87
87
|
</div>
|
|
88
88
|
<Skeleton className="h-4 w-14 shrink-0" />
|
|
89
|
+
{draft ? <Skeleton className="size-7 shrink-0" /> : null}
|
|
89
90
|
</li>
|
|
90
91
|
))}
|
|
91
92
|
</ul>
|