sanity-plugin-media 2.2.5 → 2.3.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/dist/index.d.ts +5 -1
- package/dist/index.esm.js +74 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +73 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Tool/index.tsx +10 -5
- package/src/components/UploadDropzone/index.tsx +22 -2
- package/src/contexts/ToolOptionsContext.tsx +34 -0
- package/src/index.ts +12 -9
- package/src/types/index.ts +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type {AssetSource} from 'sanity'
|
|
2
2
|
import {Plugin as Plugin_2} from 'sanity'
|
|
3
3
|
|
|
4
|
-
export declare const media: Plugin_2<void>
|
|
4
|
+
export declare const media: Plugin_2<void | MediaToolOptions>
|
|
5
5
|
|
|
6
6
|
export declare const mediaAssetSource: AssetSource
|
|
7
7
|
|
|
8
|
+
declare type MediaToolOptions = {
|
|
9
|
+
maximumUploadSize?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export {}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useClient, useColorScheme, useSchema, Preview, useDocumentStore, WithReferringDocuments, useFormValue, definePlugin } from 'sanity';
|
|
2
|
-
import { forwardRef, createElement, useRef, useCallback, useEffect, createContext, useContext, useState, memo, Component } from 'react';
|
|
2
|
+
import { forwardRef, createElement, useRef, useCallback, useEffect, createContext, useContext, useState, memo, Component, useMemo } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { Inline, Button, usePortal, MenuButton, Menu as Menu$2, MenuItem, MenuDivider, Box, studioTheme, rem, Flex, Label, Text, TextInput, Card, MenuGroup, useMediaIndex, Tooltip, Switch, Popover, Stack, Dialog as Dialog$1, TextArea, TabList, Tab, TabPanel, Container as Container$2, Spinner, Checkbox, Grid, useToast, ThemeProvider, ToastProvider, PortalProvider, useLayer, Portal } from '@sanity/ui';
|
|
5
5
|
import isHotkey from 'is-hotkey';
|
|
@@ -11411,6 +11411,29 @@ const TagsPanel = () => {
|
|
|
11411
11411
|
})
|
|
11412
11412
|
});
|
|
11413
11413
|
};
|
|
11414
|
+
const ToolOptionsContext = createContext(null);
|
|
11415
|
+
const ToolOptionsProvider = _ref70 => {
|
|
11416
|
+
let {
|
|
11417
|
+
options,
|
|
11418
|
+
children
|
|
11419
|
+
} = _ref70;
|
|
11420
|
+
const value = useMemo(() => ({
|
|
11421
|
+
dropzone: {
|
|
11422
|
+
maxSize: options == null ? void 0 : options.maximumUploadSize
|
|
11423
|
+
}
|
|
11424
|
+
}), [options == null ? void 0 : options.maximumUploadSize]);
|
|
11425
|
+
return /* @__PURE__ */jsx(ToolOptionsContext.Provider, {
|
|
11426
|
+
value,
|
|
11427
|
+
children
|
|
11428
|
+
});
|
|
11429
|
+
};
|
|
11430
|
+
const useToolOptions = () => {
|
|
11431
|
+
const context = useContext(ToolOptionsContext);
|
|
11432
|
+
if (!context) {
|
|
11433
|
+
throw new Error("useToolOptions must be used within an ToolOptionsProvider");
|
|
11434
|
+
}
|
|
11435
|
+
return context;
|
|
11436
|
+
};
|
|
11414
11437
|
var __freeze$1 = Object.freeze;
|
|
11415
11438
|
var __defProp$1 = Object.defineProperty;
|
|
11416
11439
|
var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
|
|
@@ -11434,6 +11457,11 @@ const UploadDropzone = props => {
|
|
|
11434
11457
|
const {
|
|
11435
11458
|
children
|
|
11436
11459
|
} = props;
|
|
11460
|
+
const {
|
|
11461
|
+
dropzone: {
|
|
11462
|
+
maxSize
|
|
11463
|
+
}
|
|
11464
|
+
} = useToolOptions();
|
|
11437
11465
|
const {
|
|
11438
11466
|
onSelect
|
|
11439
11467
|
} = useAssetSourceActions();
|
|
@@ -11446,6 +11474,25 @@ const UploadDropzone = props => {
|
|
|
11446
11474
|
forceAsAssetType: assetTypes.length === 1 ? assetTypes[0] : void 0
|
|
11447
11475
|
})));
|
|
11448
11476
|
};
|
|
11477
|
+
const handleDropRejected = rejections => {
|
|
11478
|
+
const errorCodes = rejections.flatMap(_ref71 => {
|
|
11479
|
+
let {
|
|
11480
|
+
errors
|
|
11481
|
+
} = _ref71;
|
|
11482
|
+
return errors.map(_ref72 => {
|
|
11483
|
+
let {
|
|
11484
|
+
code
|
|
11485
|
+
} = _ref72;
|
|
11486
|
+
return code;
|
|
11487
|
+
});
|
|
11488
|
+
});
|
|
11489
|
+
if (errorCodes.includes("file-too-large")) {
|
|
11490
|
+
dispatch(notificationsActions.add({
|
|
11491
|
+
status: "error",
|
|
11492
|
+
title: "One or more files exceed the maximum upload size."
|
|
11493
|
+
}));
|
|
11494
|
+
}
|
|
11495
|
+
};
|
|
11449
11496
|
const handleFileGetter = async event => {
|
|
11450
11497
|
var _a2;
|
|
11451
11498
|
let fileList;
|
|
@@ -11482,7 +11529,9 @@ const UploadDropzone = props => {
|
|
|
11482
11529
|
// HACK: Disable drag and drop functionality when in a selecting context
|
|
11483
11530
|
// (This is currently due to Sanity's native image input taking precedence with drag and drop)
|
|
11484
11531
|
noDrag: !!onSelect,
|
|
11485
|
-
onDrop: handleDrop
|
|
11532
|
+
onDrop: handleDrop,
|
|
11533
|
+
maxSize,
|
|
11534
|
+
onDropRejected: handleDropRejected
|
|
11486
11535
|
});
|
|
11487
11536
|
return /* @__PURE__ */jsx(DropzoneDispatchProvider, {
|
|
11488
11537
|
open,
|
|
@@ -11515,10 +11564,10 @@ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
|
|
|
11515
11564
|
value: __freeze(raw || cooked.slice())
|
|
11516
11565
|
}));
|
|
11517
11566
|
var _a, _b;
|
|
11518
|
-
const BrowserContent =
|
|
11567
|
+
const BrowserContent = _ref73 => {
|
|
11519
11568
|
let {
|
|
11520
11569
|
onClose
|
|
11521
|
-
} =
|
|
11570
|
+
} = _ref73;
|
|
11522
11571
|
const client = useVersionedClient();
|
|
11523
11572
|
const [portalElement, setPortalElement] = useState(null);
|
|
11524
11573
|
const dispatch = useDispatch();
|
|
@@ -11682,12 +11731,20 @@ const useRootPortalElement = () => {
|
|
|
11682
11731
|
}, [container]);
|
|
11683
11732
|
return container;
|
|
11684
11733
|
};
|
|
11685
|
-
const Tool =
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11734
|
+
const Tool = _ref74 => {
|
|
11735
|
+
let {
|
|
11736
|
+
tool: {
|
|
11737
|
+
options
|
|
11738
|
+
}
|
|
11739
|
+
} = _ref74;
|
|
11740
|
+
return /* @__PURE__ */jsx(ToolOptionsProvider, {
|
|
11741
|
+
options,
|
|
11742
|
+
children: /* @__PURE__ */jsx(Flex, {
|
|
11743
|
+
direction: "column",
|
|
11744
|
+
height: "fill",
|
|
11745
|
+
flex: 1,
|
|
11746
|
+
children: /* @__PURE__ */jsx(Browser, {})
|
|
11747
|
+
})
|
|
11691
11748
|
});
|
|
11692
11749
|
};
|
|
11693
11750
|
var mediaTag = {
|
|
@@ -11724,11 +11781,7 @@ const mediaAssetSource = {
|
|
|
11724
11781
|
...plugin,
|
|
11725
11782
|
component: FormBuilderTool
|
|
11726
11783
|
};
|
|
11727
|
-
const
|
|
11728
|
-
...plugin,
|
|
11729
|
-
component: Tool
|
|
11730
|
-
};
|
|
11731
|
-
const media = definePlugin({
|
|
11784
|
+
const media = definePlugin(options => ({
|
|
11732
11785
|
name: "media",
|
|
11733
11786
|
form: {
|
|
11734
11787
|
file: {
|
|
@@ -11746,8 +11799,12 @@ const media = definePlugin({
|
|
|
11746
11799
|
types: [mediaTag]
|
|
11747
11800
|
},
|
|
11748
11801
|
tools: prev => {
|
|
11749
|
-
return [...prev,
|
|
11802
|
+
return [...prev, {
|
|
11803
|
+
...plugin,
|
|
11804
|
+
options,
|
|
11805
|
+
component: Tool
|
|
11806
|
+
}];
|
|
11750
11807
|
}
|
|
11751
|
-
});
|
|
11808
|
+
}));
|
|
11752
11809
|
export { media, mediaAssetSource };
|
|
11753
11810
|
//# sourceMappingURL=index.esm.js.map
|