@prenta/admin 2.16.1 → 2.16.3

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 (70) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/__tests__/fields/field-renderer-null.render.test.d.ts +2 -0
  3. package/dist/__tests__/fields/field-renderer-null.render.test.d.ts.map +1 -0
  4. package/dist/__tests__/fields/field-renderer-null.render.test.js +21 -0
  5. package/dist/__tests__/fields/field-renderer-null.render.test.js.map +1 -0
  6. package/dist/__tests__/lib/post-custom-fields.test.d.ts +2 -0
  7. package/dist/__tests__/lib/post-custom-fields.test.d.ts.map +1 -0
  8. package/dist/__tests__/lib/post-custom-fields.test.js +158 -0
  9. package/dist/__tests__/lib/post-custom-fields.test.js.map +1 -0
  10. package/dist/__tests__/lib/post-editor-custom-fields-api.test.d.ts +2 -0
  11. package/dist/__tests__/lib/post-editor-custom-fields-api.test.d.ts.map +1 -0
  12. package/dist/__tests__/lib/post-editor-custom-fields-api.test.js +104 -0
  13. package/dist/__tests__/lib/post-editor-custom-fields-api.test.js.map +1 -0
  14. package/dist/__tests__/lib/post-editor-custom-fields-undo.test.d.ts +2 -0
  15. package/dist/__tests__/lib/post-editor-custom-fields-undo.test.d.ts.map +1 -0
  16. package/dist/__tests__/lib/post-editor-custom-fields-undo.test.js +128 -0
  17. package/dist/__tests__/lib/post-editor-custom-fields-undo.test.js.map +1 -0
  18. package/dist/__tests__/views/editor-top-bar-layout.render.test.d.ts +2 -0
  19. package/dist/__tests__/views/editor-top-bar-layout.render.test.d.ts.map +1 -0
  20. package/dist/__tests__/views/editor-top-bar-layout.render.test.js +157 -0
  21. package/dist/__tests__/views/editor-top-bar-layout.render.test.js.map +1 -0
  22. package/dist/__tests__/views/post-tab-custom-fields.render.test.d.ts +2 -0
  23. package/dist/__tests__/views/post-tab-custom-fields.render.test.d.ts.map +1 -0
  24. package/dist/__tests__/views/post-tab-custom-fields.render.test.js +164 -0
  25. package/dist/__tests__/views/post-tab-custom-fields.render.test.js.map +1 -0
  26. package/dist/components/BreakpointPicker.d.ts.map +1 -1
  27. package/dist/components/BreakpointPicker.js +2 -2
  28. package/dist/components/BreakpointPicker.js.map +1 -1
  29. package/dist/fields/FieldRenderer.d.ts.map +1 -1
  30. package/dist/fields/FieldRenderer.js +7 -1
  31. package/dist/fields/FieldRenderer.js.map +1 -1
  32. package/dist/lib/post-custom-fields.d.ts +28 -0
  33. package/dist/lib/post-custom-fields.d.ts.map +1 -0
  34. package/dist/lib/post-custom-fields.js +173 -0
  35. package/dist/lib/post-custom-fields.js.map +1 -0
  36. package/dist/lib/post-editor-service.d.ts +29 -0
  37. package/dist/lib/post-editor-service.d.ts.map +1 -1
  38. package/dist/lib/post-editor-service.js +53 -0
  39. package/dist/lib/post-editor-service.js.map +1 -1
  40. package/dist/prenta-admin.css +1 -1
  41. package/dist/views/page-editor/EditorTopBar.d.ts.map +1 -1
  42. package/dist/views/page-editor/EditorTopBar.js +28 -17
  43. package/dist/views/page-editor/EditorTopBar.js.map +1 -1
  44. package/dist/views/post-editor/PostRowsField.d.ts +17 -0
  45. package/dist/views/post-editor/PostRowsField.d.ts.map +1 -0
  46. package/dist/views/post-editor/PostRowsField.js +29 -0
  47. package/dist/views/post-editor/PostRowsField.js.map +1 -0
  48. package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
  49. package/dist/views/post-editor/PostSectionEditor.js +16 -5
  50. package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
  51. package/dist/views/post-editor/PostTab.d.ts +8 -5
  52. package/dist/views/post-editor/PostTab.d.ts.map +1 -1
  53. package/dist/views/post-editor/PostTab.js +53 -15
  54. package/dist/views/post-editor/PostTab.js.map +1 -1
  55. package/package.json +6 -6
  56. package/src/__tests__/fields/field-renderer-null.render.test.tsx +34 -0
  57. package/src/__tests__/lib/post-custom-fields.test.ts +170 -0
  58. package/src/__tests__/lib/post-editor-custom-fields-api.test.ts +129 -0
  59. package/src/__tests__/lib/post-editor-custom-fields-undo.test.ts +152 -0
  60. package/src/__tests__/views/editor-top-bar-layout.render.test.tsx +198 -0
  61. package/src/__tests__/views/post-tab-custom-fields.render.test.tsx +239 -0
  62. package/src/components/BreakpointPicker.tsx +7 -6
  63. package/src/fields/FieldRenderer.tsx +6 -1
  64. package/src/lib/post-custom-fields.ts +191 -0
  65. package/src/lib/post-editor-service.ts +71 -0
  66. package/src/styles/responsive.css +44 -18
  67. package/src/views/page-editor/EditorTopBar.tsx +109 -65
  68. package/src/views/post-editor/PostRowsField.tsx +110 -0
  69. package/src/views/post-editor/PostSectionEditor.tsx +26 -7
  70. package/src/views/post-editor/PostTab.tsx +72 -6
