@nocode-factory/sanity-kit 2.54.0 → 2.56.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 +23 -5
- package/dist/index.d.ts +48 -4
- package/dist/index.js +287 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useCollection.ts +19 -3
- package/src/lib/collectionQuery.ts +10 -2
- package/src/structure/collections.tsx +35 -5
- package/src/tools/collections/CollectionTable.tsx +257 -78
- package/src/tools/collections/CollectionToolbar.tsx +53 -4
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -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 { usePaneRouter } from "sanity/structure";
|
|
57
58
|
import { DownloadIcon } from "@sanity/icons/Download";
|
|
58
59
|
const isAbsoluteHttpUrl = (value) => {
|
|
59
60
|
try {
|
|
@@ -1421,7 +1422,7 @@ function explainGrantError(error) {
|
|
|
1421
1422
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1422
1423
|
* le vérifie.
|
|
1423
1424
|
*/
|
|
1424
|
-
const KIT_VERSION = "2.
|
|
1425
|
+
const KIT_VERSION = "2.56.0";
|
|
1425
1426
|
/**
|
|
1426
1427
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1427
1428
|
*
|
|
@@ -1919,7 +1920,7 @@ function useKitUpdate() {
|
|
|
1919
1920
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1920
1921
|
}).catch(() => {}), () => controller.abort();
|
|
1921
1922
|
}, []);
|
|
1922
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1923
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.56.0") > 0);
|
|
1923
1924
|
return {
|
|
1924
1925
|
current: KIT_VERSION,
|
|
1925
1926
|
latest,
|
|
@@ -12752,15 +12753,22 @@ function titleColumn(columns) {
|
|
|
12752
12753
|
*
|
|
12753
12754
|
* Le type passe en paramètre (`$type`), jamais interpolé dans la requête.
|
|
12754
12755
|
*
|
|
12756
|
+
* `filter` est un prédicat GROQ supplémentaire écrit par l'intégrateur (dans le
|
|
12757
|
+
* résolveur de structure), par exemple `language == $lang` : il restreint la
|
|
12758
|
+
* table au niveau feuille (une langue, une catégorie, une page…). Il est
|
|
12759
|
+
* parenthésé puis combiné en `&&`, et ses valeurs passent par `params`, jamais
|
|
12760
|
+
* interpolées. Même niveau de confiance que `S.documentList().filter(...)`.
|
|
12761
|
+
*
|
|
12755
12762
|
* On ne filtre pas les brouillons : le client (perspective `raw`) renvoie
|
|
12756
12763
|
* `drafts.x` ET `x`, que `buildCollectionRows` fusionne par id de base — sans
|
|
12757
12764
|
* quoi un item jamais publié n'apparaîtrait pas.
|
|
12758
12765
|
*/
|
|
12759
|
-
function buildCollectionQuery(columns) {
|
|
12766
|
+
function buildCollectionQuery(columns, filter) {
|
|
12767
|
+
let lines = columns.filter((column) => isSafeColumnKey(column.key)).map((column) => ` "${DATA_PREFIX}${column.key}": ${column.projection},`);
|
|
12760
12768
|
return [
|
|
12761
|
-
|
|
12769
|
+
`*[${filter && filter.trim() ? `_type == $type && (${filter.trim()})` : "_type == $type"}]{`,
|
|
12762
12770
|
" _id, _updatedAt,",
|
|
12763
|
-
...
|
|
12771
|
+
...lines,
|
|
12764
12772
|
"}"
|
|
12765
12773
|
].join("\n");
|
|
12766
12774
|
}
|
|
@@ -12834,9 +12842,16 @@ function buildCollectionRows(docs, columns) {
|
|
|
12834
12842
|
* Données d'une collection pour la vue table : colonnes tirées du schéma,
|
|
12835
12843
|
* lignes en direct. Seules les colonnes visibles sont projetées (comme
|
|
12836
12844
|
* `usePages`), pour ne pas tirer tout le schéma sur chaque document.
|
|
12845
|
+
*
|
|
12846
|
+
* `filter`/`params` restreignent la table au niveau feuille (une langue, une
|
|
12847
|
+
* catégorie…). `useQueryData` stabilise lui-même les paramètres, donc l'objet
|
|
12848
|
+
* peut être reconstruit à chaque rendu sans relancer la requête en boucle.
|
|
12837
12849
|
*/
|
|
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
|
|
12850
|
+
function useCollection(type, visibleKeys, options = {}) {
|
|
12851
|
+
let { filter, params: extraParams } = options, 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, filter), [visibleColumns, filter]), {
|
|
12852
|
+
type,
|
|
12853
|
+
...extraParams
|
|
12854
|
+
}, { listenTypes: [type] });
|
|
12840
12855
|
return {
|
|
12841
12856
|
allColumns,
|
|
12842
12857
|
visibleColumns,
|
|
@@ -12995,14 +13010,38 @@ function ColumnList(props) {
|
|
|
12995
13010
|
]
|
|
12996
13011
|
});
|
|
12997
13012
|
}
|
|
12998
|
-
/** Barre au-dessus de la
|
|
13013
|
+
/** Barre au-dessus de la collection : switch de vue, création, recherche, colonnes, export. */
|
|
12999
13014
|
function CollectionToolbar(props) {
|
|
13000
|
-
let { search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, busy, summary } = props;
|
|
13015
|
+
let { view, onView, search, onSearch, columns, visible, onToggleColumn, onExport, onRefresh, onCreate, busy, summary } = props;
|
|
13001
13016
|
return /* @__PURE__ */ jsxs(Flex, {
|
|
13002
13017
|
align: "center",
|
|
13003
13018
|
gap: 2,
|
|
13004
13019
|
wrap: "wrap",
|
|
13005
13020
|
children: [
|
|
13021
|
+
/* @__PURE__ */ jsx(Card, {
|
|
13022
|
+
radius: 2,
|
|
13023
|
+
border: !0,
|
|
13024
|
+
style: { flex: "none" },
|
|
13025
|
+
children: /* @__PURE__ */ jsxs(Flex, { children: [/* @__PURE__ */ jsx(Button, {
|
|
13026
|
+
mode: view === "list" ? "default" : "bleed",
|
|
13027
|
+
tone: view === "list" ? "primary" : "default",
|
|
13028
|
+
fontSize: 1,
|
|
13029
|
+
padding: 2,
|
|
13030
|
+
icon: UlistIcon,
|
|
13031
|
+
title: "List view",
|
|
13032
|
+
"aria-label": "List view",
|
|
13033
|
+
onClick: () => onView("list")
|
|
13034
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
13035
|
+
mode: view === "table" ? "default" : "bleed",
|
|
13036
|
+
tone: view === "table" ? "primary" : "default",
|
|
13037
|
+
fontSize: 1,
|
|
13038
|
+
padding: 2,
|
|
13039
|
+
icon: ThLargeIcon,
|
|
13040
|
+
title: "Table view",
|
|
13041
|
+
"aria-label": "Table view",
|
|
13042
|
+
onClick: () => onView("table")
|
|
13043
|
+
})] })
|
|
13044
|
+
}),
|
|
13006
13045
|
/* @__PURE__ */ jsx(Box, {
|
|
13007
13046
|
style: {
|
|
13008
13047
|
flex: 1,
|
|
@@ -13030,7 +13069,16 @@ function CollectionToolbar(props) {
|
|
|
13030
13069
|
gap: 1,
|
|
13031
13070
|
style: { flex: "none" },
|
|
13032
13071
|
children: [
|
|
13033
|
-
/* @__PURE__ */ jsx(
|
|
13072
|
+
onCreate && /* @__PURE__ */ jsx(Button, {
|
|
13073
|
+
mode: "ghost",
|
|
13074
|
+
tone: "primary",
|
|
13075
|
+
fontSize: 1,
|
|
13076
|
+
padding: 2,
|
|
13077
|
+
icon: AddIcon,
|
|
13078
|
+
text: "New",
|
|
13079
|
+
onClick: onCreate
|
|
13080
|
+
}),
|
|
13081
|
+
view === "table" && /* @__PURE__ */ jsx(CollectionColumnPicker, {
|
|
13034
13082
|
columns,
|
|
13035
13083
|
visible,
|
|
13036
13084
|
onToggle: onToggleColumn
|
|
@@ -13062,11 +13110,32 @@ function defaultVisible(columns) {
|
|
|
13062
13110
|
let title = columns.find((c) => c.key === "title") ?? columns.find((c) => c.kind === "text");
|
|
13063
13111
|
return (title ? [title, ...columns.filter((c) => c !== title)] : [...columns]).slice(0, 6).map((c) => c.key);
|
|
13064
13112
|
}
|
|
13065
|
-
|
|
13066
|
-
|
|
13113
|
+
/** Largeur par défaut d'une colonne : le titre large, le reste selon le type. */
|
|
13114
|
+
function defaultWidth(column, isFirst) {
|
|
13115
|
+
if (isFirst) return 320;
|
|
13116
|
+
switch (column.kind) {
|
|
13117
|
+
case "number": return 110;
|
|
13118
|
+
case "boolean": return 90;
|
|
13119
|
+
case "date": return 150;
|
|
13120
|
+
case "reference": return 200;
|
|
13121
|
+
default: return 190;
|
|
13122
|
+
}
|
|
13123
|
+
}
|
|
13124
|
+
/** Déplace `fromKey` à la position de `toKey` dans la liste des clés. */
|
|
13125
|
+
function moveKey(keys, fromKey, toKey) {
|
|
13126
|
+
let from = keys.indexOf(fromKey), to = keys.indexOf(toKey);
|
|
13127
|
+
if (from < 0 || to < 0 || from === to) return keys;
|
|
13128
|
+
let next = [...keys];
|
|
13129
|
+
return next.splice(from, 1), next.splice(to, 0, fromKey), next;
|
|
13130
|
+
}
|
|
13131
|
+
function CollectionTable({ type, filter, params, newTemplate }) {
|
|
13132
|
+
let router = useRouter(), { ChildLink } = usePaneRouter(), [view, setView] = useState("table"), [selected, setSelected] = useState(null), [sort, setSort] = useState({
|
|
13067
13133
|
key: null,
|
|
13068
13134
|
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
|
|
13135
|
+
}), [search, setSearch] = useState(""), [columnFilters, setColumnFilters] = useState({}), [widths, setWidths] = 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, {
|
|
13136
|
+
filter,
|
|
13137
|
+
params
|
|
13138
|
+
}), visible = useMemo(() => sortRows(filterRows(rows, {
|
|
13070
13139
|
search,
|
|
13071
13140
|
columns: columnFilters
|
|
13072
13141
|
}, visibleColumns), sort, visibleColumns), [
|
|
@@ -13075,7 +13144,10 @@ function CollectionTable({ type }) {
|
|
|
13075
13144
|
columnFilters,
|
|
13076
13145
|
visibleColumns,
|
|
13077
13146
|
sort
|
|
13078
|
-
]),
|
|
13147
|
+
]), cols = useMemo(() => visibleColumns.map((column, index) => ({
|
|
13148
|
+
column,
|
|
13149
|
+
width: widths[column.key] ?? defaultWidth(column, index === 0)
|
|
13150
|
+
})), [visibleColumns, widths]), totalWidth = useMemo(() => cols.reduce((sum, c) => sum + c.width, 0), [cols]), onToggleColumn = useCallback((key) => {
|
|
13079
13151
|
setSelected((current) => {
|
|
13080
13152
|
let base = current ?? defaultVisible(allColumns);
|
|
13081
13153
|
return base.includes(key) ? base.filter((k) => k !== key) : [...base, key];
|
|
@@ -13103,20 +13175,40 @@ function CollectionTable({ type }) {
|
|
|
13103
13175
|
...current,
|
|
13104
13176
|
[key]: value
|
|
13105
13177
|
}));
|
|
13178
|
+
}, []), onCreate = useCallback(() => {
|
|
13179
|
+
router.navigateIntent("create", newTemplate ? {
|
|
13180
|
+
type,
|
|
13181
|
+
template: newTemplate
|
|
13182
|
+
} : { type });
|
|
13183
|
+
}, [
|
|
13184
|
+
router,
|
|
13185
|
+
type,
|
|
13186
|
+
newTemplate
|
|
13187
|
+
]), dragKeyRef = useRef(null), [dragOverKey, setDragOverKey] = useState(null), onReorder = useCallback((toKey) => {
|
|
13188
|
+
let fromKey = dragKeyRef.current;
|
|
13189
|
+
dragKeyRef.current = null, setDragOverKey(null), fromKey && fromKey !== toKey && setSelected((current) => moveKey(current ?? defaultVisible(allColumns), fromKey, toKey));
|
|
13190
|
+
}, [allColumns]), onResizeStart = useCallback((key, startW) => (event) => {
|
|
13191
|
+
event.preventDefault(), event.stopPropagation();
|
|
13192
|
+
let startX = event.clientX, onMove = (ev) => {
|
|
13193
|
+
setWidths((current) => ({
|
|
13194
|
+
...current,
|
|
13195
|
+
[key]: Math.max(80, startW + (ev.clientX - startX))
|
|
13196
|
+
}));
|
|
13197
|
+
}, onUp = () => {
|
|
13198
|
+
window.removeEventListener("pointermove", onMove), window.removeEventListener("pointerup", onUp);
|
|
13199
|
+
};
|
|
13200
|
+
window.addEventListener("pointermove", onMove), window.addEventListener("pointerup", onUp);
|
|
13106
13201
|
}, []);
|
|
13107
13202
|
if (error) return /* @__PURE__ */ jsx(QueryError, {
|
|
13108
13203
|
error,
|
|
13109
13204
|
onRetry: refresh
|
|
13110
13205
|
});
|
|
13111
|
-
let summary = visible.length === rows.length ? `${rows.length} item${rows.length > 1 ? "s" : ""}` : `${visible.length} of ${rows.length}`,
|
|
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
|
-
};
|
|
13206
|
+
let summary = visible.length === rows.length ? `${rows.length} item${rows.length > 1 ? "s" : ""}` : `${visible.length} of ${rows.length}`, subtitleKey = visibleColumns.find((c, i) => i > 0 && c.kind === "text")?.key;
|
|
13117
13207
|
return /* @__PURE__ */ jsxs(Stack, {
|
|
13118
|
-
gap:
|
|
13208
|
+
gap: 3,
|
|
13119
13209
|
children: [/* @__PURE__ */ jsx(CollectionToolbar, {
|
|
13210
|
+
view,
|
|
13211
|
+
onView: setView,
|
|
13120
13212
|
search,
|
|
13121
13213
|
onSearch: setSearch,
|
|
13122
13214
|
columns: allColumns,
|
|
@@ -13124,6 +13216,7 @@ function CollectionTable({ type }) {
|
|
|
13124
13216
|
onToggleColumn,
|
|
13125
13217
|
onExport,
|
|
13126
13218
|
onRefresh: refresh,
|
|
13219
|
+
onCreate,
|
|
13127
13220
|
busy: loading,
|
|
13128
13221
|
summary
|
|
13129
13222
|
}), loading && rows.length === 0 ? /* @__PURE__ */ jsxs(Flex, {
|
|
@@ -13144,41 +13237,86 @@ function CollectionTable({ type }) {
|
|
|
13144
13237
|
align: "center",
|
|
13145
13238
|
children: "No displayable field in this type. Pick columns above."
|
|
13146
13239
|
})
|
|
13147
|
-
}) : /* @__PURE__ */
|
|
13240
|
+
}) : view === "list" ? /* @__PURE__ */ jsxs(Box, {
|
|
13241
|
+
style: {
|
|
13242
|
+
border: `1px solid ${BORDER_SOFT}`,
|
|
13243
|
+
borderRadius: 6
|
|
13244
|
+
},
|
|
13245
|
+
children: [/* @__PURE__ */ jsx("style", { children: ".ncf-coll-body a{display:contents;color:inherit;text-decoration:none}" }), /* @__PURE__ */ jsxs(Box, {
|
|
13246
|
+
className: "ncf-coll-body",
|
|
13247
|
+
children: [visible.map((row) => /* @__PURE__ */ jsx(ChildLink, {
|
|
13248
|
+
childId: row.id,
|
|
13249
|
+
children: /* @__PURE__ */ jsx(ListRowView, {
|
|
13250
|
+
row,
|
|
13251
|
+
titleKey: visibleColumns[0]?.key,
|
|
13252
|
+
subtitleKey
|
|
13253
|
+
})
|
|
13254
|
+
}, row.id)), visible.length === 0 && /* @__PURE__ */ jsx(Box, {
|
|
13255
|
+
padding: 5,
|
|
13256
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
13257
|
+
size: 1,
|
|
13258
|
+
muted: !0,
|
|
13259
|
+
align: "center",
|
|
13260
|
+
children: rows.length === 0 ? "No item yet." : "No match."
|
|
13261
|
+
})
|
|
13262
|
+
})]
|
|
13263
|
+
})]
|
|
13264
|
+
}) : /* @__PURE__ */ jsxs(Box, {
|
|
13148
13265
|
style: {
|
|
13149
13266
|
overflowX: "auto",
|
|
13150
13267
|
border: `1px solid ${BORDER_SOFT}`,
|
|
13151
13268
|
borderRadius: 6
|
|
13152
13269
|
},
|
|
13153
|
-
children: /* @__PURE__ */ jsxs(Box, {
|
|
13154
|
-
style: {
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13270
|
+
children: [/* @__PURE__ */ jsx("style", { children: ".ncf-coll-body a{display:contents;color:inherit;text-decoration:none}" }), /* @__PURE__ */ jsxs(Box, {
|
|
13271
|
+
style: {
|
|
13272
|
+
width: totalWidth,
|
|
13273
|
+
minWidth: "100%"
|
|
13274
|
+
},
|
|
13275
|
+
children: [/* @__PURE__ */ jsx(Flex, {
|
|
13276
|
+
paddingX: 3,
|
|
13277
|
+
paddingY: 2,
|
|
13278
|
+
align: "flex-end",
|
|
13279
|
+
style: {
|
|
13280
|
+
borderBottom: `1px solid ${BORDER}`,
|
|
13281
|
+
position: "sticky",
|
|
13282
|
+
top: 0,
|
|
13283
|
+
background: "var(--card-bg-color, inherit)",
|
|
13284
|
+
zIndex: 2
|
|
13285
|
+
},
|
|
13286
|
+
children: cols.map(({ column, width }) => {
|
|
13287
|
+
let active = sort.key === column.key, Arrow = sort.direction === "asc" ? ChevronUpIcon : ChevronDownIcon;
|
|
13288
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
13289
|
+
paddingRight: 2,
|
|
13290
|
+
onDragOver: (e) => {
|
|
13291
|
+
dragKeyRef.current && dragKeyRef.current !== column.key && (e.preventDefault(), setDragOverKey(column.key));
|
|
13292
|
+
},
|
|
13293
|
+
onDrop: () => onReorder(column.key),
|
|
13294
|
+
style: {
|
|
13295
|
+
width,
|
|
13296
|
+
flex: "none",
|
|
13297
|
+
position: "relative",
|
|
13298
|
+
boxSizing: "border-box",
|
|
13299
|
+
borderLeft: dragOverKey === column.key ? "2px solid var(--card-focus-ring-color, #2276fc)" : "2px solid transparent"
|
|
13300
|
+
},
|
|
13301
|
+
children: [/* @__PURE__ */ jsxs(Stack, {
|
|
13171
13302
|
gap: 2,
|
|
13172
13303
|
style: CELL,
|
|
13173
13304
|
children: [/* @__PURE__ */ jsxs(Flex, {
|
|
13174
13305
|
align: "center",
|
|
13175
13306
|
gap: 1,
|
|
13307
|
+
draggable: !0,
|
|
13308
|
+
onDragStart: () => {
|
|
13309
|
+
dragKeyRef.current = column.key;
|
|
13310
|
+
},
|
|
13311
|
+
onDragEnd: () => {
|
|
13312
|
+
dragKeyRef.current = null, setDragOverKey(null);
|
|
13313
|
+
},
|
|
13176
13314
|
onClick: () => onSort(column.key),
|
|
13177
13315
|
style: {
|
|
13178
|
-
cursor: "
|
|
13316
|
+
cursor: "grab",
|
|
13179
13317
|
userSelect: "none"
|
|
13180
13318
|
},
|
|
13181
|
-
title: `Sort by ${column.label.toLowerCase()}`,
|
|
13319
|
+
title: `Sort by ${column.label.toLowerCase()} — drag to reorder`,
|
|
13182
13320
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
13183
13321
|
size: 0,
|
|
13184
13322
|
weight: "medium",
|
|
@@ -13186,7 +13324,7 @@ function CollectionTable({ type }) {
|
|
|
13186
13324
|
textOverflow: "ellipsis",
|
|
13187
13325
|
children: column.label
|
|
13188
13326
|
}), active && /* @__PURE__ */ jsx(Arrow, { style: {
|
|
13189
|
-
fontSize:
|
|
13327
|
+
fontSize: 12,
|
|
13190
13328
|
opacity: .7,
|
|
13191
13329
|
flex: "none"
|
|
13192
13330
|
} })]
|
|
@@ -13197,6 +13335,7 @@ function CollectionTable({ type }) {
|
|
|
13197
13335
|
onChange: (event) => onColumnFilter(column.key, event.currentTarget.value),
|
|
13198
13336
|
style: {
|
|
13199
13337
|
width: "100%",
|
|
13338
|
+
boxSizing: "border-box",
|
|
13200
13339
|
font: "inherit",
|
|
13201
13340
|
fontSize: 11,
|
|
13202
13341
|
padding: "3px 6px",
|
|
@@ -13207,19 +13346,30 @@ function CollectionTable({ type }) {
|
|
|
13207
13346
|
outline: "none"
|
|
13208
13347
|
}
|
|
13209
13348
|
})]
|
|
13210
|
-
},
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13216
|
-
|
|
13217
|
-
|
|
13218
|
-
|
|
13219
|
-
|
|
13349
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
13350
|
+
onPointerDown: onResizeStart(column.key, width),
|
|
13351
|
+
title: "Drag to resize",
|
|
13352
|
+
style: {
|
|
13353
|
+
position: "absolute",
|
|
13354
|
+
top: 0,
|
|
13355
|
+
right: 0,
|
|
13356
|
+
width: 9,
|
|
13357
|
+
height: "100%",
|
|
13358
|
+
cursor: "col-resize",
|
|
13359
|
+
touchAction: "none"
|
|
13360
|
+
}
|
|
13361
|
+
})]
|
|
13362
|
+
}, column.key);
|
|
13363
|
+
})
|
|
13364
|
+
}), /* @__PURE__ */ jsxs(Box, {
|
|
13365
|
+
className: "ncf-coll-body",
|
|
13366
|
+
children: [visible.map((row) => /* @__PURE__ */ jsx(ChildLink, {
|
|
13367
|
+
childId: row.id,
|
|
13368
|
+
children: /* @__PURE__ */ jsx(TableRowView, {
|
|
13369
|
+
row,
|
|
13370
|
+
cols
|
|
13220
13371
|
})
|
|
13221
|
-
}, row.id)),
|
|
13222
|
-
visible.length === 0 && /* @__PURE__ */ jsx(Box, {
|
|
13372
|
+
}, row.id)), visible.length === 0 && /* @__PURE__ */ jsx(Box, {
|
|
13223
13373
|
padding: 5,
|
|
13224
13374
|
children: /* @__PURE__ */ jsx(Text, {
|
|
13225
13375
|
size: 1,
|
|
@@ -13227,34 +13377,38 @@ function CollectionTable({ type }) {
|
|
|
13227
13377
|
align: "center",
|
|
13228
13378
|
children: rows.length === 0 ? "No item yet." : "No match."
|
|
13229
13379
|
})
|
|
13230
|
-
})
|
|
13231
|
-
]
|
|
13232
|
-
})
|
|
13380
|
+
})]
|
|
13381
|
+
})]
|
|
13382
|
+
})]
|
|
13233
13383
|
})]
|
|
13234
13384
|
});
|
|
13235
13385
|
}
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
|
|
13386
|
+
/** Ligne de la vue TABLE : une cellule par colonne, largeurs fixes. */
|
|
13387
|
+
function TableRowView(props) {
|
|
13388
|
+
let { row, cols } = props, [hovered, setHovered] = useState(!1);
|
|
13389
|
+
return /* @__PURE__ */ jsx(Flex, {
|
|
13239
13390
|
paddingX: 3,
|
|
13240
13391
|
paddingY: 2,
|
|
13241
|
-
onClick: onOpen,
|
|
13242
13392
|
onMouseEnter: () => setHovered(!0),
|
|
13243
13393
|
onMouseLeave: () => setHovered(!1),
|
|
13244
13394
|
style: {
|
|
13245
|
-
...grid,
|
|
13246
13395
|
cursor: "pointer",
|
|
13247
13396
|
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
13248
13397
|
background: hovered ? "var(--card-muted-bg-color, rgba(127,127,127,0.08))" : "transparent"
|
|
13249
13398
|
},
|
|
13250
|
-
children:
|
|
13399
|
+
children: cols.map(({ column, width }, index) => {
|
|
13251
13400
|
let cell = row.cells[column.key], empty = !cell || cell.raw === null || cell.text === "";
|
|
13252
13401
|
return /* @__PURE__ */ jsxs(Flex, {
|
|
13253
13402
|
align: "center",
|
|
13254
13403
|
gap: 2,
|
|
13255
|
-
|
|
13404
|
+
paddingRight: 2,
|
|
13405
|
+
style: {
|
|
13406
|
+
width,
|
|
13407
|
+
flex: "none",
|
|
13408
|
+
boxSizing: "border-box"
|
|
13409
|
+
},
|
|
13256
13410
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
13257
|
-
size:
|
|
13411
|
+
size: 0,
|
|
13258
13412
|
muted: empty,
|
|
13259
13413
|
weight: index === 0 ? "medium" : "regular",
|
|
13260
13414
|
textOverflow: "ellipsis",
|
|
@@ -13274,6 +13428,44 @@ function CollectionRowView(props) {
|
|
|
13274
13428
|
})
|
|
13275
13429
|
});
|
|
13276
13430
|
}
|
|
13431
|
+
/** Ligne de la vue LISTE : titre + sous-titre, façon liste native. */
|
|
13432
|
+
function ListRowView(props) {
|
|
13433
|
+
let { row, titleKey, subtitleKey } = props, [hovered, setHovered] = useState(!1), title = titleKey ? row.cells[titleKey]?.text : "", subtitle = subtitleKey ? row.cells[subtitleKey]?.text : "";
|
|
13434
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
13435
|
+
align: "center",
|
|
13436
|
+
gap: 2,
|
|
13437
|
+
paddingX: 3,
|
|
13438
|
+
paddingY: 2,
|
|
13439
|
+
onMouseEnter: () => setHovered(!0),
|
|
13440
|
+
onMouseLeave: () => setHovered(!1),
|
|
13441
|
+
style: {
|
|
13442
|
+
cursor: "pointer",
|
|
13443
|
+
borderBottom: `1px solid ${BORDER_SOFT}`,
|
|
13444
|
+
background: hovered ? "var(--card-muted-bg-color, rgba(127,127,127,0.08))" : "transparent"
|
|
13445
|
+
},
|
|
13446
|
+
children: [/* @__PURE__ */ jsxs(Stack, {
|
|
13447
|
+
gap: 2,
|
|
13448
|
+
flex: 1,
|
|
13449
|
+
style: { minWidth: 0 },
|
|
13450
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
13451
|
+
size: 1,
|
|
13452
|
+
weight: "medium",
|
|
13453
|
+
textOverflow: "ellipsis",
|
|
13454
|
+
children: title || "Untitled"
|
|
13455
|
+
}), subtitle ? /* @__PURE__ */ jsx(Text, {
|
|
13456
|
+
size: 0,
|
|
13457
|
+
muted: !0,
|
|
13458
|
+
textOverflow: "ellipsis",
|
|
13459
|
+
children: subtitle
|
|
13460
|
+
}) : null]
|
|
13461
|
+
}), row.draftOnly && /* @__PURE__ */ jsx(Badge, {
|
|
13462
|
+
tone: "caution",
|
|
13463
|
+
fontSize: 0,
|
|
13464
|
+
style: { flex: "none" },
|
|
13465
|
+
children: "Draft"
|
|
13466
|
+
})]
|
|
13467
|
+
});
|
|
13468
|
+
}
|
|
13277
13469
|
const isReserved = (name) => name.startsWith("sanity.") || name.startsWith("_");
|
|
13278
13470
|
/**
|
|
13279
13471
|
* Types de collection retenus.
|
|
@@ -13298,7 +13490,7 @@ function discoverCollectionTypes(types, options = {}) {
|
|
|
13298
13490
|
*/
|
|
13299
13491
|
function createCollectionPane(config, issues) {
|
|
13300
13492
|
return function NcfCollectionPane(props) {
|
|
13301
|
-
let type = typeof
|
|
13493
|
+
let opts = props.options ?? {}, type = typeof opts.type == "string" ? opts.type : "", filter = typeof opts.filter == "string" ? opts.filter : void 0, params = opts.params && typeof opts.params == "object" ? opts.params : void 0, newTemplate = typeof opts.newTemplate == "string" ? opts.newTemplate : void 0;
|
|
13302
13494
|
return /* @__PURE__ */ jsx(KitProvider, {
|
|
13303
13495
|
config,
|
|
13304
13496
|
issues,
|
|
@@ -13306,7 +13498,12 @@ function createCollectionPane(config, issues) {
|
|
|
13306
13498
|
padding: 3,
|
|
13307
13499
|
height: "fill",
|
|
13308
13500
|
overflow: "auto",
|
|
13309
|
-
children: type ? /* @__PURE__ */ jsx(CollectionTable, {
|
|
13501
|
+
children: type ? /* @__PURE__ */ jsx(CollectionTable, {
|
|
13502
|
+
type,
|
|
13503
|
+
filter,
|
|
13504
|
+
params,
|
|
13505
|
+
newTemplate
|
|
13506
|
+
}) : null
|
|
13310
13507
|
})
|
|
13311
13508
|
});
|
|
13312
13509
|
};
|
|
@@ -13318,10 +13515,31 @@ function createCollectionPane(config, issues) {
|
|
|
13318
13515
|
* ```ts
|
|
13319
13516
|
* S.listItem().title('Articles').child(ncfCollectionTable(S, ncfOptions, 'article'))
|
|
13320
13517
|
* ```
|
|
13518
|
+
*
|
|
13519
|
+
* `filter`/`params` posent la table au **niveau feuille** (une langue, une
|
|
13520
|
+
* catégorie…) sans mélanger le reste ; `newTemplate` garde la création
|
|
13521
|
+
* pré-taguée de ce niveau ; `id` sert quand un même type a plusieurs tables
|
|
13522
|
+
* (ex. une par langue), pour des identifiants de structure uniques.
|
|
13523
|
+
*
|
|
13524
|
+
* ```ts
|
|
13525
|
+
* S.documentList() // ancien niveau feuille…
|
|
13526
|
+
* ncfCollectionTable(S, ncfOptions, 'newsArticle', {
|
|
13527
|
+
* id: `ncf-col-newsArticle-${lang}`,
|
|
13528
|
+
* title: `News (${lang})`,
|
|
13529
|
+
* filter: 'language == $lang',
|
|
13530
|
+
* params: {lang},
|
|
13531
|
+
* newTemplate: `newsArticle-${lang}`,
|
|
13532
|
+
* })
|
|
13533
|
+
* ```
|
|
13321
13534
|
*/
|
|
13322
13535
|
function ncfCollectionTable(S, options, type, opts = {}) {
|
|
13323
13536
|
let config = resolveConfig(options), pane = createCollectionPane(config, validateConfig(config));
|
|
13324
|
-
return S.component(pane).id(`ncf-collection-${type}`).title(opts.title ?? type).options({
|
|
13537
|
+
return S.component(pane).id(opts.id ?? `ncf-collection-${type}`).title(opts.title ?? type).options({
|
|
13538
|
+
type,
|
|
13539
|
+
filter: opts.filter,
|
|
13540
|
+
params: opts.params,
|
|
13541
|
+
newTemplate: opts.newTemplate
|
|
13542
|
+
}).child((childId) => S.document().schemaType(type).documentId(childId));
|
|
13325
13543
|
}
|
|
13326
13544
|
/** Libellé d'une entrée de collection : config, puis titre du schéma, puis nom humanisé. */
|
|
13327
13545
|
function labelFor(type, config, schemaTitle) {
|