sanity-plugin-media 6.5.0 → 6.6.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 +3 -0
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -226,6 +226,9 @@ When `locales` are provided, all localized fields (title, altText, description,
|
|
|
226
226
|
|
|
227
227
|
This will return the Italian value if present, otherwise English, otherwise French, etc. Adjust the order as needed for your project.
|
|
228
228
|
|
|
229
|
+
**Sorting by title:**
|
|
230
|
+
When `locales` are configured, "Title: A to Z" / "Title: Z to A" in the sort dropdown sort by the first available translation, checked in the order your `locales` array is declared — the same fallback pattern shown above. Assets missing a title in every configured locale sort as empty.
|
|
231
|
+
|
|
229
232
|
#### Migrating existing assets to localized format
|
|
230
233
|
|
|
231
234
|
If you enable `locales` on a project that already has assets with plain string fields (e.g. `title: "My photo"`), you should run the provided migration script to convert those fields to the localized object format (e.g. `title: {en: "My photo"}`).
|
package/dist/index.js
CHANGED
|
@@ -86,7 +86,7 @@ function _temp$38() {
|
|
|
86
86
|
const useTypedSelector = useSelector, useVersionedClient = () => {
|
|
87
87
|
let $ = c(1), t0;
|
|
88
88
|
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: "2025-10-02" }, $[0] = t0) : t0 = $[0], useClient(t0);
|
|
89
|
-
}, ORDER_DICTIONARY = {
|
|
89
|
+
}, LOCALIZED_ORDER_FIELDS = /* @__PURE__ */ new Set(["title"]), ORDER_DICTIONARY = {
|
|
90
90
|
_createdAt: {
|
|
91
91
|
asc: "Last created: Oldest first",
|
|
92
92
|
desc: "Last created: Newest first"
|
|
@@ -103,11 +103,23 @@ const useTypedSelector = useSelector, useVersionedClient = () => {
|
|
|
103
103
|
asc: "File name: A to Z",
|
|
104
104
|
desc: "File name: Z to A"
|
|
105
105
|
},
|
|
106
|
+
title: {
|
|
107
|
+
asc: "Title: A to Z",
|
|
108
|
+
desc: "Title: Z to A"
|
|
109
|
+
},
|
|
106
110
|
size: {
|
|
107
111
|
asc: "File size: Smallest first",
|
|
108
112
|
desc: "File size: Largest first"
|
|
109
113
|
}
|
|
110
|
-
}, getOrderTitle = (field, direction) => ORDER_DICTIONARY[field][direction],
|
|
114
|
+
}, getOrderTitle = (field, direction) => ORDER_DICTIONARY[field][direction], getOrderField = (field, localeIds) => {
|
|
115
|
+
if (localeIds.length === 0 || !LOCALIZED_ORDER_FIELDS.has(field)) return field;
|
|
116
|
+
let localizedFieldAccessors = localeIds.map((localeId) => groq`${field}[${JSON.stringify(localeId)}]`);
|
|
117
|
+
return groq`coalesce(${localizedFieldAccessors.join(", ")})`;
|
|
118
|
+
}, getOrderValue = (value, field, localeIds) => {
|
|
119
|
+
if (localeIds.length === 0 || !LOCALIZED_ORDER_FIELDS.has(field) || typeof value != "object" || !value) return value;
|
|
120
|
+
let localizedValues = value;
|
|
121
|
+
return localeIds.map((localeId) => localizedValues[localeId]).find((v) => v != null);
|
|
122
|
+
}, divider = { type: "divider" }, inputs = {
|
|
111
123
|
altText: {
|
|
112
124
|
assetTypes: ["file", "image"],
|
|
113
125
|
field: "altText",
|
|
@@ -472,6 +484,15 @@ const operators = {
|
|
|
472
484
|
field: "originalFilename"
|
|
473
485
|
},
|
|
474
486
|
null,
|
|
487
|
+
{
|
|
488
|
+
direction: "asc",
|
|
489
|
+
field: "title"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
direction: "desc",
|
|
493
|
+
field: "title"
|
|
494
|
+
},
|
|
495
|
+
null,
|
|
475
496
|
{
|
|
476
497
|
direction: "desc",
|
|
477
498
|
field: "size"
|
|
@@ -919,6 +940,7 @@ const UPLOADS_ACTIONS = { uploadComplete: createAction("uploads/uploadComplete",
|
|
|
919
940
|
fetching: !1,
|
|
920
941
|
fetchingError: void 0,
|
|
921
942
|
lastPicked: void 0,
|
|
943
|
+
localeIds: [],
|
|
922
944
|
order: {
|
|
923
945
|
direction: defaultOrder.direction,
|
|
924
946
|
field: defaultOrder.field,
|
|
@@ -1137,7 +1159,7 @@ const UPLOADS_ACTIONS = { uploadComplete: createAction("uploads/uploadComplete",
|
|
|
1137
1159
|
},
|
|
1138
1160
|
sort(state) {
|
|
1139
1161
|
state.allIds.sort((a, b) => {
|
|
1140
|
-
let tagA = state.byIds[a].asset[
|
|
1162
|
+
let { field } = state.order, tagA = getOrderValue(state.byIds[a].asset[field], field, state.localeIds), tagB = getOrderValue(state.byIds[b].asset[field], field, state.localeIds);
|
|
1141
1163
|
return tagA < tagB ? state.order.direction === "asc" ? -1 : 1 : tagA > tagB ? state.order.direction === "asc" ? 1 : -1 : 0;
|
|
1142
1164
|
});
|
|
1143
1165
|
},
|
|
@@ -1196,7 +1218,7 @@ const UPLOADS_ACTIONS = { uploadComplete: createAction("uploads/uploadComplete",
|
|
|
1196
1218
|
params,
|
|
1197
1219
|
queryFilter: constructedFilter,
|
|
1198
1220
|
selector: groq`[${start}...${end}]`,
|
|
1199
|
-
sort: groq`order(${state.assets
|
|
1221
|
+
sort: groq`order(${getOrderField(state.assets.order.field, state.assets.localeIds)} ${state.assets.order.direction})`
|
|
1200
1222
|
}));
|
|
1201
1223
|
})), 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]) => {
|
|
1202
1224
|
if (state.assets.allIds.length === 0) {
|
|
@@ -6443,6 +6465,7 @@ function createReduxStore(props) {
|
|
|
6443
6465
|
...initialState$1,
|
|
6444
6466
|
assetTypes: isSupportedAssetType(props?.assetType) ? [props.assetType] : ["file", "image"],
|
|
6445
6467
|
excludeTagSlugs: props.excludeTagSlugs?.length ? [...props.excludeTagSlugs] : [],
|
|
6468
|
+
localeIds: props.locales?.length ? props.locales.map((locale) => locale.id) : [],
|
|
6446
6469
|
showMediaLibraryAssets: props.showMediaLibraryAssets ?? !0
|
|
6447
6470
|
},
|
|
6448
6471
|
debug: {
|
|
@@ -8561,7 +8584,7 @@ const BrowserContent = (t0) => {
|
|
|
8561
8584
|
children: t9
|
|
8562
8585
|
}), $[11] = portalElement, $[12] = t9, $[13] = t10) : t10 = $[13], t10;
|
|
8563
8586
|
}, Browser = (props) => {
|
|
8564
|
-
let $ = c(
|
|
8587
|
+
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;
|
|
8565
8588
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(GlobalStyle, {}), $[0] = t5) : t5 = $[0];
|
|
8566
8589
|
let t6 = props?.onClose, t7 = props?.schemaType, t8;
|
|
8567
8590
|
$[1] !== t6 || $[2] !== t7 ? (t8 = /* @__PURE__ */ jsx(BrowserContent, {
|
|
@@ -8575,15 +8598,16 @@ const BrowserContent = (t0) => {
|
|
|
8575
8598
|
children: [t5, t8]
|
|
8576
8599
|
}), $[4] = t3, $[5] = t4, $[6] = t8, $[7] = t9) : t9 = $[7];
|
|
8577
8600
|
let t10;
|
|
8578
|
-
return $[8] !== client || $[9] !== excludeTagSlugs || $[10] !==
|
|
8601
|
+
return $[8] !== client || $[9] !== excludeTagSlugs || $[10] !== locales || $[11] !== showMediaLibraryAssets || $[12] !== t0 || $[13] !== t1 || $[14] !== t2 || $[15] !== t9 ? (t10 = /* @__PURE__ */ jsx(ReduxProvider, {
|
|
8579
8602
|
assetType: t0,
|
|
8580
8603
|
client,
|
|
8581
8604
|
document: t1,
|
|
8582
8605
|
excludeTagSlugs,
|
|
8606
|
+
locales,
|
|
8583
8607
|
selectedAssets: t2,
|
|
8584
8608
|
showMediaLibraryAssets,
|
|
8585
8609
|
children: t9
|
|
8586
|
-
}), $[8] = client, $[9] = excludeTagSlugs, $[10] =
|
|
8610
|
+
}), $[8] = client, $[9] = excludeTagSlugs, $[10] = locales, $[11] = showMediaLibraryAssets, $[12] = t0, $[13] = t1, $[14] = t2, $[15] = t9, $[16] = t10) : t10 = $[16], t10;
|
|
8587
8611
|
}, FormBuilderTool = (props) => {
|
|
8588
8612
|
let $ = c(13), { onClose } = props, portalElement = useRootPortalElement(), t0;
|
|
8589
8613
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|