@sanity/media-library-types 1.0.0 → 1.0.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/lib/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import {Asset as Asset_3} from '@sanity/media-library-types'
2
+ import {AssetInstanceDocument as AssetInstanceDocument_2} from '@sanity/media-library-types'
1
3
  import {ClientPerspective} from '@sanity/client'
2
4
  import {ComponentType} from 'react'
3
5
  import {ElementType} from 'react'
@@ -178,14 +180,14 @@ declare interface AssetSource {
178
180
  component: ComponentType<AssetSourceComponentProps>
179
181
  icon?: ComponentType<EmptyProps>
180
182
  /** @beta */
181
- uploader?: AssetSourceUploader
183
+ Uploader?: AssetSourceUploaderClass
182
184
  }
183
185
 
184
186
  /** @public */
185
187
  declare interface AssetSourceComponentProps {
186
188
  action?: 'select' | 'upload'
187
189
  assetSource: AssetSource
188
- assetType?: 'file' | 'image'
190
+ assetType?: 'file' | 'image' | 'sanity.video'
189
191
  accept: string
190
192
  selectionType: 'single'
191
193
  dialogHeaderTitle?: React.ReactNode
@@ -193,6 +195,8 @@ declare interface AssetSourceComponentProps {
193
195
  onClose: () => void
194
196
  onSelect: (assetFromSource: AssetFromSource[]) => void
195
197
  schemaType?: ImageSchemaType | FileSchemaType
198
+ /** @beta */
199
+ uploader?: AssetSourceUploader
196
200
  }
197
201
 
198
202
  /** @public */
@@ -248,6 +252,9 @@ declare interface AssetSourceUploader {
248
252
  reset(): void
249
253
  }
250
254
 
255
+ /** @beta */
256
+ declare type AssetSourceUploaderClass = new (...args: any[]) => AssetSourceUploader
257
+
251
258
  /** @beta */
252
259
  declare type AssetSourceUploadEvent =
253
260
  | AssetSourceUploadEventProgress
@@ -309,7 +316,7 @@ declare interface AssetSourceUploadFile {
309
316
  id: string
310
317
  file: globalThis.File
311
318
  progress: number
312
- status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted'
319
+ status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted' | 'alreadyExists'
313
320
  error?: Error
314
321
  result?: unknown
315
322
  }
@@ -368,6 +375,9 @@ declare interface BaseSchemaType extends Partial<DeprecationConfiguration> {
368
375
  input?: ComponentType<any>
369
376
  item?: ComponentType<any>
370
377
  preview?: ComponentType<any>
378
+ portableText?: {
379
+ plugins?: ComponentType<any>
380
+ }
371
381
  }
372
382
  /**
373
383
  * @deprecated This will be removed.
@@ -405,7 +415,7 @@ declare interface BaseSchemaTypeOptions {
405
415
  * {title: 'Strong', value: 'strong'},
406
416
  * {title: 'Emphasis', value: 'em'},
407
417
  * {title: 'Underline', value: 'underline'},
408
- * {title: 'Strike', value: 'strike'},
418
+ * {title: 'Strike', value: 'strike-through'},
409
419
  * {title: 'Code', value: 'code'},
410
420
  * ]
411
421
  * }
@@ -439,7 +449,7 @@ declare interface BlockDecoratorDefinition {
439
449
  * {title: 'Strong', value: 'strong'},
440
450
  * {title: 'Emphasis', value: 'em'},
441
451
  * {title: 'Underline', value: 'underline'},
442
- * {title: 'Strike', value: 'strike'},
452
+ * {title: 'Strike', value: 'strike-through'},
443
453
  * {title: 'Code', value: 'code'},
444
454
  * ],
445
455
  * annotations: [
@@ -532,6 +542,16 @@ declare interface BlockOptions extends BaseSchemaTypeOptions {
532
542
  */
533
543
  spellCheck?: boolean
534
544
  unstable_whitespaceOnPasteMode?: 'preserve' | 'normalize' | 'remove'
545
+ /**
546
+ * When enabled, the editor will restrict all line breaks and soft breaks,
547
+ * forcing content to remain on a single line. This will also update
548
+ * the styling of the editor to reflect the single-line constraint.
549
+ *
550
+ * Pasting content that is on multiple lines will be normalized to a single line, if possible.
551
+ *
552
+ * @defaultValue false
553
+ */
554
+ oneLine?: boolean
535
555
  }
536
556
 
537
557
  /** @public */
@@ -754,6 +774,8 @@ declare interface DatetimeOptions extends BaseSchemaTypeOptions {
754
774
  dateFormat?: string
755
775
  timeFormat?: string
756
776
  timeStep?: number
777
+ displayTimeZone?: string
778
+ allowTimeZoneSwitch?: boolean
757
779
  }
