sanity-plugin-cloudinary 0.2.1 → 1.0.0-v3-studio.2

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.
Files changed (51) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +160 -66
  3. package/lib/cjs/index.js +708 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/esm/index.js +697 -0
  6. package/lib/esm/index.js.map +1 -0
  7. package/lib/types/index.d.ts +22 -0
  8. package/lib/types/index.d.ts.map +1 -0
  9. package/package.json +66 -40
  10. package/sanity.json +3 -15
  11. package/src/arrayFunctions.tsx +71 -0
  12. package/src/components/AssetDiff.tsx +44 -0
  13. package/src/components/AssetPreview.tsx +41 -0
  14. package/src/components/CloudinaryInput.tsx +61 -0
  15. package/src/components/SecretsConfigView.tsx +39 -0
  16. package/src/components/VideoPlayer.tsx +62 -0
  17. package/src/components/WidgetInput.tsx +66 -0
  18. package/src/components/asset-source/CloudinaryAssetSource.tsx +155 -0
  19. package/src/components/asset-source/Icon.tsx +93 -0
  20. package/src/index.ts +30 -0
  21. package/src/schema/cloudinaryAsset.ts +99 -0
  22. package/src/schema/cloudinaryAssetDerived.ts +26 -0
  23. package/src/typings.d.ts +74 -0
  24. package/src/utils.ts +115 -0
  25. package/v2-incompatible.js +11 -0
  26. package/dist/arrayFunctions.js +0 -82
  27. package/dist/arrayFunctions.js.map +0 -1
  28. package/dist/components/AssetDiff.js +0 -62
  29. package/dist/components/AssetDiff.js.map +0 -1
  30. package/dist/components/AssetPreview.js +0 -46
  31. package/dist/components/AssetPreview.js.map +0 -1
  32. package/dist/components/CloudinaryInput.js +0 -90
  33. package/dist/components/CloudinaryInput.js.map +0 -1
  34. package/dist/components/SecretsConfigView.js +0 -37
  35. package/dist/components/SecretsConfigView.js.map +0 -1
  36. package/dist/components/VideoPlayer.js +0 -70
  37. package/dist/components/VideoPlayer.js.map +0 -1
  38. package/dist/components/WidgetInput.js +0 -87
  39. package/dist/components/WidgetInput.js.map +0 -1
  40. package/dist/index.js +0 -24
  41. package/dist/index.js.map +0 -1
  42. package/dist/schema/cloudinary.js +0 -19
  43. package/dist/schema/cloudinary.js.map +0 -1
  44. package/dist/schema/cloudinaryAsset.js +0 -100
  45. package/dist/schema/cloudinaryAsset.js.map +0 -1
  46. package/dist/schema/cloudinaryAssetDerived.js +0 -22
  47. package/dist/schema/cloudinaryAssetDerived.js.map +0 -1
  48. package/dist/typings.d.js +0 -8
  49. package/dist/typings.d.js.map +0 -1
  50. package/dist/utils.js +0 -92
  51. package/dist/utils.js.map +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Sanity.io
