Coder Social home page Coder Social logo

sanity-plugin-media's Introduction

Sanity Media (for Sanity Studio v3)

This plugin is for Sanity Studio v3.
The Sanity Studio v2 version of this plugin is no longer maintained, but still accessible on the v2 branch.

What is it?

npm-v npm-dw

A convenient way to browse, manage and refine your Sanity assets.

Use it standalone as a browser, or optionally hook it up as a custom asset source and use it to power both image and file selection too.

Grid view Default grid view

Asset view Individual asset view

Features

Manage and organise your assets

  • Support for batch uploads with drag and drop support
  • Edit text fields native to Sanity's asset documents, such as title, description, altText and originalFilename
  • View asset metadata and a limited subset of EXIF data, if present
  • Tag your assets individually or in bulk
  • Manage tags directly within the plugin
  • Get previews for audio and video files
  • Easily select and delete multiple assets in bulk

Granular search tools

  • Refine your search with any combination of search facets such as filtering by tag name, asset usage, file size, orientation, type (and more)
  • Use text search for a quick lookup by title, description and alt text

Built for large datasets and collaborative editing in mind

  • Virtualized grid + tabular views for super speedy browsing, even with thousands of assets and tags
  • Utilises Sanity's real time updates for live changes from other studio members

Fits right in with your Sanity studio

Install (Sanity Studio v3)

In your Sanity project folder:

npm install --save sanity-plugin-media

or

yarn add sanity-plugin-media

Usage

Add it as a plugin in your sanity.config.ts (or .js) file:

import {media} from 'sanity-plugin-media'

export default defineConfig({
  // ...
  plugins: [media()]
})

This will enable the Media plugin as both a standalone tool (accessible in your studio menu) and as an additional asset source for your image and file fields.

Customizing the asset source

You can configure your studio to use this asset source either exclusively, or conditionally enable it based on the type of asset (image or file).

import {media, mediaAssetSource} from 'sanity-plugin-media'

export default defineConfig({
  // ...
  plugins: [media()],
  form: {
    // Don't use this plugin when selecting files only (but allow all other enabled asset sources)
    file: {
      assetSources: previousAssetSources => {
        return previousAssetSources.filter(assetSource => assetSource !== mediaAssetSource)
      }
    }
  }
})

Known issues

There isn't a way to edit asset fields directly from the desk (without opening the plugin)
  • This is a bit of a sticking point, especially when working with large datasets
  • For example, if you want to edit fields for an already selected image – you'll need to go into the plugin and then have to manually find that image (which can be laborious when sifting through thousands of assets)
  • A future update will provide the ability to 'jump' straight to a selected asset
  • However, exposing plugin fields directly on the desk (e.g. via a custom input component) is currently outside the scope of this project
Drag and drop uploads don't work when selecting with the plugin
  • This is currently due to Sanity studio's file picker component taking precedence over window drag and drop events
  • For now, you'll need to manually press the 'upload' button if you want to add images whilst in a selecting context
Downloaded images (downloaded with the download button) aren't the originally uploaded files
  • Any images downloaded in the plugin are those already processed by Sanity without any image transformations applied
  • Please note these are not the original uploaded images: they will likely have a smaller file size and will be stripped of any EXIF data.
  • Currently, it's not possible in Sanity to grab these original image assets within the studio - but this may change in future!
Limitations when using Sanity's GraphQL endpoints
  • Currently, opt.media.tags on assets aren't accessible via GraphQL. This is because opt is a custom object used by this plugin and not part of Sanity's asset schema.

FAQ

Asset fields

Where are asset fields stored?
  • This plugin will read and write directly on the asset document itself. This will either a document of type sanity.imageAsset or sanity.fileAsset
  • This is analagous to setting values globally across all instances of these assets
  • This is in contrast to using the fields property when defining your document schema (on both image and file objects). Values that you define in the fields property can be considered 'local', or bound to the the document where that asset is linked.
  • In other words, if you want to set a caption for an image and have that change between different documents – customise the fields property in your document schema's file/image field
  • If you want to set values you can query in all instances of that asset (alternate text being a good example), consider setting those in the plugin
How can I query asset fields I've set in this plugin?

The following GROQ query will return an image with additional asset text fields as well as an array of tag names.