758
780
 
759
781
  /** @public */
@@ -935,6 +957,7 @@ declare interface FileOptions extends ObjectOptions {
935
957
  storeOriginalFilename?: boolean
936
958
  accept?: string
937
959
  sources?: AssetSource[]
960
+ mediaLibrary?: MediaLibraryOptions
938
961
  }
939
962
 
940
963
  /** @public */
@@ -960,7 +983,7 @@ declare interface FileSchemaType extends Omit<ObjectSchemaType, 'options'> {
960
983
  options?: FileOptions
961
984
  }
962
985
 
963
- export declare type FileStatus = 'pending' | 'uploading' | 'complete' | 'error'
986
+ export declare type FileStatus = 'pending' | 'uploading' | 'complete' | 'error' | 'alreadyExists'
964
987
 
965
988
  /**
966
989
  * Wrapper object for the file upload with progress and status
@@ -1217,24 +1240,28 @@ declare interface InsertMenuOptions {
1217
1240
  * `filter: 'auto'` automatically turns on filtering if there are more than 5
1218
1241
  * schema types added to the menu.
1219
1242
  */
1220
- filter?: 'auto' | boolean
1221
- groups?: Array<{
1222
- name: string
1223
- title?: string
1224
- of?: Array<string>
1225
- }>
1243
+ filter?: 'auto' | boolean | undefined
1244
+ groups?:
1245
+ | Array<{
1246
+ name: string
1247
+ title?: string
1248
+ of?: Array<string>
1249
+ }>
1250
+ | undefined
1226
1251
  /** defaultValue `true` */
1227
- showIcons?: boolean
1252
+ showIcons?: boolean | undefined
1228
1253
  /** @defaultValue `[{name: 'list'}]` */
1229
- views?: Array<
1230
- | {
1231
- name: 'list'
1232
- }
1233
- | {
1234
- name: 'grid'
1235
- previewImageUrl?: (schemaTypeName: string) => string | undefined
1236
- }
1237
- >
1254
+ views?:
1255
+ | Array<
1256
+ | {
1257
+ name: 'list'
1258
+ }
1259
+ | {
1260
+ name: 'grid'
1261
+ previewImageUrl?: (schemaTypeName: string) => string | undefined
1262
+ }
1263
+ >
1264
+ | undefined
1238
1265
  }
1239
1266
 
1240
1267
  declare const internalGroqTypeReferenceTo: unique symbol
@@ -1317,6 +1344,52 @@ declare interface LocalizedValidationMessages {
1317
1344
  [locale: string]: string
1318
1345
  }
1319
1346
 
1347
+ /** @public */
1348
+ declare type MediaAssetTypes = AssetInstanceDocument_2['_type']
1349
+
1350
+ /** @public */
1351
+ declare interface MediaLibraryFilter {
1352
+ name: string
1353
+ query: string
1354
+ }
1355
+
1356
+ /** @public */
1357
+ declare interface MediaLibraryOptions {
1358
+ filters?: MediaLibraryFilter[]
1359
+ }
1360
+
1361
+ /** @public */
1362
+ declare interface MediaValidationValue<T extends MediaAssetTypes = MediaAssetTypes> {
1363
+ /**
1364
+ * Media information
1365
+ */
1366
+ media: {
1367
+ /**
1368
+ * The Media Library Asset.
1369
+ */
1370
+ asset: Asset_3 & {
1371
+ currentVersion: Extract<
1372
+ AssetInstanceDocument_2,
1373
+ {
1374
+ _type: T
1375
+ }
1376
+ >
1377
+ }
1378
+ }
1379
+ /**
1380
+ * The field value which the media is used in.
1381
+ */
1382
+ value: unknown
1383
+ }
1384
+
1385
+ /** @public */
1386
+ declare interface MediaValidator<T extends MediaAssetTypes = MediaAssetTypes> {
1387
+ (
1388
+ value: MediaValidationValue<T>,
1389
+ context: ValidationContext,
1390
+ ): CustomValidatorResult | Promise<CustomValidatorResult>
1391
+ }
1392
+
1320
1393
  /** @public */
1321
1394
  declare interface MultiFieldSet {
1322
1395
  name: string
@@ -1741,6 +1814,7 @@ declare interface Rule {
1741
1814
  bypassConcurrencyLimit?: boolean
1742
1815
  },
1743
1816
  ): Rule
1817
+ media<T extends MediaAssetTypes = MediaAssetTypes>(fn: MediaValidator<T>): Rule
1744
1818
  min(len: number | string | FieldReference): Rule