3
+ Copyright (c) 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,12 +1,87 @@
1
- # Sanity + Cloudinary = 🖼️
1
+ # sanity-plugin-cloudinary
2
+
3
+ > **NOTE**
4
+ >
5
+ > This is the **Sanity Studio v3 version** of sanity-plugin-cloudinary AND sanity-plugin-asset-source-cloudinary.
6
+ >
7
+ > For the v2 versions of these, please refer to the [v2-branch for sanity-plugin-cloudinary](https://github.com/sanity-io/sanity-plugin-cloudinary) and
8
+ > [sanity-plugin-asset-source-cloudinary](https://github.com/sanity-io/sanity-plugin-asset-source-cloudinary).
2
9
 
3
10
  ## Installation
4
11
 
5
- `sanity install cloudinary`
12
+ ```
13
+ npm install --save sanity-plugin-cloudinary@studio-v3
14
+ ```
15
+
16
+ or
17
+
18
+ ```
19
+ yarn add sanity-plugin-cloudinary@studio-v3
20
+ ```
6
21
 
7
22
  ## Usage
8
23
 
9
- Declare a field to be `cloudinary.asset` in your schema
24
+ There are two plugins in this package:
25
+
26
+ - `cloudinaryAssetSourcePlugin` - use this if you intend to serve Cloudinary images from the Sanity CDN
27
+ - `cloudinarySchemaPlugin` - use this if you intend to serve Cloudinary images from the Cloudinary CDN
28
+
29
+ Also see notes below on how Cloudinary config should be provided.
30
+
31
+ ## Cloudinary as a Sanity asset
32
+
33
+ ### Add Cloudinary as an asset source to all images
34
+
35
+ ```js
36
+ import {createConfg} from 'sanity'
37
+ import {cloudinaryAssetSourcePlugin} from 'sanity-plugin-cloudinary'
38
+
39
+ export default createConfig({
40
+ /*...*/
41
+ plugins: [cloudinaryAssetSourcePlugin()],
42
+ })
43
+ ```
44
+
45
+ ### Fine tune image sources
46
+
47
+ ```js
48
+ import {createConfg} from 'sanity'
49
+ import {cloudinaryImageSource} from 'sanity-plugin-cloudinary'
50
+
51
+ export default createConfig({
52
+ /*...*/
53
+ form: {
54
+ image: {
55
+ assetSources: (previousAssetSources, context) => {
56
+ if (context.currentUser?.roles.includes('cloudinaryAccess')) {
57
+ // appends cloudinary as an asset source
58
+ return [...previousAssetSources, cloudinaryImageSource]
59
+ }
60
+ if (context.currentUser?.roles.includes('onlyCloudinaryAccess')) {
61
+ // only use clooudinary as an asset source
62
+ return [cloudinaryImageSource]
63
+ }
64
+ // dont add cloudnary as an asset sources
65
+ return previousAssetSources
66
+ },
67
+ },
68
+ },
69
+ })
70
+ ```
71
+
72
+ ## Cloudinary assets
73
+
74
+ ```js
75
+ import {createConfg} from 'sanity'
76
+ import {cloudinarySchemaPlugin} from 'sanity-plugin-cloudinary'
77
+
78
+ export default createConfig({
79
+ /*...*/
80
+ plugins: [cloudinarySchemaPlugin()],
81
+ })
82
+ ```
83
+
84
+ Now you can declare a field to be `cloudinary.asset` in your schema
10
85
 
11
86
  ```javascript
12
87
  {
@@ -25,7 +100,6 @@ Uses Cloudinary media library for selecting assets and transformations
25
100
 
26
101
  <img width="1416" alt="Screen Shot 2021-03-22 at 10 33 58 PM" src="https://user-images.githubusercontent.com/38528/112098236-b41e3f80-8b5e-11eb-9ee2-aa243420cf03.png">
27
102
 
28
-
29
103
  <img width="996" alt="Screen Shot 2021-03-22 at 10 07 52 PM" src="https://user-images.githubusercontent.com/38528/112096210-0f4e3300-8b5b-11eb-9f26-45481df878ba.png">
30
104
 
31
105
  ## In arrays
@@ -43,30 +117,30 @@ If you use this type in an array, you will have additional array functions for a
43
117
 
44
118
  <img width="658" alt="Screen Shot 2021-03-30 at 5 59 09 PM" src="https://user-images.githubusercontent.com/38528/113075424-bfd2bd00-9181-11eb-94e4-f69da4688963.png">
45
119
 
46
-
47
120
  ## Content
121
+
48
122
  Here is an example of which data is stored on your document after selecting an asset.
49
123
 
50
124
  ```json
51
125
  {
52
- "public_id": "29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x",
53
- "resource_type": "image",
54
- "type": "upload",
55
- "format": "jpg",
56
- "version": 1616474653,
57
- "url": "http://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
58
- "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
59
- "width": 2400,
60
- "height": 1344,
61
- "bytes": 547710,
62
- "duration": null,
63
- "tags": [],
64
- "metadata": {},
65
- "created_at": "2021-03-23T04:44:13Z",
66
- "access_mode": "public",
67
- "_version": 1,
68
- "_type": "cloudinary.asset"
69
- }
126
+ "public_id": "29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x",
127
+ "resource_type": "image",
128
+ "type": "upload",
129
+ "format": "jpg",
130
+ "version": 1616474653,
131
+ "url": "http://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
132
+ "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
133
+ "width": 2400,
134
+ "height": 1344,
135
+ "bytes": 547710,
136
+ "duration": null,
137
+ "tags": [],
138
+ "metadata": {},
139
+ "created_at": "2021-03-23T04:44:13Z",
140
+ "access_mode": "public",
141
+ "_version": 1,
142
+ "_type": "cloudinary.asset"
143
+ }
70
144
  ```
71
145
 
72
146
  Note: The `_version` in the data here refers to the schema version of this plugin, should the way it stores the data from Cloudinary change in the future.
@@ -79,31 +153,31 @@ You can create a transformation when selecting the asset, and this information i
79
153
 
80
154
  ```json
81
155
  {
82
- "public_id": "29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x",
83
- "resource_type": "image",
84
- "type": "upload",
85
- "format": "jpg",
86
- "version": 1616474653,
87
- "url": "http://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
88
- "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
89
- "width": 2400,
90
- "height": 1344,
91
- "bytes": 547710,
92
- "duration": null,
93
- "tags": null,
94
- "metadata": [],
95
- "created_at": "2021-03-23T04:44:13Z",
96
- "derived": [
97
- {
98
- "url": "http://res.cloudinary.com/dzwiku20l/image/upload/a_45/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
99
- "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/a_45/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
100
- "raw_transformation": "a_45"
101
- }
102
- ],
103
- "access_mode": "public",
104
- "_version": 1,
105
- "_type": "cloudinary.asset"
106
- }
156
+ "public_id": "29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x",
157
+ "resource_type": "image",
158
+ "type": "upload",
159
+ "format": "jpg",
160
+ "version": 1616474653,
161
+ "url": "http://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
162
+ "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
163
+ "width": 2400,
164
+ "height": 1344,
165
+ "bytes": 547710,
166
+ "duration": null,
167
+ "tags": null,
168
+ "metadata": [],
169
+ "created_at": "2021-03-23T04:44:13Z",
170
+ "derived": [
171
+ {
172
+ "url": "http://res.cloudinary.com/dzwiku20l/image/upload/a_45/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
173
+ "secure_url": "https://res.cloudinary.com/dzwiku20l/image/upload/a_45/v1616474653/29b4a88182b4cb50330011d23a29bcb371bd5886-2400x1344_lzcx7x.jpg",
174
+ "raw_transformation": "a_45"
175
+ }
176
+ ],
177
+ "access_mode": "public",
178
+ "_version": 1,
179
+ "_type": "cloudinary.asset"
180
+ }
107
181
  ```
108
182
 
109
183
  ## Video
@@ -114,22 +188,42 @@ Video assets gets a video player preview in the Studio
114
188
 
115
189
  ```json
