sanity-plugin-utils 1.4.1 → 1.6.0

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.esm.js CHANGED
@@ -1,18 +1,675 @@
1
1
  var _templateObject, _templateObject2, _templateObject3;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
- import React, { useState, useRef, useEffect } from 'react';
3
+ import React, { useMemo, useState, useRef, useEffect } from 'react';
4
+ import { useClient, useDocumentStore, useWorkspace, UserAvatar } from 'sanity';
4
5
  import { distinctUntilChanged, catchError } from 'rxjs/operators';
5
6
  import isEqual from 'react-fast-compare';
6
- import { useDocumentStore, useWorkspace, useClient, UserAvatar } from 'sanity';
7
7
  import { usePaneRouter } from 'sanity/desk';
8
8
  import { RouterContext } from 'sanity/router';
9
9
  import { jsx, jsxs } from 'react/jsx-runtime';
10
10
  import { Card, Flex, Box, Stack, Text, Menu, MenuItem, TextInput, Badge } from '@sanity/ui';
11
11
  import styled, { css } from 'styled-components';
12
12
  import { RemoveCircleIcon, AddCircleIcon, RestoreIcon } from '@sanity/icons';
13
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
14
+ var builder = {};
15
+ var urlForImage = {};
16
+ var parseAssetId$1 = {};
17
+ Object.defineProperty(parseAssetId$1, "__esModule", {
18
+ value: true
19
+ });
20
+ var example = 'image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg';
21
+ function parseAssetId(ref) {
22
+ var _a = ref.split('-'),
23
+ id = _a[1],
24
+ dimensionString = _a[2],
25
+ format = _a[3];
26
+ if (!id || !dimensionString || !format) {
27
+ throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
28
+ }
29
+ var _b = dimensionString.split('x'),
30
+ imgWidthStr = _b[0],
31
+ imgHeightStr = _b[1];
32
+ var width = +imgWidthStr;
33
+ var height = +imgHeightStr;
34
+ var isValidAssetId = isFinite(width) && isFinite(height);
35
+ if (!isValidAssetId) {
36
+ throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
37
+ }
38
+ return {
39
+ id: id,
40
+ width: width,
41
+ height: height,
42
+ format: format
43
+ };
44
+ }
45
+ parseAssetId$1.default = parseAssetId;
46
+ var parseSource$1 = {};
47
+ var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function () {
48
+ __assign$1 = Object.assign || function (t) {
49
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
50
+ s = arguments[i];
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
52
+ }
53
+ return t;
54
+ };
55
+ return __assign$1.apply(this, arguments);
56
+ };
57
+ Object.defineProperty(parseSource$1, "__esModule", {
58
+ value: true
59
+ });
60
+ var isRef = function (src) {
61
+ var source = src;
62
+ return source ? typeof source._ref === 'string' : false;
63
+ };
64
+ var isAsset = function (src) {
65
+ var source = src;
66
+ return source ? typeof source._id === 'string' : false;
67
+ };
68
+ var isAssetStub = function (src) {
69
+ var source = src;
70
+ return source && source.asset ? typeof source.asset.url === 'string' : false;
71
+ };
72
+ // Convert an asset-id, asset or image to an image record suitable for processing
73
+ // eslint-disable-next-line complexity
74
+ function parseSource(source) {
75
+ if (!source) {
76
+ return null;
77
+ }
78
+ var image;
79
+ if (typeof source === 'string' && isUrl(source)) {
80
+ // Someone passed an existing image url?
81
+ image = {
82
+ asset: {
83
+ _ref: urlToId(source)
84
+ }
85
+ };
86
+ } else if (typeof source === 'string') {
87
+ // Just an asset id
88
+ image = {
89
+ asset: {
90
+ _ref: source
91
+ }
92
+ };
93
+ } else if (isRef(source)) {
94
+ // We just got passed an asset directly
95
+ image = {
96
+ asset: source
97
+ };
98
+ } else if (isAsset(source)) {
99
+ // If we were passed an image asset document
100
+ image = {
101
+ asset: {
102
+ _ref: source._id || ''
103
+ }
104
+ };
105
+ } else if (isAssetStub(source)) {
106
+ // If we were passed a partial asset (`url`, but no `_id`)
107
+ image = {
108
+ asset: {
109
+ _ref: urlToId(source.asset.url)
110
+ }
111
+ };
112
+ } else if (typeof source.asset === 'object') {
113
+ // Probably an actual image with materialized asset
114
+ image = __assign$1({}, source);
115
+ } else {
116
+ // We got something that does not look like an image, or it is an image
117
+ // that currently isn't sporting an asset.
118
+ return null;
119
+ }
120
+ var img = source;
121
+ if (img.crop) {
122
+ image.crop = img.crop;
123
+ }
124
+ if (img.hotspot) {
125
+ image.hotspot = img.hotspot;
126
+ }
127
+ return applyDefaults(image);
128
+ }
129
+ parseSource$1.default = parseSource;
130
+ function isUrl(url) {
131
+ return /^https?:\/\//.test("".concat(url));
132
+ }
133
+ function urlToId(url) {
134
+ var parts = url.split('/').slice(-1);
135
+ return "image-".concat(parts[0]).replace(/\.([a-z]+)$/, '-$1');
136
+ }
137
+ // Mock crop and hotspot if image lacks it
138
+ function applyDefaults(image) {
139
+ if (image.crop && image.hotspot) {
140
+ return image;
141
+ }
142
+ // We need to pad in default values for crop or hotspot
143
+ var result = __assign$1({}, image);
144
+ if (!result.crop) {
145
+ result.crop = {
146
+ left: 0,
147
+ top: 0,
148
+ bottom: 0,
149
+ right: 0
150
+ };
151
+ }
152
+ if (!result.hotspot) {
153
+ result.hotspot = {
154
+ x: 0.5,
155
+ y: 0.5,
156
+ height: 1.0,
157
+ width: 1.0
158
+ };
159
+ }
160
+ return result;
161
+ }
162
+ (function (exports) {
163
+ var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
164
+ __assign = Object.assign || function (t) {
165
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
166
+ s = arguments[i];
167
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
168
+ }
169
+ return t;
170
+ };
171
+ return __assign.apply(this, arguments);
172
+ };
173
+ var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
174
+ return mod && mod.__esModule ? mod : {
175
+ "default": mod
176
+ };
177
+ };
178
+ Object.defineProperty(exports, "__esModule", {
179
+ value: true
180
+ });
181
+ exports.parseSource = exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
182
+ var parseAssetId_1 = __importDefault(parseAssetId$1);
183
+ var parseSource_1 = __importDefault(parseSource$1);
184
+ exports.parseSource = parseSource_1.default;
185
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS = [['width', 'w'], ['height', 'h'], ['format', 'fm'], ['download', 'dl'], ['blur', 'blur'], ['sharpen', 'sharp'], ['invert', 'invert'], ['orientation', 'or'], ['minHeight', 'min-h'], ['maxHeight', 'max-h'], ['minWidth', 'min-w'], ['maxWidth', 'max-w'], ['quality', 'q'], ['fit', 'fit'], ['crop', 'crop'], ['saturation', 'sat'], ['auto', 'auto'], ['dpr', 'dpr'], ['pad', 'pad']];
186
+ function urlForImage(options) {
187
+ var spec = __assign({}, options || {});
188
+ var source = spec.source;
189
+ delete spec.source;
190
+ var image = (0, parseSource_1.default)(source);
191
+ if (!image) {
192
+ throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
193
+ }
194
+ var id = image.asset._ref || image.asset._id || '';
195
+ var asset = (0, parseAssetId_1.default)(id);
196
+ // Compute crop rect in terms of pixel coordinates in the raw source image
197
+ var cropLeft = Math.round(image.crop.left * asset.width);
198
+ var cropTop = Math.round(image.crop.top * asset.height);
199
+ var crop = {
200
+ left: cropLeft,
201
+ top: cropTop,
202
+ width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
203
+ height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
204
+ };
205
+ // Compute hot spot rect in terms of pixel coordinates
206
+ var hotSpotVerticalRadius = image.hotspot.height * asset.height / 2;
207
+ var hotSpotHorizontalRadius = image.hotspot.width * asset.width / 2;
208
+ var hotSpotCenterX = image.hotspot.x * asset.width;
209
+ var hotSpotCenterY = image.hotspot.y * asset.height;
210
+ var hotspot = {
211
+ left: hotSpotCenterX - hotSpotHorizontalRadius,
212
+ top: hotSpotCenterY - hotSpotVerticalRadius,
213
+ right: hotSpotCenterX + hotSpotHorizontalRadius,
214
+ bottom: hotSpotCenterY + hotSpotVerticalRadius
215
+ };
216
+ // If irrelevant, or if we are requested to: don't perform crop/fit based on
217
+ // the crop/hotspot.
218
+ if (!(spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop)) {
219
+ spec = __assign(__assign({}, spec), fit({
220
+ crop: crop,
221
+ hotspot: hotspot
222
+ }, spec));
223
+ }
224
+ return specToImageUrl(__assign(__assign({}, spec), {
225
+ asset: asset
226
+ }));
227
+ }
228
+ exports.default = urlForImage;
229
+ // eslint-disable-next-line complexity
230
+ function specToImageUrl(spec) {
231
+ var cdnUrl = (spec.baseUrl || 'https://cdn.sanity.io').replace(/\/+$/, '');
232
+ var filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format);
233
+ var baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename);
234
+ var params = [];
235
+ if (spec.rect) {
236
+ // Only bother url with a crop if it actually crops anything
237
+ var _a = spec.rect,
238
+ left = _a.left,
239
+ top_1 = _a.top,
240
+ width = _a.width,
241
+ height = _a.height;
242
+ var isEffectiveCrop = left !== 0 || top_1 !== 0 || height !== spec.asset.height || width !== spec.asset.width;
243
+ if (isEffectiveCrop) {
244
+ params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
245
+ }
246
+ }
247
+ if (spec.bg) {
248
+ params.push("bg=".concat(spec.bg));
249
+ }
250
+ if (spec.focalPoint) {
251
+ params.push("fp-x=".concat(spec.focalPoint.x));
252
+ params.push("fp-y=".concat(spec.focalPoint.y));
253
+ }
254
+ var flip = [spec.flipHorizontal && 'h', spec.flipVertical && 'v'].filter(Boolean).join('');
255
+ if (flip) {
256
+ params.push("flip=".concat(flip));
257
+ }
258
+ // Map from spec name to url param name, and allow using the actual param name as an alternative
259
+ exports.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function (mapping) {
260
+ var specName = mapping[0],
261
+ param = mapping[1];
262
+ if (typeof spec[specName] !== 'undefined') {
263
+ params.push("".concat(param, "=").concat(encodeURIComponent(spec[specName])));
264
+ } else if (typeof spec[param] !== 'undefined') {
265
+ params.push("".concat(param, "=").concat(encodeURIComponent(spec[param])));
266
+ }
267
+ });
268
+ if (params.length === 0) {
269
+ return baseUrl;
270
+ }
271
+ return "".concat(baseUrl, "?").concat(params.join('&'));
272
+ }
273
+ function fit(source, spec) {
274
+ var cropRect;
275
+ var imgWidth = spec.width;
276
+ var imgHeight = spec.height;
277
+ // If we are not constraining the aspect ratio, we'll just use the whole crop
278
+ if (!(imgWidth && imgHeight)) {
279
+ return {
280
+ width: imgWidth,
281
+ height: imgHeight,
282
+ rect: source.crop
283
+ };
284
+ }
285
+ var crop = source.crop;
286
+ var hotspot = source.hotspot;
287
+ // If we are here, that means aspect ratio is locked and fitting will be a bit harder
288
+ var desiredAspectRatio = imgWidth / imgHeight;
289
+ var cropAspectRatio = crop.width / crop.height;
290
+ if (cropAspectRatio > desiredAspectRatio) {
291
+ // The crop is wider than the desired aspect ratio. That means we are cutting from the sides
292
+ var height = Math.round(crop.height);
293
+ var width = Math.round(height * desiredAspectRatio);
294
+ var top_2 = Math.max(0, Math.round(crop.top));
295
+ // Center output horizontally over hotspot
296
+ var hotspotXCenter = Math.round((hotspot.right - hotspot.left) / 2 + hotspot.left);
297
+ var left = Math.max(0, Math.round(hotspotXCenter - width / 2));
298
+ // Keep output within crop
299
+ if (left < crop.left) {
300
+ left = crop.left;
301
+ } else if (left + width > crop.left + crop.width) {
302
+ left = crop.left + crop.width - width;
303
+ }
304
+ cropRect = {
305
+ left: left,
306
+ top: top_2,
307
+ width: width,
308
+ height: height
309
+ };
310
+ } else {
311
+ // The crop is taller than the desired ratio, we are cutting from top and bottom
312
+ var width = crop.width;
313
+ var height = Math.round(width / desiredAspectRatio);
314
+ var left = Math.max(0, Math.round(crop.left));
315
+ // Center output vertically over hotspot
316
+ var hotspotYCenter = Math.round((hotspot.bottom - hotspot.top) / 2 + hotspot.top);
317
+ var top_3 = Math.max(0, Math.round(hotspotYCenter - height / 2));
318
+ // Keep output rect within crop
319
+ if (top_3 < crop.top) {
320
+ top_3 = crop.top;
321
+ } else if (top_3 + height > crop.top + crop.height) {
322
+ top_3 = crop.top + crop.height - height;
323
+ }
324
+ cropRect = {
325
+ left: left,
326
+ top: top_3,
327
+ width: width,
328
+ height: height
329
+ };
330
+ }
331
+ return {
332
+ width: imgWidth,
333
+ height: imgHeight,
334
+ rect: cropRect
335
+ };
336
+ }
337
+ })(urlForImage);
338
+ var __assign = commonjsGlobal && commonjsGlobal.__assign || function () {
339
+ __assign = Object.assign || function (t) {
340
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
341
+ s = arguments[i];
342
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
343
+ }
344
+ return t;
345
+ };
346
+ return __assign.apply(this, arguments);
347
+ };
348
+ var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function (o, m, k, k2) {
349
+ if (k2 === undefined) k2 = k;
350
+ Object.defineProperty(o, k2, {
351
+ enumerable: true,
352
+ get: function () {
353
+ return m[k];
354
+ }
355
+ });
356
+ } : function (o, m, k, k2) {
357
+ if (k2 === undefined) k2 = k;
358
+ o[k2] = m[k];
359
+ });
360
+ var __setModuleDefault = commonjsGlobal && commonjsGlobal.__setModuleDefault || (Object.create ? function (o, v) {
361
+ Object.defineProperty(o, "default", {
362
+ enumerable: true,
363
+ value: v
364
+ });
365
+ } : function (o, v) {
366
+ o["default"] = v;
367
+ });
368
+ var __importStar = commonjsGlobal && commonjsGlobal.__importStar || function (mod) {
369
+ if (mod && mod.__esModule) return mod;
370
+ var result = {};
371
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
372
+ __setModuleDefault(result, mod);
373
+ return result;
374
+ };
375
+ Object.defineProperty(builder, "__esModule", {
376
+ value: true
377
+ });
378
+ builder.ImageUrlBuilder = void 0;
379
+ var urlForImage_1 = __importStar(urlForImage);
380
+ var validFits = ['clip', 'crop', 'fill', 'fillmax', 'max', 'scale', 'min'];
381
+ var validCrops = ['top', 'bottom', 'left', 'right', 'center', 'focalpoint', 'entropy'];
382
+ var validAutoModes = ['format'];
383
+ function isSanityModernClientLike(client) {
384
+ return client && 'config' in client ? typeof client.config === 'function' : false;
385
+ }
386
+ function isSanityClientLike(client) {
387
+ return client && 'clientConfig' in client ? typeof client.clientConfig === 'object' : false;
388
+ }
389
+ function rewriteSpecName(key) {
390
+ var specs = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS;
391
+ for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
392
+ var entry = specs_1[_i];
393
+ var specName = entry[0],
394
+ param = entry[1];
395
+ if (key === specName || key === param) {
396
+ return specName;
397
+ }
398
+ }
399
+ return key;
400
+ }
401
+ function urlBuilder(options) {
402
+ // Did we get a modernish client?
403
+ if (isSanityModernClientLike(options)) {
404
+ // Inherit config from client
405
+ var _a = options.config(),
406
+ apiUrl = _a.apiHost,
407
+ projectId = _a.projectId,
408
+ dataset = _a.dataset;
409
+ var apiHost = apiUrl || 'https://api.sanity.io';
410
+ return new ImageUrlBuilder(null, {
411
+ baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
412
+ projectId: projectId,
413
+ dataset: dataset
414
+ });
415
+ }
416
+ // Did we get a SanityClient?
417
+ var client = options;
418
+ if (isSanityClientLike(client)) {
419
+ // Inherit config from client
420
+ var _b = client.clientConfig,
421
+ apiUrl = _b.apiHost,
422
+ projectId = _b.projectId,
423
+ dataset = _b.dataset;
424
+ var apiHost = apiUrl || 'https://api.sanity.io';
425
+ return new ImageUrlBuilder(null, {
426
+ baseUrl: apiHost.replace(/^https:\/\/api\./, 'https://cdn.'),
427
+ projectId: projectId,
428
+ dataset: dataset
429
+ });
430
+ }
431
+ // Or just accept the options as given
432
+ return new ImageUrlBuilder(null, options);
433
+ }
434
+ builder.default = urlBuilder;
435
+ var ImageUrlBuilder = /** @class */function () {
436
+ function ImageUrlBuilder(parent, options) {
437
+ this.options = parent ? __assign(__assign({}, parent.options || {}), options || {}) : __assign({}, options || {}); // Copy options
438
+ }
439
+
440
+ ImageUrlBuilder.prototype.withOptions = function (options) {
441
+ var baseUrl = options.baseUrl || this.options.baseUrl;
442
+ var newOptions = {
443
+ baseUrl: baseUrl
444
+ };
445
+ for (var key in options) {
446
+ if (options.hasOwnProperty(key)) {
447
+ var specKey = rewriteSpecName(key);
448
+ newOptions[specKey] = options[key];
449
+ }
450
+ }
451
+ return new ImageUrlBuilder(this, __assign({
452
+ baseUrl: baseUrl
453
+ }, newOptions));
454
+ };
455
+ // The image to be represented. Accepts a Sanity 'image'-document, 'asset'-document or
456
+ // _id of asset. To get the benefit of automatic hot-spot/crop integration with the content
457
+ // studio, the 'image'-document must be provided.
458
+ ImageUrlBuilder.prototype.image = function (source) {
459
+ return this.withOptions({
460
+ source: source
461
+ });
462
+ };
463
+ // Specify the dataset
464
+ ImageUrlBuilder.prototype.dataset = function (dataset) {
465
+ return this.withOptions({
466
+ dataset: dataset
467
+ });
468
+ };
469
+ // Specify the projectId
470
+ ImageUrlBuilder.prototype.projectId = function (projectId) {
471
+ return this.withOptions({
472
+ projectId: projectId
473
+ });
474
+ };
475
+ // Specify background color
476
+ ImageUrlBuilder.prototype.bg = function (bg) {
477
+ return this.withOptions({
478
+ bg: bg
479
+ });
480
+ };
481
+ // Set DPR scaling factor
482
+ ImageUrlBuilder.prototype.dpr = function (dpr) {
483
+ // A DPR of 1 is the default - so only include it if we have a different value
484
+ return this.withOptions(dpr && dpr !== 1 ? {
485
+ dpr: dpr
486
+ } : {});
487
+ };
488
+ // Specify the width of the image in pixels
489
+ ImageUrlBuilder.prototype.width = function (width) {
490
+ return this.withOptions({
491
+ width: width
492
+ });
493
+ };
494
+ // Specify the height of the image in pixels
495
+ ImageUrlBuilder.prototype.height = function (height) {
496
+ return this.withOptions({
497
+ height: height
498
+ });
499
+ };
500
+ // Specify focal point in fraction of image dimensions. Each component 0.0-1.0
501
+ ImageUrlBuilder.prototype.focalPoint = function (x, y) {
502
+ return this.withOptions({
503
+ focalPoint: {
504
+ x: x,
505
+ y: y
506
+ }
507
+ });
508
+ };
509
+ ImageUrlBuilder.prototype.maxWidth = function (maxWidth) {
510
+ return this.withOptions({
511
+ maxWidth: maxWidth
512
+ });
513
+ };
514
+ ImageUrlBuilder.prototype.minWidth = function (minWidth) {
515
+ return this.withOptions({
516
+ minWidth: minWidth
517
+ });
518
+ };
519
+ ImageUrlBuilder.prototype.maxHeight = function (maxHeight) {
520
+ return this.withOptions({
521
+ maxHeight: maxHeight
522
+ });
523
+ };
524
+ ImageUrlBuilder.prototype.minHeight = function (minHeight) {
525
+ return this.withOptions({
526
+ minHeight: minHeight
527
+ });
528
+ };
529
+ // Specify width and height in pixels
530
+ ImageUrlBuilder.prototype.size = function (width, height) {
531
+ return this.withOptions({
532
+ width: width,
533
+ height: height
534
+ });
535
+ };
536
+ // Specify blur between 0 and 100
537
+ ImageUrlBuilder.prototype.blur = function (blur) {
538
+ return this.withOptions({
539
+ blur: blur
540
+ });
541
+ };
542
+ ImageUrlBuilder.prototype.sharpen = function (sharpen) {
543
+ return this.withOptions({
544
+ sharpen: sharpen
545
+ });
546
+ };
547
+ // Specify the desired rectangle of the image
548
+ ImageUrlBuilder.prototype.rect = function (left, top, width, height) {
549
+ return this.withOptions({
550
+ rect: {
551
+ left: left,
552
+ top: top,
553
+ width: width,
554
+ height: height
555
+ }
556
+ });
557
+ };
558
+ // Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
559
+ ImageUrlBuilder.prototype.format = function (format) {
560
+ return this.withOptions({
561
+ format: format
562
+ });
563
+ };
564
+ ImageUrlBuilder.prototype.invert = function (invert) {
565
+ return this.withOptions({
566
+ invert: invert
567
+ });
568
+ };
569
+ // Rotation in degrees 0, 90, 180, 270
570
+ ImageUrlBuilder.prototype.orientation = function (orientation) {
571
+ return this.withOptions({
572
+ orientation: orientation
573
+ });
574
+ };
575
+ // Compression quality 0-100
576
+ ImageUrlBuilder.prototype.quality = function (quality) {
577
+ return this.withOptions({
578
+ quality: quality
579
+ });
580
+ };
581
+ // Make it a download link. Parameter is default filename.
582
+ ImageUrlBuilder.prototype.forceDownload = function (download) {
583
+ return this.withOptions({
584
+ download: download
585
+ });
586
+ };
587
+ // Flip image horizontally
588
+ ImageUrlBuilder.prototype.flipHorizontal = function () {
589
+ return this.withOptions({
590
+ flipHorizontal: true
591
+ });
592
+ };
593
+ // Flip image vertically
594
+ ImageUrlBuilder.prototype.flipVertical = function () {
595
+ return this.withOptions({
596
+ flipVertical: true
597
+ });
598
+ };
599
+ // Ignore crop/hotspot from image record, even when present
600
+ ImageUrlBuilder.prototype.ignoreImageParams = function () {
601
+ return this.withOptions({
602
+ ignoreImageParams: true
603
+ });
604
+ };
605
+ ImageUrlBuilder.prototype.fit = function (value) {
606
+ if (validFits.indexOf(value) === -1) {
607
+ throw new Error("Invalid fit mode \"".concat(value, "\""));
608
+ }
609
+ return this.withOptions({
610
+ fit: value
611
+ });
612
+ };
613
+ ImageUrlBuilder.prototype.crop = function (value) {
614
+ if (validCrops.indexOf(value) === -1) {
615
+ throw new Error("Invalid crop mode \"".concat(value, "\""));
616
+ }
617
+ return this.withOptions({
618
+ crop: value
619
+ });
620
+ };
621
+ // Saturation
622
+ ImageUrlBuilder.prototype.saturation = function (saturation) {
623
+ return this.withOptions({
624
+ saturation: saturation
625
+ });
626
+ };
627
+ ImageUrlBuilder.prototype.auto = function (value) {
628
+ if (validAutoModes.indexOf(value) === -1) {
629
+ throw new Error("Invalid auto mode \"".concat(value, "\""));
630
+ }
631
+ return this.withOptions({
632
+ auto: value
633
+ });
634
+ };
635
+ // Specify the number of pixels to pad the image
636
+ ImageUrlBuilder.prototype.pad = function (pad) {
637
+ return this.withOptions({
638
+ pad: pad
639
+ });
640
+ };
641
+ // Gets the url based on the submitted parameters
642
+ ImageUrlBuilder.prototype.url = function () {
643
+ return (0, urlForImage_1.default)(this.options);
644
+ };
645
+ // Alias for url()
646
+ ImageUrlBuilder.prototype.toString = function () {
647
+ return this.url();
648
+ };
649
+ return ImageUrlBuilder;
650
+ }();
651
+ builder.ImageUrlBuilder = ImageUrlBuilder;
652
+ var __importDefault = commonjsGlobal && commonjsGlobal.__importDefault || function (mod) {
653
+ return mod && mod.__esModule ? mod : {
654
+ "default": mod
655
+ };
656
+ };
657
+ var builder_1 = __importDefault(builder);
658
+ var node = builder_1.default;
659
+ var createImageUrlBuilder = node;
660
+ function useImageUrlBuilder(clientOptions) {
661
+ const client = useClient(clientOptions);
662
+ const builder = useMemo(() => createImageUrlBuilder(client), [client]);
663
+ return builder;
664
+ }
665
+ function useImageUrlBuilderImage(source, clientOptions) {
666
+ const builder = useImageUrlBuilder(clientOptions);
667
+ const image = useMemo(() => source && builder ? builder.image(source) : null, [builder, source]);
668
+ return image;
669
+ }
13
670
  const DEFAULT_PARAMS = {};
14
671
  const DEFAULT_OPTIONS = {
15
- apiVersion: "v2022-05-09"
672
+ apiVersion: "v2023-05-01"
16
673
  };
17
674
  const DEFAULT_INITIAL_VALUE = null;
18
675
  function useListeningQuery(query, _ref) {
@@ -312,5 +969,5 @@ function UserSelectMenu(props) {
312
969
  }, user.id))]
313
970
  });
314
971
  }
315
- export { Cell, Feedback, Row, Table, UserSelectMenu, useListeningQuery, useOpenInNewPane, useProjectUsers };
972
+ export { Cell, Feedback, Row, Table, UserSelectMenu, useImageUrlBuilder, useImageUrlBuilderImage, useListeningQuery, useOpenInNewPane, useProjectUsers };
316
973
  //# sourceMappingURL=index.esm.js.map