@nocode-factory/sanity-kit 2.6.1 → 2.7.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/index.d.ts +11 -1
- package/dist/index.js +50 -8
- package/dist/index.js.map +1 -1
- package/dist/web-server.d.ts +4 -1
- package/dist/web-server.js +5 -2
- package/dist/web-server.js.map +1 -1
- package/package.json +1 -1
- package/src/config/defaults.ts +2 -0
- package/src/config/resolve.ts +2 -0
- package/src/config/types.ts +10 -0
- package/src/lib/blocks.ts +21 -0
- package/src/tools/components/BlockCard.tsx +12 -2
- package/src/tools/components/ComponentsTool.tsx +31 -2
- package/src/version.ts +1 -1
- package/src/web/previewGrant.ts +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,14 @@ interface NcfComponentPreviewConfig {
|
|
|
51
51
|
anchor?: string;
|
|
52
52
|
/** Chemin de la capture, relatif à `previewUrl`. Gabarit : {name} / {kebab}. */
|
|
53
53
|
thumbnail?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Type du document des valeurs par défaut des composants (un champ par
|
|
56
|
+
* composant, nommé `{name}`). Présent dans le schéma : un clic sur un composant
|
|
57
|
+
* ouvre Presentation avec son rendu réel et ses valeurs par défaut côte à côte.
|
|
58
|
+
*/
|
|
59
|
+
defaultsType?: string;
|
|
60
|
+
/** Page qui rend un composant seul, avec ses valeurs par défaut. Gabarit : {name} / {kebab}. */
|
|
61
|
+
live?: string;
|
|
54
62
|
}
|
|
55
63
|
/** Journal des modifications (phase 2). */
|
|
56
64
|
interface NcfHistoryConfig {
|
|
@@ -218,6 +226,8 @@ interface ResolvedComponentPreview {
|
|
|
218
226
|
path: string;
|
|
219
227
|
anchor: string;
|
|
220
228
|
thumbnail: string;
|
|
229
|
+
defaultsType: string;
|
|
230
|
+
live: string;
|
|
221
231
|
}
|
|
222
232
|
interface ResolvedKitConfig {
|
|
223
233
|
pageTypes: ResolvedPageType[];
|
|
@@ -1270,7 +1280,7 @@ export declare function ActorName(props: {
|
|
|
1270
1280
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1271
1281
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1272
1282
|
*/
|
|
1273
|
-
export declare const KIT_VERSION = "2.
|
|
1283
|
+
export declare const KIT_VERSION = "2.7.0";
|
|
1274
1284
|
/**
|
|
1275
1285
|
* Données de la page proposées comme colonnes.
|
|
1276
1286
|
*
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,9 @@ const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFA
|
|
|
39
39
|
provider: "designSystemPage",
|
|
40
40
|
path: "/design-system",
|
|
41
41
|
anchor: "{name}",
|
|
42
|
-
thumbnail: "/sections/{name}.png"
|
|
42
|
+
thumbnail: "/sections/{name}.png",
|
|
43
|
+
defaultsType: "componentDefaults",
|
|
44
|
+
live: "/design-system/composant?type={name}"
|
|
43
45
|
}, DEFAULT_TOOLS = {
|
|
44
46
|
pages: !0,
|
|
45
47
|
components: !0,
|
|
@@ -128,7 +130,9 @@ function resolveConfig(input) {
|
|
|
128
130
|
provider: input.componentPreview?.provider ?? DEFAULT_COMPONENT_PREVIEW.provider,
|
|
129
131
|
path: input.componentPreview?.path ?? DEFAULT_COMPONENT_PREVIEW.path,
|
|
130
132
|
anchor: input.componentPreview?.anchor ?? DEFAULT_COMPONENT_PREVIEW.anchor,
|
|
131
|
-
thumbnail: input.componentPreview?.thumbnail ?? DEFAULT_COMPONENT_PREVIEW.thumbnail
|
|
133
|
+
thumbnail: input.componentPreview?.thumbnail ?? DEFAULT_COMPONENT_PREVIEW.thumbnail,
|
|
134
|
+
defaultsType: input.componentPreview?.defaultsType ?? DEFAULT_COMPONENT_PREVIEW.defaultsType,
|
|
135
|
+
live: input.componentPreview?.live ?? DEFAULT_COMPONENT_PREVIEW.live
|
|
132
136
|
},
|
|
133
137
|
serviceEndpoint: input.serviceEndpoint === !1 ? null : trimTrailingSlash((input.serviceEndpoint || "https://dkoxgivytgsmvqmjvmjt.supabase.co/functions/v1").trim()),
|
|
134
138
|
history: input.history?.projectKey?.trim() ? {
|
|
@@ -1300,7 +1304,7 @@ function explainGrantError(error) {
|
|
|
1300
1304
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1301
1305
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1302
1306
|
*/
|
|
1303
|
-
const KIT_VERSION = "2.
|
|
1307
|
+
const KIT_VERSION = "2.7.0";
|
|
1304
1308
|
/**
|
|
1305
1309
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1306
1310
|
*
|
|
@@ -1611,7 +1615,7 @@ function useKitUpdate() {
|
|
|
1611
1615
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1612
1616
|
}).catch(() => {}), () => controller.abort();
|
|
1613
1617
|
}, []);
|
|
1614
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1618
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.7.0") > 0);
|
|
1615
1619
|
return {
|
|
1616
1620
|
current: KIT_VERSION,
|
|
1617
1621
|
latest,
|
|
@@ -5638,6 +5642,21 @@ function humanizeBlockName(type, namespace) {
|
|
|
5638
5642
|
return [first.charAt(0).toUpperCase() + first.slice(1), ...rest].join(" ");
|
|
5639
5643
|
}
|
|
5640
5644
|
/**
|
|
5645
|
+
* Paramètres de l'intention qui ouvre un composant dans Presentation : son rendu
|
|
5646
|
+
* réel (page `live`) à gauche, le champ de ses valeurs par défaut à droite.
|
|
5647
|
+
* `documentId` : document des valeurs par défaut (créé à la première saisie s'il
|
|
5648
|
+
* n'existe pas encore).
|
|
5649
|
+
*/
|
|
5650
|
+
function componentIntentParams(type, namespace, preview, documentId) {
|
|
5651
|
+
return {
|
|
5652
|
+
id: documentId.replace(/^drafts\./, ""),
|
|
5653
|
+
type: preview.defaultsType,
|
|
5654
|
+
mode: "presentation",
|
|
5655
|
+
path: blockName(type, namespace),
|
|
5656
|
+
preview: fillTemplate(preview.live, type, namespace)
|
|
5657
|
+
};
|
|
5658
|
+
}
|
|
5659
|
+
/**
|
|
5641
5660
|
* Tuile d'un bloc dans la grille.
|
|
5642
5661
|
*
|
|
5643
5662
|
* Volontairement dépouillée : la capture, le nom, sa référence technique et
|
|
@@ -5646,14 +5665,20 @@ function humanizeBlockName(type, namespace) {
|
|
|
5646
5665
|
* à le lire.
|
|
5647
5666
|
*/
|
|
5648
5667
|
function BlockCard(props) {
|
|
5649
|
-
let { block, occurrence, namespace, thumbnailUrl } = props, [failed, setFailed] = useState(!1), unused = occurrence.count === 0;
|
|
5668
|
+
let { block, occurrence, namespace, thumbnailUrl, onOpen } = props, [failed, setFailed] = useState(!1), unused = occurrence.count === 0;
|
|
5650
5669
|
return /* @__PURE__ */ jsx(Card, {
|
|
5651
5670
|
radius: 3,
|
|
5652
5671
|
shadow: 1,
|
|
5653
5672
|
padding: 0,
|
|
5673
|
+
as: onOpen ? "button" : void 0,
|
|
5674
|
+
onClick: onOpen,
|
|
5675
|
+
title: onOpen ? "Voir le composant en vrai et régler ses valeurs par défaut" : void 0,
|
|
5654
5676
|
style: {
|
|
5655
5677
|
height: "100%",
|
|
5656
|
-
overflow: "hidden"
|
|
5678
|
+
overflow: "hidden",
|
|
5679
|
+
width: "100%",
|
|
5680
|
+
textAlign: "left",
|
|
5681
|
+
cursor: onOpen ? "pointer" : void 0
|
|
5657
5682
|
},
|
|
5658
5683
|
children: /* @__PURE__ */ jsxs(Stack, {
|
|
5659
5684
|
gap: 0,
|
|
@@ -6171,7 +6196,23 @@ const ORDERS = [
|
|
|
6171
6196
|
}
|
|
6172
6197
|
];
|
|
6173
6198
|
function ComponentsTool() {
|
|
6174
|
-
let config = useKitConfig(), { blockTypes, occurrences, pagesById, truncated, scanned, loading, error, refresh } = useOccurrences(), [order, setOrder] = useState("type"), [view, setView] = useState("grid"), preview = config.componentPreview, canPreview = preview.provider === "designSystemPage" && !!config.previewUrl,
|
|
6199
|
+
let config = useKitConfig(), { blockTypes, occurrences, pagesById, truncated, scanned, loading, error, refresh } = useOccurrences(), [order, setOrder] = useState("type"), [view, setView] = useState("grid"), preview = config.componentPreview, canPreview = preview.provider === "designSystemPage" && !!config.previewUrl, schema = useSchema(), router = useRouter(), client = useKitClient(), hasDefaults = !!schema.get(preview.defaultsType), openComponent = useCallback(async (type) => {
|
|
6200
|
+
if (!hasDefaults) {
|
|
6201
|
+
config.previewUrl && window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, "_blank", "noopener");
|
|
6202
|
+
return;
|
|
6203
|
+
}
|
|
6204
|
+
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`, {
|
|
6205
|
+
type: preview.defaultsType,
|
|
6206
|
+
lang
|
|
6207
|
+
}).catch(() => null);
|
|
6208
|
+
router.navigateIntent("edit", componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType));
|
|
6209
|
+
}, [
|
|
6210
|
+
hasDefaults,
|
|
6211
|
+
config,
|
|
6212
|
+
preview,
|
|
6213
|
+
client,
|
|
6214
|
+
router
|
|
6215
|
+
]), cards = useMemo(() => {
|
|
6175
6216
|
let byName = new Map(blockTypes.map((b) => [b.name, b])), rows = occurrences.map((occurrence) => ({
|
|
6176
6217
|
occurrence,
|
|
6177
6218
|
block: byName.get(occurrence.type)
|
|
@@ -6311,7 +6352,8 @@ function ComponentsTool() {
|
|
|
6311
6352
|
block,
|
|
6312
6353
|
occurrence,
|
|
6313
6354
|
namespace: config.blockNamespace,
|
|
6314
|
-
thumbnailUrl: canPreview ? `${config.previewUrl}${fillTemplate(preview.thumbnail, block.name, config.blockNamespace)}` : null
|
|
6355
|
+
thumbnailUrl: canPreview ? `${config.previewUrl}${fillTemplate(preview.thumbnail, block.name, config.blockNamespace)}` : null,
|
|
6356
|
+
onOpen: hasDefaults || config.previewUrl ? () => void openComponent(block.name) : void 0
|
|
6315
6357
|
}, block.name))
|
|
6316
6358
|
})
|
|
6317
6359
|
]
|