@nuasite/collections-admin 0.43.0-beta.4 → 0.43.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/dist/types/app.d.ts +11 -6
- package/dist/types/app.d.ts.map +1 -1
- package/dist/types/entry-create.d.ts +1 -1
- package/dist/types/entry-create.d.ts.map +1 -1
- package/dist/types/entry-editor.d.ts +1 -1
- package/dist/types/entry-editor.d.ts.map +1 -1
- package/dist/types/field-editor.d.ts +1 -1
- package/dist/types/field-editor.d.ts.map +1 -1
- package/dist/types/media-picker.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/app.tsx +181 -109
- package/src/entry-editor.tsx +224 -36
- package/src/field-editor.tsx +54 -5
- package/src/media-picker.tsx +16 -2
- package/src/styles.css +220 -1
- package/src/tsconfig.json +1 -0
- package/dist/types/app.js +0 -240
- package/dist/types/client.d.ts +0 -149
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/client.js +0 -134
- package/dist/types/field-view.d.ts +0 -17
- package/dist/types/field-view.d.ts.map +0 -1
- package/dist/types/field-view.js +0 -77
- package/dist/types/form-model.d.ts +0 -61
- package/dist/types/form-model.d.ts.map +0 -1
- package/dist/types/index.js +0 -8
package/src/styles.css
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
position: relative;
|
|
20
20
|
display: flex;
|
|
21
|
-
flex-direction:
|
|
21
|
+
flex-direction: row;
|
|
22
22
|
height: 100%;
|
|
23
23
|
min-height: 0;
|
|
24
24
|
color: var(--nua-cadmin-fg);
|
|
@@ -35,6 +35,115 @@
|
|
|
35
35
|
box-sizing: border-box;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/* --- Sidebar: content-type menu --- */
|
|
39
|
+
|
|
40
|
+
.nua-cadmin-sidebar {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
width: 240px;
|
|
44
|
+
flex-shrink: 0;
|
|
45
|
+
min-height: 0;
|
|
46
|
+
border-right: 1px solid var(--nua-cadmin-border);
|
|
47
|
+
background: var(--nua-cadmin-bg-subtle);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.nua-cadmin-sidebar-head {
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: space-between;
|
|
54
|
+
gap: 8px;
|
|
55
|
+
padding: 12px 14px;
|
|
56
|
+
flex-shrink: 0;
|
|
57
|
+
border-bottom: 1px solid var(--nua-cadmin-border);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.nua-cadmin-brand {
|
|
61
|
+
font-size: 13px;
|
|
62
|
+
font-weight: 700;
|
|
63
|
+
letter-spacing: 0.02em;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.nua-cadmin-nav {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
gap: 1px;
|
|
70
|
+
padding: 8px;
|
|
71
|
+
overflow-y: auto;
|
|
72
|
+
min-height: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.nua-cadmin-nav-item {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: space-between;
|
|
79
|
+
gap: 8px;
|
|
80
|
+
width: 100%;
|
|
81
|
+
padding: 7px 10px;
|
|
82
|
+
border: none;
|
|
83
|
+
border-radius: 6px;
|
|
84
|
+
background: transparent;
|
|
85
|
+
color: var(--nua-cadmin-fg);
|
|
86
|
+
text-align: left;
|
|
87
|
+
font-size: 13px;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.nua-cadmin-nav-item:hover {
|
|
92
|
+
background: var(--nua-cadmin-border);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.nua-cadmin-nav-item.is-active {
|
|
96
|
+
background: var(--nua-cadmin-accent);
|
|
97
|
+
color: #ffffff;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.nua-cadmin-nav-label {
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
text-overflow: ellipsis;
|
|
103
|
+
white-space: nowrap;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.nua-cadmin-nav-count {
|
|
107
|
+
flex-shrink: 0;
|
|
108
|
+
padding: 0 7px;
|
|
109
|
+
border: 1px solid var(--nua-cadmin-border);
|
|
110
|
+
border-radius: 999px;
|
|
111
|
+
background: var(--nua-cadmin-bg);
|
|
112
|
+
color: var(--nua-cadmin-muted);
|
|
113
|
+
font-size: 11px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.nua-cadmin-nav-item.is-active .nua-cadmin-nav-count {
|
|
117
|
+
border-color: transparent;
|
|
118
|
+
background: rgba(255, 255, 255, 0.2);
|
|
119
|
+
color: #ffffff;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.nua-cadmin-nav-state {
|
|
123
|
+
padding: 10px;
|
|
124
|
+
color: var(--nua-cadmin-muted);
|
|
125
|
+
font-size: 12px;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.nua-cadmin-nav-error {
|
|
129
|
+
width: 100%;
|
|
130
|
+
border: none;
|
|
131
|
+
background: transparent;
|
|
132
|
+
text-align: left;
|
|
133
|
+
color: var(--nua-cadmin-danger);
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* --- Main pane --- */
|
|
138
|
+
|
|
139
|
+
.nua-cadmin-main {
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
flex: 1;
|
|
143
|
+
min-width: 0;
|
|
144
|
+
min-height: 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
38
147
|
/* --- Header / breadcrumb bar --- */
|
|
39
148
|
|
|
40
149
|
.nua-cadmin-header {
|
|
@@ -403,6 +512,13 @@ select.nua-cadmin-input:focus {
|
|
|
403
512
|
min-height: 64px;
|
|
404
513
|
}
|
|
405
514
|
|
|
515
|
+
/* Autosizing textareas drive their own height from content (JS), so no manual
|
|
516
|
+
resize handle and no inner scrollbar. */
|
|
517
|
+
.nua-cadmin-textarea-autosize {
|
|
518
|
+
resize: none;
|
|
519
|
+
overflow-y: hidden;
|
|
520
|
+
}
|
|
521
|
+
|
|
406
522
|
.nua-cadmin-body-editor {
|
|
407
523
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
408
524
|
font-size: 12px;
|
|
@@ -628,6 +744,109 @@ select.nua-cadmin-input:focus {
|
|
|
628
744
|
color: var(--nua-cadmin-muted);
|
|
629
745
|
}
|
|
630
746
|
|
|
747
|
+
/* --- Field grid (width-aware: `width: 'half'` shares a row) --- */
|
|
748
|
+
|
|
749
|
+
.nua-cadmin-field-grid {
|
|
750
|
+
display: grid;
|
|
751
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
752
|
+
gap: 10px 12px;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
.nua-cadmin-field-grid > .nua-cadmin-field {
|
|
756
|
+
grid-column: 1 / -1;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
.nua-cadmin-field-grid > .nua-cadmin-field-half {
|
|
760
|
+
grid-column: span 1;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/* The sidebar is narrow — always a single column there. */
|
|
764
|
+
.nua-cadmin-editor-sidebar .nua-cadmin-field-grid {
|
|
765
|
+
grid-template-columns: 1fr;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
@media (max-width: 640px) {
|
|
769
|
+
.nua-cadmin-field-grid > .nua-cadmin-field-half {
|
|
770
|
+
grid-column: 1 / -1;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
.nua-cadmin-field-help {
|
|
775
|
+
font-size: 11px;
|
|
776
|
+
color: var(--nua-cadmin-muted);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/* --- Collapsible sections (stacked display) --- */
|
|
780
|
+
|
|
781
|
+
.nua-cadmin-section {
|
|
782
|
+
border: 1px solid var(--nua-cadmin-border);
|
|
783
|
+
border-radius: 8px;
|
|
784
|
+
background: var(--nua-cadmin-bg-subtle);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
.nua-cadmin-section-summary {
|
|
788
|
+
padding: 9px 12px;
|
|
789
|
+
font-weight: 600;
|
|
790
|
+
cursor: pointer;
|
|
791
|
+
list-style: none;
|
|
792
|
+
user-select: none;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
.nua-cadmin-section-summary::-webkit-details-marker {
|
|
796
|
+
display: none;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
.nua-cadmin-section-summary::before {
|
|
800
|
+
content: "▸";
|
|
801
|
+
display: inline-block;
|
|
802
|
+
margin-right: 8px;
|
|
803
|
+
color: var(--nua-cadmin-muted);
|
|
804
|
+
transition: transform 0.15s;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
.nua-cadmin-section[open] > .nua-cadmin-section-summary::before {
|
|
808
|
+
transform: rotate(90deg);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
.nua-cadmin-section-body {
|
|
812
|
+
padding: 2px 12px 12px;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/* --- Tabs (tabbed display) --- */
|
|
816
|
+
|
|
817
|
+
.nua-cadmin-tabs {
|
|
818
|
+
display: flex;
|
|
819
|
+
flex-direction: column;
|
|
820
|
+
gap: 14px;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
.nua-cadmin-tabbar {
|
|
824
|
+
display: flex;
|
|
825
|
+
flex-wrap: wrap;
|
|
826
|
+
gap: 2px;
|
|
827
|
+
border-bottom: 1px solid var(--nua-cadmin-border);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
.nua-cadmin-tab {
|
|
831
|
+
padding: 7px 12px;
|
|
832
|
+
border: none;
|
|
833
|
+
border-bottom: 2px solid transparent;
|
|
834
|
+
background: transparent;
|
|
835
|
+
color: var(--nua-cadmin-muted);
|
|
836
|
+
font-size: 12px;
|
|
837
|
+
font-weight: 600;
|
|
838
|
+
cursor: pointer;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
.nua-cadmin-tab:hover {
|
|
842
|
+
color: var(--nua-cadmin-fg);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
.nua-cadmin-tab.is-active {
|
|
846
|
+
color: var(--nua-cadmin-accent);
|
|
847
|
+
border-bottom-color: var(--nua-cadmin-accent);
|
|
848
|
+
}
|
|
849
|
+
|
|
631
850
|
/* --- Buttons --- */
|
|
632
851
|
|
|
633
852
|
.nua-cadmin-btn {
|
package/src/tsconfig.json
CHANGED
package/dist/types/app.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* collections-admin SPA — read-only milestone (cms-headless F3.1).
|
|
3
|
-
*
|
|
4
|
-
* Host-agnostic: driven only by an `apiBase` prop, with internal view-state
|
|
5
|
-
* navigation (list → entries → detail) via React state — never the host router.
|
|
6
|
-
* That keeps the same component usable as a webmaster tab today and at
|
|
7
|
-
* `/_nua/admin` for local dev later (F7).
|
|
8
|
-
*
|
|
9
|
-
* Read-only: browse collections, list entries (sparse projection + cursor
|
|
10
|
-
* pagination), and view a single entry's frontmatter + markdown body. Mutations
|
|
11
|
-
* (editor/media/conflict) arrive in F3.2.
|
|
12
|
-
*/
|
|
13
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
-
import { CmsClientError, createClient } from './client';
|
|
15
|
-
import { FieldRow } from './field-view';
|
|
16
|
-
import './styles.css';
|
|
17
|
-
function useAsync(load, deps) {
|
|
18
|
-
const [state, setState] = useState({ data: null, error: null, loading: true });
|
|
19
|
-
const [nonce, setNonce] = useState(0);
|
|
20
|
-
const loadRef = useRef(load);
|
|
21
|
-
loadRef.current = load;
|
|
22
|
-
// `load` is read through a ref; re-runs are driven by the explicit `deps` and
|
|
23
|
-
// the reload `nonce` so the effect deps stay stable and lint-clean.
|
|
24
|
-
const effectDeps = [...deps, nonce];
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
let active = true;
|
|
27
|
-
setState({ data: null, error: null, loading: true });
|
|
28
|
-
loadRef.current().then((data) => {
|
|
29
|
-
if (active)
|
|
30
|
-
setState({ data, error: null, loading: false });
|
|
31
|
-
}, (error) => {
|
|
32
|
-
if (active)
|
|
33
|
-
setState({ data: null, error: error instanceof Error ? error : new Error(String(error)), loading: false });
|
|
34
|
-
});
|
|
35
|
-
return () => {
|
|
36
|
-
active = false;
|
|
37
|
-
};
|
|
38
|
-
}, effectDeps);
|
|
39
|
-
const reload = useCallback(() => setNonce((n) => n + 1), []);
|
|
40
|
-
return { ...state, reload };
|
|
41
|
-
}
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// Presentational primitives
|
|
44
|
-
// ============================================================================
|
|
45
|
-
function Spinner({ label }) {
|
|
46
|
-
return (<div className="nua-cadmin-state">
|
|
47
|
-
<div className="nua-cadmin-spinner"/>
|
|
48
|
-
<div>{label}</div>
|
|
49
|
-
</div>);
|
|
50
|
-
}
|
|
51
|
-
function ErrorState({ error, onRetry }) {
|
|
52
|
-
const title = error instanceof CmsClientError && error.isUnauthorized
|
|
53
|
-
? 'Session expired'
|
|
54
|
-
: error instanceof CmsClientError && error.isForbidden
|
|
55
|
-
? 'No access'
|
|
56
|
-
: 'Something went wrong';
|
|
57
|
-
return (<div className="nua-cadmin-error">
|
|
58
|
-
<div className="nua-cadmin-error-title">{title}</div>
|
|
59
|
-
<div>{error.message}</div>
|
|
60
|
-
{onRetry ? <button type="button" className="nua-cadmin-retry" onClick={onRetry}>Try again</button> : null}
|
|
61
|
-
</div>);
|
|
62
|
-
}
|
|
63
|
-
function EmptyState({ label }) {
|
|
64
|
-
return <div className="nua-cadmin-state">{label}</div>;
|
|
65
|
-
}
|
|
66
|
-
// ============================================================================
|
|
67
|
-
// Collection list
|
|
68
|
-
// ============================================================================
|
|
69
|
-
function CollectionList({ client, onOpen }) {
|
|
70
|
-
const { data, error, loading, reload } = useAsync(() => client.getCollections(), [client]);
|
|
71
|
-
if (loading)
|
|
72
|
-
return <Spinner label="Loading collections…"/>;
|
|
73
|
-
if (error)
|
|
74
|
-
return <ErrorState error={error} onRetry={reload}/>;
|
|
75
|
-
if (!data || data.length === 0)
|
|
76
|
-
return <EmptyState label="No collections found in this project."/>;
|
|
77
|
-
return (<div className="nua-cadmin-list">
|
|
78
|
-
{data.map((collection) => (<button key={collection.name} type="button" className="nua-cadmin-card" onClick={() => onOpen(collection.name)}>
|
|
79
|
-
<span className="nua-cadmin-card-main">
|
|
80
|
-
<span className="nua-cadmin-card-label">{collection.label || collection.name}</span>
|
|
81
|
-
<span className="nua-cadmin-card-sub">
|
|
82
|
-
{collection.name}
|
|
83
|
-
{collection.type ? ` · ${collection.type}` : ''}
|
|
84
|
-
{` · ${collection.fileExtension}`}
|
|
85
|
-
</span>
|
|
86
|
-
</span>
|
|
87
|
-
<span className="nua-cadmin-badge">{collection.entryCount} {collection.entryCount === 1 ? 'entry' : 'entries'}</span>
|
|
88
|
-
</button>))}
|
|
89
|
-
</div>);
|
|
90
|
-
}
|
|
91
|
-
// ============================================================================
|
|
92
|
-
// Entries table (sparse projection + cursor pagination)
|
|
93
|
-
// ============================================================================
|
|
94
|
-
const ENTRIES_PAGE_SIZE = 50;
|
|
95
|
-
const ENTRIES_FIELDS = 'slug,title,draft,pathname';
|
|
96
|
-
function EntriesTable({ client, collection, onOpen }) {
|
|
97
|
-
const [rows, setRows] = useState([]);
|
|
98
|
-
const [cursor, setCursor] = useState(undefined);
|
|
99
|
-
const [hasMore, setHasMore] = useState(false);
|
|
100
|
-
const [error, setError] = useState(null);
|
|
101
|
-
const [loading, setLoading] = useState(true);
|
|
102
|
-
const [loadingMore, setLoadingMore] = useState(false);
|
|
103
|
-
const loadPage = useCallback(async (nextCursor, append) => {
|
|
104
|
-
if (append)
|
|
105
|
-
setLoadingMore(true);
|
|
106
|
-
else
|
|
107
|
-
setLoading(true);
|
|
108
|
-
setError(null);
|
|
109
|
-
try {
|
|
110
|
-
const result = await client.getEntries(collection, {
|
|
111
|
-
fields: ENTRIES_FIELDS,
|
|
112
|
-
draft: 'all',
|
|
113
|
-
limit: ENTRIES_PAGE_SIZE,
|
|
114
|
-
cursor: nextCursor,
|
|
115
|
-
});
|
|
116
|
-
setRows((prev) => (append ? [...prev, ...result.entries] : result.entries));
|
|
117
|
-
setCursor(result.cursor);
|
|
118
|
-
setHasMore(result.hasMore);
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
setError(e instanceof Error ? e : new Error(String(e)));
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
setLoading(false);
|
|
125
|
-
setLoadingMore(false);
|
|
126
|
-
}
|
|
127
|
-
}, [client, collection]);
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
setRows([]);
|
|
130
|
-
setCursor(undefined);
|
|
131
|
-
setHasMore(false);
|
|
132
|
-
void loadPage(undefined, false);
|
|
133
|
-
}, [loadPage]);
|
|
134
|
-
if (loading)
|
|
135
|
-
return <Spinner label="Loading entries…"/>;
|
|
136
|
-
if (error)
|
|
137
|
-
return <ErrorState error={error} onRetry={() => void loadPage(undefined, false)}/>;
|
|
138
|
-
if (rows.length === 0)
|
|
139
|
-
return <EmptyState label="This collection has no entries."/>;
|
|
140
|
-
return (<div>
|
|
141
|
-
<table className="nua-cadmin-table">
|
|
142
|
-
<thead>
|
|
143
|
-
<tr>
|
|
144
|
-
<th>Slug</th>
|
|
145
|
-
<th>Title</th>
|
|
146
|
-
<th>Draft</th>
|
|
147
|
-
<th>Pathname</th>
|
|
148
|
-
</tr>
|
|
149
|
-
</thead>
|
|
150
|
-
<tbody>
|
|
151
|
-
{rows.map((entry) => (<tr key={entry.slug} className="nua-cadmin-row" onClick={() => onOpen(entry.slug)}>
|
|
152
|
-
<td className="nua-cadmin-cell-mono">{entry.slug}</td>
|
|
153
|
-
<td>{entry.title ?? <span className="nua-cadmin-field-empty">—</span>}</td>
|
|
154
|
-
<td>{entry.draft ? <span className="nua-cadmin-badge nua-cadmin-badge-draft">draft</span> : ''}</td>
|
|
155
|
-
<td className="nua-cadmin-cell-mono">{entry.pathname ?? '—'}</td>
|
|
156
|
-
</tr>))}
|
|
157
|
-
</tbody>
|
|
158
|
-
</table>
|
|
159
|
-
{hasMore ? (<button type="button" className="nua-cadmin-load-more" disabled={loadingMore} onClick={() => void loadPage(cursor, true)}>
|
|
160
|
-
{loadingMore ? 'Loading…' : 'Load more'}
|
|
161
|
-
</button>) : null}
|
|
162
|
-
</div>);
|
|
163
|
-
}
|
|
164
|
-
// ============================================================================
|
|
165
|
-
// Entry detail
|
|
166
|
-
// ============================================================================
|
|
167
|
-
/**
|
|
168
|
-
* Order the collection's fields for display: `publish-toggle`/`publish-date`
|
|
169
|
-
* roles and `sidebar`/`header` positioned fields first, then the rest in schema
|
|
170
|
-
* order. Hidden fields are dropped.
|
|
171
|
-
*/
|
|
172
|
-
function orderFields(fields) {
|
|
173
|
-
const visible = fields.filter((f) => !f.hidden);
|
|
174
|
-
const pinned = visible.filter((f) => f.role !== undefined || f.position !== undefined);
|
|
175
|
-
const rest = visible.filter((f) => f.role === undefined && f.position === undefined);
|
|
176
|
-
return [...pinned, ...rest];
|
|
177
|
-
}
|
|
178
|
-
function EntryDetail({ client, collections, collection, slug }) {
|
|
179
|
-
const { data, error, loading, reload } = useAsync(() => client.getEntry(collection, slug), [client, collection, slug]);
|
|
180
|
-
const def = useMemo(() => collections.find((c) => c.name === collection), [collections, collection]);
|
|
181
|
-
if (loading)
|
|
182
|
-
return <Spinner label="Loading entry…"/>;
|
|
183
|
-
if (error)
|
|
184
|
-
return <ErrorState error={error} onRetry={reload}/>;
|
|
185
|
-
if (!data)
|
|
186
|
-
return <EmptyState label="Entry not found."/>;
|
|
187
|
-
const fieldDefs = def ? orderFields(def.fields) : [];
|
|
188
|
-
const renderedNames = new Set(fieldDefs.map((f) => f.name));
|
|
189
|
-
// Frontmatter keys present on the entry but absent from the inferred schema.
|
|
190
|
-
const extraKeys = Object.keys(data.frontmatter).filter((k) => !renderedNames.has(k));
|
|
191
|
-
return (<div>
|
|
192
|
-
<div className="nua-cadmin-fields">
|
|
193
|
-
{fieldDefs.length === 0 && extraKeys.length === 0 ? <EmptyState label="No frontmatter fields."/> : null}
|
|
194
|
-
{fieldDefs.map((field) => (<FieldRow key={field.name} field={field} raw={data.frontmatter[field.name]?.value}/>))}
|
|
195
|
-
{extraKeys.map((key) => (<FieldRow key={key} field={{ name: key, type: 'text', required: false }} raw={data.frontmatter[key]?.value}/>))}
|
|
196
|
-
</div>
|
|
197
|
-
|
|
198
|
-
<h3 className="nua-cadmin-section-title">Body</h3>
|
|
199
|
-
{data.body.trim() === ''
|
|
200
|
-
? <EmptyState label="This entry has no markdown body."/>
|
|
201
|
-
: <pre className="nua-cadmin-body-content">{data.body}</pre>}
|
|
202
|
-
</div>);
|
|
203
|
-
}
|
|
204
|
-
export function CollectionsAdminApp({ apiBase, onClose }) {
|
|
205
|
-
const client = useMemo(() => createClient(apiBase), [apiBase]);
|
|
206
|
-
const [state, setState] = useState({ view: 'list' });
|
|
207
|
-
// The collection definitions are needed by the detail view to drive field
|
|
208
|
-
// rendering; load them once at the root and pass down.
|
|
209
|
-
const collectionsState = useAsync(() => client.getCollections(), [client]);
|
|
210
|
-
const collections = collectionsState.data ?? [];
|
|
211
|
-
const goList = useCallback(() => setState({ view: 'list' }), []);
|
|
212
|
-
const goEntries = useCallback((collection) => setState({ view: 'entries', collection }), []);
|
|
213
|
-
const goDetail = useCallback((collection, slug) => setState({ view: 'detail', collection, slug }), []);
|
|
214
|
-
const activeCollection = state.view !== 'list'
|
|
215
|
-
? collections.find((c) => c.name === state.collection)
|
|
216
|
-
: undefined;
|
|
217
|
-
const collectionLabel = activeCollection ? (activeCollection.label || activeCollection.name) : (state.view !== 'list' ? state.collection : '');
|
|
218
|
-
return (<div className="nua-cadmin">
|
|
219
|
-
<div className="nua-cadmin-header">
|
|
220
|
-
{state.view === 'entries' ? (<button type="button" className="nua-cadmin-back" onClick={goList}>← Collections</button>) : null}
|
|
221
|
-
{state.view === 'detail' ? (<button type="button" className="nua-cadmin-back" onClick={() => goEntries(state.collection)}>← {collectionLabel}</button>) : null}
|
|
222
|
-
|
|
223
|
-
{state.view === 'list' ? <h2 className="nua-cadmin-title">Collections</h2> : null}
|
|
224
|
-
{state.view === 'entries' ? <h2 className="nua-cadmin-title">{collectionLabel}</h2> : null}
|
|
225
|
-
{state.view === 'detail' ? (<h2 className="nua-cadmin-title">
|
|
226
|
-
{collectionLabel}
|
|
227
|
-
<span className="nua-cadmin-crumb"> / {state.slug}</span>
|
|
228
|
-
</h2>) : null}
|
|
229
|
-
|
|
230
|
-
<span className="nua-cadmin-spacer"/>
|
|
231
|
-
{onClose ? <button type="button" className="nua-cadmin-close" aria-label="Close" onClick={onClose}>×</button> : null}
|
|
232
|
-
</div>
|
|
233
|
-
|
|
234
|
-
<div className="nua-cadmin-body">
|
|
235
|
-
{state.view === 'list' ? <CollectionList client={client} onOpen={goEntries}/> : null}
|
|
236
|
-
{state.view === 'entries' ? <EntriesTable client={client} collection={state.collection} onOpen={(slug) => goDetail(state.collection, slug)}/> : null}
|
|
237
|
-
{state.view === 'detail' ? <EntryDetail client={client} collections={collections} collection={state.collection} slug={state.slug}/> : null}
|
|
238
|
-
</div>
|
|
239
|
-
</div>);
|
|
240
|
-
}
|
package/dist/types/client.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed client over the cms-sidecar `/cms/v1` HTTP contract (reads + mutations).
|
|
3
|
-
*
|
|
4
|
-
* The host (webmaster BFF, or a local dev proxy in F7) mounts the sidecar under
|
|
5
|
-
* an `apiBase` and adds the `/cms/v1` prefix itself — so this client requests
|
|
6
|
-
* `${apiBase}/project`, `${apiBase}/collections`, etc. (never `/cms/v1/...`).
|
|
7
|
-
*
|
|
8
|
-
* The structural model (collections/entries/fields) is reused 1:1 from
|
|
9
|
-
* `@nuasite/cms-types`. The thin HTTP envelope (project model, sparse entries
|
|
10
|
-
* list, error codes, mutation bodies, conflict response) mirrors the sidecar's
|
|
11
|
-
* wire types; it is declared here because those types are not part of the
|
|
12
|
-
* `@nuasite/cms-types` contract surface.
|
|
13
|
-
*/
|
|
14
|
-
import type { CollectionDefinition, CollectionEntry, CollectionEntryInfo, MediaListResult, MediaUploadResult, MutationResult } from '@nuasite/cms-types';
|
|
15
|
-
/** Stable error codes the sidecar exposes, each mapped to an HTTP status. */
|
|
16
|
-
export type CmsErrorCode = 'not_found' | 'conflict' | 'validation' | 'parse_error' | 'io_error' | 'unsupported' | 'unauthorized';
|
|
17
|
-
/** JSON body returned for every non-2xx response that is not a conflict. */
|
|
18
|
-
export interface CmsApiError {
|
|
19
|
-
error: string;
|
|
20
|
-
code: CmsErrorCode;
|
|
21
|
-
sourcePath?: string;
|
|
22
|
-
}
|
|
23
|
-
/** A static page route discovered under `src/pages` (pathname-only). */
|
|
24
|
-
export interface CmsPageEntry {
|
|
25
|
-
pathname: string;
|
|
26
|
-
title?: string;
|
|
27
|
-
}
|
|
28
|
-
/** Features the sidecar advertises so the UI can degrade gracefully. */
|
|
29
|
-
export interface CmsCapabilities {
|
|
30
|
-
coreVersion: string;
|
|
31
|
-
features: string[];
|
|
32
|
-
}
|
|
33
|
-
/** `GET /project` — the whole structural model in one call. */
|
|
34
|
-
export interface CmsProjectModel {
|
|
35
|
-
collections: CollectionDefinition[];
|
|
36
|
-
pages: CmsPageEntry[];
|
|
37
|
-
capabilities: CmsCapabilities;
|
|
38
|
-
}
|
|
39
|
-
/** `GET …/entries` — projected entries plus an opaque continuation cursor. */
|
|
40
|
-
export interface CmsEntriesListResult {
|
|
41
|
-
entries: CollectionEntryInfo[];
|
|
42
|
-
cursor?: string;
|
|
43
|
-
hasMore: boolean;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* `409` body for a `PATCH` whose `baseHash` no longer matches disk (an agent or a
|
|
47
|
-
* human wrote in between). Carries the current server version so the UI can offer
|
|
48
|
-
* "use server" vs "use ours". Mirrors the sidecar `ConflictResponse`.
|
|
49
|
-
*/
|
|
50
|
-
export interface CmsConflict {
|
|
51
|
-
code: 'conflict';
|
|
52
|
-
serverHash: string;
|
|
53
|
-
/** Raw (non-stringified) server frontmatter — unlike the line-keyed GET-detail shape. */
|
|
54
|
-
serverFrontmatter: Record<string, unknown>;
|
|
55
|
-
serverBody?: string;
|
|
56
|
-
}
|
|
57
|
-
/** `PATCH …/entries/:slug` — frontmatter keys are merged (not replaced). */
|
|
58
|
-
export interface UpdateEntryInput {
|
|
59
|
-
frontmatter?: Record<string, unknown>;
|
|
60
|
-
body?: string;
|
|
61
|
-
/** Hash of the source the client edited; drives optimistic concurrency. */
|
|
62
|
-
baseHash?: string;
|
|
63
|
-
}
|
|
64
|
-
export interface CreateEntryInput {
|
|
65
|
-
slug: string;
|
|
66
|
-
frontmatter: Record<string, unknown>;
|
|
67
|
-
body?: string;
|
|
68
|
-
/** File extension override for data collections (e.g. 'json', 'yaml'). */
|
|
69
|
-
fileExtension?: string;
|
|
70
|
-
}
|
|
71
|
-
/** Context passed to media operations so uploads can be filed against an entry/field. */
|
|
72
|
-
export interface MediaContext {
|
|
73
|
-
collection?: string;
|
|
74
|
-
entry?: string;
|
|
75
|
-
field?: string;
|
|
76
|
-
/** Subfolder under the media root. */
|
|
77
|
-
folder?: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Either a successful `MutationResult` or a `409` conflict the caller must
|
|
81
|
-
* resolve. Returned (not thrown) by `updateEntry` so the editor can branch
|
|
82
|
-
* without exception flow.
|
|
83
|
-
*/
|
|
84
|
-
export type UpdateEntryResult = {
|
|
85
|
-
status: 'ok';
|
|
86
|
-
result: MutationResult;
|
|
87
|
-
} | {
|
|
88
|
-
status: 'conflict';
|
|
89
|
-
conflict: CmsConflict;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Thrown for any non-2xx response. Carries the parsed sidecar error code so the
|
|
93
|
-
* UI can distinguish auth failures (`unauthorized`/`forbidden`) from a missing
|
|
94
|
-
* collection/entry (`not_found`) or a generic failure.
|
|
95
|
-
*/
|
|
96
|
-
export declare class CmsClientError extends Error {
|
|
97
|
-
readonly status: number;
|
|
98
|
-
readonly code: CmsErrorCode | 'forbidden' | 'unknown';
|
|
99
|
-
constructor(status: number, code: CmsErrorCode | 'forbidden' | 'unknown', message: string);
|
|
100
|
-
/** Session cookie missing/expired upstream — the user must re-authenticate. */
|
|
101
|
-
get isUnauthorized(): boolean;
|
|
102
|
-
/** Authenticated but lacks access to this project. */
|
|
103
|
-
get isForbidden(): boolean;
|
|
104
|
-
get isNotFound(): boolean;
|
|
105
|
-
}
|
|
106
|
-
export interface GetEntriesOptions {
|
|
107
|
-
/** "slug,title" | "*" ; absent = light header (slug/title/draft/pathname). */
|
|
108
|
-
fields?: string;
|
|
109
|
-
/** Draft filter — defaults to `'false'` (published only) on the sidecar. */
|
|
110
|
-
draft?: 'true' | 'false' | 'all';
|
|
111
|
-
/** Opaque continuation cursor from a previous page's `cursor`. */
|
|
112
|
-
cursor?: string;
|
|
113
|
-
limit?: number;
|
|
114
|
-
}
|
|
115
|
-
export interface CmsClient {
|
|
116
|
-
getProject(): Promise<CmsProjectModel>;
|
|
117
|
-
getCollections(): Promise<CollectionDefinition[]>;
|
|
118
|
-
getEntries(collection: string, options?: GetEntriesOptions): Promise<CmsEntriesListResult>;
|
|
119
|
-
getEntry(collection: string, slug: string): Promise<CollectionEntry>;
|
|
120
|
-
/**
|
|
121
|
-
* Merge-patch an entry's frontmatter/body. Returns a discriminated result: a
|
|
122
|
-
* `409` is surfaced as `{ status: 'conflict' }` (not thrown) so the editor can
|
|
123
|
-
* open the conflict dialog. The new `baseHash` is on `result.sourceHash`.
|
|
124
|
-
*/
|
|
125
|
-
updateEntry(collection: string, slug: string, input: UpdateEntryInput): Promise<UpdateEntryResult>;
|
|
126
|
-
createEntry(collection: string, input: CreateEntryInput): Promise<MutationResult>;
|
|
127
|
-
deleteEntry(collection: string, slug: string): Promise<MutationResult>;
|
|
128
|
-
renameEntry(collection: string, slug: string, to: string): Promise<MutationResult>;
|
|
129
|
-
addArrayItem(collection: string, slug: string, field: string, value: unknown, index?: number): Promise<MutationResult>;
|
|
130
|
-
removeArrayItem(collection: string, slug: string, field: string, index: number): Promise<MutationResult>;
|
|
131
|
-
listMedia(options?: {
|
|
132
|
-
folder?: string;
|
|
133
|
-
cursor?: string;
|
|
134
|
-
limit?: number;
|
|
135
|
-
}): Promise<MediaListResult>;
|
|
136
|
-
uploadMedia(file: File, context?: MediaContext): Promise<MediaUploadResult>;
|
|
137
|
-
deleteMedia(id: string): Promise<{
|
|
138
|
-
success: boolean;
|
|
139
|
-
error?: string;
|
|
140
|
-
}>;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Whether a thrown `CmsClientError` means "media is not available" — the deployed
|
|
144
|
-
* sidecar may have no media adapter wired (`501 unsupported`). The picker uses
|
|
145
|
-
* this to degrade gracefully instead of surfacing a hard error.
|
|
146
|
-
*/
|
|
147
|
-
export declare function isMediaUnavailable(error: unknown): boolean;
|
|
148
|
-
export declare function createClient(apiBase: string): CmsClient;
|
|
149
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACX,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,MAAM,oBAAoB,CAAA;AAS3B,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GACrB,WAAW,GACX,UAAU,GACV,YAAY,GACZ,aAAa,GACb,UAAU,GACV,aAAa,GACb,cAAc,CAAA;AAEjB,4EA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