@nocode-factory/sanity-kit 2.9.0 → 2.10.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @nocode-factory/sanity-kit
2
2
 
3
3
  Outils Sanity Studio de NoCode Factory : **Pages** (liste + board), **Composants**,
4
- **Historique**, aperçu multi-environnements et partage de préversion. Plus, côté
4
+ **Historique**, **Design system**, aperçu multi-environnements et partage de préversion. Plus, côté
5
5
  site Next.js : garde de préproduction, bascule brouillons / en ligne, bandeau.
6
6
 
7
7
  ## Installer
@@ -41,6 +41,35 @@ npx ncf-kit doctor
41
41
 
42
42
  Zéro ✖ = projet complet. Sortie 1 sinon (utilisable en CI).
43
43
 
44
+ ## Design system : la page de tous les styles et composants
45
+
46
+ La page `/design-system` du site (option `componentPreview.path`) est **LA page du
47
+ design system** : fondations (couleurs, typographie, grille), marque, icônes et
48
+ chaque composant rendu avec ses valeurs par défaut. Le bouton **Design system** de
49
+ la barre du Studio l'ouvre dans Presentation, avec le document des valeurs par
50
+ défaut des composants à côté.
51
+
52
+ **Un style changé sur cette page change le composant global** : cliquer un composant
53
+ ouvre ses réglages par défaut, et la modification s'applique partout où une
54
+ instance ne l'a pas surchargée (pastille bleue sur les champs surchargés).
55
+
56
+ Côté Studio, lier les pages du design system au document des valeurs par défaut :
57
+
58
+ ```ts
59
+ presentationTool({resolve: {mainDocuments: defineDocuments([
60
+ ...componentDefaultsMainDocuments({language: 'fr'}), // /design-system et /design-system/composant
61
+ ])}})
62
+ ```
63
+
64
+ Côté site, la page rend chaque démo avec les valeurs par défaut prioritaires
65
+ (`inherit(defaults[type], demo)`), lues dans Sanity : en Presentation, les textes et
66
+ options proviennent du document des valeurs par défaut, donc cliquables.
67
+
68
+ Barre du Studio : le kit rend les boutons d'outils. Les outils techniques (Vision,
69
+ planification « Scheduled drafts » / Releases) sont rangés dans **Plus** (option
70
+ `moreTools`, `false` pour tout garder en boutons). Ne pas définir de
71
+ `studio.components.toolMenu` dans le projet : il masquerait ce menu.
72
+
44
73
  ## Composants : valeurs par défaut, instances et overrides
45
74
 
46
75
  Chaque composant (section du page builder) a des **valeurs par défaut**, réglées
@@ -54,6 +83,8 @@ Dans le Studio :
54
83
  - **Onglet Composants** : un clic sur un composant (grille ou vue Map) ouvre
55
84
  Presentation avec son rendu réel et ses valeurs par défaut côte à côte. Depuis
56
85
  la Map, chaque page listée ouvre le formulaire sur l'instance.
86
+ - **Formulaire d'une instance** : le bouton « Modifier l'instance principale »
87
+ ouvre les valeurs par défaut du composant (rendu réel + réglages).
57
88
  - **Formulaire d'une page** : une pastille bleue marque tout champ d'instance
58
89
  différent de la valeur par défaut. Au survol, elle affiche la valeur par défaut ;
59
90
  au clic, le champ revient en héritage. Un champ qui hérite affiche la valeur par
@@ -72,6 +72,21 @@ function componentDefaultsMainDocument(options = {}) {
72
72
  filter: `_type == "${type}"${safeLang ? ` && language == "${safeLang}"` : ""}`
73
73
  };
74
74
  }
