@prismicio/editor-fields 0.4.44-new-codeblock-re-release.4 → 0.4.45

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { MediaAssetType } from "./core/MediaLibrary/hooks/mediaLibraryData";
2
+ import { type MediaAssetType } from "@prismicio/editor-ui";
3
3
  export type EditorConfig = {
4
4
  baseUrl: URL;
5
5
  embedApiEndpoint: URL;
@@ -1,8 +1,9 @@
1
+ import { type MediaAssetType } from "@prismicio/editor-ui";
1
2
  import { type RefObject } from "react";
2
- import { type MediaAssetType } from "../MediaLibrary/hooks/mediaLibraryData";
3
3
  interface MediaLibraryProps {
4
4
  /**
5
- * The type of media to fetch from the media library.
5
+ * The type of media to limit the media library to.
6
+ * If different than `all`, the media library will disable the asset type filter
6
7
  * @default all
7
8
  */
8
9
  assetType?: MediaAssetType;
@@ -1,5 +1,6 @@
1
+ import { type MediaAssetType } from "@prismicio/editor-ui";
1
2
  import { type PropsWithChildren, type RefObject } from "react";
2
- import { type MediaAsset, type MediaAssetType } from "../hooks/mediaLibraryData";
3
+ import { type MediaAsset, type MediaLibraryFilters } from "../hooks/mediaLibraryData";
3
4
  import { type UploadFile } from "../hooks/useMediaLibraryUpload";
4
5
  interface MediaLibraryContextValue {
5
6
  onScrollToBottom: () => void;
@@ -14,7 +15,6 @@ interface MediaLibraryContextValue {
14
15
  * A ref to render the actions container outside the media library.
15
16
  */
16
17
  actionContainerRef?: RefObject<HTMLDivElement>;
17
- assetType?: MediaAssetType;
18
18
  onFilesUpload: (files: File[]) => void;
19
19
  isUploading: boolean;
20
20
  uploadingFiles: UploadFile[];
@@ -22,9 +22,18 @@ interface MediaLibraryContextValue {
22
22
  isMediaRevalidationInProgress: boolean;
23
23
  revalidateMedia: () => void;
24
24
  keyword: string;
25
- onKeywordChange: (term: string) => void;
25
+ /**
26
+ * The type of assets to search for.
27
+ * Possible to change using a filter in the media library.
28
+ */
29
+ assetType: MediaAssetType;
30
+ /**
31
+ * The type of assets this media library is restricted to.
32
+ * Possible to change using an `assetType` prop in MediaLibrary
33
+ */
34
+ initialAssetType: MediaAssetType;
26
35
  tagIds: string[];
27
- onTagIdsChange: (newTagIds: string[]) => void;
36
+ onFilterChange: (filters: Partial<MediaLibraryFilters>) => void;
28
37
  isSearchingMedia: boolean;
29
38
  tagManagerOpen: boolean;
30
39
  setTagManagerOpen: (open: boolean) => void;
@@ -34,7 +43,7 @@ interface MediaLibraryContextValue {
34
43
  type MediaSection = "tags";
35
44
  interface MediaLibraryProviderProps extends PropsWithChildren {
36
45
  /**
37
- * The type of media to fetch from the media library.
46
+ * The type of media to allow in the media library.
38
47
  * @default all
39
48
  */
40
49
  assetType?: MediaAssetType;
@@ -1,3 +1,4 @@
1
+ import { type MediaAssetType } from "@prismicio/editor-ui";
1
2
  import { z } from "zod";
2
3
  import { type AuthStrategy, type EditorConfig } from "../../../EditorConfig";
3
4
  export declare const mediaAssetType: z.ZodObject<{
@@ -52,7 +53,6 @@ export declare const mediaAssetType: z.ZodObject<{
52
53
  count?: number | undefined;
53
54
  }>, "many">;
54
55
  }, "strip", z.ZodTypeAny, {
55
- id: string;
56
56
  tags: {
57
57
  id: string;
58
58
  name: string;
@@ -61,11 +61,12 @@ export declare const mediaAssetType: z.ZodObject<{
61
61
  count: number;
62
62
  uploader_id?: string | undefined;
63
63
  }[];
64
+ id: string;
65
+ url: string;
66
+ size: number;
64
67
  last_modified: number;
65
68
  kind: string;
66
69
  filename: string;
67
- url: string;
68
- size: number;
69
70
  extension?: string | undefined;
70
71
  width?: number | undefined;
71
72
  height?: number | undefined;
@@ -79,7 +80,6 @@ export declare const mediaAssetType: z.ZodObject<{
79
80
  credits?: string | undefined;
80
81
  } | undefined;
81
82
  }, {
82
- id: string;
83
83
  tags: {
84
84
  id: string;
85
85
  name: string;
@@ -88,11 +88,12 @@ export declare const mediaAssetType: z.ZodObject<{
88
88
  uploader_id?: string | undefined;
89
89
  count?: number | undefined;
90
90
  }[];
91
+ id: string;
92
+ url: string;
93
+ size: number;
91
94
  last_modified: number;
92
95
  kind: string;
93
96
  filename: string;
94
- url: string;
95
- size: number;
96
97
  extension?: string | undefined;
97
98
  width?: number | undefined;
98
99
  height?: number | undefined;
@@ -164,7 +165,6 @@ export declare const mediaSearchResponse: z.ZodObject<{
164
165
  count?: number | undefined;
165
166
  }>, "many">;
166
167
  }, "strip", z.ZodTypeAny, {
167
- id: string;
168
168
  tags: {
169
169
  id: string;
170
170
  name: string;
@@ -173,11 +173,12 @@ export declare const mediaSearchResponse: z.ZodObject<{
173
173
  count: number;
174
174
  uploader_id?: string | undefined;
175
175
  }[];
176
+ id: string;
177
+ url: string;
178
+ size: number;
176
179
  last_modified: number;
177
180
  kind: string;
178
181
  filename: string;
179
- url: string;
180
- size: number;
181
182
  extension?: string | undefined;
182
183
  width?: number | undefined;
183
184
  height?: number | undefined;
@@ -191,7 +192,6 @@ export declare const mediaSearchResponse: z.ZodObject<{
191
192
  credits?: string | undefined;
192
193
  } | undefined;
193
194
  }, {
194
- id: string;
195
195
  tags: {
196
196
  id: string;
197
197
  name: string;
@@ -200,11 +200,12 @@ export declare const mediaSearchResponse: z.ZodObject<{
200
200
  uploader_id?: string | undefined;
201
201
  count?: number | undefined;
202
202
  }[];
203
+ id: string;
204
+ url: string;
205
+ size: number;
203
206
  last_modified: number;
204
207
  kind: string;
205
208
  filename: string;
206
- url: string;
207
- size: number;
208
209
  extension?: string | undefined;
209
210
  width?: number | undefined;
210
211
  height?: number | undefined;
@@ -221,7 +222,6 @@ export declare const mediaSearchResponse: z.ZodObject<{
221
222
  }, "strip", z.ZodTypeAny, {
222
223
  total: number;
223
224
  items: {
224
- id: string;
225
225
  tags: {
226
226
  id: string;
227
227
  name: string;
@@ -230,11 +230,12 @@ export declare const mediaSearchResponse: z.ZodObject<{
230
230
  count: number;
231
231
  uploader_id?: string | undefined;
232
232
  }[];
233
+ id: string;
234
+ url: string;
235
+ size: number;
233
236
  last_modified: number;
234
237
  kind: string;
235
238
  filename: string;
236
- url: string;
237
- size: number;
238
239
  extension?: string | undefined;
239
240
  width?: number | undefined;
240
241
  height?: number | undefined;
@@ -252,7 +253,6 @@ export declare const mediaSearchResponse: z.ZodObject<{
252
253
  }, {
253
254
  total: number;
254
255
  items: {
255
- id: string;
256
256
  tags: {
257
257
  id: string;
258
258
  name: string;
@@ -261,11 +261,12 @@ export declare const mediaSearchResponse: z.ZodObject<{
261
261
  uploader_id?: string | undefined;
262
262
  count?: number | undefined;
263
263
  }[];
264
+ id: string;
265
+ url: string;
266
+ size: number;
264
267
  last_modified: number;
265
268
  kind: string;
266
269
  filename: string;
267
- url: string;
268
- size: number;
269
270
  extension?: string | undefined;
270
271
  width?: number | undefined;
271
272
  height?: number | undefined;
@@ -290,12 +291,6 @@ export interface ExternalImage {
290
291
  alt?: string;
291
292
  }
292
293
  export type MediaAssetOrExternalImage = MediaAsset | ExternalImage;
293
- /**
294
- * set the allowed media type for the media library
295
- * @param all for both images and PDFs
296
- * @param image for only images
297
- */
298
- export type MediaAssetType = "all" | "image";
299
294
  export declare function searchMedia(baseUrl: URL | undefined, repository: string, authStrategy: AuthStrategy, assetType: MediaAssetType, keyword: string, tags: string, useOpenSearch: boolean, page: number, cursor?: string): Promise<{
300
295
  time: string;
301
296
  assetType: MediaAssetType;
@@ -304,7 +299,6 @@ export declare function searchMedia(baseUrl: URL | undefined, repository: string
304
299
  tags: string;
305
300
  total: number;
306
301
  items: {
307
- id: string;
308
302
  tags: {
309
303
  id: string;
310
304
  name: string;
@@ -313,11 +307,12 @@ export declare function searchMedia(baseUrl: URL | undefined, repository: string
313
307
  count: number;
314
308
  uploader_id?: string | undefined;
315
309
  }[];
310
+ id: string;
311
+ url: string;
312
+ size: number;
316
313
  last_modified: number;
317
314
  kind: string;
318
315
  filename: string;
319
- url: string;
320
- size: number;
321
316
  extension?: string | undefined;
322
317
  width?: number | undefined;
323
318
  height?: number | undefined;
@@ -334,16 +329,22 @@ export declare function searchMedia(baseUrl: URL | undefined, repository: string
334
329
  cursor?: string | undefined;
335
330
  }>;
336
331
  interface UseMediaLibrarySearchArgs {
337
- assetType?: MediaAssetType;
332
+ initialAssetType?: MediaAssetType;
338
333
  mode: "select" | "browse";
339
334
  }
335
+ export interface MediaLibraryFilters {
336
+ keyword: string;
337
+ assetType: MediaAssetType;
338
+ tagIds: string[];
339
+ }
340
+ export declare const defaultMediaLibraryFilters: MediaLibraryFilters;
340
341
  export declare function useMediaSearch(args: UseMediaLibrarySearchArgs): {
341
342
  keyword: string;
342
- setKeyword: (keyword: string) => void;
343
+ assetType: MediaAssetType;
343
344
  tagIds: string[];
344
- setTagIds: (newTagIds: string[]) => void;
345
+ setFilters: (filters: Partial<MediaLibraryFilters>) => void;
346
+ resetFilters: () => void;
345
347
  media: {
346
- id: string;
347
348
  tags: {
348
349
  id: string;
349
350
  name: string;
@@ -352,11 +353,12 @@ export declare function useMediaSearch(args: UseMediaLibrarySearchArgs): {
352
353
  count: number;
353
354
  uploader_id?: string | undefined;
354
355
  }[];
356
+ id: string;
357
+ url: string;
358
+ size: number;
355
359
  last_modified: number;
356
360
  kind: string;
357
361
  filename: string;
358
- url: string;
359
- size: number;
360
362
  extension?: string | undefined;
361
363
  width?: number | undefined;
362
364
  height?: number | undefined;
@@ -380,19 +382,18 @@ export declare function useMediaSearch(args: UseMediaLibrarySearchArgs): {
380
382
  deleteSearchData: typeof deleteSearchData;
381
383
  revalidateFirstPage: typeof revalidateFirstPage;
382
384
  };
385
+ /**
386
+ * Function to update media items in the cache and ensure
387
+ * that the shown data is up to date.
388
+ */
383
389
  declare function updateMedia(newFiles: {
384
390
  id: string;
385
391
  response: Partial<MediaAsset> | undefined;
386
392
  }[]): void;
387
393
  declare function deleteMedia(mediaIds: string[]): void;
388
- interface DeleteSearchDataArgs {
389
- keyword?: string;
390
- tagIds?: string[];
391
- }
392
- declare function deleteSearchData(args: DeleteSearchDataArgs): void;
394
+ declare function deleteSearchData(args: MediaLibraryFilters): void;
393
395
  type MediaPage = Awaited<ReturnType<typeof searchMedia>>;
394
396
  export declare function getMedia(allPages: MediaPage[], assetType: MediaAssetType, keyword: string, tags: string): {
395
- id: string;
396
397
  tags: {
397
398
  id: string;
398
399
  name: string;
@@ -401,11 +402,12 @@ export declare function getMedia(allPages: MediaPage[], assetType: MediaAssetTyp
401
402
  count: number;
402
403
  uploader_id?: string | undefined;
403
404
  }[];
405
+ id: string;
406
+ url: string;
407
+ size: number;
404
408
  last_modified: number;
405
409
  kind: string;
406
410
  filename: string;
407
- url: string;
408
- size: number;
409
411
  extension?: string | undefined;
410
412
  width?: number | undefined;
411
413
  height?: number | undefined;
@@ -428,8 +430,13 @@ type UpdateMediaFunction = (currentItems: MediaAsset[], metadata: PageMetadata)
428
430
  export declare function updateMediaCache(updateFunction: UpdateMediaFunction): void;
429
431
  interface RevalidateFirstPageArgs {
430
432
  config: EditorConfig;
431
- assetType: MediaAssetType;
433
+ keyword?: string;
434
+ assetType?: MediaAssetType;
435
+ tagIds?: string[];
432
436
  }
437
+ /**
438
+ * Revalidates the first page of the media library immediately.
439
+ */
433
440
  declare function revalidateFirstPage(args: RevalidateFirstPageArgs): void;
434
441
  /**
435
442
  * Function to remove media items from cache and ensure that the shown data
@@ -437,12 +444,12 @@ declare function revalidateFirstPage(args: RevalidateFirstPageArgs): void;
437
444
  *
438
445
  * Clear all media library cache but the first page.
439
446
  *
440
- * Then the first page will be revalidated to be insync with the server data.
447
+ * Then the first page will be revalidated to be in sync with the server data.
441
448
  * By not removing the first page and then revalidating we can avoid unnecessary
442
449
  * loading states while relying on the cached data.
443
450
  */
444
451
  export declare function clearMediaCacheAndRevalidateFirstPage(args: RevalidateFirstPageArgs): void;
445
- interface SearchMediaArgs {
452
+ export interface SearchMediaArgs {
446
453
  assetsApiBaseUrl: URL | undefined;
447
454
  repository: string;
448
455
  authStrategy: AuthStrategy;
@@ -1,4 +1,4 @@
1
- import { type MediaAssetType } from "./mediaLibraryData";
1
+ import { type MediaAssetType } from "@prismicio/editor-ui";
2
2
  interface AnalyticsMediaSearchArgs {
3
3
  assetType: MediaAssetType;
4
4
  keyword: string;
@@ -1,13 +1,17 @@
1
+ import { type MediaAssetType } from "@prismicio/editor-ui";
1
2
  import type { EditorConfig } from "../../../EditorConfig";
2
- import { type MediaAssetType } from "./mediaLibraryData";
3
+ import { type SearchMediaArgs } from "./mediaLibraryData";
3
4
  interface UseMediaLibraryCacheInvalidationArgs {
4
5
  revalidate: () => void;
5
6
  config: EditorConfig;
7
+ keyword: string;
6
8
  assetType: MediaAssetType;
9
+ tagIds: string[];
7
10
  }
8
11
  export declare function useMediaLibraryCacheInvalidation(args: UseMediaLibraryCacheInvalidationArgs): {
9
12
  isMediaRevalidationInProgress: boolean;
10
13
  isMediaCacheInvalid: boolean;
11
14
  revalidateMedia: () => void;
15
+ revalidateWithParams: (args: Partial<SearchMediaArgs>) => void;
12
16
  };
13
17
  export {};
@@ -1,5 +1,4 @@
1
1
  export declare function useSelectedMedia(): {
2
- id: string;
3
2
  tags: {
4
3
  id: string;
5
4
  name: string;
@@ -8,11 +7,12 @@ export declare function useSelectedMedia(): {
8
7
  count: number;
9
8
  uploader_id?: string | undefined;
10
9
  }[];
10
+ id: string;
11
+ url: string;
12
+ size: number;
11
13
  last_modified: number;
12
14
  kind: string;
13
15
  filename: string;
14
- url: string;
15
- size: number;
16
16
  extension?: string | undefined;
17
17
  width?: number | undefined;
18
18
  height?: number | undefined;
@@ -17,9 +17,9 @@ declare const unsplashImage: import("zod").ZodObject<{
17
17
  description: import("zod").ZodNullable<import("zod").ZodString>;
18
18
  }, "strip", import("zod").ZodTypeAny, {
19
19
  id: string;
20
+ description: string | null;
20
21
  width: number;
21
22
  height: number;
22
- description: string | null;
23
23
  urls: {
24
24
  small: string;
25
25
  full: string;
@@ -27,9 +27,9 @@ declare const unsplashImage: import("zod").ZodObject<{
27
27
  alt_description?: string | undefined;
28
28
  }, {
29
29
  id: string;
30
+ description: string | null;
30
31
  width: number;
31
32
  height: number;
32
- description: string | null;
33
33
  urls: {
34
34
  small: string;
35
35
  full: string;
@@ -55,9 +55,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
55
55
  description: import("zod").ZodNullable<import("zod").ZodString>;
56
56
  }, "strip", import("zod").ZodTypeAny, {
57
57
  id: string;
58
+ description: string | null;
58
59
  width: number;
59
60
  height: number;
60
- description: string | null;
61
61
  urls: {
62
62
  small: string;
63
63
  full: string;
@@ -65,9 +65,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
65
65
  alt_description?: string | undefined;
66
66
  }, {
67
67
  id: string;
68
+ description: string | null;
68
69
  width: number;
69
70
  height: number;
70
- description: string | null;
71
71
  urls: {
72
72
  small: string;
73
73
  full: string;
@@ -77,9 +77,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
77
77
  }, "strip", import("zod").ZodTypeAny, {
78
78
  results: {
79
79
  id: string;
80
+ description: string | null;
80
81
  width: number;
81
82
  height: number;
82
- description: string | null;
83
83
  urls: {
84
84
  small: string;
85
85
  full: string;
@@ -89,9 +89,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
89
89
  }, {
90
90
  results: {
91
91
  id: string;
92
+ description: string | null;
92
93
  width: number;
93
94
  height: number;
94
- description: string | null;
95
95
  urls: {
96
96
  small: string;
97
97
  full: string;
@@ -100,9 +100,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
100
100
  }[];
101
101
  }>, {
102
102
  id: string;
103
+ description: string | null;
103
104
  width: number;
104
105
  height: number;
105
- description: string | null;
106
106
  urls: {
107
107
  small: string;
108
108
  full: string;
@@ -111,9 +111,9 @@ export declare const unsplashSearchApiType: import("zod").ZodEffects<import("zod
111
111
  }[], {
112
112
  results: {
113
113
  id: string;
114
+ description: string | null;
114
115
  width: number;
115
116
  height: number;
116
- description: string | null;
117
117
  urls: {
118
118
  small: string;
119
119
  full: string;
@@ -125,9 +125,9 @@ export type UnplashSearchApi = TypeOf<typeof unsplashSearchApiType>;
125
125
  export type UnsplashImage = TypeOf<typeof unsplashImage>;
126
126
  export declare function useUnsplashSearch(baseUrl: URL, term: string): {
127
127
  id: string;
128
+ description: string | null;
128
129
  width: number;
129
130
  height: number;
130
- description: string | null;
131
131
  urls: {
132
132
  small: string;
133
133
  full: string;
@@ -6,21 +6,21 @@ declare const customTypeResponse: z.ZodObject<{
6
6
  repeatable: z.ZodBoolean;
7
7
  status: z.ZodBoolean;
8
8
  }, "strip", z.ZodTypeAny, {
9
- id: string;
10
9
  label: string;
11
- repeatable: boolean;
10
+ id: string;
12
11
  status: boolean;
12
+ repeatable: boolean;
13
13
  }, {
14
- id: string;
15
14
  label: string;
16
- repeatable: boolean;
15
+ id: string;
17
16
  status: boolean;
17
+ repeatable: boolean;
18
18
  }>;
19
19
  export type CustomTypeResponse = z.TypeOf<typeof customTypeResponse>;
20
20
  export declare function getRepositoryCustomTypes(baseUrl: URL, repository: string, authStrategy: AuthStrategy): Promise<{
21
- id: string;
22
21
  label: string;
23
- repeatable: boolean;
22
+ id: string;
24
23
  status: boolean;
24
+ repeatable: boolean;
25
25
  }[]>;
26
26
  export {};