sanity-plugin-utils 1.8.0 → 2.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.js DELETED
@@ -1,655 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Card, Flex, Box, Stack, Text, Menu, MenuItem, TextInput, Badge } from "@sanity/ui";
3
- import { styled, css } from "styled-components";
4
- import { RemoveCircleIcon, AddCircleIcon, RestoreIcon } from "@sanity/icons";
5
- import { useState, useRef, useMemo, useEffect, useContext, useCallback } from "react";
6
- import { UserAvatar, useClient, useDocumentStore, useWorkspace } from "sanity";
7
- import isEqual from "react-fast-compare";
8
- import { distinctUntilChanged, catchError } from "rxjs/operators";
9
- import { RouterContext } from "sanity/router";
10
- import { usePaneRouter } from "sanity/structure";
11
- const DEFAULT_PROPS = {
12
- tone: "primary"
13
- };
14
- function Feedback(props) {
15
- const { title, description, icon, tone, children } = {
16
- ...DEFAULT_PROPS,
17
- ...props
18
- };
19
- return /* @__PURE__ */ jsx(Card, { tone, padding: 4, radius: 3, border: !0, children: /* @__PURE__ */ jsxs(Flex, { children: [
20
- icon ? "display icon" : null,
21
- children || /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
22
- title ? /* @__PURE__ */ jsx(Text, { weight: "semibold", children: title }) : null,
23
- description ? /* @__PURE__ */ jsx(Text, { size: 2, children: description }) : null
24
- ] }) })
25
- ] }) });
26
- }
27
- const TableWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, { as: "table", ...props }), StyledTable = styled(TableWrapper)(
28
- () => css`
29
- display: table;
30
- width: 100%;
31
- border-collapse: collapse;
32
-
33
- &:not([hidden]) {
34
- display: table;
35
- border-collapse: collapse;
36
- }
37
- `
38
- );
39
- function Table(props) {
40
- const { children, ...rest } = props;
41
- return /* @__PURE__ */ jsx(StyledTable, { ...rest, children });
42
- }
43
- const RowWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, { as: "tr", ...props }), StyledRow = styled(RowWrapper)(
44
- () => css`
45
- display: table-row;
46
-
47
- &:not([hidden]) {
48
- display: table-row;
49
- }
50
- `
51
- );
52
- function Row(props) {
53
- const { children, ...rest } = props;
54
- return /* @__PURE__ */ jsx(StyledRow, { ...rest, children });
55
- }
56
- const CellWrapper = (props = {}) => /* @__PURE__ */ jsx(Card, { as: "td", ...props }), StyledCell = styled(CellWrapper)(
57
- () => css`
58
- display: table-cell;
59
-
60
- &:not([hidden]) {
61
- display: table-cell;
62
- }
63
- `
64
- );
65
- function Cell(props) {
66
- const { children, ...rest } = props;
67
- return /* @__PURE__ */ jsx(StyledCell, { ...rest, children });
68
- }
69
- function searchUsers(users, searchString) {
70
- return users.filter((user) => !!((user.displayName || "").toLowerCase().startsWith(searchString) || (user.givenName || "").toLowerCase().startsWith(searchString) || (user.middleName || "").toLowerCase().startsWith(searchString) || (user.familyName || "").toLowerCase().startsWith(searchString)));
71
- }
72
- const LABELS = {
73
- addMe: "Assign myself",
74
- removeMe: "Unassign myself",
75
- clear: "Clear assignees",
76
- searchPlaceholder: "Search users",
77
- notFound: "No users found"
78
- };
79
- function UserSelectMenu(props) {
80
- const {
81
- value = [],
82
- userList = [],
83
- onAdd,
84
- onRemove,
85
- onClear,
86
- style = {}
87
- } = props, labels = props?.labels ? { ...LABELS, ...props.labels } : LABELS, [searchString, setSearchString] = useState(""), searchResults = searchUsers(userList || [], searchString), me = userList.find((u) => u.isCurrentUser), meAssigned = me && value.includes(me.id), input = useRef(null), handleSearchChange = (event) => {
88
- setSearchString(event.target.value);
89
- }, handleSelect = (isChecked, user) => {
90
- isChecked ? onRemove && onRemove(user.id) : onAdd && onAdd(user.id);
91
- }, handleAssignMyself = () => {
92
- me && onAdd && onAdd(me.id);
93
- }, handleUnassignMyself = () => {
94
- me && onRemove && onRemove(me.id);
95
- }, handleClearAssigneesClick = () => {
96
- onClear && onClear();
97
- };
98
- return /* @__PURE__ */ jsxs(Menu, { style, children: [
99
- meAssigned ? /* @__PURE__ */ jsx(
100
- MenuItem,
101
- {
102
- tone: "caution",
103
- disabled: !me,
104
- onClick: handleUnassignMyself,
105
- icon: RemoveCircleIcon,
106
- text: labels.removeMe
107
- }
108
- ) : /* @__PURE__ */ jsx(
109
- MenuItem,
110
- {
111
- tone: "positive",
112
- onClick: handleAssignMyself,
113
- icon: AddCircleIcon,
114
- text: labels.addMe
115
- }
116
- ),
117
- /* @__PURE__ */ jsx(
118
- MenuItem,
119
- {
120
- tone: "critical",
121
- disabled: value.length === 0,
122
- onClick: handleClearAssigneesClick,
123
- icon: RestoreIcon,
124
- text: labels.clear
125
- }
126
- ),
127
- /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(
128
- TextInput,
129
- {
130
- ref: input,
131
- onChange: handleSearchChange,
132
- placeholder: labels.searchPlaceholder,
133
- value: searchString
134
- }
135
- ) }),
136
- searchString && searchResults?.length === 0 && /* @__PURE__ */ jsx(MenuItem, { disabled: !0, text: labels.notFound }),
137
- searchResults && searchResults.map((user) => /* @__PURE__ */ jsx(
138
- MenuItem,
139
- {
140
- pressed: value.includes(user.id),
141
- onClick: () => handleSelect(value.indexOf(user.id) > -1, user),
142
- children: /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
143
- /* @__PURE__ */ jsx(UserAvatar, { user, size: 1 }),
144
- /* @__PURE__ */ jsx(Box, { paddingX: 2, flex: 1, children: /* @__PURE__ */ jsx(Text, { children: user.displayName }) }),
145
- user.isCurrentUser && /* @__PURE__ */ jsx(Badge, { fontSize: 1, tone: "positive", mode: "outline", children: "Me" })
146
- ] })
147
- },
148
- user.id
149
- ))
150
- ] });
151
- }
152
- function getDefaultExportFromCjs(x) {
153
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
154
- }
155
- var builder = {}, urlForImage = {}, parseAssetId = {}, hasRequiredParseAssetId;
156
- function requireParseAssetId() {
157
- if (hasRequiredParseAssetId) return parseAssetId;
158
- hasRequiredParseAssetId = 1, Object.defineProperty(parseAssetId, "__esModule", { value: !0 });
159
- var example = "image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg";
160
- function parseAssetId$1(ref) {
161
- var _a = ref.split("-"), id = _a[1], dimensionString = _a[2], format = _a[3];
162
- if (!id || !dimensionString || !format)
163
- throw new Error("Malformed asset _ref '".concat(ref, `'. Expected an id like "`).concat(example, '".'));
164
- var _b = dimensionString.split("x"), imgWidthStr = _b[0], imgHeightStr = _b[1], width = +imgWidthStr, height = +imgHeightStr, isValidAssetId = isFinite(width) && isFinite(height);
165
- if (!isValidAssetId)
166
- throw new Error("Malformed asset _ref '".concat(ref, `'. Expected an id like "`).concat(example, '".'));
167
- return { id, width, height, format };
168
- }
169
- return parseAssetId.default = parseAssetId$1, parseAssetId;
170
- }
171
- var parseSource = {}, hasRequiredParseSource;
172
- function requireParseSource() {
173
- if (hasRequiredParseSource) return parseSource;
174
- hasRequiredParseSource = 1;
175
- var __assign = parseSource && parseSource.__assign || function() {
176
- return __assign = Object.assign || function(t) {
177
- for (var s, i = 1, n = arguments.length; i < n; i++) {
178
- s = arguments[i];
179
- for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
180
- }
181
- return t;
182
- }, __assign.apply(this, arguments);
183
- };
184
- Object.defineProperty(parseSource, "__esModule", { value: !0 }), parseSource.isInProgressUpload = void 0;
185
- var isRef = function(src) {
186
- var source = src;
187
- return source ? typeof source._ref == "string" : !1;
188
- }, isAsset = function(src) {
189
- var source = src;
190
- return source ? typeof source._id == "string" : !1;
191
- }, isAssetStub = function(src) {
192
- var source = src;
193
- return source && source.asset ? typeof source.asset.url == "string" : !1;
194
- }, isInProgressUpload = function(src) {
195
- if (typeof src == "object" && src !== null) {
196
- var obj = src;
197
- return obj._upload && (!obj.asset || !obj.asset._ref);
198
- }
199
- return !1;
200
- };
201
- parseSource.isInProgressUpload = isInProgressUpload;
202
- function parseSource$1(source) {
203
- if (!source)
204
- return null;
205
- var image;
206
- if (typeof source == "string" && isUrl(source))
207
- image = {
208
- asset: { _ref: urlToId(source) }
209
- };
210
- else if (typeof source == "string")
211
- image = {
212
- asset: { _ref: source }
213
- };
214
- else if (isRef(source))
215
- image = {
216
- asset: source
217
- };
218
- else if (isAsset(source))
219
- image = {
220
- asset: {
221
- _ref: source._id || ""
222
- }
223
- };
224
- else if (isAssetStub(source))
225
- image = {
226
- asset: {
227
- _ref: urlToId(source.asset.url)
228
- }
229
- };
230
- else if (typeof source.asset == "object")
231
- image = __assign({}, source);
232
- else
233
- return null;
234
- var img = source;
235
- return img.crop && (image.crop = img.crop), img.hotspot && (image.hotspot = img.hotspot), applyDefaults(image);
236
- }
237
- parseSource.default = parseSource$1;
238
- function isUrl(url) {
239
- return /^https?:\/\//.test("".concat(url));
240
- }
241
- function urlToId(url) {
242
- var parts = url.split("/").slice(-1);
243
- return "image-".concat(parts[0]).replace(/\.([a-z]+)$/, "-$1");
244
- }
245
- function applyDefaults(image) {
246
- if (image.crop && image.hotspot)
247
- return image;
248
- var result = __assign({}, image);
249
- return result.crop || (result.crop = {
250
- left: 0,
251
- top: 0,
252
- bottom: 0,
253
- right: 0
254
- }), result.hotspot || (result.hotspot = {
255
- x: 0.5,
256
- y: 0.5,
257
- height: 1,
258
- width: 1
259
- }), result;
260
- }
261
- return parseSource;
262
- }
263
- var hasRequiredUrlForImage;
264
- function requireUrlForImage() {
265
- return hasRequiredUrlForImage || (hasRequiredUrlForImage = 1, function(exports$1) {
266
- var __assign = urlForImage && urlForImage.__assign || function() {
267
- return __assign = Object.assign || function(t) {
268
- for (var s, i = 1, n = arguments.length; i < n; i++) {
269
- s = arguments[i];
270
- for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
271
- }
272
- return t;
273
- }, __assign.apply(this, arguments);
274
- }, __createBinding = urlForImage && urlForImage.__createBinding || (Object.create ? function(o, m, k, k2) {
275
- k2 === void 0 && (k2 = k);
276
- var desc = Object.getOwnPropertyDescriptor(m, k);
277
- (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) && (desc = { enumerable: !0, get: function() {
278
- return m[k];
279
- } }), Object.defineProperty(o, k2, desc);
280
- } : function(o, m, k, k2) {
281
- k2 === void 0 && (k2 = k), o[k2] = m[k];
282
- }), __setModuleDefault = urlForImage && urlForImage.__setModuleDefault || (Object.create ? function(o, v) {
283
- Object.defineProperty(o, "default", { enumerable: !0, value: v });
284
- } : function(o, v) {
285
- o.default = v;
286
- }), __importStar = urlForImage && urlForImage.__importStar || function(mod) {
287
- if (mod && mod.__esModule) return mod;
288
- var result = {};
289
- if (mod != null) for (var k in mod) k !== "default" && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
290
- return __setModuleDefault(result, mod), result;
291
- }, __importDefault = urlForImage && urlForImage.__importDefault || function(mod) {
292
- return mod && mod.__esModule ? mod : { default: mod };
293
- };
294
- Object.defineProperty(exports$1, "__esModule", { value: !0 }), exports$1.parseSource = exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS = void 0;
295
- var parseAssetId_1 = __importDefault(requireParseAssetId()), parseSource_1 = __importStar(requireParseSource());
296
- exports$1.parseSource = parseSource_1.default, exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS = [
297
- ["width", "w"],
298
- ["height", "h"],
299
- ["format", "fm"],
300
- ["download", "dl"],
301
- ["blur", "blur"],
302
- ["sharpen", "sharp"],
303
- ["invert", "invert"],
304
- ["orientation", "or"],
305
- ["minHeight", "min-h"],
306
- ["maxHeight", "max-h"],
307
- ["minWidth", "min-w"],
308
- ["maxWidth", "max-w"],
309
- ["quality", "q"],
310
- ["fit", "fit"],
311
- ["crop", "crop"],
312
- ["saturation", "sat"],
313
- ["auto", "auto"],
314
- ["dpr", "dpr"],
315
- ["pad", "pad"],
316
- ["frame", "frame"]
317
- ];
318
- function urlForImage$1(options) {
319
- var spec = __assign({}, options || {}), source = spec.source;
320
- delete spec.source;
321
- var image = (0, parseSource_1.default)(source);
322
- if (!image) {
323
- if (source && (0, parseSource_1.isInProgressUpload)(source))
324
- return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8HwQACfsD/QNViZkAAAAASUVORK5CYII=";
325
- throw new Error("Unable to resolve image URL from source (".concat(JSON.stringify(source), ")"));
326
- }
327
- var id = image.asset._ref || image.asset._id || "", asset = (0, parseAssetId_1.default)(id), cropLeft = Math.round(image.crop.left * asset.width), cropTop = Math.round(image.crop.top * asset.height), crop = {
328
- left: cropLeft,
329
- top: cropTop,
330
- width: Math.round(asset.width - image.crop.right * asset.width - cropLeft),
331
- height: Math.round(asset.height - image.crop.bottom * asset.height - cropTop)
332
- }, hotSpotVerticalRadius = image.hotspot.height * asset.height / 2, hotSpotHorizontalRadius = image.hotspot.width * asset.width / 2, hotSpotCenterX = image.hotspot.x * asset.width, hotSpotCenterY = image.hotspot.y * asset.height, hotspot = {
333
- left: hotSpotCenterX - hotSpotHorizontalRadius,
334
- top: hotSpotCenterY - hotSpotVerticalRadius,
335
- right: hotSpotCenterX + hotSpotHorizontalRadius,
336
- bottom: hotSpotCenterY + hotSpotVerticalRadius
337
- };
338
- return spec.rect || spec.focalPoint || spec.ignoreImageParams || spec.crop || (spec = __assign(__assign({}, spec), fit({ crop, hotspot }, spec))), specToImageUrl(__assign(__assign({}, spec), { asset }));
339
- }
340
- exports$1.default = urlForImage$1;
341
- function specToImageUrl(spec) {
342
- var cdnUrl = (spec.baseUrl || "https://cdn.sanity.io").replace(/\/+$/, ""), vanityStub = spec.vanityName ? "/".concat(spec.vanityName) : "", filename = "".concat(spec.asset.id, "-").concat(spec.asset.width, "x").concat(spec.asset.height, ".").concat(spec.asset.format).concat(vanityStub), baseUrl = "".concat(cdnUrl, "/images/").concat(spec.projectId, "/").concat(spec.dataset, "/").concat(filename), params = [];
343
- if (spec.rect) {
344
- var _a = spec.rect, left = _a.left, top_1 = _a.top, width = _a.width, height = _a.height, isEffectiveCrop = left !== 0 || top_1 !== 0 || height !== spec.asset.height || width !== spec.asset.width;
345
- isEffectiveCrop && params.push("rect=".concat(left, ",").concat(top_1, ",").concat(width, ",").concat(height));
346
- }
347
- spec.bg && params.push("bg=".concat(spec.bg)), spec.focalPoint && (params.push("fp-x=".concat(spec.focalPoint.x)), params.push("fp-y=".concat(spec.focalPoint.y)));
348
- var flip = [spec.flipHorizontal && "h", spec.flipVertical && "v"].filter(Boolean).join("");
349
- return flip && params.push("flip=".concat(flip)), exports$1.SPEC_NAME_TO_URL_NAME_MAPPINGS.forEach(function(mapping) {
350
- var specName = mapping[0], param = mapping[1];
351
- typeof spec[specName] < "u" ? params.push("".concat(param, "=").concat(encodeURIComponent(spec[specName]))) : typeof spec[param] < "u" && params.push("".concat(param, "=").concat(encodeURIComponent(spec[param])));
352
- }), params.length === 0 ? baseUrl : "".concat(baseUrl, "?").concat(params.join("&"));
353
- }
354
- function fit(source, spec) {
355
- var cropRect, imgWidth = spec.width, imgHeight = spec.height;
356
- if (!(imgWidth && imgHeight))
357
- return { width: imgWidth, height: imgHeight, rect: source.crop };
358
- var crop = source.crop, hotspot = source.hotspot, desiredAspectRatio = imgWidth / imgHeight, cropAspectRatio = crop.width / crop.height;
359
- if (cropAspectRatio > desiredAspectRatio) {
360
- var height = Math.round(crop.height), width = Math.round(height * desiredAspectRatio), top_2 = Math.max(0, Math.round(crop.top)), hotspotXCenter = Math.round((hotspot.right - hotspot.left) / 2 + hotspot.left), left = Math.max(0, Math.round(hotspotXCenter - width / 2));
361
- left < crop.left ? left = crop.left : left + width > crop.left + crop.width && (left = crop.left + crop.width - width), cropRect = { left, top: top_2, width, height };
362
- } else {
363
- var width = crop.width, height = Math.round(width / desiredAspectRatio), left = Math.max(0, Math.round(crop.left)), hotspotYCenter = Math.round((hotspot.bottom - hotspot.top) / 2 + hotspot.top), top_3 = Math.max(0, Math.round(hotspotYCenter - height / 2));
364
- top_3 < crop.top ? top_3 = crop.top : top_3 + height > crop.top + crop.height && (top_3 = crop.top + crop.height - height), cropRect = { left, top: top_3, width, height };
365
- }
366
- return {
367
- width: imgWidth,
368
- height: imgHeight,
369
- rect: cropRect
370
- };
371
- }
372
- }(urlForImage)), urlForImage;
373
- }
374
- var hasRequiredBuilder;
375
- function requireBuilder() {
376
- if (hasRequiredBuilder) return builder;
377
- hasRequiredBuilder = 1;
378
- var __assign = builder && builder.__assign || function() {
379
- return __assign = Object.assign || function(t) {
380
- for (var s, i = 1, n = arguments.length; i < n; i++) {
381
- s = arguments[i];
382
- for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
383
- }
384
- return t;
385
- }, __assign.apply(this, arguments);
386
- }, __createBinding = builder && builder.__createBinding || (Object.create ? function(o, m, k, k2) {
387
- k2 === void 0 && (k2 = k);
388
- var desc = Object.getOwnPropertyDescriptor(m, k);
389
- (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) && (desc = { enumerable: !0, get: function() {
390
- return m[k];
391
- } }), Object.defineProperty(o, k2, desc);
392
- } : function(o, m, k, k2) {
393
- k2 === void 0 && (k2 = k), o[k2] = m[k];
394
- }), __setModuleDefault = builder && builder.__setModuleDefault || (Object.create ? function(o, v) {
395
- Object.defineProperty(o, "default", { enumerable: !0, value: v });
396
- } : function(o, v) {
397
- o.default = v;
398
- }), __importStar = builder && builder.__importStar || function(mod) {
399
- if (mod && mod.__esModule) return mod;
400
- var result = {};
401
- if (mod != null) for (var k in mod) k !== "default" && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
402
- return __setModuleDefault(result, mod), result;
403
- };
404
- Object.defineProperty(builder, "__esModule", { value: !0 }), builder.ImageUrlBuilder = void 0;
405
- var urlForImage_1 = __importStar(requireUrlForImage()), validFits = ["clip", "crop", "fill", "fillmax", "max", "scale", "min"], validCrops = ["top", "bottom", "left", "right", "center", "focalpoint", "entropy"], validAutoModes = ["format"];
406
- function isSanityModernClientLike(client) {
407
- return client && "config" in client ? typeof client.config == "function" : !1;
408
- }
409
- function isSanityClientLike(client) {
410
- return client && "clientConfig" in client ? typeof client.clientConfig == "object" : !1;
411
- }
412
- function rewriteSpecName(key) {
413
- for (var specs = urlForImage_1.SPEC_NAME_TO_URL_NAME_MAPPINGS, _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {
414
- var entry = specs_1[_i], specName = entry[0], param = entry[1];
415
- if (key === specName || key === param)
416
- return specName;
417
- }
418
- return key;
419
- }
420
- function urlBuilder(options) {
421
- if (isSanityModernClientLike(options)) {
422
- var _a = options.config(), apiUrl = _a.apiHost, projectId = _a.projectId, dataset = _a.dataset, apiHost = apiUrl || "https://api.sanity.io";
423
- return new ImageUrlBuilder(null, {
424
- baseUrl: apiHost.replace(/^https:\/\/api\./, "https://cdn."),
425
- projectId,
426
- dataset
427
- });
428
- }
429
- if (isSanityClientLike(options)) {
430
- var _b = options.clientConfig, apiUrl = _b.apiHost, projectId = _b.projectId, dataset = _b.dataset, apiHost = apiUrl || "https://api.sanity.io";
431
- return new ImageUrlBuilder(null, {
432
- baseUrl: apiHost.replace(/^https:\/\/api\./, "https://cdn."),
433
- projectId,
434
- dataset
435
- });
436
- }
437
- return new ImageUrlBuilder(null, options || {});
438
- }
439
- builder.default = urlBuilder;
440
- var ImageUrlBuilder = (
441
- /** @class */
442
- function() {
443
- function ImageUrlBuilder2(parent, options) {
444
- this.options = parent ? __assign(__assign({}, parent.options || {}), options || {}) : __assign({}, options || {});
445
- }
446
- return ImageUrlBuilder2.prototype.withOptions = function(options) {
447
- var baseUrl = options.baseUrl || this.options.baseUrl, newOptions = { baseUrl };
448
- for (var key in options)
449
- if (options.hasOwnProperty(key)) {
450
- var specKey = rewriteSpecName(key);
451
- newOptions[specKey] = options[key];
452
- }
453
- return new ImageUrlBuilder2(this, __assign({ baseUrl }, newOptions));
454
- }, ImageUrlBuilder2.prototype.image = function(source) {
455
- return this.withOptions({ source });
456
- }, ImageUrlBuilder2.prototype.dataset = function(dataset) {
457
- return this.withOptions({ dataset });
458
- }, ImageUrlBuilder2.prototype.projectId = function(projectId) {
459
- return this.withOptions({ projectId });
460
- }, ImageUrlBuilder2.prototype.bg = function(bg) {
461
- return this.withOptions({ bg });
462
- }, ImageUrlBuilder2.prototype.dpr = function(dpr) {
463
- return this.withOptions(dpr && dpr !== 1 ? { dpr } : {});
464
- }, ImageUrlBuilder2.prototype.width = function(width) {
465
- return this.withOptions({ width });
466
- }, ImageUrlBuilder2.prototype.height = function(height) {
467
- return this.withOptions({ height });
468
- }, ImageUrlBuilder2.prototype.focalPoint = function(x, y) {
469
- return this.withOptions({ focalPoint: { x, y } });
470
- }, ImageUrlBuilder2.prototype.maxWidth = function(maxWidth) {
471
- return this.withOptions({ maxWidth });
472
- }, ImageUrlBuilder2.prototype.minWidth = function(minWidth) {
473
- return this.withOptions({ minWidth });
474
- }, ImageUrlBuilder2.prototype.maxHeight = function(maxHeight) {
475
- return this.withOptions({ maxHeight });
476
- }, ImageUrlBuilder2.prototype.minHeight = function(minHeight) {
477
- return this.withOptions({ minHeight });
478
- }, ImageUrlBuilder2.prototype.size = function(width, height) {
479
- return this.withOptions({ width, height });
480
- }, ImageUrlBuilder2.prototype.blur = function(blur) {
481
- return this.withOptions({ blur });
482
- }, ImageUrlBuilder2.prototype.sharpen = function(sharpen) {
483
- return this.withOptions({ sharpen });
484
- }, ImageUrlBuilder2.prototype.rect = function(left, top, width, height) {
485
- return this.withOptions({ rect: { left, top, width, height } });
486
- }, ImageUrlBuilder2.prototype.format = function(format) {
487
- return this.withOptions({ format });
488
- }, ImageUrlBuilder2.prototype.invert = function(invert) {
489
- return this.withOptions({ invert });
490
- }, ImageUrlBuilder2.prototype.orientation = function(orientation) {
491
- return this.withOptions({ orientation });
492
- }, ImageUrlBuilder2.prototype.quality = function(quality) {
493
- return this.withOptions({ quality });
494
- }, ImageUrlBuilder2.prototype.forceDownload = function(download) {
495
- return this.withOptions({ download });
496
- }, ImageUrlBuilder2.prototype.flipHorizontal = function() {
497
- return this.withOptions({ flipHorizontal: !0 });
498
- }, ImageUrlBuilder2.prototype.flipVertical = function() {
499
- return this.withOptions({ flipVertical: !0 });
500
- }, ImageUrlBuilder2.prototype.ignoreImageParams = function() {
501
- return this.withOptions({ ignoreImageParams: !0 });
502
- }, ImageUrlBuilder2.prototype.fit = function(value) {
503
- if (validFits.indexOf(value) === -1)
504
- throw new Error('Invalid fit mode "'.concat(value, '"'));
505
- return this.withOptions({ fit: value });
506
- }, ImageUrlBuilder2.prototype.crop = function(value) {
507
- if (validCrops.indexOf(value) === -1)
508
- throw new Error('Invalid crop mode "'.concat(value, '"'));
509
- return this.withOptions({ crop: value });
510
- }, ImageUrlBuilder2.prototype.saturation = function(saturation) {
511
- return this.withOptions({ saturation });
512
- }, ImageUrlBuilder2.prototype.auto = function(value) {
513
- if (validAutoModes.indexOf(value) === -1)
514
- throw new Error('Invalid auto mode "'.concat(value, '"'));
515
- return this.withOptions({ auto: value });
516
- }, ImageUrlBuilder2.prototype.pad = function(pad) {
517
- return this.withOptions({ pad });
518
- }, ImageUrlBuilder2.prototype.vanityName = function(value) {
519
- return this.withOptions({ vanityName: value });
520
- }, ImageUrlBuilder2.prototype.frame = function(frame) {
521
- if (frame !== 1)
522
- throw new Error('Invalid frame value "'.concat(frame, '"'));
523
- return this.withOptions({ frame });
524
- }, ImageUrlBuilder2.prototype.url = function() {
525
- return (0, urlForImage_1.default)(this.options);
526
- }, ImageUrlBuilder2.prototype.toString = function() {
527
- return this.url();
528
- }, ImageUrlBuilder2;
529
- }()
530
- );
531
- return builder.ImageUrlBuilder = ImageUrlBuilder, builder;
532
- }
533
- var node, hasRequiredNode;
534
- function requireNode() {
535
- if (hasRequiredNode) return node;
536
- hasRequiredNode = 1;
537
- var __importDefault = node && node.__importDefault || function(mod) {
538
- return mod && mod.__esModule ? mod : { default: mod };
539
- }, builder_1 = __importDefault(requireBuilder());
540
- return node = builder_1.default, node;
541
- }
542
- var nodeExports = /* @__PURE__ */ requireNode(), createImageUrlBuilder = /* @__PURE__ */ getDefaultExportFromCjs(nodeExports);
543
- function useImageUrlBuilder(clientOptions) {
544
- const client = useClient(clientOptions);
545
- return useMemo(() => createImageUrlBuilder(client), [client]);
546
- }
547
- function useImageUrlBuilderImage(source, clientOptions) {
548
- const builder2 = useImageUrlBuilder(clientOptions);
549
- return useMemo(
550
- () => source && builder2 ? builder2.image(source) : null,
551
- [builder2, source]
552
- );
553
- }
554
- const DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2023-05-01" }, DEFAULT_INITIAL_VALUE = null;
555
- function useParams(params) {
556
- const stringifiedParams = useMemo(
557
- () => JSON.stringify(params || {}),
558
- [params]
559
- );
560
- return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]);
561
- }
562
- function useListeningQuery(query, {
563
- params = DEFAULT_PARAMS,
564
- options = DEFAULT_OPTIONS,
565
- initialValue = DEFAULT_INITIAL_VALUE
566
- }) {
567
- const [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(initialValue), memoParams = useParams(params), memoOptions = useParams(options), subscription = useRef(null), documentStore = useDocumentStore();
568
- return useEffect(() => {
569
- if (query && !error && !subscription.current)
570
- try {
571
- subscription.current = documentStore.listenQuery(query, memoParams, memoOptions).pipe(
572
- distinctUntilChanged(isEqual),
573
- catchError((err) => (console.error(err), setError(err), setLoading(!1), setData(null), err))
574
- ).subscribe((documents) => {
575
- setData(
576
- (current) => isEqual(current, documents) ? current : documents
577
- ), setLoading(!1), setError(!1);
578
- });
579
- } catch (err) {
580
- console.error(err), setLoading(!1), setError(err);
581
- }
582
- return error && subscription.current && subscription.current.unsubscribe(), () => {
583
- subscription.current && (subscription?.current?.unsubscribe(), subscription.current = null);
584
- };
585
- }, [query, error, memoParams, memoOptions, documentStore]), { data, loading, error };
586
- }
587
- function useOpenInNewPane(id, type) {
588
- const routerContext = useContext(RouterContext), { routerPanesState, groupIndex } = usePaneRouter();
589
- return useCallback(() => {
590
- if (!routerContext || !id || !type)
591
- return;
592
- const panes = [...routerPanesState];
593
- panes.splice(groupIndex + 1, 0, [
594
- {
595
- id,
596
- params: { type }
597
- }
598
- ]);
599
- const href = routerContext.resolvePathFromState({ panes });
600
- routerContext.navigateUrl({ path: href });
601
- }, [id, type, routerContext, routerPanesState, groupIndex]);
602
- }
603
- function chunkArray(array, size) {
604
- const chunks = [];
605
- for (let i = 0; i < array.length; i += size)
606
- chunks.push(array.slice(i, i + size));
607
- return chunks;
608
- }
609
- function useProjectUsers({ apiVersion }) {
610
- const { currentUser } = useWorkspace(), client = useClient({ apiVersion: apiVersion ?? "2023-01-01" }), [users, setUsers] = useState([]);
611
- return useEffect(() => {
612
- const { projectId } = client.config();
613
- async function getUsersWithRoles() {
614
- try {
615
- const aclData = await client.request({
616
- url: `/projects/${projectId}/acl`
617
- }), userIds = aclData.map((user) => user.projectUserId), userIdChunks = chunkArray(userIds, 200);
618
- let usersData = [];
619
- for (const chunk of userIdChunks) {
620
- const chunkedUserIds = chunk.join(","), response = await client.request({
621
- url: `/projects/${projectId}/users/${chunkedUserIds}`
622
- });
623
- usersData = [...usersData, ...response];
624
- }
625
- const usersWithRoles = usersData.map((user) => {
626
- const userRoles = aclData.find(
627
- (aclUser) => aclUser.projectUserId === user.id
628
- )?.roles || [];
629
- return {
630
- ...user,
631
- isCurrentUser: user.id === currentUser?.id,
632
- roles: userRoles
633
- };
634
- });
635
- setUsers(usersWithRoles);
636
- } catch (err) {
637
- console.error("Failed to fetch users:", err);
638
- }
639
- }
640
- users.length || getUsersWithRoles();
641
- }, [client, currentUser?.id, users.length]), users;
642
- }
643
- export {
644
- Cell,
645
- Feedback,
646
- Row,
647
- Table,
648
- UserSelectMenu,
649
- useImageUrlBuilder,
650
- useImageUrlBuilderImage,
651
- useListeningQuery,
652
- useOpenInNewPane,
653
- useProjectUsers
654
- };
655
- //# sourceMappingURL=index.js.map