sanity-plugin-media 2.2.5 → 2.3.1
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 +16 -3
- package/dist/index.esm.js +64 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +63 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/UploadDropzone/index.tsx +22 -2
- package/src/contexts/ToolOptionsContext.tsx +32 -0
- package/src/index.ts +2 -44
- package/src/plugin.tsx +53 -0
- package/src/types/index.ts +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {AssetSourceComponentProps} from 'sanity'
|
|
2
|
+
import {JSX as JSX_2} from 'react/jsx-runtime'
|
|
2
3
|
import {Plugin as Plugin_2} from 'sanity'
|
|
4
|
+
import {default as React_2} from 'react'
|
|
3
5
|
|
|
4
|
-
export declare const media: Plugin_2<void>
|
|
6
|
+
export declare const media: Plugin_2<void | MediaToolOptions>
|
|
5
7
|
|
|
6
|
-
export declare const mediaAssetSource:
|
|
8
|
+
export declare const mediaAssetSource: {
|
|
9
|
+
component: (props: AssetSourceComponentProps) => JSX_2.Element
|
|
10
|
+
icon: React_2.ForwardRefExoticComponent<
|
|
11
|
+
Omit<React_2.SVGProps<SVGSVGElement>, 'ref'> & React_2.RefAttributes<SVGSVGElement>
|
|
12
|
+
>
|
|
13
|
+
name: string
|
|
14
|
+
title: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare type MediaToolOptions = {
|
|
18
|
+
maximumUploadSize?: number
|
|
19
|
+
}
|
|
7
20
|
|
|
8
21
|
export {}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
|
3
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useClient, useColorScheme, useSchema, Preview, useDocumentStore, WithReferringDocuments, useFormValue, definePlugin } from 'sanity';
|
|
3
|
+
import { forwardRef, createElement, useRef, useCallback, useEffect, createContext, useContext, useState, memo, Component, useMemo } from 'react';
|
|
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';
|
|
6
6
|
import groq from 'groq';
|
|
@@ -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();
|
|
@@ -11728,8 +11777,16 @@ const tool = {
|
|
|
11728
11777
|
...plugin,
|
|
11729
11778
|
component: Tool
|
|
11730
11779
|
};
|
|
11731
|
-
const media = definePlugin({
|
|
11780
|
+
const media = definePlugin(options => ({
|
|
11732
11781
|
name: "media",
|
|
11782
|
+
studio: {
|
|
11783
|
+
components: {
|
|
11784
|
+
layout: props => /* @__PURE__ */jsx(ToolOptionsProvider, {
|
|
11785
|
+
options,
|
|
11786
|
+
children: props.renderDefault(props)
|
|
11787
|
+
})
|
|
11788
|
+
}
|
|
11789
|
+
},
|
|
11733
11790
|
form: {
|
|
11734
11791
|
file: {
|
|
11735
11792
|
assetSources: prev => {
|
|
@@ -11748,6 +11805,6 @@ const media = definePlugin({
|
|
|
11748
11805
|
tools: prev => {
|
|
11749
11806
|
return [...prev, tool];
|
|
11750
11807
|
}
|
|
11751
|
-
});
|
|
11808
|
+
}));
|
|
11752
11809
|
export { media, mediaAssetSource };
|
|
11753
11810
|
//# sourceMappingURL=index.esm.js.map
|