75
- export { requiredUnlessDefault as a, defineComponentDefaults as i, componentDefaultsMainDocument as n, requiredUnlessDefaultFor as o, defaultsFieldName as r, DEFAULT_COMPONENT_DEFAULTS_TYPE as t };
75
+ /**
76
+ * Presentation : les pages du design system ont pour document principal les valeurs
77
+ * par défaut des composants. `/design-system` (toute la bibliothèque) et
78
+ * `/design-system/composant` (un composant seul) : cliquer un composant ouvre ses
79
+ * réglages globaux, et un style changé change le composant partout où il n'est
80
+ * pas surchargé.
81
+ * `presentationTool({resolve: {mainDocuments: defineDocuments(componentDefaultsMainDocuments({language: 'fr'}))}})`
82
+ */
83
+ function componentDefaultsMainDocuments(options = {}) {
84
+ let { routes = ["/design-system/composant", "/design-system"], ...rest } = options;
85
+ return routes.map((route) => componentDefaultsMainDocument({
86
+ ...rest,
87
+ route
88
+ }));
89
+ }
90
+ export { defineComponentDefaults as a, defaultsFieldName as i, componentDefaultsMainDocument as n, requiredUnlessDefault as o, componentDefaultsMainDocuments as r, requiredUnlessDefaultFor as s, DEFAULT_COMPONENT_DEFAULTS_TYPE as t };
76
91
 