1745
1819
  max(len: number | string | FieldReference): Rule
1746
1820
  length(len: number | FieldReference): Rule
@@ -1844,15 +1918,15 @@ declare type RuleSpec =
1844
1918
  }
1845
1919
  | {
1846
1920
  flag: 'min'
1847
- constraint: number | string
1921
+ constraint: number | string | FieldReference
1848
1922
  }
1849
1923
  | {
1850
1924
  flag: 'max'
1851
- constraint: number | string
1925
+ constraint: number | string | FieldReference
1852
1926
  }
1853
1927
  | {
1854
1928
  flag: 'length'
1855
- constraint: number
1929
+ constraint: number | FieldReference
1856
1930
  }
1857
1931
  | {
1858
1932
  flag: 'valid'
@@ -1860,15 +1934,15 @@ declare type RuleSpec =
1860
1934
  }
1861
1935
  | {
1862
1936
  flag: 'precision'
1863
- constraint: number
1937
+ constraint: number | FieldReference
1864
1938
  }
1865
1939
  | {
1866
1940
  flag: 'lessThan'
1867
- constraint: number
1941
+ constraint: number | FieldReference
1868
1942
  }
1869
1943
  | {
1870
1944
  flag: 'greaterThan'
1871
- constraint: number
1945
+ constraint: number | FieldReference
1872
1946
  }
1873
1947
  | {
1874
1948
  flag: 'stringCasing'
@@ -1880,6 +1954,10 @@ declare type RuleSpec =
1880
1954
  assetType: 'asset' | 'image' | 'file'
1881
1955
  }
1882
1956
  }
