@nuasite/collections-admin 0.43.0-beta.3 → 0.43.0-beta.8
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/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/media-picker.d.ts +1 -1
- package/dist/types/media-picker.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/src/app.tsx +182 -110
- package/src/entry-create.tsx +1 -2
- package/src/entry-editor.tsx +233 -39
- package/src/field-editor.tsx +55 -7
- package/src/index.ts +4 -2
- package/src/media-picker.tsx +17 -3
- package/src/styles.css +220 -1
- package/src/tsconfig.json +2 -0
- package/dist/types/client.d.ts +0 -149
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/form-model.d.ts +0 -61
- package/dist/types/form-model.d.ts.map +0 -1
- package/src/client.ts +0 -405
- package/src/form-model.ts +0 -182
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/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,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,YAAY,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC/B,WAAW,EAAE,oBAAoB,EAAE,CAAA;IACnC,KAA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frontmatter shapes:
|
|
5
|
-
* - `GET …/entries/:slug` returns `frontmatter: Record<string, { value: string; line: number }>`,
|
|
6
|
-
* where `value` is already stringified (objects/arrays are JSON).
|
|
7
|
-
* - `PATCH …` accepts `frontmatter?: Record<string, unknown>` of *native* values (merged), and a
|
|
8
|
-
* `409` `serverFrontmatter` is likewise native (not stringified).
|
|
9
|
-
*
|
|
10
|
-
* The editor works on a single native draft (`EntryDraft`): `frontmatter` is a
|
|
11
|
-
* `Record<string, unknown>` of native JS values keyed by field name, plus the
|
|
12
|
-
* markdown `body`. This module converts to/from the wire and coerces raw input
|
|
13
|
-
* (form strings) into the native value a `FieldType` expects. Keeping it pure
|
|
14
|
-
* (no React/DOM) makes the mapping unit-testable.
|
|
15
|
-
*/
|
|
16
|
-
import type { CollectionEntry, FieldDefinition, FieldType } from '@nuasite/cms-types';
|
|
17
|
-
/** The editor's in-memory state: native frontmatter values + the markdown body. */
|
|
18
|
-
export interface EntryDraft {
|
|
19
|
-
frontmatter: Record<string, unknown>;
|
|
20
|
-
body: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Parse one stringified frontmatter `value` (from `GET …/entries/:slug`) into the
|
|
24
|
-
* native value a field of `type` expects. Structural types (object/array) and
|
|
25
|
-
* unknowns fall back to a best-effort `JSON.parse`; scalars are coerced per type.
|
|
26
|
-
*/
|
|
27
|
-
export declare function parseWireValue(type: FieldType, raw: string): unknown;
|
|
28
|
-
/**
|
|
29
|
-
* Build a native draft from a loaded entry, driven by the collection's fields.
|
|
30
|
-
* Frontmatter keys present on the entry but absent from the inferred schema are
|
|
31
|
-
* preserved verbatim (as raw strings) so a save never silently drops them.
|
|
32
|
-
*/
|
|
33
|
-
export declare function draftFromEntry(entry: CollectionEntry, fields: FieldDefinition[]): EntryDraft;
|
|
34
|
-
/**
|
|
35
|
-
* Build a fresh draft for a create form from the collection's fields, seeding
|
|
36
|
-
* each field with its `defaultValue` (when present) or a type-appropriate blank.
|
|
37
|
-
*/
|
|
38
|
-
export declare function draftForCreate(fields: FieldDefinition[]): EntryDraft;
|
|
39
|
-
/** A type-appropriate empty value used to seed create forms. */
|
|
40
|
-
export declare function blankValue(type: FieldType): unknown;
|
|
41
|
-
/**
|
|
42
|
-
* Adopt a server-provided native frontmatter map (from a `409` `serverFrontmatter`)
|
|
43
|
-
* into a draft, re-coercing per field where a definition exists.
|
|
44
|
-
*/
|
|
45
|
-
export declare function draftFromServerFrontmatter(serverFrontmatter: Record<string, unknown>, serverBody: string | undefined, fields: FieldDefinition[]): EntryDraft;
|
|
46
|
-
/**
|
|
47
|
-
* Coerce a raw form-control string into the native value a field expects. Used by
|
|
48
|
-
* the widgets, whose `<input>` values are always strings.
|
|
49
|
-
*/
|
|
50
|
-
export declare function coerceInput(type: FieldType, raw: string): unknown;
|
|
51
|
-
/** Render a native value back to a string for a text/number/date/select control. */
|
|
52
|
-
export declare function valueToInput(value: unknown): string;
|
|
53
|
-
/** Read a value as a boolean for toggle widgets, tolerating string encodings. */
|
|
54
|
-
export declare function valueToBoolean(value: unknown): boolean;
|
|
55
|
-
/** Read a value as an array of items for repeater widgets. */
|
|
56
|
-
export declare function valueToArray(value: unknown): unknown[];
|
|
57
|
-
/** Read a value as an object for nested-group widgets. */
|
|
58
|
-
export declare function valueToObject(value: unknown): Record<string, unknown>;
|
|
59
|
-
/** Immutably set a top-level frontmatter key in a draft. */
|
|
60
|
-
export declare function setDraftField(draft: EntryDraft, name: string, value: unknown): EntryDraft;
|
|
61
|
-
//# sourceMappingURL=form-model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form-model.d.ts","sourceRoot":"","sources":["../../src/form-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAErF,mFAAmF;AACnF,MAAM,WAAW,UAAU;IAC1B,WAAW,EAAE,MAAM,CA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