@nocode-factory/sanity-kit 2.53.0 → 2.54.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 +31 -0
- package/dist/{finalUrl-CaFXmYvm.js → finalUrl-IXF3zbT9.js} +7 -2
- package/dist/finalUrl-IXF3zbT9.js.map +1 -0
- package/dist/{fixCrossLanguageReferences-w3whO9xM.d.ts → fixCrossLanguageReferences-C1VsmGsJ.d.ts} +21 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js → fixCrossLanguageReferences-CDczoic9.js} +2 -2
- package/dist/{fixCrossLanguageReferences-BeXywAAU.js.map → fixCrossLanguageReferences-CDczoic9.js.map} +1 -1
- package/dist/index.d.ts +173 -7
- package/dist/index.js +715 -26
- package/dist/index.js.map +1 -1
- package/dist/jsonld.js +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +2 -2
- package/package.json +1 -1
- package/src/config/resolve.ts +5 -0
- package/src/config/types.ts +21 -0
- package/src/hooks/useCollection.ts +51 -0
- package/src/index.ts +18 -0
- package/src/lib/collectionColumns.ts +114 -0
- package/src/lib/collectionQuery.ts +23 -0
- package/src/lib/collectionRows.ts +92 -0
- package/src/lib/collectionTable.ts +72 -0
- package/src/lib/collectionTypes.ts +49 -0
- package/src/lib/csv.ts +24 -0
- package/src/lib/download.ts +24 -0
- package/src/lib/schemaColumns.ts +18 -5
- package/src/structure/collections.tsx +103 -0
- package/src/tools/collections/CollectionColumnPicker.tsx +122 -0
- package/src/tools/collections/CollectionTable.tsx +259 -0
- package/src/tools/collections/CollectionToolbar.tsx +68 -0
- package/src/version.ts +1 -1
- package/dist/finalUrl-CaFXmYvm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as DEFAULT_PAGE_BUILDER_FIELD, a as depth, c as segments, d as normalizePath, f as resolveConfig, g as DEFAULT_INTERNAL_FIELDS, h as DEFAULT_I18N, i as redirectMapOf, l as toPath, m as DEFAULT_COMPONENT_PREVIEW, o as pageTypeFor, p as DEFAULT_BOARD_TAGS, s as parentPath, t as finalPath, u as toUrl, v as DEFAULT_SLUG_FIELD, y as DEFAULT_TITLE_FIELD } from "./finalUrl-
|
|
1
|
+
import { _ as DEFAULT_PAGE_BUILDER_FIELD, a as depth, c as segments, d as normalizePath, f as resolveConfig, g as DEFAULT_INTERNAL_FIELDS, h as DEFAULT_I18N, i as redirectMapOf, l as toPath, m as DEFAULT_COMPONENT_PREVIEW, o as pageTypeFor, p as DEFAULT_BOARD_TAGS, s as parentPath, t as finalPath, u as toUrl, v as DEFAULT_SLUG_FIELD, y as DEFAULT_TITLE_FIELD } from "./finalUrl-IXF3zbT9.js";
|
|
2
2
|
import { a as collectTexts$1, c as valueAtKey, d as useKitContext, f as useOptionalKitConfig, i as guessDocumentTitle, l as KitProvider, o as replaceTexts, p as useOptionalKitContext, r as collectDocumentText, s as setAtKey, t as generateJsonLd, u as useKitConfig } from "./aiJsonLd-BFyxgYen.js";
|
|
3
|
-
import { a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, p as translationRedirectOptions, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-
|
|
3
|
+
import { a as componentDefaultsMainDocument, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, l as requiredUnlessDefault, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, p as translationRedirectOptions, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor } from "./fixCrossLanguageReferences-CDczoic9.js";
|
|
4
4
|
import { i as codeEditorInput, n as CodeEmbedInput, r as CodeEditorInput, t as defineCodeEmbedType } from "./codeEmbedType-1bEOTxBT.js";
|
|
5
5
|
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
6
|
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, usePerspective, useSchema, useSetPerspective, useUser, useWorkspace } from "sanity";
|
|
@@ -54,6 +54,7 @@ import { DragHandleIcon } from "@sanity/icons/DragHandle";
|
|
|
54
54
|
import { createPortal } from "react-dom";
|
|
55
55
|
import { TabletDeviceIcon } from "@sanity/icons/TabletDevice";
|
|
56
56
|
import { PanelRightIcon } from "@sanity/icons/PanelRight";
|
|
57
|
+
import { DownloadIcon } from "@sanity/icons/Download";
|
|
57
58
|
const isAbsoluteHttpUrl = (value) => {
|
|
58
59
|
try {
|
|
59
60
|
let url = new URL(value);
|
|
@@ -1420,7 +1421,7 @@ function explainGrantError(error) {
|
|
|
1420
1421
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1421
1422
|
* le vérifie.
|
|
1422
1423
|
*/
|
|
1423
|
-
const KIT_VERSION = "2.
|
|
1424
|
+
const KIT_VERSION = "2.54.0";
|
|
1424
1425
|
/**
|
|
1425
1426
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1426
1427
|
*
|
|
@@ -1918,7 +1919,7 @@ function useKitUpdate() {
|
|
|
1918
1919
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1919
1920
|
}).catch(() => {}), () => controller.abort();
|
|
1920
1921
|
}, []);
|
|
1921
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1922
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.54.0") > 0);
|
|
1922
1923
|
return {
|
|
1923
1924
|
current: KIT_VERSION,
|
|
1924
1925
|
latest,
|
|
@@ -1938,7 +1939,7 @@ const TABULAR = { fontVariantNumeric: "tabular-nums" }, MONO = {
|
|
|
1938
1939
|
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
1939
1940
|
fontVariantNumeric: "tabular-nums",
|
|
1940
1941
|
letterSpacing: "-0.01em"
|
|
1941
|
-
}, CELL = { minWidth: 0 }, BORDER = "var(--card-border-color, rgba(127,127,127,0.22))", OPTION_COLORS = [
|
|
1942
|
+
}, CELL = { minWidth: 0 }, BORDER = "var(--card-border-color, rgba(127,127,127,0.22))", BORDER_SOFT = "var(--card-border-color, rgba(127,127,127,0.12))", OPTION_COLORS = [
|
|
1942
1943
|
"#f5a623",
|
|
1943
1944
|
"#43d675",
|
|
1944
1945
|
"#2276fc",
|
|
@@ -2561,7 +2562,7 @@ const STATUS_ORDER = {
|
|
|
2561
2562
|
case "blockCount": return a.blockCount - b.blockCount;
|
|
2562
2563
|
}
|
|
2563
2564
|
};
|
|
2564
|
-
function sortRows(rows, key, direction, options = {}) {
|
|
2565
|
+
function sortRows$1(rows, key, direction, options = {}) {
|
|
2565
2566
|
if (key === "manual") {
|
|
2566
2567
|
let sorted = orderByIds([...rows].sort((a, b) => a.title.localeCompare(b.title, void 0, { sensitivity: "base" })), options.pageOrder ?? []);
|
|
2567
2568
|
return direction === "asc" ? sorted : sorted.reverse();
|
|
@@ -2569,10 +2570,10 @@ function sortRows(rows, key, direction, options = {}) {
|
|
|
2569
2570
|
let sorted = [...rows].sort((a, b) => compare(a, b, key, options));
|
|
2570
2571
|
return direction === "asc" ? sorted : sorted.reverse();
|
|
2571
2572
|
}
|
|
2572
|
-
const normalize = (value) => value.toLocaleLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
|
2573
|
-
function filterRows(rows, filters) {
|
|
2574
|
-
let search = filters.search?.trim() ? normalize(filters.search.trim()) : null;
|
|
2575
|
-
return rows.filter((row) => !(filters.types?.length && !filters.types.includes(row.type) || filters.statuses?.length && !filters.statuses.includes(row.status) || filters.locales?.length && row.locale && !filters.locales.includes(row.locale) || search && !`${normalize(row.title)} ${normalize(row.path ?? "")}`.includes(search)));
|
|
2573
|
+
const normalize$1 = (value) => value.toLocaleLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
|
2574
|
+
function filterRows$1(rows, filters) {
|
|
2575
|
+
let search = filters.search?.trim() ? normalize$1(filters.search.trim()) : null;
|
|
2576
|
+
return rows.filter((row) => !(filters.types?.length && !filters.types.includes(row.type) || filters.statuses?.length && !filters.statuses.includes(row.status) || filters.locales?.length && row.locale && !filters.locales.includes(row.locale) || search && !`${normalize$1(row.title)} ${normalize$1(row.path ?? "")}`.includes(search)));
|
|
2576
2577
|
}
|
|
2577
2578
|
/** Langues réellement présentes, pour ne proposer que des filtres utiles. */
|
|
2578
2579
|
function localesInRows(rows) {
|
|
@@ -2679,6 +2680,10 @@ const OPAQUE_TYPES = /* @__PURE__ */ new Set([
|
|
|
2679
2680
|
"globalDocumentReference",
|
|
2680
2681
|
"block",
|
|
2681
2682
|
"geopoint"
|
|
2683
|
+
]), REFERENCE_TYPES = /* @__PURE__ */ new Set([
|
|
2684
|
+
"reference",
|
|
2685
|
+
"crossDatasetReference",
|
|
2686
|
+
"globalDocumentReference"
|
|
2682
2687
|
]);
|
|
2683
2688
|
/** Remonte la chaîne d'héritage jusqu'à trouver la nature JSON du champ. */
|
|
2684
2689
|
function jsonTypeOf(type) {
|
|
@@ -2705,6 +2710,15 @@ function isOpaque(type) {
|
|
|
2705
2710
|
}
|
|
2706
2711
|
return !1;
|
|
2707
2712
|
}
|
|
2713
|
+
/** Vrai pour un champ référence (vers un autre document). */
|
|
2714
|
+
function isReference(type) {
|
|
2715
|
+
let current = type;
|
|
2716
|
+
for (let depth = 0; current && depth < 10; depth += 1) {
|
|
2717
|
+
if (current.name && REFERENCE_TYPES.has(current.name)) return !0;
|
|
2718
|
+
current = current.type;
|
|
2719
|
+
}
|
|
2720
|
+
return !1;
|
|
2721
|
+
}
|
|
2708
2722
|
const labelOf = (field) => field.type?.title?.trim() || humanise(field.name);
|
|
2709
2723
|
/** `metaDescription` → `Meta description`. */
|
|
2710
2724
|
function humanise(name) {
|
|
@@ -4175,7 +4189,7 @@ const formatter = new Intl.DateTimeFormat("en-US", {
|
|
|
4175
4189
|
minute: "2-digit"
|
|
4176
4190
|
});
|
|
4177
4191
|
/** Date lisible, ou un tiret cadratin quand il n'y en a pas. */
|
|
4178
|
-
function formatDate(value) {
|
|
4192
|
+
function formatDate$1(value) {
|
|
4179
4193
|
if (!value) return "—";
|
|
4180
4194
|
let date = new Date(value);
|
|
4181
4195
|
return Number.isNaN(date.getTime()) ? "—" : formatter.format(date);
|
|
@@ -4863,7 +4877,7 @@ function PagesTable(props) {
|
|
|
4863
4877
|
].join(" "),
|
|
4864
4878
|
gap: "0.875rem",
|
|
4865
4879
|
alignItems: "center",
|
|
4866
|
-
borderBottom:
|
|
4880
|
+
borderBottom: `1px solid ${BORDER_SOFT}`
|
|
4867
4881
|
};
|
|
4868
4882
|
return /* @__PURE__ */ jsxs(Box, {
|
|
4869
4883
|
style: { overflowX: "auto" },
|
|
@@ -5063,7 +5077,7 @@ function PagesTable(props) {
|
|
|
5063
5077
|
size: 0,
|
|
5064
5078
|
muted: !0,
|
|
5065
5079
|
style: TABULAR,
|
|
5066
|
-
children: formatDate(entryRow.updatedAt)
|
|
5080
|
+
children: formatDate$1(entryRow.updatedAt)
|
|
5067
5081
|
})
|
|
5068
5082
|
}),
|
|
5069
5083
|
dataColumns.map((column) => {
|
|
@@ -5186,7 +5200,7 @@ function ColumnVisibility(props) {
|
|
|
5186
5200
|
})
|
|
5187
5201
|
});
|
|
5188
5202
|
}
|
|
5189
|
-
function Row$
|
|
5203
|
+
function Row$2(props) {
|
|
5190
5204
|
return /* @__PURE__ */ jsxs(Flex, {
|
|
5191
5205
|
align: "center",
|
|
5192
5206
|
gap: 2,
|
|
@@ -5231,7 +5245,7 @@ function DataColumnList(props) {
|
|
|
5231
5245
|
}, [dataColumns, filter]);
|
|
5232
5246
|
return /* @__PURE__ */ jsxs(Stack, {
|
|
5233
5247
|
gap: 0,
|
|
5234
|
-
children: [HIDEABLE.map((column) => /* @__PURE__ */ jsx(Row$
|
|
5248
|
+
children: [HIDEABLE.map((column) => /* @__PURE__ */ jsx(Row$2, {
|
|
5235
5249
|
label: column.label,
|
|
5236
5250
|
checked: !hidden.has(column.key),
|
|
5237
5251
|
onClick: () => onToggle(column.key)
|
|
@@ -5268,7 +5282,7 @@ function DataColumnList(props) {
|
|
|
5268
5282
|
}
|
|
5269
5283
|
})
|
|
5270
5284
|
}),
|
|
5271
|
-
matches.map((column) => /* @__PURE__ */ jsx(Row$
|
|
5285
|
+
matches.map((column) => /* @__PURE__ */ jsx(Row$2, {
|
|
5272
5286
|
label: column.label,
|
|
5273
5287
|
checked: shownData.has(column.key),
|
|
5274
5288
|
onClick: () => onToggleData(column.key)
|
|
@@ -6431,7 +6445,7 @@ function PagesTool() {
|
|
|
6431
6445
|
let next = new Set(current);
|
|
6432
6446
|
return next.has(key) ? next.delete(key) : next.add(key), next;
|
|
6433
6447
|
});
|
|
6434
|
-
}, []), documentColumns = useDocumentColumns(), visibleDataColumns = useMemo(() => documentColumns.filter((column) => shownData.has(column.key)), [documentColumns, shownData]), { rows, loading, error, refresh } = usePages(visibleDataColumns), colorBy = resolveColorBy(rawColorBy, columns), locales = useMemo(() => config.i18n?.locales.length ? config.i18n.locales : localesInRows(rows), [config.i18n, rows]), effectiveSortKey = sortKey ?? (pageOrder.length > 0 ? "manual" : "structure"), visible = useMemo(() => sortRows(filterRows(rows, {
|
|
6448
|
+
}, []), documentColumns = useDocumentColumns(), visibleDataColumns = useMemo(() => documentColumns.filter((column) => shownData.has(column.key)), [documentColumns, shownData]), { rows, loading, error, refresh } = usePages(visibleDataColumns), colorBy = resolveColorBy(rawColorBy, columns), locales = useMemo(() => config.i18n?.locales.length ? config.i18n.locales : localesInRows(rows), [config.i18n, rows]), effectiveSortKey = sortKey ?? (pageOrder.length > 0 ? "manual" : "structure"), visible = useMemo(() => sortRows$1(filterRows$1(rows, {
|
|
6435
6449
|
search,
|
|
6436
6450
|
locales: locale ? [locale] : void 0
|
|
6437
6451
|
}).filter((row) => !onlyTodo || todos.has(row.id)), effectiveSortKey, sortDirection, {
|
|
@@ -9198,7 +9212,7 @@ function countByFolder(assets, folders) {
|
|
|
9198
9212
|
}
|
|
9199
9213
|
return counts;
|
|
9200
9214
|
}
|
|
9201
|
-
function Row(props) {
|
|
9215
|
+
function Row$1(props) {
|
|
9202
9216
|
return /* @__PURE__ */ jsxs(Flex, {
|
|
9203
9217
|
align: "center",
|
|
9204
9218
|
gap: 1,
|
|
@@ -9278,19 +9292,19 @@ function FolderSidebar(props) {
|
|
|
9278
9292
|
/* @__PURE__ */ jsxs(Stack, {
|
|
9279
9293
|
gap: 1,
|
|
9280
9294
|
children: [
|
|
9281
|
-
/* @__PURE__ */ jsx(Row, {
|
|
9295
|
+
/* @__PURE__ */ jsx(Row$1, {
|
|
9282
9296
|
label: "Tous les médias",
|
|
9283
9297
|
count: total,
|
|
9284
9298
|
active: selection === null,
|
|
9285
9299
|
onClick: () => onSelect(null)
|
|
9286
9300
|
}),
|
|
9287
|
-
/* @__PURE__ */ jsx(Row, {
|
|
9301
|
+
/* @__PURE__ */ jsx(Row$1, {
|
|
9288
9302
|
label: "Non classés",
|
|
9289
9303
|
count: counts.get("") ?? 0,
|
|
9290
9304
|
active: selection === "",
|
|
9291
9305
|
onClick: () => onSelect("")
|
|
9292
9306
|
}),
|
|
9293
|
-
folders.map((folder) => /* @__PURE__ */ jsx(Row, {
|
|
9307
|
+
folders.map((folder) => /* @__PURE__ */ jsx(Row$1, {
|
|
9294
9308
|
label: folder.name,
|
|
9295
9309
|
count: counts.get(folder.id) ?? 0,
|
|
9296
9310
|
active: selection === folder.id,
|
|
@@ -9868,7 +9882,7 @@ function AssetTable(props) {
|
|
|
9868
9882
|
size: 1,
|
|
9869
9883
|
muted: !0,
|
|
9870
9884
|
style: TABULAR,
|
|
9871
|
-
children: formatDate(asset._createdAt)
|
|
9885
|
+
children: formatDate$1(asset._createdAt)
|
|
9872
9886
|
})
|
|
9873
9887
|
})
|
|
9874
9888
|
]
|
|
@@ -9908,7 +9922,7 @@ function toPatchPath(segments) {
|
|
|
9908
9922
|
function assetUnsetPaths(doc, assetId) {
|
|
9909
9923
|
return findAssetRefPaths(doc, assetId).map(toPatchPath).filter(Boolean);
|
|
9910
9924
|
}
|
|
9911
|
-
const baseId$
|
|
9925
|
+
const baseId$2 = (id) => id.replace(/^drafts\./, "");
|
|
9912
9926
|
/**
|
|
9913
9927
|
* Suppression d'un asset depuis l'outil Assets. Sanity refuse de supprimer un
|
|
9914
9928
|
* asset référencé : on retire d'abord l'asset de chaque document (le champ
|
|
@@ -9920,7 +9934,7 @@ function useAssetDelete() {
|
|
|
9920
9934
|
usage: useCallback(async (assetId) => {
|
|
9921
9935
|
let docs = await client.fetch("*[references($id)]{_id, _type, \"title\": coalesce(title, name, originalFilename, slug.current, _id)}", { id: assetId }), seen = /* @__PURE__ */ new Map();
|
|
9922
9936
|
for (let doc of docs ?? []) {
|
|
9923
|
-
let id = baseId$
|
|
9937
|
+
let id = baseId$2(doc._id);
|
|
9924
9938
|
seen.has(id) || seen.set(id, {
|
|
9925
9939
|
id,
|
|
9926
9940
|
type: doc._type,
|
|
@@ -10149,7 +10163,7 @@ function AssetDetail(props) {
|
|
|
10149
10163
|
}),
|
|
10150
10164
|
/* @__PURE__ */ jsx(Metric, {
|
|
10151
10165
|
label: "Ajouté",
|
|
10152
|
-
value: formatDate(asset._createdAt)
|
|
10166
|
+
value: formatDate$1(asset._createdAt)
|
|
10153
10167
|
})
|
|
10154
10168
|
]
|
|
10155
10169
|
}),
|
|
@@ -12670,6 +12684,681 @@ function ncfPresentationComponents(options) {
|
|
|
12670
12684
|
unstable_header: { component: NcfPresentationHeader }
|
|
12671
12685
|
};
|
|
12672
12686
|
}
|
|
12687
|
+
/** Champs d'un titre affichable d'un document référencé, par ordre de préférence. */
|
|
12688
|
+
const REFERENCE_TITLE_FIELDS = [
|
|
12689
|
+
"title",
|
|
12690
|
+
"name",
|
|
12691
|
+
"label",
|
|
12692
|
+
"heading"
|
|
12693
|
+
];
|
|
12694
|
+
/**
|
|
12695
|
+
* Colonnes tirées du schéma d'un type de collection. Aucune liste à tenir :
|
|
12696
|
+
* chaque champ scalaire, date ou référence devient une colonne proposable. Les
|
|
12697
|
+
* tableaux, images, fichiers et blocs sont écartés — rien à rendre en ligne.
|
|
12698
|
+
*/
|
|
12699
|
+
function deriveCollectionColumns(type, options = {}) {
|
|
12700
|
+
let maxDepth = options.depth ?? 1, found = /* @__PURE__ */ new Map(), add = (path, label, kind, projection) => {
|
|
12701
|
+
let key = keyForPath(path);
|
|
12702
|
+
!found.has(key) && isSafeColumnKey(key) && found.set(key, {
|
|
12703
|
+
key,
|
|
12704
|
+
label,
|
|
12705
|
+
kind,
|
|
12706
|
+
projection
|
|
12707
|
+
});
|
|
12708
|
+
}, visit = (fields, prefix, prefixLabel, depth) => {
|
|
12709
|
+
for (let field of fields) {
|
|
12710
|
+
if (!field.name || field.name.startsWith("_")) continue;
|
|
12711
|
+
let path = prefix ? `${prefix}.${field.name}` : field.name;
|
|
12712
|
+
if (!isSafeFieldPath(path)) continue;
|
|
12713
|
+
let label = prefixLabel ? `${prefixLabel} · ${labelOf(field)}` : labelOf(field), typeName = typeNameOf(field.type);
|
|
12714
|
+
if (typeName === "slug") {
|
|
12715
|
+
add(path, label, "text", `${path}.current`);
|
|
12716
|
+
continue;
|
|
12717
|
+
}
|
|
12718
|
+
if (isReference(field.type)) {
|
|
12719
|
+
let titles = REFERENCE_TITLE_FIELDS.map((f) => `${path}->${f}`);
|
|
12720
|
+
add(path, label, "reference", `coalesce(${titles.join(", ")}, ${path}->_id)`);
|
|
12721
|
+
continue;
|
|
12722
|
+
}
|
|
12723
|
+
if (isOpaque(field.type)) continue;
|
|
12724
|
+
if (typeName === "datetime" || typeName === "date") {
|
|
12725
|
+
add(path, label, "date", path);
|
|
12726
|
+
continue;
|
|
12727
|
+
}
|
|
12728
|
+
let json = jsonTypeOf(field.type);
|
|
12729
|
+
if (json === "string") {
|
|
12730
|
+
add(path, label, "text", path);
|
|
12731
|
+
continue;
|
|
12732
|
+
}
|
|
12733
|
+
if (json === "number" || json === "boolean") {
|
|
12734
|
+
add(path, label, json, path);
|
|
12735
|
+
continue;
|
|
12736
|
+
}
|
|
12737
|
+
json === "object" && depth < maxDepth && field.type?.fields?.length && visit(field.type.fields, path, label, depth + 1);
|
|
12738
|
+
}
|
|
12739
|
+
};
|
|
12740
|
+
return type?.fields?.length && visit(type.fields, "", "", 0), [...found.values()];
|
|
12741
|
+
}
|
|
12742
|
+
/** Nom du champ titre d'une collection, pour la colonne mise en avant. */
|
|
12743
|
+
function titleColumn(columns) {
|
|
12744
|
+
return columns.find((c) => c.key === "title") ?? columns.find((c) => c.kind === "text");
|
|
12745
|
+
}
|
|
12746
|
+
/**
|
|
12747
|
+
* Requête d'une collection : `_id`, `_updatedAt`, et une projection par colonne
|
|
12748
|
+
* **visible** (clé préfixée `ncfData_` pour ne jamais heurter un champ du
|
|
12749
|
+
* client). Les expressions des colonnes sont construites par le kit à partir de
|
|
12750
|
+
* chemins déjà validés (`deriveCollectionColumns`), donc sûres ; la clé est
|
|
12751
|
+
* revérifiée par prudence avant interpolation.
|
|
12752
|
+
*
|
|
12753
|
+
* Le type passe en paramètre (`$type`), jamais interpolé dans la requête.
|
|
12754
|
+
*
|
|
12755
|
+
* On ne filtre pas les brouillons : le client (perspective `raw`) renvoie
|
|
12756
|
+
* `drafts.x` ET `x`, que `buildCollectionRows` fusionne par id de base — sans
|
|
12757
|
+
* quoi un item jamais publié n'apparaîtrait pas.
|
|
12758
|
+
*/
|
|
12759
|
+
function buildCollectionQuery(columns) {
|
|
12760
|
+
return [
|
|
12761
|
+
"*[_type == $type]{",
|
|
12762
|
+
" _id, _updatedAt,",
|
|
12763
|
+
...columns.filter((column) => isSafeColumnKey(column.key)).map((column) => ` "${DATA_PREFIX}${column.key}": ${column.projection},`),
|
|
12764
|
+
"}"
|
|
12765
|
+
].join("\n");
|
|
12766
|
+
}
|
|
12767
|
+
const baseId$1 = (id) => id.startsWith("drafts.") ? id.slice(7) : id, isDraft = (id) => id.startsWith("drafts."), dateFormatter = new Intl.DateTimeFormat("en-US", {
|
|
12768
|
+
day: "2-digit",
|
|
12769
|
+
month: "2-digit",
|
|
12770
|
+
year: "numeric"
|
|
12771
|
+
});
|
|
12772
|
+
function formatDate(value) {
|
|
12773
|
+
if (typeof value != "string" || !value) return "";
|
|
12774
|
+
let date = new Date(value);
|
|
12775
|
+
return Number.isNaN(date.getTime()) ? "" : dateFormatter.format(date);
|
|
12776
|
+
}
|
|
12777
|
+
function cellOf(raw, kind) {
|
|
12778
|
+
if (raw == null) return {
|
|
12779
|
+
raw: null,
|
|
12780
|
+
text: ""
|
|
12781
|
+
};
|
|
12782
|
+
if (kind === "boolean") {
|
|
12783
|
+
let value = !!raw;
|
|
12784
|
+
return {
|
|
12785
|
+
raw: value,
|
|
12786
|
+
text: value ? "Yes" : "No"
|
|
12787
|
+
};
|
|
12788
|
+
}
|
|
12789
|
+
if (kind === "number") return typeof raw == "number" ? {
|
|
12790
|
+
raw,
|
|
12791
|
+
text: String(raw)
|
|
12792
|
+
} : {
|
|
12793
|
+
raw: null,
|
|
12794
|
+
text: ""
|
|
12795
|
+
};
|
|
12796
|
+
if (kind === "date") return {
|
|
12797
|
+
raw: typeof raw == "string" ? raw : null,
|
|
12798
|
+
text: formatDate(raw)
|
|
12799
|
+
};
|
|
12800
|
+
let text = typeof raw == "string" ? raw.trim() : String(raw);
|
|
12801
|
+
return {
|
|
12802
|
+
raw: text,
|
|
12803
|
+
text
|
|
12804
|
+
};
|
|
12805
|
+
}
|
|
12806
|
+
/**
|
|
12807
|
+
* Documents → lignes, une par item. Le client (perspective `raw`) renvoie le
|
|
12808
|
+
* brouillon ET la version publiée : on les fusionne par id de base, en gardant
|
|
12809
|
+
* le brouillon s'il existe (valeurs les plus fraîches).
|
|
12810
|
+
*/
|
|
12811
|
+
function buildCollectionRows(docs, columns) {
|
|
12812
|
+
let byId = /* @__PURE__ */ new Map();
|
|
12813
|
+
for (let doc of docs) {
|
|
12814
|
+
if (!doc?._id) continue;
|
|
12815
|
+
let entry = byId.get(baseId$1(doc._id)) ?? {};
|
|
12816
|
+
isDraft(doc._id) ? entry.draft = doc : entry.published = doc, byId.set(baseId$1(doc._id), entry);
|
|
12817
|
+
}
|
|
12818
|
+
let rows = [];
|
|
12819
|
+
for (let [id, { draft, published }] of byId) {
|
|
12820
|
+
let source = draft ?? published;
|
|
12821
|
+
if (!source) continue;
|
|
12822
|
+
let cells = {};
|
|
12823
|
+
for (let column of columns) cells[column.key] = cellOf(source[`${DATA_PREFIX}${column.key}`], column.kind);
|
|
12824
|
+
rows.push({
|
|
12825
|
+
id,
|
|
12826
|
+
updatedAt: source._updatedAt ?? null,
|
|
12827
|
+
draftOnly: !!draft && !published,
|
|
12828
|
+
cells
|
|
12829
|
+
});
|
|
12830
|
+
}
|
|
12831
|
+
return rows;
|
|
12832
|
+
}
|
|
12833
|
+
/**
|
|
12834
|
+
* Données d'une collection pour la vue table : colonnes tirées du schéma,
|
|
12835
|
+
* lignes en direct. Seules les colonnes visibles sont projetées (comme
|
|
12836
|
+
* `usePages`), pour ne pas tirer tout le schéma sur chaque document.
|
|
12837
|
+
*/
|
|
12838
|
+
function useCollection(type, visibleKeys) {
|
|
12839
|
+
let schema = useSchema(), allColumns = useMemo(() => deriveCollectionColumns(schema.get(type)), [schema, type]), visibleColumns = useMemo(() => visibleKeys.map((key) => allColumns.find((c) => c.key === key)).filter((c) => !!c), [allColumns, visibleKeys]), { data, loading, error, refresh } = useQueryData(useMemo(() => buildCollectionQuery(visibleColumns), [visibleColumns]), useMemo(() => ({ type }), [type]), { listenTypes: [type] });
|
|
12840
|
+
return {
|
|
12841
|
+
allColumns,
|
|
12842
|
+
visibleColumns,
|
|
12843
|
+
rows: useMemo(() => buildCollectionRows(data ?? [], visibleColumns), [data, visibleColumns]),
|
|
12844
|
+
loading,
|
|
12845
|
+
error,
|
|
12846
|
+
refresh
|
|
12847
|
+
};
|
|
12848
|
+
}
|
|
12849
|
+
/** Insensible à la casse et aux accents, comme la recherche de l'onglet Pages. */
|
|
12850
|
+
const normalize = (value) => value.toLocaleLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
|
12851
|
+
/** Compare deux valeurs non vides selon le type de la colonne. */
|
|
12852
|
+
function compareNonNull(ra, rb, kind) {
|
|
12853
|
+
return kind === "number" || kind === "boolean" ? Number(ra) - Number(rb) : kind === "date" ? String(ra).localeCompare(String(rb)) : String(ra).localeCompare(String(rb), void 0, { sensitivity: "base" });
|
|
12854
|
+
}
|
|
12855
|
+
function sortRows(rows, sort, columns) {
|
|
12856
|
+
if (!sort.key) return [...rows];
|
|
12857
|
+
let column = columns.find((c) => c.key === sort.key);
|
|
12858
|
+
if (!column) return [...rows];
|
|
12859
|
+
let dir = sort.direction === "asc" ? 1 : -1;
|
|
12860
|
+
return [...rows].sort((a, b) => {
|
|
12861
|
+
let ra = a.cells[column.key]?.raw ?? null, rb = b.cells[column.key]?.raw ?? null;
|
|
12862
|
+
return ra === null && rb === null ? 0 : ra === null ? 1 : rb === null ? -1 : dir * compareNonNull(ra, rb, column.kind);
|
|
12863
|
+
});
|
|
12864
|
+
}
|
|
12865
|
+
function filterRows(rows, filters, visibleColumns) {
|
|
12866
|
+
let search = filters.search?.trim() ? normalize(filters.search.trim()) : null, columnNeedles = Object.entries(filters.columns ?? {}).map(([key, value]) => [key, normalize(value.trim())]).filter(([, value]) => value.length > 0);
|
|
12867
|
+
return !search && columnNeedles.length === 0 ? [...rows] : rows.filter((row) => {
|
|
12868
|
+
if (search && !visibleColumns.map((c) => normalize(row.cells[c.key]?.text ?? "")).join(" ").includes(search)) return !1;
|
|
12869
|
+
for (let [key, needle] of columnNeedles) if (!normalize(row.cells[key]?.text ?? "").includes(needle)) return !1;
|
|
12870
|
+
return !0;
|
|
12871
|
+
});
|
|
12872
|
+
}
|
|
12873
|
+
/** Échappement RFC 4180 : guillemets doublés, champ cité s'il contient `,` `"` ou un saut de ligne. */
|
|
12874
|
+
function escapeField(value) {
|
|
12875
|
+
return /[",\n\r]/.test(value) ? `"${value.replace(/"/g, "\"\"")}"` : value;
|
|
12876
|
+
}
|
|
12877
|
+
/**
|
|
12878
|
+
* Lignes → CSV. En-têtes = libellés des colonnes visibles, cellules = le texte
|
|
12879
|
+
* déjà mis en forme (`row.cells[key].text`). Lignes séparées par CRLF, comme
|
|
12880
|
+
* l'attendent les tableurs. Pur : l'appelant ajoute l'éventuel BOM au moment du
|
|
12881
|
+
* téléchargement.
|
|
12882
|
+
*/
|
|
12883
|
+
function toCsv(rows, columns) {
|
|
12884
|
+
let header = columns.map((column) => escapeField(column.label)), body = rows.map((row) => columns.map((column) => escapeField(row.cells[column.key]?.text ?? "")).join(","));
|
|
12885
|
+
return [header.join(","), ...body].join("\r\n");
|
|
12886
|
+
}
|
|
12887
|
+
/**
|
|
12888
|
+
* Propose un fichier texte au téléchargement depuis le navigateur. Déclenché
|
|
12889
|
+
* par un clic de l'utilisateur (bouton « Exporter »), jamais tout seul.
|
|
12890
|
+
*
|
|
12891
|
+
* Un BOM UTF-8 est ajouté par défaut pour que les accents s'affichent dans
|
|
12892
|
+
* Excel. No-op hors navigateur (rendu serveur, tests).
|
|
12893
|
+
*/
|
|
12894
|
+
function downloadText(filename, text, mime = "text/csv;charset=utf-8", withBom = !0) {
|
|
12895
|
+
if (typeof window > "u" || typeof document > "u") return;
|
|
12896
|
+
let blob = new Blob([withBom ? `${text}` : text], { type: mime }), url = URL.createObjectURL(blob), anchor = document.createElement("a");
|
|
12897
|
+
anchor.href = url, anchor.download = filename, document.body.appendChild(anchor), anchor.click(), anchor.remove(), URL.revokeObjectURL(url);
|
|
12898
|
+
}
|
|
12899
|
+
/** Choix des colonnes affichées, sans quitter la table (façon tableur). */
|
|
12900
|
+
function CollectionColumnPicker(props) {
|
|
12901
|
+
let { columns, visible, onToggle } = props, visibleSet = useMemo(() => new Set(visible), [visible]);
|
|
12902
|
+
return /* @__PURE__ */ jsx(InlinePopover, {
|
|
12903
|
+
width: 264,
|
|
12904
|
+
trigger: ({ toggle }) => /* @__PURE__ */ jsx(Button, {
|
|
12905
|
+
mode: "bleed",
|
|
12906
|
+
fontSize: 1,
|
|
12907
|
+
padding: 2,
|
|
12908
|
+
icon: ControlsIcon,
|
|
12909
|
+
text: `Columns · ${visible.length}`,
|
|
12910
|
+
onClick: toggle
|
|
12911
|
+
}),
|
|
12912
|
+
children: () => /* @__PURE__ */ jsx(ColumnList, {
|
|
12913
|
+
columns,
|
|
12914
|
+
visibleSet,
|
|
12915
|
+
onToggle
|
|
12916
|
+
})
|
|
12917
|
+
});
|
|
12918
|
+
}
|
|
12919
|
+
function Row(props) {
|
|
12920
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
12921
|
+
align: "center",
|
|
12922
|
+
gap: 2,
|
|
12923
|
+
padding: 2,
|
|
12924
|
+
onClick: props.onClick,
|
|
12925
|
+
style: {
|
|
12926
|
+
cursor: "pointer",
|
|
12927
|
+
borderRadius: 3
|
|
12928
|
+
},
|
|
12929
|
+
onMouseEnter: (event) => {
|
|
12930
|
+
event.currentTarget.style.background = "var(--card-muted-bg-color, rgba(127,127,127,0.12))";
|
|
12931
|
+
},
|
|
12932
|
+
onMouseLeave: (event) => {
|
|
12933
|
+
event.currentTarget.style.background = "transparent";
|
|
12934
|
+
},
|
|
12935
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
12936
|
+
style: {
|
|
12937
|
+
width: 14,
|
|
12938
|
+
flex: "none"
|
|
12939
|
+
},
|
|
12940
|
+
children: props.checked && /* @__PURE__ */ jsx(CheckmarkIcon, { style: {
|
|
12941
|
+
fontSize: 14,
|
|
12942
|
+
opacity: .7
|
|
12943
|
+
} })
|
|
12944
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
12945
|
+
size: 1,
|
|
12946
|
+
muted: !props.checked,
|
|
12947
|
+
textOverflow: "ellipsis",
|
|
12948
|
+
children: props.label
|
|
12949
|
+
})]
|
|
12950
|
+
});
|
|
12951
|
+
}
|
|
12952
|
+
/** Au-delà d'une poignée de champs, un filtre apparaît pour en chercher un. */
|
|
12953
|
+
function ColumnList(props) {
|
|
12954
|
+
let { columns, visibleSet, onToggle } = props, [filter, setFilter] = useState(""), matches = useMemo(() => {
|
|
12955
|
+
let needle = filter.trim().toLowerCase();
|
|
12956
|
+
return needle ? columns.filter((column) => column.label.toLowerCase().includes(needle)) : columns;
|
|
12957
|
+
}, [columns, filter]);
|
|
12958
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
12959
|
+
gap: 0,
|
|
12960
|
+
children: [
|
|
12961
|
+
columns.length > 8 && /* @__PURE__ */ jsx(Box, {
|
|
12962
|
+
paddingX: 1,
|
|
12963
|
+
paddingBottom: 1,
|
|
12964
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
12965
|
+
type: "text",
|
|
12966
|
+
value: filter,
|
|
12967
|
+
placeholder: "Filter…",
|
|
12968
|
+
onChange: (event) => setFilter(event.currentTarget.value),
|
|
12969
|
+
style: {
|
|
12970
|
+
width: "100%",
|
|
12971
|
+
font: "inherit",
|
|
12972
|
+
fontSize: 12,
|
|
12973
|
+
padding: "6px",
|
|
12974
|
+
borderRadius: 3,
|
|
12975
|
+
border: "1px solid var(--card-border-color, rgba(127,127,127,0.22))",
|
|
12976
|
+
background: "var(--card-bg-color)",
|
|
12977
|
+
color: "var(--card-fg-color)",
|
|
12978
|
+
outline: "none"
|
|
12979
|
+
}
|
|
12980
|
+
})
|
|
12981
|
+
}),
|
|
12982
|
+
matches.map((column) => /* @__PURE__ */ jsx(Row, {
|
|
12983
|
+
label: column.label,
|
|
12984
|
+
checked: visibleSet.has(column.key),
|
|
12985
|
+
onClick: () => onToggle(column.key)
|
|
12986
|
+
}, column.key)),
|
|
12987
|
+
matches.length === 0 && /* @__PURE__ */ jsx(Box, {
|
|
12988
|
+
padding: 2,
|
|
12989
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
12990
|
+
size: 0,
|
|
12991
|
+
muted: !0,
|
|
12992
|
+
children: "No matching fields."
|
|
12993
|
+
})
|
|
12994
|
+
})
|
|
12995
|
+
]
|
|
12996
|
+
});
|
|
12997
|
+
}
|
|
12998
|
+
/** Barre au-dessus de la table : recherche, colonnes, export CSV. */
|
|
12999
|
+
function CollectionToolbar(props) {
|
|
13000
|
+
let { search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary } = props;
|
|
13001
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
13002
|
+
align: "center",
|
|
13003
|
+
gap: 2,
|
|
13004
|
+
wrap: "wrap",
|
|
13005
|
+
children: [
|
|
13006
|
+
/* @__PURE__ */ jsx(Box, {
|
|
13007
|
+
style: {
|
|
13008
|
+
flex: 1,
|
|
13009
|
+
minWidth: 180
|
|
13010
|
+
},
|
|
13011
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
13012
|
+
icon: SearchIcon,
|
|
13013
|
+
fontSize: 1,
|
|
13014
|
+
padding: 2,
|
|
13015
|
+
radius: 2,
|
|
13016
|
+
placeholder: "Search",
|
|
13017
|
+
value: search,
|
|
13018
|
+
onChange: (event) => onSearch(event.currentTarget.value),
|
|
13019
|
+
clearButton: !!search,
|
|
13020
|
+
onClear: () => onSearch("")
|
|
13021
|
+
})
|
|
13022
|
+
}),
|
|
13023
|
+
/* @__PURE__ */ jsx(Text, {
|
|
13024
|
+
size: 1,
|
|
13025
|
+
muted: !0,
|
|
13026
|
+
style: { flex: "none" },
|
|
13027
|
+
children: summary
|
|
13028
|
+
}),
|
|
13029
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
13030
|
+
gap: 1,
|
|
13031
|
+
style: { flex: "none" },
|
|
13032
|
+
children: [
|
|
13033
|
+
/* @__PURE__ */ jsx(CollectionColumnPicker, {
|
|
13034
|
+
columns,
|
|
13035
|
+
visible,
|
|
13036
|
+
onToggle: onToggleColumn
|
|
13037
|
+
}),
|
|
13038
|
+
/* @__PURE__ */ jsx(Button, {
|
|
13039
|
+
mode: "bleed",
|
|
13040
|
+
fontSize: 1,
|
|
13041
|
+
padding: 2,
|
|
13042
|
+
icon: DownloadIcon,
|
|
13043
|
+
text: "Export CSV",
|
|
13044
|
+
onClick: onExport
|
|
13045
|
+
}),
|
|
13046
|
+
/* @__PURE__ */ jsx(Button, {
|
|
13047
|
+
mode: "bleed",
|
|
13048
|
+
fontSize: 1,
|
|
13049
|
+
padding: 2,
|
|
13050
|
+
icon: RefreshIcon,
|
|
13051
|
+
title: "Refresh",
|
|
13052
|
+
"aria-label": "Refresh",
|
|
13053
|
+
onClick: onRefresh,
|
|
13054
|
+
disabled: busy
|
|
13055
|
+
})
|
|
13056
|
+
]
|
|
13057
|
+
})
|
|
13058
|
+
]
|
|
13059
|
+
});
|
|
13060
|
+
}
|
|
13061
|
+
function defaultVisible(columns) {
|
|
13062
|
+
let title = columns.find((c) => c.key === "title") ?? columns.find((c) => c.kind === "text");
|
|
13063
|
+
return (title ? [title, ...columns.filter((c) => c !== title)] : [...columns]).slice(0, 6).map((c) => c.key);
|
|
13064
|
+
}
|
|
13065
|
+
function CollectionTable({ type }) {
|
|
13066
|
+
let router = useRouter(), [selected, setSelected] = useState(null), [sort, setSort] = useState({
|
|
13067
|
+
key: null,
|
|
13068
|
+
direction: "asc"
|
|
13069
|
+
}), [search, setSearch] = useState(""), [columnFilters, setColumnFilters] = useState({}), schema = useSchema(), allColumns = useMemo(() => deriveCollectionColumns(schema.get(type)), [schema, type]), visibleKeys = useMemo(() => selected ?? defaultVisible(allColumns), [selected, allColumns]), { visibleColumns, rows, loading, error, refresh } = useCollection(type, visibleKeys), visible = useMemo(() => sortRows(filterRows(rows, {
|
|
13070
|
+
search,
|
|
13071
|
+
columns: columnFilters
|
|
13072
|
+
}, visibleColumns), sort, visibleColumns), [
|
|
13073
|
+
rows,
|
|
13074
|
+
search,
|
|
13075
|
+
columnFilters,
|
|
13076
|
+
visibleColumns,
|
|
13077
|
+
sort
|
|
13078
|
+
]), onToggleColumn = useCallback((key) => {
|
|
13079
|
+
setSelected((current) => {
|
|
13080
|
+
let base = current ?? defaultVisible(allColumns);
|
|
13081
|
+
return base.includes(key) ? base.filter((k) => k !== key) : [...base, key];
|
|
13082
|
+
}), setColumnFilters((current) => {
|
|
13083
|
+
if (!current[key]) return current;
|
|
13084
|
+
let { [key]: _removed, ...rest } = current;
|
|
13085
|
+
return rest;
|
|
13086
|
+
});
|
|
13087
|
+
}, [allColumns]), onSort = useCallback((key) => {
|
|
13088
|
+
setSort((current) => current.key === key ? {
|
|
13089
|
+
key,
|
|
13090
|
+
direction: current.direction === "asc" ? "desc" : "asc"
|
|
13091
|
+
} : {
|
|
13092
|
+
key,
|
|
13093
|
+
direction: "asc"
|
|
13094
|
+
});
|
|
13095
|
+
}, []), onExport = useCallback(() => {
|
|
13096
|
+
downloadText(`${type}.csv`, toCsv(visible, visibleColumns));
|
|
13097
|
+
}, [
|
|
13098
|
+
type,
|
|
13099
|
+
visible,
|
|
13100
|
+
visibleColumns
|
|
13101
|
+
]), onColumnFilter = useCallback((key, value) => {
|
|
13102
|
+
setColumnFilters((current) => ({
|
|
13103
|
+
...current,
|
|
13104
|
+
[key]: value
|
|
13105
|
+
}));
|
|
13106
|
+
}, []);
|
|
13107
|
+
if (error) return /* @__PURE__ */ jsx(QueryError, {
|
|
13108
|
+
error,
|
|
13109
|
+
onRetry: refresh
|
|
13110
|
+
});
|
|
13111
|
+
let summary = visible.length === rows.length ? `${rows.length} item${rows.length > 1 ? "s" : ""}` : `${visible.length} of ${rows.length}`, grid = {
|
|
13112
|
+
display: "grid",
|
|
13113
|
+
gridTemplateColumns: visibleColumns.map((_, index) => index === 0 ? "minmax(200px, 1.6fr)" : "minmax(150px, 1fr)").join(" "),
|
|
13114
|
+
gap: "0.875rem",
|
|
13115
|
+
alignItems: "center"
|
|
13116
|
+
};
|
|
13117
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
13118
|
+
gap: 4,
|
|
13119
|
+
children: [/* @__PURE__ */ jsx(CollectionToolbar, {
|
|
13120
|
+
search,
|
|
13121
|
+
onSearch: setSearch,
|
|
13122
|
+
columns: allColumns,
|
|
13123
|
+
visible: visibleKeys,
|
|
13124
|
+
onToggleColumn,
|
|
13125
|
+
onExport,
|
|
13126
|
+
onRefresh: refresh,
|
|
13127
|
+
busy: loading,
|
|
13128
|
+
summary
|
|
13129
|
+
}), loading && rows.length === 0 ? /* @__PURE__ */ jsxs(Flex, {
|
|
13130
|
+
align: "center",
|
|
13131
|
+
justify: "center",
|
|
13132
|
+
padding: 6,
|
|
13133
|
+
gap: 3,
|
|
13134
|
+
children: [/* @__PURE__ */ jsx(Spinner, { muted: !0 }), /* @__PURE__ */ jsx(Text, {
|
|
13135
|
+
size: 1,
|
|
13136
|
+
muted: !0,
|
|
13137
|
+
children: "Loading…"
|
|
13138
|
+
})]
|
|
13139
|
+
}) : visibleColumns.length === 0 ? /* @__PURE__ */ jsx(Box, {
|
|
13140
|
+
padding: 5,
|
|
13141
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
13142
|
+
size: 1,
|
|
13143
|
+
muted: !0,
|
|
13144
|
+
align: "center",
|
|
13145
|
+
children: "No displayable field in this type. Pick columns above."
|
|
13146
|
+
})
|
|
13147
|
+
}) : /* @__PURE__ */ jsx(Box, {
|
|
13148
|
+
style: {
|
|
13149
|
+
overflowX: "auto",
|
|
13150
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
13151
|
+
borderRadius: 6
|
|
13152
|
+
},
|
|
13153
|
+
children: /* @__PURE__ */ jsxs(Box, {
|
|
13154
|
+
style: { minWidth: "min-content" },
|
|
13155
|
+
children: [
|
|
13156
|
+
/* @__PURE__ */ jsx(Box, {
|
|
13157
|
+
paddingX: 3,
|
|
13158
|
+
paddingY: 2,
|
|
13159
|
+
style: {
|
|
13160
|
+
...grid,
|
|
13161
|
+
alignItems: "end",
|
|
13162
|
+
borderBottom: `1px solid ${BORDER}`,
|
|
13163
|
+
position: "sticky",
|
|
13164
|
+
top: 0,
|
|
13165
|
+
background: "var(--card-bg-color, inherit)",
|
|
13166
|
+
zIndex: 2
|
|
13167
|
+
},
|
|
13168
|
+
children: visibleColumns.map((column) => {
|
|
13169
|
+
let active = sort.key === column.key, Arrow = sort.direction === "asc" ? ChevronUpIcon : ChevronDownIcon;
|
|
13170
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
13171
|
+
gap: 2,
|
|
13172
|
+
style: CELL,
|
|
13173
|
+
children: [/* @__PURE__ */ jsxs(Flex, {
|
|
13174
|
+
align: "center",
|
|
13175
|
+
gap: 1,
|
|
13176
|
+
onClick: () => onSort(column.key),
|
|
13177
|
+
style: {
|
|
13178
|
+
cursor: "pointer",
|
|
13179
|
+
userSelect: "none"
|
|
13180
|
+
},
|
|
13181
|
+
title: `Sort by ${column.label.toLowerCase()}`,
|
|
13182
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
13183
|
+
size: 0,
|
|
13184
|
+
weight: "medium",
|
|
13185
|
+
muted: !active,
|
|
13186
|
+
textOverflow: "ellipsis",
|
|
13187
|
+
children: column.label
|
|
13188
|
+
}), active && /* @__PURE__ */ jsx(Arrow, { style: {
|
|
13189
|
+
fontSize: 13,
|
|
13190
|
+
opacity: .7,
|
|
13191
|
+
flex: "none"
|
|
13192
|
+
} })]
|
|
13193
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
13194
|
+
type: "text",
|
|
13195
|
+
value: columnFilters[column.key] ?? "",
|
|
13196
|
+
placeholder: "Filter…",
|
|
13197
|
+
onChange: (event) => onColumnFilter(column.key, event.currentTarget.value),
|
|
13198
|
+
style: {
|
|
13199
|
+
width: "100%",
|
|
13200
|
+
font: "inherit",
|
|
13201
|
+
fontSize: 11,
|
|
13202
|
+
padding: "3px 6px",
|
|
13203
|
+
borderRadius: 3,
|
|
13204
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
13205
|
+
background: "var(--card-bg-color)",
|
|
13206
|
+
color: "var(--card-fg-color)",
|
|
13207
|
+
outline: "none"
|
|
13208
|
+
}
|
|
13209
|
+
})]
|
|
13210
|
+
}, column.key);
|
|
13211
|
+
})
|
|
13212
|
+
}),
|
|
13213
|
+
visible.map((row) => /* @__PURE__ */ jsx(CollectionRowView, {
|
|
13214
|
+
row,
|
|
13215
|
+
columns: visibleColumns,
|
|
13216
|
+
grid,
|
|
13217
|
+
onOpen: () => router.navigateIntent("edit", {
|
|
13218
|
+
id: row.id,
|
|
13219
|
+
type
|
|
13220
|
+
})
|
|
13221
|
+
}, row.id)),
|
|
13222
|
+
visible.length === 0 && /* @__PURE__ */ jsx(Box, {
|
|
13223
|
+
padding: 5,
|
|
13224
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
13225
|
+
size: 1,
|
|
13226
|
+
muted: !0,
|
|
13227
|
+
align: "center",
|
|
13228
|
+
children: rows.length === 0 ? "No item yet." : "No match."
|
|
13229
|
+
})
|
|
13230
|
+
})
|
|
13231
|
+
]
|
|
13232
|
+
})
|
|
13233
|
+
})]
|
|
13234
|
+
});
|
|
13235
|
+
}
|
|
13236
|
+
function CollectionRowView(props) {
|
|
13237
|
+
let { row, columns, grid, onOpen } = props, [hovered, setHovered] = useState(!1);
|
|
13238
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
13239
|
+
paddingX: 3,
|
|
13240
|
+
paddingY: 2,
|
|
13241
|
+
onClick: onOpen,
|
|
13242
|
+
onMouseEnter: () => setHovered(!0),
|
|
13243
|
+
onMouseLeave: () => setHovered(!1),
|
|
13244
|
+
style: {
|
|
13245
|
+
...grid,
|
|
13246
|
+
cursor: "pointer",
|
|
13247
|
+
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
13248
|
+
background: hovered ? "var(--card-muted-bg-color, rgba(127,127,127,0.08))" : "transparent"
|
|
13249
|
+
},
|
|
13250
|
+
children: columns.map((column, index) => {
|
|
13251
|
+
let cell = row.cells[column.key], empty = !cell || cell.raw === null || cell.text === "";
|
|
13252
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
13253
|
+
align: "center",
|
|
13254
|
+
gap: 2,
|
|
13255
|
+
style: CELL,
|
|
13256
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
13257
|
+
size: 1,
|
|
13258
|
+
muted: empty,
|
|
13259
|
+
weight: index === 0 ? "medium" : "regular",
|
|
13260
|
+
textOverflow: "ellipsis",
|
|
13261
|
+
style: {
|
|
13262
|
+
flex: 1,
|
|
13263
|
+
minWidth: 0,
|
|
13264
|
+
...column.kind === "number" || column.kind === "date" ? TABULAR : null
|
|
13265
|
+
},
|
|
13266
|
+
children: empty ? "—" : cell.text
|
|
13267
|
+
}), index === 0 && row.draftOnly && /* @__PURE__ */ jsx(Badge, {
|
|
13268
|
+
tone: "caution",
|
|
13269
|
+
fontSize: 0,
|
|
13270
|
+
style: { flex: "none" },
|
|
13271
|
+
children: "Draft"
|
|
13272
|
+
})]
|
|
13273
|
+
}, column.key);
|
|
13274
|
+
})
|
|
13275
|
+
});
|
|
13276
|
+
}
|
|
13277
|
+
const isReserved = (name) => name.startsWith("sanity.") || name.startsWith("_");
|
|
13278
|
+
/**
|
|
13279
|
+
* Types de collection retenus.
|
|
13280
|
+
*
|
|
13281
|
+
* - `include` fournie → on respecte cette liste (dans son ordre), en gardant
|
|
13282
|
+
* seulement ce qui est un type de document connu et hors `exclude`.
|
|
13283
|
+
* - sinon → tous les types de documents, moins `exclude` et les types réservés,
|
|
13284
|
+
* triés par nom pour une liste stable.
|
|
13285
|
+
*/
|
|
13286
|
+
function discoverCollectionTypes(types, options = {}) {
|
|
13287
|
+
let excluded = new Set(options.exclude ?? []), documents = new Set(types.filter((t) => t.jsonType === "document").map((t) => t.name));
|
|
13288
|
+
if (options.include?.length) {
|
|
13289
|
+
let seen = /* @__PURE__ */ new Set();
|
|
13290
|
+
return options.include.filter((name) => seen.has(name) || excluded.has(name) || !documents.has(name) ? !1 : (seen.add(name), !0));
|
|
13291
|
+
}
|
|
13292
|
+
return [...documents].filter((name) => !excluded.has(name) && !isReserved(name)).sort((a, b) => a.localeCompare(b));
|
|
13293
|
+
}
|
|
13294
|
+
/**
|
|
13295
|
+
* Composant de panneau pour une collection. Le type arrive par les `options`
|
|
13296
|
+
* du pane de structure ; la configuration est fermée par la fabrique (elle
|
|
13297
|
+
* n'est pas sérialisable dans les options).
|
|
13298
|
+
*/
|
|
13299
|
+
function createCollectionPane(config, issues) {
|
|
13300
|
+
return function NcfCollectionPane(props) {
|
|
13301
|
+
let type = typeof props.options?.type == "string" ? props.options.type : "";
|
|
13302
|
+
return /* @__PURE__ */ jsx(KitProvider, {
|
|
13303
|
+
config,
|
|
13304
|
+
issues,
|
|
13305
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
13306
|
+
padding: 3,
|
|
13307
|
+
height: "fill",
|
|
13308
|
+
overflow: "auto",
|
|
13309
|
+
children: type ? /* @__PURE__ */ jsx(CollectionTable, { type }) : null
|
|
13310
|
+
})
|
|
13311
|
+
});
|
|
13312
|
+
};
|
|
13313
|
+
}
|
|
13314
|
+
/**
|
|
13315
|
+
* Vue table d'UNE collection, à utiliser comme enfant d'une entrée de structure
|
|
13316
|
+
* pour que cliquer la collection ouvre la table (au lieu de la liste native) :
|
|
13317
|
+
*
|
|
13318
|
+
* ```ts
|
|
13319
|
+
* S.listItem().title('Articles').child(ncfCollectionTable(S, ncfOptions, 'article'))
|
|
13320
|
+
* ```
|
|
13321
|
+
*/
|
|
13322
|
+
function ncfCollectionTable(S, options, type, opts = {}) {
|
|
13323
|
+
let config = resolveConfig(options), pane = createCollectionPane(config, validateConfig(config));
|
|
13324
|
+
return S.component(pane).id(`ncf-collection-${type}`).title(opts.title ?? type).options({ type });
|
|
13325
|
+
}
|
|
13326
|
+
/** Libellé d'une entrée de collection : config, puis titre du schéma, puis nom humanisé. */
|
|
13327
|
+
function labelFor(type, config, schemaTitle) {
|
|
13328
|
+
return config.collections.labels[type] ?? schemaTitle ?? humanise(type);
|
|
13329
|
+
}
|
|
13330
|
+
/** Types toujours écartés de la découverte, en plus de l'`exclude` du projet. */
|
|
13331
|
+
function reservedExcludes(config) {
|
|
13332
|
+
return [
|
|
13333
|
+
...config.pageTypeNames,
|
|
13334
|
+
config.redirectType,
|
|
13335
|
+
config.componentPreview.defaultsType,
|
|
13336
|
+
...NCF_HIDDEN_TYPES,
|
|
13337
|
+
...config.collections.exclude
|
|
13338
|
+
].filter(Boolean);
|
|
13339
|
+
}
|
|
13340
|
+
/**
|
|
13341
|
+
* Entrées « collection » pour la structure du Studio, une par type découvert,
|
|
13342
|
+
* chacune ouvrant la vue table. À épandre dans la liste racine :
|
|
13343
|
+
*
|
|
13344
|
+
* ```ts
|
|
13345
|
+
* structure: (S, context) =>
|
|
13346
|
+
* S.list().title('Contenu').items([..., ...ncfCollections(S, context, ncfOptions)])
|
|
13347
|
+
* ```
|
|
13348
|
+
*/
|
|
13349
|
+
function ncfCollections(S, context, options) {
|
|
13350
|
+
let config = resolveConfig(options);
|
|
13351
|
+
return discoverCollectionTypes(context.schema.getTypeNames().map((name) => ({
|
|
13352
|
+
name,
|
|
13353
|
+
jsonType: context.schema.get(name)?.jsonType
|
|
13354
|
+
})), {
|
|
13355
|
+
include: config.collections.include,
|
|
13356
|
+
exclude: reservedExcludes(config)
|
|
13357
|
+
}).map((type) => {
|
|
13358
|
+
let schemaType = context.schema.get(type), label = labelFor(type, config, schemaType?.title), item = S.listItem().id(`ncf-collection-${type}`).title(label).child(ncfCollectionTable(S, options, type, { title: label }));
|
|
13359
|
+
return schemaType?.icon ? item.icon(schemaType.icon) : item;
|
|
13360
|
+
});
|
|
13361
|
+
}
|
|
12673
13362
|
const SAFE = /^[A-Za-z0-9_.-]+$/, quote = (value) => JSON.stringify(value);
|
|
12674
13363
|
/**
|
|
12675
13364
|
* Presentation : le document du panneau de droite est TOUJOURS celui de la page
|
|
@@ -12868,6 +13557,6 @@ function hasLanguageField(schemaType, field) {
|
|
|
12868
13557
|
let fields = schemaType?.fields;
|
|
12869
13558
|
return Array.isArray(fields) && fields.some((f) => f?.name === field);
|
|
12870
13559
|
}
|
|
12871
|
-
export { ANNOTATION_TYPE, ActorName, AssetSourceBrowser, AssetsTool, 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, CodeEditorInput, CodeEmbedInput, 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, HelpTextStyle, KIT_API_VERSION, KIT_VERSION, NCF_ASSETS_TOOL, 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, assetName, assetsInFolder, assignmentMap, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, codeEditorInput, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, countByFolder, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineCodeEmbedType, defineComponentDefaults, depth, deriveDocumentColumns, detectPageBuilderField, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterAssets, filterRows, fixCrossLanguageReferences, flatten, formatBytes, formatDocumentValue, groupComponents, groupMap, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isImageAsset, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, nameMap, ncfAllowedOrigins, ncfKit, ncfMainDocuments, ncfPresentationComponents, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, resolvePageBuilderField, sectionNamesFromDefaults, segments, slugKey, sortAssets, sortRows, summarize, thumbnailUrl, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useAssetMeta, useAssetUpload, useAssets, useBoardLayout, useComponentNames, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, useOptionalKitConfig, useOptionalKitContext, usePageBuilder, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withCustomNames, withMoreTool, withSameLanguageReferences };
|
|
13560
|
+
export { ANNOTATION_TYPE, ActorName, AssetSourceBrowser, AssetsTool, 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, CodeEditorInput, CodeEmbedInput, CollectionTable, 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, HelpTextStyle, KIT_API_VERSION, KIT_VERSION, NCF_ASSETS_TOOL, 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, assetName, assetsInFolder, assignmentMap, baseId, blockName, blockTypesFromSchema, buildCollectionQuery, buildCollectionRows, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, codeEditorInput, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, countByFolder, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineCodeEmbedType, defineComponentDefaults, depth, deriveCollectionColumns, deriveDocumentColumns, detectPageBuilderField, diffDocuments, diffWords, discoverCollectionTypes, downloadText, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterAssets, filterRows as filterCollectionRows, filterRows$1 as filterRows, fixCrossLanguageReferences, flatten, formatBytes, formatDocumentValue, groupComponents, groupMap, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isImageAsset, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, nameMap, ncfAllowedOrigins, ncfCollectionTable, ncfCollections, ncfKit, ncfMainDocuments, ncfPresentationComponents, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, resolvePageBuilderField, sectionNamesFromDefaults, segments, slugKey, sortAssets, sortRows as sortCollectionRows, sortRows$1 as sortRows, summarize, thumbnailUrl, titleColumn, toCsv, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useAssetMeta, useAssetUpload, useAssets, useBoardLayout, useCollection, useComponentNames, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, useOptionalKitConfig, useOptionalKitContext, usePageBuilder, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withCustomNames, withMoreTool, withSameLanguageReferences };
|
|
12872
13561
|
|
|
12873
13562
|
//# sourceMappingURL=index.js.map
|