77
- //# sourceMappingURL=componentDefaults-YFpAqFb4.js.map
92
+ //# sourceMappingURL=componentDefaults-BY3hQ6aD.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"componentDefaults-YFpAqFb4.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"],"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"}
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"}
@@ -58,5 +58,21 @@ declare function componentDefaultsMainDocument(options?: {
58
58
  route: string;
59
59
  filter: string;
60
60
  };
61
- export { requiredUnlessDefault as a, defineComponentDefaults as i, componentDefaultsMainDocument as n, requiredUnlessDefaultFor as o, defaultsFieldName as r, DEFAULT_COMPONENT_DEFAULTS_TYPE as t };
62
- //# sourceMappingURL=componentDefaults-CbOXLaYE.d.ts.map
61
+ /**
62
+ * Presentation : les pages du design system ont pour document principal les valeurs
63
+ * par défaut des composants. `/design-system` (toute la bibliothèque) et
64
+ * `/design-system/composant` (un composant seul) : cliquer un composant ouvre ses
65
+ * réglages globaux, et un style changé change le composant partout où il n'est
66
+ * pas surchargé.
67
+ * `presentationTool({resolve: {mainDocuments: defineDocuments(componentDefaultsMainDocuments({language: 'fr'}))}})`
68
+ */
69
+ declare function componentDefaultsMainDocuments(options?: {
70
+ language?: string;
71
+ type?: string;
72
+ routes?: string[];
73
+ }): {
74
+ route: string;
75
+ filter: string;
76
+ }[];
77
+ export { defineComponentDefaults as a, defaultsFieldName as i, componentDefaultsMainDocument as n, requiredUnlessDefault as o, componentDefaultsMainDocuments as r, requiredUnlessDefaultFor as s, DEFAULT_COMPONENT_DEFAULTS_TYPE as t };
78
+ //# sourceMappingURL=componentDefaults-CNiuukLt.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as requiredUnlessDefault, i as defineComponentDefaults, n as componentDefaultsMainDocument, o as requiredUnlessDefaultFor, r as defaultsFieldName, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CbOXLaYE.js";
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
  import { SanityClient, Schema, Tool, ToolMenuProps } from "sanity";
3
3
  import { ReactNode } from "react";
4
4
  import { PreviewHeaderProps } from "sanity/presentation";
@@ -136,6 +136,8 @@ interface NcfToolsConfig {
136
136
  pages?: boolean;
137
137
  components?: boolean;
138
138
  history?: boolean;
139
+ /** Bouton « Design system » : ouvre la page /design-system dans Presentation. */
140
+ designSystem?: boolean;
139
141
  }
140
142
  interface NcfKitConfig {
141
143
  /** Types de documents traités comme des pages. Au moins un. */
@@ -192,6 +194,12 @@ interface NcfKitConfig {
192
194
  serviceEndpoint?: string | false;
193
195
  /** Permet de n'activer qu'une partie des outils. */
194
196
  tools?: NcfToolsConfig;
197
+ /**
198
+ * Outils techniques rangés dans le menu « Plus » de la barre du Studio, pour ne
199
+ * pas encombrer le marketing. Par défaut : Vision et la planification
200
+ * (« Scheduled drafts » / Releases, nom d'outil `releases`). `false` : aucun.
201
+ */
202
+ moreTools?: string[] | false;
195
203
  /**
196
204
  * Étiquettes de suivi du board. Remplacent entièrement les valeurs par
197
205
  * défaut quand elles sont fournies.
@@ -245,6 +253,8 @@ interface ResolvedKitConfig {
245
253
  /** `null` quand on a explicitement coupé les appels sortants. */
246
254
  serviceEndpoint: string | null;
247
255
  tools: Required<NcfToolsConfig>;
256
+ /** Outils rangés dans le menu « Plus » de la barre (noms d'outils). */
257
+ moreTools: string[];
248
258
  boardTags: NcfBoardTag[];
249
259
  internalFields: NcfInternalField[];
250
260
  documentColumns: ResolvedDocumentColumn[];
@@ -278,7 +288,7 @@ interface ConfigIssue {
278
288
  /** Quels outils sont concernés. Vide = tous. */
279
289
  tools?: NcfToolName[];
280
290
  }
281
- type NcfToolName = 'pages' | 'components' | 'history';
291
+ type NcfToolName = 'pages' | 'components' | 'history' | 'designSystem';
282
292
  interface KitContextValue {
283
293
  config: ResolvedKitConfig;
284
294
  issues: ConfigIssue[];
@@ -1292,7 +1302,7 @@ export declare function ActorName(props: {
1292
1302
  * Version du kit, rapportée au service pour savoir quels projets tournent sur
1293
1303
  * quelle version. Tenue à jour avec `package.json`.
1294
1304
  */
1295
- export declare const KIT_VERSION = "2.9.0";
1305
+ export declare const KIT_VERSION = "2.10.0";
1296
1306
  /**
1297
1307
  * Données de la page proposées comme colonnes.
1298
1308
  *
@@ -1760,7 +1770,8 @@ export declare function humanizeBlockName(type: string, namespace: string): stri
1760
1770
  export declare const NCF_PAGES_TOOL = "ncf-pages";
1761
1771
  export declare const NCF_COMPONENTS_TOOL = "ncf-components";
1762
1772
  export declare const NCF_HISTORY_TOOL = "ncf-history";
1763
- export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "ncf-history"];
1773
+ export declare const NCF_DESIGN_SYSTEM_TOOL = "ncf-design-system";
1774
+ export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "ncf-history", "ncf-design-system"];
1764
1775
  export declare const ncfKit: import("sanity").Plugin<NcfKitConfig>;
1765
- export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
1776
+ export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, DEFAULT_COMPONENT_DEFAULTS_TYPE, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type KitUpdate, type LayoutMode, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc, componentDefaultsMainDocument, componentDefaultsMainDocuments, defaultsFieldName, defineComponentDefaults, requiredUnlessDefault, requiredUnlessDefaultFor };
1766
1777
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
- import { a as requiredUnlessDefault, i as defineComponentDefaults, n as componentDefaultsMainDocument, o as requiredUnlessDefaultFor, r as defaultsFieldName, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-YFpAqFb4.js";
2
- import { defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser } from "sanity";
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-BY3hQ6aD.js";
2
+ import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser } from "sanity";
3
3
  import { ClockIcon } from "@sanity/icons/Clock";
4
4
  import { ComponentIcon } from "@sanity/icons/Component";
5
5
  import { DocumentsIcon } from "@sanity/icons/Documents";
6
+ import { ColorWheelIcon } from "@sanity/icons/ColorWheel";
6
7
  import { Badge, Box, Button, Card, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
7
- import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
8
+ import { createContext, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
8
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
10
  import { IntentLink, useRouter } from "sanity/router";
10
11
  import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
@@ -12,6 +13,8 @@ import { LaunchIcon } from "@sanity/icons/Launch";
12
13
  import { ArrowUpIcon } from "@sanity/icons/ArrowUp";
13
14
  import { CheckmarkIcon } from "@sanity/icons/Checkmark";
14
15
  import { CopyIcon } from "@sanity/icons/Copy";
16
+ import { Menu, MenuButton, MenuItem } from "@sanity/ui/menu";
17
+ import { EllipsisHorizontalIcon } from "@sanity/icons/EllipsisHorizontal";
15
18
  import { CloseIcon } from "@sanity/icons/Close";
16
19
  import { EarthGlobeIcon } from "@sanity/icons/EarthGlobe";
17
20
  import { ProjectsIcon } from "@sanity/icons/Projects";
@@ -32,7 +35,6 @@ import { TrashIcon } from "@sanity/icons/Trash";
32
35
  import { RefreshIcon } from "@sanity/icons/Refresh";
33
36
  import { RestoreIcon } from "@sanity/icons/Restore";
34
37
  import { Tooltip } from "@sanity/ui/tooltip";
35
- import { EllipsisHorizontalIcon } from "@sanity/icons/EllipsisHorizontal";
36
38
  const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFAULT_TITLE_FIELD = "title", DEFAULT_NOINDEX_FIELDS = ["seo.noindex", "noindex"], DEFAULT_I18N = {
37
39
  field: "language",
38
40
  defaultLocale: "fr",
@@ -47,8 +49,13 @@ const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFA
47
49
  }, DEFAULT_TOOLS = {
48
50
  pages: !0,
49
51
  components: !0,
50
- history: !0
51
- }, DEFAULT_BOARD_TAGS = [
52
+ history: !0,
53
+ designSystem: !0
54
+ }, DEFAULT_TOOLBAR_MORE = [
55
+ "vision",
56
+ "releases",
57
+ "schedules"
58
+ ], DEFAULT_BOARD_TAGS = [
52
59
  {
53
60
  id: "en-cours",
54
61
  label: "En cours",
@@ -145,6 +152,7 @@ function resolveConfig(input) {
145
152
  ...DEFAULT_TOOLS,
146
153
  ...input.tools
147
154
  },
155
+ moreTools: input.moreTools === !1 ? [] : input.moreTools ?? DEFAULT_TOOLBAR_MORE,
148
156
  boardTags: input.boardTags?.length ? input.boardTags : DEFAULT_BOARD_TAGS,
149
157
  internalFields: input.internalFields?.length ? input.internalFields : DEFAULT_INTERNAL_FIELDS,
150
158
  documentColumns: (input.documentColumns ?? []).map((column) => ({
@@ -1306,7 +1314,7 @@ function explainGrantError(error) {
1306
1314
  * Version du kit, rapportée au service pour savoir quels projets tournent sur
1307
1315
  * quelle version. Tenue à jour avec `package.json`.
1308
1316
  */
1309
- const KIT_VERSION = "2.9.0";
1317
+ const KIT_VERSION = "2.10.0";
1310
1318
  /**
1311
1319
  * Signale ce Studio au service du kit, une fois par montage.
1312
1320
  *
@@ -1617,7 +1625,7 @@ function useKitUpdate() {
1617
1625
  !controller.signal.aborted && body?.version && setLatest(body.version);
1618
1626
  }).catch(() => {}), () => controller.abort();
1619
1627
  }, []);
1620
- let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.9.0") > 0);
1628
+ let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.10.0") > 0);
1621
1629
  return {
1622
1630
  current: KIT_VERSION,
1623
1631
  latest,
@@ -1743,6 +1751,75 @@ function NcfKitUpdate(props) {
1743
1751
  });
1744
1752
  }
1745
1753
  /**
1754
+ * Sépare les outils de la barre : ceux du quotidien restent en boutons, les outils
1755
+ * techniques (`more`) passent dans le menu « Plus ». L'ordre d'origine est gardé.
1756
+ */
1757
+ function splitTools(tools, more) {
1758
+ return [tools.filter((t) => !more.includes(t.name)), tools.filter((t) => more.includes(t.name))];
1759
+ }
1760
+ const ToolAnchor = forwardRef(function ToolAnchor({ children, ...props }, ref) {
1761
+ return /* @__PURE__ */ jsx(ToolLink, {
1762
+ ...props,
1763
+ ref,
1764
+ children
1765
+ });
1766
+ });
1767
+ /**
1768
+ * Barre d'outils du Studio : les outils du quotidien en boutons (dont « Design
1769
+ * system »), les outils techniques (Vision, planification) dans « Plus ». Dans le
1770
+ * volet latéral (mobile), tout est listé.
1771
+ */
1772
+ function NcfToolButtons(props) {
1773
+ let { activeToolName, context, tools, closeSidebar, isSidebarOpen, more: moreNames } = props, [main, more] = useMemo(() => splitTools(tools, moreNames), [tools, moreNames]), isSidebar = context === "sidebar", onClick = useCallback(() => {
1774
+ isSidebar && isSidebarOpen && closeSidebar();
1775
+ }, [
1776
+ closeSidebar,
1777
+ isSidebar,
1778
+ isSidebarOpen
1779
+ ]), button = (tool) => /* @__PURE__ */ jsx(Button, {
1780
+ as: ToolAnchor,
1781
+ name: tool.name,
1782
+ icon: tool.icon,
1783
+ text: tool.title || tool.name,
1784
+ mode: "bleed",
1785
+ selected: activeToolName === tool.name,
1786
+ justify: isSidebar ? "flex-start" : void 0,
1787
+ onClick,
1788
+ fontSize: 1,
1789
+ padding: 3
1790
+ }, tool.name);
1791
+ return isSidebar ? /* @__PURE__ */ jsx(Stack, {
1792
+ gap: 1,
1793
+ children: [...main, ...more].map(button)
1794
+ }) : /* @__PURE__ */ jsxs(Flex, {
1795
+ gap: 1,
1796
+ align: "center",
1797
+ children: [main.map(button), more.length > 0 && /* @__PURE__ */ jsx(MenuButton, {
1798
+ id: "ncf-tool-menu-more",
1799
+ button: /* @__PURE__ */ jsx(Button, {
1800
+ icon: EllipsisHorizontalIcon,
1801
+ text: "Plus",
1802
+ mode: "bleed",
1803
+ fontSize: 1,
1804
+ padding: 3,
1805
+ selected: more.some((t) => t.name === activeToolName),
1806
+ title: `Outils techniques (${more.map((t) => t.title || t.name).join(", ")})`
1807
+ }),
1808
+ menu: /* @__PURE__ */ jsx(Menu, { children: more.map((tool) => /* @__PURE__ */ jsx(MenuItem, {
1809
+ as: ToolAnchor,
1810
+ name: tool.name,
1811
+ icon: tool.icon,
1812
+ text: tool.title || tool.name,
1813
+ pressed: activeToolName === tool.name
1814
+ }, tool.name)) }),
1815
+ popover: {
1816
+ portal: !0,
1817
+ placement: "bottom-end"
1818
+ }
1819
+ })]
1820
+ });
1821
+ }
1822
+ /**
1746
1823
  * Lanceur d'aperçu, posé dans la barre du haut à droite des outils.
1747
1824
  *
1748
1825
  * Deux questions, une seule poignée : **quelle version du site**, et **quel
@@ -1758,7 +1835,10 @@ function NcfPreviewLauncher(props) {
1758
1835
  if (environments.length === 0) return /* @__PURE__ */ jsxs(Flex, {
1759
1836
  align: "center",
1760
1837
  gap: 2,
1761
- children: [props.renderDefault(props), /* @__PURE__ */ jsx(NcfKitUpdate, { inline: props.context === "topbar" })]
1838
+ children: [/* @__PURE__ */ jsx(NcfToolButtons, {
1839
+ ...props,
1840
+ more: config.moreTools
1841
+ }), /* @__PURE__ */ jsx(NcfKitUpdate, { inline: props.context === "topbar" })]
1762
1842
  });
1763
1843
  let openInStudio = (environment, perspective) => {
1764
1844
  let path = presentationPath(environment.url, {
@@ -1774,7 +1854,10 @@ function NcfPreviewLauncher(props) {
1774
1854
  direction: inline ? "row" : "column",
1775
1855
  gap: inline ? 2 : 1,
1776
1856
  children: [
1777
- props.renderDefault(props),
1857
+ /* @__PURE__ */ jsx(NcfToolButtons, {
1858
+ ...props,
1859
+ more: config.moreTools
1860
+ }),
1778
1861
  /* @__PURE__ */ jsx(NcfKitUpdate, { inline }),
1779
1862
  /* @__PURE__ */ jsx(InlinePopover, {
1780
1863
  width: 248,
@@ -5668,25 +5751,66 @@ function componentIntentParams(type, namespace, preview, documentId) {
5668
5751
  }
5669
5752
  /**
5670
5753
  * Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
5671
- * défaut côte à côte. Sans document de valeurs par défaut dans le schéma : la
5672
- * démo du design system dans un nouvel onglet. `null` : rien à ouvrir.
5673
- * Partagé par la grille et la vue Map de l'onglet Composants.
5754
+ * défaut côte à côte (le document des valeurs par défaut, champ du composant).
5755
+ * Sans document de valeurs par défaut dans le schéma : la démo du design system
5756
+ * dans un nouvel onglet. Partagé par l'onglet Composants (grille, Map) et le
5757
+ * bouton « Modifier l'instance principale » des formulaires.
5758
+ */
5759
+ async function openComponentDefaults(options) {
5760
+ let { type, config, hasDefaults, client, navigateIntent } = options, preview = config.componentPreview;
5761
+ if (!hasDefaults) {
5762
+ config.previewUrl && window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, "_blank", "noopener");
5763
+ return;
5764
+ }
5765
+ let id = await defaultsDocumentId(config, client);
5766
+ navigateIntent("edit", componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType));
5767
+ }
5768
+ /** Document des valeurs par défaut (langue par défaut en priorité), ou null. */
5769
+ async function defaultsDocumentId(config, client) {
5770
+ let lang = config.i18n?.defaultLocale ?? null;
5771
+ return client.fetch(`*[_type == $type] | order(select($lang != null && ${config.i18n?.field ?? "language"} == $lang => 0, 1))[0]._id`, {
5772
+ type: config.componentPreview.defaultsType,
5773
+ lang
5774
+ }).catch(() => null);
5775
+ }
5776
+ /**
5777
+ * Paramètres de l'intention qui ouvre la page du design system dans Presentation,
5778
+ * avec le document des valeurs par défaut des composants à côté : un style changé
5779
+ * sur cette page change le composant partout où il n'est pas surchargé.
5780
+ */
5781
+ function designSystemIntentParams(config, documentId) {
5782
+ return {
5783
+ id: documentId.replace(/^drafts\./, ""),
5784
+ type: config.componentPreview.defaultsType,
5785
+ mode: "presentation",
5786
+ preview: config.componentPreview.path
5787
+ };
5788
+ }
5789
+ /**
5790
+ * Ouvre le design system : Presentation sur la page `/design-system`, document des
5791
+ * valeurs par défaut à côté. Sans valeurs par défaut dans le schéma : la page seule
5792
+ * dans Presentation.
5674
5793
  */
5794
+ async function openDesignSystem(options) {
5795
+ let { config, hasDefaults, client, navigateIntent, navigateUrl } = options;
5796
+ if (hasDefaults) {
5797
+ navigateIntent("edit", designSystemIntentParams(config, await defaultsDocumentId(config, client) ?? config.componentPreview.defaultsType));
5798
+ return;
5799
+ }
5800
+ let path = presentationPath(config.previewUrl ? `${config.previewUrl}${config.componentPreview.path}` : null);
5801
+ path && navigateUrl(path);
5802
+ }
5803
+ /** Ouvre un composant (voir openComponentDefaults). `null` : rien à ouvrir. */
5675
5804
  function useOpenComponent() {
5676
- let config = useKitConfig(), schema = useSchema(), router = useRouter(), client = useKitClient(), preview = config.componentPreview, hasDefaults = !!schema.get(preview.defaultsType), open = useCallback(async (type) => {
5677
- if (!hasDefaults) {
5678
- config.previewUrl && window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, "_blank", "noopener");
5679
- return;
5680
- }
5681
- let lang = config.i18n?.defaultLocale ?? null, id = await client.fetch(`*[_type == $type] | order(select($lang != null && ${config.i18n?.field ?? "language"} == $lang => 0, 1))[0]._id`, {
5682
- type: preview.defaultsType,
5683
- lang
5684
- }).catch(() => null);
5685
- router.navigateIntent("edit", componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType));
5686
- }, [
5805
+ let config = useKitConfig(), schema = useSchema(), router = useRouter(), client = useKitClient(), preview = config.componentPreview, hasDefaults = !!schema.get(preview.defaultsType), open = useCallback((type) => openComponentDefaults({
5806
+ type,
5807
+ config,
5808
+ hasDefaults,
5809
+ client,
5810
+ navigateIntent: (i, p) => router.navigateIntent(i, p)
5811
+ }), [
5687
5812
  hasDefaults,
5688
5813
  config,
5689
- preview,
5690
5814
  client,
5691
5815
  router
5692
5816
  ]);
@@ -7146,6 +7270,58 @@ function HistoryTool() {
7146
7270
  })
7147
7271
  });
7148
7272
  }
7273
+ /**
7274
+ * Onglet « Design system » : un raccourci, pas un écran. Il ouvre aussitôt la page
7275
+ * `/design-system` du site dans Presentation, avec le document des valeurs par
7276
+ * défaut des composants à côté. Cliquer un composant sur la page ouvre ses
7277
+ * réglages globaux : un style changé ici change le composant partout où il n'est
7278
+ * pas surchargé.
7279
+ */
7280
+ function DesignSystemTool() {
7281
+ let config = useKitConfig(), schema = useSchema(), router = useRouter(), client = useKitClient(), hasDefaults = !!schema.get(config.componentPreview.defaultsType), opened = useRef(!1), open = useCallback(() => void openDesignSystem({
7282
+ config,
7283
+ hasDefaults,
7284
+ client,
7285
+ navigateIntent: (intent, params) => router.navigateIntent(intent, params),
7286
+ navigateUrl: (path) => router.navigateUrl({ path })
7287
+ }), [
7288
+ config,
7289
+ hasDefaults,
7290
+ client,
7291
+ router
7292
+ ]);
7293
+ useEffect(() => {
7294
+ opened.current || (opened.current = !0, open());
7295
+ }, [open]);
7296
+ let available = hasDefaults || !!config.previewUrl;
7297
+ return /* @__PURE__ */ jsx(Card, {
7298
+ padding: 4,
7299
+ radius: 2,
7300
+ tone: available ? "default" : "caution",
7301
+ border: !0,
7302
+ children: /* @__PURE__ */ jsxs(Stack, {
7303
+ gap: 3,
7304
+ children: [
7305
+ /* @__PURE__ */ jsx(Text, {
7306
+ size: 1,
7307
+ weight: "semibold",
7308
+ children: "Design system"
7309
+ }),
7310
+ /* @__PURE__ */ jsx(Text, {
7311
+ size: 1,
7312
+ muted: !0,
7313
+ children: available ? `Ouverture de la page ${config.componentPreview.path} dans Presentation, avec les valeurs par défaut des composants. Un style changé ici change le composant partout où il n’est pas surchargé.` : "Ni document de valeurs par défaut des composants, ni previewUrl : rien à ouvrir. Voir la checklist du kit (README)."
7314
+ }),
7315
+ available && /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(Button, {
7316
+ text: "Ouvrir le design system",
7317
+ tone: "primary",
7318
+ fontSize: 1,
7319
+ onClick: open
7320
+ }) })
7321
+ ]
7322
+ })
7323
+ });
7324
+ }
7149
7325
  const store = /* @__PURE__ */ new Map();
7150
7326
  function entryFor(client, type, languageField, language) {
7151
7327
  let { projectId, dataset } = client.config(), key = `${projectId}:${dataset}:${type}:${language ?? ""}`, entry = store.get(key);
@@ -7301,7 +7477,11 @@ function shortValue(value, max = 32) {
7301
7477
  function createOverrideInput(config) {
7302
7478
  let { defaultsType } = config.componentPreview, namespace = config.blockNamespace;
7303
7479
  function OverrideInput(props) {
7304
- let schema = useSchema(), path = props.path, keyed = firstKeyedIndex(path), anchor = keyed >= 0 ? keyed : 0, instance = useFormValue(path.slice(0, anchor + 1)), parent = useFormValue(path.length > 1 ? path.slice(0, -1) : path), resolved = resolveFieldPath(path, anchor, instance, namespace);
7480
+ let schema = useSchema(), path = props.path, keyed = firstKeyedIndex(path), anchor = keyed >= 0 ? keyed : 0, instance = useFormValue(path.slice(0, anchor + 1)), parent = useFormValue(path.length > 1 ? path.slice(0, -1) : path), resolved = resolveFieldPath(path, anchor, instance, namespace), own = props.value;
7481
+ if (props.schemaType.jsonType === "object" && typeof own?._type == "string" && own._type.startsWith(namespace) && props.path.length > 0 && schema.get(defaultsType)) return /* @__PURE__ */ jsx(WithMainInstance, {
7482
+ ...props,
7483
+ type: own._type
7484
+ });
7305
7485
  if (!resolved || !schema.get(defaultsType) || !carriesDot(props.schemaType)) return props.renderDefault(props);
7306
7486
  let shortName = blockName(instance._type, namespace);
7307
7487
  return /* @__PURE__ */ jsx(WithDot, {
@@ -7348,6 +7528,30 @@ function createOverrideInput(config) {
7348
7528
  })]
7349
7529
  });
7350
7530
  }
7531
+ function WithMainInstance(props) {
7532
+ let { type, ...inputProps } = props, client = useKitClient(), router = useRouter(), open = () => void openComponentDefaults({
7533
+ type,
7534
+ config,
7535
+ hasDefaults: !0,
7536
+ client,
7537
+ navigateIntent: (i, p) => router.navigateIntent(i, p)
7538
+ });
7539
+ return /* @__PURE__ */ jsxs(Stack, {
7540
+ gap: 3,
7541
+ children: [/* @__PURE__ */ jsx(Flex, {
7542
+ justify: "flex-end",
7543
+ children: /* @__PURE__ */ jsx(Button, {
7544
+ mode: "ghost",
7545
+ tone: "primary",
7546
+ fontSize: 1,
7547
+ padding: 2,
7548
+ text: "Modifier l'instance principale",
7549
+ title: "Valeurs par défaut du composant : elles s'appliquent à toutes ses instances dont le champ est vide",
7550
+ onClick: open
7551
+ })
7552
+ }), inputProps.renderDefault(inputProps)]
7553
+ });
7554
+ }
7351
7555
  return OverrideInput;
7352
7556
  }
7353
7557
  function carriesDot(schemaType) {
@@ -7579,10 +7783,11 @@ function ncfPreviewComponents() {
7579
7783
  * pas le Studio de démarrer : l'onglet concerné affiche le détail à corriger.
7580
7784
  */
7581
7785
  /** Noms des outils dans la barre du Studio. Exportés pour filtrer `tools`. */
7582
- const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_HISTORY_TOOL = "ncf-history", NCF_TOOL_NAMES = [
7786
+ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_HISTORY_TOOL = "ncf-history", NCF_DESIGN_SYSTEM_TOOL = "ncf-design-system", NCF_TOOL_NAMES = [
7583
7787
  NCF_PAGES_TOOL,
7584
7788
  NCF_COMPONENTS_TOOL,
7585
- NCF_HISTORY_TOOL
7789
+ NCF_HISTORY_TOOL,
7790
+ NCF_DESIGN_SYSTEM_TOOL
7586
7791
  ], ncfKit = definePlugin((options) => {
7587
7792
  let config = resolveConfig(options), issues = validateConfig(config);
7588
7793
  return {
@@ -7632,6 +7837,21 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
7632
7837
  Component: HistoryTool
7633
7838
  })
7634
7839
  }
7840
+ },
7841
+ {
7842
+ name: "designSystem",
7843
+ tool: {
7844
+ name: NCF_DESIGN_SYSTEM_TOOL,
7845
+ title: "Design system",
7846
+ icon: ColorWheelIcon,
7847
+ component: createToolComponent({
7848
+ name: "designSystem",
7849
+ title: "Design system",
7850
+ config,
7851
+ issues,
7852
+ Component: DesignSystemTool
7853
+ })
7854
+ }
7635
7855
  }
7636
7856
  ].filter((d) => config.tools[d.name]).map((d) => d.tool),
7637
7857
  schema: {
@@ -7643,6 +7863,6 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
7643
7863
  form: { components: { input: createOverrideInput(config) } }
7644
7864
  };
7645
7865
  });
7646
- export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_DEFAULTS_TYPE, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineComponentDefaults, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
7866
+ export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_DEFAULTS_TYPE, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_DESIGN_SYSTEM_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineComponentDefaults, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
7647
7867
 
7648
7868
  //# sourceMappingURL=index.js.map