1957
+ | {
1958
+ flag: 'media'
1959
+ constraint: MediaValidator<any>
1960
+ }
1883
1961
  | {
1884
1962
  flag: 'regex'
1885
1963
  constraint: {
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import {Asset as Asset_3} from '@sanity/media-library-types'
2
+ import {AssetInstanceDocument as AssetInstanceDocument_2} from '@sanity/media-library-types'
1
3
  import {ClientPerspective} from '@sanity/client'
2
4
  import {ComponentType} from 'react'
3
5
  import {ElementType} from 'react'
@@ -178,14 +180,14 @@ declare interface AssetSource {
178
180
  component: ComponentType<AssetSourceComponentProps>
179
181
  icon?: ComponentType<EmptyProps>
180
182
  /** @beta */
181
- uploader?: AssetSourceUploader
183
+ Uploader?: AssetSourceUploaderClass
182
184
  }
183
185
 
184
186
  /** @public */
185
187
  declare interface AssetSourceComponentProps {
186
188
  action?: 'select' | 'upload'
187
189
  assetSource: AssetSource
188
- assetType?: 'file' | 'image'
190
+ assetType?: 'file' | 'image' | 'sanity.video'
189
191
  accept: string
190
192
  selectionType: 'single'
191
193
  dialogHeaderTitle?: React.ReactNode
@@ -193,6 +195,8 @@ declare interface AssetSourceComponentProps {
193
195
  onClose: () => void
194
196
  onSelect: (assetFromSource: AssetFromSource[]) => void
195
197
  schemaType?: ImageSchemaType | FileSchemaType
198
+ /** @beta */
199
+ uploader?: AssetSourceUploader
196
200
  }
197
201
 
198
202
  /** @public */
@@ -248,6 +252,9 @@ declare interface AssetSourceUploader {
248
252
  reset(): void
249
253
  }
250
254
 
255
+ /** @beta */
256
+ declare type AssetSourceUploaderClass = new (...args: any[]) => AssetSourceUploader
257
+
251
258
  /** @beta */
252
259
  declare type AssetSourceUploadEvent =
253
260
  | AssetSourceUploadEventProgress
@@ -309,7 +316,7 @@ declare interface AssetSourceUploadFile {
309
316
  id: string
310
317
  file: globalThis.File
311
318
  progress: number
312
- status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted'
319
+ status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted' | 'alreadyExists'
313
320
  error?: Error
314
321
  result?: unknown
315
322
  }
@@ -368,6 +375,9 @@ declare interface BaseSchemaType extends Partial<DeprecationConfiguration> {
368
375
  input?: ComponentType<any>
369
376
  item?: ComponentType<any>
370
377
  preview?: ComponentType<any>
378
+ portableText?: {
379
+ plugins?: ComponentType<any>
380
+ }
371
381
  }
372
382
  /**
373
383
  * @deprecated This will be removed.
@@ -405,7 +415,7 @@ declare interface BaseSchemaTypeOptions {
405
415
  * {title: 'Strong', value: 'strong'},
406
416
  * {title: 'Emphasis', value: 'em'},
407
417
  * {title: 'Underline', value: 'underline'},
408
- * {title: 'Strike', value: 'strike'},
418
+ * {title: 'Strike', value: 'strike-through'},
409
419
  * {title: 'Code', value: 'code'},
410
420
  * ]
411
421
  * }
@@ -439,7 +449,7 @@ declare interface BlockDecoratorDefinition {
439
449
  * {title: 'Strong', value: 'strong'},
440
450
  * {title: 'Emphasis', value: 'em'},
441
451
  * {title: 'Underline', value: 'underline'},
442
- * {title: 'Strike', value: 'strike'},
452
+ * {title: 'Strike', value: 'strike-through'},
443
453
  * {title: 'Code', value: 'code'},
444
454
  * ],
445
455
  * annotations: [
@@ -532,6 +542,16 @@ declare interface BlockOptions extends BaseSchemaTypeOptions {
532
542
  */
533
543
  spellCheck?: boolean
534
544
  unstable_whitespaceOnPasteMode?: 'preserve' | 'normalize' | 'remove'
545
+ /**
546
+ * When enabled, the editor will restrict all line breaks and soft breaks,
547
+ * forcing content to remain on a single line. This will also update
548
+ * the styling of the editor to reflect the single-line constraint.
549
+ *
550
+ * Pasting content that is on multiple lines will be normalized to a single line, if possible.
551
+ *
552
+ * @defaultValue false
553
+ */
554
+ oneLine?: boolean
535
555
  }
536
556
 
537
557
  /** @public */
@@ -754,6 +774,8 @@ declare interface DatetimeOptions extends BaseSchemaTypeOptions {
754
774
  dateFormat?: string
755
775
  timeFormat?: string
756
776
  timeStep?: number
777
+ displayTimeZone?: string
778
+ allowTimeZoneSwitch?: boolean
757
779
  }
758
780
 
759
781
  /** @public */
@@ -935,6 +957,7 @@ declare interface FileOptions extends ObjectOptions {
935
957
  storeOriginalFilename?: boolean
936
958
  accept?: string
937
959
  sources?: AssetSource[]
960
+ mediaLibrary?: MediaLibraryOptions
938
961
  }
939
962
 
940
963
  /** @public */
@@ -960,7 +983,7 @@ declare interface FileSchemaType extends Omit<ObjectSchemaType, 'options'> {
960
983
  options?: FileOptions
961
984
  }
962
985
 
963
- export declare type FileStatus = 'pending' | 'uploading' | 'complete' | 'error'
986
+ export declare type FileStatus = 'pending' | 'uploading' | 'complete' | 'error' | 'alreadyExists'
964
987
 
965
988
  /**
966
989
  * Wrapper object for the file upload with progress and status
@@ -1217,24 +1240,28 @@ declare interface InsertMenuOptions {
1217
1240
  * `filter: 'auto'` automatically turns on filtering if there are more than 5
1218
1241
  * schema types added to the menu.
1219
1242
  */
1220
- filter?: 'auto' | boolean
1221
- groups?: Array<{
1222
- name: string
1223
- title?: string
1224
- of?: Array<string>
1225
- }>
1243
+ filter?: 'auto' | boolean | undefined
1244
+ groups?:
1245
+ | Array<{
1246
+ name: string
1247
+ title?: string
1248
+ of?: Array<string>
1249
+ }>
1250
+ | undefined
1226
1251
  /** defaultValue `true` */
1227
- showIcons?: boolean
1252
+ showIcons?: boolean | undefined
1228
1253
  /** @defaultValue `[{name: 'list'}]` */
1229
- views?: Array<
1230
- | {
1231
- name: 'list'
1232
- }
1233
- | {
1234
- name: 'grid'
1235
- previewImageUrl?: (schemaTypeName: string) => string | undefined
1236
- }
1237
- >
1254
+ views?:
1255
+ | Array<
1256
+ | {
1257
+ name: 'list'
1258
+ }
1259
+ | {
1260
+ name: 'grid'
1261
+ previewImageUrl?: (schemaTypeName: string) => string | undefined
1262
+ }
1263
+ >
1264
+ | undefined
1238
1265
  }
1239
1266
 
1240
1267
  declare const internalGroqTypeReferenceTo: unique symbol
@@ -1317,6 +1344,52 @@ declare interface LocalizedValidationMessages {
1317
1344
  [locale: string]: string
1318
1345
  }
1319
1346
 
1347
+ /** @public */
1348
+ declare type MediaAssetTypes = AssetInstanceDocument_2['_type']
1349
+
1350
+ /** @public */
1351
+ declare interface MediaLibraryFilter {
1352
+ name: string
1353
+ query: string
1354
+ }
1355
+
1356
+ /** @public */
1357
+ declare interface MediaLibraryOptions {
1358
+ filters?: MediaLibraryFilter[]
1359
+ }
1360
+
1361
+ /** @public */
1362
+ declare interface MediaValidationValue<T extends MediaAssetTypes = MediaAssetTypes> {
1363
+ /**
1364
+ * Media information
1365
+ */
1366
+ media: {
1367
+ /**
1368
+ * The Media Library Asset.
1369
+ */
1370
+ asset: Asset_3 & {
1371
+ currentVersion: Extract<
1372
+ AssetInstanceDocument_2,
1373
+ {
1374
+ _type: T
1375
+ }
1376
+ >
1377
+ }
1378
+ }
1379
+ /**
1380
+ * The field value which the media is used in.
1381
+ */
1382
+ value: unknown
1383
+ }
1384
+
1385
+ /** @public */
1386
+ declare interface MediaValidator<T extends MediaAssetTypes = MediaAssetTypes> {
1387
+ (
1388
+ value: MediaValidationValue<T>,
1389
+ context: ValidationContext,
1390
+ ): CustomValidatorResult | Promise<CustomValidatorResult>
1391
+ }
1392
+
1320
1393
  /** @public */
1321
1394
  declare interface MultiFieldSet {
1322
1395
  name: string
@@ -1741,6 +1814,7 @@ declare interface Rule {
1741
1814
  bypassConcurrencyLimit?: boolean
1742
1815
  },
1743
1816
  ): Rule
1817
+ media<T extends MediaAssetTypes = MediaAssetTypes>(fn: MediaValidator<T>): Rule
1744
1818
  min(len: number | string | FieldReference): Rule
1745
1819
  max(len: number | string | FieldReference): Rule
1746
1820
  length(len: number | FieldReference): Rule
@@ -1844,15 +1918,15 @@ declare type RuleSpec =
1844
1918
  }
