sanity-plugin-r2-video 0.1.10 → 0.1.11
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/studio/index.js +69 -9
- package/package.json +1 -1
package/dist/studio/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveRenditionPath } from '../chunk-D5VS4ED7.js';
|
|
2
2
|
export { resolveRenditionPath } from '../chunk-D5VS4ED7.js';
|
|
3
|
-
import { createContext, useState, useCallback, useEffect, useRef, useMemo, useId, useContext } from 'react';
|
|
3
|
+
import { createContext, useState, useCallback, useEffect, Fragment, useRef, useMemo, useId, useContext } from 'react';
|
|
4
4
|
import { defineType, defineField, definePlugin, set, useClient } from 'sanity';
|
|
5
5
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
6
|
import { PlayIcon } from '@sanity/icons/Play';
|
|
@@ -11,9 +11,12 @@ import { canEncodeVideo } from 'mediabunny';
|
|
|
11
11
|
import { WarningOutlineIcon } from '@sanity/icons/WarningOutline';
|
|
12
12
|
import { ChevronDownIcon } from '@sanity/icons/ChevronDown';
|
|
13
13
|
import { ChevronRightIcon } from '@sanity/icons/ChevronRight';
|
|
14
|
+
import { CheckmarkIcon } from '@sanity/icons/Checkmark';
|
|
15
|
+
import { FilterIcon } from '@sanity/icons/Filter';
|
|
14
16
|
import { SearchIcon } from '@sanity/icons/Search';
|
|
15
17
|
import { SyncIcon } from '@sanity/icons/Sync';
|
|
16
18
|
import { TrashIcon } from '@sanity/icons/Trash';
|
|
19
|
+
import { MenuButton, Menu, MenuDivider, MenuItem } from '@sanity/ui/menu';
|
|
17
20
|
import styled from 'styled-components';
|
|
18
21
|
import { FolderIcon } from '@sanity/icons/Folder';
|
|
19
22
|
|
|
@@ -1775,6 +1778,40 @@ var matches = (asset, search) => {
|
|
|
1775
1778
|
const folderName = asset.folderName ?? "";
|
|
1776
1779
|
return asset.filename.toLowerCase().includes(term) || folderName.toLowerCase().includes(term);
|
|
1777
1780
|
};
|
|
1781
|
+
var FILTERS = [
|
|
1782
|
+
{
|
|
1783
|
+
key: "foldered",
|
|
1784
|
+
group: "folder",
|
|
1785
|
+
label: "In a folder",
|
|
1786
|
+
test: (asset) => Boolean(asset.folder)
|
|
1787
|
+
},
|
|
1788
|
+
{
|
|
1789
|
+
key: "unfoldered",
|
|
1790
|
+
group: "folder",
|
|
1791
|
+
label: "No folder",
|
|
1792
|
+
test: (asset) => !asset.folder
|
|
1793
|
+
},
|
|
1794
|
+
{
|
|
1795
|
+
key: "used",
|
|
1796
|
+
group: "usage",
|
|
1797
|
+
label: "In use",
|
|
1798
|
+
test: (asset) => asset.isUsed
|
|
1799
|
+
},
|
|
1800
|
+
{
|
|
1801
|
+
key: "unused",
|
|
1802
|
+
group: "usage",
|
|
1803
|
+
label: "Unused",
|
|
1804
|
+
test: (asset) => !asset.isUsed
|
|
1805
|
+
}
|
|
1806
|
+
];
|
|
1807
|
+
var FILTER_GROUPS = [...new Set(FILTERS.map((filter) => filter.group))];
|
|
1808
|
+
var passesFilters = (asset, keys) => {
|
|
1809
|
+
const active = FILTERS.filter((filter) => keys.includes(filter.key));
|
|
1810
|
+
return FILTER_GROUPS.every((group) => {
|
|
1811
|
+
const inGroup = active.filter((filter) => filter.group === group);
|
|
1812
|
+
return inGroup.length === 0 || inGroup.some((filter) => filter.test(asset));
|
|
1813
|
+
});
|
|
1814
|
+
};
|
|
1778
1815
|
var SelectableCard = styled(Box)`
|
|
1779
1816
|
position: relative;
|
|
1780
1817
|
|
|
@@ -1800,7 +1837,7 @@ var ToolVideoLibrary = () => {
|
|
|
1800
1837
|
const [droppedFiles, setDroppedFiles] = useState([]);
|
|
1801
1838
|
const [detailing, setDetailing] = useState(null);
|
|
1802
1839
|
const [deleting, setDeleting] = useState(null);
|
|
1803
|
-
const [
|
|
1840
|
+
const [filterKeys, setFilterKeys] = useState([]);
|
|
1804
1841
|
const [selectedIds, setSelectedIds] = useState([]);
|
|
1805
1842
|
const [isMoving, setIsMoving] = useState(false);
|
|
1806
1843
|
const load = useCallback(() => {
|
|
@@ -1832,10 +1869,14 @@ var ToolVideoLibrary = () => {
|
|
|
1832
1869
|
};
|
|
1833
1870
|
const visible = (assets ?? []).filter((asset) => {
|
|
1834
1871
|
const inFolder = !folderId || asset.folder && asset.folder._ref === folderId;
|
|
1835
|
-
|
|
1836
|
-
return matches(asset, search) && inFolder && isShown;
|
|
1872
|
+
return matches(asset, search) && inFolder && passesFilters(asset, filterKeys);
|
|
1837
1873
|
});
|
|
1838
1874
|
const selected = visible.filter((asset) => selectedIds.includes(asset._id));
|
|
1875
|
+
const toggleFilter = (key) => {
|
|
1876
|
+
setFilterKeys((current) => {
|
|
1877
|
+
return current.includes(key) ? current.filter((entry) => entry !== key) : [...current, key];
|
|
1878
|
+
});
|
|
1879
|
+
};
|
|
1839
1880
|
const toggleSelected = (id) => {
|
|
1840
1881
|
setSelectedIds((current) => {
|
|
1841
1882
|
return current.includes(id) ? current.filter((entry) => entry !== id) : [...current, id];
|
|
@@ -1883,12 +1924,31 @@ var ToolVideoLibrary = () => {
|
|
|
1883
1924
|
}
|
|
1884
1925
|
) }),
|
|
1885
1926
|
/* @__PURE__ */ jsx(
|
|
1886
|
-
|
|
1927
|
+
MenuButton,
|
|
1887
1928
|
{
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1929
|
+
button: /* @__PURE__ */ jsx(
|
|
1930
|
+
Button,
|
|
1931
|
+
{
|
|
1932
|
+
icon: FilterIcon,
|
|
1933
|
+
mode: filterKeys.length > 0 ? "default" : "ghost",
|
|
1934
|
+
text: filterKeys.length > 0 ? `Filters (${filterKeys.length})` : "Filters",
|
|
1935
|
+
tone: filterKeys.length > 0 ? "primary" : "default"
|
|
1936
|
+
}
|
|
1937
|
+
),
|
|
1938
|
+
id: "r2-video-filters",
|
|
1939
|
+
menu: /* @__PURE__ */ jsx(Menu, { children: FILTERS.map((filter, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1940
|
+
index > 0 && FILTERS[index - 1].group !== filter.group && /* @__PURE__ */ jsx(MenuDivider, {}),
|
|
1941
|
+
/* @__PURE__ */ jsx(
|
|
1942
|
+
MenuItem,
|
|
1943
|
+
{
|
|
1944
|
+
iconRight: filterKeys.includes(filter.key) ? CheckmarkIcon : void 0,
|
|
1945
|
+
pressed: filterKeys.includes(filter.key),
|
|
1946
|
+
text: filter.label,
|
|
1947
|
+
onClick: () => toggleFilter(filter.key)
|
|
1948
|
+
}
|
|
1949
|
+
)
|
|
1950
|
+
] }, filter.key)) }),
|
|
1951
|
+
popover: { placement: "bottom-start" }
|
|
1892
1952
|
}
|
|
1893
1953
|
),
|
|
1894
1954
|
/* @__PURE__ */ jsx(
|