@nocode-factory/sanity-kit 2.25.0 → 2.27.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/{componentDefaults-BY3hQ6aD.js → componentDefaults-2eWjLLBf.js} +6 -6
- package/dist/componentDefaults-2eWjLLBf.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +605 -406
- package/dist/index.js.map +1 -1
- package/dist/schema.js +1 -1
- package/dist/web-server.js +2 -2
- package/dist/web-server.js.map +1 -1
- package/dist/web.js +9 -9
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/PropagatePublish.tsx +52 -21
- package/src/actions/RemoveFromSite.tsx +9 -9
- package/src/config/defaults.ts +8 -8
- package/src/config/resolve.ts +4 -1
- package/src/config/types.ts +8 -0
- package/src/config/validate.ts +24 -24
- package/src/context/BoardLayoutContext.tsx +1 -1
- package/src/context/KitContext.tsx +1 -1
- package/src/context/PreviewTargetContext.tsx +1 -1
- package/src/form/OverrideInput.tsx +67 -6
- package/src/form/SlugUrlInput.tsx +2 -2
- package/src/form/TranslationTodoInput.tsx +38 -4
- package/src/hooks/useHistory.ts +5 -5
- package/src/hooks/useOccurrences.ts +1 -1
- package/src/hooks/useOpenOnline.ts +4 -4
- package/src/hooks/useTranslationTodo.ts +2 -1
- package/src/index.ts +9 -5
- package/src/lib/aiTexts.ts +72 -0
- package/src/lib/aiTranslate.ts +61 -0
- package/src/lib/grouping.ts +2 -2
- package/src/lib/overrides.ts +10 -10
- package/src/lib/pages.ts +3 -3
- package/src/lib/service.ts +5 -5
- package/src/lib/status.ts +3 -3
- package/src/lib/studioLinks.ts +6 -6
- package/src/schema/boardLayout.ts +32 -32
- package/src/schema/componentDefaults.ts +5 -5
- package/src/schema/translationTodo.ts +6 -6
- package/src/tools/components/BlockCard.tsx +3 -3
- package/src/tools/components/ComponentsTool.tsx +17 -17
- package/src/tools/components/map/SectionNode.tsx +1 -1
- package/src/tools/components/map/SectionsMap.tsx +10 -10
- package/src/tools/designSystem/DesignSystemTool.tsx +3 -3
- package/src/tools/history/DiffPanel.tsx +23 -23
- package/src/tools/history/HistoryTool.tsx +21 -23
- package/src/tools/more/MoreTool.tsx +1 -1
- package/src/tools/navbar/KitUpdate.tsx +8 -8
- package/src/tools/navbar/PreviewLauncher.tsx +6 -6
- package/src/tools/navbar/ToolButtons.tsx +2 -2
- package/src/tools/pages/ColumnHeader.tsx +18 -18
- package/src/tools/pages/ColumnVisibility.tsx +10 -10
- package/src/tools/pages/FieldValue.tsx +9 -9
- package/src/tools/pages/PagesTable.tsx +11 -11
- package/src/tools/pages/PagesTool.tsx +19 -19
- package/src/tools/pages/PagesToolbar.tsx +3 -3
- package/src/tools/pages/PathCell.tsx +1 -1
- package/src/tools/pages/PreviewTarget.tsx +10 -10
- package/src/tools/pages/SharePreview.tsx +19 -20
- package/src/tools/pages/TagCell.tsx +2 -2
- package/src/tools/pages/ViewTabs.tsx +4 -4
- package/src/tools/pages/board/BoardView.tsx +11 -11
- package/src/tools/pages/board/PageNode.tsx +5 -5
- package/src/tools/pages/board/PagePanel.tsx +10 -10
- package/src/tools/presentation/PreviewHeader.tsx +1 -1
- package/src/tools/shared/AnnotationNode.tsx +3 -3
- package/src/ui/ActorName.tsx +1 -1
- package/src/ui/ConfigIssues.tsx +3 -3
- package/src/ui/PreviewOriginsNotice.tsx +3 -3
- package/src/ui/ProjectStatusNotice.tsx +7 -7
- package/src/ui/QueryError.tsx +2 -2
- package/src/ui/ToolPlaceholder.tsx +2 -2
- package/src/ui/formatDate.ts +1 -1
- package/src/version.ts +1 -1
- package/src/web/PreviewBanner.tsx +9 -9
- package/src/web/draftModeToggle.ts +1 -1
- package/src/web/previewGrant.ts +5 -5
- package/dist/componentDefaults-BY3hQ6aD.js.map +0 -1
|
@@ -223,10 +223,10 @@ function TreeNode(props: NodeProps<PageFlowNode> & {data: PageNodeData}) {
|
|
|
223
223
|
<Flex align="center" justify="center" style={{height: '100%'}}>
|
|
224
224
|
<Text size={0} muted>
|
|
225
225
|
{thumbnailFailed
|
|
226
|
-
? '
|
|
226
|
+
? 'Screenshot not generated'
|
|
227
227
|
: siteUrl
|
|
228
|
-
? '
|
|
229
|
-
: '
|
|
228
|
+
? 'Hover to preview'
|
|
229
|
+
: 'No preview'}
|
|
230
230
|
</Text>
|
|
231
231
|
</Flex>
|
|
232
232
|
)}
|
|
@@ -259,7 +259,7 @@ function TreeNode(props: NodeProps<PageFlowNode> & {data: PageNodeData}) {
|
|
|
259
259
|
textOverflow="ellipsis"
|
|
260
260
|
style={{fontSize: Math.round(11 * textScale), lineHeight: 1.3}}
|
|
261
261
|
>
|
|
262
|
-
{tags.find((t) => t.id === tag)?.label ?? '
|
|
262
|
+
{tags.find((t) => t.id === tag)?.label ?? 'No tag'}
|
|
263
263
|
</Text>
|
|
264
264
|
) : (
|
|
265
265
|
<Flex gap={2} align="center">
|
|
@@ -272,7 +272,7 @@ function TreeNode(props: NodeProps<PageFlowNode> & {data: PageNodeData}) {
|
|
|
272
272
|
value={tag ?? ''}
|
|
273
273
|
onChange={(event) => onTag(props.id, event.currentTarget.value || null)}
|
|
274
274
|
>
|
|
275
|
-
<option value="">
|
|
275
|
+
<option value="">No tag</option>
|
|
276
276
|
{tags.map((option) => (
|
|
277
277
|
<option key={option.id} value={option.id}>
|
|
278
278
|
{option.label}
|
|
@@ -83,7 +83,7 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
83
83
|
padding={1}
|
|
84
84
|
fontSize={0}
|
|
85
85
|
icon={CloseIcon}
|
|
86
|
-
aria-label="
|
|
86
|
+
aria-label="Close"
|
|
87
87
|
onClick={onClose}
|
|
88
88
|
/>
|
|
89
89
|
</Flex>
|
|
@@ -112,7 +112,7 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
112
112
|
) : (
|
|
113
113
|
<Flex align="center" justify="center" style={{height: '100%'}} padding={3}>
|
|
114
114
|
<Text size={0} muted align="center">
|
|
115
|
-
{failed ? '
|
|
115
|
+
{failed ? 'Screenshot not generated' : 'No screenshot'}
|
|
116
116
|
</Text>
|
|
117
117
|
</Flex>
|
|
118
118
|
)}
|
|
@@ -145,19 +145,19 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
145
145
|
</Text>
|
|
146
146
|
|
|
147
147
|
<Text size={0} muted>
|
|
148
|
-
{incoming}
|
|
148
|
+
{incoming} incoming link(s) · {outgoing} outgoing
|
|
149
149
|
</Text>
|
|
150
150
|
|
|
151
151
|
<Stack gap={2}>
|
|
152
152
|
<Text size={0} weight="semibold" muted>
|
|
153
|
-
|
|
153
|
+
Tag
|
|
154
154
|
</Text>
|
|
155
155
|
<Select
|
|
156
156
|
fontSize={1}
|
|
157
157
|
value={tag ?? ''}
|
|
158
158
|
onChange={(event) => onTag(row.id, event.currentTarget.value || null)}
|
|
159
159
|
>
|
|
160
|
-
<option value="">
|
|
160
|
+
<option value="">No tag</option>
|
|
161
161
|
{tags.map((option) => (
|
|
162
162
|
<option key={option.id} value={option.id}>
|
|
163
163
|
{option.label}
|
|
@@ -169,7 +169,7 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
169
169
|
{columns.length > 0 && (
|
|
170
170
|
<Stack gap={2}>
|
|
171
171
|
<Text size={0} weight="semibold" muted>
|
|
172
|
-
|
|
172
|
+
Internal management
|
|
173
173
|
</Text>
|
|
174
174
|
{columns.map((column) => (
|
|
175
175
|
<Flex key={column.id} align="center" gap={2}>
|
|
@@ -199,8 +199,8 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
199
199
|
mode="default"
|
|
200
200
|
fontSize={1}
|
|
201
201
|
padding={2}
|
|
202
|
-
text="
|
|
203
|
-
title="
|
|
202
|
+
text="Open page"
|
|
203
|
+
title="Opens in Presentation"
|
|
204
204
|
onClick={onOpen}
|
|
205
205
|
/>
|
|
206
206
|
<IntentLink
|
|
@@ -208,7 +208,7 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
208
208
|
params={{id: row.id, type: row.type}}
|
|
209
209
|
style={{textDecoration: 'none'}}
|
|
210
210
|
>
|
|
211
|
-
<Button mode="ghost" fontSize={1} padding={2} text="
|
|
211
|
+
<Button mode="ghost" fontSize={1} padding={2} text="Edit" as="span" />
|
|
212
212
|
</IntentLink>
|
|
213
213
|
{siteUrl && (
|
|
214
214
|
<Button
|
|
@@ -228,7 +228,7 @@ export function PagePanel(props: PagePanelProps) {
|
|
|
228
228
|
icon={LaunchIcon}
|
|
229
229
|
// Le libellé nomme l'environnement dès qu'il y a un choix :
|
|
230
230
|
// « Voir en ligne » serait faux en pointant une recette.
|
|
231
|
-
text={environments.length > 1 ? (environment?.label ?? '
|
|
231
|
+
text={environments.length > 1 ? (environment?.label ?? 'View') : 'View live'}
|
|
232
232
|
title={siteUrl}
|
|
233
233
|
/>
|
|
234
234
|
)}
|
|
@@ -82,7 +82,7 @@ function AnnotationNodeComponent(props: NodeProps<AnnotationFlowNode>) {
|
|
|
82
82
|
overflow: 'hidden',
|
|
83
83
|
}}
|
|
84
84
|
>
|
|
85
|
-
{annotation.text || 'Double-
|
|
85
|
+
{annotation.text || 'Double-click to write'}
|
|
86
86
|
</Box>
|
|
87
87
|
)}
|
|
88
88
|
|
|
@@ -112,8 +112,8 @@ function AnnotationNodeComponent(props: NodeProps<AnnotationFlowNode>) {
|
|
|
112
112
|
fontSize={0}
|
|
113
113
|
icon={TrashIcon}
|
|
114
114
|
tone="critical"
|
|
115
|
-
title="
|
|
116
|
-
aria-label="
|
|
115
|
+
title="Delete annotation"
|
|
116
|
+
aria-label="Delete annotation"
|
|
117
117
|
onClick={() => onRemove(annotation.id)}
|
|
118
118
|
/>
|
|
119
119
|
</Flex>
|
package/src/ui/ActorName.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import {useUser} from 'sanity'
|
|
|
10
10
|
*/
|
|
11
11
|
export function ActorName(props: {actorId: string | null; actorName: string | null}) {
|
|
12
12
|
const [user] = useUser(props.actorId ?? '')
|
|
13
|
-
const label = props.actorName || user?.displayName || (props.actorId ? '
|
|
13
|
+
const label = props.actorName || user?.displayName || (props.actorId ? 'Unknown account' : '—')
|
|
14
14
|
|
|
15
15
|
return (
|
|
16
16
|
<Text size={0} muted textOverflow="ellipsis" title={props.actorId ?? undefined}>
|
package/src/ui/ConfigIssues.tsx
CHANGED
|
@@ -19,8 +19,8 @@ export function ConfigIssues(props: {issues: ConfigIssue[]; toolTitle: string})
|
|
|
19
19
|
<Stack gap={4}>
|
|
20
20
|
<Text weight="semibold">
|
|
21
21
|
{blocking
|
|
22
|
-
?
|
|
23
|
-
:
|
|
22
|
+
? `"${toolTitle}" is disabled: the ncfKit() configuration is incomplete.`
|
|
23
|
+
: `"${toolTitle}" is running in degraded mode.`}
|
|
24
24
|
</Text>
|
|
25
25
|
<Stack gap={3} as="ul">
|
|
26
26
|
{issues.map((issue) => (
|
|
@@ -31,7 +31,7 @@ export function ConfigIssues(props: {issues: ConfigIssue[]; toolTitle: string})
|
|
|
31
31
|
))}
|
|
32
32
|
</Stack>
|
|
33
33
|
<Text size={1} muted>
|
|
34
|
-
|
|
34
|
+
Fix it in the ncfKit() call in sanity.config.ts.
|
|
35
35
|
</Text>
|
|
36
36
|
</Stack>
|
|
37
37
|
</Card>
|
|
@@ -22,15 +22,15 @@ export function PreviewOriginsNotice() {
|
|
|
22
22
|
<Container width={2}>
|
|
23
23
|
<Card padding={4} radius={3} shadow={1} tone="caution">
|
|
24
24
|
<Stack gap={3}>
|
|
25
|
-
<Text weight="semibold">
|
|
25
|
+
<Text weight="semibold">Preview not interactive on {missing.length > 1 ? 'these environments' : 'this environment'}</Text>
|
|
26
26
|
<Stack gap={2}>
|
|
27
27
|
{missing.map((origin) => (
|
|
28
28
|
<InlineCode key={origin}>{origin}</InlineCode>
|
|
29
29
|
))}
|
|
30
30
|
</Stack>
|
|
31
31
|
<Text size={1}>
|
|
32
|
-
Presentation
|
|
33
|
-
|
|
32
|
+
Presentation does not allow {missing.length > 1 ? 'these origins' : 'this origin'}: the page is shown without visual editing. In sanity.config.ts,
|
|
33
|
+
pass <InlineCode>allowOrigins: ncfAllowedOrigins(options)</InlineCode> to presentationTool.
|
|
34
34
|
</Text>
|
|
35
35
|
</Stack>
|
|
36
36
|
</Card>
|
|
@@ -25,10 +25,10 @@ export function ProjectStatusNotice(props: {registration: Registration | null})
|
|
|
25
25
|
<Card padding={3} radius={2} tone="caution">
|
|
26
26
|
<Stack gap={2}>
|
|
27
27
|
<Text size={1} weight="semibold">
|
|
28
|
-
|
|
28
|
+
The log is not enabled for this project yet.
|
|
29
29
|
</Text>
|
|
30
30
|
<Text size={0} muted>
|
|
31
|
-
NoCode Factory
|
|
31
|
+
NoCode Factory enables it by running <code>npx ncf-kit setup</code> in the studio folder.
|
|
32
32
|
</Text>
|
|
33
33
|
</Stack>
|
|
34
34
|
</Card>
|
|
@@ -37,10 +37,10 @@ export function ProjectStatusNotice(props: {registration: Registration | null})
|
|
|
37
37
|
|
|
38
38
|
const message =
|
|
39
39
|
status === 'expired'
|
|
40
|
-
? "
|
|
40
|
+
? "Access to this project has expired."
|
|
41
41
|
: status === 'suspended'
|
|
42
|
-
? '
|
|
43
|
-
: "
|
|
42
|
+
? 'This project is suspended.'
|
|
43
|
+
: "This project is no longer authorized."
|
|
44
44
|
|
|
45
45
|
return (
|
|
46
46
|
<Card padding={3} radius={2} tone="caution">
|
|
@@ -49,8 +49,8 @@ export function ProjectStatusNotice(props: {registration: Registration | null})
|
|
|
49
49
|
{message}
|
|
50
50
|
</Text>
|
|
51
51
|
<Text size={0} muted>
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
The tools remain usable, but the change log is stopped.
|
|
53
|
+
Contact NoCode Factory to restore the service.
|
|
54
54
|
</Text>
|
|
55
55
|
</Stack>
|
|
56
56
|
</Card>
|
package/src/ui/QueryError.tsx
CHANGED
|
@@ -5,10 +5,10 @@ export function QueryError(props: {error: Error; onRetry: () => void}) {
|
|
|
5
5
|
return (
|
|
6
6
|
<Card padding={4} radius={3} shadow={1} tone="critical">
|
|
7
7
|
<Stack gap={4}>
|
|
8
|
-
<Text weight="semibold">
|
|
8
|
+
<Text weight="semibold">The query failed.</Text>
|
|
9
9
|
<Text size={1}>{props.error.message}</Text>
|
|
10
10
|
<div>
|
|
11
|
-
<Button text="
|
|
11
|
+
<Button text="Retry" mode="ghost" onClick={props.onRetry} />
|
|
12
12
|
</div>
|
|
13
13
|
</Stack>
|
|
14
14
|
</Card>
|
|
@@ -12,8 +12,8 @@ export function ToolPlaceholder(props: {title: string; phase: string; children?:
|
|
|
12
12
|
{title}
|
|
13
13
|
</Text>
|
|
14
14
|
<Text size={1} muted>
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Coming in {phase}. The plugin foundation is in place: configuration read, validated, and
|
|
16
|
+
tool mounted in the Studio.
|
|
17
17
|
</Text>
|
|
18
18
|
{children}
|
|
19
19
|
</Stack>
|
package/src/ui/formatDate.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -61,7 +61,7 @@ export interface PreviewBannerProps {
|
|
|
61
61
|
* `isPreviewSite()`.
|
|
62
62
|
*/
|
|
63
63
|
export function NcfPreviewBanner(props: PreviewBannerProps) {
|
|
64
|
-
const {isDraft, togglePath = '/api/draft-mode/toggle', label = '
|
|
64
|
+
const {isDraft, togglePath = '/api/draft-mode/toggle', label = 'Preview'} = props
|
|
65
65
|
const pathname = usePathname()
|
|
66
66
|
// Clé de préversion mémorisée par le garde (absente avec une session Presentation).
|
|
67
67
|
const grant = useSyncExternalStore(noSubscribe, readGrant, () => null)
|
|
@@ -110,32 +110,32 @@ export function NcfPreviewBanner(props: PreviewBannerProps) {
|
|
|
110
110
|
</span>
|
|
111
111
|
|
|
112
112
|
<span aria-hidden style={divider} />
|
|
113
|
-
<span style={{opacity: 0.75}}>
|
|
113
|
+
<span style={{opacity: 0.75}}>Data</span>
|
|
114
114
|
|
|
115
|
-
<span role="group" aria-label="
|
|
115
|
+
<span role="group" aria-label="Displayed data" style={{display: 'inline-flex', gap: 2}}>
|
|
116
116
|
<a
|
|
117
117
|
href={href(true)}
|
|
118
|
-
title="
|
|
118
|
+
title="What will go live after publishing"
|
|
119
119
|
aria-current={isDraft ? 'true' : undefined}
|
|
120
120
|
style={isDraft ? segmentOn : segmentOff}
|
|
121
121
|
>
|
|
122
|
-
|
|
122
|
+
Drafts
|
|
123
123
|
</a>
|
|
124
124
|
<a
|
|
125
125
|
href={href(false)}
|
|
126
|
-
title="
|
|
126
|
+
title="What the public sees today"
|
|
127
127
|
aria-current={isDraft ? undefined : 'true'}
|
|
128
128
|
style={isDraft ? segmentOff : segmentOn}
|
|
129
129
|
>
|
|
130
|
-
|
|
130
|
+
Published
|
|
131
131
|
</a>
|
|
132
132
|
</span>
|
|
133
133
|
|
|
134
134
|
{grant && (
|
|
135
135
|
<>
|
|
136
136
|
<span aria-hidden style={divider} />
|
|
137
|
-
<button type="button" onClick={share} title="
|
|
138
|
-
{copied ? '
|
|
137
|
+
<button type="button" onClick={share} title="Copy the address of this page, including the preview key" style={shareButton}>
|
|
138
|
+
{copied ? 'Link copied' : 'Copy link'}
|
|
139
139
|
</button>
|
|
140
140
|
</>
|
|
141
141
|
)}
|
|
@@ -36,7 +36,7 @@ export function ncfDraftModeToggle(options: DraftModeToggleOptions = {}) {
|
|
|
36
36
|
if (isProductionSite()) {
|
|
37
37
|
;(await draftMode()).disable()
|
|
38
38
|
return NextResponse.json(
|
|
39
|
-
{error: '
|
|
39
|
+
{error: 'Draft mode is disabled in production.'},
|
|
40
40
|
{status: 403},
|
|
41
41
|
)
|
|
42
42
|
}
|
package/src/web/previewGrant.ts
CHANGED
|
@@ -193,14 +193,14 @@ function refuse(request: NextRequest): NextResponse {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
const PAGE = `<!doctype html>
|
|
196
|
-
<html lang="
|
|
196
|
+
<html lang="en"><head><meta charset="utf-8">
|
|
197
197
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
198
198
|
<meta name="robots" content="noindex">
|
|
199
|
-
<title>
|
|
199
|
+
<title>Private preview</title></head>
|
|
200
200
|
<body style="margin:0;min-height:100vh;display:grid;place-items:center;background:#faf9f7;color:#1c1917;font:16px/1.6 ui-sans-serif,system-ui,-apple-system,Segoe UI,sans-serif">
|
|
201
201
|
<main style="max-width:30rem;padding:2rem;text-align:center">
|
|
202
202
|
<p style="display:inline-flex;align-items:center;gap:.5rem;margin:0 0 1.25rem;padding:.3rem .75rem;border-radius:999px;background:#fef3c7;color:#451a03;font-size:.8125rem;font-weight:500">
|
|
203
|
-
<span style="width:7px;height:7px;border-radius:50%;background:#d97706"></span>
|
|
204
|
-
<h1 style="margin:0 0 .75rem;font-size:1.375rem;font-weight:600">
|
|
205
|
-
<p style="margin:0;color:#57534e">
|
|
203
|
+
<span style="width:7px;height:7px;border-radius:50%;background:#d97706"></span>Preview</p>
|
|
204
|
+
<h1 style="margin:0 0 .75rem;font-size:1.375rem;font-weight:600">This version of the site is private</h1>
|
|
205
|
+
<p style="margin:0;color:#57534e">It is used to review content before it goes live. To access it, ask your NoCode Factory contact for a share link.</p>
|
|
206
206
|
</main></body></html>`
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"componentDefaults-BY3hQ6aD.js","names":[],"sources":["../src/schema/componentDefaults.ts"],"sourcesContent":["import {defineField, defineType, type Rule} from 'sanity'\n\n/**\n * VALEURS PAR DÉFAUT DES COMPOSANTS, côté Studio.\n *\n * Un document (un par langue) avec un bloc par composant de la bibliothèque,\n * GÉNÉRÉ depuis les schémas des sections : une section ajoutée y apparaît sans\n * rien faire. Une instance dont un champ est vide affiche la valeur par défaut ;\n * un champ rempli (override) n'est jamais écrasé. Côté site :\n * `@nocode-factory/sanity-kit/web/defaults`. Dans le Studio, l'onglet Composants\n * ouvre chaque composant (rendu réel + réglages), et une pastille bleue marque\n * chaque champ d'instance qui diffère de la valeur par défaut.\n *\n * Deux règles pour les champs de section, qui en découlent :\n * - jamais d'`initialValue` (ce serait un override involontaire) ;\n * - « obligatoire » = `requiredUnlessDefault`.\n */\n\ntype FieldDef = {name: string; type: string; validation?: unknown; initialValue?: unknown; fields?: FieldDef[]; of?: FieldDef[]; [k: string]: unknown}\ntype SectionDef = {name: string; title?: string; fields: FieldDef[]}\n\nexport const DEFAULT_COMPONENT_DEFAULTS_TYPE = 'componentDefaults'\n\n/** Nom du champ d'un composant dans le document des valeurs par défaut : `section.cta` -> `cta`. */\nexport function defaultsFieldName(type: string, namespace = 'section.'): string {\n return type.startsWith(namespace) ? type.slice(namespace.length) : type\n}\n\n// Dans les valeurs par défaut, rien n'est obligatoire et rien n'est prérempli.\nconst relax = (f: FieldDef): FieldDef => {\n const {validation: _v, initialValue: _i, ...rest} = f\n return {\n ...rest,\n ...(rest.fields ? {fields: rest.fields.map(relax)} : {}),\n ...(rest.of ? {of: rest.of.map(relax)} : {}),\n }\n}\n\n/** Document « Composants : valeurs par défaut », généré depuis les sections. */\nexport function defineComponentDefaults(options: {sections: readonly unknown[]; name?: string; title?: string; namespace?: string}) {\n const {name = DEFAULT_COMPONENT_DEFAULTS_TYPE, title = '🧩 Composants : valeurs par défaut', namespace = 'section.'} = options\n return defineType({\n name,\n title,\n type: 'document',\n description:\n 'Valeurs appliquées à chaque instance d\\'un composant dont le champ est vide. Un champ rempli dans une instance reste prioritaire (override).',\n fields: (options.sections as SectionDef[]).map((t) =>\n defineField({\n name: defaultsFieldName(t.name, namespace),\n title: t.title || t.name,\n type: 'object',\n description: 'Valeurs par défaut de ce composant. Vide = valeur du design system.',\n options: {collapsible: true, collapsed: true},\n fields: t.fields.map(relax) as never,\n }),\n ),\n preview: {prepare: () => ({title: title.replace(/^\\S+\\s/, '')})},\n })\n}\n\nconst isEmpty = (v: unknown) => v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0)\n\n/**\n * Règle « obligatoire SAUF si le composant a une valeur par défaut » pour un autre\n * type de document des valeurs par défaut ou un autre espace de noms.\n * `validation: requiredUnlessDefaultFor({type: 'mesDefauts'})`\n */\nexport function requiredUnlessDefaultFor(options: {type?: string; namespace?: string} = {}) {\n const {type: defaultsType = DEFAULT_COMPONENT_DEFAULTS_TYPE, namespace = 'section.'} = options\n return <R>(rule: R): R =>\n (rule as unknown as Rule).custom(async (value, context) => {\n if (!isEmpty(value)) return true\n const type = (context.parent as {_type?: string} | undefined)?._type\n const field = context.path?.[context.path.length - 1]\n const name = type ? defaultsFieldName(type, namespace) : ''\n if (!type?.startsWith(namespace) || typeof field !== 'string' || !/^\\w+$/.test(name) || !/^\\w+$/.test(field)) return 'Obligatoire.'\n const language = (context.document as {language?: string} | undefined)?.language ?? null\n const inherited = await context\n .getClient({apiVersion: '2024-10-01'})\n .fetch(\n `*[_type == $defaultsType && !(_id in path(\"drafts.**\")) && ($language == null || language == $language)][0].${name}.${field}`,\n {defaultsType, language},\n )\n return isEmpty(inherited) ? 'Obligatoire (ou à définir dans Composants > valeurs par défaut).' : true\n }) as unknown as R\n}\n\n/**\n * Champ de section obligatoire, SAUF si le composant a une valeur par défaut\n * pour ce champ (elle s'affichera). Tout type de champ.\n * `validation: requiredUnlessDefault`\n */\nexport const requiredUnlessDefault: <R>(rule: R) => R = requiredUnlessDefaultFor()\n\n/**\n * Presentation : la page qui rend un composant seul (par défaut\n * `/design-system/composant`) a pour document principal les valeurs par défaut.\n * Rendu réel et réglages côte à côte, en direct.\n * `presentationTool({resolve: {mainDocuments: defineDocuments([componentDefaultsMainDocument({language: 'fr'})])}})`\n */\nexport function componentDefaultsMainDocument(options: {language?: string; route?: string; type?: string} = {}): {route: string; filter: string} {\n const {language, route = '/design-system/composant', type = DEFAULT_COMPONENT_DEFAULTS_TYPE} = options\n const safeLang = language && /^[a-z]{2}(-[A-Za-z]{2})?$/.test(language) ? language : null\n return {route, filter: `_type == \"${type}\"${safeLang ? ` && language == \"${safeLang}\"` : ''}`}\n}\n\n/**\n * Presentation : les pages du design system ont pour document principal les valeurs\n * par défaut des composants. `/design-system` (toute la bibliothèque) et\n * `/design-system/composant` (un composant seul) : cliquer un composant ouvre ses\n * réglages globaux, et un style changé change le composant partout où il n'est\n * pas surchargé.\n * `presentationTool({resolve: {mainDocuments: defineDocuments(componentDefaultsMainDocuments({language: 'fr'}))}})`\n */\nexport function componentDefaultsMainDocuments(\n options: {language?: string; type?: string; routes?: string[]} = {},\n): {route: string; filter: string}[] {\n const {routes = ['/design-system/composant', '/design-system'], ...rest} = options\n return routes.map((route) => componentDefaultsMainDocument({...rest, route}))\n}\n"],"mappings":";AAqBA,MAAa,kCAAkC;;AAG/C,SAAgB,kBAAkB,MAAc,YAAY,YAAoB;CAC9E,OAAO,KAAK,WAAW,SAAS,IAAI,KAAK,MAAM,UAAU,MAAM,IAAI;AACrE;AAGA,MAAM,SAAS,MAA0B;CACvC,IAAM,EAAC,YAAY,IAAI,cAAc,IAAI,GAAG,SAAQ;CACpD,OAAO;EACL,GAAG;EACH,GAAI,KAAK,SAAS,EAAC,QAAQ,KAAK,OAAO,IAAI,KAAK,EAAC,IAAI,CAAC;EACtD,GAAI,KAAK,KAAK,EAAC,IAAI,KAAK,GAAG,IAAI,KAAK,EAAC,IAAI,CAAC;CAC5C;AACF;;AAGA,SAAgB,wBAAwB,SAA4F;CAClI,IAAM,EAAC,OAAO,iCAAiC,QAAQ,sCAAsC,YAAY,eAAc;CACvH,OAAO,WAAW;EAChB;EACA;EACA,MAAM;EACN,aACE;EACF,QAAS,QAAQ,SAA0B,KAAK,MAC9C,YAAY;GACV,MAAM,kBAAkB,EAAE,MAAM,SAAS;GACzC,OAAO,EAAE,SAAS,EAAE;GACpB,MAAM;GACN,aAAa;GACb,SAAS;IAAC,aAAa;IAAM,WAAW;GAAI;GAC5C,QAAQ,EAAE,OAAO,IAAI,KAAK;EAC5B,CAAC,CACH;EACA,SAAS,EAAC,gBAAgB,EAAC,OAAO,MAAM,QAAQ,UAAU,EAAE,EAAC,GAAE;CACjE,CAAC;AACH;AAEA,MAAM,WAAW,MAAe,KAAyB,QAAQ,MAAM,MAAO,MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW;;;;;;AAO/G,SAAgB,yBAAyB,UAA+C,CAAC,GAAG;CAC1F,IAAM,EAAC,MAAM,eAAe,iCAAiC,YAAY,eAAc;CACvF,QAAW,SACR,KAAyB,OAAO,OAAO,OAAO,YAAY;EACzD,IAAI,CAAC,QAAQ,KAAK,GAAG,OAAO;EAC5B,IAAM,OAAQ,QAAQ,QAAyC,OACzD,QAAQ,QAAQ,OAAO,QAAQ,KAAK,SAAS,IAC7C,OAAO,OAAO,kBAAkB,MAAM,SAAS,IAAI;EACzD,IAAI,CAAC,MAAM,WAAW,SAAS,KAAK,OAAO,SAAU,YAAY,CAAC,QAAQ,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,GAAG,OAAO;EACrH,IAAM,WAAY,QAAQ,UAA8C,YAAY,MAC9E,YAAY,MAAM,QACrB,UAAU,EAAC,YAAY,aAAY,CAAC,CAAC,CACrC,MACC,+GAA+G,KAAK,GAAG,SACvH;GAAC;GAAc;EAAQ,CACzB;EACF,OAAO,SAAQ,SAAS,KAAI;CAC9B,CAAC;AACL;;;;;;AAOA,MAAa,wBAA2C,yBAAyB;;;;;;;AAQjF,SAAgB,8BAA8B,UAA8D,CAAC,GAAoC;CAC/I,IAAM,EAAC,UAAU,QAAQ,4BAA4B,OAAO,oCAAmC,SACzF,WAAW,YAAY,4BAA4B,KAAK,QAAQ,IAAI,WAAW;CACrF,OAAO;EAAC;EAAO,QAAQ,aAAa,KAAK,GAAG,WAAW,oBAAoB,SAAS,KAAK;CAAI;AAC/F;;;;;;;;;AAUA,SAAgB,+BACd,UAAiE,CAAC,GAC/B;CACnC,IAAM,EAAC,SAAS,CAAC,4BAA4B,gBAAgB,GAAG,GAAG,SAAQ;CAC3E,OAAO,OAAO,KAAK,UAAU,8BAA8B;EAAC,GAAG;EAAM;CAAK,CAAC,CAAC;AAC9E"}
|