1845
1919
  | {
1846
1920
  flag: 'min'
1847
- constraint: number | string
1921
+ constraint: number | string | FieldReference
1848
1922
  }
1849
1923
  | {
1850
1924
  flag: 'max'
1851
- constraint: number | string
1925
+ constraint: number | string | FieldReference
1852
1926
  }
1853
1927
  | {
1854
1928
  flag: 'length'
1855
- constraint: number
1929
+ constraint: number | FieldReference
1856
1930
  }
1857
1931
  | {
1858
1932
  flag: 'valid'
@@ -1860,15 +1934,15 @@ declare type RuleSpec =
1860
1934
  }
1861
1935
  | {
1862
1936
  flag: 'precision'
1863
- constraint: number
1937
+ constraint: number | FieldReference
1864
1938
  }
1865
1939
  | {
1866
1940
  flag: 'lessThan'
1867
- constraint: number
1941
+ constraint: number | FieldReference
1868
1942
  }
1869
1943
  | {
1870
1944
  flag: 'greaterThan'
1871
- constraint: number
1945
+ constraint: number | FieldReference
1872
1946
  }
1873
1947
  | {
1874
1948
  flag: 'stringCasing'
@@ -1880,6 +1954,10 @@ declare type RuleSpec =
1880
1954
  assetType: 'asset' | 'image' | 'file'
1881
1955
  }
1882
1956
  }
1957
+ | {
1958
+ flag: 'media'
1959
+ constraint: MediaValidator<any>
1960
+ }
1883
1961
  | {
1884
1962
  flag: 'regex'
1885
1963
  constraint: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/media-library-types",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Type definitions for common Sanity Media Library data structures",
5
5
  "keywords": [
6
6
  "sanity",
@@ -36,10 +36,9 @@
36
36
  "lib",
37
37
  "src"
38
38
  ],
39
- "dependencies": {},
40
39
  "devDependencies": {
41
- "@sanity/types": "^3.90.0",
42
- "@sanity/pkg-utils": "^7.2.3",
40
+ "@sanity/pkg-utils": "^8.1.9",
41
+ "@sanity/types": "^4.8.1",
43
42
  "rimraf": "^5.0.10"
44
43
  },
45
44
  "scripts": {
package/src/files.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type FileStatus = 'pending' | 'uploading' | 'complete' | 'error'
1
+ export type FileStatus = 'pending' | 'uploading' | 'complete' | 'error' | 'alreadyExists'
2
2
 
3
3
  /**
4
4
  * Wrapper object for the file upload with progress and status