Note that tags are namespaced within opt.media and tag names are accessed via the current property (as they're defined as slugs on the tag.media document schema).

*[_id == 'my-document-id'] {
  image {
    asset->{
      _ref,
      _type,
      altText,
      description,
      "tags": opt.media.tags[]->name.current,
      title
    }
  }
}
What EXIF fields are displayed and how can I get these to show up?
  • ISO, aperture, focal length, exposure time and original date are displayed
  • By default, Sanity won't automatically extract EXIF data unless you explicitly tell it to
  • Manually tell Sanity to process EXIF metadata by updating your image field options accordingly
  • Note that all images uploaded directly within the plugin will include all metadata by default

Tags

How and where are asset tags stored?
  • This plugin defines the document type media.tag
  • All tags are stored as weak references and being a third-party plugin, are stored in the namespaced object opt.media
  • This behaviour differs from asset fields such as title, description and altText which are stored directly on the asset as they're part of Sanity's defined asset schema
How can I hide the Media Tag document type which has now appeared in my desk?
  • If you're not using a custom desk, Sanity attaches custom schema defined by third party plugins to your desk. This is currently the default behaviour
  • However, you can override this behaviour by defining your own custom desk with Sanity's structure builder and simply omit the media.tag document type in your definition
How can I edit and / or delete tags I've already created?
  • You can create, rename and delete tags from directly within the plugin itself
  • It is strongly recommended that you manually delete tags directly from within the plugin – doing so will ensure that (weak) references are removed from any linked assets
  • Alternatively, you can delete tags either from the desk (if you're not using a custom desk) or via Sanity's API – just be mindful that any assets previously assigned to deleted tags will have 'hanging' weak references. This won't cause serious issues, but it may cause some false positives when searching. (E.g. a search for 'all assets where tags is not empty' will yield assets that have references to tags that no longer exist)

Deleting assets

Why am I unable to delete multiple assets, even if only one asset is in use?
  • Batch mutations are carried out via Sanity transactions. These transactions are atomic, meaning that if one deletion fails (often because it's referenced elsewhere), then all mutations in the transaction will fail and no changes will occur
  • To get around this, simply make sure that all assets you've marked for deletion are not referenced – this can be easily accomplished by using a search facet to only show assets which are not in use

Uploading assets

How does the plugin determine what should uploaded as a sanity.imageAsset or sanity.fileAsset?
  • As a rule of thumb, when uploading when accessing the plugin as a tool (e.g. if you've acceessed it via the studio menu), it will look at any incoming files' MIME type. All files of type image/* will be uploaded as sanity.imageAsset whilst everything else will be treated as sanity.fileAsset
  • If you upload when using the plugin in a file selection context, these be uploaded as sanity.fileAsset regardless of their MIME type. This is probably not what you want, since images uploaded as files won't have associated metadata nor will they work in Sanity's image pipeline.

Contributing

Contributions, issues and feature requests are welcome!

License

MIT © Sanity.io

Develop & test

This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.

See Testing a plugin in Sanity Studio on how to run this plugin with hot-reload in the studio.

Release new version

Run the "CI & Release" workflow. Make sure to select the main branch and check "Release new version".

Semantic release will only release on configured branches, so it is safe to run the workflow on any branch.

sanity-plugin-media's People

Contributors

bjoerge avatar coreyward avatar dependabot[bot] avatar grsmto avatar hahlh avatar hdoro avatar nickrttn avatar nkgentile avatar r3nanp avatar renovate[bot] avatar rexxars avatar robinpyon avatar semantic-release-bot avatar simeongriggs avatar snorrees avatar stipsan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sanity-plugin-media's Issues

Support for rxjs 7.x.x

rxjs is listed as a peer dependency in package.json
"rxjs": "^6.5.3",

It would be nice to support newer versions for rxjs. With
"rxjs": "^7.5.4", in our code base, the media tab will crash with the following error

Scheduler.js:10 
        
Uncaught TypeError: this.schedulerActionCtor is not a constructor
    at QueueScheduler.Scheduler.schedule (Scheduler.js:10:1)
    at executeSchedule (executeSchedule.js:4:1)
    at observeOn.js:7:1
    at OperatorSubscriber._this._next (OperatorSubscriber.js:15:1)
    at OperatorSubscriber.Subscriber.next (Subscriber.js:34:1)
    at Subject.js:41:1
    at errorContext (errorContext.js:19:1)
    at Subject.next (Subject.js:31:1)
    at AnonymousSubject.next (Subject.js:145:1)
    at createEpicMiddleware.js:58:1

How to upload images without optimization?

Hello.
I'm working with sprite images and if the width is more than 8192px width it resizes it to fit this width.
For example, if I have an image with dimensions 13560 x 438px (it's around 6 MP, 312 KB )
then it resizes it to 8192 x 265 (2.17 MP, 197KB).
Is it possible to let such images upload without optimization?

Thanks.

[Feature Request] - Filtering by multiple tags

Unless I'm missing something I believe assets can only be filtered by one tag type. It would be really useful (and we have this use case in the company I work for).

e.g.

photo_a | tags: 'animal', 'funny'
photo_b | tags: 'animal'
photo_c | tags: 'funny'

It should be possible to add two tags to the filter and narrow your results to just photo_a

TypeError: Y.definePlugin is not a function

error - TypeError: Y.definePlugin is not a function at Object.<anonymous> (/Users/logangelzer/logo-media-sanityv3/logo-media-sanityv3/node_modules/sanity-plugin-media/lib/index.js:1:110321) at Module._compile (node:internal/modules/cjs/loader:1097:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:999:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.sanity-plugin-media (/Users/logangelzer/logo-media-sanityv3/logo-media-sanityv3/.next/server/pages/admin/[[...index]].js:282:18) at __webpack_require__ (/Users/logangelzer/logo-media-sanityv3/logo-media-sanityv3/.next/server/webpack-runtime.js:33:42) at eval (webpack-internal:///./sanity.config.ts:13:77) { page: '/admin/[[...index]]' }

last item in menuFacets is not rendered

While working on #56, I noticed that the last item in the list of filters (in this case height) is not being rendered.

Doesn't seem to be specific to the config of the height filter, because adding an additional item to the end of the list will then render the height filter but not the newly added last item.

Issues uploading images

Hi there

I am using your media tool to load ecommerce images into Sanity but I am occasionally hitting issues and errors:

TypeError: Cannot read properties of undefined (reading 'asset')

Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Great tool though. Very helpful!

Steve

Saving tags to an image asset crashes studio

  1. Either have a ready tag or make it inline in the Individual asset view.
  2. Select the tag on the asset, click save
  3. React loop detection massive crash

Nevertheless, the tag is persisted to the asset as it becomes a search result under the tag.

However, attempting to edit the asset now leads to a similar looking stack trace crash.

sanity-plugin-media 1.4.9
sanity stuff 2.30.1 (latest as of today)

I'm not sure the stack trace is very helpful, but the error seems to be an infinite loop on state changes and hooks/lifecycle methods in the react-select library.

Stack trace:
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
at checkForNestedUpdates (/static/js/vendor.bundle.js:26235:15)
at scheduleUpdateOnFiber (/static/js/vendor.bundle.js:24306:3)
at dispatchAction (/static/js/vendor.bundle.js:18802:5)
at Object.set (/static/js/app.bundle.js:67509:25)
at http://localhost:3333/static/js/app.bundle.js:66489:23
at registerFieldRef (/static/js/app.bundle.js:66869:17)
at register (/static/js/app.bundle.js:66900:17)
at http://localhost:3333/static/js/app.bundle.js:67503:13
at http://localhost:3333/static/js/app.bundle.js:67533:9
at commitHookEffectListMount (/static/js/vendor.bundle.js:22873:26)

The above error occurred in the component:
in Controller (created by FormFieldInputTags)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by FormFieldInputTags)
in FormFieldInputTags (created by DialogAssetEdit)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(Stack))
in ForwardRef(Stack) (created by DialogAssetEdit)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by ForwardRef(TabPanel))
in ForwardRef(TabPanel) (created by DialogAssetEdit)
in form (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by DialogAssetEdit)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by DialogAssetEdit)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(Flex))
in ForwardRef(Flex) (created by DialogAssetEdit)
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(DialogCard))
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(Flex))
in ForwardRef(Flex) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(DialogCard))
in div (created by styled.div)
in styled.div (created by ForwardRef(Box))
in ForwardRef(Box) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(Card))
in Fe (created by ThemeProvider)
in ThemeProvider (created by ThemeColorProvider)
in ThemeColorProvider (created by ForwardRef(Card))
in ForwardRef(Card) (created by Styled(Component))
in Styled(Component) (created by ForwardRef(DialogCard))
in div (created by styled.div)

Warning message in console when running `sanity start`

I'm seeing this error in the terminal each time a file is saved/reloaded:

Warning in ./node_modules/sanity-plugin-media/node_modules/framer-motion/dist/framer-motion.es.js
743:18-24 "export 'filter' was not found in 'style-value-types'

Using v1.0.1:

sanity-plugin-media@^1.0.1:
  version "1.0.1"
  resolved "https://registry.yarnpkg.com/sanity-plugin-media/-/sanity-plugin-media-1.0.1.tgz#2c25cf1d82b15a7f6ae09266fc9958c9b65d600f"
  integrity sha512-bs0U8MtoNPUQndv1iCszlWtVhxny6D1bHayB4WEGNJc+l7bnZC/1RWzEJ5yeULRK0bgNvBMjSXrweuEvKy5tUA==
  dependencies:
    "@hookform/resolvers" "2.0.0-beta.3"
    "@sanity/components" "2.1.0"
    "@sanity/icons" "1.0.1"
    "@sanity/ui" "0.32.2"
    "@tanem/react-nprogress" "3.0.52"
    date-fns "2.16.1"
    filesize "6.1.0"
    groq "2.0.9"
    immer "8.0.0"
    is-hotkey "0.2.0"
    pluralize "8.0.0"
    react-file-icon "1.0.0"
    react-hook-form "6.14.0"
    react-redux "7.2.2"
    react-select "3.1.1"
    react-virtualized-auto-sizer "1.0.3"
    react-window "1.8.6"
    react-window-infinite-loader "1.0.5"
    redux "4.0.5"
    redux-devtools-extension "2.13.8"
    redux-observable "1.2.0"
    rxjs "6.6.3"
    styled-components "5.2.1"
    theme-ui "0.3.5"
    typesafe-actions "5.1.0"
    yup "0.32.8"

Studio unable to compile

Hey.

Love the plugin and we're using it on all of our projects.

We get several variation on this error error on our project with this plugin.

It shows up if either the plugin is added to the plugins array in sanity.json or imported/exported in assetSources.js

Warning in ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/node_modules/framer-motion/dist/es/components/AnimatePresence/index.js
123:27-40 "export '__spreadArray' was not found in 'tslib'
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/node_modules/framer-motion/dist/es/components/AnimatePresence/index.js
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/node_modules/framer-motion/dist/es/index.js
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/dist/es/components/toast/toastProvider.js
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/dist/es/components/toast/index.js
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/dist/es/components/index.js
 @ ./node_modules/sanity-plugin-media/node_modules/@sanity/ui/dist/es/index.js
 @ ./node_modules/sanity-plugin-media/dist/app.js
 @ ./node_modules/sanity-plugin-media/dist/index.js
 @ ./node_modules/@sanity/vision/lib/VisionTool.js (all:part:@sanity/base/tool)
 @ ./node_modules/@sanity/default-layout/lib/util/getOrderedTools.js
 @ ./node_modules/@sanity/default-layout/lib/Root.js (part:@sanity/base/root)
 @ ./node_modules/@sanity/base/lib/components/SanityRoot.js (part:@sanity/base/sanity-root)
 @ ./node_modules/@sanity/server/lib/browser/entry-dev.js
 @ multi ./node_modules/@sanity/server/lib/browser/entry-dev.js

This happened after upgrading Sanity. Current version we're using:


  "@sanity/base": "^2.8.1",
  "@sanity/block-content-to-react": "^2.0.7",
  "@sanity/color-input": "^2.2.6",
  "@sanity/components": "^2.2.6",
  "@sanity/core": "^2.8.0",
  "@sanity/default-layout": "^2.8.1",
  "@sanity/default-login": "^2.8.0",
  "@sanity/desk-tool": "^2.8.1",
  "@sanity/production-preview": "^2.2.6",
  "@sanity/vision": "^2.8.0",
  "get-youtube-id": "^1.0.1",
  "prop-types": "^15.7",
  "react": "16.14.0",
  "react-dom": "16.14.0",
  "react-icons": "^3.11.0",
  "react-moveable": "^0.22.6",
  "react-youtube": "^7.13.1",
  "resize-observer": "^1.0.0",
  "sanity-plugin-asset-source-unsplash": "^0.1.3",
  "sanity-plugin-better-slug": "^1.0.0",
  "sanity-plugin-color-list": "^2.0.1",
  "sanity-plugin-media": "^1.2.2",
  "sanity-plugin-media-library": "^1.0.5"

can't select image through plugin (sanity 2.3.8)

With Sanity 2.3.8 it's not possible to select an image through the plugin. When hitting the "select" button, the plugin page opens up but clicking on an image just opens up the image properties (just like if I were to click on it from the plugin's page).

I have another install with sanity 2.3.3 which works just fine. Both sanity instances use "sanity-plugin-media": "^1.0.1"

Media selector closes prematurely when in popover

When using a structure like the following where there is an image field on an object that is in an array, and the array is configured to show in a popover, attempting to select an image from Media fails. The Media window pulls up as expected, but attempting to select an image results in the Media window closing immediately without an error or selection.

{
  // …
  fields: [
    {
      title: "Actions",
      name: "actions",
      type: "array",
      of: [
        {
          type: "object",
          fields: [{ name: "image", type: "image" }],
        },
      ],
    },
  ],
  options: {
    editModal: "popover",
  },
}

Removing the editModal property from options on the object resolves the issue.

Dark images with transparency renders low contrast

We use several image assets with dark or black graphics with transparency, in the media manager these assets become almost illegible due to low contrast. Especially when containing text this becomes an issue, an example is a client logo which contains the company name and is impossible to read. Here's a slightly more legible example which demonstrates the issue (I can't share client logos unfortunately):

image

A couple of suggested solutions

a) In the above instance a solid background-color (e.g. --card-muted-fg-color would look good as it is used for the asset title) would render a better contrast. However, it would fail with images that contain a similar color to --card-muted-fg-color).
b) Another option would be to adapt the checkerboard to use two grays instead of the background color which is so close to black. Again this might fail with gray foregrounds.
c) An option for a light mode? (Maybe this is an option already but I can't find it). A light mode would work better with these assets, however you could foresee someone running into the same type of issue with transparent assets with white foregrounds.

Issue with React hook form

My app already have React Hook Form version 7x, and seems this has a conflict with it.

Warning in /nx/client/node_modules/@hookform/resolvers/yup/dist/yup.module.js
1:1131-1132 "export 'transformToNestObject' (imported as 'e') was not found in 'react-hook-form'
 @ /nx/client/node_modules/@hookform/resolvers/yup/dist/yup.module.js

Greatly appreciated if it got a fix.

Document graphql limitation

This project should probably add a friendly caveat that the tags field on asset documents are not currently visible to the graphql query endpoints, as those fields are not part of the schema for asset documents.

title, description, and altText are, but the opt object with the tags array refs is not.

Library goes on top of the studio nav bar

After upgrading Sanity, when accessing the library by the nav bar we cannot close it as it goes on top of Sanity UI and there is not a close button.

Using:
"@sanity/base": "^2.21.2",
"@sanity/cli": "^2.21.0",
"@sanity/components": "^2.14.0",
"@sanity/core": "^2.21.0",
"@sanity/default-layout": "^2.21.2",
"@sanity/default-login": "^2.21.0",
"@sanity/desk-tool": "^2.21.2",
"@sanity/production-preview": "^2.15.0",
"sanity-plugin-media": "^1.4.0"

Capture d’écran 2021-10-10 à 19 37 32

Can't browse images when selecting an image with a new document that has no Id yet

Hi! Thank you for this awesome plugin. I've encountered an error when selecting an image with a new document whose Id is not yet initialized due no input/changes yet.

{"error":{"description":"Unable to parse value of \"$documentId=undefined\". Please quote string values.","type":"httpBadRequest"}}

The API request:

'https://myprojectid.api.sanity.io/v1/data/query/dataset?query=\n' +
  '    {\n' +
  '      "items"%3A *[_type %3D%3D "sanity.imageAsset"] {\n' +
  '            _id%2C\n' +
  '            _updatedAt%2C\n' +
  '            extension%2C\n' +
  '            metadata {\n' +
  '              dimensions%2C\n' +
  '              isOpaque%2C\n' +
  '            }%2C\n' +
  '            originalFilename%2C\n' +
  '            size%2C\n' +
  '            url\n' +
  '          } | order(_updatedAt desc) [0...50]%2C\n' +
  '    }\n' +
  '  &%24documentId=undefined'

Wrapping undefined with double quotes sends the request successfully.

I have to fill in another field in order to initialize the document's Id (turning it into a draft) before I can open the media library.

plugin broken on mobile

Screenshot 2022-03-07 at 15 31 15

The plugin is working perfectly on PC/mac, but not working on mobile. Any soultion? our editor uses mobile as their primary editing tool

Feature Suggestion: Add `source` field

Source is incredibly important in media. There are legal ramifications if editors aren't correctly adding a source to their assets.

It would be awesome if the dialog/modal was either customizable (without having to fork this plugin) or if being able to add a source came out of the box with this plugin.

Ideally source would be portable text due to the fact that a source might require a link or as is directed by the MLA - some sources should be italicized.

Thanks for considering Rob

Tainted canvas exception when uploading svg file

When I try to upload a svg file to sanity using the "Upload assets" option, it fails to upload and throws this error in the console:
Uncaught DOMException: Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported.

I went through the node package, and modified the "createBlob" function inside /node_modules/sanity-plugin-media/dist/utils/generatePreviewBlobUrl.js, I added img.crossOrigin = "Anonymous"; to the image element being sent to the function and it works fine now, but I'm not sure if that's the right way of fixing this issue.

I include the svg file used for testing.
long_text.svg.zip

Display other asset types

It would be great if the media gallery plugin also displayed other assets (sanity.fileAsset), at least videos.

(Happy to help to implement this feature with some guidance!)

Slow query at scale

First off, thanks a ton @robinpyon for the plugin. Saves us a lot of work!

In the process of migrating over our assets and tag to Sanity (7k assets and 2400 tags) our users' browsers were consistently crashing when accessing the media library. With some digging on the the network tab it looks like this query here is the main issue:

https://github.com/robinpyon/sanity-plugin-media/blob/cfa18eaf3b63828d63df8c5fb962e5877df57a5b/src/modules/tags/index.ts#L155

Pulling back 2400 tags from sanity via GROQ multiple times on page appears to be the crashing point.

I'm wondering if there's a better way here to display the tags to the end user while limiting the amount of tags we're pulling in a single query.

If our team can be of help at all in thinking about a solution don't hesitate to reach out.

Feature request: Helper function to easily get image data

Hi, I would like to get the alt, description and filename data. We can get it with the query

*[_id == 'my-document-id'] {
  image {
    asset->{
      _ref,
      _type,
      altText,
      description,
      "tags": opt.media.tags[]->name.current,
      title
    }
  }
}

However, I have so many queries (also nested). It would be challenging to do this on every image field. Could we somehow create a helper function that I can pass only the image source/ref and it would return me all the related image data?

Something like https://github.com/sanity-io/image-url

Thank you so much!

Error in @floating-ui/dom/dist/floating-ui.dom.esm.js

Came across this issue on a build which seems to come from react select and the media plugin.

Using V2 branch, version ^1.4.14

[1] Module parse failed: Unexpected token (307:11)
[1] You may need an appropriate loader to handle this file type.
[1] |   }
[1] | 
[1] |   return { ...rect,
[1] |     x: rect.x - scroll.scrollLeft + offsets.x,
[1] |     y: rect.y - scroll.scrollTop + offsets.y
[1]  @ ./node_modules/react-select/creatable/dist/react-select-creatable.esm.js 22:0-26
[1]  @ ./node_modules/sanity-plugin-media/dist/components/FormFieldInputTags/index.js

New version suggestion: change `mediaTags` to `media-plugin.tags`

Hey Robin! Love what you're doing since the first release of your asset source, but the new version just takes it to a whole new level 🤯

Quick suggestion: as it stands, tags' _type is mediaTags, which could very easily collide with user-provided types. I highly suggest namespacing whichever types we end up implementing to prevent that. media-plugin.tags is just an idea, of course, I'm not bound to specifics.

If you want, I can do the change myself, let me know 😄

Thanks a ton for the effort \o/

EDIT: I just realized the beta version I was in was old and you already fixed it - great job 🎉

Sorry for opening the issue 😅

Is the "Current Entry" option coming back?

The ability to select from images that are only associated with the current document is really helpful - especially for one of my clients with a massive dataset with thousands of images. Will this be re-implemented in 1.x?

For now, I've reverted to 0.4.0 because this feature is crucial for them.

Plugin contaminating studio form input styles

image

There have been reports of the plugin altering styles of other form fields outside the plugin – from what I can gather, this seems to happen once the media plugin has been opened at least once.

I'd wager that it's possibly linked to a dependency issue with styled-components and/or @sanity/ui, which has since been patched out

For those who are experiencing this issue:

  • Have you tried clearing your node_modules and re-installing all modules? (This has fixed various dependency issues with @sanity/ui in the past)
  • What version of the plugin are you running?
  • Please paste your output of sanity versions
  • Does this happen across both dev + deployed environments?
  • Is opening the plugin enough to trigger this issue? (E.g. does it occur if you open it as a tool and immediately close it?)

In use in current document filter does not work with custom image type

As mentioned here #26 the filter does not work as expected, and these images are not shown (empty result).

// product.js
export default {
  name: 'product',
  title: 'Product',
  type: 'document',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
    },
    {
      name: 'images',
      title: 'Images',
      type: 'array',
      of: [
        {
          type: 'productImage',
        },
      ],
    },
}

// productImage.js
export default {
  title: 'Image',
  name: 'productImage',
  type: 'image',
  options: {
    hotspot: true,
  },
  fields: [
    {
      name: 'custom',
      title: 'Custom',
      type: 'string',
    },
  ],
};

Custom asset source

Hello there ✌️
First wanna say thanks for this great plugin !
I want to ask is there a way when you click 'browse' to upload image to open 'Media Plugin' as default.
Currently on click I have a drop-down of 'uploaded images' and 'media'.

altText metadata field doesn't exist

The altText field does not exist in my GraphQL query.
Nothing to report concerning the title and description fields

Capture d’écran 2021-09-29 à 19 16 31

However, when uploading the media, I have the possibility of adding this ALT attribute:

Capture d’écran 2021-09-29 à 19 20 54

Is this a bug or does it require additional action?

Thanks

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.


Using a curated preset maintained by


Sanity: The Composable Content Cloud

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional)
  • chore(deps): update dependency @sanity/color to v3
  • chore(deps): update dependency @sanity/icons to v3
  • chore(deps): update dependency @sanity/pkg-utils to v4
  • chore(deps): update dependency @sanity/pkg-utils to v5
  • chore(deps): update dependency @sanity/pkg-utils to v6
  • chore(deps): update dependency @sanity/plugin-kit to v4
  • chore(deps): update dependency @sanity/semantic-release-preset to v5
  • chore(deps): update dependency conventional-changelog-conventionalcommits to v7
  • chore(deps): update dependency conventional-changelog-conventionalcommits to v8
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency rimraf to v4
  • chore(deps): update dependency styled-components to v6
  • chore(deps): update dependency typescript to v5
  • chore(deps): update linters to v6 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update linters to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser, eslint-config-sanity)
  • fix(deps): Update dependency @reduxjs/toolkit to v2
  • fix(deps): Update dependency @sanity/ui to v2
  • fix(deps): Update dependency date-fns to v3
  • fix(deps): Update dependency react-redux to v9
  • fix(deps): Update dependency redux to v5
  • 🔐 Create all pending approval PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v3@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
  • actions/setup-node v3@8c91899e586c5b171469028077307d293428b516
  • actions/checkout v3@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
  • actions/setup-node v3@8c91899e586c5b171469028077307d293428b516
  • actions/checkout v3@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
  • actions/setup-node v3@8c91899e586c5b171469028077307d293428b516
npm
package.json
  • @hookform/resolvers ^3.1.1
  • @reduxjs/toolkit ^1.9.0
  • @sanity/incompatible-plugin ^1.0.4
  • @sanity/ui ^1.9.3
  • @sanity/uuid ^3.0.1
  • @tanem/react-nprogress ^5.0.0
  • copy-to-clipboard ^3.3.1
  • date-fns ^2.27.0
  • filesize ^9.0.0
  • groq ^3.0.0
  • is-hotkey ^0.2.0
  • nanoid ^3.3.3
  • npm-run-all ^4.1.5
  • pluralize ^8.0.0
  • react-dropzone ^11.3.1
  • react-file-icon ^1.1.0
  • react-hook-form ^7.45.1
  • react-redux ^7.2.2
  • react-select ^5.3.2
  • react-virtuoso ^4.3.11
  • redux ^4.2.0
  • redux-observable ^2.0.0
  • rxjs ^7.0.0
  • zod ^3.21.4
  • @commitlint/cli ^17.2.0
  • @commitlint/config-conventional ^17.2.0
  • @sanity/client ^6.7.0
  • @sanity/color ^2.1.20
  • @sanity/icons ^2.0.0
  • @sanity/pkg-utils ^2.4.8
  • @sanity/plugin-kit ^3.1.10
  • @sanity/semantic-release-preset ^2.0.2
  • @types/is-hotkey ^0.1.7
  • @types/pluralize ^0.0.29
  • @types/react ^18
  • @types/react-dom ^18
  • @types/react-file-icon ^1.0.1
  • @types/react-redux ^7.1.24
  • @types/styled-components ^5.1.7
  • @typescript-eslint/eslint-plugin ^5.42.0
  • @typescript-eslint/parser ^5.42.0
  • conventional-changelog-conventionalcommits ^5.0.0
  • eslint ^8.27.0
  • eslint-config-prettier ^8.5.0
  • eslint-config-sanity ^6.0.0
  • eslint-plugin-prettier ^4.2.1
  • eslint-plugin-react ^7.31.10
  • eslint-plugin-react-hooks ^4.6.0
  • prettier ^2.7.1
  • prettier-plugin-packagejson ^2.3.0
  • react ^18
  • react-dom ^18
  • rimraf ^3.0.2
  • sanity ^3.2.0
  • standard-version ^9.5.0
  • styled-components ^5.3.3
  • typescript ^4.8.4
  • @sanity/ui ^1.0 || ^2.0
  • react ^18
  • react-dom ^18
  • sanity ^3.0.0
  • styled-components ^5.0 || ^6.0
  • node >=14

  • Check this box to trigger a request for Renovate to run again on this repository

Silent Upload Failure if `window.crypto.subtle` Not Available

Heads-up that I got caught by this TODO: https://github.com/robinpyon/sanity-plugin-media/blob/master/src/modules/uploads/index.ts#L198

Turns out if you use a custom domain locally like http://my-site.test:3000, window.crypto.subtle isn't defined in that environment. Instead, you have to use localhost:3000 when using this plugin. It would be nice if there were a Toasted error message if the file hash generation fails. Or perhaps even disable upload entirely if the crypto APIs aren't available.

Feature Request: Upload multiple images in an array

Hi, I have a feature request about uploading multiple images in an array. This can happen which a drag and drop or selecting the images with either mouse or clicking a tag. It would be a nice addition that can contribute a much faster workflow on sanity.

Thank you so much for your work!

Sorting alphabetically getting thrown by the dash character.

Hi there,

So we have a naming structure like continent-country-region.jpg and when sorting alphabetically the capitalisation seems to be throwing it off. See attached image.

Screenshot 2021-04-08 at 21 57 38

Can you replicate this? Any way around it?

Thanks so much!

Mark

ERROR: [plugin: vite:dep-pre-bundle] Missing "./router" export in "sanity" package

Running into this in a Sanity Studio v3 project.

Steps to reproduce:

  1. npm create [email protected]
  2. npm install --save sanity-plugin-media@studio-v3
  3. Add media plugin to plugins list
  4. npm run start

My sanity.config.js:

import {createConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {schemaTypes} from './schemas'
import {media} from 'sanity-plugin-media'

export default createConfig({
  name: 'default',
  title: 'My Sanity Project',

  projectId: '9ni8tf9u',
  dataset: 'production',

  plugins: [deskTool(), media()],

  schema: {
    types: schemaTypes,
  },
})

The full error:
Screen Shot 2022-10-12 at 6 05 52 PM

In select asset view, no filters can be added.

When in select asset mode, the button "Add filter" does nothing. No errors either.

When opening the plugin using top bar "Media", so in general browsing mode, the button works with no issues.

sanity-plugin-media 1.4.4 (also tested 1.4.9, no difference).
sanity-X 2.30.1

If this does not reproduce for you, I'm happy to supply addition info, but hard to know what is pertinent.

Media view covers Sanity "new document" popup when on /media

Hi!
First, thanks for your work this is a really great plugin, Sanity should get it built-in!

I noticed an issue when on /media, if you click on the "+" to reach the Sanity's "new document" dialog, there is a z-index clash and the media library is covering the dialog.
I was intending to submit a PR but then I saw that you have been fighting the z-index war already so it's probably better for me to just report and let you fix it 😝

image

I don't how hard it is but changing the z-index when on /media (even removing it entirely) would just solve the issue.

Thanks again!

Add and edit metadata fields

It Would be great if you could add metadata to assets from within the media library.
This would come in handy if you need to display copyright information of an image on the frontend.

Do you think this is possible with the way sanity handles images?
Would be happy to help implementing this feature.

Cannot retrieve altText and other data when image is in Block Content (Richt Text)

Hi,
I am using this plug in. For Images that are as document field this works great. But when Image is in Block Content I only get:

"image": {
                    "_type": "image",
                    "asset": {
                      "_ref": "image-xxxx-1544x726-jpg",
                      "_type": "reference"
                    }

This is my query (where challenge is a Rich Text field):

allSanityCaseStudies {
    edges {
      node {
        challenge {
          _raw
        }
      }
    }
  }

I am expecting image.asset to have all descriptive fields.

Does this require additional action?

Files are stuck in Queued state.

Hi!

My files are stuck in Queued (attached sreenshot) state (video, pdf, mp3, zip, etc.), but images (png,jpeg) are uploading without any issues. Anyone else experiencing same problems?

files-stuck

My package.json:

  "dependencies": {
    "@sanity/base": "^2.17.2",
    "@sanity/cli": "^2.17.1",
    "@sanity/components": "^2.14.0",
    "@sanity/core": "^2.17.2",
    "@sanity/default-layout": "^2.17.2",
    "@sanity/default-login": "^2.17.2",
    "@sanity/desk-tool": "^2.17.2",
    "@sanity/google-maps-input": "^2.18.0",
    "@sanity/orderable-document-list": "^0.0.9",
    "@sanity/production-preview": "^2.15.0",
    "@sanity/vision": "^2.17.2",
    "prop-types": "^15.7",
    "react": "^17.0",
    "react-dom": "^17.0",
    "react-icons": "^4.2.0",
    "react-is": "^18.1.0",
    "sanity-plugin-color-picker": "^1.0.3",
    "sanity-plugin-iframe-pane": "^1.0.6",
    "sanity-plugin-media": "^1.4.8",
    "styled-components": "^5.3.5"
  }

If anyone can help, thanks in advance!

Asset URL display/copy

Hi there, I was wondering if there's a way to display/copy the asset URL? This is useful as a work around if the asset, say a PDF, needs to be linked to multiple times due to Sanity Studio not having custom asset sources for files.

Select button is invisible on light background images

When the image is white or of a light colour the select button is not visible. I propose we give it a background colour and for extra clarity add a text label.

This is what the problem looks like
Screenshot 2020-07-14 at 12 46 11

Suggestion for solving the issue
Screenshot 2020-07-14 at 14 33 34

I can make a PR for this if my suggestion is acceptable.

Feature request: Allow configuring metadata

From the plugin's README:

Note that all images uploaded directly within the plugin will include all metadata by default

It would be more intuitive for the plugin to use the same as Sanity's default configuration (i.e. do not include exif and location). This would reduce the likelihood of editors accidentally leaking sensitive data through images.

It should also be possible to configure which metadata fields are included, in the same format as specified in Sanity's docs: https://www.sanity.io/docs/image-metadata

See also: https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1639774440206000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.