@nocode-factory/sanity-kit 2.27.1 → 2.28.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/bin/ncf-kit.mjs +43 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +73 -41
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +38 -1
- package/dist/schema.js +77 -1
- package/dist/schema.js.map +1 -0
- package/package.json +1 -1
- package/src/form/TranslationTodoInput.tsx +25 -2
- package/src/schema/formTabs.ts +53 -0
- package/src/schema/index.ts +2 -0
- package/src/version.ts +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -1,2 +1,39 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CNiuukLt.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Onglets du formulaire d'un document : Content, Sections, SEO, Settings.
|
|
4
|
+
*
|
|
5
|
+
* Un formulaire de page en une seule colonne mélange le contenu, le page builder et
|
|
6
|
+
* les réglages SEO : on cherche, on se trompe de champ. Ici, chaque champ d'un
|
|
7
|
+
* document va dans son onglet d'après son nom ; « Content » s'ouvre par défaut.
|
|
8
|
+
* - Sections : le champ du page builder (`pageBuilderField`, défaut `pageBuilder`).
|
|
9
|
+
* - SEO : `seo`, `structuredData` et les champs de métadonnées connus.
|
|
10
|
+
* - Settings : réglages de page (`pageOptions`, `options`, `settings`...).
|
|
11
|
+
* - Content : tout le reste (titre, slug, corps, image...).
|
|
12
|
+
* Un type qui déclare déjà ses `groups` n'est pas touché ; un champ qui a déjà son
|
|
13
|
+
* `group` le garde. Pas d'onglets pour un document qui n'aurait qu'un onglet.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* schema: {types: withNcfFormTabs(schemaTypes, {pageBuilderField: 'pageBuilder'})}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const GROUPS: readonly [{
|
|
20
|
+
readonly name: "content";
|
|
21
|
+
readonly title: "Content";
|
|
22
|
+
readonly default: true;
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "sections";
|
|
25
|
+
readonly title: "Sections";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "seo";
|
|
28
|
+
readonly title: "SEO";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "settings";
|
|
31
|
+
readonly title: "Settings";
|
|
32
|
+
}];
|
|
33
|
+
/** Onglet d'un champ d'après son nom. */
|
|
34
|
+
export declare function formTabOf(name: string, pageBuilderField?: string): (typeof GROUPS)[number]['name'];
|
|
35
|
+
export declare function withNcfFormTabs<T>(types: readonly T[], options?: {
|
|
36
|
+
pageBuilderField?: string;
|
|
37
|
+
}): T[];
|
|
38
|
+
export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
|
|
39
|
+
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.js
CHANGED
|
@@ -1,2 +1,78 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-2eWjLLBf.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Onglets du formulaire d'un document : Content, Sections, SEO, Settings.
|
|
4
|
+
*
|
|
5
|
+
* Un formulaire de page en une seule colonne mélange le contenu, le page builder et
|
|
6
|
+
* les réglages SEO : on cherche, on se trompe de champ. Ici, chaque champ d'un
|
|
7
|
+
* document va dans son onglet d'après son nom ; « Content » s'ouvre par défaut.
|
|
8
|
+
* - Sections : le champ du page builder (`pageBuilderField`, défaut `pageBuilder`).
|
|
9
|
+
* - SEO : `seo`, `structuredData` et les champs de métadonnées connus.
|
|
10
|
+
* - Settings : réglages de page (`pageOptions`, `options`, `settings`...).
|
|
11
|
+
* - Content : tout le reste (titre, slug, corps, image...).
|
|
12
|
+
* Un type qui déclare déjà ses `groups` n'est pas touché ; un champ qui a déjà son
|
|
13
|
+
* `group` le garde. Pas d'onglets pour un document qui n'aurait qu'un onglet.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* schema: {types: withNcfFormTabs(schemaTypes, {pageBuilderField: 'pageBuilder'})}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const SEO_FIELDS = /* @__PURE__ */ new Set([
|
|
20
|
+
"seo",
|
|
21
|
+
"structuredData",
|
|
22
|
+
"jsonld",
|
|
23
|
+
"noindex",
|
|
24
|
+
"metaTitle",
|
|
25
|
+
"metaDescription",
|
|
26
|
+
"ogImage",
|
|
27
|
+
"canonical",
|
|
28
|
+
"canonicalUrl"
|
|
29
|
+
]), SETTINGS_FIELDS = /* @__PURE__ */ new Set([
|
|
30
|
+
"pageOptions",
|
|
31
|
+
"options",
|
|
32
|
+
"settings",
|
|
33
|
+
"hideFromMenu",
|
|
34
|
+
"showInMenu",
|
|
35
|
+
"parent",
|
|
36
|
+
"publishedAt",
|
|
37
|
+
"redirects"
|
|
38
|
+
]), GROUPS = [
|
|
39
|
+
{
|
|
40
|
+
name: "content",
|
|
41
|
+
title: "Content",
|
|
42
|
+
default: !0
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "sections",
|
|
46
|
+
title: "Sections"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "seo",
|
|
50
|
+
title: "SEO"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "settings",
|
|
54
|
+
title: "Settings"
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
/** Onglet d'un champ d'après son nom. */
|
|
58
|
+
function formTabOf(name, pageBuilderField = "pageBuilder") {
|
|
59
|
+
return name === pageBuilderField ? "sections" : SEO_FIELDS.has(name) ? "seo" : SETTINGS_FIELDS.has(name) ? "settings" : "content";
|
|
60
|
+
}
|
|
61
|
+
function withNcfFormTabs(types, options = {}) {
|
|
62
|
+
return types.map((input) => {
|
|
63
|
+
let type = input;
|
|
64
|
+
if (type.type !== "document" || type.groups || !Array.isArray(type.fields)) return input;
|
|
65
|
+
let fields = type.fields.map((field) => field.group || !field.name ? field : {
|
|
66
|
+
...field,
|
|
67
|
+
group: formTabOf(field.name, options.pageBuilderField)
|
|
68
|
+
}), used = new Set(fields.filter((f) => f.hidden !== !0).map((f) => f.group).flat()), groups = GROUPS.filter((g) => used.has(g.name)).map((g) => ({ ...g }));
|
|
69
|
+
return groups.length < 2 ? input : (groups.some((g) => "default" in g && g.default) || (groups[0].default = !0), {
|
|
70
|
+
...type,
|
|
71
|
+
groups,
|
|
72
|
+
fields
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export { DEFAULT_COMPONENT_DEFAULTS_TYPE, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, formTabOf, requiredUnlessDefault, requiredUnlessDefaultFor, withNcfFormTabs };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema/formTabs.ts"],"sourcesContent":["/**\n * Onglets du formulaire d'un document : Content, Sections, SEO, Settings.\n *\n * Un formulaire de page en une seule colonne mélange le contenu, le page builder et\n * les réglages SEO : on cherche, on se trompe de champ. Ici, chaque champ d'un\n * document va dans son onglet d'après son nom ; « Content » s'ouvre par défaut.\n * - Sections : le champ du page builder (`pageBuilderField`, défaut `pageBuilder`).\n * - SEO : `seo`, `structuredData` et les champs de métadonnées connus.\n * - Settings : réglages de page (`pageOptions`, `options`, `settings`...).\n * - Content : tout le reste (titre, slug, corps, image...).\n * Un type qui déclare déjà ses `groups` n'est pas touché ; un champ qui a déjà son\n * `group` le garde. Pas d'onglets pour un document qui n'aurait qu'un onglet.\n *\n * ```ts\n * schema: {types: withNcfFormTabs(schemaTypes, {pageBuilderField: 'pageBuilder'})}\n * ```\n */\n\nconst SEO_FIELDS = new Set(['seo', 'structuredData', 'jsonld', 'noindex', 'metaTitle', 'metaDescription', 'ogImage', 'canonical', 'canonicalUrl'])\nconst SETTINGS_FIELDS = new Set(['pageOptions', 'options', 'settings', 'hideFromMenu', 'showInMenu', 'parent', 'publishedAt', 'redirects'])\n\nconst GROUPS = [\n {name: 'content', title: 'Content', default: true},\n {name: 'sections', title: 'Sections'},\n {name: 'seo', title: 'SEO'},\n {name: 'settings', title: 'Settings'},\n] as const\n\ntype Field = {name?: string; group?: unknown; hidden?: unknown}\ntype TypeLike = {type?: string; groups?: unknown; fields?: Field[]}\n\n/** Onglet d'un champ d'après son nom. */\nexport function formTabOf(name: string, pageBuilderField = 'pageBuilder'): (typeof GROUPS)[number]['name'] {\n if (name === pageBuilderField) return 'sections'\n if (SEO_FIELDS.has(name)) return 'seo'\n if (SETTINGS_FIELDS.has(name)) return 'settings'\n return 'content'\n}\n\nexport function withNcfFormTabs<T>(types: readonly T[], options: {pageBuilderField?: string} = {}): T[] {\n return types.map((input) => {\n const type = input as unknown as TypeLike\n if (type.type !== 'document' || type.groups || !Array.isArray(type.fields)) return input\n const fields = type.fields.map((field) =>\n field.group || !field.name ? field : {...field, group: formTabOf(field.name, options.pageBuilderField)},\n )\n const used = new Set(fields.filter((f) => f.hidden !== true).map((f) => f.group).flat())\n const groups = GROUPS.filter((g) => used.has(g.name)).map((g) => ({...g}))\n if (groups.length < 2) return input\n if (!groups.some((g) => 'default' in g && g.default)) (groups[0] as {default?: boolean}).default = true\n return {...type, groups, fields} as unknown as T\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,6BAAa,IAAI,IAAI;C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 -1,10 +1,10 @@
|
|
|
1
|
-
import {createElement, useState, type ComponentType} from 'react'
|
|
1
|
+
import {createElement, useEffect, useState, type ComponentType} from 'react'
|
|
2
2
|
import {set, useFormValue, type InputProps} from 'sanity'
|
|
3
3
|
import {Button, Card, Flex, Stack, Text} from '@sanity/ui'
|
|
4
4
|
import type {ResolvedKitConfig} from '../config/types'
|
|
5
5
|
import {useKitClient} from '../hooks/useKitClient'
|
|
6
6
|
import {fieldPathKey, useTranslationTodo} from '../hooks/useTranslationTodo'
|
|
7
|
-
import {valueAtKey} from '../lib/aiTexts'
|
|
7
|
+
import {collectTexts, valueAtKey} from '../lib/aiTexts'
|
|
8
8
|
import {translateValues} from '../lib/aiTranslate'
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -24,6 +24,24 @@ export function withTranslationTodo(Inner: ComponentType<InputProps>, config: Re
|
|
|
24
24
|
const key = fieldPathKey(props.path)
|
|
25
25
|
const inner = createElement(Inner, props)
|
|
26
26
|
const show = Boolean(todo?.paths?.includes(key))
|
|
27
|
+
// Texte de la version principale (publiée), affiché pour aider à traduire.
|
|
28
|
+
const [master, setMaster] = useState<string | null>(null)
|
|
29
|
+
const sourceId = show ? todo?.sourceId : undefined
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!sourceId) return
|
|
32
|
+
let alive = true
|
|
33
|
+
void client
|
|
34
|
+
.getDocument(sourceId)
|
|
35
|
+
.then((doc) => {
|
|
36
|
+
if (!alive) return
|
|
37
|
+
const text = collectTexts(valueAtKey(doc, key)).join('').trim()
|
|
38
|
+
setMaster(text || null)
|
|
39
|
+
})
|
|
40
|
+
.catch(() => alive && setMaster(null))
|
|
41
|
+
return () => {
|
|
42
|
+
alive = false
|
|
43
|
+
}
|
|
44
|
+
}, [client, sourceId, key])
|
|
27
45
|
const done = () => {
|
|
28
46
|
if (!todo) return
|
|
29
47
|
setBusy(true)
|
|
@@ -68,6 +86,11 @@ export function withTranslationTodo(Inner: ComponentType<InputProps>, config: Re
|
|
|
68
86
|
)}
|
|
69
87
|
<Button mode="ghost" fontSize={1} padding={2} text="Mark as translated" disabled={busy} onClick={done} />
|
|
70
88
|
</Flex>
|
|
89
|
+
{master && (
|
|
90
|
+
<Text size={1} muted style={{marginTop: 8, whiteSpace: 'pre-wrap'}}>
|
|
91
|
+
{(todo?.sourceLanguage ?? '').toUpperCase()}: {master.length > 600 ? `${master.slice(0, 600)}…` : master}
|
|
92
|
+
</Text>
|
|
93
|
+
)}
|
|
71
94
|
{error && (
|
|
72
95
|
<Text size={1} style={{marginTop: 8, color: 'var(--card-badge-critical-fg-color, #c00)'}}>
|
|
73
96
|
{error}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onglets du formulaire d'un document : Content, Sections, SEO, Settings.
|
|
3
|
+
*
|
|
4
|
+
* Un formulaire de page en une seule colonne mélange le contenu, le page builder et
|
|
5
|
+
* les réglages SEO : on cherche, on se trompe de champ. Ici, chaque champ d'un
|
|
6
|
+
* document va dans son onglet d'après son nom ; « Content » s'ouvre par défaut.
|
|
7
|
+
* - Sections : le champ du page builder (`pageBuilderField`, défaut `pageBuilder`).
|
|
8
|
+
* - SEO : `seo`, `structuredData` et les champs de métadonnées connus.
|
|
9
|
+
* - Settings : réglages de page (`pageOptions`, `options`, `settings`...).
|
|
10
|
+
* - Content : tout le reste (titre, slug, corps, image...).
|
|
11
|
+
* Un type qui déclare déjà ses `groups` n'est pas touché ; un champ qui a déjà son
|
|
12
|
+
* `group` le garde. Pas d'onglets pour un document qui n'aurait qu'un onglet.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* schema: {types: withNcfFormTabs(schemaTypes, {pageBuilderField: 'pageBuilder'})}
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const SEO_FIELDS = new Set(['seo', 'structuredData', 'jsonld', 'noindex', 'metaTitle', 'metaDescription', 'ogImage', 'canonical', 'canonicalUrl'])
|
|
20
|
+
const SETTINGS_FIELDS = new Set(['pageOptions', 'options', 'settings', 'hideFromMenu', 'showInMenu', 'parent', 'publishedAt', 'redirects'])
|
|
21
|
+
|
|
22
|
+
const GROUPS = [
|
|
23
|
+
{name: 'content', title: 'Content', default: true},
|
|
24
|
+
{name: 'sections', title: 'Sections'},
|
|
25
|
+
{name: 'seo', title: 'SEO'},
|
|
26
|
+
{name: 'settings', title: 'Settings'},
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
type Field = {name?: string; group?: unknown; hidden?: unknown}
|
|
30
|
+
type TypeLike = {type?: string; groups?: unknown; fields?: Field[]}
|
|
31
|
+
|
|
32
|
+
/** Onglet d'un champ d'après son nom. */
|
|
33
|
+
export function formTabOf(name: string, pageBuilderField = 'pageBuilder'): (typeof GROUPS)[number]['name'] {
|
|
34
|
+
if (name === pageBuilderField) return 'sections'
|
|
35
|
+
if (SEO_FIELDS.has(name)) return 'seo'
|
|
36
|
+
if (SETTINGS_FIELDS.has(name)) return 'settings'
|
|
37
|
+
return 'content'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function withNcfFormTabs<T>(types: readonly T[], options: {pageBuilderField?: string} = {}): T[] {
|
|
41
|
+
return types.map((input) => {
|
|
42
|
+
const type = input as unknown as TypeLike
|
|
43
|
+
if (type.type !== 'document' || type.groups || !Array.isArray(type.fields)) return input
|
|
44
|
+
const fields = type.fields.map((field) =>
|
|
45
|
+
field.group || !field.name ? field : {...field, group: formTabOf(field.name, options.pageBuilderField)},
|
|
46
|
+
)
|
|
47
|
+
const used = new Set(fields.filter((f) => f.hidden !== true).map((f) => f.group).flat())
|
|
48
|
+
const groups = GROUPS.filter((g) => used.has(g.name)).map((g) => ({...g}))
|
|
49
|
+
if (groups.length < 2) return input
|
|
50
|
+
if (!groups.some((g) => 'default' in g && g.default)) (groups[0] as {default?: boolean}).default = true
|
|
51
|
+
return {...type, groups, fields} as unknown as T
|
|
52
|
+
})
|
|
53
|
+
}
|
package/src/schema/index.ts
CHANGED
package/src/version.ts
CHANGED