116
190
  {
117
- "public_id": "Make_it_happen_together.-WWa8qtgD0f0_nucpr9",
118
- "resource_type": "video",
119
- "type": "upload",
120
- "format": "mp4",
121
- "version": 1616474928,
122
- "url": "http://res.cloudinary.com/dzwiku20l/video/upload/v1616474928/Make_it_happen_together.-WWa8qtgD0f0_nucpr9.mp4",
123
- "secure_url": "https://res.cloudinary.com/dzwiku20l/video/upload/v1616474928/Make_it_happen_together.-WWa8qtgD0f0_nucpr9.mp4",
124
- "width": 1920,
125
- "height": 1080,
126
- "bytes": 3937717,
127
- "duration": 24.1,
128
- "tags": [],
129
- "metadata": [],
130
- "created_at": "2021-03-23T04:48:48Z",
131
- "access_mode": "public",
132
- "_version": 1,
133
- "_type": "cloudinary.asset"
134
- }
191
+ "public_id": "Make_it_happen_together.-WWa8qtgD0f0_nucpr9",
192
+ "resource_type": "video",
193
+ "type": "upload",
194
+ "format": "mp4",
195
+ "version": 1616474928,
196
+ "url": "http://res.cloudinary.com/dzwiku20l/video/upload/v1616474928/Make_it_happen_together.-WWa8qtgD0f0_nucpr9.mp4",
197
+ "secure_url": "https://res.cloudinary.com/dzwiku20l/video/upload/v1616474928/Make_it_happen_together.-WWa8qtgD0f0_nucpr9.mp4",
198
+ "width": 1920,
199
+ "height": 1080,
200
+ "bytes": 3937717,
201
+ "duration": 24.1,
202
+ "tags": [],
203
+ "metadata": [],
204
+ "created_at": "2021-03-23T04:48:48Z",
205
+ "access_mode": "public",
206
+ "_version": 1,
207
+ "_type": "cloudinary.asset"
208
+ }
135
209
  ```
210
+
211
+ ## License
212
+
213
+ MIT-licensed. See LICENSE.
214
+
215
+ ## Develop & test
216
+
217
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
218
+ with default configuration for build & watch scripts.
219
+
220
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
221
+ on how to run this plugin with hotreload in the studio.
222
+
223
+ ### Release new version
224
+
225
+ Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-cloudinary/actions/workflows/main.yml).
226
+ Make sure to select the main branch and check "Release new version".
227
+
228
+ Semantic release will only release on configured branches, so it is safe to run release on any branch.
229
+