sanity-plugin-media 2.2.4 → 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/LICENSE +1 -1
- 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 +4 -3
- 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.js
CHANGED
|
@@ -11451,6 +11451,29 @@ const TagsPanel = () => {
|
|
|
11451
11451
|
})
|
|
11452
11452
|
});
|
|
11453
11453
|
};
|
|
11454
|
+
const ToolOptionsContext = react.createContext(null);
|
|
11455
|
+
const ToolOptionsProvider = _ref70 => {
|
|
11456
|
+
let {
|
|
11457
|
+
options,
|
|
11458
|
+
children
|
|
11459
|
+
} = _ref70;
|
|
11460
|
+
const value = react.useMemo(() => ({
|
|
11461
|
+
dropzone: {
|
|
11462
|
+
maxSize: options == null ? void 0 : options.maximumUploadSize
|
|
11463
|
+
}
|
|
11464
|
+
}), [options == null ? void 0 : options.maximumUploadSize]);
|
|
11465
|
+
return /* @__PURE__ */jsxRuntime.jsx(ToolOptionsContext.Provider, {
|
|
11466
|
+
value,
|
|
11467
|
+
children
|
|
11468
|
+
});
|
|
11469
|
+
};
|
|
11470
|
+
const useToolOptions = () => {
|
|
11471
|
+
const context = react.useContext(ToolOptionsContext);
|
|
11472
|
+
if (!context) {
|
|
11473
|
+
throw new Error("useToolOptions must be used within an ToolOptionsProvider");
|
|
11474
|
+
}
|
|
11475
|
+
return context;
|
|
11476
|
+
};
|
|
11454
11477
|
var __freeze$1 = Object.freeze;
|
|
11455
11478
|
var __defProp$1 = Object.defineProperty;
|
|
11456
11479
|
var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
|
|
@@ -11474,6 +11497,11 @@ const UploadDropzone = props => {
|
|
|
11474
11497
|
const {
|
|
11475
11498
|
children
|
|
11476
11499
|
} = props;
|
|
11500
|
+
const {
|
|
11501
|
+
dropzone: {
|
|
11502
|
+
maxSize
|
|
11503
|
+
}
|
|
11504
|
+
} = useToolOptions();
|
|
11477
11505
|
const {
|
|
11478
11506
|
onSelect
|
|
11479
11507
|
} = useAssetSourceActions();
|
|
@@ -11486,6 +11514,25 @@ const UploadDropzone = props => {
|
|
|
11486
11514
|
forceAsAssetType: assetTypes.length === 1 ? assetTypes[0] : void 0
|
|
11487
11515
|
})));
|
|
11488
11516
|
};
|
|
11517
|
+
const handleDropRejected = rejections => {
|
|
11518
|
+
const errorCodes = rejections.flatMap(_ref71 => {
|
|
11519
|
+
let {
|
|
11520
|
+
errors
|
|
11521
|
+
} = _ref71;
|
|
11522
|
+
return errors.map(_ref72 => {
|
|
11523
|
+
let {
|
|
11524
|
+
code
|
|
11525
|
+
} = _ref72;
|
|
11526
|
+
return code;
|
|
11527
|
+
});
|
|
11528
|
+
});
|
|
11529
|
+
if (errorCodes.includes("file-too-large")) {
|
|
11530
|
+
dispatch(notificationsActions.add({
|
|
11531
|
+
status: "error",
|
|
11532
|
+
title: "One or more files exceed the maximum upload size."
|
|
11533
|
+
}));
|
|
11534
|
+
}
|
|
11535
|
+
};
|
|
11489
11536
|
const handleFileGetter = async event => {
|
|
11490
11537
|
var _a2;
|
|
11491
11538
|
let fileList;
|
|
@@ -11522,7 +11569,9 @@ const UploadDropzone = props => {
|
|
|
11522
11569
|
// HACK: Disable drag and drop functionality when in a selecting context
|
|
11523
11570
|
// (This is currently due to Sanity's native image input taking precedence with drag and drop)
|
|
11524
11571
|
noDrag: !!onSelect,
|
|
11525
|
-
onDrop: handleDrop
|
|
11572
|
+
onDrop: handleDrop,
|
|
11573
|
+
maxSize,
|
|
11574
|
+
onDropRejected: handleDropRejected
|
|
11526
11575
|
});
|
|
11527
11576
|
return /* @__PURE__ */jsxRuntime.jsx(DropzoneDispatchProvider, {
|
|
11528
11577
|
open,
|
|
@@ -11555,10 +11604,10 @@ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
|
|
|
11555
11604
|
value: __freeze(raw || cooked.slice())
|
|
11556
11605
|
}));
|
|
11557
11606
|
var _a, _b;
|
|
11558
|
-
const BrowserContent =
|
|
11607
|
+
const BrowserContent = _ref73 => {
|
|
11559
11608
|
let {
|
|
11560
11609
|
onClose
|
|
11561
|
-
} =
|
|
11610
|
+
} = _ref73;
|
|
11562
11611
|
const client = useVersionedClient();
|
|
11563
11612
|
const [portalElement, setPortalElement] = react.useState(null);
|
|
11564
11613
|
const dispatch = reactRedux.useDispatch();
|
|
@@ -11722,12 +11771,20 @@ const useRootPortalElement = () => {
|
|
|
11722
11771
|
}, [container]);
|
|
11723
11772
|
return container;
|
|
11724
11773
|
};
|
|
11725
|
-
const Tool =
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
|
|
11730
|
-
|
|
11774
|
+
const Tool = _ref74 => {
|
|
11775
|
+
let {
|
|
11776
|
+
tool: {
|
|
11777
|
+
options
|
|
11778
|
+
}
|
|
11779
|
+
} = _ref74;
|
|
11780
|
+
return /* @__PURE__ */jsxRuntime.jsx(ToolOptionsProvider, {
|
|
11781
|
+
options,
|
|
11782
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
11783
|
+
direction: "column",
|
|
11784
|
+
height: "fill",
|
|
11785
|
+
flex: 1,
|
|
11786
|
+
children: /* @__PURE__ */jsxRuntime.jsx(Browser, {})
|
|
11787
|
+
})
|
|
11731
11788
|
});
|
|
11732
11789
|
};
|
|
11733
11790
|
var mediaTag = {
|
|
@@ -11764,11 +11821,7 @@ const mediaAssetSource = {
|
|
|
11764
11821
|
...plugin,
|
|
11765
11822
|
component: FormBuilderTool
|
|
11766
11823
|
};
|
|
11767
|
-
const
|
|
11768
|
-
...plugin,
|
|
11769
|
-
component: Tool
|
|
11770
|
-
};
|
|
11771
|
-
const media = sanity.definePlugin({
|
|
11824
|
+
const media = sanity.definePlugin(options => ({
|
|
11772
11825
|
name: "media",
|
|
11773
11826
|
form: {
|
|
11774
11827
|
file: {
|
|
@@ -11786,9 +11839,13 @@ const media = sanity.definePlugin({
|
|
|
11786
11839
|
types: [mediaTag]
|
|
11787
11840
|
},
|
|
11788
11841
|
tools: prev => {
|
|
11789
|
-
return [...prev,
|
|
11842
|
+
return [...prev, {
|
|
11843
|
+
...plugin,
|
|
11844
|
+
options,
|
|
11845
|
+
component: Tool
|
|
11846
|
+
}];
|
|
11790
11847
|
}
|
|
11791
|
-
});
|
|
11848
|
+
}));
|
|
11792
11849
|
exports.media = media;
|
|
11793
11850
|
exports.mediaAssetSource = mediaAssetSource;
|
|
11794
11851
|
//# sourceMappingURL=index.js.map
|