sanity-plugin-media 6.0.7 → 6.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +85 -84
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ImageIcon } from "@sanity/icons/Image";
|
|
|
2
2
|
import { Preview, WithReferringDocuments, definePlugin, useClient, useColorSchemeValue, useDocumentStore, useFormValue, useSchema } from "sanity";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { Box, Button, Card, Checkbox, Container, Dialog, Flex, Grid, Inline, Label, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem, Popover, Portal, PortalProvider, Spinner, Stack, Switch, Tab, TabList, TabPanel, Text, TextArea, TextInput, Tooltip, rem, studioTheme, useLayer, useMediaIndex, usePortal, useToast } from "@sanity/ui";
|
|
5
|
-
import {
|
|
5
|
+
import { createContext, memo, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { isHotkey } from "is-hotkey-esm";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { createGlobalStyle, css, styled } from "styled-components";
|
|
@@ -521,39 +521,39 @@ const useKeyPress = (hotkey, onPress) => {
|
|
|
521
521
|
value: tag?._id
|
|
522
522
|
}), acc;
|
|
523
523
|
}, []), ASSETS_ACTIONS = {
|
|
524
|
-
tagsAddComplete: createAction("actions/tagsAddComplete", function({ assets, tag }) {
|
|
524
|
+
tagsAddComplete: createAction("actions/tagsAddComplete", function prepare({ assets, tag }) {
|
|
525
525
|
return { payload: {
|
|
526
526
|
assets,
|
|
527
527
|
tag
|
|
528
528
|
} };
|
|
529
529
|
}),
|
|
530
|
-
tagsAddError: createAction("actions/tagsAddError", function({ assets, error, tag }) {
|
|
530
|
+
tagsAddError: createAction("actions/tagsAddError", function prepare({ assets, error, tag }) {
|
|
531
531
|
return { payload: {
|
|
532
532
|
assets,
|
|
533
533
|
error,
|
|
534
534
|
tag
|
|
535
535
|
} };
|
|
536
536
|
}),
|
|
537
|
-
tagsAddRequest: createAction("actions/tagsAddRequest", function({ assets, tag }) {
|
|
537
|
+
tagsAddRequest: createAction("actions/tagsAddRequest", function prepare({ assets, tag }) {
|
|
538
538
|
return { payload: {
|
|
539
539
|
assets,
|
|
540
540
|
tag
|
|
541
541
|
} };
|
|
542
542
|
}),
|
|
543
|
-
tagsRemoveComplete: createAction("actions/tagsRemoveComplete", function({ assets, tag }) {
|
|
543
|
+
tagsRemoveComplete: createAction("actions/tagsRemoveComplete", function prepare({ assets, tag }) {
|
|
544
544
|
return { payload: {
|
|
545
545
|
assets,
|
|
546
546
|
tag
|
|
547
547
|
} };
|
|
548
548
|
}),
|
|
549
|
-
tagsRemoveError: createAction("actions/tagsRemoveError", function({ assets, error, tag }) {
|
|
549
|
+
tagsRemoveError: createAction("actions/tagsRemoveError", function prepare({ assets, error, tag }) {
|
|
550
550
|
return { payload: {
|
|
551
551
|
assets,
|
|
552
552
|
error,
|
|
553
553
|
tag
|
|
554
554
|
} };
|
|
555
555
|
}),
|
|
556
|
-
tagsRemoveRequest: createAction("actions/tagsRemoveRequest", function({ assets, tag }) {
|
|
556
|
+
tagsRemoveRequest: createAction("actions/tagsRemoveRequest", function prepare({ assets, tag }) {
|
|
557
557
|
return { payload: {
|
|
558
558
|
assets,
|
|
559
559
|
tag
|
|
@@ -561,7 +561,7 @@ const useKeyPress = (hotkey, onPress) => {
|
|
|
561
561
|
})
|
|
562
562
|
}, DIALOG_ACTIONS = {
|
|
563
563
|
showTagCreate: createAction("dialog/showTagCreate"),
|
|
564
|
-
showTagEdit: createAction("dialog/showTagEdit", function({ tagId }) {
|
|
564
|
+
showTagEdit: createAction("dialog/showTagEdit", function prepare({ tagId }) {
|
|
565
565
|
return { payload: { tagId } };
|
|
566
566
|
})
|
|
567
567
|
}, tagsSlice = createSlice({
|
|
@@ -781,7 +781,7 @@ const useKeyPress = (hotkey, onPress) => {
|
|
|
781
781
|
},
|
|
782
782
|
tag
|
|
783
783
|
}))));
|
|
784
|
-
})), selectTagsByIds = (state) => state.tags.byIds,
|
|
784
|
+
})), selectTagsByIds = (state) => state.tags.byIds, selectTagsAllIds = (state) => state.tags.allIds, selectTags = createSelector([selectTagsByIds, selectTagsAllIds], (byIds, allIds) => allIds.map((id) => byIds[id])), selectTagById = createSelector([selectTagsByIds, (_state, tagId) => tagId], (byIds, tagId) => byIds[tagId]), selectTagSelectOptions = (asset) => (state) => {
|
|
785
785
|
let tags = asset?.opt?.media?.tags?.reduce((acc, v) => {
|
|
786
786
|
let tagItem = state.tags.byIds[v._ref];
|
|
787
787
|
return tagItem?.tag && acc.push(tagItem), acc;
|
|
@@ -839,7 +839,7 @@ const searchSlice = createSlice({
|
|
|
839
839
|
})) : EMPTY;
|
|
840
840
|
})), selectIsSearchFacetTag = createSelector([(state) => state.search.facets, (_state, tagId) => tagId], (searchFacets, tagId) => searchFacets.some((facet) => facet.name === "tag" && facet.type === "searchable" && (facet.operatorType === "references" || facet.operatorType === "doesNotReference") && facet.value?.value === tagId)), searchActions = { ...searchSlice.actions };
|
|
841
841
|
var search_default = searchSlice.reducer;
|
|
842
|
-
const UPLOADS_ACTIONS = { uploadComplete: createAction("uploads/uploadComplete", function({ asset }) {
|
|
842
|
+
const UPLOADS_ACTIONS = { uploadComplete: createAction("uploads/uploadComplete", function prepare({ asset }) {
|
|
843
843
|
return { payload: { asset } };
|
|
844
844
|
}) }, defaultOrder = ORDER_OPTIONS[0], initialState = {
|
|
845
845
|
allIds: [],
|
|
@@ -1893,6 +1893,18 @@ const Container$2 = /* @__PURE__ */ styled(Box).withConfig({
|
|
|
1893
1893
|
children: t1
|
|
1894
1894
|
})
|
|
1895
1895
|
}), $[3] = props, $[4] = t1, $[5] = t2) : t2 = $[5], t2;
|
|
1896
|
+
}, SingleValue = (props) => {
|
|
1897
|
+
let $ = c(5), t0;
|
|
1898
|
+
$[0] === props.children ? t0 = $[1] : (t0 = /* @__PURE__ */ jsx(Text, {
|
|
1899
|
+
size: 1,
|
|
1900
|
+
textOverflow: "ellipsis",
|
|
1901
|
+
children: props.children
|
|
1902
|
+
}), $[0] = props.children, $[1] = t0);
|
|
1903
|
+
let t1;
|
|
1904
|
+
return $[2] !== props || $[3] !== t0 ? (t1 = /* @__PURE__ */ jsx(components.SingleValue, {
|
|
1905
|
+
...props,
|
|
1906
|
+
children: t0
|
|
1907
|
+
}), $[2] = props, $[3] = t0, $[4] = t1) : t1 = $[4], t1;
|
|
1896
1908
|
}, reactSelectComponents$1 = {
|
|
1897
1909
|
ClearIndicator,
|
|
1898
1910
|
DropdownIndicator: null,
|
|
@@ -1901,19 +1913,7 @@ const Container$2 = /* @__PURE__ */ styled(Box).withConfig({
|
|
|
1901
1913
|
MenuList: MenuList$1,
|
|
1902
1914
|
NoOptionsMessage,
|
|
1903
1915
|
Option: Option$1,
|
|
1904
|
-
SingleValue
|
|
1905
|
-
let $ = c(5), t0;
|
|
1906
|
-
$[0] === props.children ? t0 = $[1] : (t0 = /* @__PURE__ */ jsx(Text, {
|
|
1907
|
-
size: 1,
|
|
1908
|
-
textOverflow: "ellipsis",
|
|
1909
|
-
children: props.children
|
|
1910
|
-
}), $[0] = props.children, $[1] = t0);
|
|
1911
|
-
let t1;
|
|
1912
|
-
return $[2] !== props || $[3] !== t0 ? (t1 = /* @__PURE__ */ jsx(components.SingleValue, {
|
|
1913
|
-
...props,
|
|
1914
|
-
children: t0
|
|
1915
|
-
}), $[2] = props, $[3] = t0, $[4] = t1) : t1 = $[4], t1;
|
|
1916
|
-
}
|
|
1916
|
+
SingleValue
|
|
1917
1917
|
}, SearchFacetTags = (t0) => {
|
|
1918
1918
|
let $ = c(24), { facet } = t0, scheme = useColorSchemeValue(), dispatch = useDispatch(), tags = useTypedSelector(_temp$25), tagsFetching = useTypedSelector(_temp2$17), t1;
|
|
1919
1919
|
$[0] === tags ? t1 = $[1] : (t1 = getTagSelectOptions(tags), $[0] = tags, $[1] = t1);
|
|
@@ -4534,8 +4534,7 @@ const selectCombinedItems = createSelector([(state) => state.assets.allIds, (sta
|
|
|
4534
4534
|
})(({ $scheme }) => css`cursor:pointer;height:${32}px;transition:all 300ms;@media (hover:hover) and (pointer:fine){&:hover{background:${getSchemeColor($scheme, "bg")};}}`), StyledWarningOutlineIcon = /* @__PURE__ */ styled(WarningFilledIcon).withConfig({
|
|
4535
4535
|
displayName: "StyledWarningOutlineIcon",
|
|
4536
4536
|
componentId: "sc-1uiydw-3"
|
|
4537
|
-
})(({ theme }) => ({ color: theme.sanity.color.spot.red }))
|
|
4538
|
-
var CardAsset_default = memo((props) => {
|
|
4537
|
+
})(({ theme }) => ({ color: theme.sanity.color.spot.red })), CardAsset = (props) => {
|
|
4539
4538
|
let $ = c(63), { id, selected } = props, scheme = useColorSchemeValue(), shiftPressed = useKeyPress("shift"), dispatch = useDispatch(), lastPicked = useTypedSelector(_temp$10), t0;
|
|
4540
4539
|
$[0] === id ? t0 = $[1] : (t0 = (state_0) => selectAssetById(state_0, id), $[0] = id, $[1] = t0);
|
|
4541
4540
|
let item = useTypedSelector(t0), asset = item?.asset, error = item?.error, isOpaque = item?.asset?.metadata?.isOpaque, picked = item?.picked, updating = item?.updating, { onSelect } = useAssetSourceActions();
|
|
@@ -4712,7 +4711,8 @@ var CardAsset_default = memo((props) => {
|
|
|
4712
4711
|
]
|
|
4713
4712
|
})
|
|
4714
4713
|
}), $[57] = item.updating, $[58] = picked, $[59] = t11, $[60] = t15, $[61] = t16, $[62] = t17) : t17 = $[62], t17;
|
|
4715
|
-
}
|
|
4714
|
+
};
|
|
4715
|
+
var CardAsset_default = memo(CardAsset);
|
|
4716
4716
|
function _temp$10(state) {
|
|
4717
4717
|
return state.assets.lastPicked;
|
|
4718
4718
|
}
|
|
@@ -4771,7 +4771,7 @@ const createThrottler = (concurrency = 4) => {
|
|
|
4771
4771
|
}), hexFromBuffer = (buffer) => Array.prototype.map.call(new Uint8Array(buffer), (x) => `00${x.toString(16)}`.slice(-2)).join(""), hashFile$ = (file) => !window.crypto || !window.crypto.subtle || !window.FileReader ? throwError({
|
|
4772
4772
|
message: "Unable to generate hash: uploads are only allowed in secure contexts",
|
|
4773
4773
|
statusCode: 500
|
|
4774
|
-
}) : readFile$(file).pipe(mergeMap((arrayBuffer) => window.crypto.subtle.digest("SHA-1", arrayBuffer)), map(hexFromBuffer)),
|
|
4774
|
+
}) : readFile$(file).pipe(mergeMap((arrayBuffer) => window.crypto.subtle.digest("SHA-1", arrayBuffer)), map(hexFromBuffer)), uploadSanityAsset$ = (client, assetType, file, hash) => of(null).pipe(mergeMap(() => fetchExisting$(client, `sanity.${assetType}Asset`, hash)), mergeMap((existingAsset) => existingAsset ? throwError({
|
|
4775
4775
|
message: "Asset already exists",
|
|
4776
4776
|
statusCode: 409
|
|
4777
4777
|
}) : of(null)), mergeMap(() => client.observable.assets.upload(assetType, file, {
|
|
@@ -4787,7 +4787,7 @@ const createThrottler = (concurrency = 4) => {
|
|
|
4787
4787
|
asset: event.body.document,
|
|
4788
4788
|
id: event.body.document._id,
|
|
4789
4789
|
type: "complete"
|
|
4790
|
-
} : event))))), uploadsSlice = createSlice({
|
|
4790
|
+
} : event)))), uploadAsset$ = withMaxConcurrency(uploadSanityAsset$), uploadsSlice = createSlice({
|
|
4791
4791
|
name: "uploads",
|
|
4792
4792
|
initialState: {
|
|
4793
4793
|
allIds: [],
|
|
@@ -5239,8 +5239,7 @@ const ContainerGrid = /* @__PURE__ */ styled(Grid).withConfig({
|
|
|
5239
5239
|
})(({ $scheme }) => css`cursor:pointer;@media (hover:hover) and (pointer:fine){&:hover{background:${getSchemeColor($scheme, "bg2")};}}`), StyledWarningIcon = /* @__PURE__ */ styled(WarningFilledIcon).withConfig({
|
|
5240
5240
|
displayName: "StyledWarningIcon",
|
|
5241
5241
|
componentId: "sc-6mcfu2-2"
|
|
5242
|
-
})(({ theme }) => ({ color: theme.sanity.color.spot.red }))
|
|
5243
|
-
var TableRowAsset_default = memo((props) => {
|
|
5242
|
+
})(({ theme }) => ({ color: theme.sanity.color.spot.red })), TableRowAsset = (props) => {
|
|
5244
5243
|
let $ = c(145), { id, selected } = props, scheme = useColorSchemeValue(), shiftPressed = useKeyPress("shift"), [referenceCountVisible, setReferenceCountVisible] = useState(!1), refCountVisibleTimeout = useRef(null), dispatch = useDispatch(), lastPicked = useTypedSelector(_temp$6), t0;
|
|
5245
5244
|
$[0] === id ? t0 = $[1] : (t0 = (state_0) => selectAssetById(state_0, id), $[0] = id, $[1] = t0);
|
|
5246
5245
|
let item = useTypedSelector(t0), mediaIndex = useMediaIndex(), asset = item?.asset, error = item?.error, isOpaque = item?.asset?.metadata?.isOpaque, picked = item?.picked, updating = item?.updating, { onSelect } = useAssetSourceActions(), t1;
|
|
@@ -5587,7 +5586,8 @@ var TableRowAsset_default = memo((props) => {
|
|
|
5587
5586
|
t65
|
|
5588
5587
|
]
|
|
5589
5588
|
}), $[130] = item.updating, $[131] = scheme, $[132] = selected, $[133] = t13, $[134] = t22, $[135] = t28, $[136] = t36, $[137] = t41, $[138] = t47, $[139] = t5, $[140] = t55, $[141] = t60, $[142] = t65, $[143] = t9, $[144] = t66) : t66 = $[144], t66;
|
|
5590
|
-
}
|
|
5589
|
+
};
|
|
5590
|
+
var TableRowAsset_default = memo(TableRowAsset);
|
|
5591
5591
|
function _temp$6(state) {
|
|
5592
5592
|
return state.assets.lastPicked;
|
|
5593
5593
|
}
|
|
@@ -6064,60 +6064,61 @@ const rootEpic = combineEpics(assetsDeleteEpic, assetsFetchEpic, assetsFetchAfte
|
|
|
6064
6064
|
function isSupportedAssetType(assetType) {
|
|
6065
6065
|
return assetType ? SUPPORTED_ASSET_TYPES.includes(assetType) : !1;
|
|
6066
6066
|
}
|
|
6067
|
-
|
|
6068
|
-
store
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
},
|
|
6107
|
-
uploads: {
|
|
6108
|
-
allIds: [],
|
|
6109
|
-
byIds: {}
|
|
6110
|
-
}
|
|
6067
|
+
function createReduxStore(props) {
|
|
6068
|
+
let epicMiddleware = createEpicMiddleware({ dependencies: { client: props.client } }), store = configureStore({
|
|
6069
|
+
reducer: rootReducer,
|
|
6070
|
+
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
|
|
6071
|
+
serializableCheck: !1,
|
|
6072
|
+
thunk: !1
|
|
6073
|
+
}).prepend(epicMiddleware),
|
|
6074
|
+
devTools: !0,
|
|
6075
|
+
preloadedState: {
|
|
6076
|
+
assets: {
|
|
6077
|
+
...initialState,
|
|
6078
|
+
assetTypes: isSupportedAssetType(props?.assetType) ? [props.assetType] : ["file", "image"]
|
|
6079
|
+
},
|
|
6080
|
+
debug: {
|
|
6081
|
+
badConnection: !1,
|
|
6082
|
+
enabled: !1
|
|
6083
|
+
},
|
|
6084
|
+
dialog: { items: [] },
|
|
6085
|
+
notifications: { items: [] },
|
|
6086
|
+
search: {
|
|
6087
|
+
facets: [],
|
|
6088
|
+
query: ""
|
|
6089
|
+
},
|
|
6090
|
+
selected: {
|
|
6091
|
+
assets: props.selectedAssets || [],
|
|
6092
|
+
document: props.document,
|
|
6093
|
+
documentAssetIds: props.document ? getDocumentAssetIds(props.document) : []
|
|
6094
|
+
},
|
|
6095
|
+
tags: {
|
|
6096
|
+
allIds: [],
|
|
6097
|
+
byIds: {},
|
|
6098
|
+
creating: !1,
|
|
6099
|
+
fetchCount: -1,
|
|
6100
|
+
fetching: !1,
|
|
6101
|
+
panelVisible: !0
|
|
6102
|
+
},
|
|
6103
|
+
uploads: {
|
|
6104
|
+
allIds: [],
|
|
6105
|
+
byIds: {}
|
|
6111
6106
|
}
|
|
6112
|
-
}
|
|
6113
|
-
}
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6107
|
+
}
|
|
6108
|
+
});
|
|
6109
|
+
return epicMiddleware.run(rootEpic), store;
|
|
6110
|
+
}
|
|
6111
|
+
function ReduxProvider(t0) {
|
|
6112
|
+
let $ = c(8), children, props;
|
|
6113
|
+
$[0] === t0 ? (children = $[1], props = $[2]) : ({children, ...props} = t0, $[0] = t0, $[1] = children, $[2] = props);
|
|
6114
|
+
let t1;
|
|
6115
|
+
$[3] === props ? t1 = $[4] : (t1 = () => createReduxStore(props), $[3] = props, $[4] = t1);
|
|
6116
|
+
let [store] = useState(t1), t2;
|
|
6117
|
+
return $[5] !== children || $[6] !== store ? (t2 = /* @__PURE__ */ jsx(Provider, {
|
|
6118
|
+
store,
|
|
6119
|
+
children
|
|
6120
|
+
}), $[5] = children, $[6] = store, $[7] = t2) : t2 = $[7], t2;
|
|
6121
|
+
}
|
|
6121
6122
|
const TagsPanel = () => {
|
|
6122
6123
|
let $ = c(2);
|
|
6123
6124
|
if (!useTypedSelector(_temp$2)) return null;
|