@@ -0,0 +1,198 @@
1
+ // @vitest-environment happy-dom
2
+ import { readFileSync } from 'node:fs'
3
+ import path from 'node:path'
4
+ import { afterEach, describe, expect, it, vi } from 'vitest'
5
+ import { cleanup, render, screen } from '@testing-library/react'
6
+
7
+ import { EditorTopBar } from '../../views/page-editor/EditorTopBar.js'
8
+
9
+ afterEach(cleanup)
10
+
11
+ /**
12
+ * A post in review, seen by an editor, with a public site: the fullest bar
13
+ * the editor shows. This is the state that wrapped its buttons onto two
14
+ * lines at 1280px with the sidebar open.
15
+ */
16
+ const reviewProps = {
17
+ title: 'Mary Frances: +60% Ecommerce Revenue with an Integrated Digital Strategy',
18
+ status: 'DRAFT' as const,
19
+ workflowStage: 'IN_REVIEW' as const,
20
+ role: 'EDITOR',
21
+ dirty: true,
22
+ saveState: 'idle' as const,
23
+ publishing: false,
24
+ canEdit: true,
25
+ publishReady: true,
26
+ hasPublicSiteUrl: true,
27
+ viewport: 'wide' as const,
28
+ backLabel: 'Posts',
29
+ onViewport: vi.fn(),
30
+ onBack: vi.fn(),
31
+ onOpenSettings: vi.fn(),
32
+ onOpenSeo: vi.fn(),
33
+ onHistory: vi.fn(),
34
+ onViewOnSite: vi.fn(),
35
+ onShare: vi.fn(),
36
+ onSchedule: vi.fn(),
37
+ onSaveDraft: vi.fn(),
38
+ onSubmitForReview: vi.fn(),
39
+ onApprove: vi.fn(),
40
+ onRequestChanges: vi.fn(),
41
+ }
42
+
43
+ const TEXT_ACTIONS = [
44
+ 'View site',
45
+ 'Share',
46
+ 'Save Draft',
47
+ 'Schedule publish',
48
+ 'Approve',
49
+ 'Request changes',
50
+ ]
51
+
52
+ // happy-dom gives this module an http URL, so resolve from the package root.
53
+ const css = readFileSync(path.resolve(process.cwd(), 'src/styles/responsive.css'), 'utf-8')
54
+
55
+ describe('EditorTopBar layout', () => {
56
+ it('gives every text action the same height and never lets its label wrap', () => {
57
+ render(<EditorTopBar {...reviewProps} />)
58
+
59
+ for (const name of TEXT_ACTIONS) {
60
+ const button = screen.getByRole('button', { name })
61
+ const classes = button.className.split(/\s+/)
62
+ expect(classes, `${name} can wrap`).toContain('whitespace-nowrap')
63
+ expect(classes, `${name} can be squeezed`).toContain('shrink-0')
64
+ expect(classes, `${name} is not 34px tall`).toContain('h-[34px]')
65
+ }
66
+ })
67
+
68
+ it('makes the icon buttons the same height as the text actions', () => {
69
+ render(<EditorTopBar {...reviewProps} onUndo={vi.fn()} onRedo={vi.fn()} />)
70
+
71
+ for (const name of ['Post settings', 'Version history', 'Undo', 'Redo']) {
72
+ const classes = screen.getByRole('button', { name }).className.split(/\s+/)
73
+ expect(classes, `${name} is not 34px`).toEqual(
74
+ expect.arrayContaining(['h-[34px]', 'w-[34px]']),
75
+ )
76
+ }
77
+ })
78
+
79
+ it('lets the bar grow and wrap instead of crushing the title into a fixed row', () => {
80
+ const { container } = render(<EditorTopBar {...reviewProps} />)
81
+ const classes = container.querySelector('header')!.className.split(/\s+/)
82
+
83
+ expect(classes).toContain('flex-wrap')
84
+ expect(classes).toContain('min-h-14')
85
+ expect(classes).not.toContain('h-14')
86
+ })
87
+
88
+ it('keeps the breadcrumb inside its own box so the status cannot print over it', () => {
89
+ render(<EditorTopBar {...reviewProps} />)
90
+ const nav = screen.getByRole('navigation', { name: 'Breadcrumb' })
91
+ expect(nav.className.split(/\s+/)).toContain('overflow-hidden')
92
+ })
93
+
94
+ it('reserves room for a readable title before the actions may stay on its line', () => {
95
+ render(<EditorTopBar {...reviewProps} />)
96
+ const nav = screen.getByRole('navigation', { name: 'Breadcrumb' })
97
+ // The title's floor, and a left group that cannot shrink below its content.
98
+ expect(nav.className.split(/\s+/)).toContain('min-w-[5rem]')
99
+ expect(nav.parentElement!.className.split(/\s+/)).toContain('min-w-min')
100
+ // A stylesheet reset of that minimum is what let the title collapse.
101
+ expect(css).not.toMatch(/\.prenta-editor-header > \*\s*\{\s*min-width:\s*0/)
102
+ })
103
+
104
+ it('never breaks the save status onto two lines, and lets it give way before the bar wraps', () => {
105
+ render(<EditorTopBar {...reviewProps} />)
106
+ expect(screen.getByText('Unsaved changes').className.split(/\s+/)).toContain('truncate')
107
+ })
108
+
109
+ it('gives each collapsible action a touch target, since it becomes an icon button', () => {
110
+ render(<EditorTopBar {...reviewProps} />)
111
+ for (const name of ['Share', 'Schedule publish', 'Request changes']) {
112
+ expect(screen.getByRole('button', { name }).className).toContain('prenta-touch-target')
113
+ }
114
+ })
115
+
116
+ it('forces the narrow SEO padding past the shared button padding', () => {
117
+ render(<EditorTopBar {...reviewProps} seoScore={80} />)
118
+ const seo = screen.getByRole('button', { name: /^SEO/ })
119
+ expect(seo.className.split(/\s+/)).toContain('px-2!')
120
+ })
121
+
122
+ it('truncates a long reviewer note and keeps the full text in a title', () => {
123
+ const note =
124
+ 'Please tighten the opening, check every figure against the client report, and add a quote.'
125
+ render(<EditorTopBar {...reviewProps} workflowStage="DRAFT" reviewNote={note} />)
126
+ const shown = screen.getByText(new RegExp(note.slice(0, 20)))
127
+ expect(shown.className.split(/\s+/)).toContain('truncate')
128
+ expect(shown.getAttribute('title')).toContain(note)
129
+ })
130
+
131
+ it('marks the secondary actions as collapsible, each with a name that survives a hidden label', () => {
132
+ render(<EditorTopBar {...reviewProps} />)
133
+
134
+ for (const name of ['Share', 'Schedule publish', 'Request changes']) {
135
+ const button = screen.getByRole('button', { name })
136
+ expect(button.className, `${name} cannot collapse`).toContain('prenta-editor-collapsible')
137
+ expect(button.getAttribute('aria-label'), `${name} loses its name as an icon`).toBeTruthy()
138
+ expect(
139
+ button.querySelector('.prenta-editor-label'),
140
+ `${name} has no label to hide`,
141
+ ).not.toBeNull()
142
+ expect(button.querySelector('svg'), `${name} has no icon to fall back to`).not.toBeNull()
143
+ }
144
+ })
145
+
146
+ it('never collapses the actions an author must be able to read', () => {
147
+ render(<EditorTopBar {...reviewProps} />)
148
+
149
+ for (const name of ['View site', 'Save Draft', 'Approve']) {
150
+ const button = screen.getByRole('button', { name })
151
+ expect(button.className).not.toContain('prenta-editor-collapsible')
152
+ expect(button.querySelector('.prenta-editor-label')).toBeNull()
153
+ }
154
+ })
155
+
156
+ it('still shows the reason on a disabled action', () => {
157
+ render(
158
+ <EditorTopBar
159
+ {...reviewProps}
160
+ publishReady={false}
161
+ publishDisabledReason="Add a title before publishing"
162
+ />,
163
+ )
164
+ const approve = screen.getByRole('button', { name: 'Approve' })
165
+ expect(approve.getAttribute('title')).toBe('Add a title before publishing')
166
+ // The shared Button ignores the pointer while disabled, which would hide
167
+ // the title; these opt back in.
168
+ expect(approve.className).toContain('disabled:pointer-events-auto!')
169
+ })
170
+ })
171
+
172
+ describe('editor bar responsive rules', () => {
173
+ it("collapses by the bar's own width, not the viewport's", () => {
174
+ expect(css).toMatch(
175
+ /\.prenta-editor-header\s*\{\s*container:\s*editor-header\s*\/\s*inline-size/,
176
+ )
177
+ expect(css).toMatch(/@container editor-header \(max-width: 1360px\)/)
178
+ // The old rule keyed off the window, so a 1280px window with the sidebar
179
+ // open (a 1050px bar) never triggered it.
180
+ expect(css).not.toMatch(
181
+ /@media \(max-width: 1180px\)\s*\{\s*\.prenta-admin \.prenta-editor-header/,
182
+ )
183
+ })
184
+
185
+ it('draws the back button focus ring inside the clipped breadcrumb', () => {
186
+ // overflow-hidden on the breadcrumb would cut off an outline drawn outside it.
187
+ expect(css).toMatch(
188
+ /\.prenta-editor-header nav button:focus-visible\s*\{\s*outline-offset:\s*-2px/,
189
+ )
190
+ })
191
+
192
+ it('hides labels, shows the short canvas name and squares the buttons when collapsed', () => {
193
+ const block = css.slice(css.indexOf('@container editor-header'))
194
+ expect(block).toMatch(/\.prenta-editor-label\s*\{\s*display:\s*none/)
195
+ expect(block).toMatch(/\.prenta-editor-abbr\s*\{\s*display:\s*inline/)
196
+ expect(block).toMatch(/\.prenta-editor-collapsible\s*\{[^}]*width:\s*34px/)
197
+ })
198
+ })
@@ -0,0 +1,239 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, describe, expect, it, vi } from 'vitest'
3
+ import { cleanup, fireEvent, render } from '@testing-library/react'
4
+
5
+ // The identity form has its own tests; keep this one on the custom fields.
6
+ vi.mock('../../views/post-editor/PostFieldsForm.js', () => ({
7
+ PostFieldsForm: () => null,
8
+ }))
9
+
10
+ const { PostTab } = await import('../../views/post-editor/PostTab.js')
11
+
12
+ afterEach(cleanup)
13
+
14
+ function post(overrides: Record<string, unknown> = {}) {
15
+ return {
16
+ id: 'cs1',
17
+ postType: 'case-studies',
18
+ title: 'Mary Frances',
19
+ slug: 'mary-frances',
20
+ excerpt: '',
21
+ featuredImage: '',
22
+ featuredImageUrl: '',
23
+ body: '',
24
+ category: '',
25
+ authorName: '',
26
+ canvasRelatedPosts: null,
27
+ tags: [],
28
+ status: 'DRAFT' as const,
29
+ workflowStage: 'DRAFT' as const,
30
+ reviewNote: null,
31
+ publishDate: null,
32
+ scheduledAt: null,
33
+ scheduledUnpublishAt: null,
34
+ sections: [],
35
+ seoTitle: '',
36
+ seoDescription: '',
37
+ publishedAt: null,
38
+ updatedAt: null,
39
+ customFields: { clientName: 'Mary Frances' },
40
+ customFieldEdits: {},
41
+ ...overrides,
42
+ }
43
+ }
44
+
45
+ const fields = {
46
+ title: { type: 'text', label: 'Title' },
47
+ body: { type: 'richText', label: 'Body' },
48
+ sections: { type: 'json', label: 'Sections' },
49
+ clientName: { type: 'text', label: 'Client name', required: true },
50
+ industry: { type: 'text', label: 'Industry' },
51
+ ctaUrl: { type: 'url', label: 'CTA link' },
52
+ contact: { type: 'email', label: 'Contact email' },
53
+ featured: { type: 'boolean', label: 'Featured' },
54
+ publishedDate: { type: 'date', label: 'Published' },
55
+ keyMetrics: {
56
+ type: 'array',
57
+ label: 'Key metrics',
58
+ maxRows: 2,
59
+ fields: {
60
+ value: { type: 'text', label: 'Value', required: true },
61
+ label: { type: 'text', label: 'Label', required: true },
62
+ },
63
+ },
64
+ logo: { type: 'media', label: 'Client logo' },
65
+ services: { type: 'relationship', label: 'Services', relationTo: 'services' },
66
+ }
67
+
68
+ function inputFor(container: HTMLElement, label: string): HTMLInputElement {
69
+ const labels = [...container.querySelectorAll('label')]
70
+ const match = labels.find((l) => l.textContent?.includes(label))
71
+ const input = match?.parentElement?.querySelector('input')
72
+ if (!input) throw new Error(`no input for ${label}`)
73
+ return input
74
+ }
75
+
76
+ describe('PostTab custom fields', () => {
77
+ it("renders the post type's own fields with their stored values", () => {
78
+ const { container, getByTestId } = render(
79
+ <PostTab post={post()} canEdit fields={fields} onChange={() => {}} />,
80
+ )
81
+
82
+ const group = getByTestId('post-custom-fields')
83
+ for (const label of ['Client name', 'Industry', 'CTA link', 'Contact email', 'Featured']) {
84
+ expect(group.textContent).toContain(label)
85
+ }
86
+ expect(group.textContent).not.toContain('Unknown field type')
87
+ expect(inputFor(container, 'Client name').value).toBe('Mary Frances')
88
+ expect(inputFor(container, 'Industry').value).toBe('')
89
+ })
90
+
91
+ it('does not offer controls that would store a placeholder or a wrong reference', () => {
92
+ const { getByTestId } = render(
93
+ <PostTab post={post()} canEdit fields={fields} onChange={() => {}} />,
94
+ )
95
+ const text = getByTestId('post-custom-fields').textContent
96
+ expect(text).not.toContain('Client logo')
97
+ expect(text).not.toContain('Services')
98
+ })
99
+
100
+ it('reports an edit as that one field', () => {
101
+ const onChange = vi.fn()
102
+ const { container } = render(
103
+ <PostTab
104
+ post={post({ customFieldEdits: { industry: 'Fashion' } })}
105
+ canEdit
106
+ fields={fields}
107
+ onChange={onChange}
108
+ />,
109
+ )
110
+
111
+ fireEvent.change(inputFor(container, 'Client name'), { target: { value: 'MF' } })
112
+
113
+ // The editor merges this into the pending edits, so `industry` survives.
114
+ expect(onChange).toHaveBeenCalledWith({ customFieldEdits: { clientName: 'MF' } })
115
+ })
116
+
117
+ it('renders stored null values as empty instead of crashing', () => {
118
+ const { container } = render(
119
+ <PostTab
120
+ post={post({ customFields: { clientName: null, ctaUrl: null, contact: null } })}
121
+ canEdit
122
+ fields={fields}
123
+ onChange={() => {}}
124
+ />,
125
+ )
126
+ expect(inputFor(container, 'Client name').value).toBe('')
127
+ expect(inputFor(container, 'CTA link').value).toBe('')
128
+ })
129
+
130
+ it('shows the date part of a stored timestamp', () => {
131
+ const { container } = render(
132
+ <PostTab
133
+ post={post({ customFields: { publishedDate: '2026-11-26T15:41:39.442Z' } })}
134
+ canEdit
135
+ fields={fields}
136
+ onChange={() => {}}
137
+ />,
138
+ )
139
+ expect(inputFor(container, 'Published').value).toBe('2026-11-26')
140
+ })
141
+
142
+ it('edits key metrics as flat rows and keeps the other rows', () => {
143
+ const onChange = vi.fn()
144
+ const { container } = render(
145
+ <PostTab
146
+ post={post({
147
+ customFields: {
148
+ keyMetrics: [
149
+ { value: '+60%', label: 'Revenue', source: 'GA4' },
150
+ { value: '+153%', label: 'Organic' },
151
+ ],
152
+ },
153
+ })}
154
+ canEdit
155
+ fields={fields}
156
+ onChange={onChange}
157
+ />,
158
+ )
159
+
160
+ const first = container.querySelector<HTMLInputElement>('#post-rows-keyMetrics-0-value')
161
+ expect(first?.value).toBe('+60%')
162
+ fireEvent.change(first!, { target: { value: '+61%' } })
163
+
164
+ expect(onChange).toHaveBeenCalledWith({
165
+ customFieldEdits: {
166
+ keyMetrics: [
167
+ { value: '+61%', label: 'Revenue', source: 'GA4' },
168
+ { value: '+153%', label: 'Organic' },
169
+ ],
170
+ },
171
+ })
172
+ })
173
+
174
+ it('adds an empty row with the declared columns and stops at the row limit', () => {
175
+ const onChange = vi.fn()
176
+ const { getByText, rerender } = render(
177
+ <PostTab
178
+ post={post({ customFields: { keyMetrics: [{ value: '+60%', label: 'Revenue' }] } })}
179
+ canEdit
180
+ fields={fields}
181
+ onChange={onChange}
182
+ />,
183
+ )
184
+
185
+ fireEvent.click(getByText('Add row'))
186
+ expect(onChange).toHaveBeenCalledWith({
187
+ customFieldEdits: {
188
+ keyMetrics: [
189
+ { value: '+60%', label: 'Revenue' },
190
+ { value: '', label: '' },
191
+ ],
192
+ },
193
+ })
194
+
195
+ rerender(
196
+ <PostTab
197
+ post={post({
198
+ customFields: {
199
+ keyMetrics: [
200
+ { value: '+60%', label: 'Revenue' },
201
+ { value: '+153%', label: 'Organic' },
202
+ ],
203
+ },
204
+ })}
205
+ canEdit
206
+ fields={fields}
207
+ onChange={onChange}
208
+ />,
209
+ )
210
+ expect((getByText('Add row').closest('button') as HTMLButtonElement).disabled).toBe(true)
211
+ })
212
+
213
+ it('shows nothing extra for a post type with only the shared fields', () => {
214
+ const { queryByTestId } = render(
215
+ <PostTab
216
+ post={post()}
217
+ canEdit
218
+ fields={{ title: fields.title, body: fields.body }}
219
+ onChange={() => {}}
220
+ />,
221
+ )
222
+ expect(queryByTestId('post-custom-fields')).toBeNull()
223
+ })
224
+
225
+ it('disables the fields for a viewer who cannot edit, and ignores any edit that gets through', () => {
226
+ const onChange = vi.fn()
227
+ const { container, getByTestId } = render(
228
+ <PostTab post={post()} canEdit={false} fields={fields} onChange={onChange} />,
229
+ )
230
+ const group = getByTestId('post-custom-fields') as HTMLFieldSetElement
231
+ expect(group.disabled).toBe(true)
232
+ // inert keeps keyboard focus out of a rich text editor, which a disabled
233
+ // fieldset does not.
234
+ expect(group.hasAttribute('inert')).toBe(true)
235
+
236
+ fireEvent.change(inputFor(container, 'Client name'), { target: { value: 'MF' } })
237
+ expect(onChange).not.toHaveBeenCalled()
238
+ })
239
+ })
@@ -43,18 +43,19 @@ export function BreakpointPicker({ value, onChange, disabled }: BreakpointPicker
43
43
  disabled={disabled}
44
44
  aria-label={canvasWidthLabel}
45
45
  title={canvasWidthLabel}
46
- className={`border-border flex h-[34px] items-center gap-1.5 rounded-lg border px-2.5 text-[12.5px] font-medium transition-colors disabled:opacity-50 ${
46
+ className={`border-border flex h-[34px] shrink-0 items-center gap-1.5 rounded-lg border px-2.5 text-[12.5px] font-medium transition-colors disabled:opacity-50 ${
47
47
  open
48
48
  ? 'border-brand bg-accent text-accent-foreground'
49
49
  : 'bg-card text-foreground hover:bg-accent'
50
50
  }`}
51
51
  >
52
52
  <ActiveIcon className={`h-4 w-4 shrink-0 ${open ? '' : 'text-brand'}`} aria-hidden />
53
- {/* The name is the useful label; below `lg` the header is too tight
54
- for it, so fall back to the two-letter form rather than truncating. */}
55
- <span className="hidden lg:inline">{active.name}</span>
56
- <span className="lg:hidden">{active.abbr}</span>
57
- <span className="text-muted-foreground hidden text-[11.5px] tabular-nums xl:inline">
53
+ {/* The name is the useful label; when the editor bar is too tight for
54
+ it, fall back to the two-letter form rather than truncating. The
55
+ switch follows the bar's width (responsive.css), not the viewport. */}
56
+ <span className="prenta-editor-label whitespace-nowrap">{active.name}</span>
57
+ <span className="prenta-editor-abbr">{active.abbr}</span>
58
+ <span className="prenta-editor-label text-muted-foreground text-[11.5px] tabular-nums">
58
59
  {active.width}
59
60
  </span>
60
61
  <ChevronDown
@@ -49,6 +49,9 @@ const FIELD_MAP: Record<string, React.ComponentType<any>> = {
49
49
  relationship: RelationshipField,
50
50
  date: DateField,
51
51
  toggle: ToggleField,
52
+ boolean: ToggleField,
53
+ url: TextField,
54
+ email: TextField,
52
55
  array: ArrayField,
53
56
  blocks: BlockBuilderField,
54
57
  group: GroupField,
@@ -71,7 +74,9 @@ export function FieldRenderer({ field, value, onChange }: FieldRendererProps) {
71
74
  return (
72
75
  <Component
73
76
  label={field.label}
74
- value={value}
77
+ // Controls default a missing value but not a `null` one, and stored
78
+ // documents hold `null` for cleared optional fields.
79
+ value={value ?? undefined}
75
80
  onChange={onChange}
76
81
  required={field.required}
77
82
  maxLength={field.maxLength}
@@ -0,0 +1,191 @@
1
+ import { humanizeFieldName } from './post-types-service.js'
2
+
3
+ /**
4
+ * Fields the post editor already has a home for: the Post tab's identity
5
+ * fields, the Article Body section, the section list, and everything the
6
+ * SEO & GEO tab saves. A post type's remaining fields are its custom fields.
7
+ */
8
+ const EDITOR_OWNED_FIELDS: ReadonlySet<string> = new Set([
9
+ // Post tab and canvas
10
+ 'title',
11
+ 'slug',
12
+ 'excerpt',
13
+ 'featuredImage',
14
+ 'body',
15
+ 'category',
16
+ 'tags',
17
+ 'publishDate',
18
+ 'sections',
19
+ // SEO & GEO tab
20
+ 'metaTitle',
21
+ 'metaDescription',
22
+ 'focusKeyword',
23
+ 'keyTakeaway',
24
+ 'canonical',
25
+ 'robotsPolicy',
26
+ 'noIndex',
27
+ 'noindex',
28
+ 'noFollow',
29
+ 'nofollow',
30
+ 'ogTitle',
31
+ 'ogDescription',
32
+ 'ogImage',
33
+ 'twitterTitle',
34
+ 'twitterDescription',
35
+ 'twitterImage',
36
+ 'isCornerstone',
37
+ 'schemaType',
38
+ 'structuredDataType',
39
+ 'structuredData',
40
+ 'llmsInclude',
41
+ 'llmsSection',
42
+ 'llmsOptional',
43
+ 'llmsDescription',
44
+ // Read by the server as lifecycle status or the page-builder envelope,
45
+ // never as a plain field value.
46
+ 'status',
47
+ 'data',
48
+ 'layout',
49
+ 'pageSettings',
50
+ ])
51
+
52
+ /**
53
+ * Field types the Post tab can edit and store correctly. `media`,
54
+ * `relationship`, `number`, `blocks`, `nav`, `componentBlock`, `color`, `json`
55
+ * and multi-value selects are left out: their generic controls either write a
56
+ * placeholder, search the wrong collection, or cannot hold the stored shape.
57
+ */
58
+ const SIMPLE_TYPES: ReadonlySet<string> = new Set([
59
+ 'text',
60
+ 'richText',
61
+ 'url',
62
+ 'email',
63
+ 'boolean',
64
+ 'date',
65
+ 'select',
66
+ ])
67
+
68
+ /** Sub-field types a row of an `array` field may hold to be editable here. */
69
+ const ROW_FIELD_TYPES: ReadonlySet<string> = new Set(['text', 'url', 'email'])
70
+
71
+ export interface CustomRowField {
72
+ name: string
73
+ label: string
74
+ required: boolean
75
+ maxLength?: number
76
+ }
77
+
78
+ /** A custom field in the shape `FieldRenderer` takes. */
79
+ export interface CustomFieldDefinition {
80
+ name: string
81
+ /** A `FieldRenderer` type, or `rows` for an array of plain text rows. */
82
+ type: string
83
+ label: string
84
+ required?: boolean
85
+ helpText?: string
86
+ options?: string[]
87
+ /** `rows` only: the columns of each row. */
88
+ rowFields?: CustomRowField[]
89
+ /** `rows` only. */
90
+ maxRows?: number
91
+ [key: string]: unknown
92
+ }
93
+
94
+ function optionValues(options: unknown): string[] | undefined {
95
+ if (!Array.isArray(options)) return undefined
96
+ const out: string[] = []
97
+ for (const option of options) {
98
+ if (typeof option === 'string') out.push(option)
99
+ else if (option && typeof option === 'object') {
100
+ const value = (option as { value?: unknown }).value
101
+ if (typeof value === 'string') out.push(value)
102
+ }
103
+ }
104
+ return out
105
+ }
106
+
107
+ function labelOf(def: Record<string, unknown>, name: string): string {
108
+ return typeof def.label === 'string' && def.label.trim() ? def.label : humanizeFieldName(name)
109
+ }
110
+
111
+ /** The columns of an array field, or null when a row holds more than plain text. */
112
+ function rowFieldsOf(def: Record<string, unknown>): CustomRowField[] | null {
113
+ const sub = def.fields
114
+ if (!sub || typeof sub !== 'object' || Array.isArray(sub)) return null
115
+ const out: CustomRowField[] = []
116
+ for (const [name, raw] of Object.entries(sub as Record<string, unknown>)) {
117
+ if (!raw || typeof raw !== 'object') return null
118
+ const field = raw as Record<string, unknown>
119
+ if (typeof field.type !== 'string' || !ROW_FIELD_TYPES.has(field.type)) return null
120
+ // A row is edited and stored whole, so one protected column rules out
121
+ // the array: showing it would expose the column, hiding it could drop it.
122
+ const columnAdmin = field.admin as { readOnly?: unknown } | undefined
123
+ if (field.hidden === true || columnAdmin?.readOnly === true) return null
124
+ out.push({
125
+ name,
126
+ label: labelOf(field, name),
127
+ required: field.required === true,
128
+ maxLength: typeof field.maxLength === 'number' ? field.maxLength : undefined,
129
+ })
130
+ }
131
+ return out.length > 0 ? out : null
132
+ }
133
+
134
+ /**
135
+ * The post type's own fields, in config order: every declared field the
136
+ * editor does not already manage, that is not hidden or read-only, and that
137
+ * the Post tab has a working control for.
138
+ */
139
+ export function customPostFields(
140
+ fields: Record<string, unknown> | undefined | null,
141
+ ): CustomFieldDefinition[] {
142
+ if (!fields || typeof fields !== 'object') return []
143
+ const out: CustomFieldDefinition[] = []
144
+ for (const [name, raw] of Object.entries(fields)) {
145
+ if (EDITOR_OWNED_FIELDS.has(name)) continue
146
+ if (!raw || typeof raw !== 'object') continue
147
+ const def = raw as Record<string, unknown>
148
+ if (def.hidden === true) continue
149
+ const admin = def.admin as { description?: unknown; readOnly?: unknown } | undefined
150
+ if (admin?.readOnly === true) continue
151
+ const type = typeof def.type === 'string' ? def.type : undefined
152
+ if (!type) continue
153
+
154
+ const base = {
155
+ name,
156
+ label: labelOf(def, name),
157
+ required: def.required === true,
158
+ helpText:
159
+ typeof def.helpText === 'string'
160
+ ? def.helpText
161
+ : typeof admin?.description === 'string'
162
+ ? admin.description
163
+ : undefined,
164
+ }
165
+
166
+ if (type === 'array') {
167
+ const rowFields = rowFieldsOf(def)
168
+ if (!rowFields) continue
169
+ out.push({
170
+ ...base,
171
+ type: 'rows',
172
+ rowFields,
173
+ maxRows: typeof def.maxRows === 'number' ? def.maxRows : undefined,
174
+ })
175
+ continue
176
+ }
177
+
178
+ if (!SIMPLE_TYPES.has(type)) continue
179
+ if (type === 'select' && def.multiple === true) continue
180
+ // The date control is date-only; it would write `YYYY-MM-DD` over a
181
+ // stored time.
182
+ if (type === 'date' && def.includeTime === true) continue
183
+ out.push({
184
+ ...base,
185
+ type,
186
+ maxLength: typeof def.maxLength === 'number' ? def.maxLength : undefined,
187
+ options: optionValues(def.options),
188
+ })
189
+ }
190
+ return out
191
+ }