sanity-plugin-media
6.5.06.6.0
dist/index.js~
dist/index.jsModified+31−7
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -85,9 +85,9 @@
}
const useTypedSelector = useSelector, useVersionedClient = () => {
let $ = c(1), t0;
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: "2025-10-02" }, $[0] = t0) : t0 = $[0], useClient(t0);
-}, ORDER_DICTIONARY = {
+}, LOCALIZED_ORDER_FIELDS = /* @__PURE__ */ new Set(["title"]), ORDER_DICTIONARY = {
_createdAt: {
asc: "Last created: Oldest first",
desc: "Last created: Newest first"
},
@@ -102,13 +102,25 @@
originalFilename: {
asc: "File name: A to Z",
desc: "File name: Z to A"
},
+ title: {
+ asc: "Title: A to Z",
+ desc: "Title: Z to A"
+ },
size: {
asc: "File size: Smallest first",
desc: "File size: Largest first"
}
-}, getOrderTitle = (field, direction) => ORDER_DICTIONARY[field][direction], divider = { type: "divider" }, inputs = {
+}, getOrderTitle = (field, direction) => ORDER_DICTIONARY[field][direction], getOrderField = (field, localeIds) => {
+ if (localeIds.length === 0 || !LOCALIZED_ORDER_FIELDS.has(field)) return field;
+ let localizedFieldAccessors = localeIds.map((localeId) => groq`${field}[${JSON.stringify(localeId)}]`);
+ return groq`coalesce(${localizedFieldAccessors.join(", ")})`;
+}, getOrderValue = (value, field, localeIds) => {
+ if (localeIds.length === 0 || !LOCALIZED_ORDER_FIELDS.has(field) || typeof value != "object" || !value) return value;
+ let localizedValues = value;
+ return localeIds.map((localeId) => localizedValues[localeId]).find((v) => v != null);
+}, divider = { type: "divider" }, inputs = {
altText: {
assetTypes: ["file", "image"],
field: "altText",
name: "altText",
@@ -472,9 +484,18 @@
field: "originalFilename"
},
null,
{
+ direction: "asc",
+ field: "title"
+ },
+ {
direction: "desc",
+ field: "title"
+ },
+ null,
+ {
+ direction: "desc",
field: "size"
},
{
direction: "asc",
@@ -918,8 +939,9 @@
fetchCount: -1,
fetching: !1,
fetchingError: void 0,
lastPicked: void 0,
+ localeIds: [],
order: {
direction: defaultOrder.direction,
field: defaultOrder.field,
title: getOrderTitle(defaultOrder.field, defaultOrder.direction)
@@ -1136,9 +1158,9 @@
}), state.lastPicked = state.allIds[endIndex];
},
sort(state) {
state.allIds.sort((a, b) => {
- let tagA = state.byIds[a].asset[state.order.field], tagB = state.byIds[b].asset[state.order.field];
+ let { field } = state.order, tagA = getOrderValue(state.byIds[a].asset[field], field, state.localeIds), tagB = getOrderValue(state.byIds[b].asset[field], field, state.localeIds);
return tagA < tagB ? state.order.direction === "asc" ? -1 : 1 : tagA > tagB ? state.order.direction === "asc" ? 1 : -1 : 0;
});
},
updateComplete(state, action) {
@@ -1195,9 +1217,9 @@
return of(assetsActions.fetchRequest({
params,
queryFilter: constructedFilter,
selector: groq`[${start}...${end}]`,
- sort: groq`order(${state.assets?.order?.field} ${state.assets?.order?.direction})`
+ sort: groq`order(${getOrderField(state.assets.order.field, state.assets.localeIds)} ${state.assets.order.direction})`
}));
})), assetsFetchNextPageEpic = (action$, state$) => action$.pipe(filter(assetsActions.loadNextPage.match), withLatestFrom(state$), switchMap(([_action, state]) => of(assetsActions.loadPageIndex({ pageIndex: state.assets.pageIndex + 1 })))), assetsFetchAfterDeleteAllEpic = (action$, state$) => action$.pipe(filter(assetsActions.deleteComplete.match), withLatestFrom(state$), switchMap(([_action, state]) => {
if (state.assets.allIds.length === 0) {
let nextPageIndex = Math.floor(state.assets.allIds.length / state.assets.pageSize);
@@ -6442,8 +6464,9 @@
assets: {
...initialState$1,
assetTypes: isSupportedAssetType(props?.assetType) ? [props.assetType] : ["file", "image"],
excludeTagSlugs: props.excludeTagSlugs?.length ? [...props.excludeTagSlugs] : [],
+ localeIds: props.locales?.length ? props.locales.map((locale) => locale.id) : [],
showMediaLibraryAssets: props.showMediaLibraryAssets ?? !0
},
debug: {
badConnection: !1,
@@ -8560,9 +8583,9 @@
element: portalElement,
children: t9
}), $[11] = portalElement, $[12] = t9, $[13] = t10) : t10 = $[13], t10;
}, Browser = (props) => {
- let $ = c(16), client = useVersionedClient(), { excludeTagSlugs, showMediaLibraryAssets } = useToolOptions(), t0 = props?.assetType, t1 = props?.document, t2 = props?.selectedAssets, t3 = props?.isMultiSelect, t4 = props?.onSelect, t5;
+ let $ = c(17), client = useVersionedClient(), { excludeTagSlugs, locales, showMediaLibraryAssets } = useToolOptions(), t0 = props?.assetType, t1 = props?.document, t2 = props?.selectedAssets, t3 = props?.isMultiSelect, t4 = props?.onSelect, t5;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(GlobalStyle, {}), $[0] = t5) : t5 = $[0];
let t6 = props?.onClose, t7 = props?.schemaType, t8;
$[1] !== t6 || $[2] !== t7 ? (t8 = /* @__PURE__ */ jsx(BrowserContent, {
onClose: t6,
@@ -8574,17 +8597,18 @@
onSelect: t4,
children: [t5, t8]
}), $[4] = t3, $[5] = t4, $[6] = t8, $[7] = t9) : t9 = $[7];
let t10;
- return $[8] !== client || $[9] !== excludeTagSlugs || $[10] !== showMediaLibraryAssets || $[11] !== t0 || $[12] !== t1 || $[13] !== t2 || $[14] !== t9 ? (t10 = /* @__PURE__ */ jsx(ReduxProvider, {
+ return $[8] !== client || $[9] !== excludeTagSlugs || $[10] !== locales || $[11] !== showMediaLibraryAssets || $[12] !== t0 || $[13] !== t1 || $[14] !== t2 || $[15] !== t9 ? (t10 = /* @__PURE__ */ jsx(ReduxProvider, {
assetType: t0,
client,
document: t1,
excludeTagSlugs,
+ locales,
selectedAssets: t2,
showMediaLibraryAssets,
children: t9
- }), $[8] = client, $[9] = excludeTagSlugs, $[10] = showMediaLibraryAssets, $[11] = t0, $[12] = t1, $[13] = t2, $[14] = t9, $[15] = t10) : t10 = $[15], t10;
+ }), $[8] = client, $[9] = excludeTagSlugs, $[10] = locales, $[11] = showMediaLibraryAssets, $[12] = t0, $[13] = t1, $[14] = t2, $[15] = t9, $[16] = t10) : t10 = $[16], t10;
}, FormBuilderTool = (props) => {
let $ = c(13), { onClose } = props, portalElement = useRootPortalElement(), t0;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
let currentDocument = useFormValue(t0), selectionType = props?.selectionType, schemaJsonType = props?.schemaType?.jsonType, isMultiSelect = selectionType === "multiple" || schemaJsonType === "array";