@nocode-factory/sanity-kit 2.7.0 → 2.8.1
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 +12 -11
- package/dist/index.js +318 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/form/OverrideInput.tsx +135 -0
- package/src/hooks/useComponentDefaults.ts +68 -0
- package/src/hooks/useOpenComponent.ts +43 -0
- package/src/index.ts +8 -0
- package/src/lib/occurrences.ts +20 -8
- package/src/lib/overrides.ts +146 -0
- package/src/lib/sectionsMap.ts +1 -1
- package/src/tools/components/ComponentsTool.tsx +5 -31
- package/src/tools/components/map/SectionsMap.tsx +37 -13
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -786,6 +786,17 @@ interface BlockOccurrence {
|
|
|
786
786
|
count: number;
|
|
787
787
|
/** Identifiants des documents où le bloc apparaît, sans doublon. */
|
|
788
788
|
documentIds: string[];
|
|
789
|
+
/**
|
|
790
|
+
* Emplacement de chaque instance : document et chemin depuis la racine du
|
|
791
|
+
* champ page builder (`[{_key}]`, ou plus profond pour un bloc imbriqué).
|
|
792
|
+
* Sert à ouvrir le formulaire directement sur l'instance.
|
|
793
|
+
*/
|
|
794
|
+
locations: {
|
|
795
|
+
documentId: string;
|
|
796
|
+
path: ({
|
|
797
|
+
_key: string;
|
|
798
|
+
} | string | number)[];
|
|
799
|
+
}[];
|
|
789
800
|
}
|
|
790
801
|
interface OccurrenceInput {
|
|
791
802
|
_id: string;
|
|
@@ -1280,7 +1291,7 @@ export declare function ActorName(props: {
|
|
|
1280
1291
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1281
1292
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1282
1293
|
*/
|
|
1283
|
-
export declare const KIT_VERSION = "2.
|
|
1294
|
+
export declare const KIT_VERSION = "2.8.1";
|
|
1284
1295
|
/**
|
|
1285
1296
|
* Données de la page proposées comme colonnes.
|
|
1286
1297
|
*
|
|
@@ -1749,16 +1760,6 @@ export declare const NCF_PAGES_TOOL = "ncf-pages";
|
|
|
1749
1760
|
export declare const NCF_COMPONENTS_TOOL = "ncf-components";
|
|
1750
1761
|
export declare const NCF_HISTORY_TOOL = "ncf-history";
|
|
1751
1762
|
export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "ncf-history"];
|
|
1752
|
-
/**
|
|
1753
|
-
* Plugin Studio de NoCode Factory : Pages, Composants, Historique.
|
|
1754
|
-
*
|
|
1755
|
-
* ```ts
|
|
1756
|
-
* plugins: [ncfKit({pageTypes: [{type: 'homePage', path: '/'}, 'page']})]
|
|
1757
|
-
* ```
|
|
1758
|
-
*
|
|
1759
|
-
* La configuration est validée au démarrage. Une option invalide n'empêche
|
|
1760
|
-
* pas le Studio de démarrer : l'onglet concerné affiche le détail à corriger.
|
|
1761
|
-
*/
|
|
1762
1763
|
export declare const ncfKit: import("sanity").Plugin<NcfKitConfig>;
|
|
1763
1764
|
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, 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 };
|
|
1764
1765
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineField, definePlugin, defineType, useClient, useCurrentUser, useSchema, useUser } from "sanity";
|
|
1
|
+
import { defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser } from "sanity";
|
|
2
2
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
3
3
|
import { ComponentIcon } from "@sanity/icons/Component";
|
|
4
4
|
import { DocumentsIcon } from "@sanity/icons/Documents";
|
|
5
5
|
import { Badge, Box, Button, Card, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
|
|
6
|
-
import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { IntentLink, useRouter } from "sanity/router";
|
|
9
9
|
import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
|
|
@@ -30,6 +30,7 @@ import "@xyflow/react/dist/style.css";
|
|
|
30
30
|
import { TrashIcon } from "@sanity/icons/Trash";
|
|
31
31
|
import { RefreshIcon } from "@sanity/icons/Refresh";
|
|
32
32
|
import { RestoreIcon } from "@sanity/icons/Restore";
|
|
33
|
+
import { Tooltip } from "@sanity/ui/tooltip";
|
|
33
34
|
import { EllipsisHorizontalIcon } from "@sanity/icons/EllipsisHorizontal";
|
|
34
35
|
const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFAULT_TITLE_FIELD = "title", DEFAULT_NOINDEX_FIELDS = ["seo.noindex", "noindex"], DEFAULT_I18N = {
|
|
35
36
|
field: "language",
|
|
@@ -1304,7 +1305,7 @@ function explainGrantError(error) {
|
|
|
1304
1305
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1305
1306
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1306
1307
|
*/
|
|
1307
|
-
const KIT_VERSION = "2.
|
|
1308
|
+
const KIT_VERSION = "2.8.1";
|
|
1308
1309
|
/**
|
|
1309
1310
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1310
1311
|
*
|
|
@@ -1615,7 +1616,7 @@ function useKitUpdate() {
|
|
|
1615
1616
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1616
1617
|
}).catch(() => {}), () => controller.abort();
|
|
1617
1618
|
}, []);
|
|
1618
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1619
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.8.1") > 0);
|
|
1619
1620
|
return {
|
|
1620
1621
|
current: KIT_VERSION,
|
|
1621
1622
|
latest,
|
|
@@ -5543,29 +5544,36 @@ function pageTypesWithoutBuilder(schema, pageTypes, pageBuilderField) {
|
|
|
5543
5544
|
/** Compte les blocs par type sur un ensemble de documents. */
|
|
5544
5545
|
function collectOccurrences(docs, options) {
|
|
5545
5546
|
let known = new Set(options.blockTypes), result = /* @__PURE__ */ new Map(), seenPerType = /* @__PURE__ */ new Map();
|
|
5546
|
-
for (let doc of docs) walk(doc.blocks, (type) => {
|
|
5547
|
+
for (let doc of docs) walk(doc.blocks, (type, path) => {
|
|
5547
5548
|
if (!known.has(type)) return;
|
|
5548
5549
|
let entry = result.get(type) ?? {
|
|
5549
5550
|
type,
|
|
5550
5551
|
count: 0,
|
|
5551
|
-
documentIds: []
|
|
5552
|
+
documentIds: [],
|
|
5553
|
+
locations: []
|
|
5552
5554
|
};
|
|
5553
|
-
entry.count += 1,
|
|
5555
|
+
entry.count += 1, entry.locations.push({
|
|
5556
|
+
documentId: doc._id,
|
|
5557
|
+
path
|
|
5558
|
+
}), result.set(type, entry);
|
|
5554
5559
|
let seen = seenPerType.get(type) ?? /* @__PURE__ */ new Set();
|
|
5555
5560
|
seen.has(doc._id) || (seen.add(doc._id), seenPerType.set(type, seen), entry.documentIds.push(doc._id));
|
|
5556
5561
|
});
|
|
5557
5562
|
return result;
|
|
5558
5563
|
}
|
|
5559
|
-
/** Appelle `visit` pour chaque `_type` rencontré, à toute profondeur. */
|
|
5560
|
-
function walk(value, visit) {
|
|
5564
|
+
/** Appelle `visit` pour chaque `_type` rencontré, à toute profondeur, avec son chemin. */
|
|
5565
|
+
function walk(value, visit, path = []) {
|
|
5561
5566
|
if (Array.isArray(value)) {
|
|
5562
|
-
|
|
5567
|
+
value.forEach((item, i) => {
|
|
5568
|
+
let key = item?._key;
|
|
5569
|
+
walk(item, visit, [...path, typeof key == "string" ? { _key: key } : i]);
|
|
5570
|
+
});
|
|
5563
5571
|
return;
|
|
5564
5572
|
}
|
|
5565
5573
|
if (typeof value != "object" || !value) return;
|
|
5566
5574
|
let type = value._type;
|
|
5567
|
-
typeof type == "string" && visit(type);
|
|
5568
|
-
for (let child of Object.
|
|
5575
|
+
typeof type == "string" && visit(type, path);
|
|
5576
|
+
for (let [k, child] of Object.entries(value)) walk(child, visit, [...path, k]);
|
|
5569
5577
|
}
|
|
5570
5578
|
/**
|
|
5571
5579
|
* Occurrences de tous les types connus, y compris ceux à zéro — ce sont eux
|
|
@@ -5576,7 +5584,8 @@ function occurrencesForTypes(docs, blockTypes) {
|
|
|
5576
5584
|
return blockTypes.map((type) => counted.get(type) ?? {
|
|
5577
5585
|
type,
|
|
5578
5586
|
count: 0,
|
|
5579
|
-
documentIds: []
|
|
5587
|
+
documentIds: [],
|
|
5588
|
+
locations: []
|
|
5580
5589
|
});
|
|
5581
5590
|
}
|
|
5582
5591
|
/** Nombre de blocs de premier niveau d'une page (colonne « blocs » de la liste). */
|
|
@@ -5657,6 +5666,32 @@ function componentIntentParams(type, namespace, preview, documentId) {
|
|
|
5657
5666
|
};
|
|
5658
5667
|
}
|
|
5659
5668
|
/**
|
|
5669
|
+
* Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
|
|
5670
|
+
* défaut côte à côte. Sans document de valeurs par défaut dans le schéma : la
|
|
5671
|
+
* démo du design system dans un nouvel onglet. `null` : rien à ouvrir.
|
|
5672
|
+
* Partagé par la grille et la vue Map de l'onglet Composants.
|
|
5673
|
+
*/
|
|
5674
|
+
function useOpenComponent() {
|
|
5675
|
+
let config = useKitConfig(), schema = useSchema(), router = useRouter(), client = useKitClient(), preview = config.componentPreview, hasDefaults = !!schema.get(preview.defaultsType), open = useCallback(async (type) => {
|
|
5676
|
+
if (!hasDefaults) {
|
|
5677
|
+
config.previewUrl && window.open(`${config.previewUrl}${preview.path}#${fillTemplate(preview.anchor, type, config.blockNamespace)}`, "_blank", "noopener");
|
|
5678
|
+
return;
|
|
5679
|
+
}
|
|
5680
|
+
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`, {
|
|
5681
|
+
type: preview.defaultsType,
|
|
5682
|
+
lang
|
|
5683
|
+
}).catch(() => null);
|
|
5684
|
+
router.navigateIntent("edit", componentIntentParams(type, config.blockNamespace, preview, id ?? preview.defaultsType));
|
|
5685
|
+
}, [
|
|
5686
|
+
hasDefaults,
|
|
5687
|
+
config,
|
|
5688
|
+
preview,
|
|
5689
|
+
client,
|
|
5690
|
+
router
|
|
5691
|
+
]);
|
|
5692
|
+
return !hasDefaults && !config.previewUrl ? null : (type) => void open(type);
|
|
5693
|
+
}
|
|
5694
|
+
/**
|
|
5660
5695
|
* Tuile d'un bloc dans la grille.
|
|
5661
5696
|
*
|
|
5662
5697
|
* Volontairement dépouillée : la capture, le nom, sa référence technique et
|
|
@@ -5771,7 +5806,8 @@ function layoutSectionsMap(blocks, occurrences, options = {}) {
|
|
|
5771
5806
|
occurrence: byType.get(block.name) ?? {
|
|
5772
5807
|
type: block.name,
|
|
5773
5808
|
count: 0,
|
|
5774
|
-
documentIds: []
|
|
5809
|
+
documentIds: [],
|
|
5810
|
+
locations: []
|
|
5775
5811
|
}
|
|
5776
5812
|
})).sort(compareBy(order)), max = Math.max(1, ...entries.map((entry) => entry.occurrence.count)), cell = maxSize + gap;
|
|
5777
5813
|
return entries.map((entry, index) => {
|
|
@@ -5900,7 +5936,7 @@ const nodeTypes = {
|
|
|
5900
5936
|
"--xy-attribution-background-color": "transparent"
|
|
5901
5937
|
};
|
|
5902
5938
|
function MapCanvas(props) {
|
|
5903
|
-
let { blockTypes, occurrences, pagesById, order } = props, config = useKitConfig(), { sectionsByName, loading, saveError, saveSections, resetSections } = useBoardLayout(), [selected, setSelected] = useState(null), { screenToFlowPosition } = useReactFlow(), { annotations, add: addAnnotation, update: updateAnnotation, remove: removeAnnotation } = useAnnotations("sections"), [nodes, setNodes, onNodesChange] = useNodesState([]), preview = config.componentPreview, canPreview = preview.provider === "designSystemPage" && !!config.previewUrl, placed = useMemo(() => layoutSectionsMap(blockTypes, occurrences, { order }), [
|
|
5939
|
+
let { blockTypes, occurrences, pagesById, order } = props, config = useKitConfig(), { sectionsByName, loading, saveError, saveSections, resetSections } = useBoardLayout(), [selected, setSelected] = useState(null), { screenToFlowPosition } = useReactFlow(), { annotations, add: addAnnotation, update: updateAnnotation, remove: removeAnnotation } = useAnnotations("sections"), [nodes, setNodes, onNodesChange] = useNodesState([]), openComponent = useOpenComponent(), preview = config.componentPreview, canPreview = preview.provider === "designSystemPage" && !!config.previewUrl, placed = useMemo(() => layoutSectionsMap(blockTypes, occurrences, { order }), [
|
|
5904
5940
|
blockTypes,
|
|
5905
5941
|
occurrences,
|
|
5906
5942
|
order
|
|
@@ -6127,24 +6163,40 @@ function MapCanvas(props) {
|
|
|
6127
6163
|
muted: !0,
|
|
6128
6164
|
children: selectedEntry.occurrence.count === 0 ? "Jamais utilisé sur le site." : `${selectedPages.length} page${selectedPages.length > 1 ? "s" : ""} · ${selectedEntry.occurrence.count} instance${selectedEntry.occurrence.count > 1 ? "s" : ""}`
|
|
6129
6165
|
}),
|
|
6166
|
+
openComponent && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Button, {
|
|
6167
|
+
mode: "default",
|
|
6168
|
+
tone: "primary",
|
|
6169
|
+
fontSize: 1,
|
|
6170
|
+
padding: 2,
|
|
6171
|
+
text: "Ouvrir le composant",
|
|
6172
|
+
title: "Rendu réel et valeurs par défaut, côte à côte",
|
|
6173
|
+
onClick: () => openComponent(selectedEntry.block.name)
|
|
6174
|
+
}) }),
|
|
6130
6175
|
/* @__PURE__ */ jsx(Stack, {
|
|
6131
6176
|
gap: 2,
|
|
6132
|
-
children: selectedPages.map((page) =>
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6177
|
+
children: selectedPages.map((page) => {
|
|
6178
|
+
let here = selectedEntry.occurrence.locations.filter((l) => l.documentId === page.id), first = here[0], path = first ? pathToString([config.pageBuilderField, ...first.path]) : void 0;
|
|
6179
|
+
return /* @__PURE__ */ jsx(IntentLink, {
|
|
6180
|
+
intent: "edit",
|
|
6181
|
+
params: path ? {
|
|
6182
|
+
id: page.id,
|
|
6183
|
+
type: page.type,
|
|
6184
|
+
path
|
|
6185
|
+
} : {
|
|
6186
|
+
id: page.id,
|
|
6187
|
+
type: page.type
|
|
6188
|
+
},
|
|
6189
|
+
style: {
|
|
6190
|
+
textDecoration: "none",
|
|
6191
|
+
color: "inherit"
|
|
6192
|
+
},
|
|
6193
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
6194
|
+
size: 1,
|
|
6195
|
+
textOverflow: "ellipsis",
|
|
6196
|
+
children: [page.title, here.length > 1 ? ` (${here.length} instances)` : ""]
|
|
6197
|
+
})
|
|
6198
|
+
}, page.id);
|
|
6199
|
+
})
|
|
6148
6200
|
}),
|
|
6149
6201
|
designSystemUrl && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Button, {
|
|
6150
6202
|
as: "a",
|
|
@@ -6166,7 +6218,7 @@ function MapCanvas(props) {
|
|
|
6166
6218
|
size: 0,
|
|
6167
6219
|
muted: !0,
|
|
6168
6220
|
align: "center",
|
|
6169
|
-
children: "Cliquer une section pour
|
|
6221
|
+
children: "Cliquer une section pour l’ouvrir (rendu réel et valeurs par défaut) ou aller à ses emplacements dans les pages."
|
|
6170
6222
|
})
|
|
6171
6223
|
})
|
|
6172
6224
|
})]
|
|
@@ -6196,23 +6248,7 @@ const ORDERS = [
|
|
|
6196
6248
|
}
|
|
6197
6249
|
];
|
|
6198
6250
|
function ComponentsTool() {
|
|
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,
|
|
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(() => {
|
|
6251
|
+
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, openComponent = useOpenComponent(), cards = useMemo(() => {
|
|
6216
6252
|
let byName = new Map(blockTypes.map((b) => [b.name, b])), rows = occurrences.map((occurrence) => ({
|
|
6217
6253
|
occurrence,
|
|
6218
6254
|
block: byName.get(occurrence.type)
|
|
@@ -6353,7 +6389,7 @@ function ComponentsTool() {
|
|
|
6353
6389
|
occurrence,
|
|
6354
6390
|
namespace: config.blockNamespace,
|
|
6355
6391
|
thumbnailUrl: canPreview ? `${config.previewUrl}${fillTemplate(preview.thumbnail, block.name, config.blockNamespace)}` : null,
|
|
6356
|
-
onOpen:
|
|
6392
|
+
onOpen: openComponent ? () => openComponent(block.name) : void 0
|
|
6357
6393
|
}, block.name))
|
|
6358
6394
|
})
|
|
6359
6395
|
]
|
|
@@ -7109,6 +7145,226 @@ function HistoryTool() {
|
|
|
7109
7145
|
})
|
|
7110
7146
|
});
|
|
7111
7147
|
}
|
|
7148
|
+
const store = /* @__PURE__ */ new Map();
|
|
7149
|
+
function entryFor(client, type, languageField, language) {
|
|
7150
|
+
let { projectId, dataset } = client.config(), key = `${projectId}:${dataset}:${type}:${language ?? ""}`, entry = store.get(key);
|
|
7151
|
+
entry || (entry = {
|
|
7152
|
+
value: null,
|
|
7153
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
7154
|
+
stop: null
|
|
7155
|
+
}, store.set(key, entry));
|
|
7156
|
+
let e = entry;
|
|
7157
|
+
if (!e.stop) {
|
|
7158
|
+
let filter = `_type == $type && ($language == null || !defined(${languageField}) || ${languageField} == $language)`, params = {
|
|
7159
|
+
type,
|
|
7160
|
+
language
|
|
7161
|
+
}, drafts = client.withConfig({ perspective: "drafts" }), load = () => drafts.fetch(`*[${filter}][0]`, params).then((value) => {
|
|
7162
|
+
e.value = value, e.listeners.forEach((l) => l());
|
|
7163
|
+
}).catch(() => {});
|
|
7164
|
+
load();
|
|
7165
|
+
let sub = client.listen(`*[${filter}]`, params, {
|
|
7166
|
+
visibility: "query",
|
|
7167
|
+
includeResult: !1
|
|
7168
|
+
}).subscribe({ next: () => void load() });
|
|
7169
|
+
e.stop = () => sub.unsubscribe();
|
|
7170
|
+
}
|
|
7171
|
+
return [key, e];
|
|
7172
|
+
}
|
|
7173
|
+
function useComponentDefaults(client, type, languageField, language) {
|
|
7174
|
+
let [, entry] = entryFor(client, type, languageField, language), value = useSyncExternalStore((listener) => (entry.listeners.add(listener), () => {
|
|
7175
|
+
entry.listeners.delete(listener);
|
|
7176
|
+
}), () => entry.value);
|
|
7177
|
+
return useEffect(() => () => {
|
|
7178
|
+
entry.listeners.size === 0 && entry.stop && (entry.stop(), entry.stop = null);
|
|
7179
|
+
}, [entry]), value;
|
|
7180
|
+
}
|
|
7181
|
+
const LINK_TARGET_FIELDS = [
|
|
7182
|
+
"page",
|
|
7183
|
+
"fixedPath",
|
|
7184
|
+
"href",
|
|
7185
|
+
"email",
|
|
7186
|
+
"phone",
|
|
7187
|
+
"file"
|
|
7188
|
+
], LINK_TYPES = /* @__PURE__ */ new Set(["link", "cardLink"]);
|
|
7189
|
+
function isEmptyValue(value) {
|
|
7190
|
+
return value == null || value === "" || Array.isArray(value) && value.length === 0;
|
|
7191
|
+
}
|
|
7192
|
+
const isKeyed = (s) => typeof s == "object" && !!s && !Array.isArray(s) && typeof s._key == "string";
|
|
7193
|
+
/** Index du premier élément de liste du chemin (l'instance de composant dans le page builder), ou -1. */
|
|
7194
|
+
function firstKeyedIndex(path) {
|
|
7195
|
+
return path.findIndex(isKeyed);
|
|
7196
|
+
}
|
|
7197
|
+
/**
|
|
7198
|
+
* Chemin du champ à l'intérieur de l'instance, listes comprises : un élément de
|
|
7199
|
+
* liste est repéré par son rang (`['items', 0, 'title']`), comparé à l'élément de
|
|
7200
|
+
* même rang de la valeur par défaut. `inList` : le champ est dans un élément de
|
|
7201
|
+
* liste (une liste remplie remplace celle du défaut en entier : réinitialiser
|
|
7202
|
+
* RECOPIE la valeur par défaut au lieu de vider le champ). `null` : pas un
|
|
7203
|
+
* composant de l'espace de noms.
|
|
7204
|
+
*/
|
|
7205
|
+
function resolveFieldPath(path, index, instance, namespace) {
|
|
7206
|
+
let type = instance?._type;
|
|
7207
|
+
if (index < 0 || typeof type != "string" || !type.startsWith(namespace)) return null;
|
|
7208
|
+
let rest = path.slice(index + 1);
|
|
7209
|
+
if (rest.length === 0) return null;
|
|
7210
|
+
let out = [], inList = !1, node = instance;
|
|
7211
|
+
for (let seg of rest) if (typeof seg == "string") out.push(seg), node = node && typeof node == "object" ? node[seg] : void 0;
|
|
7212
|
+
else if (isKeyed(seg) || typeof seg == "number") {
|
|
7213
|
+
if (!Array.isArray(node)) return null;
|
|
7214
|
+
let i = typeof seg == "number" ? seg : node.findIndex((item) => item?._key === seg._key);
|
|
7215
|
+
if (i < 0 || node[i]?._type === "block") return null;
|
|
7216
|
+
out.push(i), inList = !0, node = node[i];
|
|
7217
|
+
} else return null;
|
|
7218
|
+
return {
|
|
7219
|
+
path: out,
|
|
7220
|
+
inList
|
|
7221
|
+
};
|
|
7222
|
+
}
|
|
7223
|
+
/** Valeur par défaut d'un champ de composant. */
|
|
7224
|
+
function defaultValueAt(defaults, blockShortName, relPath) {
|
|
7225
|
+
let node = defaults?.[blockShortName];
|
|
7226
|
+
for (let key of relPath) {
|
|
7227
|
+
if (!node || typeof node != "object") return;
|
|
7228
|
+
node = node[key];
|
|
7229
|
+
}
|
|
7230
|
+
return node;
|
|
7231
|
+
}
|
|
7232
|
+
const hasLinkTarget = (link) => {
|
|
7233
|
+
let l = link ?? {};
|
|
7234
|
+
return LINK_TARGET_FIELDS.some((k) => k === "file" ? !!l.file?.asset : !isEmptyValue(l[k]));
|
|
7235
|
+
};
|
|
7236
|
+
/**
|
|
7237
|
+
* Le champ est-il un override ? Valeur propre à l'instance DIFFÉRENTE de la
|
|
7238
|
+
* valeur par défaut du composant (y compris quand le composant n'a pas de valeur
|
|
7239
|
+
* par défaut pour ce champ). Un champ vide hérite : jamais d'override. Une case
|
|
7240
|
+
* décochée vaut une case non renseignée. Le type d'un lien ne compte que si le
|
|
7241
|
+
* lien a sa propre cible (il est prérempli par le Studio).
|
|
7242
|
+
*/
|
|
7243
|
+
function isOverride(local, inherited, field, parent) {
|
|
7244
|
+
if (isEmptyValue(local) || local === !1 && isEmptyValue(inherited)) return !1;
|
|
7245
|
+
let parentType = parent?._type;
|
|
7246
|
+
return field === "type" && typeof parentType == "string" && LINK_TYPES.has(parentType) && !hasLinkTarget(parent) ? !1 : !sameValue(local, inherited);
|
|
7247
|
+
}
|
|
7248
|
+
/** Égalité de valeurs (champ identique au défaut : override « figé »). */
|
|
7249
|
+
function sameValue(a, b) {
|
|
7250
|
+
if (a === b) return !0;
|
|
7251
|
+
let clean = (v) => Array.isArray(v) ? v.map(clean) : v && typeof v == "object" ? Object.fromEntries(Object.entries(v).filter(([k]) => !k.startsWith("_") || k === "_ref").sort(([x], [y]) => x.localeCompare(y)).map(([k, x]) => [k, clean(x)])) : v;
|
|
7252
|
+
return JSON.stringify(clean(a)) === JSON.stringify(clean(b));
|
|
7253
|
+
}
|
|
7254
|
+
/** Valeur par défaut lisible, pour la bulle de la pastille. */
|
|
7255
|
+
function describeValue(value) {
|
|
7256
|
+
if (isEmptyValue(value)) return "vide (valeur du design system)";
|
|
7257
|
+
if (typeof value == "string") return value.length > 60 ? `« ${value.slice(0, 57)}… »` : `« ${value} »`;
|
|
7258
|
+
if (typeof value == "boolean") return value ? "Oui" : "Non";
|
|
7259
|
+
if (typeof value == "number") return String(value);
|
|
7260
|
+
if (Array.isArray(value)) return `${value.length} élément${value.length > 1 ? "s" : ""}`;
|
|
7261
|
+
if (value && typeof value == "object") {
|
|
7262
|
+
let v = value;
|
|
7263
|
+
if (typeof v.token == "string") return `couleur ${v.token}`;
|
|
7264
|
+
if (typeof v.customHex == "string") return `couleur ${v.customHex}`;
|
|
7265
|
+
if (typeof v.label == "string") return `« ${v.label} »`;
|
|
7266
|
+
if (v.asset) return "une image";
|
|
7267
|
+
if (typeof v._ref == "string") return "un document";
|
|
7268
|
+
}
|
|
7269
|
+
return "une valeur";
|
|
7270
|
+
}
|
|
7271
|
+
/**
|
|
7272
|
+
* Pastille bleue sur tout champ d'une instance de composant dont la valeur
|
|
7273
|
+
* DIFFÈRE de la valeur par défaut du composant (valeur par défaut vide comprise),
|
|
7274
|
+
* éléments de liste compris (comparés à l'élément de même rang). Au survol, elle
|
|
7275
|
+
* devient « Réinitialiser » : retour à la valeur par défaut. Les champs
|
|
7276
|
+
* « simples » la portent (texte, nombre, choix, case, liste, image, référence,
|
|
7277
|
+
* couleur...) ; un objet composé (lien) la porte sur ses sous-champs.
|
|
7278
|
+
*/
|
|
7279
|
+
function createOverrideInput(config) {
|
|
7280
|
+
let { defaultsType } = config.componentPreview, namespace = config.blockNamespace;
|
|
7281
|
+
function OverrideInput(props) {
|
|
7282
|
+
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);
|
|
7283
|
+
if (!resolved || !schema.get(defaultsType) || !carriesDot(props.schemaType)) return props.renderDefault(props);
|
|
7284
|
+
let shortName = blockName(instance._type, namespace);
|
|
7285
|
+
return /* @__PURE__ */ jsx(WithDot, {
|
|
7286
|
+
...props,
|
|
7287
|
+
rel: resolved.path,
|
|
7288
|
+
inList: resolved.inList,
|
|
7289
|
+
shortName,
|
|
7290
|
+
parent
|
|
7291
|
+
});
|
|
7292
|
+
}
|
|
7293
|
+
function WithDot(props) {
|
|
7294
|
+
let { rel, inList, shortName, parent, ...inputProps } = props, client = useKitClient(), languageField = config.i18n?.field ?? "language", language = useFormValue([languageField]) ?? null, inherited = defaultValueAt(useComponentDefaults(client, defaultsType, languageField, language), shortName, rel), field = rel[rel.length - 1] ?? "";
|
|
7295
|
+
if (!isOverride(inputProps.value, inherited, field, parent)) return inputProps.renderDefault(inputProps);
|
|
7296
|
+
let reset = () => inputProps.onChange(inList && inherited != null ? set(structuredClone(inherited)) : unset());
|
|
7297
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
7298
|
+
align: "flex-start",
|
|
7299
|
+
gap: 2,
|
|
7300
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
7301
|
+
flex: 1,
|
|
7302
|
+
style: { minWidth: 0 },
|
|
7303
|
+
children: inputProps.renderDefault(inputProps)
|
|
7304
|
+
}), /* @__PURE__ */ jsx(OverrideDot, {
|
|
7305
|
+
inherited: describeValue(inherited),
|
|
7306
|
+
onReset: reset
|
|
7307
|
+
})]
|
|
7308
|
+
});
|
|
7309
|
+
}
|
|
7310
|
+
return OverrideInput;
|
|
7311
|
+
}
|
|
7312
|
+
function carriesDot(schemaType) {
|
|
7313
|
+
if (schemaType.jsonType !== "object") return !0;
|
|
7314
|
+
let t = schemaType;
|
|
7315
|
+
for (; t;) {
|
|
7316
|
+
if (t.components?.input || t.name === "image" || t.name === "file" || t.name === "reference") return !0;
|
|
7317
|
+
t = t.type;
|
|
7318
|
+
}
|
|
7319
|
+
return !1;
|
|
7320
|
+
}
|
|
7321
|
+
function OverrideDot(props) {
|
|
7322
|
+
let [hover, setHover] = useState(!1);
|
|
7323
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
7324
|
+
portal: !0,
|
|
7325
|
+
placement: "left",
|
|
7326
|
+
content: /* @__PURE__ */ jsx(Box, {
|
|
7327
|
+
padding: 2,
|
|
7328
|
+
style: { maxWidth: 260 },
|
|
7329
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
7330
|
+
size: 1,
|
|
7331
|
+
children: [
|
|
7332
|
+
"Valeur différente du défaut du composant (",
|
|
7333
|
+
props.inherited,
|
|
7334
|
+
"). Survoler puis cliquer pour revenir à la valeur par défaut."
|
|
7335
|
+
]
|
|
7336
|
+
})
|
|
7337
|
+
}),
|
|
7338
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
7339
|
+
type: "button",
|
|
7340
|
+
onClick: props.onReset,
|
|
7341
|
+
onMouseEnter: () => setHover(!0),
|
|
7342
|
+
onMouseLeave: () => setHover(!1),
|
|
7343
|
+
onFocus: () => setHover(!0),
|
|
7344
|
+
onBlur: () => setHover(!1),
|
|
7345
|
+
"aria-label": "Réinitialiser à la valeur par défaut du composant",
|
|
7346
|
+
style: {
|
|
7347
|
+
marginTop: 9,
|
|
7348
|
+
flex: "none",
|
|
7349
|
+
height: hover ? 22 : 10,
|
|
7350
|
+
minWidth: 10,
|
|
7351
|
+
padding: hover ? "0 8px" : 0,
|
|
7352
|
+
borderRadius: 999,
|
|
7353
|
+
border: 0,
|
|
7354
|
+
background: "var(--card-badge-primary-dot-color, #2276fc)",
|
|
7355
|
+
color: "#fff",
|
|
7356
|
+
fontSize: 11,
|
|
7357
|
+
fontWeight: 600,
|
|
7358
|
+
lineHeight: "22px",
|
|
7359
|
+
whiteSpace: "nowrap",
|
|
7360
|
+
cursor: "pointer",
|
|
7361
|
+
transform: hover ? "translateY(-6px)" : "none",
|
|
7362
|
+
transition: "all 120ms ease"
|
|
7363
|
+
},
|
|
7364
|
+
children: hover ? "↺ Réinitialiser" : ""
|
|
7365
|
+
})
|
|
7366
|
+
});
|
|
7367
|
+
}
|
|
7112
7368
|
/**
|
|
7113
7369
|
* `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
|
|
7114
7370
|
* le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
|
|
@@ -7272,6 +7528,16 @@ function NcfPreviewHeader(props) {
|
|
|
7272
7528
|
function ncfPreviewComponents() {
|
|
7273
7529
|
return { unstable_header: { component: NcfPreviewHeader } };
|
|
7274
7530
|
}
|
|
7531
|
+
/**
|
|
7532
|
+
* Plugin Studio de NoCode Factory : Pages, Composants, Historique.
|
|
7533
|
+
*
|
|
7534
|
+
* ```ts
|
|
7535
|
+
* plugins: [ncfKit({pageTypes: [{type: 'homePage', path: '/'}, 'page']})]
|
|
7536
|
+
* ```
|
|
7537
|
+
*
|
|
7538
|
+
* La configuration est validée au démarrage. Une option invalide n'empêche
|
|
7539
|
+
* pas le Studio de démarrer : l'onglet concerné affiche le détail à corriger.
|
|
7540
|
+
*/
|
|
7275
7541
|
/** Noms des outils dans la barre du Studio. Exportés pour filtrer `tools`. */
|
|
7276
7542
|
const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_HISTORY_TOOL = "ncf-history", NCF_TOOL_NAMES = [
|
|
7277
7543
|
NCF_PAGES_TOOL,
|
|
@@ -7333,7 +7599,8 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
|
|
|
7333
7599
|
templates: (prev) => prev.filter((template) => !isKitType(template.schemaType))
|
|
7334
7600
|
},
|
|
7335
7601
|
document: { newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE) },
|
|
7336
|
-
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } }
|
|
7602
|
+
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
|
|
7603
|
+
form: { components: { input: createOverrideInput(config) } }
|
|
7337
7604
|
};
|
|
7338
7605
|
});
|
|
7339
7606
|
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_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, createPreviewLauncher, customEnvironment, defaultNodeSize, 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, 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 };
|